ecoportal-api-oozes 0.6.1 → 0.7.4

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.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +86 -0
  3. data/ecoportal-api-oozes.gemspec +6 -6
  4. data/lib/ecoportal/api/common/content/collection_model.rb +25 -3
  5. data/lib/ecoportal/api/common/content/double_model.rb +27 -12
  6. data/lib/ecoportal/api/common/content/hash_diff_patch.rb +8 -1
  7. data/lib/ecoportal/api/v2.rb +27 -2
  8. data/lib/ecoportal/api/v2/page.rb +3 -3
  9. data/lib/ecoportal/api/v2/page/component.rb +11 -2
  10. data/lib/ecoportal/api/v2/page/component/action.rb +14 -3
  11. data/lib/ecoportal/api/v2/page/component/action_field.rb +40 -2
  12. data/lib/ecoportal/api/v2/page/component/chart_field.rb +54 -0
  13. data/lib/ecoportal/api/v2/page/component/chart_field/frequency.rb +29 -0
  14. data/lib/ecoportal/api/v2/page/component/chart_field/heatmap.rb +27 -0
  15. data/lib/ecoportal/api/v2/page/component/chart_field/indicator.rb +26 -0
  16. data/lib/ecoportal/api/v2/page/component/chart_field/multiseries.rb +31 -0
  17. data/lib/ecoportal/api/v2/page/component/chart_field/sankey.rb +27 -0
  18. data/lib/ecoportal/api/v2/page/component/chart_field/serie.rb +26 -0
  19. data/lib/ecoportal/api/v2/page/component/chart_field/series_config.rb +23 -0
  20. data/lib/ecoportal/api/v2/page/component/chart_fr_field.rb +32 -0
  21. data/lib/ecoportal/api/v2/page/component/checklist_field.rb +35 -2
  22. data/lib/ecoportal/api/v2/page/component/checklist_item.rb +10 -0
  23. data/lib/ecoportal/api/v2/page/component/date_field.rb +21 -0
  24. data/lib/ecoportal/api/v2/page/component/files_field.rb +1 -2
  25. data/lib/ecoportal/api/v2/page/component/gauge_field.rb +24 -1
  26. data/lib/ecoportal/api/v2/page/component/gauge_stop.rb +88 -0
  27. data/lib/ecoportal/api/v2/page/component/images_field.rb +1 -2
  28. data/lib/ecoportal/api/v2/page/component/people_field.rb +8 -1
  29. data/lib/ecoportal/api/v2/page/component/plain_text_field.rb +2 -0
  30. data/lib/ecoportal/api/v2/page/component/reference_field.rb +4 -0
  31. data/lib/ecoportal/api/v2/page/component/selection_field.rb +4 -5
  32. data/lib/ecoportal/api/v2/page/component/selection_option.rb +1 -0
  33. data/lib/ecoportal/api/v2/page/component/signature_field.rb +1 -1
  34. data/lib/ecoportal/api/v2/page/component/tag_field.rb +2 -0
  35. data/lib/ecoportal/api/v2/page/components.rb +2 -2
  36. data/lib/ecoportal/api/v2/page/section.rb +1 -0
  37. data/lib/ecoportal/api/v2/page/sections.rb +1 -1
  38. data/lib/ecoportal/api/v2/version.rb +1 -1
  39. metadata +60 -32
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 169653f85a26c45f2b60eb95358dd7e547185b07a5a722bb56643a63daa1fb1f
4
- data.tar.gz: 696de7a2f37b8fcf7409be373bfb491b4fa70bfc504cace816a4b64076cb9bd7
3
+ metadata.gz: 6039e6c6b1c32fcbcd956ef9a425588cbd9dfe94d06898223af14f433bab2c3a
4
+ data.tar.gz: c4dca6d50e4a664d343942636079f7c3cfe11999502ca891e8cf1f8598ed79f3
5
5
  SHA512:
