jinda 0.4.9 → 0.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -3
  3. data/lib/generators/jinda/install_generator.rb +13 -6
  4. data/lib/generators/jinda/templates/README.md +3 -3
  5. data/lib/generators/jinda/templates/app/assets/javascripts/{disable_enter_key.js-org → disable_enter_key.js} +0 -0
  6. data/lib/generators/jinda/templates/app/assets/stylesheets/modules.scss +84 -0
  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 +351 -0
  9. data/lib/generators/jinda/templates/app/controllers/jinda_org/docs_controller.rb +55 -0
  10. data/lib/generators/jinda/templates/app/controllers/jinda_org/jinda_controller.rb +30 -544
  11. data/lib/generators/jinda/templates/app/controllers/jinda_org/notes_controller.rb +4 -7
  12. data/lib/generators/jinda/templates/app/jinda/index.mm +55 -15
  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 +31 -17
  15. data/lib/generators/jinda/templates/app/views/docs/doc_edit/doc_edit.html.erb +21 -0
  16. data/lib/generators/jinda/templates/app/views/docs/doc_edit/doc_select.html.erb +14 -0
  17. data/lib/generators/jinda/templates/app/views/docs/doc_new/doc_form.html.erb +26 -0
  18. data/lib/generators/jinda/templates/app/views/docs/doc_new/doc_form.md +36 -0
  19. data/lib/generators/jinda/templates/app/views/docs/doc_xedit/doc_edit.html.erb +21 -0
  20. data/lib/generators/jinda/templates/app/views/docs/edit/select_note.html.erb +14 -0
  21. data/lib/generators/jinda/templates/app/views/docs/index.haml +21 -0
  22. data/lib/generators/jinda/templates/app/views/docs/my.haml +27 -0
  23. data/lib/generators/jinda/templates/app/views/jinda/index.html.haml +3 -3
  24. data/lib/generators/jinda/templates/app/views/jinda/run_output.haml +3 -3
  25. data/lib/generators/jinda/templates/app/views/notes/my.haml +1 -1
  26. data/lib/jinda/helpers.rb +208 -59
  27. data/lib/jinda/version.rb +1 -1
  28. metadata +17 -8
  29. data/lib/generators/jinda/templates/app/controllers/ctrs_controller.rb-gem-test +0 -2
  30. data/lib/jinda/ template/view.html.erb +0 -25
  31. 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: 042bb6fc61b659ff7b4a49552b2b12235d78f5330d87f45d41c372a4babd13da
4
- data.tar.gz: a7e2f7d48ff8586ae259d58f182e0508c18c16f2f00ea36ad333e8ed6a85c16e
3
+ metadata.gz: a17b43b4b898dae67bb7c0f10f5ac9b0b4dc804b4d724a98de77575aff7a6122
4
+ data.tar.gz: e9e61b49a95d6a88ded3051d4b2f9f55d74fca6be0ee8f07b99f3103bd3e4d6d
5
5
  SHA512:
6
- metadata.gz: 2463085a390a255b882fc7e0f3fe4107a079d13bbbc65988ee3148a4934dbf636e4a1d11dea8ae2c224c40144fec6fce585965e5b2c339b0b684e0e60207ef95
7
- data.tar.gz: 58406a110bf6c497f6355e0673bc73b26da51bc12d39909c868cdee4b73fb4d3b5717abc5cdfb3ad63bb89ca16490bc2f403bb0517a4f34b758d7a67aa141235
6
+ metadata.gz: 8490aa2e9ef93bdd6b7fadfd6a49fbdf53b4799e11b1b3f26de526b6e4d06aaf83f82cb22081c885951c2097c5e4fbd68241413bc3a55d1e2c3d81afc694d896
7
+ data.tar.gz: a29f70fc72a7785a8997720e9231aed38ba145fee7e17fccc5fdbb83af99404c7e912f397129eb656b45f0909eea209f7e35ed0a8f879d0b3415422112d560e6
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.4.9'
43
+ gem 'jinda', '~> 0.5.4'
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')}
@@ -92,9 +93,9 @@ module Jinda
92
93
  inside("app/controllers") {(File.file? "sitemap_controller.rb") ? ( say "Please merge existing jinda_org/sitemap_controller.rb after this installation", :red) : (FileUtils.mv 'jinda_org/sitemap_controller.rb', 'sitemap_controller.rb')}
