jinda 0.5.1 → 0.5.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -3
  3. data/lib/generators/jinda/install_generator.rb +6 -0
  4. data/lib/generators/jinda/templates/README.md +1 -1
  5. data/lib/generators/jinda/templates/app/assets/stylesheets/app.scss +11 -5
  6. data/lib/generators/jinda/templates/app/assets/stylesheets/articles.scss +16 -6
  7. data/lib/generators/jinda/templates/app/controllers/concerns/jinda_general_concern.rb +179 -0
  8. data/lib/generators/jinda/templates/app/controllers/concerns/jinda_run_concern.rb +365 -0
  9. data/lib/generators/jinda/templates/app/controllers/jinda_org/docs_controller.rb +56 -0
  10. data/lib/generators/jinda/templates/app/controllers/jinda_org/jinda_controller.rb +29 -573
  11. data/lib/generators/jinda/templates/app/controllers/jinda_org/notes_controller.rb +6 -8
  12. data/lib/generators/jinda/templates/app/jinda/index.mm +71 -23
  13. data/lib/generators/jinda/templates/app/jinda/template/view.html.erb +22 -23
  14. data/lib/generators/jinda/templates/app/models/jinda/doc.rb +5 -0
  15. data/lib/generators/jinda/templates/app/views/articles/new_article/form_article.html.erb +5 -3
  16. data/lib/generators/jinda/templates/app/views/docs/doc_edit/doc_edit.html.erb +21 -0
  17. data/lib/generators/jinda/templates/app/views/docs/doc_edit/doc_select.html.erb +14 -0
  18. data/lib/generators/jinda/templates/app/views/docs/doc_new/doc_form.html.erb +26 -0
  19. data/lib/generators/jinda/templates/app/views/docs/doc_new/doc_form.md +36 -0
  20. data/lib/generators/jinda/templates/app/views/docs/doc_xedit/doc_edit.html.erb +21 -0
  21. data/lib/generators/jinda/templates/app/views/docs/edit/select_note.html.erb +14 -0
  22. data/lib/generators/jinda/templates/app/views/docs/index.haml +21 -0
  23. data/lib/generators/jinda/templates/app/views/docs/my.haml +27 -0
  24. data/lib/generators/jinda/templates/app/views/jinda/index.html.haml +3 -3
  25. data/lib/generators/jinda/templates/app/views/jinda/run_output.haml +3 -3
  26. data/lib/generators/jinda/templates/app/views/layouts/_head.html.erb +7 -10
  27. data/lib/generators/jinda/templates/app/views/layouts/{_metatag.html.erb → _meta_tag.html.erb} +0 -0
  28. data/lib/generators/jinda/templates/app/views/layouts/jqm/_full.haml +1 -9
  29. data/lib/generators/jinda/templates/app/views/notes/new/new_note.html.erb +1 -1
  30. data/lib/jinda/helpers.rb +201 -57
  31. data/lib/jinda/version.rb +1 -1
  32. metadata +16 -11
  33. data/lib/generators/jinda/templates/app/controllers/ctrs_controller.rb-gem-test +0 -2
  34. data/lib/generators/jinda/templates/app/views/layouts/_meta_tags.html.erb +0 -5
  35. data/lib/generators/jinda/templates/app/views/new.html.erb +0 -7
  36. data/lib/jinda/ template/view.html.erb +0 -25
  37. data/lib/jinda/app/jinda/index.mm +0 -308
  38. data/lib/jinda/app/jinda/template/view.html.erb +0 -27
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 86e26953c4782d41554c6d2d906ce58d2a2320ddfa49446d14920819fbd19990
4
- data.tar.gz: 6e4752ee8dcab6758bcb5d3640fcb5af993800bfa965c6a937ab794f0066d5d8
3
+ metadata.gz: b19ce89ffc7d0cc62a3694aa01206e6de1d04ae31c3204a8fd39ca7195593434
4
+ data.tar.gz: 425b20ce57cfba2d88b3eb9f578366bdb363594bde4e175f98e4a5106a38ba45
5
5
  SHA512:
6
- metadata.gz: c0ade9552fde2d3b14032f796845465cf591e70d8d906821301ada8f3e2e30456d9b2632cf7642663d1601e54d463d0ef848c78c8ed6a7eb94a48845d1605b56
7
- data.tar.gz: 59b9411947dbc7290dc94fb7b4f37700554507a8b910c01324b29012e359428999a911118212e0490e0fbf5e2dc10e79af8b9e89d64b56b796c118f2d5c4c07d
6
+ metadata.gz: 1380caefa23d4e6fc49053f55f40dcfd1e5b244efdebe101b7adfb48043bf0d8b57cfc6f2b5fa48dcd67f500d5e99a3574c75608cff9521d7b0a3643f6c093ef
7
+ data.tar.gz: 7fef8092499796b99418abef949dce07f3d61565dcdfd5a95525580a90ceefeea5c7c443e1a8b60588265cad164052a9b8bca74f1f2f85c6eb6b4c23a0477c3a
data/README.md CHANGED
@@ -14,8 +14,8 @@ Rails Application Generator using Freemind
14
14
 
