rbbt-rest 1.1.4 → 1.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +8 -8
  2. data/config.ru +3 -0
  3. data/lib/rbbt/rest/client.rb +9 -10
  4. data/lib/rbbt/rest/common/cache.rb +32 -7
  5. data/lib/rbbt/rest/common/forms.rb +33 -0
  6. data/lib/rbbt/rest/common/locate.rb +4 -0
  7. data/lib/rbbt/rest/common/misc.rb +24 -0
  8. data/lib/rbbt/rest/common/render.rb +26 -9
  9. data/lib/rbbt/rest/common/resources.rb +1 -1
  10. data/lib/rbbt/rest/common/table.rb +87 -26
  11. data/lib/rbbt/rest/common/users.rb +5 -1
  12. data/lib/rbbt/rest/entity.rb +300 -95
  13. data/lib/rbbt/rest/entity/action_controller.rb +6 -1
  14. data/lib/rbbt/rest/entity/entity_list_card.rb +1 -1
  15. data/lib/rbbt/rest/entity/entity_map_card.rb +15 -0
  16. data/lib/rbbt/rest/entity/favourites.rb +57 -1
  17. data/lib/rbbt/rest/entity/finder.rb +1 -1
  18. data/lib/rbbt/rest/entity/helpers.rb +40 -7
  19. data/lib/rbbt/rest/entity/list.rb +8 -0
  20. data/lib/rbbt/rest/entity/locate.rb +114 -0
  21. data/lib/rbbt/rest/entity/map.rb +99 -0
  22. data/lib/rbbt/rest/entity/render.rb +25 -0
  23. data/lib/rbbt/rest/entity/rest.rb +33 -4
  24. data/lib/rbbt/rest/main.rb +27 -4
  25. data/lib/rbbt/rest/workflow.rb +7 -1
  26. data/lib/rbbt/rest/workflow/jobs.rb +21 -1
  27. data/share/views/compass/app.sass +17 -9
  28. data/share/views/compass/entity_card.sass +16 -3
  29. data/share/views/compass/favourites.sass +44 -2
  30. data/share/views/compass/form.sass +11 -0
  31. data/share/views/compass/list_container.sass +1 -1
  32. data/share/views/compass/reveal.sass +31 -0
  33. data/share/views/compass/style.sass +29 -1
  34. data/share/views/compass/style_mixins.sass +18 -6
  35. data/share/views/compass/table.sass +19 -3
  36. data/share/views/compass/topbar.sass +8 -2
  37. data/share/views/entity_map/Default.haml +5 -0
  38. data/share/views/entity_partials/action_card.haml +2 -0
  39. data/share/views/entity_partials/action_controller.haml +8 -1
  40. data/share/views/entity_partials/entity_list_card.haml +8 -6
  41. data/share/views/entity_partials/entity_map_card.haml +63 -0
  42. data/share/views/entity_partials/list_container.haml +3 -2
  43. data/share/views/error.haml +14 -10
  44. data/share/views/help.haml +34 -0
  45. data/share/views/help/entity.haml +193 -0
  46. data/share/views/help/workflow.haml +77 -0
  47. data/share/views/job_result/tsv.haml +3 -2
  48. data/share/views/layout.haml +33 -3
  49. data/share/views/layout/favourites.haml +14 -4
  50. data/share/views/layout/header.haml +4 -0
  51. data/share/views/partials/form.haml +3 -1
  52. data/share/views/partials/table.haml +16 -52
  53. data/share/views/partials/table/column.haml +10 -0
  54. data/share/views/partials/table/files.haml +4 -0
  55. data/share/views/partials/table/filters.haml +11 -0
  56. data/share/views/partials/table/page.haml +37 -0
  57. data/share/views/public/favicon.gif +0 -0
  58. data/share/views/public/js/_ajax_replace.js +76 -4
  59. data/share/views/public/js/_fix_tablesorter_science.js +13 -0
  60. data/share/views/public/js/actions.js +8 -2
  61. data/share/views/public/js/base.js +12 -1
  62. data/share/views/public/js/entities.js +39 -7
  63. data/share/views/public/js/favourites.js +308 -77
  64. data/share/views/public/js/helpers.js +9 -5
  65. data/share/views/public/js/lists.js +12 -12
  66. data/share/views/public/js/maps.js +17 -0
  67. data/share/views/public/js/reveal.js +48 -0
  68. data/share/views/public/js/tables.js +110 -51
  69. data/share/views/public/js/workflow.js +4 -16
  70. data/share/views/public/plugins/underscore/js/underscore.js +1227 -0
  71. data/share/views/tasks.haml +12 -1
  72. data/share/views/wait.haml +7 -0
  73. metadata +17 -2
