rbbt-views 0.1.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (156) hide show
  1. data/lib/rbbt/workflow/rest.rb +142 -57
  2. data/lib/rbbt/workflow/rest/auth.rb +3 -2
  3. data/lib/rbbt/workflow/rest/client.rb +4 -1
  4. data/lib/rbbt/workflow/rest/email.rb +23 -0
  5. data/lib/rbbt/workflow/rest/entity.rb +87 -62
  6. data/lib/rbbt/workflow/rest/helpers.rb +38 -0
  7. data/lib/rbbt/workflow/rest/render.rb +532 -153
  8. data/lib/rbbt/workflow/rest/util.rb +81 -104
  9. data/share/views/compass/_base.sass +0 -3
  10. data/share/views/compass/app.sass +0 -103
  11. data/share/views/compass/compass.config +5 -5
  12. data/share/views/compass/layout.sass +133 -0
  13. data/share/views/compass/main.sass +28 -5
  14. data/share/views/entity/GOTerm.haml +15 -0
  15. data/share/views/entity/Gene.haml +7 -0
  16. data/share/views/entity/GenomicMutation.haml +10 -0
  17. data/share/views/entity/KeggPathway.haml +13 -0
  18. data/share/views/entity/MutatedIsoform.haml +43 -0
  19. data/share/views/entity/NCIBioCartaPathways.haml +9 -0
  20. data/share/views/entity/NCINaturePathways.haml +9 -0
  21. data/share/views/entity/NCIReactomePathways.haml +9 -0
  22. data/share/views/entity/PfamDomain.haml +1 -0
  23. data/share/views/entity_list/Default.haml +10 -0
  24. data/share/views/form.haml +2 -54
  25. data/share/views/front.haml +1 -0
  26. data/share/views/job_list.haml +1 -1
  27. data/share/views/js/app.js +122 -68
  28. data/share/views/layout.haml +28 -22
  29. data/share/views/partials/_form.haml +36 -0
  30. data/share/views/partials/_job_control.haml +8 -8
  31. data/share/views/partials/_result_table.haml +12 -40
  32. data/share/views/partials/_result_table_controls.haml +36 -28
  33. data/share/views/partials/_table.haml +39 -0
  34. data/share/views/public/favicon.gif +0 -0
  35. data/share/views/public/plugins/jmol/CHANGES.txt +11124 -0
  36. data/share/views/public/plugins/jmol/COPYRIGHT.txt +73 -0
  37. data/share/views/public/plugins/jmol/ChimeToJmol.jar +0 -0
  38. data/share/views/public/plugins/jmol/Jmol.jar +0 -0
  39. data/share/views/public/plugins/jmol/Jmol.js +1711 -0
  40. data/share/views/public/plugins/jmol/JmolApplet.jar +0 -0
  41. data/share/views/public/plugins/jmol/JmolApplet0.jar +0 -0
  42. data/share/views/public/plugins/jmol/JmolApplet0_Console.jar +0 -0
  43. data/share/views/public/plugins/jmol/JmolApplet0_Minimize.jar +0 -0
  44. data/share/views/public/plugins/jmol/JmolApplet0_Popup.jar +0 -0
  45. data/share/views/public/plugins/jmol/JmolApplet0_ReadersCifPdb.jar +0 -0
  46. data/share/views/public/plugins/jmol/JmolApplet0_ReadersMolXyz.jar +0 -0
  47. data/share/views/public/plugins/jmol/JmolApplet0_ReadersMore.jar +0 -0
  48. data/share/views/public/plugins/jmol/JmolApplet0_ReadersQuantum.jar +0 -0
  49. data/share/views/public/plugins/jmol/JmolApplet0_ReadersSimple.jar +0 -0
  50. data/share/views/public/plugins/jmol/JmolApplet0_ReadersXml.jar +0 -0
  51. data/share/views/public/plugins/jmol/JmolApplet0_ReadersXtal.jar +0 -0
  52. data/share/views/public/plugins/jmol/JmolApplet0_ShapeBio.jar +0 -0
  53. data/share/views/public/plugins/jmol/JmolApplet0_ShapeSpecial.jar +0 -0
  54. data/share/views/public/plugins/jmol/JmolApplet0_ShapeSurface.jar +0 -0
  55. data/share/views/public/plugins/jmol/JmolApplet0_Smiles.jar +0 -0
  56. data/share/views/public/plugins/jmol/JmolApplet0_Symmetry.jar +0 -0
  57. data/share/views/public/plugins/jmol/JmolApplet0_i18n_ar.jar +0 -0
  58. data/share/views/public/plugins/jmol/JmolApplet0_i18n_bs.jar +0 -0
  59. data/share/views/public/plugins/jmol/JmolApplet0_i18n_ca.jar +0 -0
  60. data/share/views/public/plugins/jmol/JmolApplet0_i18n_cs.jar +0 -0
  61. data/share/views/public/plugins/jmol/JmolApplet0_i18n_da.jar +0 -0
  62. data/share/views/public/plugins/jmol/JmolApplet0_i18n_de.jar +0 -0
  63. data/share/views/public/plugins/jmol/JmolApplet0_i18n_el.jar +0 -0
  64. data/share/views/public/plugins/jmol/JmolApplet0_i18n_en_GB.jar +0 -0
  65. data/share/views/public/plugins/jmol/JmolApplet0_i18n_es.jar +0 -0
  66. data/share/views/public/plugins/jmol/JmolApplet0_i18n_et.jar +0 -0
  67. data/share/views/public/plugins/jmol/JmolApplet0_i18n_fi.jar +0 -0
  68. data/share/views/public/plugins/jmol/JmolApplet0_i18n_fr.jar +0 -0
  69. data/share/views/public/plugins/jmol/JmolApplet0_i18n_fy.jar +0 -0
  70. data/share/views/public/plugins/jmol/JmolApplet0_i18n_hu.jar +0 -0
  71. data/share/views/public/plugins/jmol/JmolApplet0_i18n_hy.jar +0 -0
  72. data/share/views/public/plugins/jmol/JmolApplet0_i18n_id.jar +0 -0
  73. data/share/views/public/plugins/jmol/JmolApplet0_i18n_it.jar +0 -0
  74. data/share/views/public/plugins/jmol/JmolApplet0_i18n_jv.jar +0 -0
  75. data/share/views/public/plugins/jmol/JmolApplet0_i18n_ko.jar +0 -0
  76. data/share/views/public/plugins/jmol/JmolApplet0_i18n_ms.jar +0 -0
  77. data/share/views/public/plugins/jmol/JmolApplet0_i18n_nb.jar +0 -0
  78. data/share/views/public/plugins/jmol/JmolApplet0_i18n_nl.jar +0 -0
  79. data/share/views/public/plugins/jmol/JmolApplet0_i18n_oc.jar +0 -0
  80. data/share/views/public/plugins/jmol/JmolApplet0_i18n_pl.jar +0 -0
  81. data/share/views/public/plugins/jmol/JmolApplet0_i18n_pt.jar +0 -0
  82. data/share/views/public/plugins/jmol/JmolApplet0_i18n_pt_BR.jar +0 -0
  83. data/share/views/public/plugins/jmol/JmolApplet0_i18n_ru.jar +0 -0
  84. data/share/views/public/plugins/jmol/JmolApplet0_i18n_sl.jar +0 -0
  85. data/share/views/public/plugins/jmol/JmolApplet0_i18n_sv.jar +0 -0
  86. data/share/views/public/plugins/jmol/JmolApplet0_i18n_ta.jar +0 -0
  87. data/share/views/public/plugins/jmol/JmolApplet0_i18n_te.jar +0 -0
  88. data/share/views/public/plugins/jmol/JmolApplet0_i18n_tr.jar +0 -0
  89. data/share/views/public/plugins/jmol/JmolApplet0_i18n_uk.jar +0 -0
  90. data/share/views/public/plugins/jmol/JmolApplet0_i18n_zh_CN.jar +0 -0
  91. data/share/views/public/plugins/jmol/JmolApplet0_i18n_zh_TW.jar +0 -0
  92. data/share/views/public/plugins/jmol/JmolAppletSigned.jar +0 -0
  93. data/share/views/public/plugins/jmol/JmolAppletSigned0.jar +0 -0
  94. data/share/views/public/plugins/jmol/JmolAppletSigned0_Console.jar +0 -0
  95. data/share/views/public/plugins/jmol/JmolAppletSigned0_Minimize.jar +0 -0
  96. data/share/views/public/plugins/jmol/JmolAppletSigned0_MultiTouch.jar +0 -0
  97. data/share/views/public/plugins/jmol/JmolAppletSigned0_Popup.jar +0 -0
  98. data/share/views/public/plugins/jmol/JmolAppletSigned0_ReadersCifPdb.jar +0 -0
  99. data/share/views/public/plugins/jmol/JmolAppletSigned0_ReadersMolXyz.jar +0 -0
  100. data/share/views/public/plugins/jmol/JmolAppletSigned0_ReadersMore.jar +0 -0
  101. data/share/views/public/plugins/jmol/JmolAppletSigned0_ReadersQuantum.jar +0 -0
  102. data/share/views/public/plugins/jmol/JmolAppletSigned0_ReadersSimple.jar +0 -0
  103. data/share/views/public/plugins/jmol/JmolAppletSigned0_ReadersXml.jar +0 -0
  104. data/share/views/public/plugins/jmol/JmolAppletSigned0_ReadersXtal.jar +0 -0
  105. data/share/views/public/plugins/jmol/JmolAppletSigned0_ShapeBio.jar +0 -0
  106. data/share/views/public/plugins/jmol/JmolAppletSigned0_ShapeSpecial.jar +0 -0
  107. data/share/views/public/plugins/jmol/JmolAppletSigned0_ShapeSurface.jar +0 -0
  108. data/share/views/public/plugins/jmol/JmolAppletSigned0_Smiles.jar +0 -0
  109. data/share/views/public/plugins/jmol/JmolAppletSigned0_Symmetry.jar +0 -0
  110. data/share/views/public/plugins/jmol/JmolAppletSigned0_i18n_ar.jar +0 -0
  111. data/share/views/public/plugins/jmol/JmolAppletSigned0_i18n_bs.jar +0 -0
  112. data/share/views/public/plugins/jmol/JmolAppletSigned0_i18n_ca.jar +0 -0
  113. data/share/views/public/plugins/jmol/JmolAppletSigned0_i18n_cs.jar +0 -0
  114. data/share/views/public/plugins/jmol/JmolAppletSigned0_i18n_da.jar +0 -0
  115. data/share/views/public/plugins/jmol/JmolAppletSigned0_i18n_de.jar +0 -0
  116. data/share/views/public/plugins/jmol/JmolAppletSigned0_i18n_el.jar +0 -0
  117. data/share/views/public/plugins/jmol/JmolAppletSigned0_i18n_en_GB.jar +0 -0
  118. data/share/views/public/plugins/jmol/JmolAppletSigned0_i18n_es.jar +0 -0
  119. data/share/views/public/plugins/jmol/JmolAppletSigned0_i18n_et.jar +0 -0
  120. data/share/views/public/plugins/jmol/JmolAppletSigned0_i18n_fi.jar +0 -0
  121. data/share/views/public/plugins/jmol/JmolAppletSigned0_i18n_fr.jar +0 -0
  122. data/share/views/public/plugins/jmol/JmolAppletSigned0_i18n_fy.jar +0 -0
  123. data/share/views/public/plugins/jmol/JmolAppletSigned0_i18n_hu.jar +0 -0
  124. data/share/views/public/plugins/jmol/JmolAppletSigned0_i18n_hy.jar +0 -0
  125. data/share/views/public/plugins/jmol/JmolAppletSigned0_i18n_id.jar +0 -0
  126. data/share/views/public/plugins/jmol/JmolAppletSigned0_i18n_it.jar +0 -0
  127. data/share/views/public/plugins/jmol/JmolAppletSigned0_i18n_jv.jar +0 -0
  128. data/share/views/public/plugins/jmol/JmolAppletSigned0_i18n_ko.jar +0 -0
  129. data/share/views/public/plugins/jmol/JmolAppletSigned0_i18n_ms.jar +0 -0
  130. data/share/views/public/plugins/jmol/JmolAppletSigned0_i18n_nb.jar +0 -0
  131. data/share/views/public/plugins/jmol/JmolAppletSigned0_i18n_nl.jar +0 -0
  132. data/share/views/public/plugins/jmol/JmolAppletSigned0_i18n_oc.jar +0 -0
  133. data/share/views/public/plugins/jmol/JmolAppletSigned0_i18n_pl.jar +0 -0
  134. data/share/views/public/plugins/jmol/JmolAppletSigned0_i18n_pt.jar +0 -0
  135. data/share/views/public/plugins/jmol/JmolAppletSigned0_i18n_pt_BR.jar +0 -0
  136. data/share/views/public/plugins/jmol/JmolAppletSigned0_i18n_ru.jar +0 -0
  137. data/share/views/public/plugins/jmol/JmolAppletSigned0_i18n_sl.jar +0 -0
  138. data/share/views/public/plugins/jmol/JmolAppletSigned0_i18n_sv.jar +0 -0
  139. data/share/views/public/plugins/jmol/JmolAppletSigned0_i18n_ta.jar +0 -0
  140. data/share/views/public/plugins/jmol/JmolAppletSigned0_i18n_te.jar +0 -0
  141. data/share/views/public/plugins/jmol/JmolAppletSigned0_i18n_tr.jar +0 -0
  142. data/share/views/public/plugins/jmol/JmolAppletSigned0_i18n_uk.jar +0 -0
  143. data/share/views/public/plugins/jmol/JmolAppletSigned0_i18n_zh_CN.jar +0 -0
  144. data/share/views/public/plugins/jmol/JmolAppletSigned0_i18n_zh_TW.jar +0 -0
  145. data/share/views/public/plugins/jmol/JmolData.jar +0 -0
  146. data/share/views/public/plugins/jmol/LEAME.txt +217 -0
  147. data/share/views/public/plugins/jmol/LICENSE.txt +504 -0
  148. data/share/views/public/plugins/jmol/README.txt +203 -0
  149. data/share/views/public/plugins/jmol/jmol +22 -0
  150. data/share/views/public/plugins/jmol/jmol.bat +5 -0
  151. data/share/views/public/plugins/jmol/jmol.mac +0 -0
  152. data/share/views/public/plugins/jmol/jmol.sh +39 -0
  153. data/share/views/public/plugins/jquery/js/jquery.form.js +980 -0
  154. data/share/views/result.haml +2 -2
  155. metadata +139 -6
  156. data/share/views/workflow_list.haml +0 -5