15
15
  These versions works for sure but others may do.
16
16
 
17
- * Ruby 2.6.3
18
- * Rails 6.0.1
17
+ * Ruby 2.7.1
18
+ * Rails 6.0.3
19
19
  * MongoDB 6
20
20
  * Freemind 1.0.1
21
21
 
@@ -40,7 +40,7 @@ app without ActiveRecord
40
40
 
41
41
  ## Add jinda to your Gemfile:
42
42
 
43
- gem 'jinda', '~> 0.5.1'
43
+ gem 'jinda', '~> 0.5.6'
44
44
 
45
45
  For Development (most updated)
46
46
 
@@ -83,6 +83,7 @@ module Jinda
83
83
  inside("app/controllers") {(File.file? "admins_controller.rb") ? ( say "Please merge existing jinda_org/admins_controller.rb after this installation", :red) : (FileUtils.mv 'jinda_org/admins_controller.rb', 'admins_controller.rb')}
84
84
  inside("app/controllers") {(File.file? "articles_controller.rb") ? ( say "Please merge existing jinda_org/articles_controller.rb after this installation", :red) : (FileUtils.mv 'jinda_org/articles_controller.rb', 'articles_controller.rb')}
85
85
  inside("app/controllers") {(File.file? "comments_controller.rb") ? ( say "Please merge existing jinda_org/comments_controller.rb after this installation", :red) : (FileUtils.mv 'jinda_org/comments_controller.rb', 'comments_controller.rb')}
86
+ inside("app/controllers") {(File.file? "docs_controller.rb") ? ( say "Please merge existing jinda_org/docs_controller.rb after this installation", :red) : (FileUtils.mv 'jinda_org/docs_controller.rb', 'docs_controller.rb')}
86
87
  inside("app/controllers") {(File.file? "identities_controller.rb") ? ( say "Please merge existing jinda_org/identities_controller.rb after this installation", :red) : (FileUtils.mv 'jinda_org/identities_controller.rb', 'identities_controller.rb')}
87
88
  inside("app/controllers") {(File.file? "jinda_controller.rb") ? ( say "Please merge existing jinda_org/jinda_controller.rb after this installation", :red) : (FileUtils.mv 'jinda_org/jinda_controller.rb', 'jinda_controller.rb')}
88
89
  inside("app/controllers") {(File.file? "password_resets_controller.rb") ? ( say "Please merge existing jinda_org/password_resets_controller.rb after this installation", :red) : (FileUtils.mv 'jinda_org/password_resets_controller.rb', 'password_resets_controller.rb')}
@@ -107,11 +108,15 @@ module Jinda
107
108
  route "resources :sessions"
108
109
  route "resources :identities"
109
110
  route "resources :users"
111
+ route "resources :docs"
110
112
  route "resources :notes"
111
113
  route "resources :articles"
114
+ route "get '/jinda/document/:id' => 'jinda#document'"
112
115
  route "get '/notes/destroy/:id' => 'notes#destroy'"
113
116
  route "get '/notes/my/destroy/:id' => 'notes#destroy'"
117
+ route "get '/docs/my/destroy' => 'docs#destroy'"
114
118
  route "get '/notes/my' => 'notes/my'"
119
+ route "get '/docs/my' => 'docs/my'"
115
120
  route "get '/articles/my/destroy' => 'articles#destroy'"
116
121
  route "get '/articles/my' => 'articles/my'"
117
122
  route "get '/logout' => 'sessions#destroy', :as => 'logout'"
@@ -125,6 +130,7 @@ module Jinda
125
130
  route "post '/jinda/init' => 'jinda#init'"
126
131
  route "jinda_methods.each do \|aktion\| get \"/jinda/\#\{aktion\}\" => \"jinda#\#\{aktion\}\" end"
127
132
  route "jinda_methods += ['error_logs', 'notice_logs', 'cancel', 'run_output', 'end_output']"
133
+ route "jinda_methods += ['run_redirect', 'run_direct_to','run_if']"
128
134
  route "jinda_methods += ['init', 'run', 'run_mail', 'document', 'run_do', 'run_form', 'end_form']"
129
135
  route "jinda_methods = ['pending', 'status', 'search', 'doc', 'doc_print', 'logs', 'ajax_notice']"
130
136
  route "\# start jiinda method routes"
@@ -36,7 +36,7 @@ app without ActiveRecord
36
36
 
37
37
  ## Add jinda to your Gemfile:
38
38
 
39
- gem 'jinda', '~> 0.5.1'
39
+ gem 'jinda', '~> 0.5.3'
40
40
 
41
41
  For Development (most updated)
42
42
 
@@ -1,14 +1,19 @@
1
1
 