@@ -20,10 +20,15 @@ module EntityRESTHelpers
20
20
  def default_action_controller(entity, list_id = nil)
21
21
  action_controller = ActionController.new(entity, list_id)
22
22
 
23
- if Array === entity
23
+ case
24
+ when Array === entity
24
25
  find_all_entity_list_action_templates(entity, true).each do |action|
25
26
  action_controller.add action, Misc.humanize(action, :format => :sentence), :reuse => true
26
27
  end
28
+ when TSV === entity
29
+ find_all_entity_map_action_templates(entity, true).each do |action|
30
+ action_controller.add action, Misc.humanize(action, :format => :sentence), :reuse => true
31
+ end
27
32
  else
28
33
  find_all_entity_action_templates(entity, true).each do |action|
29
34
  action_controller.add action, Misc.humanize(action, :format => :sentence)
@@ -2,7 +2,7 @@ class EntityListCard
2
2
 
3
3
  attr_accessor :list, :list_id
4
4
  attr_accessor :meta, :description
5
- attr_accessor :list_container, :action_controller
5
+ attr_accessor :action_controller, :list_container
6
6
 
7
7
  def initialize(list, list_id)
8
8
  @list, @list_id = list, list_id
@@ -0,0 +1,15 @@
1
+ class EntityMapCard
2
+
3
+ attr_accessor :map, :map_id
4
+ attr_accessor :action_controller
5
+
6
+ def initialize(map, map_id)
7
+ @map, @map_id = map, map_id
8
+ end
9
+ end
10
+
11
+ module EntityRESTHelpers
12
+ def entity_map_card_render(card)
13
+ partial_render('entity_partials/entity_map_card', :card => card)
14
+ end
15
+ end
@@ -71,7 +71,7 @@ module EntityRESTHelpers
71
71
  if (file = dir[entity_type]).exists?
72
72
  lists = Open.read(file).split("\n")
73
73
  lists << list
74
- Open.write(file, lists * "\n")
74
+ Open.write(file, lists.uniq * "\n")
75
75
  else
76
76
  lists = [list]
77
77
  Open.write(file, lists * "\n")
@@ -94,4 +94,60 @@ module EntityRESTHelpers
94
94
  end
95
95
  end
96
96
 
97
+ #{{{ Entity Maps
98
+
99
+ def favourite_entity_maps
100
+ raise "You need to login to have favourites" unless authorized?
101
+
102
+ dir = Path.setup(File.join(settings.favourite_maps_dir, user))
103
+ favourites = {}
104
+ dir.find.glob('*').each do |type_dir|
105
+ type = File.basename(type_dir)
106
+ Path.setup(type_dir).glob('*').each do |file|
107
+ column = File.basename(file).gsub('--', '/')
108
+ maps = Open.read(file).split("\n")
109
+ favourites[type] ||= {}
110
+ favourites[type][column] = maps
111
+ end
112
+ end
113
+ favourites
114
+ end
115
+
116
+ def add_favourite_entity_map(entity_type, column, map)
117
+ raise "You need to login to have favourites" unless authorized?
118
+
119
+ column = column.gsub('/', '--')
120
+ dir = Path.setup(File.join(settings.favourite_maps_dir, user))
121
+
122
+ if (file = dir[entity_type][column]).exists?
123
+ maps = Open.read(file).split("\n")
124
+ maps << map
125
+ maps.uniq!
126
+ Open.write(file, maps.uniq * "\n")
127
+ else
128
+ maps = [map]
129
+ Open.write(file, maps * "\n")
130
+ end
131
+ ddd favourite_entity_maps
132
+ end
133
+
134
+ def remove_favourite_entity_map(entity_type, column, map)
135
+ raise "You need to login to have favourites" unless authorized?
136
+
137
+ column = column.gsub('/', '--')
138
+
139
+ dir = Path.setup(File.join(settings.favourite_maps_dir, user))
140
+
141
+ if (file = dir[entity_type][column]).exists?
142
+ maps = Open.read(file).split("\n")
143
+ maps -= [map]
144
+ if maps.any?
145
+ Open.write(file, maps * "\n")
146
+ else
147
+ FileUtils.rm file
148
+ end
149
+ end
150
+ end
151
+
152
+
97
153
  end