@@ -10,9 +10,10 @@ require 'sinatra/authorization'
10
10
  require 'rbbt/workflow/rest/util.rb'
11
11
  require 'rbbt/workflow/rest/render.rb'
12
12
  require 'rbbt/workflow/rest/auth.rb'
13
+ require 'rbbt/workflow/rest/email.rb'
14
+ require 'rbbt/workflow/rest/helpers.rb'
13
15
 
14
16
  module WorkflowREST
15
- extend Resource
16
17
 
17
18
  class << self
18
19
  attr_accessor :workflows
@@ -20,18 +21,21 @@ module WorkflowREST
20
21
  end
21
22
  self.workflows = []
22
23
 
24
+
23
25
  def self.setup
24
26
  configure do
25
- Compass.add_project_configuration(WorkflowREST.share.views.compass["compass.config"].find.dup.to_s)
27
+ Compass.add_project_configuration(Rbbt.share.views.compass["compass.config"].find.dup.to_s)
26
28
  end
27
29
 
28
30
  Sinatra.module_eval do
29
31
  helpers Sinatra::SinatraRbbt
30
32
  enable :sessions
33
+ enable :static
31
34
 
32
35
  before do
33
36
  @file_cache = {}
34
37
  @result_cache = {}
38
+ headers "AJAX-URL" => request.env["REQUEST_URI"]
35
39
  end