93
94
  inside("app/controllers") {(File.file? "notes_controller.rb") ? ( say "Please merge existing jinda_org/notes_controller.rb after this installation", :red) : (FileUtils.mv 'jinda_org/notes_controller.rb', 'notes_controller.rb')}
94
95
  end
95
- # routes created each line as reversed order button up in routes
96
+ # routes created each line as reversed order in routes
96
97
  def setup_routes
97
- route "end"
98
+ # route "end"
98
99
  route " end"
99
100
  route " namespace :v1 do resources :notes, :only => [:index] end"
100
101
  route " namespace :api do"
@@ -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'"
@@ -119,14 +124,16 @@ module Jinda
119
124
  route "get '/auth/:provider/callback' => 'sessions#create'"
120
125
  route "post '/auth/:provider/callback' => 'sessions#create'"
121
126
  route "\# end jinda method routes"
127
+ route "post '/jinda/end_output' => 'jinda#end_output'"
122
128
  route "post '/jinda/end_form' => 'jinda#end_form'"
123
129
  route "post '/jinda/pending' => 'jinda#index'"
124
130
  route "post '/jinda/init' => 'jinda#init'"
125
131
  route "jinda_methods.each do \|aktion\| get \"/jinda/\#\{aktion\}\" => \"jinda#\#\{aktion\}\" end"
126
- route "jinda_methods += ['init','run','run_mail','document','run_do','run_form','end_form','error_logs', 'notice_logs', 'cancel']"
127
- route "jinda_methods = ['pending','status','search','doc','logs','ajax_notice']"
132
+ route "jinda_methods += ['error_logs', 'notice_logs', 'cancel', 'run_output', 'end_output']"
133
+ route "jinda_methods += ['init', 'run', 'run_mail', 'document', 'run_do', 'run_form', 'end_form']"
134
+ route "jinda_methods = ['pending', 'status', 'search', 'doc', 'doc_print', 'logs', 'ajax_notice']"
128
135
  route "\# start jiinda method routes"
129
- end
136
+ end
130
137
 
131
138
  def setup_env
132
139
  FileUtils.mv "README.md", "README.md.bak"
@@ -148,7 +155,7 @@ module Jinda
148
155
  end
149
156
 
150
157
  # config time zone
151
- # config.time_zone = "Central Time (US & Canada)"
158
+ config.time_zone = "Central Time (US & Canada)"
152
159
 
153
160
  # gmail config
154
161
  # config.action_mailer.delivery_method = :smtp
@@ -15,8 +15,8 @@ Rails Application Generator using Freemind
15
15
 
16
16
  These versions works for sure but others may do.
17
17
 
18
- * Ruby 2.5.5
19
- * Rails 5.2.3
18
+ * Ruby 2.7.0
19
+ * Rails 6.0.2
20
20
  * MongoDB 6
21
21
  * Freemind 1.0.1
22
22
 
@@ -36,7 +36,7 @@ app without ActiveRecord
36
36
 
37
37
  ## Add jinda to your Gemfile:
38
38
 
39
- gem 'jinda', '~> 0.3.9'
39
+ gem 'jinda', '~> 0.5.3'
40
40
 
41
41
  For Development (most updated)
42
42
 