@@ -2,7 +2,7 @@ require 'rbbt/ner/finder'
2
2
 
3
3
  module EntityRESTHelpers
4
4
  def finder_find(term)
5
- return [] unless settings.respond_to? :finder and not settings.finder.nil?
5
+ return [] unless settings.respond_to? :finder and not settings.finder.nil? and not settings.finder.instances.empty?
6
6
  results = settings.finder.find(term)
7
7
 
8
8
  results.uniq.collect{|r|
@@ -52,7 +52,7 @@ module EntityRESTHelpers
52
52
  end
53
53
 
54
54
  def page_type(path = nil)
55
- path = request.path_info
55
+ path = request.path_info if path.nil?
56
56
 
57
57
  case
58
58
  when path.match(/^\/entity\//)
@@ -63,13 +63,17 @@ module EntityRESTHelpers
63
63
  return "entity_list";
64
64
  when path.match(/^\/entity_list_action\//)
65
65
  return "entity_list_action";
66
+ when path.match(/^\/entity_map\//)
67
+ return "entity_map";
68
+ when path.match(/^\/entity_map_action\//)
69
+ return "entity_map_action";
66
70
  else
67
71
  return nil;
68
72
  end
69
73
  end
70
74
 
71
75
  def page_entity(path = nil)
72
- path = request.path_info
76
+ path = request.path_info if path.nil?
73
77
 
74
78
  case page_type
75
79
  when "entity"
@@ -82,7 +86,7 @@ module EntityRESTHelpers
82
86
  end
83
87
 
84
88
  def page_action(path = nil)
85
- path = request.path_info
89
+ path = request.path_info if path.nil?
86
90
 
87
91
  case page_type
88
92
  when "entity_action", "entity_list_action"
@@ -92,9 +96,8 @@ module EntityRESTHelpers
92
96
  end
93
97
  end
94
98
 
95
-
96
99
  def page_entity_list(path = nil)
97
- path = request.path_info
100
+ path = request.path_info if path.nil?
98
101
 
99
102
  case page_type
100
103
  when "entity_list"
@@ -105,17 +108,47 @@ module EntityRESTHelpers
105
108
  return nil
106
109
  end
107
110
  end
111
+
112
+ def page_entity_map(path = nil)
113
+ path = request.path_info if path.nil?
114
+
115
+ case page_type
116
+ when "entity_map"
117
+ return Entity::REST.restore_element(path.split("/")[4])
118
+ when "entity_map_action"
119
+ return Entity::REST.restore_element(path.split("/")[5])
120
+ else
121
+ return nil
122
+ end
123
+ end
108
124
 
109
125
  def page_entity_type(path = nil)
110
- path = request.path_info
126
+ path = request.path_info if path.nil?
111
127
 
112
128
  case page_type
113
- when "entity", "entity_list", "entity_action", "entity_list_action"
129
+ when "entity", "entity_list", "entity_action", "entity_list_action", "entity_map"
114
130
  return Entity::REST.restore_element(path.split("/")[2])
115
131
  else
116
132
  return nil
117
133
  end
118
134
  end
135
+
136
+ def page_entity_base_type(path = nil)
137
+ page_entity_type.split(":").first
138
+ end
139
+
140
+ def page_entity_map_column(path = nil)
141
+ path = request.path_info if path.nil?
142
+
143
+ case page_type
144
+ when "entity_map"
145
+ return Entity::REST.restore_element(path.split("/")[3])
146
+ else
147
+ return nil
148
+ end
149
+ end
150
+
151
+
119
152
  #
120
153
  #
121
154
  #function page_entity_base_type(){
@@ -2,9 +2,17 @@ require 'rbbt/entity'
2
2
  require 'cgi'
3
3
 
4
4
  module Entity
5
+
6
+ class << self
7
+ attr_accessor :entity_list_cache
8
+ end
9
+
10
+ self.entity_list_cache = "var/entity_list"
11
+
5
12
  module List
6
13
 
7
14
  def self.list_file(entity_type, id, user = nil)
15
+ id = Entity::REST.clean_element(id)
8
16
  id = Misc.sanitize_filename(id)
9
17
 
10
18
  entity_type = entity_type.split(":").first
@@ -278,4 +278,118 @@ module EntityRESTHelpers
278
278
 
279
279
  raise "Template not found for list #{ action } (#{list.annotation_types * ", "})"
280
280
  end
281
+
282
+ #{{{ ENTITY MAP
283
+
284
+ def locate_entity_map_template_from_resource(resource, type)
285
+ if type == "Default"
286
+ path = resource.entity_map["Default.haml"]
287
+ if path.exists?
288
+ return path
289
+ else
290
+ return nil
291
+ end
292
+ end
293
+
294
+ path = resource.entity_map[type.to_s + ".haml"]
295
+ return path if path.exists?
296
+
297
+ nil
298
+ end
299
+
300
+ def locate_entity_map_template(type, column)
301
+ entity_resources.each do |resource|
302
+ path = locate_entity_map_template_from_resource(resource, type)
303
+ return path if path and path.exists?
304
+ end
305
+
306
+ entity_resources.each do |resource|
307
+ path = locate_entity_map_template_from_resource(resource, "Default")
308
+ return path if path and path.exists?
309
+ end
310
+
311
+ raise "Template not found for list (#{list.annotation_types * ", "})"
312
+ end
313
+
314
+
315
+ #{{{ ENTITY MAP ACTION
316
+
317
+ def find_all_entity_map_action_templates_from_resource(resource, map)
318
+ field = map.key_field
319
+
320
+ if map.entity_templates[field]
321
+ annotation_types = map.entity_templates[field].annotation_types
322
+ else
323
+ annotation_types = [Entity.formats[field]].compact
324
+ end
325
+
326
+ annotation_types += ["Default"]
327
+
328
+ annotation_types.collect do |annotation|
329
+ resource.entity_map[annotation].glob('*.haml')
330
+ end.compact.flatten
331
+ end
332
+
333
+ def find_all_entity_map_action_templates(map, check = false)
334
+ paths = []
335
+
336
+ entity_resources.each do |resource|
337
+ paths.concat find_all_entity_map_action_templates_from_resource(resource, map)
338
+ end
339
+
340
+ if check
341
+ paths = paths.reject do |path|
342
+ check_file = path.sub(/\.haml$/, '.check')
343
+ case
344
+ when (path.basename == "edit.haml" or path.basename == 'new.haml')
345
+ true
346
+ when File.exists?(check_file)
347
+ begin
348
+ Log.debug("Checking action template: #{path}")
349
+ code = File.read(check_file)
350
+ accept = eval code
351
+ not accept
352
+ rescue
353
+ Log.debug("Error Checking action template #{path}: #{$!.message}")
354
+ true
355
+ end
356
+ else
357
+ false
358
+ end
359
+ end
360
+ end
361
+
362
+ paths.collect{|file| file.basename.sub('.haml', '') }.uniq
363
+ end
364
+
365
+
366
+ def locate_entity_map_action_template_from_resource(resource, map, action)
367
+ field = map.key_field
368
+
369
+ if map.entity_templates[field]
370
+ annotation_types = map.entity_templates[field].annotation_types
371
+ else
372
+ annotation_types = [Entity.formats[field]].compact
373
+ end
374
+
375
+ annotation_types += ["Default"]
376
+
377
+ annotation_types.each do |annotation|
378
+ path = resource.entity_map[annotation][action.to_s + ".haml"]
379
+ return path if path.exists?
380
+ end
381
+
382
+ nil
383
+ end
384
+
385
+ def locate_entity_map_action_template(map, action)
386
+
387
+ entity_resources.each do |resource|
388
+ path = locate_entity_map_action_template_from_resource(resource, map, action)
389
+ return path if path and path.exists?
390
+ end
391
+
392
+ raise "Template not found for map #{ action } (#{map.key_field * ", "})"
393
+ end
394
+
281
395
  end
@@ -0,0 +1,99 @@
1
+ require 'rbbt/entity'
2
+ require 'cgi'
3
+
4
+ module Entity
5
+
6
+ class << self
7
+ attr_accessor :entity_map_cache
8
+ end
9
+
10
+ self.entity_map_cache = "var/entity_map"
11
+
12
+
13
+ module Map
14
+ def self.map_file(entity_type, column, id, user = nil)
15
+ id = Misc.sanitize_filename(Entity::REST.clean_element(id))
16
+ column = Entity::REST.clean_element(column)
17
+
18
+ entity_type = entity_type.split(":").first
19
+
20
+ raise "Ilegal map id: #{ id }" unless Misc.path_relative_to Entity.entity_map_cache, File.join(Entity.entity_map_cache, id)
21
+
22
+ path = if user.nil?
23
+ Dir.glob(File.join(Entity.entity_map_cache, entity_type.to_s, column, Regexp.quote(id))).first || File.join(Entity.entity_map_cache, entity_type.to_s, column, id)
24
+ else
25
+ Dir.glob(File.join(Entity.entity_map_cache, user.to_s, entity_type.to_s, column, Regexp.quote(id))).first || File.join(Entity.entity_map_cache, user.to_s, entity_type.to_s, column, id)
26
+ end
27
+
28
+ path
29
+ end
30
+
31
+ def self.map_files(user = nil)
32
+ path = user.nil? ?
33
+ File.join(Entity.entity_map_cache, '*', '*') :
34
+ File.join(Entity.entity_map_cache, user, '*', '*')
35
+
36
+ maps = {}
37
+ Dir.glob(path).each do |file|
38
+ next if File.directory? file
39
+
40
+ file = File.expand_path(file)
41
+ raise "Ilegal path: #{ file }. Not relative to #{File.expand_path(Entity.entity_map_cache)}" unless
42
+ Misc.path_relative_to(File.expand_path(Entity.entity_map_cache), file)
43
+
44
+ if user.nil?
45
+ entity_type, column, map = file.split("/")[-2..-1]
46
+ else
47
+ user, entity_type, column, map = file.split("/")[-3..-1]
48
+ end
49
+
50
+ maps[entity_type] ||= []
51
+ maps[entity_type][column] ||= []
52
+ maps[entity_type][column] << map
53
+ end
54
+
55
+ maps
56
+ end
57
+
58
+ def self.load_map(entity_type, column, id, user = nil)
59
+ path = map_file(entity_type, column, id, user)
60
+ path = map_file(entity_type, column, id, :public) unless path != nil and File.exists? path
61
+ path = map_file(entity_type, column, id) unless path != nil and File.exists? path
62
+
63
+ begin
64
+ RbbtRESTHelpers.load_tsv(path).first
65
+ rescue
66
+ Log.error("Error loading map #{ path }: #{$!.message}")
67
+ nil
68
+ end
69
+ end
70
+
71
+ def self.save_map(entity_type, column, id, map, user = nil)
72
+ path = map_file(entity_type, column, id, user)
73
+
74
+ Misc.lock path do
75
+ begin
76
+ RbbtRESTHelpers.save_tsv(map, path)
77
+ rescue
78
+ FileUtils.rm path if path and File.exists? path
79
+ raise $!
80
+ end
81
+ end
82
+ end
83
+
84
+ def self.delete_map(entity_type, column, id, user)
85
+ path = map_file(entity_type, column, id, user)
86
+
87
+ "This map does not belong to #{ user }: #{[entity_type, column, id] * ": "}" unless File.exists? path
88
+
89
+ Misc.lock path do
90
+ begin
91
+ FileUtils.rm path if File.exists? path
92
+ rescue
93
+ raise $!
94
+ end
95
+ end
96
+ end
97
+ end
98
+ end
99
+