6
- metadata.gz: 6b134337977269a67e49d451bad2a854da602724326483e72cfa3c95cbb012d6f8fbbd88742d9f58fba019869c7c11ae5e14f74e2ae8756daaa8035ab9658d09
7
- data.tar.gz: 342dbf60de74361387b383428a8b066184c9b0ce73dba98f3761da5c83b5efd8393da8cc7e836b58bf47aacac660493d316b93be0a88a3876c7d7195ab7afb49
6
+ metadata.gz: 91f9c47478b1054e0efb2380bb623c951d751f10c24a833b7fd380ddaa35bdc825b42b5574f23524accfc0e10ba692857c0597be9805cde1acede6d5959b0730
7
+ data.tar.gz: 2106b17efa000c7d1b44ce667bf3d80fe84a4c59bb7c0772cc8d19396e5fa024e39fc7823064e9531ac9c82037be3bfdc17e8827ae41ae1bdb7b648c15d52abe
data/CHANGELOG.md CHANGED
@@ -1,6 +1,92 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## [0.7.4] - 2021-02-12
5
+
6
+ ### Added
7
+ - `Ecoportal::API::V2::Page::Component::GaugeStop#color=` enabled setting colours using a `symbol`
8
+ - `:blue`, `:blue_greyed`, `:blue_light`
9
+ - `:turquoise`, `:jade`, `:green`, `:pistachio`, `:avocado`
10
+ - `:yellow`, `:orange`, `:pumpkin`, `:red`, `:magenta`, `:fuchsia`, `:purple`, `:violet`
11
+ - `Ecoportal::API::V2::Page::Component::GaugeStop#color_sym` to get the color as `symbol` name
12
+ - added support for chart fields:
13
+ - `Ecoportal::API::V2::Page::Component::ChartField` with the different `mode` types
14
+ - `Ecoportal::API::V2::Page::Component::ChartFrField` (LTIFR)
15
+
16
+ ### Changed
17
+ - `Ecoportal::API::Page::Component::DateField` Date objects + Timezones
18
+ - `#value` should be shown in local time
19
+ - `#value=` should be set by local time
20
+ - `Ecoportal::API::Common::Content::DoubleModel.embeds_multiple` renamed to `embeds_many`
21
+ - `Ecoportal::API::Common::Content::DoubleModel.embeds_one` removed parameter `:multiple`
22
+ - Fields under `Ecoportal::API::Page::Component` that `embeds_many` should generate new elements in a standard way
23
+ - added `Ecoportal::API::Common::Content::CollectionModel#items_class` method
24
+
25
+ ### Fixed
26
+ - solved `pretty_print` name collision renaming to `Ecoportal::API::Common::Content::DoubleModel#print_pretty`
27
+
28
+ ## [0.7.3] - 2021-02-01
29
+
30
+ ### Added
31
+ - `Ecoportal::API::Common::Content::CollectionModel#delete!` finally scoped how delete should work :)
32
+ - `Ecoportal::API::V2.new` better feedback on key error.
33
+ - `Ecoportal::API::V2::Page::Component::SignatureField` added property `signed_by_name`
34
+ - `Ecoportal::API::V2::Page::Component#required` this field property is currently supported
35
+ - `Ecoportal::API::V2::Page::Component::DateField` more supported properties:
36
+ * `show_time`, `today_button`, `past_only`, `create_event`, `remind_me_in`, `renews`, `renews_every`, `renews_unit`, `renews_until`
37
+ - `Ecoportal::API::V2::Page::Component::ChecklistField`
38
+ * added more methods: `add_item`, `ordered_items`
39
+ - `Ecoportal::API::V2::Page::Component::GaugeField`
40
+ * more supported properties: `max`, `active_color` and `stops`
41
+ - for `stops` added class `Ecoportal::API::V2::Page::Component::GaugeStop`
42
+ * added more methods: `add_stop`, `ordered_stops`
43
+ - `Ecoportal::API::V2::Page::Component::ReferenceField` more supported properties:
44
+ * `register_id`, `hide_create`, `hide_attach`, `hide_metadata`, `hide_dashboards`, `display_fields`, `display_fields_in_lookup`
45
+ - `Ecoportal::API::V2::Page::Component::ActionField`
46
+ * more supported properties:`create_actions`, `required_number_of_completed_actions`, `permits_and_rules_integration`, `add_subscribed`, `add_subscribed_to_tasks`
47
+ * added more methods: `add_task`, `ordered_tasks`
48
+ - `Ecoportal::API::V2::Page::Component::Action` modified, provided that some properties are `read_only`
49
+ - `Ecoportal::API::V2::Page::Component::PeopleField` more supported properties:
50
+ * `is_me_button`, `attach_mode`, `person_schema_id`, `viewable_fields`, `singular`, `requires_number`, `cached_people`, `attached_people_permissions_enabled`, `apply_attached_people_permissions_to`, `attached_people_permissions_editable`, `attached_people_permissions_flags`
51
+ - `Ecoportal::API::V2::Page::Component::PlainTextField` more supported properties:
52
+ * `multiline`, `max_length`, `exact_index`
53
+ - `Ecoportal::API::V2::Page::Component::SelectionField` more supported properties:
54
+ * `flat`
55
+ - `Ecoportal::API::V2::Page::Component::TagField` more supported properties:
56
+ * `single_select`, `use_defaults`, `tag_tree_id`, `button_text`
57
+ - `Ecoportal::API::V2::Page::Section` more supported properties:
58
+ * `minimized`
59
+
60
+ ### Changed
61
+ - upgraded `ecoportal-api` dependency
62
+
63
+ ### Fixed
64
+ - `Ecoportal::API::Common::Content::CollectionModel#upsert!` was not actually moving the element to the new position when it already existed
65
+
66
+ ## [0.7.2] - 2020-10-07
67
+
68
+ ### Added
69
+ - automatic key builder
70
+ - helper: `Ecoportal::API::V2::v2key` method
71
+ - `user_key:` and `org_key:` as constructor methods for `Ecoportal::API::V2`
72
+ ### Changed
73
+ ### Fixed
74
+
75
+ ## [0.7.1] - 2020-10-07
76
+
77
+ ### Added
78
+ ### Changed
79
+ - updated dependencies
80
+ ### Fixed
81
+
82
+
83
+ ## [0.7.0] - 2020-09-10
84
+
85
+ ### Added
86
+ ### Changed
87
+ - updated dependencies
88
+ ### Fixed
89
+
4
90
  ## [0.6.1] - 2020-07-11