36
40
 
37
41
  after do
@@ -44,40 +48,85 @@ module WorkflowREST
44
48
  "Workflow Explorer"
45
49
  end
46
50
 
47
- def authorize(login, password)
48
- login == "miki" && password == "miki"
49
- end
50
-
51
51
  def check_user(user)
52
52
  login_required
53
53
  request.env['REMOTE_USER'] == user || throw(:halt, [ 401, 'Authorization Required' ])
54
54
  end
55
55
  end
56
+ end
56
57
 
58
+ set :public_folder, RbbtHTMLHelpers.locate_file(nil, nil, 'public/').find
59
+
60
+ begin
61
+ set :users, RbbtHTMLHelpers.locate_file(nil, nil, 'config/users').yaml
62
+ rescue
63
+ if Rbbt.etc.web_users.exists?
64
+ set :users, Rbbt.etc.web_users.yaml
65
+ else
66
+ set :users, {}
67
+ end
57
68
  end
58
69
 
59
- set :public_folder, Sinatra::SinatraRbbt.locate_file(nil, nil, 'public/').find
70
+ if production?
71
+ before do
72
+ cache_control :public, :must_revalidate, :max_age => 60
73
+ end
74
+ Log.severity = 0
75
+ end
60
76
 
61
77
  get '/stylesheets/:name.css' do
