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
@@ -0,0 +1,38 @@
1
+
2
+ module RbbtHTMLHelpers
3
+ def input(type, name, options = {})
4
+ id, hide, value, klass, default, description = Misc.process_options options, :id, :hide, :value, :class, :default, :description
5
+ str = "<div class='form_input' id='#{ id }'>"
6
+
7
+ if hide
8
+ str << "<input #{"id='#{ id }'" if id} type='hidden' name='#{ name }' #{"class='#{ klass }'" if klass} #{"value='#{ value }'" if value}/>" << '</div>' << "\n"
9
+ return str
10
+ end
11
+
12
+ case type
13
+ when :boolean
14
+ not_value = ! value
15
+ str << "<label #{"for='#{ id }" if id}'><span class='input_name'>#{ name }</span>#{": <span class='input_description'>#{ description }</span>" if description}</label>" << "\n"
16
+ str << "<input type='radio' id='input_#{id}_true' name='#{ name }' value='true' #{"checked='true'" if value}>" << "\n"
17
+ str << "<label type='radio_option radio_true' for='input_#{id}_true' name='#{ name }'>true</label>" << "\n"
18
+ str << "<input type='radio' id='input_#{id}_false' name='#{ name }' value='false' #{"checked='false'" if not value}>" << "\n"
19
+ str << "<label type='radio_option radio_false' for='input_#{id}_false' name='#{ name }'>false</label>" << "\n"
20
+ str << "</div>"
21
+ str
22
+ when :string, :float, :integer
23
+ str << "<label #{"for='#{ id }" if id}'><span class='input_name'>#{ name }</span>#{": <span class='input_description'>#{ description }</span>" if description}#{": <span class='input_default'>(Default: #{ default })</span>" if default}</label>" << "\n"
24
+ str << "<input #{"class='#{klass ? klass : "#{ name } #{ type }" }'"} #{"id='#{ id }'" if id} name='#{ name }' #{"value='#{ value }'" if value}/>" << "\n"
25
+ str << "</div>"
26
+ str
27
+ when :tsv, :array, :text
28
+ str << "<label #{"for='#{ id }" if id}'><span class='input_name'>#{ name }</span>#{": <span class='input_description'>#{ description }</span>" if description}#{": <span class='input_default'>(Default: #{ default })</span>" if default}</label>" << "\n"
29
+ str << "<p>"
30
+ str << "<input type='file' #{"class='#{klass ? klass : "#{ name } #{ type }" }'"} #{"id='input_#{ id }_tsv_file'" if id} name='#{ name }_param_file' #{"value='#{ value }'" if value}/>" << "\n"
31
+ str << "<span class='tsv_textarea_note note'>(or use text area bellow)</span>"
32
+ str << "</p>"
33
+ str << "<textarea #{"class='#{klass ? klass : "#{ name } #{ type }" }'"} name='#{ name }' #{"id='input_#{ id }'" if id}></textarea>"
34
+ str << "</div>"
35
+ str
36
+ end
37
+ end
38
+ end
@@ -1,209 +1,588 @@
1
- require 'rbbt/workflow/rest/entity'
1
+ require 'rbbt/entity'
2
+
3
+ module RbbtHTMLHelpers
4
+ PAGESIZE = 25
5
+
6
+ def self.locate_file(workflow, task, file)
7
+ file = case
8
+ when file =~ /\.[a-z]{2,4}$/
9
+ file
10
+ when file =~ /(.*)\/$/
11
+ $1
12
+ else
13
+ file + '.haml'
14
+ end
15
+
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
21
+
22
+ path = case
23
+ when webapp_dir_views[workflow][task][file].exists?
24
+ webapp_dir_views[workflow][task][file]
25
+ when webapp_dir_views[task][file].exists?
26
+ webapp_dir_views[task][file]
27
+ when webapp_dir_views[workflow][file].exists?
28
+ webapp_dir_views[workflow][file]
29
+ when webapp_dir_views[file].exists?
30
+ webapp_dir_views[file]
31
+
32
+ when (not workflow_dir_views.nil? and workflow_dir_views[workflow][task][file].exists?)
33
+ workflow_dir_views[workflow][task][file]
34
+ when (not workflow_dir_views.nil? and workflow_dir_views[task][file].exists?)
35
+ workflow_dir_views[task][file]
36
+ when (not workflow_dir_views.nil? and workflow_dir_views[workflow][file].exists?)
37
+ workflow_dir_views[workflow][file]
38
+ when (not workflow_dir_views.nil? and workflow_dir_views[file].exists?)
39
+ workflow_dir_views[file]
40
+
41
+ when global_views[workflow][task][file].exists?
42
+ global_views[workflow][task][file]
43
+ when global_views[task][file].exists?
44
+ global_views[task][file]
45
+ when global_views[workflow][file].exists?
46
+ global_views[workflow][file]
47
+ when global_views[file].exists?
48
+ global_views[file]
49
+ else
50
+ raise "File not found: #{[workflow, task, file].compact * ", "}"
51
+ end
52
+
53
+ Log.debug "File #{[workflow, task, file].collect{|v| "'#{ v }'"} * ", "} located at #{ path }"
54
+ path
55
+ end
2
56
 
