Module: JindaGeneralConcern

Extended by:
ActiveSupport::Concern
Included in:
JindaController
Defined in:
app/controllers/concerns/jinda_general_concern.rb

Instance Method Summary collapse

Instance Method Details

#cancelObject



24
25
26
27
28
29
30
31
# File 'app/controllers/concerns/jinda_general_concern.rb', line 24

def cancel
  Jinda::Xmain.find(params[:id]).update_attributes :status=>'X'
  if params[:return]
    redirect_to params[:return]
  else
    redirect_to action:"pending"
  end
end

#docObject



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'app/controllers/concerns/jinda_general_concern.rb', line 108

def doc
  require 'rdoc'
  @app= get_app
  @intro = File.read('README.md')
  @print= "<div align='right'><img src='/assets/printer.png'/> <a href='/jinda/doc_print' target='_blank'/>Print</a></div>"
  doc= render_to_string 'doc.md', :layout => false
  html= Maruku.new(doc).to_html
  File.open('public/doc.html','w') {|f| f.puts html }
  respond_to do |format|
    format.html {
      render :plain=> @print+html, :layout => 'layouts/jqm/_page'
      # render :text=> Maruku.new(doc).to_html, :layout => false
      # format.html {
      #   h = RDoc::Markup::ToHtml.new
      #   render :text=> h.convert(doc), :layout => 'layouts/_page'
    }
      format.pdf  {
        latex= Maruku.new(doc).to_latex
        File.open('tmp/doc.md','w') {|f| f.puts doc}
        File.open('tmp/doc.tex','w') {|f| f.puts latex}
        # system('pdflatex tmp/doc.tex ')
        # send_file( 'tmp/doc.pdf', :type => ‘application/pdf’,
        # :disposition => ‘inline’, :filename => 'doc.pdf')
        render :plain=>'done'
      }
  end
end

#doc_printObject



88
89
90
# File 'app/controllers/concerns/jinda_general_concern.rb', line 88

def doc_print
  render :file=>'public/doc.html', :layout=>'layouts/print'
end

#documentObject

generate documentation for application search data from Doc



94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'app/controllers/concerns/jinda_general_concern.rb', line 94

def document
  doc = Jinda::Doc.find params[:id]
  if doc.cloudinary
    require 'net/http'
    require "uri"
    uri = URI.parse(doc.url)
    data = Net::HTTP.get_response(uri)
    send_data(data.body, :filename=>doc.filename, :type=>doc.content_type, :disposition=>"inline")
  else
    data= read_binary(doc.url)
    send_data(data, :filename=>doc.filename, :type=>doc.content_type, :disposition=>"inline")
  end
end

#err404Object



164
165
166
167
168
169
# File 'app/controllers/concerns/jinda_general_concern.rb', line 164

def err404
  # ma_log 'ERROR', 'main/err404'
  flash[:notice] = "We're sorry, but something went wrong. We've been notified about this issue and we'll take a look at it shortly."
  ma_log "We're sorry, but something went wrong. We've been notified about this issue and we'll take a look at it shortly."
  redirect_to '/'
end

#err500Object



171
172
173
174
175
176
# File 'app/controllers/concerns/jinda_general_concern.rb', line 171

def err500
  # ma_log 'ERROR', 'main/err500'
  flash[:notice] = "We're sorry, but something went wrong. We've been notified about this issue and we'll take a look at it shortly."
  ma_log "We're sorry, but something went wrong. We've been notified about this issue and we'll take a look at it shortly."
  redirect_to '/'
end

#error_logsObject



11
12
13
# File 'app/controllers/concerns/jinda_general_concern.rb', line 11

def error_logs
  @xmains = Jinda::Xmain.in(status:['E']).desc(:created_at).page(params[:page]).per(10)
end

#get_image(key, params) ⇒ Object

process images from first level



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/concerns/jinda_general_concern.rb', line 34