62
- file = locate_file(nil, nil, File.join("compass", params[:name] + '.sass'))
63
- css = Persist.persist("Stylesheet:#{file}", :string, :persist => ENV["RACK_ENV"].to_s == 'production', :dir => 'cache') do
78
+ file = locate_file(WorkflowREST.workflows.last, nil, File.join("compass", params[:name] + '.sass'))
79
+
80
+ content_type 'text/css', :charset => 'utf-8'
81
+ cache('css', params) do
64
82
  renderer = Sass::Engine.new(file.read)
65
- renderer.render.to_s
83
+ renderer.render
66
84
  end
67
- content_type 'text/css', :charset => 'utf-8'
68
- css
69
85
  end
70
86
 
71
87
  get '/js/:name.js' do
72
88
  content_type 'text/css', :charset => 'utf-8'
73
- file = locate_file(nil, nil, File.join("js", params[:name] + '.js'))
74
- file.read
89
+ send_file locate_file(nil, nil, File.join("js", params[:name] + '.js')).find
75
90
  end
76
91
 
77
92
  get '/entity/:type/:entity' do
78
93
  type = params[:type]
79
94
 
80
- entity_render(type, params)
95
+ visualization_parameters = get_visualization_parameters(params)
96
+ cache("Entity:", :params => params, :visualization_params => visualization_parameters, :user => user) do
97
+ entity_render(type, params.merge(visualization_parameters))
98
+ end
99
+ end
100
+
101
+ get '/entity_list/:type/:id' do
102
+ type = params.delete "type"
103
+ visualization_parameters = get_visualization_parameters(params)
104
+
105
+ cache("Entity List:", :params => params, :type => type, :visualization_params => visualization_parameters, :user => user) do
106
+ entity_list_render(type, params.merge(visualization_parameters))
107
+ end
108
+ end
109
+
110
+ get '/entity_action/:type/:action/:entity' do
111
+ type = params.delete "type"
112
+ action = params.delete "action"
113
+
114
+ visualization_parameters = get_visualization_parameters(params)
115
+
116
+ cache("Entity Action [#{action}]:", :params => params, :type => type, :action => action, :visualization_params => visualization_parameters, :user => user) do
117
+ entity_action_render(type, action, params.merge(visualization_parameters))
118
+ end
119
+ end
120
+
121
+ get '/entity_list_action/:type/:action/:id' do
122
+ type = params.delete "type"
123
+ action = params.delete "action"
124
+
125
+ visualization_parameters = get_visualization_parameters(params)
126
+
127
+ cache("Entity List Action [#{action}]:", :params => params, :type => type, :action => action, :visualization_params => visualization_parameters, :user => user) do
128
+ entity_list_action_render(type, action, params.merge(visualization_parameters))
129
+ end
81
130
  end
82
131
 
83
132
  end
@@ -87,12 +136,6 @@ module WorkflowREST
87
136
  task_name = task_name.to_s
88
137
  workflow_name = workflow.to_s
89
138
 
90
- # MOVE!!!!
91
- get File.join("/plugins", workflow_name, "*") do
92
- file = params[:splat].first
93
- send_file Sinatra::SinatraRbbt.locate_file(workflow, nil, 'plugins/' + file)
94
- end
95
-
96
139
  # context info
97
140
  delete File.join("/context", workflow_name, ":task") do
98
141
  task, jobname = params.values_at :task