3
- module Sinatra
4
- module SinatraRbbt
57
+ def locate_file(workflow, task, file)
58
+ RbbtHTMLHelpers.locate_file(workflow, task, file)
59
+ end
5
60
 
6
- PAGESIZE = 25
7
61
 
8
- def parse_page(page)
9
- field, num, size = page.split("~").values_at 0, 1, 2
10
- if num.nil?
11
- num = field
12
- field = "key"
13
- end
14
- size ||= PAGESIZE
15
- [field, num, size]
62
+ def parse_page(page)
63
+ field, num, size = page.split("~").values_at 0, 1, 2
64
+ if num.nil?
65
+ num = field
66
+ field = "key"
16
67
  end
68
+ size ||= PAGESIZE
69
+ [field, num, size]
70
+ end
17
71
 
18
- def paginate(object, page = nil, just_keys = false)
19
- return object unless TSV === object and not page.nil?
72
+ def paginate(object, page = nil, just_keys = false)
73
+ return object unless TSV === object and not page.nil?
20
74
 
21
- page = "key~1~#{PAGESIZE}" if page.nil? and object.size > 100
22
- return object if page.nil? or page == "all"
23
- field, num, size = parse_page(page)
75
+ return object if page == "all" or page.nil?
76
+ field, num, size = parse_page(page)
24
77
 
25
- entity = Entity.formats[field]
78
+ entity = Entity.formats[field]
26
79
 
27
- num = num.to_i
28
- size = size.to_i
29
- max = object.size / size + 1
80
+ num = num.to_i
81
+ size = size.to_i
82
+ max = object.size / size + 1
30
83
 
31
- num = max if num > max
32
- num = - max if num < - max
84
+ num = max if num > max
85
+ num = - max if num < - max
33
86
 
34
- if entity and entity.respond_to? :tsv_sort
35
- object.page(num, size, field, just_keys, entity.method(:tsv_sort))
36
- else
37
- object.page(num, size, field, just_keys)
38
- end
87
+ if entity and entity.respond_to? :tsv_sort
88
+ object.page(num, size, field, just_keys, &entity.method(:tsv_sort))
89
+ else
90
+ object.page(num, size, field, just_keys)
39
91
  end