2
+ #article-title {
3
+ text-align: left;
4
+ font-family: 'TH SarabunPSK', Helvetica, Arial, sans-serif;
5
+ color:#333;
6
+ }
7
+
2
8
  #title {
3
9
  font-size: 14pt;
4
10
  font-weight: bold;
5
- text-align: center;
6
- background: #d2f0ff;
11
+ text-align: left;
7
12
  font-family: 'TH SarabunPSK', Helvetica, Arial, sans-serif;
8
13
  color:#333;
9
14
 
10
15
  }
11
- #text {
16
+ #text{
12
17
  font-size: 14pt;
13
18
  font-weight: bold;
14
19
  text-align:left;
@@ -41,7 +46,6 @@
41
46
  #table th {
42
47
  background-color: #bcecff;
43
48
  color:#333;
44
- ;
45
49
  width:100%;
46
50
  }
47
51
 
@@ -59,12 +63,14 @@
59
63
  font-family: 'TH SarabunPSK', Helvetica, Arial, sans-serif;
60
64
  /*font-size: 110%;*/
61
65
  }
62
- .ui-li .ui-btn-inner a.ui-link-inherit, .ui-li-static.ui-li { padding: 7px 75px 7px 15px; display: block; }
66
+ .ui-li .ui-btn-inner a.ui-link-inherit, .ui-li-static.ui-li { padding: 7px 75px 7px 7px; display: block; }
63
67
  .ui-link-inherit { font-family: 'TH SarabunPSK', Helvetica, Arial, sans-serif;}
64
68
  label.ui-input-text {
65
69
  font-family: 'TH SarabunPSK', Helvetica, Arial, sans-serif;
66
70
  /*font-size: 110%;*/
67
71
  text-shadow: none;
72
+ margin: 2% 2% 0 0;
73
+
68
74
  }
69
75
  label.ui-select {
70
76
  font-family: 'TH SarabunPSK', Helvetica, Arial, sans-serif;
@@ -1,16 +1,28 @@
1
1
 
2
- #article-title {
2
+
3
+ #article-table {
3
4
  font-size: 14pt;
4
5
  font-weight: bold;
5
- text-align: center;
6
- background: #d2f0ff;
6
+ text-align: left;
7
+ background:#f7f7f7;
7
8
  font-family: 'TH SarabunPSK', Helvetica, Arial, sans-serif;
9
+ padding:2px 5px;
8
10
  color:#333;
9
11
 
10
12
  }
11
- #article-text {
13
+
14
+ #article-title {
12
15
  font-size: 14pt;
13
16
  font-weight: bold;
17
+ text-align: left;
18
+ background:#f7f7f7;
19
+ font-family: 'TH SarabunPSK', Helvetica, Arial, sans-serif;
20
+ padding:2px 5px;
21
+ color:#333;
22
+
23
+ }
24
+ #article-text {
25
+ font-size: 8pt;
14
26
  text-align:left;
15
27
  border:1px solid #c1c1c1;
16
28
  background:#f7f7f7;
@@ -28,7 +40,6 @@
28
40
 
29
41
  #comment-body {
30
42
  font-size: 10pt;
31
- font-weight: bold;
32
43
  text-align:left;
33
44
  color:#333;
34
45
  }
@@ -41,7 +52,6 @@
41
52
  #article-table th {
42
53
  background-color: #bcecff;
43
54
  color:#333;
44
- ;
45
55
  width:100%;
46
56
  }
47
57
 