@@ -118,7 +161,7 @@ module WorkflowREST
118
161
  when visualization_parameters[:_format] == "raw"
119
162
  task_info.collect{|k,v| [k,v] * "\t"} * "\n"
120
163
  when visualization_parameters[:_format] == "html"
121
- workflow_render(workflow, task_name, "task_info", workflow.task_info(task_name).merge(visualization_parameters).merge(:task_info => task_info))
164
+ workflow_render("task_info", workflow, task_name, workflow.task_info(task_name).merge(visualization_parameters).merge(:task_info => task_info))
122
165
  end
123
166
  end
124
167
 
@@ -131,7 +174,7 @@ module WorkflowREST
131
174
 
132
175
  job_list = workflow.jobs(task_name, user + "/").collect{|jobname| File.basename(jobname)}
133
176
 
134
- workflow_render(workflow, task_name, "job_list", visualization_parameters.merge(:workflow => workflow, :task_name => task_name, :job_list => job_list))
177
+ workflow_render("job_list", workflow, task_name, visualization_parameters.merge(:workflow => workflow, :task_name => task_name, :job_list => job_list))
135
178
  end
136
179
 
137
180
 
@@ -147,7 +190,7 @@ module WorkflowREST
147
190
  result = workflow.job(task_name, "EXEC", inputs.dup).exec
148
191
  result = paginate(result, params[:_page]) if params.include? :_page
149
192
 
150
- workflow_render_result(workflow, task_name, result, visualization_parameters.merge(:inputs => inputs))
193
+ workflow_render_result(result, workflow, task_name, visualization_parameters.merge(:inputs => inputs))
151
194
 
152
195
  # direct job issuing and redirection when job has all paramteres
153
196
  when has_all_inputs(workflow, task_name, inputs)
@@ -173,7 +216,7 @@ module WorkflowREST
173
216
 
174
217
  redirect redirection
175
218
  else
176
- workflow_render(workflow, task_name, "form", workflow.task_info(task_name).merge(visualization_parameters))
219
+ workflow_render("form", workflow, task_name, workflow.task_info(task_name).merge(visualization_parameters))
177
220
  end
178
221
  end
179
222
 
@@ -189,7 +232,7 @@ module WorkflowREST
189
232
 
190
233
  when :exec
191
234
  result = workflow.job(task_name, real_jobname, inputs.dup).exec
192
- workflow_render_result(workflow, task_name, result, visualization_parameters.merge(:inputs => inputs))
235
+ workflow_render_result(result, workflow, task_name, visualization_parameters.merge(:inputs => inputs))
193
236
 
194
237
  when :synchronous, :asynchronous
195
238
  job = workflow.job(task_name, real_jobname, inputs)
@@ -197,7 +240,22 @@ module WorkflowREST
197
240
  if type.to_sym == :synchronous
198
241
  job.run
199
242
  else
243
+ email = get_email(params)
200
244
  job.fork
245
+ if can_send_email? and not (email.nil? or email.empty?) and valid_email?(email)
246
+ Log.debug "Monitoring #{job.name} completion for email notification"
247
+ Process.fork do
248
+ while not job.done?
249
+ sleep 5
250
+ end
251
+ case
252
+ when job.error?
253
+ send_email(workflow, email, "Job #{job.name} failed", job.messages.last)
254
+ else
255
+ send_email(workflow, email, "Job #{job.name} succeded", "")
256
+ end
257
+ end
258
+ end
201
259
  end
202
260
 
203
261
  return job.name if visualization_parameters[:_format] == "json"
@@ -234,7 +292,7 @@ module WorkflowREST
234
292
  if visualization_parameters[:_format] == "html"
235
293
  content_type "text/html"
236
294
  status 500
237
- return workflow_render(workflow, task_name, "error", workflow.task_info(task_name).merge(visualization_parameters).merge(:jobname => jobname, :step => step, :inputs => step.info[:inputs]))
295
+ return workflow_render("error", workflow, task_name, workflow.task_info(task_name).merge(visualization_parameters).merge(:jobname => jobname, :step => step, :inputs => step.info[:inputs]))
238
296
  else
239
297
  status 500
240
298
  content_type "text/plain"
@@ -248,7 +306,7 @@ module WorkflowREST
248
306
  content_type "text/html"
249
307
  status 202
250
308
  @rbbt_refresh = 30 unless step.error?
251
- return workflow_render(workflow, task_name, "wait", workflow.task_info(task_name).merge(visualization_parameters).merge(:jobname => jobname, :step => step, :inputs => step.info[:inputs]))
309
+ return workflow_render("wait", workflow, task_name, workflow.task_info(task_name).merge(visualization_parameters).merge(:jobname => jobname, :step => step, :inputs => step.info[:inputs]))
252
310
  else
253
311
  status 202
254
312
  step.status
@@ -257,24 +315,42 @@ module WorkflowREST
257
315
  # DONE
258
316
  else
259
317
 