40
-
41
- def process_result(result, options)
42
- rows = result
43
-
44
- if options.include? :_filter and not options[:_filter].nil?
45
- field, query = options[:_filter].split("~")
46
-
47
- entity = Entity.formats[field]
48
-
49
- if entity and entity.respond_to?(:filter)
50
- filter_proc = entity.method :filter
51
- if filter_proc.respond_to? :curry
52
- curried_proc = filter_proc.curry(query, type, options.merge(:tsv => result, :field => field))
53
- else
54
- curried_proc = Proc.new{|entity|
55
- filter_proc.call(query, type, options.merge(:tsv => result, :field => field), entity)
56
- }
57
- end
58
- rows = rows.select field => curried_proc
92
+ end
93
+
94
+ def process_result(result, options)
95
+ rows = result
96
+
97
+ if options.include? :_filter and not options[:_filter].nil?
98
+ field, query = options[:_filter].split("~")
99
+
100
+ entity = Entity.formats[field]
101
+
102
+ if entity and entity.respond_to?(:filter)
103
+ filter_proc = entity.method :filter
104
+ if filter_proc.respond_to? :curry
105
+ curried_proc = filter_proc.curry(query, field, options.merge(:tsv => result, :field => field))
59
106
  else
60
- rows = rows.select field => Regexp.new(query)
107
+ curried_proc = Proc.new{|entity|
108
+ filter_proc.call(query, field, options.merge(:tsv => result, :field => field), entity)
109
+ }
61
110
  end
111
+ rows = rows.select field => curried_proc
112
+ else
113
+ rows = rows.select field => Regexp.new(query)
62
114
  end
115
+ end
63
116
 
64
- total = rows.size
117
+ total = rows.size
65
118
 
66
- if options.include? :_page and not options[:_page].nil?
67
- keys = paginate(rows, options[:_page], true)
68
-
69
- if keys
70
- rows = keys.zip(rows.values_at *keys)
71
- end
119
+ options[:_page] = "1" if rows.size > 100 and options[:_page].nil?
120
+ if options.include?(:_page) and not options[:_page].nil?
121
+ keys = paginate(rows, options[:_page], true)
72
122
 
123
+ if keys
124
+ rows = keys.zip(rows.values_at *keys)
73
125
  end
74
126
 
75
- [rows, total]
76
127
  end
77
128
 
78
- def workflow_render(workflow, task, file, locals = {}, &block)
79
- size = locals["_size"] || :normal
129
+ [rows, total]
130
+ end
131
+
132
+ #def workflow_render(file, workflow = nil, task = nil, locals = {}, &block)
133
+ def workflow_render(file, *args, &block)
134
+ locals = Hash === args.last ? args.pop : {}
135
+
136
+ case args.length
137
+ when 0
138
+ workflow = locals[:workflow]
139
+ task = locals[:task]
140
+ when 1
141
+ workflow = args.shift
142
+ task = locals[:task]
143
+ when 2
144
+ workflow = args.shift
145
+ task = args.shift
146
+ end
80
147
 
81
- case size.to_sym
82
- when :normal
148
+ size = locals.delete(:_size) || locals.delete("_size") || :normal
149
+
150
+ case size.to_sym
151
+ when :normal
152
+ path = locate_file(workflow, task, file)
153
+ when :small
154
+ begin
155
+ path = locate_file(workflow, task, file + '.small')
156
+ rescue
157
+ Log.debug $!.message
83
158
  path = locate_file(workflow, task, file)
84
- when :small
85
- begin
86
- path = locate_file(workflow, task, file + '.small')
87
- rescue
88
- Log.debug $!.message
89
- path = locate_file(workflow, task, file)
90
- end
91
159
  end
160
+ end
92
161
 
93
- layout = locals[:_layout]
94
- layout = false if request.xhr? and layout.nil?
95
-
96
- headers "AJAX-URL" => request.env["REQUEST_URI"]
162
+ layout = locals[:_layout]
163
+ layout = false if locals[:_xhr] and layout.nil?
164
+ layout = true if layout.nil?
97
165
 
98
- locals = Misc.add_defaults locals, :workflow => workflow, :task => task
166
+ locals = Misc.add_defaults locals, :workflow => workflow, :task => task
99
167
 
100
- renderer = Haml::Engine.new(path.read)
168
+ renderer = Haml::Engine.new(path.read)
101
169
 
