rbbt-views 1.0.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (177) hide show
  1. data/lib/rbbt/workflow/rest.rb +365 -95
  2. data/lib/rbbt/workflow/rest/client.rb +2 -0
  3. data/lib/rbbt/workflow/rest/entity.rb +82 -76
  4. data/lib/rbbt/workflow/rest/finder.rb +78 -0
  5. data/lib/rbbt/workflow/rest/helpers.rb +288 -47
  6. data/lib/rbbt/workflow/rest/notes.rb +125 -0
  7. data/lib/rbbt/workflow/rest/render.rb +280 -240
  8. data/lib/rbbt/workflow/rest/util.rb +47 -31
  9. data/share/views/compass/_base.sass +0 -8
  10. data/share/views/compass/colors.sass +10 -0
  11. data/share/views/compass/colors/ventana_azul.sass +5 -0
  12. data/share/views/compass/compass.config +2 -1
  13. data/share/views/compass/details.sass +50 -0
  14. data/share/views/compass/dom.sass +64 -0
  15. data/share/views/compass/embedded.sass +111 -0
  16. data/share/views/compass/entities.sass +8 -0
  17. data/share/views/compass/error.sass +13 -0
  18. data/share/views/compass/finder.sass +42 -0
  19. data/share/views/compass/fonts.sass +8 -0
  20. data/share/views/compass/form.sass +49 -1
  21. data/share/views/compass/header.sass +68 -0
  22. data/share/views/compass/{main.sass → helpers.sass} +53 -21
  23. data/share/views/compass/layout.sass +31 -199
  24. data/share/views/compass/lists.sass +128 -0
  25. data/share/views/compass/menu.sass +35 -0
  26. data/share/views/compass/notes.sass +52 -0
  27. data/share/views/compass/sizes.sass +8 -0
  28. data/share/views/compass/tables.sass +22 -0
  29. data/share/views/compass/wait.sass +9 -0
  30. data/share/views/edit_list.haml +41 -30
  31. data/share/views/entity/GOTerm.haml +4 -3
  32. data/share/views/entity/Gene.haml +8 -1
  33. data/share/views/entity/GenomicMutation.haml +4 -1
  34. data/share/views/entity/KeggPathway.haml +1 -1
  35. data/share/views/entity/MutatedIsoform.haml +68 -11
  36. data/share/views/entity/NCIBioCartaPathway.haml +2 -3
  37. data/share/views/entity/NCINaturePathway.haml +3 -3
  38. data/share/views/entity/NCIReactomePathway.haml +2 -3
  39. data/share/views/entity/PfamDomain.haml +2 -0
  40. data/share/views/entity/Transcript.haml +10 -0
  41. data/share/views/entity_list/Default.haml +4 -0
  42. data/share/views/entity_list/Default/compare_to_other_lists.haml +41 -0
  43. data/share/views/entity_list/Default/entity_links.haml +6 -0
  44. data/share/views/entity_list/Default/find_in_other_lists.haml +36 -0
  45. data/share/views/error.haml +6 -1
  46. data/share/views/find.haml +10 -0
  47. data/share/views/form.haml +1 -1
  48. data/share/views/info.haml +1 -1
  49. data/share/views/js/_action_setup.js +250 -0
  50. data/share/views/js/_basic.js +269 -0
  51. data/share/views/js/_cytoscape.js +44 -0
  52. data/share/views/js/_details.js +239 -0
  53. data/share/views/js/_dom_updates.js +384 -0
  54. data/share/views/js/_embedded.js +95 -0
  55. data/share/views/js/_images.js +20 -0
  56. data/share/views/js/_layout.js +21 -0
  57. data/share/views/js/_lists.js +224 -0
  58. data/share/views/js/_table.js +36 -0
  59. data/share/views/js/_workflow.js +42 -0
  60. data/share/views/js/app.js +0 -570
  61. data/share/views/js/fix_tablesorter_scientific.js +25 -0
  62. data/share/views/js/json2.js +487 -0
  63. data/share/views/layout.haml +8 -98
  64. data/share/views/notes.haml +15 -0
  65. data/share/views/partials/_form.haml +22 -7
  66. data/share/views/partials/_job_control.haml +8 -8
  67. data/share/views/partials/_list_control.haml +32 -0
  68. data/share/views/partials/_list_header.haml +6 -0
  69. data/share/views/partials/_note_list.haml +64 -0
  70. data/share/views/partials/_result_table.haml +12 -7
  71. data/share/views/partials/_result_table_controls.haml +11 -5
  72. data/share/views/partials/_table.haml +24 -6
  73. data/share/views/partials/layout/_coda.haml +10 -0
  74. data/share/views/partials/layout/_details.haml +25 -0
  75. data/share/views/partials/layout/_head.haml +22 -0
  76. data/share/views/partials/layout/_header.haml +29 -0
  77. data/share/views/partials/layout/_menu.haml +20 -0
  78. data/share/views/partials/layout/_resources.haml +41 -0
  79. data/share/views/public/background.png +0 -0
  80. data/share/views/public/plugins/cytoscape-web/LICENSE.txt +504 -0
  81. data/share/views/public/plugins/cytoscape-web/README.txt +213 -0
  82. data/share/views/public/plugins/cytoscape-web/js/AC_OETags.js +1 -0
  83. data/share/views/public/plugins/cytoscape-web/js/cytoscapeweb.js +1 -0
  84. data/share/views/public/plugins/cytoscape-web/js/json2.js +1 -0
  85. data/share/views/public/plugins/cytoscape-web/swf/CytoscapeWeb.swf +0 -0
  86. data/share/views/public/plugins/cytoscape-web/swf/playerProductInstall.swf +0 -0
  87. data/share/views/public/plugins/fancybox/CHANGELOG.md +68 -0
  88. data/share/views/public/plugins/fancybox/README.md +220 -0
  89. data/share/views/public/plugins/fancybox/css/blank.gif +0 -0
  90. data/share/views/public/plugins/fancybox/css/fancybox_loading.gif +0 -0
  91. data/share/views/public/plugins/fancybox/css/fancybox_sprite.png +0 -0
  92. data/share/views/public/plugins/fancybox/css/jquery.fancybox.css +234 -0
  93. data/share/views/public/plugins/fancybox/helpers/fancybox_buttons.png +0 -0
  94. data/share/views/public/plugins/fancybox/helpers/jquery.fancybox-buttons.css +85 -0
  95. data/share/views/public/plugins/fancybox/helpers/jquery.fancybox-buttons.js +115 -0
  96. data/share/views/public/plugins/fancybox/helpers/jquery.fancybox-media.js +85 -0
  97. data/share/views/public/plugins/fancybox/helpers/jquery.fancybox-thumbs.css +54 -0
  98. data/share/views/public/plugins/fancybox/helpers/jquery.fancybox-thumbs.js +157 -0
  99. data/share/views/public/plugins/fancybox/js/jquery.fancybox.js +1463 -0
  100. data/share/views/public/plugins/fancybox/js/jquery.mousewheel-3.0.6.pack.js +13 -0
  101. data/share/views/public/plugins/fancybox/lib/jquery-1.7.2.min.js +4 -0
  102. data/share/views/public/plugins/featuredimagezoomer/css/featuredimagezoomer.css +8 -0
  103. data/share/views/public/plugins/featuredimagezoomer/images/spinningred.gif +0 -0
  104. data/share/views/public/plugins/featuredimagezoomer/js/featuredimagezoomer.js +245 -0
  105. data/share/views/public/plugins/jquery-ui.hitarea.js +173 -0
  106. data/share/views/public/plugins/jquery/js/jquery-1.8.0.min.js +2 -0
  107. data/share/views/public/plugins/tablesorter/addons/pager/jquery.tablesorter.pager.css +25 -0
  108. data/share/views/public/plugins/tablesorter/addons/pager/jquery.tablesorter.pager.js +184 -0
  109. data/share/views/public/plugins/tablesorter/build.xml +26 -0
  110. data/share/views/public/plugins/tablesorter/build/ParseMaster.js +106 -0
  111. data/share/views/public/plugins/tablesorter/build/js.jar +0 -0
  112. data/share/views/public/plugins/tablesorter/build/jsmin.js +316 -0
  113. data/share/views/public/plugins/tablesorter/build/min.js +5 -0
  114. data/share/views/public/plugins/tablesorter/build/pack.js +5 -0
  115. data/share/views/public/plugins/tablesorter/build/packer.js +316 -0
  116. data/share/views/public/plugins/tablesorter/build/writeFile.js +19 -0
  117. data/share/views/public/plugins/tablesorter/changelog +41 -0
  118. data/share/views/public/plugins/tablesorter/docs/assets/ajax-content.html +43 -0
  119. data/share/views/public/plugins/tablesorter/docs/css/jq.css +29 -0
  120. data/share/views/public/plugins/tablesorter/docs/example-ajax.html +119 -0
  121. data/share/views/public/plugins/tablesorter/docs/example-empty-table.html +75 -0
  122. data/share/views/public/plugins/tablesorter/docs/example-extending-defaults.html +109 -0
  123. data/share/views/public/plugins/tablesorter/docs/example-meta-headers.html +108 -0
  124. data/share/views/public/plugins/tablesorter/docs/example-meta-parsers.html +105 -0
  125. data/share/views/public/plugins/tablesorter/docs/example-meta-sort-list.html +107 -0
  126. data/share/views/public/plugins/tablesorter/docs/example-option-debug.html +116 -0
  127. data/share/views/public/plugins/tablesorter/docs/example-option-digits.html +106 -0
  128. data/share/views/public/plugins/tablesorter/docs/example-option-sort-force.html +107 -0
  129. data/share/views/public/plugins/tablesorter/docs/example-option-sort-key.html +108 -0
  130. data/share/views/public/plugins/tablesorter/docs/example-option-sort-list.html +108 -0
  131. data/share/views/public/plugins/tablesorter/docs/example-option-sort-order.html +108 -0
  132. data/share/views/public/plugins/tablesorter/docs/example-option-text-extraction.html +85 -0
  133. data/share/views/public/plugins/tablesorter/docs/example-options-headers.html +118 -0
  134. data/share/views/public/plugins/tablesorter/docs/example-pager.html +329 -0
  135. data/share/views/public/plugins/tablesorter/docs/example-parsers.html +112 -0
  136. data/share/views/public/plugins/tablesorter/docs/example-trigger-sort.html +113 -0
  137. data/share/views/public/plugins/tablesorter/docs/example-triggers.html +336 -0
  138. data/share/views/public/plugins/tablesorter/docs/example-update-cell.html +118 -0
  139. data/share/views/public/plugins/tablesorter/docs/example-widgets.html +383 -0
  140. data/share/views/public/plugins/tablesorter/docs/img/external.png +0 -0
  141. data/share/views/public/plugins/tablesorter/docs/index.html +576 -0
  142. data/share/views/public/plugins/tablesorter/docs/js/docs.js +23 -0
  143. data/share/views/public/plugins/tablesorter/docs/js/examples.js +29 -0
  144. data/share/views/public/plugins/tablesorter/jquery-latest.js +154 -0
  145. data/share/views/public/plugins/tablesorter/jquery.metadata.js +122 -0
  146. data/share/views/public/plugins/tablesorter/jquery.tablesorter.js +1031 -0
  147. data/share/views/public/plugins/tablesorter/jquery.tablesorter.min.js +4 -0
  148. data/share/views/public/plugins/tablesorter/tests/assets/ajax-content.html +28 -0
  149. data/share/views/public/plugins/tablesorter/tests/cell.metadata.html +112 -0
  150. data/share/views/public/plugins/tablesorter/tests/checkbox.html +117 -0
  151. data/share/views/public/plugins/tablesorter/tests/colspan.html +149 -0
  152. data/share/views/public/plugins/tablesorter/tests/demo.html +353 -0
  153. data/share/views/public/plugins/tablesorter/tests/index.html +22 -0
  154. data/share/views/public/plugins/tablesorter/tests/large.html +30 -0
  155. data/share/views/public/plugins/tablesorter/tests/lockedOrder.html +355 -0
  156. data/share/views/public/plugins/tablesorter/tests/metadata.html +320 -0
  157. data/share/views/public/plugins/tablesorter/tests/multiple-headers.html +67 -0
  158. data/share/views/public/plugins/tablesorter/tests/pager.html +553 -0
  159. data/share/views/public/plugins/tablesorter/themes/blue/asc.gif +0 -0
  160. data/share/views/public/plugins/tablesorter/themes/blue/bg.gif +0 -0
  161. data/share/views/public/plugins/tablesorter/themes/blue/blue.zip +0 -0
  162. data/share/views/public/plugins/tablesorter/themes/blue/desc.gif +0 -0
  163. data/share/views/public/plugins/tablesorter/themes/blue/style.css +39 -0
  164. data/share/views/public/plugins/tablesorter/themes/green/asc.png +0 -0
  165. data/share/views/public/plugins/tablesorter/themes/green/bg.png +0 -0
  166. data/share/views/public/plugins/tablesorter/themes/green/desc.png +0 -0
  167. data/share/views/public/plugins/tablesorter/themes/green/green.zip +0 -0
  168. data/share/views/public/plugins/tablesorter/themes/green/style.css +39 -0
  169. data/share/views/public/plugins/wz_jsgraphics.js +1108 -0
  170. data/share/views/public/tmp/foo +0 -0
  171. data/share/views/result.haml +6 -1
  172. data/share/views/step_error.haml +5 -0
  173. data/share/views/user_lists.haml +8 -7
  174. data/share/views/wait.haml +40 -2
  175. metadata +302 -106
  176. data/share/views/compass/screen.sass +0 -8
  177. data/share/views/public/plugins/jquery/js/jquery-1.6.2.min.js +0 -18
