rbbt-views 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -19,37 +19,53 @@ module RbbtHTMLHelpers
19
19
 
20
20
  # workflow = workflow.to_s unless workflow.nil? or String === workflow
21
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
22
+ 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
34
+ break unless path.nil?
35
+ end
52
36
 
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?
53
69
  Log.debug "File #{[workflow, task, file].collect{|v| "'#{ v }'"} * ", "} located at #{ path }"
54
70
  path
55
71
  end
@@ -129,7 +145,6 @@ module RbbtHTMLHelpers
129
145
  [rows, total]
130
146
  end
131
147
 
132
- #def workflow_render(file, workflow = nil, task = nil, locals = {}, &block)
133
148
  def workflow_render(file, *args, &block)
134
149
  locals = Hash === args.last ? args.pop : {}
135
150
 
@@ -247,10 +262,9 @@ module RbbtHTMLHelpers
247
262
 
248
263
  size = locals.delete(:_size) || locals.delete("_size") || :normal
249
264
 
250
- workflow = WorkflowREST.workflows.last
251
-
252
265
  entity = locals[:entity]
253
266
 
267
+
254
268
  entity_class = case
255
269
  when Entity.formats.include?(format)
256
270
  Entity.formats[format]
@@ -260,6 +274,8 @@ module RbbtHTMLHelpers
260
274
  nil
261
275
  end
262
276
 
277
+ workflow = Workflow === entity_class ? entity_class : WorkflowREST.workflows.last
278
+
263
279
  path = case
264
280
  when (entity.respond_to? :template and not entity.template.nil?)
265
281
  entity.template
@@ -330,9 +346,6 @@ module RbbtHTMLHelpers
330
346
  type, format = type.split ":"
331
347
 
332
348
  size = locals.delete(:_size) || locals.delete("_size") || :normal
333
-
334
- workflow = WorkflowREST.workflows.last
335
-
336
349
  entity = locals[:entity]
337
350
 
338
351
  entity_class = case
@@ -344,6 +357,8 @@ module RbbtHTMLHelpers
344
357
  nil
345
358
  end
346
359
 
360
+ workflow = Workflow === entity_class ? entity_class : WorkflowREST.workflows.last
361
+
347
362
  path = case
348
363
  when (entity.respond_to? :action_template and Hash === entity.action_template and not entity.action_template[action].nil?)
349
364
  entity.action_template[action]
@@ -415,9 +430,10 @@ module RbbtHTMLHelpers
415
430
 
416
431
  size = locals.delete(:_size) || locals.delete("_size") || :normal
417
432
 
418
- workflow = WorkflowREST.workflows.last
433
+ locals[:type] = type
434
+ locals[:format] = format
419
435
 
420
- list = locals[:list] = Entity::REST.load_list(locals[:id])
436
+ list = locals[:list] = Entity::REST.load_list(locals[:type], locals[:id], user)
421
437
 
422
438
  entity_class = case
423
439
  when Entity.formats.include?(format)
@@ -428,6 +444,8 @@ module RbbtHTMLHelpers
428
444
  nil
429
445
  end
430
446
 
447
+ workflow = Workflow === entity_class ? entity_class : WorkflowREST.workflows.last
448
+
431
449
  path = case
432
450
  when (list.respond_to? :list_template and not list.list_template.nil?)
433
451
  list.list_template
@@ -436,7 +454,7 @@ module RbbtHTMLHelpers
436
454
  else
437
455
  path = nil
438
456
 
439
- [format, type].compact.each do |file|
457
+ [format, type, "Default"].compact.each do |file|
440
458
  break unless path.nil?
441
459
  begin
442
460
  case size.to_sym
@@ -457,24 +475,10 @@ module RbbtHTMLHelpers
457
475
  next
458
476
  end
459
477
  end
460
- raise "List Template not found for type, format: #{[type, format] * ", "}" if path.nil?
478
+ raise "List template not found for type, format: #{[type, format] * ", "}" if path.nil?
461
479
  path
462
480
  end
463
481
 
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
473
- end
474
- })
475
- list.format = format if list.respond_to? :format
476
- end
477
-
478
482
  layout = locals[:_layout]
479
483
  layout = false if locals[:_xhr] and layout.nil?
480
484
  layout = true if layout.nil?
@@ -493,16 +497,15 @@ module RbbtHTMLHelpers
493
497
  end
494
498
  end
495
499
 
496
-
500
+
497
501
 
498
502
  def entity_list_action_render(type, action, locals, &block)
499
503
  type, format = type.split ":"
500
504
 
501
505
  size = locals.delete(:_size) || locals.delete("_size") || :normal
502
506
 
503
- workflow = WorkflowREST.workflows.last
504
-
505
- list = locals[:list] = Entity::REST.load_list(locals[:id])
507
+ list = locals[:list] = Entity::REST.load_list(type, locals[:id], user)
508
+ locals[:type] = type
506
509
 