102
- case
103
- when (not layout)
104
- renderer.render(self, locals, &block)
105
- when (not block_given?)
106
- workflow_render(workflow, task, "layout", locals) do
107
- renderer.render(self, locals)
108
- end
109
- else
110
- renderer.render(self, locals, &block)
170
+ case
171
+ when (not layout)
172
+ renderer.render(self, locals, &block)
173
+ when (not block_given?)
174
+ workflow_render("layout", workflow, task, locals) do
175
+ renderer.render(self, locals)
111
176
  end
177
+ else
178
+ renderer.render(self, locals, &block)
112
179
  end
180
+ end
181
+
182
+ def workflow_partial(file, *args)
183
+ locals = Hash === args.last ? args.pop : {}
184
+
185
+ case args.length
186
+ when 0
187
+ workflow = locals[:workflow]
188
+ task = locals[:task]
189
+ when 1
190
+ workflow = args.shift
191
+ task = locals[:task]
192
+ when 2
193
+ workflow = args.shift
194
+ task = args.shift
195
+ end
196
+
197
+ workflow_render(file, workflow, task, locals.merge(:_layout => false))
198
+ end
113
199
 
114
- def workflow_partial(workflow, task, file, locals = {})
115
- workflow_render(workflow, task, file, locals.merge(:_layout => false))
200
+ def workflow_render_result(result, *args)
201
+ options = Hash === args.last ? args.pop : {}
202
+
203
+ case args.length
204
+ when 0
205
+ workflow = options[:workflow]
206
+ task = options[:task]
207
+ when 1
208
+ workflow = args.shift
209
+ task = options[:task]
210
+ when 2
211
+ workflow = args.shift
212
+ task = args.shift
116
213
  end
117
214
 
118
- def workflow_render_result(workflow, task_name, result, options = {})
119
- format = options[:_format]
120
- page = options[:_page]
121
215
 
