jinda 0.4.9 → 0.5.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/lib/generators/jinda/install_generator.rb +13 -6
- data/lib/generators/jinda/templates/README.md +3 -3
- data/lib/generators/jinda/templates/app/assets/javascripts/{disable_enter_key.js-org → disable_enter_key.js} +0 -0
- data/lib/generators/jinda/templates/app/assets/stylesheets/modules.scss +84 -0
- data/lib/generators/jinda/templates/app/controllers/concerns/jinda_general_concern.rb +179 -0
- data/lib/generators/jinda/templates/app/controllers/concerns/jinda_run_concern.rb +351 -0
- data/lib/generators/jinda/templates/app/controllers/jinda_org/docs_controller.rb +55 -0
- data/lib/generators/jinda/templates/app/controllers/jinda_org/jinda_controller.rb +30 -544
- data/lib/generators/jinda/templates/app/controllers/jinda_org/notes_controller.rb +4 -7
- data/lib/generators/jinda/templates/app/jinda/index.mm +55 -15
- data/lib/generators/jinda/templates/app/jinda/template/view.html.erb +22 -23
- data/lib/generators/jinda/templates/app/models/jinda/doc.rb +31 -17
- data/lib/generators/jinda/templates/app/views/docs/doc_edit/doc_edit.html.erb +21 -0
- data/lib/generators/jinda/templates/app/views/docs/doc_edit/doc_select.html.erb +14 -0
- data/lib/generators/jinda/templates/app/views/docs/doc_new/doc_form.html.erb +26 -0
- data/lib/generators/jinda/templates/app/views/docs/doc_new/doc_form.md +36 -0
- data/lib/generators/jinda/templates/app/views/docs/doc_xedit/doc_edit.html.erb +21 -0
- data/lib/generators/jinda/templates/app/views/docs/edit/select_note.html.erb +14 -0
- data/lib/generators/jinda/templates/app/views/docs/index.haml +21 -0
- data/lib/generators/jinda/templates/app/views/docs/my.haml +27 -0
- data/lib/generators/jinda/templates/app/views/jinda/index.html.haml +3 -3
- data/lib/generators/jinda/templates/app/views/jinda/run_output.haml +3 -3
- data/lib/generators/jinda/templates/app/views/notes/my.haml +1 -1
- data/lib/jinda/helpers.rb +208 -59
- data/lib/jinda/version.rb +1 -1
- metadata +17 -8
- data/lib/generators/jinda/templates/app/controllers/ctrs_controller.rb-gem-test +0 -2
- data/lib/jinda/ template/view.html.erb +0 -25
- data/lib/jinda/app/jinda/template/view.html.erb +0 -27
@@ -0,0 +1,55 @@
|
|
1
|
+
class DocsController < ApplicationController
|
2
|
+
before_action :load_doc, only: [:destroy]
|
3
|
+
before_action :load_doc_form, only: [:doc_update, :edit, :my]
|
4
|
+
|
5
|
+
def index
|
6
|
+
@documents = Jinda::Doc.desc(:created_at).page(params[:page]).per(10)
|
7
|
+
end
|
8
|
+
|
9
|
+
def edit
|
10
|
+
end
|
11
|
+
|
12
|
+
def my
|
13
|
+
@page_title = 'My Document'
|
14
|
+
end
|
15
|
+
|
16
|
+
def doc_update
|
17
|
+
|
18
|
+
if Jinda::Doc.where(:runseq_id => $xvars["doc_form"]["runseq_id"]).exists?
|
19
|
+
@doc = Jinda::Doc.where(:runseq_id => $xvars["doc_form"]["runseq_id"]).first
|
20
|
+
@doc.update(description: $xvars["doc_form"]["description"],
|
21
|
+
category: $xvars["doc_form"]["jinda_doc"]["category"],
|
22
|
+
keywords: $xvars["doc_form"]["keywords"],
|
23
|
+
user_id: $xvars["user_id"]
|
24
|
+
)
|
25
|
+
else
|
26
|
+
# create here
|
27
|
+
# Todo
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def destroy
|
32
|
+
# duplicated from jinda_controller
|
33
|
+
# Expected to use in jinda_controller
|
34
|
+
current_ma_user = User.where(:auth_token => cookies[:auth_token]).first if cookies[:auth_token]
|
35
|
+
|
36
|
+
if Rails.env.test? #Temp solution until fix test of current_ma_user
|
37
|
+
current_ma_user = $xvars["current_ma_user"]
|
38
|
+
#current_ma_user = @doc.user
|
39
|
+
end
|
40
|
+
|
41
|
+
if current_ma_user.role.upcase.split(',').include?("A") || current_ma_user == @doc.user
|
42
|
+
@doc.destroy
|
43
|
+
end
|
44
|
+
redirect_to :action=>'my'
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def load_doc_form
|
50
|
+
@docs = Jinda::Doc.all.desc(:created_at).page(params[:page]).per(10)
|
51
|
+
end
|
52
|
+
def load_doc
|
53
|
+
@doc = Jinda::Doc.find(params[:doc_id])
|
54
|
+
end
|
55
|
+
end
|
@@ -1,77 +1,19 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
|
-
###################################################### @runseq ####################################################
|
3
|
-
# @runseq => #<Jinda::Runseq _id: 5df31912a54d758417a7afc9,
|
4
|
-
# created_at: 2019-12-13 04:52:34 UTC,
|
5
|
-
# updated_at: 2019-12-13 04:52:43 UTC,
|
6
|
-
# user_id: nil,
|
7
|
-
# xmain_id: BSON::ObjectId('5df31912a54d758417a7afc7'),
|
8
|
-
# action: "do",
|
9
|
-
# status: "R",
|
10
|
-
# code: "create",
|
11
|
-
# name: "Create Article",
|
12
|
-
# role: "",
|
13
|
-
# rule: "true",
|
14
|
-
# rstep: 2,
|
15
|
-
# form_step: 1,
|
16
|
-
# start: 2019-12-13 04:52:43 UTC,
|
17
|
-
# stop: nil,
|
18
|
-
# end: true,
|
19
|
-
# xml: "<node CREATED='1493419491125' ID='ID_1687683396' MODIFIED='1493483244848' TEXT='create: Create Article'><icon BUILTIN='bookmark'/></node>",
|
20
|
-
# ip: nil>
|
21
|
-
|
22
|
-
######################################################################################################################
|
23
2
|
|
24
3
|
class JindaController < ApplicationController
|
25
|
-
|
26
|
-
|
27
|
-
def logs
|
28
|
-
@xmains = Jinda::Xmain.all.desc(:created_at).page(params[:page]).per(10)
|
29
|
-
end
|
30
|
-
def error_logs
|
31
|
-
@xmains = Jinda::Xmain.in(status:['E']).desc(:created_at).page(params[:page]).per(10)
|
32
|
-
end
|
33
|
-
def notice_logs
|
34
|
-
@notices= Jinda::Notice.desc(:created_at).page(params[:page]).per(10)
|
35
|
-
end
|
36
|
-
def pending
|
37
|
-
@title= "Pending Tasks"
|
38
|
-
@xmains = Jinda::Xmain.in(status:['R','I']).asc(:created_at)
|
39
|
-
end
|
40
|
-
def cancel
|
41
|
-
Jinda::Xmain.find(params[:id]).update_attributes :status=>'X'
|
42
|
-
if params[:return]
|
43
|
-
redirect_to params[:return]
|
44
|
-
else
|
45
|
-
redirect_to action:"pending"
|
46
|
-
end
|
47
|
-
end
|
48
|
-
def clear_xmains
|
49
|
-
Jinda::Xmain.where(:status =>{'$in'=>['R','I']}).update_all(:status=>'X')
|
50
|
-
redirect_to action:"pending"
|
51
|
-
end
|
52
|
-
def ajax_notice
|
53
|
-
if notice=Jinda::Notice.recent(current_ma_user, request.env["REMOTE_ADDR"])
|
54
|
-
notice.update_attribute :unread, false
|
55
|
-
js = "notice('#{notice.message}');"
|
56
|
-
else
|
57
|
-
js = ""
|
58
|
-
end
|
59
|
-
render plain: "<script>#{js}</script>"
|
60
|
-
end
|
61
|
-
####################################################################################################]
|
62
|
-
# prepare xmain.runseq eg: how many form_step or total_step and step properties check if authorized
|
63
|
-
####################################################################################################]
|
4
|
+
include JindaRunConcern
|
5
|
+
include JindaGeneralConcern
|
64
6
|
# view menu by user selected what service (module and code) to run (not all services like menu did
|
65
7
|
# Its only one service
|
8
|
+
|
66
9
|
def init
|
67
10
|
module_code, code = params[:s].split(":")
|
68
11
|
@service= Jinda::Service.where(:module_code=> module_code, :code=> code).first
|
69
|
-
# @service= Jinda::Service.where(:module_code=> params[:module], :code=> params[:service]).first
|
70
12
|
if @service && authorize_init?
|
71
13
|
xmain = create_xmain(@service)
|
72
14
|
result = create_runseq(xmain)
|
73
15
|
unless result
|
74
|
-
message = "cannot find action for xmain #{xmain.id}"
|
16
|
+
message = "Node missing action icon: cannot find action for xmain #{xmain.id}, the node required action(icon) in freemind eg: form, list, method"
|
75
17
|
ma_log(message)
|
76
18
|
flash[:notice]= message
|
77
19
|
redirect_to "pending" and return
|
@@ -79,16 +21,38 @@ class JindaController < ApplicationController
|
|
79
21
|
xmain.update_attribute(:xvars, @xvars)
|
80
22
|
xmain.runseqs.last.update_attribute(:end,true)
|
81
23
|
#Above line cause error update_attribute in heroku shown in logs and it was proposed to fixed in github:'kul1/g241502'
|
24
|
+
# Main action run with :id
|
82
25
|
redirect_to :action=>'run', :id=>xmain.id
|
83
26
|
else
|
84
27
|
refresh_to "/", :alert => "Error: cannot process"
|
28
|
+
error_run_xmain = "Error_run_xmain"
|
29
|
+
ma_log(error_run_xmain)
|
85
30
|
end
|
86
31
|
end
|
87
|
-
|
32
|
+
|
33
|
+
########################################################################]
|
88
34
|
# run if, form, mail, output etc depend on icon in freemind
|
89
|
-
# action from @
|
90
|
-
# Then will call
|
91
|
-
|
35
|
+
# action from @r.action == do, form, if, output
|
36
|
+
# Then will call def run_do, run_form, run_if, run_output
|
37
|
+
########################################################################]
|
38
|
+
#
|
39
|
+
# run
|
40
|
+
# init_vars
|
41
|
+
# To get all var from global and runseq, action
|
42
|
+
# (@runseq.action)
|
43
|
+
#
|
44
|
+
# run_do, run_form, run_if, run_output
|
45
|
+
# run_do => controller => action eg: update, create, document
|
46
|
+
# run_form =>
|
47
|
+
# run_form.haml => - next step => def end_form
|
48
|
+
# - next_step = end_form
|
49
|
+
# run_if =>
|
50
|
+
# run_output =>
|
51
|
+
#
|
52
|
+
# end_action
|
53
|
+
# => save local var to database :current_runseq
|
54
|
+
# :current_runseq => next_runseq
|
55
|
+
#
|
92
56
|
def run
|
93
57
|
init_vars(params[:id])
|
94
58
|
if authorize?
|
@@ -98,482 +62,4 @@ class JindaController < ApplicationController
|
|
98
62
|
redirect_to_root
|
99
63
|
end
|
100
64
|
end
|
101
|
-
def run_form
|
102
|
-
init_vars(params[:id])
|
103
|
-
if authorize?
|
104
|
-
if ['F', 'X'].include? @xmain.status
|
105
|
-
redirect_to_root
|
106
|
-
else
|
107
|
-
service= @xmain.service
|
108
|
-
###############################################################################################
|
109
|
-
# Run View Form f created template by jinda rake follow freemind mm file
|
110
|
-
###############################################################################################
|
111
|
-
if service
|
112
|
-
@title= "Transaction ID #{@xmain.xid}: #{@xmain.name} / #{@runseq.name}"
|
113
|
-
fhelp= "app/views/#{service.module.code}/#{service.code}/#{@runseq.code}.md"
|
114
|
-
@help = File.read(fhelp) if File.exists?(fhelp)
|
115
|
-
f= "app/views/#{service.module.code}/#{service.code}/#{@runseq.code}.html.erb"
|
116
|
-
if File.file?(f)
|
117
|
-
@ui= File.read(f)
|
118
|
-
else
|
119
|
-
# flash[:notice]= "Error: Can not find the view file for this controller"
|
120
|
-
ma_log "Error: Can not find the view file for this controller"
|
121
|
-
redirect_to_root
|
122
|
-
end
|
123
|
-
|
124
|
-
end
|
125
|
-
end
|
126
|
-
else
|
127
|
-
redirect_to_root
|
128
|
-
end
|
129
|
-
end
|
130
|
-
def run_if
|
131
|
-
init_vars(params[:id])
|
132
|
-
condition= eval(@runseq.code).to_s
|
133
|
-
match_found= false
|
134
|
-
if condition
|
135
|
-
xml= REXML::Document.new(@runseq.xml).root
|
136
|
-
next_runseq= nil
|
137
|
-
text = xml.elements['//node/node'].attributes['TEXT']
|
138
|
-
match, name= text.split(':',2)
|
139
|
-
label= name2code(name.strip)
|
140
|
-
if condition==match
|
141
|
-
if label=="end"
|
142
|
-
@end_job= true
|
143
|
-
else
|
144
|
-
next_runseq= @xmain.runseqs.where(:code=> label, :action.ne=>'redirect').first
|
145
|
-
match_found= true if next_runseq
|
146
|
-
@runseq_not_f= false
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end
|
150
|
-
unless match_found || @end_job
|
151
|
-
next_runseq= @xmain.runseqs.where( rstep:(@xvars['current_step']+1) ).first
|
152
|
-
end
|
153
|
-
end_action(next_runseq)
|
154
|
-
end
|
155
|
-
def run_redirect
|
156
|
-
init_vars(params[:id])
|
157
|
-
# next_runseq= @xmain.runseqs.first :conditions=>["id != ? AND code = ?",@runseq.id, @runseq.code]
|
158
|
-
next_runseq= @xmain.runseqs.where(:id.ne=>@runseq.id, :code=>@runseq.code).first
|
159
|
-
@xmain.current_runseq= next_runseq.id
|
160
|
-
end_action(next_runseq)
|
161
|
-
end
|
162
|
-
def run_do
|
163
|
-
init_vars(params[:id])
|
164
|
-
@runseq.start ||= Time.now
|
165
|
-
@runseq.status= 'R' # running
|
166
|
-
$runseq_id= @runseq.id
|
167
|
-
$user_id= current_ma_user.try(:id)
|
168
|
-
set_global
|
169
|
-
controller = Kernel.const_get(@xvars['custom_controller']).new
|
170
|
-
result = controller.send(@runseq.code)
|
171
|
-
init_vars_by_runseq($runseq_id)
|
172
|
-
@xvars = $xvars
|
173
|
-
@xvars[@runseq.code.to_sym]= result.to_s
|
174
|
-
@xvars['current_step']= @runseq.rstep
|
175
|
-
@runseq.status= 'F' #finish
|
176
|
-
@runseq.stop= Time.now
|
177
|
-
@runseq.save
|
178
|
-
end_action
|
179
|
-
rescue => e
|
180
|
-
@xmain.status='E'
|
181
|
-
@xvars['error']= e.to_s+e.backtrace.to_s
|
182
|
-
@xmain.xvars= $xvars
|
183
|
-
@xmain.save
|
184
|
-
@runseq.status= 'F' #finish
|
185
|
-
@runseq.stop= Time.now
|
186
|
-
@runseq.save
|
187
|
-
refresh_to "/", :alert => "Sorry opeation error at #{@xmain.id} #{@xvars['error']}"
|
188
|
-
end
|
189
|
-
def run_output
|
190
|
-
init_vars(params[:id])
|
191
|
-
service= @xmain.service
|
192
|
-
disp= get_option("ma_display")
|
193
|
-
ma_display = (disp && !affirm(disp)) ? false : true
|
194
|
-
if service
|
195
|
-
f= "app/views/#{service.module.code}/#{service.code}/#{@runseq.code}.html.erb"
|
196
|
-
@ui= File.read(f)
|
197
|
-
if Jinda::Doc.where(:runseq_id=>@runseq.id).exists?
|
198
|
-
@doc= Jinda::Doc.where(:runseq_id=>@runseq.id).first
|
199
|
-
@doc.update_attributes :data_text=> render_to_string(:inline=>@ui, :layout=>"utf8"),
|
200
|
-
:xmain=>@xmain, :runseq=>@runseq, :user=>current_ma_user,
|
201
|
-
:ip=> get_ip, :service=>service, :ma_display=>ma_display,
|
202
|
-
:ma_secured => @xmain.service.ma_secured
|
203
|
-
else
|
204
|
-
@doc= Jinda::Doc.create :name=> @runseq.name,
|
205
|
-
:content_type=>"output", :data_text=> render_to_string(:inline=>@ui, :layout=>"utf8"),
|
206
|
-
:xmain=>@xmain, :runseq=>@runseq, :user=>current_ma_user,
|
207
|
-
:ip=> get_ip, :service=>service, :ma_display=>ma_display,
|
208
|
-
:ma_secured => @xmain.service.ma_secured
|
209
|
-
end
|
210
|
-
@message = defined?(MSG_NEXT) ? MSG_NEXT : "Next >"
|
211
|
-
@message = "Finish" if @runseq.end
|
212
|
-
eval "@xvars[@runseq.code] = url_for(:controller=>'Jinda', :action=>'document', :id=>@doc.id)"
|
213
|
-
else
|
214
|
-
# flash[:notice]= "Error: Can not find the view file for this controller"
|
215
|
-
ma_log "Error: Can not find the view file for this controller"
|
216
|
-
redirect_to_root
|
217
|
-
end
|
218
|
-
#ma_display= get_option("ma_display")
|
219
|
-
unless ma_display
|
220
|
-
end_action
|
221
|
-
end
|
222
|
-
end
|
223
|
-
def run_mail
|
224
|
-
init_vars(params[:id])
|
225
|
-
service= @xmain.service
|
226
|
-
f= "app/views/#{service.module.code}/#{service.code}/#{@runseq.code}.html.erb"
|
227
|
-
@ui= File.read(f).html_safe
|
228
|
-
@doc= Jinda::Doc.create :name=> @runseq.name,
|
229
|
-
:content_type=>"mail", :data_text=> render_to_string(:inline=>@ui, :layout=>false),
|
230
|
-
:xmain=>@xmain, :runseq=>@runseq, :user=>current_ma_user,
|
231
|
-
:ip=> get_ip, :service=>service, :ma_display=>false,
|
232
|
-
:ma_secured => @xmain.service.ma_secured
|
233
|
-
eval "@xvars[:#{@runseq.code}] = url_for(:controller=>'jinda', :action=>'document', :id=>@doc.id)"
|
234
|
-
mail_from = get_option('from')
|
235
|
-
# sender= render_to_string(:inline=>mail_from) if mail_from
|
236
|
-
mail_to = get_option('to')
|
237
|
-
recipients= render_to_string(:inline=>mail_to) if mail_to
|
238
|
-
mail_subject = get_option('subject')
|
239
|
-
subject= render_to_string(:inline=>mail_subject) || "#{@runseq.name}"
|
240
|
-
JindaMailer.gmail(@doc.data_text, recipients, subject).deliver unless DONT_SEND_MAIL
|
241
|
-
end_action
|
242
|
-
end
|
243
|
-
def end_output
|
244
|
-
init_vars(params[:xmain_id])
|
245
|
-
end_action
|
246
|
-
end
|
247
|
-
|
248
|
-
####################################################
|
249
|
-
# search for original_filename if attached #
|
250
|
-
####################################################
|
251
|
-
#
|
252
|
-
# def end_form
|
253
|
-
# init_vars(params[:xmain_id])
|
254
|
-
# eval "@xvars[@runseq.code] = {} unless @xvars[@runseq.code]"
|
255
|
-
# params.each { |k,v|
|
256
|
-
# if params[k].respond_to? :original_filename
|
257
|
-
# get_image(k, params[k])
|
258
|
-
# elsif params[k].is_a?(Hash)
|
259
|
-
# eval "@xvars[@runseq.code][k] = v"
|
260
|
-
# params[k].each { |k1,v1|
|
261
|
-
# next unless v1.respond_to?(:original_filename)
|
262
|
-
# get_image1(k, k1, params[k][k1])
|
263
|
-
# }
|
264
|
-
# else
|
265
|
-
# v = v.to_unsafe_h unless v.class == String
|
266
|
-
# eval "@xvars[@runseq.code][k] = v"
|
267
|
-
# end
|
268
|
-
# }
|
269
|
-
# end_action
|
270
|
-
# end
|
271
|
-
# Not working at ?(Hash)
|
272
|
-
# Temp hardcode below!! require field to load name :filename
|
273
|
-
|
274
|
-
|
275
|
-
def end_form
|
276
|
-
init_vars(params[:xmain_id])
|
277
|
-
eval "@xvars[@runseq.code] = {} unless @xvars[@runseq.code]"
|
278
|
-
# Search for uploaded file name if exist
|
279
|
-
params.each { |k,v|
|
280
|
-
if params[k].respond_to? :original_filename
|
281
|
-
get_image(k, params[k])
|
282
|
-
# check if params of array in form eg: edit_article
|
283
|
-
elsif params[k].is_a?(ActionController::Parameters)
|
284
|
-
params[k].each { |k1,v1|
|
285
|
-
# eval "@xvars[@runseq.code][k1] = params.require(k1).permit(k1)"
|
286
|
-
eval "@xvars[@runseq.code][k1] = v1"
|
287
|
-
next unless v1.respond_to?(:original_filename)
|
288
|
-
get_image1(k, k1, params[k][k1])
|
289
|
-
}
|
290
|
-
else
|
291
|
-
# bug in to_unsalfe_h rails 5.1.6 https://github.com/getsentry/raven-ruby/issues/799
|
292
|
-
# Solution:
|
293
|
-
# https://stackoverflow.com/questions/34949505/rails-5-unable-to-retrieve-hash-values-from-parameter
|
294
|
-
# v = v.to_unsafe_h unless v.class == String
|
295
|
-
# v = params.require[k] unless v.class == String
|
296
|
-
v = v.to_s unless v.class == String
|
297
|
-
eval "@xvars[@runseq.code][k] = v"
|
298
|
-
end
|
299
|
-
}
|
300
|
-
end_action
|
301
|
-
end
|
302
|
-
|
303
|
-
def end_action(next_runseq = nil)
|
304
|
-
# @runseq.status='F' unless @runseq_not_f
|
305
|
-
@xmain.xvars= @xvars
|
306
|
-
@xmain.status= 'R' # running
|
307
|
-
@xmain.save!
|
308
|
-
@runseq.status='F'
|
309
|
-
@runseq.user= current_ma_user
|
310
|
-
@runseq.stop= Time.now
|
311
|
-
@runseq.save
|
312
|
-
next_runseq= @xmain.runseqs.where(:rstep=> @runseq.rstep+1).first unless next_runseq
|
313
|
-
if @end_job || !next_runseq # job finish
|
314
|
-
@xmain.xvars= @xvars
|
315
|
-
@xmain.status= 'F' unless @xmain.status== 'E' # finish
|
316
|
-
@xmain.stop= Time.now
|
317
|
-
@xmain.save
|
318
|
-
if @xvars['p']['return']
|
319
|
-
redirect_to @xvars['p']['return'] and return
|
320
|
-
else
|
321
|
-
if @user
|
322
|
-
redirect_to :action=>'index' and return
|
323
|
-
else
|
324
|
-
redirect_to_root and return
|
325
|
-
end
|
326
|
-
end
|
327
|
-
else
|
328
|
-
@xmain.update_attribute :current_runseq, next_runseq.id
|
329
|
-
redirect_to :action=>'run', :id=>@xmain.id and return
|
330
|
-
end
|
331
|
-
end
|
332
|
-
# process images from first level
|
333
|
-
def get_image(key, params)
|
334
|
-
doc = Jinda::Doc.create(
|
335
|
-
:name=> key.to_s,
|
336
|
-
:xmain=> @xmain.id,
|
337
|
-
:runseq=> @runseq.id,
|
338
|
-
:filename=> params.original_filename,
|
339
|
-
:content_type => params.content_type || 'application/zip',
|
340
|
-
:data_text=> '',
|
341
|
-
:ma_display=>true,
|
342
|
-
:ma_secured => @xmain.service.ma_secured )
|
343
|
-
if defined?(IMAGE_LOCATION)
|
344
|
-
filename = "#{IMAGE_LOCATION}/f#{Param.gen(:asset_id)}"
|
345
|
-
File.open(filename,"wb") { |f| f.write(params.read) }
|
346
|
-
# File.open(filename,"wb") { |f| f.puts(params.read) }
|
347
|
-
eval "@xvars[@runseq.code][key] = '#{url_for(:action=>'document', :id=>doc.id, :only_path => true )}' "
|
348
|
-
doc.update_attributes :url => filename, :basename => File.basename(filename), :cloudinary => false
|
349
|
-
else
|
350
|
-
result = Cloudinary::Uploader.upload(params)
|
351
|
-
eval %Q{ @xvars[@runseq.code][key] = '#{result["url"]}' }
|
352
|
-
doc.update_attributes :url => result["url"], :basename => File.basename(result["url"]), :cloudinary => true
|
353
|
-
end
|
354
|
-
end
|
355
|
-
# process images from second level, e.g,, fields_for
|
356
|
-
def get_image1(key, key1, params)
|
357
|
-
doc = Jinda::Doc.create(
|
358
|
-
:name=> "#{key}_#{key1}",
|
359
|
-
:xmain=> @xmain.id,
|
360
|
-
:runseq=> @runseq.id,
|
361
|
-
:filename=> params.original_filename,
|
362
|
-
:content_type => params.content_type || 'application/zip',
|
363
|
-
:data_text=> '',
|
364
|
-
:ma_display=>true, :ma_secured => @xmain.service.ma_secured )
|
365
|
-
if defined?(IMAGE_LOCATION)
|
366
|
-
filename = "#{IMAGE_LOCATION}/f#{Param.gen(:asset_id)}"
|
367
|
-
File.open(filename,"wb") { |f| f.write(params.read) }
|
368
|
-
eval "@xvars[@runseq.code][key][key1] = '#{url_for(:action=>'document', :id=>doc.id, :only_path => true)}' "
|
369
|
-
doc.update_attributes :url => filename, :basename => File.basename(filename), :cloudinary => false
|
370
|
-
else
|
371
|
-
result = Cloudinary::Uploader.upload(params)
|
372
|
-
eval %Q{ @xvars[@runseq.code][key][key1] = '#{result["url"]}' }
|
373
|
-
doc.update_attributes :url => result["url"], :basename => File.basename(result["url"]), :cloudinary => true
|
374
|
-
end
|
375
|
-
end
|
376
|
-
def doc_print
|
377
|
-
render :file=>'public/doc.html', :layout=>'layouts/print'
|
378
|
-
end
|
379
|
-
# generate documentation for application
|
380
|
-
def doc
|
381
|
-
require 'rdoc'
|
382
|
-
@app= get_app
|
383
|
-
@intro = File.read('README.md')
|
384
|
-
@print= "<div align='right'><img src='/assets/printer.png'/> <a href='/jinda/doc_print' target='_blank'/>Print</a></div>"
|
385
|
-
doc= render_to_string 'doc.md', :layout => false
|
386
|
-
html= Maruku.new(doc).to_html
|
387
|
-
File.open('public/doc.html','w') {|f| f.puts html }
|
388
|
-
respond_to do |format|
|
389
|
-
format.html {
|
390
|
-
render :plain=> @print+html, :layout => 'layouts/jqm/_page'
|
391
|
-
# render :text=> Maruku.new(doc).to_html, :layout => false
|
392
|
-
# format.html {
|
393
|
-
# h = RDoc::Markup::ToHtml.new
|
394
|
-
# render :text=> h.convert(doc), :layout => 'layouts/_page'
|
395
|
-
}
|
396
|
-
format.pdf {
|
397
|
-
latex= Maruku.new(doc).to_latex
|
398
|
-
File.open('tmp/doc.md','w') {|f| f.puts doc}
|
399
|
-
File.open('tmp/doc.tex','w') {|f| f.puts latex}
|
400
|
-
# system('pdflatex tmp/doc.tex ')
|
401
|
-
# send_file( 'tmp/doc.pdf', :type => ‘application/pdf’,
|
402
|
-
# :disposition => ‘inline’, :filename => 'doc.pdf')
|
403
|
-
render :plain=>'done'
|
404
|
-
}
|
405
|
-
end
|
406
|
-
end
|
407
|
-
# handle uploaded image
|
408
|
-
def document
|
409
|
-
doc = Jinda::Doc.find params[:id]
|
410
|
-
if doc.cloudinary
|
411
|
-
require 'net/http'
|
412
|
-
require "uri"
|
413
|
-
uri = URI.parse(doc.url)
|
414
|
-
data = Net::HTTP.get_response(uri)
|
415
|
-
send_data(data.body, :filename=>doc.filename, :type=>doc.content_type, :disposition=>"inline")
|
416
|
-
else
|
417
|
-
data= read_binary(doc.url)
|
418
|
-
send_data(data, :filename=>doc.filename, :type=>doc.content_type, :disposition=>"inline")
|
419
|
-
end
|
420
|
-
end
|
421
|
-
def status
|
422
|
-
@xmain= Jinda::Xmain.where(:xid=>params[:xid]).first
|
423
|
-
@title= "Task number #{params[:xid]} #{@xmain.name}"
|
424
|
-
@backbtn= true
|
425
|
-
@xvars= @xmain.xvars
|
426
|
-
# flash.now[:notice]= "รายการ #{@xmain.id} ได้ถูกยกเลิกแล้ว" if @xmain.status=='X'
|
427
|
-
ma_log "Task #{@xmain.id} is cancelled" if @xmain.status=='X'
|
428
|
-
# flash.now[:notice]= "transaction #{@xmain.id} was cancelled" if @xmain.status=='X'
|
429
|
-
rescue
|
430
|
-
refresh_to "/", :alert => "Could not find task number <b> #{params[:xid]} </b>"
|
431
|
-
end
|
432
|
-
def help
|
433
|
-
end
|
434
|
-
def search
|
435
|
-
@q = params[:q] || params[:ma_search][:q] || ""
|
436
|
-
@title = "ผลการค้นหา #{@q}"
|
437
|
-
@backbtn= true
|
438
|
-
@cache= true
|
439
|
-
if @q.blank?
|
440
|
-
redirect_to "/"
|
441
|
-
else
|
442
|
-
s= GmaSearch.create :q=>@q, :ip=> request.env["REMOTE_ADDR"]
|
443
|
-
do_search
|
444
|
-
end
|
445
|
-
end
|
446
|
-
def err404
|
447
|
-
# ma_log 'ERROR', 'main/err404'
|
448
|
-
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."
|
449
|
-
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."
|
450
|
-
redirect_to '/'
|
451
|
-
end
|
452
|
-
def err500
|
453
|
-
# ma_log 'ERROR', 'main/err500'
|
454
|
-
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."
|
455
|
-
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."
|
456
|
-
redirect_to '/'
|
457
|
-
end
|
458
|
-
|
459
|
-
private
|
460
|
-
def create_xmain(service)
|
461
|
-
c = name2camel(service.module.code)
|
462
|
-
custom_controller= "#{c}Controller"
|
463
|
-
params["return"] = request.env['HTTP_REFERER']
|
464
|
-
Jinda::Xmain.create :service=>service,
|
465
|
-
:start=>Time.now,
|
466
|
-
:name=>service.name,
|
467
|
-
:ip=> get_ip,
|
468
|
-
:status=>'I', # init
|
469
|
-
:user=>current_ma_user,
|
470
|
-
:xvars=> {
|
471
|
-
:service_id=>service.id,
|
472
|
-
:p=>params.to_unsafe_h,
|
473
|
-
:id=>params[:id],
|
474
|
-
:user_id=>current_ma_user.try(:id),
|
475
|
-
:custom_controller=>custom_controller,
|
476
|
-
:host=>request.host,
|
477
|
-
:referer=>request.env['HTTP_REFERER']
|
478
|
-
}
|
479
|
-
end
|
480
|
-
def create_runseq(xmain)
|
481
|
-
@xvars= xmain.xvars
|
482
|
-
default_role= get_default_role
|
483
|
-
xml= xmain.service.xml
|
484
|
-
root = REXML::Document.new(xml).root
|
485
|
-
i= 0; j= 0 # i= step, j= form_step
|
486
|
-
root.elements.each('node') do |activity|
|
487
|
-
text= activity.attributes['TEXT']
|
488
|
-
next if ma_comment?(text)
|
489
|
-
next if text =~/^rule:\s*/
|
490
|
-
action= freemind2action(activity.elements['icon'].attributes['BUILTIN']) if activity.elements['icon']
|
491
|
-
return false unless action
|
492
|
-
i= i + 1
|
493
|
-
output_ma_display= false
|
494
|
-
if action=='output'
|
495
|
-
ma_display= get_option_xml("ma_display", activity)
|
496
|
-
if ma_display && !affirm(ma_display)
|
497
|
-
output_ma_display= false
|
498
|
-
else
|
499
|
-
output_ma_display= true
|
500
|
-
end
|
501
|
-
end
|
502
|
-
j= j + 1 if (action=='form' || output_ma_display)
|
503
|
-
@xvars['referer'] = activity.attributes['TEXT'] if action=='redirect'
|
504
|
-
if action!= 'if'
|
505
|
-
scode, name= text.split(':', 2)
|
506
|
-
name ||= scode; name.strip!
|
507
|
-
code= name2code(scode)
|
508
|
-
else
|
509
|
-
code= text
|
510
|
-
name= text
|
511
|
-
end
|
512
|
-
role= get_option_xml("role", activity) || default_role
|
513
|
-
rule= get_option_xml("rule", activity) || "true"
|
514
|
-
runseq= Jinda::Runseq.create :xmain=>xmain.id,
|
515
|
-
:name=> name, :action=> action,
|
516
|
-
:code=> code, :role=>role.upcase, :rule=> rule,
|
517
|
-
:rstep=> i, :form_step=> j, :status=>'I',
|
518
|
-
:xml=>activity.to_s
|
519
|
-
xmain.current_runseq= runseq.id if i==1
|
520
|
-
end
|
521
|
-
@xvars['total_steps']= i
|
522
|
-
@xvars['total_form_steps']= j
|
523
|
-
end
|
524
|
-
def init_vars(xmain)
|
525
|
-
@xmain= Jinda::Xmain.find xmain
|
526
|
-
@xvars= @xmain.xvars
|
527
|
-
@runseq= @xmain.runseqs.find @xmain.current_runseq
|
528
|
-
# authorize?
|
529
|
-
@xvars['current_step']= @runseq.rstep
|
530
|
-
@xvars['referrer']= request.referrer
|
531
|
-
session[:xmain_id]= @xmain.id
|
532
|
-
session[:runseq_id]= @runseq.id
|
533
|
-
unless params[:action]=='run_call'
|
534
|
-
@runseq.start ||= Time.now
|
535
|
-
@runseq.status= 'R' # running
|
536
|
-
@runseq.save
|
537
|
-
end
|
538
|
-
$xmain= @xmain; $xvars= @xvars
|
539
|
-
$runseq_id= @runseq.id
|
540
|
-
$user_id= current_ma_user.try(:id)
|
541
|
-
end
|
542
|
-
def init_vars_by_runseq(runseq_id)
|
543
|
-
@runseq= Jinda::Runseq.find runseq_id
|
544
|
-
@xmain= @runseq.xmain
|
545
|
-
@xvars= @xmain.xvars
|
546
|
-
#@xvars[:current_step]= @runseq.rstep
|
547
|
-
@runseq.start ||= Time.now
|
548
|
-
@runseq.status= 'R' # running
|
549
|
-
@runseq.save
|
550
|
-
end
|
551
|
-
def store_asset
|
552
|
-
if params[:content]
|
553
|
-
doc = GmaDoc.create! :name=> 'asset',
|
554
|
-
:filename=> (params[:file_name]||''),
|
555
|
-
:content_type => (params[:content_type] || 'application/zip'),
|
556
|
-
:data_text=> '',
|
557
|
-
:ma_display=>true
|
558
|
-
path = (IMAGE_LOCATION || "tmp")
|
559
|
-
File.open("#{path}/f#{doc.id}","wb") { |f|
|
560
|
-
f.puts(params[:content])
|
561
|
-
}
|
562
|
-
render :xml=>"<elocal><doc id='#{doc.id}' /><success /></elocal>"
|
563
|
-
else
|
564
|
-
render :xml=>"<elocal><fail /></elocal>"
|
565
|
-
end
|
566
|
-
end
|
567
|
-
def do_search
|
568
|
-
if current_ma_user.ma_secured?
|
569
|
-
@docs = GmaDoc.search_ma_secured(@q.downcase, params[:page], PER_PAGE)
|
570
|
-
else
|
571
|
-
@docs = GmaDoc.search(@q.downcase, params[:page], PER_PAGE)
|
572
|
-
end
|
573
|
-
@xmains = GmaXmain.find(@docs.map(&:ma_xmain_id)).sort { |a,b| b.id<=>a.id }
|
574
|
-
# @xmains = GmaXmain.find @docs.map(&:created_at).sort { |a,b| b<=>a }
|
575
|
-
end
|
576
|
-
def read_binary(path)
|
577
|
-
File.open path, "rb" do |f| f.read end
|
578
|
-
end
|
579
65
|
end
|