5
91
 
6
92
  ### Added
@@ -20,12 +20,12 @@ Gem::Specification.new do |spec|
20
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
21
  spec.require_paths = ["lib"]
22
22
 
23
- spec.add_development_dependency "bundler", "~> 2.1"
24
- spec.add_development_dependency "rake", "~> 12.0"
25
- spec.add_development_dependency "rspec", "~> 3.0"
26
- spec.add_development_dependency "yard", "~> 0.9", ">= 0.9.18"
27
- spec.add_development_dependency "redcarpet", "~> 3.5", ">= 3.5.0"
23
+ spec.add_development_dependency "bundler", ">= 2.1.3", "< 2.2"
24
+ spec.add_development_dependency "rspec", ">= 3.9", "< 4"
25
+ spec.add_development_dependency "rake", ">= 12.3.0", "< 13"
26
+ spec.add_development_dependency "yard", ">= 0.9.18", "< 0.10"
27
+ spec.add_development_dependency "redcarpet", ">= 3.5.0", "< 3.6"
28
28
  spec.add_development_dependency "pry"
29
29
 
30
- spec.add_dependency 'ecoportal-api', '~> 0.6', '>= 0.6.0'
30
+ spec.add_dependency 'ecoportal-api', '>= 0.7.4', '< 0.8'
31
31
  end
@@ -101,6 +101,11 @@ module Ecoportal
101
101
  super(ini_doc, parent: parent, key: key)
102
102
  end
103
103
 
104
+ # @return [Class] the class of the elements of the Collection
105
+ def items_class
106
+ self.class.klass
107
+ end
108
+
104
109
  # Transforms `value` into the actual `key` to access the object in the doc `Array`
105
110
  def _doc_key(value)
106
111
  #print "*(#{value.class})"
@@ -134,6 +139,7 @@ module Ecoportal
134
139
  end
135
140
  end
136
141
 
142
+ # Get an element usign the `key`.
137
143
  def [](value)
138
144
  items_by_key[get_key(value)]
139
145
  end
@@ -161,6 +167,15 @@ module Ecoportal
161
167
  end
162
168
  end
163
169
 
170
+ def delete!(value)
171
+ unless value.is_a?(Hash) || value.is_a?(Content::DoubleModel)
172
+ raise "'Content::DoubleModel' or 'Hash' doc required"
173
+ end
174
+ if item = self[value]
175
+ _doc_delete(item.doc)
176
+ end
177
+ end
178
+
164
179
  protected
165
180
 
166
181
  def order_matters?; self.class.order_matters; end