260
- case
261
- when visualization_parameters[:_format] == "html"
262
- result = step.load
263
- workflow_render_result(workflow, task_name, result, workflow.task_info(task_name).merge(visualization_parameters).merge(:jobname => jobname, :step => step, :inputs => step.info[:inputs], :result => result))
264
-
265
- when visualization_parameters[:_format] == "json"
266
- content_type "application/json"
267
- result = step.load
268
- result = paginate(result, visualization_parameters[:_page]) if visualization_parameters.include? "_page"
269
- result.to_json
270
-
271
- else
272
- content_type "text/plain"
273
- result = step.load
274
- result = paginate(result, visualization_parameters[:_page]) if visualization_parameters.include? "_page"
275
- result.to_s
276
- end
277
-
318
+ cache("Job Result:",
319
+ :visualization_parameters => visualization_parameters,
320
+ :workflow => workflow.to_s,
321
+ :task_name => task_name,
322
+ :jobname => jobname,
323
+ :user => user
324
+ ) do
325
+ case
326
+ when visualization_parameters[:_format] == "html"
327
+ result = step.load
328
+ workflow_render_result(result, workflow, task_name, workflow.task_info(task_name).merge(visualization_parameters).merge(:jobname => jobname, :step => step, :inputs => step.info[:inputs], :result => result))
329
+
330
+ when visualization_parameters[:_format] == "json"
331
+ content_type "application/json"
332
+ result = step.load
333
+ result = paginate(result, visualization_parameters[:_page]) if visualization_parameters.include? "_page"
334
+
335
+ if TSV === result
336
+ result.dup.to_json
337
+ else
338
+ result.to_json
339
+ end
340
+
341
+ else
342
+ content_type "text/plain"
343
+ result = step.load
344
+ result = paginate(result, visualization_parameters[:_page]) if visualization_parameters.include? "_page"
345
+ case
346
+ when Array === result
347
+ result * "\n"
348
+ else
349
+ result.to_s
350
+ end
351
+ end
352
+
353
+ end
278
354
  end
279
355
  end
280
356
 
@@ -296,7 +372,7 @@ module WorkflowREST
296
372
  when visualization_parameters[:_format] == "raw"
297
373
  info.collect{|k,v| [k,v] * "\t"} * "\n"
298
374
  when visualization_parameters[:_format] == "html"
299
- workflow_render(workflow, task_name, "info", visualization_parameters.merge(:info => info))
375
+ workflow_render("info", workflow, task_name, visualization_parameters.merge(:info => info))
300
376
  end
301
377
  end
302
378
 
@@ -318,7 +394,7 @@ module WorkflowREST
318
394
  when visualization_parameters[:_format] == "raw"
319
395
  dependencies.collect{|task, job| [task, job] * "\t"} * "\n"
320
396
  when visualization_parameters[:_format] == "html"
321
- workflow_render(workflow, task_name, "dependencies", visualization_parameters.merge(:dependencies => dependencies, :workflow => workflow, :task_name => task_name, :jobname => jobname))
397
+ workflow_render("dependencies", workflow, task_name, visualization_parameters.merge(:dependencies => dependencies, :workflow => workflow, :task_name => task_name, :jobname => jobname))
322
398
  end
323
399
  end
324
400
 
@@ -340,7 +416,7 @@ module WorkflowREST
340
416
  when visualization_parameters[:_format] == "raw"
341
417
  files * "\n"
342
418
  when visualization_parameters[:_format] == "html"
343
- workflow_render(workflow, task_name, "files", visualization_parameters.merge(:files => files, :workflow => workflow, :task_name => task_name, :jobname => jobname))
419
+ workflow_render("files", workflow, task_name, visualization_parameters.merge(:files => files, :workflow => workflow, :task_name => task_name, :jobname => jobname))
344
420
  end
345
421
  end
346
422
 
@@ -398,15 +474,11 @@ module WorkflowREST
398
474
 
399
475
 
400
476
  def self.add_workflows(*workflows)
401
- self.workflows.concat workflows
477
+ self.workflows.concat workflows.select{|wf| Module === wf}
402
478
  self.workflows.uniq!
403
- get '/' do
404
- visualization_parameters = get_visualization_parameters(params)
405
- workflow_render(nil, nil, "workflow_list", visualization_parameters.merge(:workflows => WorkflowREST.workflows))
406
- end
407
-
479
+
480
+ self.workflows.each do |workflow|
408
481
 
409
- WorkflowREST.workflows.each do |workflow|
410
482
  get File.join('/', workflow.to_s) do
411
483
  visualization_parameters = get_visualization_parameters(params)
412
484
 
@@ -414,10 +486,15 @@ module WorkflowREST
414
486
  if visualization_parameters[:_format] and visualization_parameters[:_format].to_sym == :json
415
487
  tasks.to_json
416
488
  else
417
- workflow_render(workflow, nil, "task_list", visualization_parameters.merge(:workflow => workflow, :tasks => tasks))
489
+ workflow_render("task_list", workflow, nil, visualization_parameters.merge(:workflow => workflow, :tasks => tasks))
418
490
  end
419
491
  end
420
492
 
493
+ get File.join("/plugins", workflow.to_s, "*") do
494
+ file = params[:splat].first
495
+ send_file RbbtHTMLHelpers.locate_file(workflow, nil, 'plugins/' + file)
496
+ end
497
+
421
498
  workflow.asynchronous_exports.each do |name|
422
499
  WorkflowREST.add_task workflow, name, :asynchronous
423
500
  end