@@ -0,0 +1,179 @@
1
+ module JindaGeneralConcern
2
+ extend ActiveSupport::Concern
3
+
4
+ def index
5
+ end
6
+
7
+ def logs
8
+ @xmains = Jinda::Xmain.all.desc(:created_at).page(params[:page]).per(10)
9
+ end
10
+
11
+ def error_logs
12
+ @xmains = Jinda::Xmain.in(status:['E']).desc(:created_at).page(params[:page]).per(10)
13
+ end
14
+
15
+ def notice_logs
16
+ @notices= Jinda::Notice.desc(:created_at).page(params[:page]).per(10)
17
+ end
18
+
19
+ def pending
20
+ @title= "Pending Tasks"
21
+ @xmains = Jinda::Xmain.in(status:['R','I']).asc(:created_at)
22
+ end
23
+
24
+ def cancel
25
+ Jinda::Xmain.find(params[:id]).update_attributes :status=>'X'
26
+ if params[:return]
27
+ redirect_to params[:return]
28
+ else
29
+ redirect_to action:"pending"
30
+ end
31
+ end
32
+
33
+ # process images from first level
34
+ def get_image(key, params)
35
+ doc = Jinda::Doc.create(
36
+ :name=> key.to_s,
37
+ :xmain=> @xmain.id,
38
+ :runseq=> @runseq.id,
39
+ :filename=> params.original_filename,
40
+ :content_type => params.content_type || 'application/zip',
41
+ :data_text=> '',
42
+ :ma_display=>true,
43
+ :ma_secured => @xmain.service.ma_secured )
44
+ if defined?(IMAGE_LOCATION)
45
+ filename = "#{IMAGE_LOCATION}/f#{Param.gen(:asset_id)}"
46
+ File.open(filename,"wb") { |f| f.write(params.read) }
47
+ # File.open(filename,"wb") { |f| f.puts(params.read) }
48
+ eval "@xvars[@runseq.code][key] = '#{url_for(:action=>'document', :id=>doc.id, :only_path => true )}' "
49
+ doc.update_attributes :url => filename, :basename => File.basename(filename), :cloudinary => false
50
+ else
51
+ result = Cloudinary::Uploader.upload(params)
52
+ eval %Q{ @xvars[@runseq.code][key] = '#{result["url"]}' }
53
+ doc.update_attributes :url => result["url"], :basename => File.basename(result["url"]), :cloudinary => true
54
+ end
55
+ end
56
+
57
+ # process images from second level, e.g,, fields_for
58
+ # save uploaded file info to Doc
59
+ def get_image1(key, key1, params)
60
+ doc = Jinda::Doc.create(
61
+ :name=> "#{key}_#{key1}",
62
+ :xmain=> @xmain.id,
63
+ :runseq=> @runseq.id,
64
+ :filename=> params.original_filename,
65
+ :content_type => params.content_type || 'application/zip',
66
+ :data_text=> '',
67
+ :dscan=> '',
68
+ :description=>'',
69
+ :keywords=>'',
70
+ :category=>'',
71
+ :ma_display=>true, :ma_secured => @xmain.service.ma_secured )
72
+ if defined?(IMAGE_LOCATION)
73
+ filename = "#{IMAGE_LOCATION}/f#{Param.gen(:asset_id)}"
74
+ File.open(filename,"wb") { |f| f.write(params.read) }
75
+ eval "@xvars[@runseq.code][key][key1] = '#{url_for(:action=>'document', :id=>doc.id, :only_path => true)}' "
76
+ doc.update_attributes :url => filename,
77
+ :basename => File.basename(filename),
78
+ :cloudinary => false,
79
+ :dscan => @xvars[@runseq.code][key][key1],
80
+ :user_id => @xvars["user_id"]
81
+ else
82
+ result = Cloudinary::Uploader.upload(params)
83
+ eval %Q{ @xvars[@runseq.code][key][key1] = '#{result["url"]}' }
84
+ doc.update_attributes :url => result["url"], :basename => File.basename(result["url"]), :cloudinary => true, :dscan => @xvars[@runseq.code][key][key1]
85
+ end
86
+ end
87
+
88
+ def doc_print
89
+ render :file=>'public/doc.html', :layout=>'layouts/print'
90
+ end
91
+
92
+ # generate documentation for application
93
+ # search data from Doc
94
+ def document
95
+ doc = Jinda::Doc.find params[:id]
96
+ if doc.cloudinary
97
+ require 'net/http'
98
+ require "uri"
99
+ uri = URI.parse(doc.url)
100
+ data = Net::HTTP.get_response(uri)
101
+ send_data(data.body, :filename=>doc.filename, :type=>doc.content_type, :disposition=>"inline")
102
+ else
103
+ data= read_binary(doc.url)
104
+ send_data(data, :filename=>doc.filename, :type=>doc.content_type, :disposition=>"inline")
105
+ end
106
+ end
107
+
108
+ def doc
109
+ require 'rdoc'
110
+ @app= get_app
111
+ @intro = File.read('README.md')
112
+ @print= "<div align='right'><img src='/assets/printer.png'/> <a href='/jinda/doc_print' target='_blank'/>Print</a></div>"
113
+ doc= render_to_string 'doc.md', :layout => false
114
+ html= Maruku.new(doc).to_html
115
+ File.open('public/doc.html','w') {|f| f.puts html }
116
+ respond_to do |format|
117
+ format.html {
118
+ render :plain=> @print+html, :layout => 'layouts/jqm/_page'
119
+ # render :text=> Maruku.new(doc).to_html, :layout => false
120
+ # format.html {
121
+ # h = RDoc::Markup::ToHtml.new
122
+ # render :text=> h.convert(doc), :layout => 'layouts/_page'
123
+ }
124
+ format.pdf {
125
+ latex= Maruku.new(doc).to_latex
126
+ File.open('tmp/doc.md','w') {|f| f.puts doc}
127
+ File.open('tmp/doc.tex','w') {|f| f.puts latex}
128
+ # system('pdflatex tmp/doc.tex ')
129
+ # send_file( 'tmp/doc.pdf', :type => ‘application/pdf’,
130
+ # :disposition => ‘inline’, :filename => 'doc.pdf')
131
+ render :plain=>'done'
132
+ }
133
+ end
134
+ end
135
+
136
+ def status
137
+ @xmain= Jinda::Xmain.where(:xid=>params[:xid]).first
138
+ @title= "Task number #{params[:xid]} #{@xmain.name}"
139
+ @backbtn= true
140
+ @xvars= @xmain.xvars
141
+ # flash.now[:notice]= "รายการ #{@xmain.id} ได้ถูกยกเลิกแล้ว" if @xmain.status=='X'
142
+ ma_log "Task #{@xmain.id} is cancelled" if @xmain.status=='X'
143
+ # flash.now[:notice]= "transaction #{@xmain.id} was cancelled" if @xmain.status=='X'
144
+ rescue
145
+ refresh_to "/", :alert => "Could not find task number <b> #{params[:xid]} </b>"
146
+ end
147
+
148
+ def help
149
+ end
150
+
151
+ def search
152
+ @q = params[:q] || params[:ma_search][:q] || ""
153
+ @title = "Search Result #{@q}"
154
+ @backbtn= true
155
+ @cache= true
156
+ if @q.blank?
157
+ redirect_to "/"
158
+ else
159
+ s= GmaSearch.create :q=>@q, :ip=> request.env["REMOTE_ADDR"]
160
+ do_search
161
+ end
162
+ end
163
+
164
+ def err404
165
+ # ma_log 'ERROR', 'main/err404'
166
+ 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."
167
+ 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."
168
+ redirect_to '/'
169
+ end
170
+
171
+ def err500
172
+ # ma_log 'ERROR', 'main/err500'
173
+ 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."
174
+ 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."
175
+ redirect_to '/'
176
+ end
177
+
178
+ end
179
+
@@ -0,0 +1,365 @@
1
+ module JindaRunConcern
2
+ extend ActiveSupport::Concern
3
+
4
+ def run_form
5
+ init_vars(params[:id])
6
+ if authorize?
7
+ if ['F', 'X'].include? @xmain.status
8
+ redirect_to_root
9
+ else
10
+ service= @xmain.service
11
+ ###############################################################################################
12
+ # Run View Form f created template by jinda rake follow freemind mm file
13
+ ###############################################################################################
14
+ if service
15
+ @title= "Transaction ID #{@xmain.xid}: #{@xmain.name} / #{@runseq.name}"
16
+ fhelp= "app/views/#{service.module.code}/#{service.code}/#{@runseq.code}.md"
17
+ ###############################################################################################
18
+ # Check if help file available for this form
19
+ ###############################################################################################
20
+ @help = File.read(fhelp) if File.exists?(fhelp)
21
+ f= "app/views/#{service.module.code}/#{service.code}/#{@runseq.code}.html.erb"
22
+ if File.file?(f)
23
+ @ui= File.read(f)
24
+ else
25
+ # flash[:notice]= "Error: Can not find the view file for this controller"
26
+ ma_log "Error: Can not find the view file for this controller"
27
+ redirect_to_root
28
+ end
29
+ end
30
+ init_vars(params[:id])
31
+ end
32
+ else
33
+ redirect_to_root
34
+ end
35
+ end
36
+
37
+ def run_if
38
+ init_vars(params[:id])
39
+ condition= eval(@runseq.code).to_s
40
+ match_found= false
41
+ if condition
42
+ xml= REXML::Document.new(@runseq.xml).root
43
+ next_runseq= nil
44
+ text = xml.elements['//node/node'].attributes['TEXT']
45
+ match, name= text.split(':',2)
46
+ label= name2code(name.strip)
47
+ if condition==match
48
+ if label=="end"
49
+ @end_job= true
50
+ else
51
+ next_runseq= @xmain.runseqs.where(:code=> label, :action.ne=>'redirect').first
52
+ match_found= true if next_runseq
53
+ @runseq_not_f= false
54
+ end
55
+ end
56
+ end
57
+ unless match_found || @end_job
58
+ next_runseq= @xmain.runseqs.where( rstep:(@xvars['current_step']+1) ).first
59
+ end
60
+ end_action(next_runseq)
61
+ end
62
+
63
+ # redirect when finish last runseq
64
+ # eg: http://localhost:3000/notes/my
65
+ def run_direct_to
66
+ init_vars(params[:id])
67
+ next_runseq= @xmain.runseqs.where(:id.ne=>@runseq.id, :code=>@runseq.code).first
68
+ if !@runseq.code.blank?
69
+ @xvars['p']['return'] = @runseq.code
70
+ else
71
+ flash[:notice]= "Error: missing required forward path in Freemind"
72
+ ma_log "Error: require forward path in Freemind"
73
+ end
74
+ end_action(next_runseq)
75
+ end
76
+
77
+ def run_redirect
78
+ init_vars(params[:id])
79
+ # next_runseq= @xmain.runseqs.first :conditions=>["id != ? AND code = ?",@runseq.id, @runseq.code]
80
+ next_runseq= @xmain.runseqs.where(:id.ne=>@runseq.id, :code=>@runseq.code).first
81
+ @xmain.current_runseq= next_runseq.id
82
+ end_action(next_runseq)
83
+ end
84
+
85
+ # call controller to do the freemind task using Star symbol eg: Update
86
+ # not for run_form
87
+ def run_do
88
+ init_vars(params[:id])
89
+ @runseq.start ||= Time.now
90
+ @runseq.status= 'R' # running
91
+ $runseq_id= @runseq.id
92
+ $user_id= current_ma_user.try(:id)
93
+ # $xmain, $runseq, $user, $xvars, $ip from local
94
+ set_global
95
+ controller = Kernel.const_get(@xvars['custom_controller']).new
96
+ result = controller.send(@runseq.code)
97
+ # save local var to database
98
+ init_vars_by_runseq($runseq_id)
99
+ @xvars = $xvars
100
+ @xvars[@runseq.code.to_sym]= result.to_s
101
+ @xvars['current_step']= @runseq.rstep
102
+ @runseq.status= 'F' #finish
103
+ @runseq.stop= Time.now
104
+ @runseq.save
105
+ end_action
106
+ rescue => e
107
+ @xmain.status='E'
108
+ @xvars['error']= e.to_s+e.backtrace.to_s
109
+ @xmain.xvars= $xvars
110
+ @xmain.save
111
+ @runseq.status= 'F' #finish
112
+ @runseq.stop= Time.now
113
+ @runseq.save
114
+ refresh_to "/", :alert => "Sorry opeation error at #{@xmain.id} #{@xvars['error']}"
115
+ end
116
+
117
+ def run_list
118
+ init_vars(params[:id])
119
+ service= @xmain.service
120
+ # disp= get_option("display")
121
+ # disp = Nil or :"??????"
122
+ # get option from last node: rule, role, display
123
+ disp= get_option("display")
124
+ # change from Nil to false and string to true
125
+ ma_display = (disp && !affirm(disp)) ? false : true
126
+ # Todo check if file is available
127
+ # if service and file exist
128
+ # ma_display from disp of 3rd level node as rule, role, display
129
+ if service && !@runseq.code.blank?
130
+ f= "app/views/#{service.module.code}/#{service.code}/#{@runseq.code}.html.erb"
131
+ @ui= File.read(f)
132
+ if Jinda::Doc.where(:runseq_id=>@runseq.id).exists?
133
+ @doc= Jinda::Doc.where(:runseq_id=>@runseq.id).first
134
+ @doc.update_attributes :data_text=> render_to_string(:inline=>@ui, :layout=>"utf8"),
135
+ :xmain=>@xmain, :runseq=>@runseq, :user=>current_ma_user,
136
+ :ip=> get_ip, :service=>service, :ma_display=>ma_display,
137
+ :ma_secured => @xmain.service.ma_secured,
138
+ :filename => "#{@runseq.code}.html.erb"
139
+ else
140
+ @doc= Jinda::Doc.create :name=> @runseq.name,
141
+ :content_type=>"output", :data_text=> render_to_string(:inline=>@ui, :layout=>"utf8"),
142
+ :xmain=>@xmain, :runseq=>@runseq, :user=>current_ma_user,
143
+ :ip=> get_ip, :service=>service, :ma_display=>ma_display,
144
+ :ma_secured => @xmain.service.ma_secured,
145
+ :filename => "#{@runseq.code}.html.erb"
146
+ end
147
+ # @message = defined?(MSG_NEXT) ? MSG_NEXT : "Next &gt;"
148
+ @message = defined?(MSG_NEXT) ? MSG_NEXT : "Next >>"
149
+ @message = "Finish" if @runseq.end
150
+ ma_log("Todo defined?(NSG_NEXT : Next >>)")
151
+ eval "@xvars[@runseq.code] = url_for(:controller=>'jinda', :action=>'document', :id=>@doc.id)"
152
+ else
153
+ flash[:notice]= "Error: Can not find the view file for this controller"
154
+ ma_log "Error: Can not find the view file for this controller"
155
+ redirect_to_root
156
+ end
157
+ # Check if ma_display available
158
+ # ma_display= get_option("display")
159
+ # if not ma_display then no display both controller-view and content then end back to root
160
+ unless ma_display
161
+ end_action
162
+ end
163
+ # controller display from @ui
164
+ end
165
+
166
+ def run_folder
167
+ init_vars(params[:id])
168
+ service= @xmain.service
169
+ # disp= get_option("display")
170
+ # disp = Nil or :"??????"
171
+ disp= get_option("display")
172
+ ma_display = (disp && !affirm(disp)) ? false : true
173
+ # Todo check if file is available
174
+ # if service and file exist
175
+ if service && !@runseq.code.blank?
176
+ f= "app/views/#{service.module.code}/#{service.code}/#{@runseq.code}.html.erb"
177
+ @ui= File.read(f)
178
+ if Jinda::Doc.where(:runseq_id=>@runseq.id).exists?
179
+ @doc= Jinda::Doc.where(:runseq_id=>@runseq.id).first
180
+ @doc.update_attributes :data_text=> render_to_string(:inline=>@ui, :layout=>"utf8"),
181
+ :xmain=>@xmain, :runseq=>@runseq, :user=>current_ma_user,
182
+ :ip=> get_ip, :service=>service, :ma_display=>ma_display,
183
+ :ma_secured => @xmain.service.ma_secured,
184
+ :filename => "#{@runseq.code}.html.erb"
185
+ else
186
+ @doc= Jinda::Doc.create :name=> @runseq.name,
187
+ :content_type=>"output", :data_text=> render_to_string(:inline=>@ui, :layout=>"utf8"),
188
+ :xmain=>@xmain, :runseq=>@runseq, :user=>current_ma_user,
189
+ :ip=> get_ip, :service=>service, :ma_display=>ma_display,
190
+ :ma_secured => @xmain.service.ma_secured,
191
+ :filename => "#{@runseq.code}.html.erb"
192
+ end
193
+ # @message = defined?(MSG_NEXT) ? MSG_NEXT : "Next &gt;"
194
+ @message = defined?(MSG_NEXT) ? MSG_NEXT : "Next >>"
195
+ @message = "Finish" if @runseq.end
196
+ ma_log("Todo defined?(NSG_NEXT : Next >>)")
197
+ eval "@xvars[@runseq.code] = url_for(:controller=>'jinda', :action=>'document', :id=>@doc.id)"
198
+ else
199
+ flash[:notice]= "Error: Can not find the view file for this controller"
200
+ ma_log "Error: Can not find the view file for this controller"
201
+ redirect_to_root
202
+ end
203
+ # Check if ma_display available
204
+ # ma_display= get_option("display")
205
+ unless ma_display
206
+ end_action
207
+ end
208
+ # controller display from @ui
209
+ end
210
+
211
+ def run_output
212
+ init_vars(params[:id])
213
+ service= @xmain.service
214
+ # disp= get_option("display")
215
+ # disp = Nil or :"??????"
216
+ disp= get_option("display")
217
+ ma_display = (disp && !affirm(disp)) ? false : true
218
+ # Todo check if file is available
219
+ # if service and file exist
220
+ if service && !@runseq.code.blank?
221
+ f= "app/views/#{service.module.code}/#{service.code}/#{@runseq.code}.html.erb"
222
+ @ui= File.read(f)
223
+ if Jinda::Doc.where(:runseq_id=>@runseq.id).exists?
224
+ @doc= Jinda::Doc.where(:runseq_id=>@runseq.id).first
225
+ @doc.update_attributes :data_text=> render_to_string(:inline=>@ui, :layout=>"utf8"),
226
+ :xmain=>@xmain, :runseq=>@runseq, :user=>current_ma_user,
227
+ :ip=> get_ip, :service=>service, :ma_display=>ma_display,
228
+ :ma_secured => @xmain.service.ma_secured,
229
+ :filename => "#{@runseq.code}.html.erb"
230
+ else
231
+ @doc= Jinda::Doc.create :name=> @runseq.name,
232
+ :content_type=>"output", :data_text=> render_to_string(:inline=>@ui, :layout=>"utf8"),
233
+ :xmain=>@xmain, :runseq=>@runseq, :user=>current_ma_user,
234
+ :ip=> get_ip, :service=>service, :ma_display=>ma_display,
235
+ :ma_secured => @xmain.service.ma_secured,
236
+ :filename => "#{@runseq.code}.html.erb"
237
+ end
238
+ # @message = defined?(MSG_NEXT) ? MSG_NEXT : "Next &gt;"
239
+ @message = defined?(MSG_NEXT) ? MSG_NEXT : "Next >>"
240
+ @message = "Finish" if @runseq.end
241
+ ma_log("Todo defined?(NSG_NEXT : Next >>)")
242
+ eval "@xvars[@runseq.code] = url_for(:controller=>'jinda', :action=>'document', :id=>@doc.id)"
243
+ else
244
+ flash[:notice]= "Error: Can not find the view file for this controller"
245
+ ma_log "Error: Can not find the view file for this controller"
246
+ redirect_to_root
247
+ end
248
+ # Check if ma_display available
249
+ # ma_display= get_option("display")
250
+ unless ma_display
251
+ end_action
252
+ end
253
+ # controller display from @ui
254
+ end
255
+
256
+ def run_mail
257
+ init_vars(params[:id])
258
+ service= @xmain.service
259
+ f= "app/views/#{service.module.code}/#{service.code}/#{@runseq.code}.html.erb"
260
+ @ui= File.read(f).html_safe
261
+ @doc= Jinda::Doc.create :name=> @runseq.name,
262
+ :content_type=>"mail", :data_text=> render_to_string(:inline=>@ui, :layout=>false),
263
+ :xmain=>@xmain, :runseq=>@runseq, :user=>current_ma_user,
264
+ :ip=> get_ip, :service=>service, :ma_display=>false,
265
+ :ma_secured => @xmain.service.ma_secured
266
+ eval "@xvars[:#{@runseq.code}] = url_for(:controller=>'jinda', :action=>'document', :id=>@doc.id)"
267
+ mail_from = get_option('from')
268
+ # sender= render_to_string(:inline=>mail_from) if mail_from
269
+ mail_to = get_option('to')
270
+ recipients= render_to_string(:inline=>mail_to) if mail_to
271
+ mail_subject = get_option('subject')
272
+ subject= render_to_string(:inline=>mail_subject) || "#{@runseq.name}"
273
+ JindaMailer.gmail(@doc.data_text, recipients, subject).deliver unless DONT_SEND_MAIL
274
+ end_action
275
+ end
276
+
277
+ def end_output
278
+ init_vars(params[:xmain_id])
279
+ end_action
280
+ end
281
+
282
+ # Store params to @xvars[@runseq]
283
+ # Perform task from the form input eg: attach file
284
+ # replace end_action (for form)
285
+ # Store params attach file to @xvars to use in get_image
286
+ def end_form
287
+ if params[:xmain_id]
288
+ init_vars(params[:xmain_id])
289
+ else
290
+ ma_log "Known Bug : repeated end_form "
291
+ redirect_to_root and return
292
+ end
293
+ eval "@xvars[@runseq.code] = {} unless @xvars[@runseq.code]"
294
+ # Search for uploaded file name if exist
295
+ params.each { |k,v|
296
+ if params[k].respond_to? :original_filename
297
+ get_image(k, params[k])
298
+ # check if params of array in form eg: edit_article
299
+ elsif params[k].is_a?(ActionController::Parameters)
300
+ eval "@xvars[@runseq.code][k] = {} unless @xvars[@runseq.code][k]"
301
+ params[k].each { |k1,v1|
302
+ # eval "@xvars[@runseq.code][k1] = params.require(k1).permit(k1)"
303
+ eval "@xvars[@runseq.code][k][k1] = v1"
304
+ next unless v1.respond_to?(:original_filename)
305
+ doc = {}
306
+ get_image1(k, k1, params[k][k1])
307
+ }
308
+ else
309
+ # No file attached
310
+ #
311
+ # https://stackoverflow.com/questions/34949505/rails-5-unable-to- retrieve-hash-values-from-parameter # bug in to_unsalfe_h rails 5.1.6 https://github.com/getsentry/raven-ruby/issues/799
312
+ # Solution:
313
+ # https://stackoverflow.com/questions/34949505/rails-5-unable-to-retrieve-hash-values-from-parameter
314
+ # v = v.to_unsafe_h unless v.class == String
315
+ # v = params.require[k] unless v.class == String
316
+ v = v.to_s unless v.class == String
317
+ # Create @xvars[@runseq.code]
318
+ eval "@xvars[@runseq.code][k] = v"
319
+ end
320
+ }
321
+ end_action
322
+ rescue => e
323
+ @xmain.status='E'
324
+ @xvars['error']= e.to_s+e.backtrace.to_s
325
+ @xmain.xvars= $xvars
326
+ @xmain.save
327
+ @runseq.status= 'F' #finish
328
+ @runseq.stop= Time.now
329
+ @runseq.save
330
+ ma_log "Error:end_form "
331
+ refresh_to "/", :alert => "Sorry opeation error at #{@xmain.id} #{@xvars['error']}"
332
+ end
333
+
334
+ def end_action(next_runseq = nil)
335
+ # not for form
336
+ # @runseq.status='F' unless @runseq_not_f
337
+ @xmain.xvars= @xvars
338
+ @xmain.status= 'R' # running
339
+ @xmain.save!
340
+ @runseq.status='F'
341
+ @runseq.user= current_ma_user
342
+ @runseq.stop= Time.now
343
+ @runseq.save
344
+ next_runseq= @xmain.runseqs.where(:rstep=> @runseq.rstep+1).first unless next_runseq
345
+ if @end_job || !next_runseq # job finish
346
+ @xmain.xvars= @xvars
347
+ @xmain.status= 'F' unless @xmain.status== 'E' # finish
348
+ @xmain.stop= Time.now
349
+ @xmain.save
350
+ if @xvars['p']['return']
351
+ redirect_to @xvars['p']['return'] and return
352
+ else
353
+ if @user
354
+ redirect_to :action=>'index' and return
355
+ else
356
+ redirect_to_root and return
357
+ end
358
+ end
359
+ else
360
+ @xmain.update_attribute :current_runseq, next_runseq.id
361
+ redirect_to :action=>'run', :id=>@xmain.id and return
362
+ end
363
+ end
364
+
365
+ end