507
510
  entity_class = case
508
511
  when Entity.formats.include?(format)
@@ -513,6 +516,8 @@ module RbbtHTMLHelpers
513
516
  nil
514
517
  end
515
518
 
519
+ workflow = Workflow === entity_class ? entity_class : WorkflowREST.workflows.last
520
+
516
521
  path = case
517
522
  when (list.respond_to? :list_action_template and Hash === list.list_action_template and not list.list_action_template[action].nil?)
518
523
  list.list_action_template[action]
@@ -547,20 +552,6 @@ module RbbtHTMLHelpers
547
552
  path
548
553
  end
549
554
 
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
563
-
564
555
  layout = locals[:_layout]
565
556
  layout = false if locals[:_xhr] and layout.nil?
566
557
  layout = true if layout.nil?
@@ -577,7 +568,7 @@ module RbbtHTMLHelpers
577
568
  else
578
569
  renderer.render(self, locals, &block)
579
570
  end
580
-
571
+
581
572
  end
582
573
  end
583
574
 
@@ -8,18 +8,130 @@ module Sinatra
8
8
  ENV.include? "RACK_ENV" and not ENV["RACK_ENV"].nil? and ENV['RACK_ENV'].downcase == "production"
9
9
  end
10
10
 
11
- def cache(type, options)
11
+ def old_cache(path, check)
12
+ return false if check.nil?
13
+ return false if not File.exists? path
14
+ check = [check] unless Array === check
15
+ return check.select{|file| not File.exists?(file) or File.mtime(file) > File.mtime(path)}.any?
16
+ end
17
+
18
+ def cache(type, options, &block)
19
+ cache_type, update, check = Misc.process_options options, :cache_type, :update, :check
20
+
21
+ check = [check] if not check.nil? and not Array === check
22
+
12
23
  name = type + ":" + Misc.hash2md5(options)
24
+
13
25
  if production?
14
- @@cache ||= Persist.open_tokyocabinet 'sinatra.cache', true
15
- return @@cache[name] if @@cache.include? name
16
- res = yield
17
- Misc.lock @@cache.persistence_path do
18
- @@cache.write
19
- @@cache[name] = res
20
- @@cache.read
26
+ cache_type ||= :memory
27
+ else
28
+ cache_type = :none
29
+ end
30
+
31
+ case cache_type.to_sym
32
+ when :sync, :synchronous
33
+
34
+ path = File.join(settings.cache_dir, "sinatra", name)
35
+ task = Task.setup(:name => "Sinatra cache", :result_type => :string, &block)
36
+ step = Step.new(path, task, nil, nil, self)
37
+
38
+ step.clean if old_cache(path, check)
39
+
40
+ begin
41
+ case
42
+ when (not step.started? and not update == 'check')
43
+ step.run
44
+ when (step.started? and update == 'reload')
45
+ step.clean
46
+ step.run
47
+ end
48
+ rescue
49
+ end
50
+
51
+ begin
52
+ case
53
+ when step.error?
54
+ status 500
55
+ status = step.status || "error"
56
+ messages = step.messages || []
57
+ backtrace = step.info[:backtrace] || []
58
+ step.clean
59
+ "<span class='cache_status'>" << status.to_s << "</span> " << "\n" <<
60
+ "<span class='cache_message'>" << messages.last << "</span> " << "\n" <<
61
+ "<ul class='backtrace'>" + backtrace.collect{|line| "<li>" << line << "</li>"} * "\n"
62
+ when step.done?
63
+ step.load
64
+ else
65
+ if request.xhr?
66
+ status 202
67
+ "<span class='cache_status'>" << (step.status || "starting").to_s << "</span>"
68
+ else
69
+ retry unless step.done? and not step.error?
70
+ step.load
71
+ end
72
+ end
21
73
  end
22
- res
74
+
75
+
76
+ when :async
77
+
78
+ path = File.join(settings.cache_dir, "sinatra", name)
79
+ task = Task.setup(:result_type => :string, &block)
80
+ step = Step.new(path, task, nil, nil, self)
81
+
82
+ step.clean if old_cache(path, check)
83
+
84
+ case
85
+ when (not step.started? and not update == 'check')
86
+ step.fork
87
+ sleep 0.5
88
+ sleep 2 unless step.done?
89
+ when (step.started? and update == 'reload')
90
+ step.clean
91
+ step.fork
92
+ sleep 0.5
93
+ sleep 2 unless step.done?
94
+ end
95
+
96
+ begin
97
+ case
98
+ when (not step.started?)
99
+ status 202
100
+ "<span class='cache_status'>" << "not started" << "</span>"
101
+ when step.error?
102
+ status 500
103
+ status = step.status || "error"
104
+ messages = step.messages || []
105
+ backtrace = step.info[:backtrace] || []
106
+ step.clean
107
+ "<span class='cache_status'>" << status.to_s << "</span> " << "\n" <<
108
+ "<span class='cache_message'>" << messages.last << "</span> " << "\n" <<
109
+ "<ul class='backtrace'>" + backtrace.collect{|line| "<li>" << line << "</li>"} * "\n"
110
+
111
+ when step.done?
112
+ step.load
113
+ else
114
+ if request.xhr?
115
+ status 202
116
+ "<span class='cache_status'>" << (step.status || "starting").to_s << "</span>"
117
+ else
118
+ step.join
119
+ case
120
+ when step.error?
121
+ retry
122
+ when step.done?
123
+ step.load
124
+ else
125
+ retry
126
+ end
127
+ end
128
+ end
129
+ end
130
+
131
+ when :memory
132
+ @@cache ||= {}
133
+ @@cache.delete name if not check.nil?
134
+ @@cache[name] ||= yield
23
135
  else