@@ -430,6 +507,14 @@ module WorkflowREST
430
507
  WorkflowREST.add_task workflow, name, :exec
431
508
  end
432
509
 
510
+ if workflow.libdir.lib["sinatra.rb"].exists?
511
+ require workflow.libdir.lib["sinatra.rb"].find
512
+ end
513
+ end
514
+
515
+ get '/' do
516
+ visualization_parameters = get_visualization_parameters(params)
517
+ workflow_render("front", visualization_parameters.merge(:workflows => WorkflowREST.workflows.select{|w| Module === w}))
433
518
  end
434
519
 
435
520
  end
@@ -38,12 +38,15 @@ module Sinatra
38
38
  end
39
39
 
40
40
  app.post '/login' do
41
+ Log.debug "Loggin: #{params.inspect}"
41
42
  if options.users.include? params[:user] and options.users[params[:user]] == params[:pass]
43
+ Log.debug "Loggin Successful"
42
44
  session[:authorized] = true
43
45
  session[:user] = params[:user]
44
46
  session[:context] = nil
45
47
  redirect '/'
46
48
  else
49
+ Log.debug "Loggin Failed"
47
50
  session[:authorized] = false
48
51
  session[:user] = nil
49
52
  session[:context] = nil
@@ -58,8 +61,6 @@ module Sinatra
58
61
  redirect '/'
59
62
  end
60
63
 
61
-
62
-
63
64
  end
64
65
  end
65
66
 
@@ -47,8 +47,11 @@ class RbbtRestClient
47
47
  end
48
48
 
49
49
  def load
50
- if task.result_type.to_sym == :string
50
+ case task.result_type.to_sym
51
+ when :string
51
52
  RestClient.get(File.join(task.url, task.name.to_s, @remote_name) + "?_format=raw")
53
+ when :tsv
54
+ TSV.open(StringIO.new(RestClient.get(File.join(task.url, task.name.to_s, @remote_name) + "?_format=raw")))
52
55
  else
53
56
  res = JSON.parse(RestClient.get(File.join(task.url, task.name.to_s, @remote_name) + "?_format=json"))
54
57
  res = TSV.setup(res) if task.result_type.to_sym == :tsv
@@ -0,0 +1,23 @@
1
+ require 'rbbt'
2
+ require 'rbbt/util/misc'
3
+ module Sinatra
4
+ module SinatraRbbt
5
+
6
+ def valid_email?(email)
7
+ !!(email =~ /\w@\w/)
8
+ end
9
+
10
+ def can_send_email?
11
+ Rbbt.etc.smtp_config.exists?
12
+ end
13
+
14
+ def send_email(workflow, to, subject, message)
15
+ Log.low "Sending email to: #{ to }. Subject: #{ subject }"
16
+ raise "Cannot send emails, config is missing" if not can_send_email?
17
+ mail_options = Rbbt.etc.smtp_config.yaml
18
+ Misc.send_email("no-replay@#{workflow.to_s}", to, subject, message, mail_options)
19
+ end
20
+ end
21
+ end
22
+
23
+
@@ -1,77 +1,102 @@
1
- module EntityOLD
2
- ENTITIES = {}
3
- METHODS = {}
4
- SYNONYMS = {}
5
-
6
- def self.tsv_sort(&block)
7
- METHODS[:tsv_sort] = block
8
- end
9
-
10
- def self.sort(&block)
11
- METHODS[:sort] = block
12
- end
13
-
14
- def self.sort_by(&block)
15
- METHODS[:sort_by] = block
16
- end
17
-
18
- def self.html(&block)
19
- METHODS[:html] = block
20
- end
21
-
22
- def self.filter(&block)
23
- METHODS[:filter] = block
24
- end
25
-
26
- def self.link(entity, type, params = {}, text = nil, html_class= nil)
27
- if entity.nil?
28
- ""
29
- else
30
- text ||= entity
31
- "<a class='entity #{ type.sub(/\s/,'_') }#{html_class.nil? ? "" : " " << html_class}' href='#{File.join('/entity', type, entity)}#{
32
- if params.nil? or params.empty?
33
- ""
34
- else
35
- "?" + params.collect{|*p| p * "="} * "&"
36
- end
37
- }'>#{ text }</a>"
38
- end
39
- end
40
-
41
- def self.define(name, *synonyms, &block)
42
- Log.debug "Defining entity #{ name }"
43
- Misc.lock(Rbbt.tmp.sinatra_rbbt.find) do
44
- self.instance_exec &block
45
- ENTITIES[name] = METHODS.dup
46
- METHODS.clear
47
- end
48
- synonyms.each do |syn|
49
- SYNONYMS[syn] = name
50
- end
51
- end
52
- end
53
-
54
1
  module Entity
2
+
55
3
  module REST
56
- def link(text = nil, options = {})
4
+ LIST_REPO = {}
5
+
6
+ def link(text = nil, url = nil, options = {})
57
7
  return nil if self.nil?
58
8
  if Array === self
59
9
  text ||= self.name if self.respond_to? :name
60
10
  if Array === text
61
11
  translations = Misc.zip2hash(self, text)
62
- self.collect{|e| e.link(translations[e])}
12
+ self.collect{|e| e.link(translations[e], url, options)}
63
13
  else