@@ -220,6 +235,13 @@ module Ecoportal
220
235
  super
221
236
  end
222
237
 
238
+ def _doc_delete(value)
239
+ if current_pos = _doc_key(value)
240
+ _doc_items.delete_at(current_pos)
241
+ on_change
242
+ end
243
+ end
244
+
223
245
  def _doc_upsert(value, pos: NOT_USED, before: NOT_USED, after: NOT_USED)
224
246
  current_pos = _doc_key(value)
225
247
  pos = case
@@ -228,7 +250,7 @@ module Ecoportal
228
250
  when used_param?(before)
229
251
  _doc_key(before)
230
252
  when used_param?(after)
231
- puts "to add after #{after.id}"
253
+ #puts "to add after #{after.id}"
232
254
  if i = _doc_key(after)
233
255
  i + 1
234
256
  end
@@ -237,10 +259,10 @@ module Ecoportal
237
259
  pos ||= current_pos
238
260
 
239
261
  if current_pos && pos
240
- _doc_items.delete(current_pos)
262
+ _doc_items.delete_at(current_pos)
241
263
  pos = (pos <= current_pos)? pos : pos - 1
242
264
  end
243
-
265
+
244
266
  pos = (pos && pos < _doc_items.length)? pos : _doc_items.length
245
267
 
246
268
  pos.tap do |i|
@@ -131,7 +131,32 @@ module Ecoportal
131
131
  end
132
132
 
133
133
  # Helper to embed one nested object under one property
134
- def embeds_one(method, key: method, nullable: false, multiple: false, klass:)
134
+ def embeds_one(method, key: method, nullable: false, klass:)
135
+ embed(method, key: key, nullable: nullable, multiple: false, klass: klass)
136
+ end
137
+
138
+ # @note
139
+ # - if you have a dedicated `Enumerable` class to manage `many`, you should use `:enum_class`
140
+ # - otherwise, just indicate the child class in `:klass` and it will auto generate the class
141
+ # @param
142
+ def embeds_many(method, key: method, order_matters: false, order_key: nil, klass: nil, enum_class: nil)
143
+ if enum_class
144
+ eclass = enum_class
145
+ elsif klass
146
+ eclass = new_class(method, inherits: Common::Content::CollectionModel) do |dim_class|
147
+ dim_class.klass = klass
148
+ dim_class.order_matters = order_matters
149
+ dim_class.order_key = order_key
150
+ end
151
+ else
152
+ raise "You should either specify the 'klass' of the elements or the 'enum_class'"
153
+ end
154
+ embed(method, key: key, multiple: true, klass: eclass)
155
+ end
156
+
157
+ private
158
+
159
+ def embed(method, key: method, nullable: false, multiple: false, klass:)
135
160
  method = method.to_s.freeze
136
161
  var = instance_variable_name(method).freeze
137
162
  k = key.to_s.freeze
@@ -150,16 +175,6 @@ module Ecoportal
150
175
  end
151
176
  end
152
177
 
153
- def embeds_multiple(method, key: method, order_matters: false, order_key: nil, klass:)
154
- dim_class = new_class(method, inherits: Common::Content::CollectionModel) do |dklass|
155
- dklass.klass = klass
156
- dklass.order_matters = order_matters
157
- dklass.order_key = order_key
158
- end
159
-
160
- embeds_one(method, key: key, multiple: true, klass: dim_class)
161
- end
162
-
163
178
  end
164
179
 
165
180
  attr_reader :_parent, :_key
@@ -252,7 +267,7 @@ module Ecoportal
252
267
  end
253
268
  end
254
269
 
255
- def pretty_print
270
+ def print_pretty
256
271
  puts JSON.pretty_generate(as_json)
257
272
  self
258
273
  end
@@ -60,8 +60,13 @@ module Ecoportal
60
60
  a == b
61
61
  end
62
62
 
63
- def patch_data(a, b = nil)
63
+ def patch_data(a, b = nil, delete: false)
64
64
  {}.tap do |data_hash|
65
+ if delete
66
+ patch_ver = (a && a["patch_ver"]) || 1
67
+ data_hash["patch_ver"] = patch_ver
68
+ next
69
+ end
65
70
  a.each do |key, a_value|
66
71
  b_value = b[key] if b_has_key = b && b.key?(key)