122
- case
123
- when format.to_sym == :raw
124
- content_type "text/plain"
125
- if Array === result
126
- result * "\n"
216
+ format = options[:_format]
217
+ page = options[:_page]
218
+
219
+ case
220
+ when format.to_sym == :raw
221
+ content_type "text/plain"
222
+ if Array === result
223
+ result * "\n"
224
+ else
225
+ result.to_s
226
+ end
227
+ when format.to_sym == :json
228
+ content_type "application/json"
229
+ if TSV === result
230
+ result = paginate(result, page)
231
+ result.to_json
232
+ else
233
+ result.to_json
234
+ end
235
+ when format.to_sym == :html
236
+ content_type "text/html"
237
+ options = Misc.add_defaults options, workflow.task_info(task)
238
+ options = Misc.add_defaults options, :result => result, :workflow => workflow, :task => task
239
+ workflow_render("result", workflow, task, options)
240
+ else
241
+ raise "Unkonwn format: #{format}"
242
+ end
243
+ end
244
+
245
+ def entity_render(type, locals, &block)
246
+ type, format = type.split ":"
247
+
248
+ size = locals.delete(:_size) || locals.delete("_size") || :normal
249
+
250
+ workflow = WorkflowREST.workflows.last
251
+
252
+ entity = locals[:entity]
253
+
254
+ entity_class = case
255
+ when Entity.formats.include?(format)
256
+ Entity.formats[format]
257
+ when Entity.formats.include?(type)
258
+ Entity.formats[type]
259
+ else
260
+ nil
261
+ end
262
+
263
+ path = case
264
+ when (entity.respond_to? :template and not entity.template.nil?)
265
+ entity.template
266
+ when (entity_class.respond_to? :template and not entity_class.template.nil?)
267
+ entity_class.template
268
+ else
269
+ path = nil
270
+
271
+ [format, type].compact.each do |file|
272
+ break unless path.nil?
273
+ begin
274
+ case size.to_sym
275
+ when :normal
276
+ file = File.join('entity', file + '.haml')
277
+ path = locate_file(workflow, nil, file)
278
+ when :small
279
+ begin
280
+ file_small = File.join('entity', file + '.small.haml')
281
+ path = locate_file(workflow, nil, file_small)
282
+ rescue
283
+ Log.debug $!.message
284
+ file = File.join('entity', file + '.haml')
285
+ path = locate_file(workflow, nil, file)
286
+ end
287
+ end
288
+ rescue
289
+ next
290
+ end
291
+ end
292
+ raise "Template not found for type, format: #{[type, format] * ", "}" if path.nil?
293
+
294
+ path
295
+ end
296
+
297
+ if entity_class
298
+ entity_class.setup(entity, *locals.values_at(*entity_class.annotations).collect{|v|
299
+ case v
300
+ when "false"
301
+ false
302
+ when "true"
303
+ true
127
304
  else
128
- result.to_s
305
+ v
129
306
  end
130
- when format.to_sym == :json
131
- content_type "application/json"
132
- if TSV === result
133
- result = paginate(result, page)
134
- result.to_json
307
+ })
308
+ entity.format = format if entity.respond_to? :format
309
+ end
310
+
311
+ layout = locals[:_layout]
312
+ layout = false if locals[:_xhr] and layout.nil?
313
+ layout = true if layout.nil?
314
+
315
+ renderer = Haml::Engine.new(path.read)
316
+
317
+ case
318
+ when (not layout)
319
+ renderer.render(self, locals, &block)
320
+ when (not block_given?)
321
+ workflow_render("layout", nil, nil, locals) do
322
+ renderer.render(self, locals)
323
+ end
324
+ else
325
+ renderer.render(self, locals, &block)
326
+ end
327
+ end
328
+
329
+ def entity_action_render(type, action, locals, &block)
330
+ type, format = type.split ":"
331
+
332
+ size = locals.delete(:_size) || locals.delete("_size") || :normal
333
+
334
+ workflow = WorkflowREST.workflows.last
335
+
336
+ entity = locals[:entity]
337
+
338
+ entity_class = case
339
+ when Entity.formats.include?(format)
340
+ Entity.formats[format]
341
+ when Entity.formats.include?(type)
342
+ Entity.formats[type]
343
+ else
344
+ nil
345
+ end
346
+
347
+ path = case
348
+ when (entity.respond_to? :action_template and Hash === entity.action_template and not entity.action_template[action].nil?)
349
+ entity.action_template[action]
350
+ when (entity_class.respond_to? :action_template and Hash === entity_class.action_template and not entity_class.action_template[action].nil?)
351
+ entity_class.action_template[action]
352
+ else
353
+ path = nil
354
+
355
+ [format, type].compact.each do |file|
356
+ break unless path.nil?
357
+ file = File.join(file, action)
358
+ begin
359
+ case size.to_sym
360
+ when :normal
361
+ file = File.join('entity', file + '.haml')
362
+ path = locate_file(workflow, nil, file)
363
+ when :small
364
+ begin
365
+ file_small = File.join('entity', file + '.small.haml')
366
+ path = locate_file(workflow, nil, file_small)
367
+ rescue
368
+ Log.debug $!.message
369
+ file = File.join('entity', file + '.haml')
370
+ path = locate_file(workflow, nil, file)
371
+ end
372
+ end
373
+ rescue
374
+ next
375
+ end
376
+ end
377
+ raise "Action Template not found for type, format, action: #{[type, format, action] * ", "}" if path.nil?
378
+ path
379
+ end
380
+
381
+ if entity_class
382
+ entity_class.setup(entity, *locals.values_at(*entity_class.annotations).collect{|v|
383
+ case v
384
+ when "false"
385
+ false
386
+ when "true"
387
+ true
135
388
  else
136
- result.to_json
389
+ v
137
390
  end
138
- when format.to_sym == :html
139
- content_type "text/html"
140
- options = Misc.add_defaults options, workflow.task_info(task_name)
141
- options = Misc.add_defaults options, :result => result, :workflow => workflow, :task_name => task_name
142
- workflow_render(workflow, task_name, "result", options)
143
- else
144
- raise "Unkonwn format: #{format}"
145
- end
391
+ })
392
+ entity.format = format if entity.respond_to? :format
146
393
  end
147
394
 