24
136
  yield
25
137
  end
@@ -40,14 +152,14 @@ module Sinatra
40
152
  @result_cache[workflow][task] ||= {}
41
153
  @result_cache[workflow][task][jobname] ||= yield
42
154
  end
43
-
155
+
44
156
  def context_job(workflow, task)
45
157
  return nil if not defined? session
46
158
  return nil if not session.include? "context"
47
159
  return nil if not session["context"].include? workflow
48
160
  return nil if not session["context"][workflow].include? task
49
161
  jobname = session["context"][workflow][task]
50
-
162
+
51
163
  if authorized?
52
164
  real_jobname = File.join(user, jobname)
53
165
  else
@@ -154,6 +266,7 @@ module Sinatra
154
266
 
155
267
  page = params.delete :_page
156
268
 
269
+
157
270
  filter = params.delete :_filter
158
271
 
159
272
  size = params.delete(:_size) || params.delete("_size")
@@ -9,7 +9,6 @@ span.task_description
9
9
  display: block
10
10
  font-size: 1.5em
11
11
  margin-bottom: 25px
12
- border-bottom: solid 1px
13
12
 
14
13
  form.task
15
14
 
@@ -51,7 +51,7 @@ ul.job_control
51
51
  margin-right: 15px
52
52
 
53
53
  #content
54
- +column(19)
54
+ width: 100%
55
55
  #main
56
56
  width: auto
57
57
  padding: 10px
@@ -108,7 +108,7 @@ a.entity, a.entity_list, a.entity_action, a.entity_list_action
108
108
  white-space: nowrap
109
109
  word-spacing: 0px
110
110
 
111
- a.replace
111
+ a.replace, a.check_replace
112
112
  +border_radius(4px, 4px)
113
113
  +shadowed_box()
114
114
  display: inline-block
@@ -131,3 +131,94 @@ span.user
131
131
 
132
132
  a.button
133
133
  +button_link()
134
+
135
+ span.cache_status
136
+ margin: 0px 15px
137
+ color: gray
138
+ text-decoration: none
139
+
140
+ span.note
141
+ color: gray
142
+
143
+ .embedded
144
+ position: relative
145
+ & > span.cache_status
146
+ position: absolute
147
+ top: 9px
148
+ right: 150px
149
+ text-align: center
150
+ color: red
151
+
152
+ header, .contracted_embedded
153
+ font-size: 1.8em
154
+ ul.embedded_control
155
+ float: right
156
+ font-size: 12px
157
+ +clean_list()
158
+ li > a
159
+ +button_link()
160
+ margin-left: 3px
161
+
162
+ a.retry_error, a.start_checked
163
+ +button_link()
164
+
165
+ .selected_entity
166
+ font-weight: bold
167
+
168
+ #lists
169
+ position: absolute
170
+ top: 40px
171
+ right: 10px
172
+ width: auto
173
+ min-width: 300px
174
+ padding: 20px
175
+ padding-left: 30px
176
+ background-color: #fefefe
177
+ +shadowed_box
178
+ ul.entity_list
179
+ li
180
+ display: block
181
+
182
+
183
+ span.list_dropdown
184
+ float: right
185
+ margin-right: 20px
186
+ a
187
+ +button_link
188
+ color: gray
189
+
190
+ a.remove_list, a.select_list
191
+ font-size: 0.7em
192
+ +button_link
193
+
194
+ a.view_list
195
+ margin-left: 10px
196
+
197
+ #lists
198
+ display: none
199
+ ul
200
+ +clean_list()
201
+ a
202
+ text-decoration: none
203
+
204
+ a.remove_entity_from_list
205
+ +button_link()
206
+
207
+ .edit_controls
208
+ padding: 10px
209
+ display: none
210
+
211
+ a.open_edit_controls
212
+ +button_link()
213
+
214
+ h5.loaded_lists
215
+ margin: 5px 0px
216
+ font-style: italic
217
+
218
+ .list_control
219
+ header
220
+ font-size: 1.2em
221
+ span.list_id
222
+ font-style: italic
223
+ a
224
+ +button_link()