64
- self.collect{|e| e.link(text)}
14
+ self.collect{|e| e.link(text, url, options)}
65
15
  end
66
16
  else
17
+
67
18
  text ||= self.name if self.respond_to? :name
68
- text = self if text.nil? or text == :literal
69
- klass = self.respond_to?(:format)? self.format : annotation_types.collect{|t| t.to_s} * " "
70
- klass += " " << options[:extra_classes] if options.include? :extra_classes
71
- type = self.respond_to?(:format)? annotation_types.last.to_s + ":" + self.format : annotation_types.last.to_s
72
- annotations_str = self.info.reject{|k,v| [:annotation_types, :format].include? k}.collect{|k,v| [k, CGI.escape(v)] * "="} * "&"
73
- "<a class='entity #{klass}' href='#{File.join("/entity", type, self) + '?' + annotations_str}'>#{text}</a>"
19
+ text = self if text.nil? or text == :literal or text.to_s.strip.empty?
20
+
21
+ klass = options[:class]
22
+ klass ||= "entity " + (self.respond_to?(:format)? self.format.gsub(/\s/,'_') : annotation_types.collect{|t| t.to_s.gsub(/\s/,'_')} * " ")
23
+
24
+ klass += " " << options[:extra_classes] || "" if options.include? :extra_classes
25
+ klass += " " << html_class if self.respond_to? :html_class
26
+
27
+ type = self.respond_to?(:format)? annotation_types.last.to_s +
28
+ ":" +
29
+ (self.format || "") : annotation_types.last.to_s
30
+
31
+ params = options[:params] || self.info.reject{|k,v| [:annotation_types, :format].include?(k)}
32
+ params.merge! options[:extra_params] if options.include? :extra_params
33
+
34
+ url ||= if options.include? :action
35
+ File.join("/entity_action", type, options[:action].to_s, self)
36
+ else
37
+ File.join("/entity", type, self)
38
+ end
39
+
40
+ annotations_str = params.collect{|k,v| [k, CGI.escape(v.to_s)] * "="} * "&"
41
+ "<a class='#{klass}' href='#{url + (annotations_str.any? ? '?' + annotations_str : "")}'>#{text}</a>"
42
+ end
43
+ end
44
+
45
+ def self.save_list(id, list)
46
+ Entity::REST::LIST_REPO[id] = list
47
+ end
48
+
49
+ def self.load_list(id)
50
+ Entity::REST::LIST_REPO[id]
51
+ end
52
+
53
+ def list_link(text = nil, id = nil, options = {})
54
+ text = self.length if text.nil? or (String === text and text.strip.empty?)
55
+
56
+ id ||= options[:id] || Misc.digest((self * "|").inspect)
57
+
58
+ Entity::REST.save_list(id, self)
59
+
60
+ klass = self.respond_to?(:format)? self.format.gsub(/\s/,'_') : annotation_types.collect{|t| t.to_s.gsub(/\s/,'_')} * " "
61
+
62
+ klass += " " << options[:extra_classes] if options.include? :extra_classes
63
+ klass += " " << html_class if self.respond_to? :html_class
64
+
65
+ type = self.respond_to?(:format)? annotation_types.last.to_s + ":" + self.format : annotation_types.last.to_s
66
+
67
+ annotations_str = self.info.reject{|k,v| [:annotation_types, :format].include?(k)}.collect{|k,v| [k, CGI.escape(v.to_s)] * "="} * "&"
68
+
69
+ "<a class='entity_list #{klass}' href='#{File.join("/entity_list", type, id) + (annotations_str.any? ? '?' + annotations_str : "")}'>#{text}</a>"
70
+ end
71
+
72
+ def action_link(action, text = nil, inputs = {})
73
+ options = inputs.delete(:link_options) || {}
74
+ clean_inputs = {}
75
+ inputs.each do |k, v|
76
+ clean_inputs[k] = Array === v ? v * "," : v
74
77
  end
78
+ link(text, nil, options.merge(:extra_params => clean_inputs, :action => action))
79
+ end
80
+
81
+ def list_action_link(action, text = nil, id = nil, options = {})
82
+ text = self.length if text.nil? or (String === text and text.strip.empty?)
83
+ id ||= options[:id] || Misc.digest((self * "|").inspect)
84
+
85
+ text = id if text == :id
86
+
87
+ Entity::REST.save_list(id, self)
88
+
89
+ klass = self.respond_to?(:format)? self.format.gsub(/\s/,'_') : annotation_types.collect{|t| t.to_s.gsub(/\s/,'_')} * " "
90
+
91
+ klass += " " << options[:extra_classes] if options.include? :extra_classes
92
+ klass += " " << html_class if self.respond_to? :html_class
93
+
94
+ type = self.respond_to?(:format)? annotation_types.last.to_s + ":" + self.format : annotation_types.last.to_s
95
+
96
+ annotations_str = self.info.reject{|k,v| [:annotation_types, :format].include?(k)}.collect{|k,v| [k, CGI.escape(v.to_s)] * "="} * "&"
97
+
98
+ "<a class='entity_list_action #{klass}' href='#{File.join("/entity_list_action", type, action, id) + (annotations_str.any? ? '?' + annotations_str : "")}'>#{text}</a>"
75
99
  end
100
+
76
101
  end
77
102
  end