148
- def entity_render(type, locals, &block)
149
- type, format = type.split ":"
395
+ layout = locals[:_layout]
396
+ layout = false if locals[:_xhr] and layout.nil?
397
+ layout = true if layout.nil?
150
398
 
151
- size = locals["_size"] || :normal
399
+ renderer = Haml::Engine.new(path.read)
152
400
 
153
- if Entity.formats.include?(format) and not Entity.formats[format].template.nil? or
154
- Entity.formats.include?(type) and not Entity.formats[type].template.nil?
401
+ case
402
+ when (not layout)
403
+ renderer.render(self, locals, &block)
404
+ when (not block_given?)
405
+ workflow_render("layout", nil, nil, locals) do
406
+ renderer.render(self, locals)
407
+ end
408
+ else
409
+ renderer.render(self, locals, &block)
410
+ end
411
+ end
155
412
 
156
- path = Entity.formats[format || type].template
157
- else
158
- path = nil
159
-
160
- [format, type].each do |file|
161
- begin
162
- case size.to_sym
163
- when :normal
164
- file = File.join('entity', file + '.haml')
165
- path = locate_file(nil, nil, file)
166
- when :small
167
- begin
168
- file_small = File.join('entity', file + 'small.haml')
169
- path = locate_file(nil, nil, file_small)
170
- rescue
171
- Log.debug $!.message
172
- file = File.join('entity', file + '.haml')
173
- path = locate_file(nil, nil, file)
174
- end
175
- end
176
- rescue
177
- next
178
- end
413
+ def entity_list_render(type, locals, &block)
414
+ type, format = type.split ":"
415
+
416
+ size = locals.delete(:_size) || locals.delete("_size") || :normal
417
+
418
+ workflow = WorkflowREST.workflows.last
419
+
420
+ list = locals[:list] = Entity::REST.load_list(locals[:id])
421
+
422
+ entity_class = case
423
+ when Entity.formats.include?(format)
424
+ Entity.formats[format]
425
+ when Entity.formats.include?(type)
426
+ Entity.formats[type]
427
+ else
428
+ nil
429
+ end
430
+
431
+ path = case
432
+ when (list.respond_to? :list_template and not list.list_template.nil?)
433
+ list.list_template
434
+ when (entity_class.respond_to? :list_template and not entity_class.list_template.nil?)
435
+ entity_class.list_template
436
+ else
437
+ path = nil
438
+
439
+ [format, type].compact.each do |file|
440
+ break unless path.nil?
441
+ begin
442
+ case size.to_sym
443
+ when :normal
444
+ file = File.join('entity_list', file + '.haml')
445
+ path = locate_file(workflow, nil, file)
446
+ when :small
447
+ begin
448
+ file_small = File.join('entity_list', file + '.small.haml')
449
+ path = locate_file(workflow, nil, file_small)
450
+ rescue
451
+ Log.debug $!.message
452
+ file = File.join('entity_list', file + '.haml')
453
+ path = locate_file(workflow, nil, file)
454
+ end
455
+ end
456
+ rescue
457
+ next
458
+ end
459
+ end
460
+ raise "List Template not found for type, format: #{[type, format] * ", "}" if path.nil?
461
+ path
462
+ end
463
+
464
+ if entity_class
465
+ entity_class.setup(list, *locals.values_at(*entity_class.annotations).collect{|v|
466
+ case v
467
+ when "false"
468
+ false
469
+ when "true"
470
+ true
471
+ else
472
+ v
179
473
  end
474
+ })
475
+ list.format = format if list.respond_to? :format
476
+ end
180
477
 
181
- raise "Template not found for type, format: #{[type, format] * ", "}" if path.nil?
182
- end
478
+ layout = locals[:_layout]
479
+ layout = false if locals[:_xhr] and layout.nil?
480
+ layout = true if layout.nil?
183
481
 