@@ -0,0 +1,84 @@
1
+
2
+ .module-title {
3
+ font-size: 14pt;
4
+ font-weight: bold;
5
+ text-align: center;
6
+ background: #d2f0ff;
7
+ font-family: 'TH SarabunPSK', Helvetica, Arial, sans-serif;
8
+ color:#333;
9
+
10
+ }
11
+ .module-text {
12
+ font-size: 14pt;
13
+ font-weight: bold;
14
+ text-align:left;
15
+ border:1px solid #c1c1c1;
16
+ background:#f7f7f7;
17
+ padding:2px 5px;
18
+ color:#333;
19
+ }
20
+ .module-comment {
21
+ font-size: 8pt;
22
+ text-align:left;
23
+ border:1px solid #c1c1c1;
24
+ background:#f7f7f7;
25
+ padding:2px 5px;
26
+ color:#333;
27
+ }
28
+
29
+ .comment-body {
30
+ font-size: 10pt;
31
+ font-weight: bold;
32
+ text-align:left;
33
+ color:#333;
34
+ }
35
+ .module-table {
36
+ width:100%;
37
+ font-family: 'TH SarabunPSK', Helvetica, Arial, sans-serif;
38
+
39
+ }
40
+
41
+ .module-table th {
42
+ background-color: #bcecff;
43
+ color:#333;
44
+ ;
45
+ width:100%;
46
+ }
47
+
48
+ .module-table td {
49
+ border: 1px;
50
+ padding: 8px;
51
+ witdth:100%;
52
+ }
53
+
54
+
55
+ .ui-btn-inner { padding: 2px 25px; }
56
+ .ui-btn-up-c,
57
+ .ui-btn-hover-c,
58
+ .ui-btn-down-c {
59
+ font-family: 'TH SarabunPSK', Helvetica, Arial, sans-serif;
60
+ /*font-size: 110%;*/
61
+ }
62
+ .ui-li .ui-btn-inner a.ui-link-inherit, .ui-li-static.ui-li { padding: 7px 75px 7px 15px; display: block; }
63
+ .ui-link-inherit { font-family: 'TH SarabunPSK', Helvetica, Arial, sans-serif;}
64
+ label.ui-input-text {
65
+ font-family: 'TH SarabunPSK', Helvetica, Arial, sans-serif;
66
+ /*font-size: 110%;*/
67
+ text-shadow: none;
68
+ }
69
+ label.ui-select {
70
+ font-family: 'TH SarabunPSK', Helvetica, Arial, sans-serif;
71
+ /*font-size: 110%;*/
72
+ text-shadow: none;
73
+ }
74
+ .ui-body-c {
75
+ font-family: 'TH SarabunPSK', Helvetica, Arial, sans-serif;
76
+ /*font-size: 1.4em;*/
77
+ text-shadow: none;
78
+ }
79
+ .ui-header .ui-title, .ui-footer .ui-title { font-family: 'TH SarabunPSK'; text-align: center; display: block; margin: .2em 90px .3em; padding: 0; text-overflow: ellipsis; overflow: hidden; white-space: nowrap; outline: 0 !important; }
80
+
81
+
82
+
83
+
84
+
@@ -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,351 @@
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
+ def run_redirect
64
+ init_vars(params[:id])
65
+ # next_runseq= @xmain.runseqs.first :conditions=>["id != ? AND code = ?",@runseq.id, @runseq.code]
66
+ next_runseq= @xmain.runseqs.where(:id.ne=>@runseq.id, :code=>@runseq.code).first
67
+ @xmain.current_runseq= next_runseq.id
68
+ end_action(next_runseq)
69
+ end
70
+
71
+ # call controller to do the freemind task using Star symbol eg: Update
72
+ # not for run_form
73
+ def run_do
74
+ init_vars(params[:id])
75
+ @runseq.start ||= Time.now
76
+ @runseq.status= 'R' # running
77
+ $runseq_id= @runseq.id
78
+ $user_id= current_ma_user.try(:id)
79
+ # $xmain, $runseq, $user, $xvars, $ip from local
80
+ set_global
81
+ controller = Kernel.const_get(@xvars['custom_controller']).new
82
+ result = controller.send(@runseq.code)
83
+ # save local var to database
84
+ init_vars_by_runseq($runseq_id)
85
+ @xvars = $xvars
86
+ @xvars[@runseq.code.to_sym]= result.to_s
87
+ @xvars['current_step']= @runseq.rstep
88
+ @runseq.status= 'F' #finish
89
+ @runseq.stop= Time.now
90
+ @runseq.save
91
+ end_action
92
+ rescue => e
93
+ @xmain.status='E'
94
+ @xvars['error']= e.to_s+e.backtrace.to_s
95
+ @xmain.xvars= $xvars
96
+ @xmain.save
97
+ @runseq.status= 'F' #finish
98
+ @runseq.stop= Time.now
99
+ @runseq.save
100
+ refresh_to "/", :alert => "Sorry opeation error at #{@xmain.id} #{@xvars['error']}"
101
+ end
102
+
103
+ def run_list
104
+ init_vars(params[:id])
105
+ service= @xmain.service
106
+ # disp= get_option("display")
107
+ # disp = Nil or :"??????"
108
+ # get option from last node: rule, role, display
109
+ disp= get_option("display")
110
+ # change from Nil to false and string to true
111
+ ma_display = (disp && !affirm(disp)) ? false : true
112
+ # Todo check if file is available
113
+ # if service and file exist
114
+ # ma_display from disp of 3rd level node as rule, role, display
115
+ if service && !@runseq.code.blank?
116
+ f= "app/views/#{service.module.code}/#{service.code}/#{@runseq.code}.html.erb"
117
+ @ui= File.read(f)
118
+ if Jinda::Doc.where(:runseq_id=>@runseq.id).exists?
119
+ @doc= Jinda::Doc.where(:runseq_id=>@runseq.id).first
120
+ @doc.update_attributes :data_text=> render_to_string(:inline=>@ui, :layout=>"utf8"),
121
+ :xmain=>@xmain, :runseq=>@runseq, :user=>current_ma_user,
122
+ :ip=> get_ip, :service=>service, :ma_display=>ma_display,
123
+ :ma_secured => @xmain.service.ma_secured,
124
+ :filename => "#{@runseq.code}.html.erb"
125
+ else
126
+ @doc= Jinda::Doc.create :name=> @runseq.name,
127
+ :content_type=>"output", :data_text=> render_to_string(:inline=>@ui, :layout=>"utf8"),
128
+ :xmain=>@xmain, :runseq=>@runseq, :user=>current_ma_user,
129
+ :ip=> get_ip, :service=>service, :ma_display=>ma_display,
130
+ :ma_secured => @xmain.service.ma_secured,
131
+ :filename => "#{@runseq.code}.html.erb"
132
+ end
133
+ # @message = defined?(MSG_NEXT) ? MSG_NEXT : "Next &gt;"
134
+ @message = defined?(MSG_NEXT) ? MSG_NEXT : "Next >>"
135
+ @message = "Finish" if @runseq.end
136
+ ma_log("Todo defined?(NSG_NEXT : Next >>)")
137
+ eval "@xvars[@runseq.code] = url_for(:controller=>'jinda', :action=>'document', :id=>@doc.id)"
138
+ else
139
+ flash[:notice]= "Error: Can not find the view file for this controller"
140
+ ma_log "Error: Can not find the view file for this controller"
141
+ redirect_to_root
142
+ end
143
+ # Check if ma_display available
144
+ # ma_display= get_option("display")
145
+ # if not ma_display then no display both controller-view and content then end back to root
146
+ unless ma_display
147
+ end_action
148
+ end
149
+ # controller display from @ui
150
+ end
151
+
152
+ def run_folder
153
+ init_vars(params[:id])
154
+ service= @xmain.service
155
+ # disp= get_option("display")
156
+ # disp = Nil or :"??????"
157
+ disp= get_option("display")
158
+ ma_display = (disp && !affirm(disp)) ? false : true
159
+ # Todo check if file is available
160
+ # if service and file exist
161
+ if service && !@runseq.code.blank?
162
+ f= "app/views/#{service.module.code}/#{service.code}/#{@runseq.code}.html.erb"
163
+ @ui= File.read(f)
164
+ if Jinda::Doc.where(:runseq_id=>@runseq.id).exists?
165
+ @doc= Jinda::Doc.where(:runseq_id=>@runseq.id).first
166
+ @doc.update_attributes :data_text=> render_to_string(:inline=>@ui, :layout=>"utf8"),
167
+ :xmain=>@xmain, :runseq=>@runseq, :user=>current_ma_user,
168
+ :ip=> get_ip, :service=>service, :ma_display=>ma_display,
169
+ :ma_secured => @xmain.service.ma_secured,
170
+ :filename => "#{@runseq.code}.html.erb"
171
+ else
172
+ @doc= Jinda::Doc.create :name=> @runseq.name,
173
+ :content_type=>"output", :data_text=> render_to_string(:inline=>@ui, :layout=>"utf8"),
174
+ :xmain=>@xmain, :runseq=>@runseq, :user=>current_ma_user,
175
+ :ip=> get_ip, :service=>service, :ma_display=>ma_display,
176
+ :ma_secured => @xmain.service.ma_secured,
177
+ :filename => "#{@runseq.code}.html.erb"
178
+ end
179
+ # @message = defined?(MSG_NEXT) ? MSG_NEXT : "Next &gt;"
180
+ @message = defined?(MSG_NEXT) ? MSG_NEXT : "Next >>"
181
+ @message = "Finish" if @runseq.end
182
+ ma_log("Todo defined?(NSG_NEXT : Next >>)")
183
+ eval "@xvars[@runseq.code] = url_for(:controller=>'jinda', :action=>'document', :id=>@doc.id)"
184
+ else
185
+ flash[:notice]= "Error: Can not find the view file for this controller"
186
+ ma_log "Error: Can not find the view file for this controller"
187
+ redirect_to_root
188
+ end
189
+ # Check if ma_display available
190
+ # ma_display= get_option("display")
191
+ unless ma_display
192
+ end_action
193
+ end
194
+ # controller display from @ui
195
+ end
196
+
197
+ def run_output
198
+ init_vars(params[:id])
199
+ service= @xmain.service
200
+ # disp= get_option("display")
201
+ # disp = Nil or :"??????"
202
+ disp= get_option("display")
203
+ ma_display = (disp && !affirm(disp)) ? false : true
204
+ # Todo check if file is available
205
+ # if service and file exist
206
+ if service && !@runseq.code.blank?
207
+ f= "app/views/#{service.module.code}/#{service.code}/#{@runseq.code}.html.erb"
208
+ @ui= File.read(f)
209
+ if Jinda::Doc.where(:runseq_id=>@runseq.id).exists?
210
+ @doc= Jinda::Doc.where(:runseq_id=>@runseq.id).first
211
+ @doc.update_attributes :data_text=> render_to_string(:inline=>@ui, :layout=>"utf8"),
212
+ :xmain=>@xmain, :runseq=>@runseq, :user=>current_ma_user,
213
+ :ip=> get_ip, :service=>service, :ma_display=>ma_display,
214
+ :ma_secured => @xmain.service.ma_secured,
215
+ :filename => "#{@runseq.code}.html.erb"
216
+ else
217
+ @doc= Jinda::Doc.create :name=> @runseq.name,
218
+ :content_type=>"output", :data_text=> render_to_string(:inline=>@ui, :layout=>"utf8"),
219
+ :xmain=>@xmain, :runseq=>@runseq, :user=>current_ma_user,
220
+ :ip=> get_ip, :service=>service, :ma_display=>ma_display,
221
+ :ma_secured => @xmain.service.ma_secured,
222
+ :filename => "#{@runseq.code}.html.erb"
223
+ end
224
+ # @message = defined?(MSG_NEXT) ? MSG_NEXT : "Next &gt;"
225
+ @message = defined?(MSG_NEXT) ? MSG_NEXT : "Next >>"
226
+ @message = "Finish" if @runseq.end
227
+ ma_log("Todo defined?(NSG_NEXT : Next >>)")
228
+ eval "@xvars[@runseq.code] = url_for(:controller=>'jinda', :action=>'document', :id=>@doc.id)"
229
+ else
230
+ flash[:notice]= "Error: Can not find the view file for this controller"
231
+ ma_log "Error: Can not find the view file for this controller"
232
+ redirect_to_root
233
+ end
234
+ # Check if ma_display available
235
+ # ma_display= get_option("display")
236
+ unless ma_display
237
+ end_action
238
+ end
239
+ # controller display from @ui
240
+ end
241
+
242
+ def run_mail
243
+ init_vars(params[:id])
244
+ service= @xmain.service
245
+ f= "app/views/#{service.module.code}/#{service.code}/#{@runseq.code}.html.erb"
246
+ @ui= File.read(f).html_safe
247
+ @doc= Jinda::Doc.create :name=> @runseq.name,
248
+ :content_type=>"mail", :data_text=> render_to_string(:inline=>@ui, :layout=>false),
249
+ :xmain=>@xmain, :runseq=>@runseq, :user=>current_ma_user,
250
+ :ip=> get_ip, :service=>service, :ma_display=>false,
251
+ :ma_secured => @xmain.service.ma_secured
252
+ eval "@xvars[:#{@runseq.code}] = url_for(:controller=>'jinda', :action=>'document', :id=>@doc.id)"
253
+ mail_from = get_option('from')
254
+ # sender= render_to_string(:inline=>mail_from) if mail_from
255
+ mail_to = get_option('to')
256
+ recipients= render_to_string(:inline=>mail_to) if mail_to
257
+ mail_subject = get_option('subject')
258
+ subject= render_to_string(:inline=>mail_subject) || "#{@runseq.name}"
259
+ JindaMailer.gmail(@doc.data_text, recipients, subject).deliver unless DONT_SEND_MAIL
260
+ end_action
261
+ end
262
+
263
+ def end_output
264
+ init_vars(params[:xmain_id])
265
+ end_action
266
+ end
267
+
268
+ # Store params to @xvars[@runseq]
269
+ # Perform task from the form input eg: attach file
270
+ # replace end_action (for form)
271
+ # Store params attach file to @xvars to use in get_image
272
+ def end_form
273
+ if params[:xmain_id]
274
+ init_vars(params[:xmain_id])
275
+ else
276
+ ma_log "Known Bug : repeated end_form "
277
+ redirect_to_root and return
278
+ end
279
+ eval "@xvars[@runseq.code] = {} unless @xvars[@runseq.code]"
280
+ # Search for uploaded file name if exist
281
+ params.each { |k,v|
282
+ if params[k].respond_to? :original_filename
283
+ get_image(k, params[k])
284
+ # check if params of array in form eg: edit_article
285
+ elsif params[k].is_a?(ActionController::Parameters)
286
+ eval "@xvars[@runseq.code][k] = {} unless @xvars[@runseq.code][k]"
287
+ params[k].each { |k1,v1|
288
+ # eval "@xvars[@runseq.code][k1] = params.require(k1).permit(k1)"
289
+ eval "@xvars[@runseq.code][k][k1] = v1"
290
+ next unless v1.respond_to?(:original_filename)
291
+ doc = {}
292
+ get_image1(k, k1, params[k][k1])
293
+ }
294
+ else
295
+ # No file attached
296
+ #
297
+ # 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
298
+ # Solution:
299
+ # https://stackoverflow.com/questions/34949505/rails-5-unable-to-retrieve-hash-values-from-parameter
300
+ # v = v.to_unsafe_h unless v.class == String
301
+ # v = params.require[k] unless v.class == String
302
+ v = v.to_s unless v.class == String
303
+ # Create @xvars[@runseq.code]
304
+ eval "@xvars[@runseq.code][k] = v"
305
+ end
306
+ }
307
+ end_action
308
+ rescue => e
309
+ @xmain.status='E'
310
+ @xvars['error']= e.to_s+e.backtrace.to_s
311
+ @xmain.xvars= $xvars
312
+ @xmain.save
313
+ @runseq.status= 'F' #finish
314
+ @runseq.stop= Time.now
315
+ @runseq.save
316
+ ma_log "Error:end_form "
317
+ refresh_to "/", :alert => "Sorry opeation error at #{@xmain.id} #{@xvars['error']}"
318
+ end
319
+
320
+ def end_action(next_runseq = nil)
321
+ # not for form
322
+ # @runseq.status='F' unless @runseq_not_f
323
+ @xmain.xvars= @xvars
324
+ @xmain.status= 'R' # running
325
+ @xmain.save!
326
+ @runseq.status='F'
327
+ @runseq.user= current_ma_user
328
+ @runseq.stop= Time.now
329
+ @runseq.save
330
+ next_runseq= @xmain.runseqs.where(:rstep=> @runseq.rstep+1).first unless next_runseq
331
+ if @end_job || !next_runseq # job finish
332
+ @xmain.xvars= @xvars
333
+ @xmain.status= 'F' unless @xmain.status== 'E' # finish
334
+ @xmain.stop= Time.now
335
+ @xmain.save
336
+ if @xvars['p']['return']
337
+ redirect_to @xvars['p']['return'] and return
338
+ else
339
+ if @user
340
+ redirect_to :action=>'index' and return
341
+ else
342
+ redirect_to_root and return
343
+ end
344
+ end
345
+ else
346
+ @xmain.update_attribute :current_runseq, next_runseq.id
347
+ redirect_to :action=>'run', :id=>@xmain.id and return
348
+ end
349
+ end
350
+
351
+ end