def get_image(key, params)
  doc = Jinda::Doc.create(
    :name=> key.to_s,
    :xmain=> @xmain.id,
    :runseq=> @runseq.id,
    :filename=> params.original_filename,
    :content_type => params.content_type || 'application/zip',
    :data_text=> '',
    :ma_display=>true,
    :ma_secured => @xmain.service.ma_secured )
  if defined?(IMAGE_LOCATION)
    filename = "#{IMAGE_LOCATION}/f#{Param.gen(:asset_id)}"
    File.open(filename,"wb") { |f| f.write(params.read) }
    # File.open(filename,"wb") { |f| f.puts(params.read) }
    eval "@xvars[@runseq.code][key] = '#{url_for(:action=>'document', :id=>doc.id, :only_path => true )}' "
    doc.update_attributes :url => filename, :basename => File.basename(filename), :cloudinary => false
  else
    result = Cloudinary::Uploader.upload(params)
    eval %Q{ @xvars[@runseq.code][key] = '#{result["url"]}' }
    doc.update_attributes :url => result["url"], :basename => File.basename(result["url"]), :cloudinary => true
  end
end

#get_image1(key, key1, params) ⇒ Object

process images from second level, e.g,, fields_for save uploaded file info to Doc



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'app/controllers/concerns/jinda_general_concern.rb', line 59

def get_image1(key, key1, params)
  doc = Jinda::Doc.create(
    :name=> "#{key}_#{key1}",
    :xmain=> @xmain.id,
    :runseq=> @runseq.id,
    :filename=> params.original_filename,
    :content_type => params.content_type || 'application/zip',
    :data_text=> '',
    :dscan=> '',
    :description=>'',
    :keywords=>'',
    :category=>'',
    :ma_display=>true, :ma_secured => @xmain.service.ma_secured )
  if defined?(IMAGE_LOCATION)
    filename = "#{IMAGE_LOCATION}/f#{Param.gen(:asset_id)}"
    File.open(filename,"wb") { |f| f.write(params.read) }
    eval "@xvars[@runseq.code][key][key1] = '#{url_for(:action=>'document', :id=>doc.id, :only_path => true)}' "
    doc.update_attributes :url => filename, 
      :basename => File.basename(filename), 
      :cloudinary => false, 
      :dscan => @xvars[@runseq.code][key][key1],
      :user_id => @xvars["user_id"]
  else
    result = Cloudinary::Uploader.upload(params)
    eval %Q{ @xvars[@runseq.code][key][key1] = '#{result["url"]}' }
    doc.update_attributes :url => result["url"], :basename => File.basename(result["url"]), :cloudinary => true, :dscan => @xvars[@runseq.code][key][key1]
  end
end

#helpObject



148
149
# File 'app/controllers/concerns/jinda_general_concern.rb', line 148

def help
end

#indexObject



4
5
# File 'app/controllers/concerns/jinda_general_concern.rb', line 4

def index
end

#logsObject



7
8
9
# File 'app/controllers/concerns/jinda_general_concern.rb', line 7

def logs
  @xmains = Jinda::Xmain.all.desc(:created_at).page(params[:page]).per(10)
end

#notice_logsObject



15
16
17
# File 'app/controllers/concerns/jinda_general_concern.rb', line 15

def notice_logs
  @notices= Jinda::Notice.desc(:created_at).page(params[:page]).per(10)
end

#pendingObject



19
20
21
22
# File 'app/controllers/concerns/jinda_general_concern.rb', line 19

def pending
  @title= "Pending Tasks"
  @xmains = Jinda::Xmain.in(status:['R','I']).asc(:created_at)
end

#searchObject



151
152
153
154
155
156
157
158
159
160
161
162
# File 'app/controllers/concerns/jinda_general_concern.rb', line 151

def search
  @q = params[:q] || params[:ma_search][:q] || ""
  @title = "Search Result #{@q}"
  @backbtn= true
  @cache= true
  if @q.blank?
    redirect_to "/"
  else
    s= GmaSearch.create :q=>@q, :ip=> request.env["REMOTE_ADDR"]
    do_search
  end
end

#statusObject



136
137
138
139
140
141
142
143
144
145
146
# File 'app/controllers/concerns/jinda_general_concern.rb', line 136

def status
  @xmain= Jinda::Xmain.where(:xid=>params[:xid]).first
  @title= "Task number #{params[:xid]} #{@xmain.name}"
  @backbtn= true
  @xvars= @xmain.xvars
  # flash.now[:notice]= "รายการ #{@xmain.id} ได้ถูกยกเลิกแล้ว" if @xmain.status=='X'
  ma_log "Task #{@xmain.id} is cancelled" if @xmain.status=='X'
  # flash.now[:notice]= "transaction #{@xmain.id} was cancelled" if @xmain.status=='X'
rescue
  refresh_to "/", :alert => "Could not find task number <b> #{params[:xid]} </b>"
end