@@ -0,0 +1,125 @@
1
+ require 'redcarpet/compat'
2
+ module Sinatra
3
+ module SinatraRbbt
4
+
5
+ #{{{ Locating markup
6
+
7
+ def user_notes(user = nil)
8
+ notes = {}
9
+ Dir.glob(File.join(*[settings.note_dir, user, '/**/*'].compact)).each do |path|
10
+ next if File.directory? path
11
+ path.sub!(/.*?notes\//,'')
12
+ path.sub!(/^#{user}\//,'') if user
13
+ notes[path] = '/notes/' + path
14
+ end
15
+ notes
16
+ end
17
+
18
+ def shared_notes(user)
19
+ notes = {}
20
+ Dir.glob(File.join(*[settings.note_dir, user, '.shared', '/**/*'].compact)).each do |path|
21
+ next if File.directory? path
22
+ path.sub!(/.*?notes\//,'')
23
+ path.sub!(/^#{user}\/.shared\//,'')
24
+ notes[path] = "/notes/shared/#{ user }/" + path
25
+ end
26
+ notes
27
+ end
28
+
29
+ def notes_filepath(path, params, user = nil, shared = false)
30
+ path = 'news' if path.empty?
31
+ if user and shared
32
+ filepath = File.join(*[settings.note_dir, user, '.shared', path].compact)
33
+ else
34
+ filepath = File.join(*[settings.note_dir, user, path].compact)
35
+ end
36
+
37
+ filepath = File.expand_path(filepath)
38
+ raise "Ilegal: #{ path }" unless Misc.path_relative_to(settings.note_dir, filepath)
39
+
40
+
41
+ params.delete('_update')
42
+ params.delete('_')
43
+
44
+ layout = params.delete('_layout')
45
+ layout = false if params.delete(:_xhr) and layout.nil?
46
+ layout = true if layout.nil?
47
+
48
+ filepath << "?" << Misc.hash2GET_params(params) if params.any?
49
+
50
+ [filepath, layout]
51
+ end
52
+
53
+ def get_notes_markup(path, params, user = nil, shared = false)
54
+ filepath, layout = notes_filepath(path, params, user, shared)
55
+ Open.read(filepath) rescue ""
56
+ end
57
+
58
+ def delete_notes_markup(path, params, user = nil, shared = false)
59
+ filepath, layout = notes_filepath(path, params, user, shared)
60
+ FileUtils.rm(filepath) rescue ""
61
+ end
62
+
63
+ def save_notes(path, params, markup, user = nil)
64
+ filepath, layout = notes_filepath(path, params, user)
65
+ Open.write(filepath, markup)
66
+ end
67
+
68
+ def share_notes(path, params, markup, user = nil)
69
+ filepath, layout = notes_filepath(path, params, user, false)
70
+ shared_filepath, layout = notes_filepath(path, params, user, true)
71
+ FileUtils.mkdir_p(File.dirname(shared_filepath)) unless File.exists? File.dirname(shared_filepath)
72
+ FileUtils.ln_s(filepath, shared_filepath)
73
+ end
74
+
75
+ def unshare_notes(path, params, markup, user = nil)
76
+ shared_filepath, layout = notes_filepath(path, params, user, true)
77
+ FileUtils.rm(shared_filepath)
78
+ end
79
+
80
+
81
+ #{{{ Processing markup
82
+
83
+ def gene_links(markup)
84
+ markup.gsub(/Gene ([^\s]+)/) do |gene|
85
+ Gene.setup($1, "Associated Gene Name", "Hsa/jun2011").ensembl.link
86
+ end
87
+ end
88
+
89
+ def kegg_links(markup)
90
+ markup.gsub(/KEGG:"([^"]+)"/) do |match|
91
+ pathway = KEGG.name2id($1).select{|id| id =~ /^hsa/}.first
92
+ if pathway
93
+ KeggPathway.setup(pathway, "Hsa/jun2011").link
94
+ else
95
+ match
96
+ end
97
+ end
98
+ end
99
+
100
+ def render_notes(path, params, user = nil, shared = false)
101
+ html_header = ""
102
+ html_header += "<a class='back_note' href='#{ request.env['REQUEST_URI'].sub(/\/notes/, '').sub(/^\/shared\/\w+\//, '/')}'>Page</a>\n\n" unless path == 'news'
103
+ if request.env['REQUEST_URI'].sub(/\/notes/, '') !~ /^\/shared\//
104
+ html_header += "<a class='edit_note' href='#{ request.env['REQUEST_URI'].sub(/\/notes/, '/notes/edit')}' >Edit</a>\n"
105
+ html_header += "<a class='delete_note DELETE' href='#{ request.env['REQUEST_URI'].sub(/\/notes/, '/notes')}'>Delete</a>\n\n"
106
+ end
107
+
108
+ markup = get_notes_markup(path, params, user, shared)
109
+
110
+ markup = gene_links(markup)
111
+ markup = kegg_links(markup)
112
+ engine = Markdown
113
+ if layout
114
+ workflow_render("layout", nil, nil, params) do
115
+ html_header + "<div class='note'>" + engine.new(markup).to_html + "</div>"
116
+ end
117
+ else
118
+ html_header + "<div class='note'>" + engine.new(markup).to_html + "</div>"
119
+ end
120
+ end
121
+
122
+ end
123
+ end
124
+
125
+
@@ -3,8 +3,14 @@ require 'rbbt/entity'
3
3
  module RbbtHTMLHelpers
4
4
  PAGESIZE = 25
5
5
 
6
- def self.locate_file(workflow, task, file)
7
- file = case
6
+ class << self
7
+ attr_accessor :default_workflow_views
8
+ end
9
+
10
+ class TemplateNotFoundError < StandardError; end
11
+
12
+ def self.locate_file(workflow, task, file, entity = nil)
13
+ fixed_file = case
8
14
  when file =~ /\.[a-z]{2,4}$/
9
15
  file
10
16
  when file =~ /(.*)\/$/
@@ -13,68 +19,65 @@ module RbbtHTMLHelpers
13
19
  file + '.haml'
14
20
  end
15
21
 
16
- webapp_dir_views = Rbbt.www.views.find(:lib, Sinatra::Application.root)
17
- workflow_dir_views = (workflow.nil? or workflow.libdir.nil?) ? nil : workflow.libdir.www.views
18
- global_views = Rbbt.share.views
19
-
20
- # workflow = workflow.to_s unless workflow.nil? or String === workflow
22
+ if File.exists? file
23
+ path = Path.setup(File.join('.', file))
24
+ Log.debug "File #{[workflow, task, file, entity].collect{|v| "'#{ v }'"} * ", "} located at #{ path }"
25
+ return path
26
+ end
21
27
 
22
28
  path = nil
23
- [webapp_dir_views, workflow_dir_views, global_views].compact.each do |resource|
24
- path = case
25
- when resource[workflow][task][file].exists?
26
- resource[workflow][task][file]
27
- when resource[task][file].exists?
28
- resource[task][file]
29
- when resource[workflow][file].exists?
30
- resource[workflow][file]
31
- when resource[file].exists?
32
- resource[file]
33
- end
29
+ [file, fixed_file].uniq.each do |f|
30
+
31
+ webapp_views = Rbbt.www.views.find(:lib, Sinatra::Application.root)
32
+ global_views = Rbbt.share.views
33
+
34
+ workflow_views = case
35
+ when (not workflow.nil? and workflow.respond_to? :libdir and not Path === workflow.libdir)
36
+ workflow.libdir.www.views
37
+ when Path === default_workflow_views
38
+ default_workflow_views
39
+ else
40
+ nil
41
+ end
42
+
43
+ entity_views = case
44
+ when Path === entity
45
+ entity
46
+ when Resource === entity
47
+ entity.www.views
48
+ when (Workflow === entity and not entity.libdir.nil?)
49
+ entity.libdir.www.views
50
+ else
51
+ nil
52
+ end
53
+
54
+ [webapp_views, entity_views, workflow_views, global_views].compact.each do |resource_path|
55
+
56
+ path = case
57
+ when resource_path[workflow][task][f].exists?
58
+ resource_path[workflow][task][f]
59
+ when resource_path[task][f].exists?
60
+ resource_path[task][f]
61
+ when resource_path[workflow][f].exists?
62
+ resource_path[workflow][f]
63
+ when resource_path[f].exists?
64
+ resource_path[f]
65
+ end
66
+
67
+ break unless path.nil?
68
+ end
34
69
  break unless path.nil?
35
70
  end
36
71
 
37
- # path = case
38
- # when webapp_dir_views[workflow][task][file].exists?
39
- # webapp_dir_views[workflow][task][file]
40
- # when webapp_dir_views[task][file].exists?
41
- # webapp_dir_views[task][file]
42
- # when webapp_dir_views[workflow][file].exists?
43
- # webapp_dir_views[workflow][file]
44
- # when webapp_dir_views[file].exists?
45
- # webapp_dir_views[file]
46
- #
47
- # when (not workflow_dir_views.nil? and workflow_dir_views[workflow][task][file].exists?)
48
- # workflow_dir_views[workflow][task][file]
49
- # when (not workflow_dir_views.nil? and workflow_dir_views[task][file].exists?)
50
- # workflow_dir_views[task][file]
51
- # when (not workflow_dir_views.nil? and workflow_dir_views[workflow][file].exists?)
52
- # workflow_dir_views[workflow][file]
53
- # when (not workflow_dir_views.nil? and workflow_dir_views[file].exists?)
54
- # workflow_dir_views[file]
55
- #
56
- # when global_views[workflow][task][file].exists?
57
- # global_views[workflow][task][file]
58
- # when global_views[task][file].exists?
59
- # global_views[task][file]
60
- # when global_views[workflow][file].exists?
61
- # global_views[workflow][file]
62
- # when global_views[file].exists?
63
- # global_views[file]
64
- # else
65
- # raise "File not found: #{[workflow, task, file].compact * ", "}"
66
- # end
67
-
68
- raise "File not found: #{[workflow, task, file].compact * ", "}" if path.nil?
69
- Log.debug "File #{[workflow, task, file].collect{|v| "'#{ v }'"} * ", "} located at #{ path }"
72
+ raise TemplateNotFoundError, "File not found: #{[workflow, task, file, entity].compact * ", "}" if path.nil?
73
+ Log.debug "File #{[workflow, task, file, entity].collect{|v| "'#{ v }'"} * ", "} located at #{ path }"
70
74
  path
71
75
  end
72
76
 
73
- def locate_file(workflow, task, file)
74
- RbbtHTMLHelpers.locate_file(workflow, task, file)
77
+ def locate_file(*args)
78
+ RbbtHTMLHelpers.locate_file(*args)
75
79
  end
76
80
 
77
-
78
81
  def parse_page(page)
79
82
  field, num, size = page.split("~").values_at 0, 1, 2
80
83
  if num.nil?
@@ -180,7 +183,7 @@ module RbbtHTMLHelpers
180
183
 
181
184
  locals = Misc.add_defaults locals, :workflow => workflow, :task => task
182
185
 
183
- renderer = Haml::Engine.new(path.read)
186
+ renderer = Haml::Engine.new(path.read, :filename => path.find)
184
187
 
185
188
  case
186
189
  when (not layout)
@@ -215,6 +218,7 @@ module RbbtHTMLHelpers
215
218
  def workflow_render_result(result, *args)
216
219
  options = Hash === args.last ? args.pop : {}
217
220
 
221
+
218
222
  case args.length
219
223
  when 0
220
224
  workflow = options[:workflow]
@@ -231,22 +235,32 @@ module RbbtHTMLHelpers
231
235
  format = options[:_format]
232
236
  page = options[:_page]
233
237
 
238
+ # This part might be redundant!!!!
234
239
  case
235
240
  when format.to_sym == :raw
236
241
  content_type "text/plain"
237
- if Array === result
242
+ case
243
+ when options[:result_type] == :annotations
244
+ Annotated.tsv(result, :all).to_s
245
+ when Array === result
238
246
  result * "\n"
239
247
  else
240
248
  result.to_s
241
249
  end
242
250
  when format.to_sym == :json
243
251
  content_type "application/json"
244
- if TSV === result
252
+
253
+ case
254
+ when TSV === result
245
255
  result = paginate(result, page)
246
- result.to_json
256
+ result.dup.to_json
257
+ when options[:result_type] == :annotations
258
+ Annotated.json(result, true)
247
259
  else
248
260
  result.to_json
249
261
  end
262
+
263
+ # This might be the only actual option
250
264
  when format.to_sym == :html
251
265
  content_type "text/html"
252
266
  options = Misc.add_defaults options, workflow.task_info(task)
@@ -257,61 +271,18 @@ module RbbtHTMLHelpers
257
271
  end
258
272
  end
259
273
 
260
- def entity_render(type, locals, &block)
261
- type, format = type.split ":"
262
-
263
- size = locals.delete(:_size) || locals.delete("_size") || :normal
264
-
265
- entity = locals[:entity]
266
-
267
-
274
+ def setup_entity(entity_type, format, entity, locals = {})
268
275
  entity_class = case
269
276
  when Entity.formats.include?(format)
270
277
  Entity.formats[format]
271
- when Entity.formats.include?(type)
272
- Entity.formats[type]
278
+ when Entity.formats.include?(entity_type)
279
+ Entity.formats[entity_type]
273
280
  else
274
281
  nil
275
282
  end
276
283
 
277
- workflow = Workflow === entity_class ? entity_class : WorkflowREST.workflows.last
278
-
279
- path = case
280
- when (entity.respond_to? :template and not entity.template.nil?)
281
- entity.template
282
- when (entity_class.respond_to? :template and not entity_class.template.nil?)
283
- entity_class.template
284
- else
285
- path = nil
286
-
287
- [format, type].compact.each do |file|
288
- break unless path.nil?
289
- begin
290
- case size.to_sym
291
- when :normal
292
- file = File.join('entity', file + '.haml')
293
- path = locate_file(workflow, nil, file)
294
- when :small
295
- begin
296
- file_small = File.join('entity', file + '.small.haml')
297
- path = locate_file(workflow, nil, file_small)
298
- rescue
299
- Log.debug $!.message
300
- file = File.join('entity', file + '.haml')
301
- path = locate_file(workflow, nil, file)
302
- end
303
- end
304
- rescue
305
- next
306
- end
307
- end
308
- raise "Template not found for type, format: #{[type, format] * ", "}" if path.nil?
309
-
310
- path
311
- end
312
-
313
284
  if entity_class
314
- entity_class.setup(entity, *locals.values_at(*entity_class.annotations).collect{|v|
285
+ entity_class.setup(entity, *locals.values_at(*entity_class.all_annotations).collect{|v|
315
286
  case v
316
287
  when "false"
317
288
  false
@@ -324,11 +295,71 @@ module RbbtHTMLHelpers
324
295
  entity.format = format if entity.respond_to? :format
325
296
  end
326
297
 
298
+ entity
299
+ end
300
+
301
+ def entity_render(entity_type, locals, &block)
302
+ entity_type, format = entity_type.split ":"
303
+
304
+ size = locals.delete(:_size) || locals.delete("_size") || :normal
305
+
306
+ entity = setup_entity(entity_type, format, locals[:entity], locals)
307
+
308
+ entity_class = case
309
+ when Entity.formats.include?(format)
310
+ Entity.formats[format]
311
+ when Entity.formats.include?(entity_type)
312
+ Entity.formats[entity_type]
313
+ else
314
+ nil
315
+ end
316
+
317
+ workflow = WorkflowREST.workflows.last
318
+
319
+ path = nil
320
+ begin
321
+ entity_resources = []
322
+ entity_resources << entity.template if entity.respond_to? :template
323
+ entity_resources << entity if Resource === entity or Workflow === entity
324
+ entity_resources << entity_class.template if entity_class.respond_to? :template
325
+ entity_resources << entity_class if Resource === entity_class or Workflow === entity_class
326
+ entity_resources << [nil]
327
+
328
+ entity_resources.each do |entity_resource|
329
+ [format, entity_type].compact.each do |name|
330
+
331
+ begin
332
+ case size.to_sym
333
+ when :normal
334
+ file = File.join('entity', name + '.haml')
335
+ path = locate_file(workflow, nil, file, entity_resource)
336
+ when :small
337
+ file_small = File.join('entity', name + '.small.haml')
338
+ path = locate_file(workflow, nil, file_small, entity_resource)
339
+ end
340
+ rescue TemplateNotFoundError
341
+ next
342
+ end
343
+
344
+ break unless path.nil?
345
+ end
346
+ break unless path.nil?
347
+ end
348
+ raise TemplateNotFoundError if path.nil?
349
+ rescue TemplateNotFoundError
350
+ if size.to_sym == :small
351
+ size = :normal
352
+ retry
353
+ end
354
+ end
355
+
356
+ raise "Template not found for type, format: #{[entity_type, format] * ", "}" if path.nil?
357
+
327
358
  layout = locals[:_layout]
328
359
  layout = false if locals[:_xhr] and layout.nil?
329
360
  layout = true if layout.nil?
330
361
 
331
- renderer = Haml::Engine.new(path.read)
362
+ renderer = Haml::Engine.new(path.read, :filename => path.find)
332
363
 
333
364
  case
334
365
  when (not layout)
@@ -342,76 +373,71 @@ module RbbtHTMLHelpers
342
373
  end
343
374
  end
344
375
 
345
- def entity_action_render(type, action, locals, &block)
346
- type, format = type.split ":"
376
+ def entity_action_render(entity_type, action, locals, &block)
377
+ entity_type, format = entity_type.split ":"
378
+
379
+ locals[:entity_type] = entity_type
380
+ locals[:action] = action
381
+
347
382
 
348
383
  size = locals.delete(:_size) || locals.delete("_size") || :normal
349
- entity = locals[:entity]
384
+ entity = setup_entity(entity_type, format, locals[:entity], locals)
350
385
 
351
386
  entity_class = case
352
387
  when Entity.formats.include?(format)
353
388
  Entity.formats[format]
354
- when Entity.formats.include?(type)
355
- Entity.formats[type]
389
+ when Entity.formats.include?(entity_type)
390
+ Entity.formats[entity_type]
356
391
  else
357
392
  nil
358
393
  end
359
394
 
360
- workflow = Workflow === entity_class ? entity_class : WorkflowREST.workflows.last
361
-
362
- path = case
363
- when (entity.respond_to? :action_template and Hash === entity.action_template and not entity.action_template[action].nil?)
364
- entity.action_template[action]
365
- when (entity_class.respond_to? :action_template and Hash === entity_class.action_template and not entity_class.action_template[action].nil?)
366
- entity_class.action_template[action]
367
- else
368
- path = nil
369
-
370
- [format, type].compact.each do |file|
371
- break unless path.nil?
372
- file = File.join(file, action)
373
- begin
374
- case size.to_sym
375
- when :normal
376
- file = File.join('entity', file + '.haml')
377
- path = locate_file(workflow, nil, file)
378
- when :small
379
- begin
380
- file_small = File.join('entity', file + '.small.haml')
381
- path = locate_file(workflow, nil, file_small)
382
- rescue
383
- Log.debug $!.message
384
- file = File.join('entity', file + '.haml')
385
- path = locate_file(workflow, nil, file)
386
- end
387
- end
388
- rescue
389
- next
390
- end
391
- end
392
- raise "Action Template not found for type, format, action: #{[type, format, action] * ", "}" if path.nil?
393
- path
394
- end
395
+ workflow = WorkflowREST.workflows.last
395
396
 
396
- if entity_class
397
- entity_class.setup(entity, *locals.values_at(*entity_class.annotations).collect{|v|
398
- case v
399
- when "false"
400
- false
401
- when "true"
402
- true
403
- else
404
- v
397
+ path = nil
398
+ begin
399
+ entity_resources = []
400
+ entity_resources << entity.action_template if entity.respond_to? :action_template
401
+ entity_resources << entity if Resource === entity or Workflow === entity
402
+ entity_resources << entity_class.action_template if entity_class.respond_to? :action_template
403
+ entity_resources << entity_class if Resource === entity_class or Workflow === entity_class
404
+ entity_resources << [nil]
405
+
406
+ entity_resources.each do |entity_resource|
407
+ [format, entity_type].compact.each do |name|
408
+
409
+ begin
410
+ case size.to_sym
411
+ when :normal
412
+ file = File.join('entity', name, action + '.haml')
413
+ path = locate_file(workflow, nil, file, entity_resource)
414
+ when :small
415
+ file_small = File.join('entity', name, action + '.small.haml')
416
+ path = locate_file(workflow, nil, file_small, entity_resource)
417
+ end
418
+ rescue TemplateNotFoundError
419
+ next
420
+ end
421
+
422
+ break unless path.nil?
405
423
  end
406
- })
407
- entity.format = format if entity.respond_to? :format
424
+ break unless path.nil?
425
+ end
426
+ raise TemplateNotFoundError if path.nil?
427
+ rescue TemplateNotFoundError
428
+ if size.to_sym == :small
429
+ size = :normal
430
+ retry
431
+ end
408
432
  end
409
433
 
434
+ raise "Action template not found for type, format: #{[entity_type, format] * ", "}: #{ action }" if path.nil?
435
+
410
436
  layout = locals[:_layout]
411
437
  layout = false if locals[:_xhr] and layout.nil?
412
438
  layout = true if layout.nil?
413
439
 
414
- renderer = Haml::Engine.new(path.read)
440
+ renderer = Haml::Engine.new(path.read, :filename => path.find)
415
441
 
416
442
  case
417
443
  when (not layout)
@@ -425,65 +451,71 @@ module RbbtHTMLHelpers
425
451
  end
426
452
  end
427
453
 
428
- def entity_list_render(type, locals, &block)
429
- type, format = type.split ":"
454
+ def entity_list_render(entity_type, locals, &block)
455
+ entity_type, format = entity_type.split ":"
430
456
 
431
457
  size = locals.delete(:_size) || locals.delete("_size") || :normal
432
458
 
433
- locals[:type] = type
459
+ locals[:entity_type] = entity_type
434
460
  locals[:format] = format
435
461
 
436
- list = locals[:list] = Entity::REST.load_list(locals[:type], locals[:id], user)
462
+ list = locals[:list] = Entity::REST.load_list(locals[:entity_type], locals[:id], user)
437
463
 
438
464
  entity_class = case
439
465
  when Entity.formats.include?(format)
440
466
  Entity.formats[format]
441
- when Entity.formats.include?(type)
442
- Entity.formats[type]
467
+ when Entity.formats.include?(entity_type)
468
+ Entity.formats[entity_type]
443
469
  else
444
470
  nil
445
471
  end
446
472
 
447
- workflow = Workflow === entity_class ? entity_class : WorkflowREST.workflows.last
448
-
449
- path = case
450
- when (list.respond_to? :list_template and not list.list_template.nil?)
451
- list.list_template
452
- when (entity_class.respond_to? :list_template and not entity_class.list_template.nil?)
453
- entity_class.list_template
454
- else
455
- path = nil
456
-
457
- [format, type, "Default"].compact.each do |file|
458
- break unless path.nil?
459
- begin
460
- case size.to_sym
461
- when :normal
462
- file = File.join('entity_list', file + '.haml')
463
- path = locate_file(workflow, nil, file)
464
- when :small
465
- begin
466
- file_small = File.join('entity_list', file + '.small.haml')
467
- path = locate_file(workflow, nil, file_small)
468
- rescue
469
- Log.debug $!.message
470
- file = File.join('entity_list', file + '.haml')
471
- path = locate_file(workflow, nil, file)
472
- end
473
- end
474
- rescue
475
- next
476
- end
477
- end
478
- raise "List template not found for type, format: #{[type, format] * ", "}" if path.nil?
479
- path
480
- end
473
+ workflow = WorkflowREST.workflows.last
474
+
475
+ path = nil
476
+ begin
477
+ entity_resources = []
478
+ entity_resources << list.list_template if list.respond_to? :list_template
479
+ entity_resources << list if Resource === list or Workflow === list
480
+ entity_resources << entity_class.list_template if entity_class.respond_to? :list_template
481
+ entity_resources << entity_class if Resource === entity_class or Workflow === entity_class
482
+ entity_resources << [nil]
483
+
484
+ entity_resources.each do |entity_resource|
485
+ [format, entity_type, "Default"].compact.each do |name|
486
+
487
+ begin
488
+ case size.to_sym
489
+ when :normal
490
+ file = File.join('entity_list', name + '.haml')
491
+ path = locate_file(workflow, nil, file, entity_resource)
492
+ when :small
493
+ file_small = File.join('entity_list', name + '.small.haml')
494
+ path = locate_file(workflow, nil, file_small, entity_resource)
495
+ end
496
+ rescue TemplateNotFoundError
497
+ next
498
+ end
499
+
500
+ break unless path.nil?
501
+ end
502
+ break unless path.nil?
503
+ end
504
+ raise TemplateNotFoundError if path.nil?
505
+ rescue TemplateNotFoundError
506
+ if size.to_sym == :small
507
+ size = :normal
508
+ retry
509
+ end
510
+ end
511
+
512
+ raise "List template not found for type, format: #{[entity_type, format] * ", "}" if path.nil?
481
513
 
482
514
  layout = locals[:_layout]
483
515
  layout = false if locals[:_xhr] and layout.nil?
484
516
  layout = true if layout.nil?
485
517
 
486
- renderer = Haml::Engine.new(path.read)
518
+ renderer = Haml::Engine.new(path.read, :filename => path.find)
487
519
 
488
520
  case
489
521
  when (not layout)
@@ -499,64 +531,72 @@ module RbbtHTMLHelpers
499
531
 
500
532
 
501
533
 
502
- def entity_list_action_render(type, action, locals, &block)
503
- type, format = type.split ":"
534
+ def entity_list_action_render(entity_type, action, locals, &block)
535
+ entity_type, format = entity_type.split ":"
536
+
537
+ locals[:entity_type] = entity_type
538
+ locals[:action] = action
504
539
 
505
540
  size = locals.delete(:_size) || locals.delete("_size") || :normal
506
541
 
507
- list = locals[:list] = Entity::REST.load_list(type, locals[:id], user)
508
- locals[:type] = type
542
+ list = locals[:list] = Entity::REST.load_list(entity_type, locals[:id], user)
509
543
 
510
544
  entity_class = case
511
545
  when Entity.formats.include?(format)
512
546
  Entity.formats[format]
513
- when Entity.formats.include?(type)
514
- Entity.formats[type]
547
+ when Entity.formats.include?(entity_type)
548
+ Entity.formats[entity_type]
515
549
  else
516
550
  nil
517
551
  end
518
552
 
519
- workflow = Workflow === entity_class ? entity_class : WorkflowREST.workflows.last
553
+ workflow = WorkflowREST.workflows.last
554
+
555
+ path = nil
556
+ begin
557
+ entity_resources = []
558
+ entity_resources << list.list_action_template if list.respond_to? :list_action_template
559
+ entity_resources << list if Resource === list or Workflow === list
560
+ entity_resources << entity_class.list_action_template if entity_class.respond_to? :list_action_template
561
+ entity_resources << entity_class if Resource === entity_class or Workflow === entity_class
562
+ entity_resources << [nil]
563
+
564
+ entity_resources.each do |entity_resource|
565
+ [format, entity_type, "Default"].compact.each do |name|
566
+
567
+ begin
568
+ case size.to_sym
569
+ when :normal
570
+ file = File.join('entity_list', name, action + '.haml')
571
+ path = locate_file(workflow, nil, file, entity_resource)
572
+ when :small
573
+ file_small = File.join('entity_list', name, action + '.small.haml')
574
+ path = locate_file(workflow, nil, file_small, entity_resource)
575
+ end
576
+ rescue TemplateNotFoundError
577
+ next
578
+ end
579
+
580
+ break unless path.nil?
581
+ end
582
+ break unless path.nil?
583
+ end
584
+ raise TemplateNotFoundError if path.nil?
585
+ rescue TemplateNotFoundError
586
+ if size.to_sym == :small
587
+ size = :normal
588
+ retry
589
+ end
590
+ end
591
+
592
+ raise "List action template not found for type, format: #{[entity_type, format] * ", "}: #{ action }" if path.nil?
520
593
 
521
- path = case
522
- when (list.respond_to? :list_action_template and Hash === list.list_action_template and not list.list_action_template[action].nil?)
523
- list.list_action_template[action]
524
- when (entity_class.respond_to? :list_action_template and Hash === entity_class.list_action_template and not entity_class.list_action_template[action].nil?)
525
- entity_class.list_action_template[action]
526
- else
527
- path = nil
528
-
529
- [format, type].compact.each do |file|
530
- break unless path.nil?
531
- file = File.join(file, action)
532
- begin
533
- case size.to_sym
534
- when :normal
535
- file = File.join('entity_list', file + '.haml')
536
- path = locate_file(workflow, nil, file)
537
- when :small
538
- begin
539
- file_small = File.join('entity_list', file + '.small.haml')
540
- path = locate_file(workflow, nil, file_small)
541
- rescue
542
- Log.debug $!.message
543
- file = File.join('entity_list', file + '.haml')
544
- path = locate_file(workflow, nil, file)
545
- end
546
- end
547
- rescue
548
- next
549
- end
550
- end
551
- raise "List Template not found for type, format: #{[type, format] * ", "}" if path.nil?
552
- path
553
- end
554
594
 
555
595
  layout = locals[:_layout]
556
596
  layout = false if locals[:_xhr] and layout.nil?
557
597
  layout = true if layout.nil?
558
598
 
559
- renderer = Haml::Engine.new(path.read)
599
+ renderer = Haml::Engine.new(path.read, :filename => path.find)
560
600
 
561
601
  case
562
602
  when (not layout)