67
72
  is_meta_key = META_KEYS.include?(key)
@@ -85,6 +90,8 @@ module Ecoportal
85
90
  "id" => id,
86
91
  "operation" => "delete"
87
92
  }
93
+ #,
94
+ #{}"data" => patch_data(b, delete: true)
88
95
  end
89
96
 
90
97
  def patch_new(a)
@@ -1,3 +1,5 @@
1
+ require 'base64'
2
+
1
3
  module Ecoportal
2
4
  module API
3
5
  # @attr_reader client [Common::Client] a `Common::Client` object that holds the configuration of the api connection.
@@ -8,19 +10,33 @@ module Ecoportal
8
10
 
9
11
  VERSION = "v2"
10
12
 
13
+ class << self
14
+ def v2key (ukey, gkey)
15
+ Base64.urlsafe_encode64({
16
+ organization: gkey,
17
+ user: ukey
18
+ }.to_json)
19
+ end
20
+ end
21
+
11
22
  class_resolver :registers_class, "Ecoportal::API::V2::Registers"
12
23
  class_resolver :pages_class, "Ecoportal::API::V2::Pages"
13
24
 
14
25
  attr_reader :client, :logger
15
26
 
16
27
  # Creates an `V2` object to scope version specific api requests.
28
+ # @note
29
+ # - you should use either `api_key` or `user_key` and `org_key`
17
30
  # @param api_key [String] the key version to stablish the api connection.
31
+ # @param user_key [String] the user key used for the api connection (requires `org_key`).
32
+ # @param org_key [String] the org key used for the api connection (requires `user_key`).
18
33
  # @param host [String] api server domain.
19
34
  # @param logger [Logger] an object with `Logger` interface to generate logs.
20
- def initialize(api_key, host: "live.ecoportal.com", logger: default_logger)
35
+ def initialize(api_key = nil, user_key: nil, org_key: nil, host: "live.ecoportal.com", logger: default_logger)
36
+ v2key = get_key(api_key: api_key, user_key: user_key, org_key: org_key)
21
37
  @logger = logger