184
- if (Entity.formats.include?(format) or Entity.formats.include?(type)) and locals[:entity]
185
- entity = Entity.formats[format || type]
186
- entity.setup(locals[:entity], *locals.values_at(*entity.annotations))
482
+ renderer = Haml::Engine.new(path.read)
483
+
484
+ case
485
+ when (not layout)
486
+ renderer.render(self, locals, &block)
487
+ when (not block_given?)
488
+ workflow_render("layout", nil, nil, locals) do
489
+ renderer.render(self, locals)
187
490
  end
491
+ else
492
+ renderer.render(self, locals, &block)
493
+ end
494
+ end
188
495
 
189
- layout = locals[:_layout]
190
- layout = false if request.xhr? and layout.nil?
496
+
497
+
498
+ def entity_list_action_render(type, action, locals, &block)
499
+ type, format = type.split ":"
500
+
501
+ size = locals.delete(:_size) || locals.delete("_size") || :normal
502
+
503
+ workflow = WorkflowREST.workflows.last
504
+
505
+ list = locals[:list] = Entity::REST.load_list(locals[:id])
506
+
507
+ entity_class = case
508
+ when Entity.formats.include?(format)
509
+ Entity.formats[format]
510
+ when Entity.formats.include?(type)
511
+ Entity.formats[type]
512
+ else
513
+ nil
514
+ end
515
+
516
+ path = case
517
+ when (list.respond_to? :list_action_template and Hash === list.list_action_template and not list.list_action_template[action].nil?)
518
+ list.list_action_template[action]
519
+ when (entity_class.respond_to? :list_action_template and Hash === entity_class.list_action_template and not entity_class.list_action_template[action].nil?)
520
+ entity_class.list_action_template[action]
521
+ else
522
+ path = nil
523
+
524
+ [format, type].compact.each do |file|
525
+ break unless path.nil?
526
+ file = File.join(file, action)
527
+ begin
528
+ case size.to_sym
529
+ when :normal
530
+ file = File.join('entity_list', file + '.haml')
531
+ path = locate_file(workflow, nil, file)
532
+ when :small
533
+ begin
534
+ file_small = File.join('entity_list', file + '.small.haml')
535
+ path = locate_file(workflow, nil, file_small)
536
+ rescue
537
+ Log.debug $!.message
538
+ file = File.join('entity_list', file + '.haml')
539
+ path = locate_file(workflow, nil, file)
540
+ end
541
+ end
542
+ rescue
543
+ next
544
+ end
545
+ end
546
+ raise "List Template not found for type, format: #{[type, format] * ", "}" if path.nil?
547
+ path
548
+ end
549
+
550
+ if entity_class
551
+ entity_class.setup(list, *locals.values_at(*entity_class.annotations).collect{|v|
552
+ case v
553
+ when "false"
554
+ false
555
+ when "true"
556
+ true
557
+ else
558
+ v
559
+ end
560
+ })
561
+ list.format = format if list.respond_to? :format
562
+ end
191
563
 
192
- headers "AJAX-URL" => request.env["REQUEST_URI"]
564
+ layout = locals[:_layout]
565
+ layout = false if locals[:_xhr] and layout.nil?
566
+ layout = true if layout.nil?
193
567
 
194
- renderer = Haml::Engine.new(path.read)
568
+ renderer = Haml::Engine.new(path.read)
195
569
 
196
- case
197
- when (not layout)
198
- renderer.render(self, locals, &block)
199
- when (not block_given?)
200
- entity_render(workflow, task, "layout", locals) do
201
- renderer.render(self, locals)
202
- end
203
- else
204
- renderer.render(self, locals, &block)
570
+ case
571
+ when (not layout)
572
+ renderer.render(self, locals, &block)
573
+ when (not block_given?)
574
+ workflow_render("layout", nil, nil, locals) do
575
+ renderer.render(self, locals)
205
576
  end
577
+ else
578
+ renderer.render(self, locals, &block)
206
579
  end
580
+
581
+ end
582
+ end
207
583
 
584
+ module Sinatra
585
+ module SinatraRbbt
586
+ include RbbtHTMLHelpers
208
587
  end
209
588
  end