22
38
  @client = Common::Content::Client.new(
23
- api_key: api_key,
39
+ api_key: v2key,
24
40
  host: host,
25
41
  version: self.class::VERSION,
26
42
  logger: @logger
@@ -39,6 +55,15 @@ module Ecoportal
39
55
  pages_class.new(client)
40
56
  end
41
57
 
58
+ private
59
+
60
+ def get_key(api_key: nil, user_key: nil, org_key: nil)
61
+ return self.class.v2key(user_key, org_key) if user_key && org_key
62
+ return api_key if api_key #|| ENV['X_ECOPORTAL_API_KEY']
63
+ raise "You need to provide either an api_key or user_key" unless user_key
64
+ raise "You need to provide an org_key as well (not just a user_key)" unless org_key
65
+ end
66
+
42
67
  end
43
68
  end
44
69
  end
@@ -15,9 +15,9 @@ module Ecoportal
15
15
  class_resolver :sections_class, "Ecoportal::API::V2::Page::Sections"
16
16
  class_resolver :stages_class, "Ecoportal::API::V2::Page::Stages"
17
17
 
18
- embeds_one :components, multiple: true, klass: :components_class
19
- embeds_one :sections, multiple: true, klass: :sections_class
20
- embeds_one :stages, multiple: true, klass: :stages_class
18
+ embeds_many :components, enum_class: :components_class
19
+ embeds_many :sections, enum_class: :sections_class
20
+ embeds_many :stages, enum_class: :stages_class
21
21
 
22
22
  def as_update
23
23
  super.tap do |hash|
@@ -21,6 +21,8 @@ module Ecoportal
21
21
  class_resolver :signature_field_class, "Ecoportal::API::V2::Page::Component::SignatureField"
22
22
  class_resolver :reference_field_class, "Ecoportal::API::V2::Page::Component::ReferenceField"
23
23
  class_resolver :law_field_class, "Ecoportal::API::V2::Page::Component::LawField"
24
+ class_resolver :chart_field_class, "Ecoportal::API::V2::Page::Component::ChartField"
25
+ class_resolver :chart_fr_field_class, "Ecoportal::API::V2::Page::Component::ChartFrField"
24
26
 
25
27
  class << self
26
28
  def new_doc(type:)
@@ -53,7 +55,8 @@ module Ecoportal
53
55
  people_field_class
54
56
  when "checklist"
55
57
  checklist_field_class
56
- when "page_action"
58
+ when "page_action","checklist_task"
59
+ #doc["type"] = "checklist_task"
57
60
  action_field_class
58
61
  when "file"
59
62
  files_field_class
@@ -65,6 +68,10 @@ module Ecoportal
65
68
  reference_field_class
66
69
  when "law"
67
70
  law_field_class
71
+ when "chart"
72
+ chart_field_class
73
+ when "frequency_rate_chart"
74
+ chart_fr_field_class
68
75
  else
69
76
  self
70
77
  end
@@ -75,7 +82,7 @@ module Ecoportal
75
82
  passkey :id
76
83
  passthrough :patch_ver, :undeletable
77
84
  passthrough :type, :label, :tooltip, :global_binding
78
- passthrough :hidden, :accent, :deindex
85
+ passthrough :hidden, :accent, :deindex, :required
79
86
  passthrough :hide_view, :hidden_on_reports, :hidden_on_mobile
80
87
 
81
88
  def ref
@@ -114,3 +121,5 @@ require 'ecoportal/api/v2/page/component/images_field'
114
121
  require 'ecoportal/api/v2/page/component/signature_field'
115
122
  require 'ecoportal/api/v2/page/component/reference_field'
116
123
  require 'ecoportal/api/v2/page/component/law_field'
124
+ require 'ecoportal/api/v2/page/component/chart_field'
125
+ require 'ecoportal/api/v2/page/component/chart_fr_field'
@@ -4,11 +4,22 @@ module Ecoportal
4
4
  class Page
5
5
  class Component
6
6
  class Action < Common::Content::DoubleModel
7
+ class << self
8
+ def new_doc
9
+ {
10
+ "id" => new_uuid,
11
+ "weight" => 9999
12
+ }
13
+ end
14
+ end
15
+
7
16
  passkey :id
8
17
  passthrough :patch_ver, :name
9
- passthrough :weight, :complete, :overdue, :other_information
10
- passdate :due_date, :created_at #, :completed_at
11
- passthrough :created_by, :assigned_person_member_id
18
+ passthrough :weight, :complete, :other_information
19
+ passdate :due_date
20
+ pass_reader :overdue
21
+ passdate :created_at, read_only: true #, :completed_at
22
+ pass_reader :created_by, :assigned_person_member_id
12
23
  end
13
24
  end
14
25
  end
@@ -4,8 +4,46 @@ module Ecoportal
4
4
  class Page
5
5
  class Component
6
6
  class ActionField < Page::Component
7
- #class_resolver :action_class, "Ecoportal::API::V2::Page::Component::Action"
8
- embeds_multiple :actions, klass: "Ecoportal::API::V2::Page::Component::Action", order_key: :weight
7
+ passthrough :create_actions
8
+ passthrough :required_number_of_completed_actions
9
+ passthrough :permits_and_rules_integration, :add_subscribed, :add_subscribed_to_tasks
10
+
11
+ embeds_many :actions, klass: "Ecoportal::API::V2::Page::Component::Action", order_key: :weight
12
+
13
+ # Adds a task with `name` short description
14
+ # @return [Ecoportal::API::V2::Page::Component::Action]
15
+ def add_task (name)
16
+ task_doc = actions.items_class.new_doc
17
+ actions.upsert!(task_doc) do |task|
18
+ task.name = name
19
+ if prev = previous_task(task)
20
+ task.weight = prev.weight
21
+ end
22
+ yield(task) if block_given?
23
+ fix_task_weights!
24
+ end
25
+ end
26
+
27
+ def ordered_tasks
28
+ actions.each_with_index.sort_by do |task, index|
29
+ (task.weight >= 9999) ? [index, index] : [task.weight, index]
30
+ end.map(&:first)
31
+ end
32
+
33
+ private
34
+
35
+ def fix_task_weights!
36
+ ordered_tasks.each_with_index do |task, index|
37
+ task.weight = index
38
+ end
39
+ end
40
+
41
+ def previous_task(value)
42
+ tasks = ordered_tasks
43
+ pos = tasks.index(value) - 1
44
+ return if pos < 0
45
+ tasks[pos]
46
+ end
9
47
  end
10
48
  end
11
49
  end