ecoportal-api-oozes 0.7.3 → 0.7.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (28) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +25 -2
  3. data/lib/ecoportal/api/common/content/collection_model.rb +5 -0
  4. data/lib/ecoportal/api/common/content/double_model.rb +27 -12
  5. data/lib/ecoportal/api/common/content/hash_diff_patch.rb +8 -1
  6. data/lib/ecoportal/api/v2/page.rb +3 -3
  7. data/lib/ecoportal/api/v2/page/component.rb +8 -0
  8. data/lib/ecoportal/api/v2/page/component/action_field.rb +2 -2
  9. data/lib/ecoportal/api/v2/page/component/chart_field.rb +54 -0
  10. data/lib/ecoportal/api/v2/page/component/chart_field/frequency.rb +29 -0
  11. data/lib/ecoportal/api/v2/page/component/chart_field/heatmap.rb +27 -0
  12. data/lib/ecoportal/api/v2/page/component/chart_field/indicator.rb +26 -0
  13. data/lib/ecoportal/api/v2/page/component/chart_field/multiseries.rb +31 -0
  14. data/lib/ecoportal/api/v2/page/component/chart_field/sankey.rb +27 -0
  15. data/lib/ecoportal/api/v2/page/component/chart_field/serie.rb +26 -0
  16. data/lib/ecoportal/api/v2/page/component/chart_field/series_config.rb +23 -0
  17. data/lib/ecoportal/api/v2/page/component/chart_fr_field.rb +32 -0
  18. data/lib/ecoportal/api/v2/page/component/checklist_field.rb +2 -2
  19. data/lib/ecoportal/api/v2/page/component/date_field.rb +18 -0
  20. data/lib/ecoportal/api/v2/page/component/files_field.rb +1 -2
  21. data/lib/ecoportal/api/v2/page/component/gauge_field.rb +2 -2
  22. data/lib/ecoportal/api/v2/page/component/gauge_stop.rb +62 -0
  23. data/lib/ecoportal/api/v2/page/component/images_field.rb +1 -2
  24. data/lib/ecoportal/api/v2/page/component/selection_field.rb +2 -3
  25. data/lib/ecoportal/api/v2/page/components.rb +2 -2
  26. data/lib/ecoportal/api/v2/page/sections.rb +1 -1
  27. data/lib/ecoportal/api/v2/version.rb +1 -1
  28. metadata +11 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d9c761acea6fa4c7a6cef0c0b56716906368032d14e891fbcad192487a3d46f4
4
- data.tar.gz: b16661800fd19357336f645832fe0a053105febdc2e58a4556d66c2c084742a8
3
+ metadata.gz: 6039e6c6b1c32fcbcd956ef9a425588cbd9dfe94d06898223af14f433bab2c3a
4
+ data.tar.gz: c4dca6d50e4a664d343942636079f7c3cfe11999502ca891e8cf1f8598ed79f3
5
5
  SHA512:
6
- metadata.gz: 2931d29722ac006672127d5c675ae3522c84b118075f244ec96c3b0d1534d2170595bfbcc4e0f616de9162f46f085f2e02bce50426ba55e331f3380ef20961d7
7
- data.tar.gz: 40ca60459ecc7cf9569d49a8c57a3866176b867f7dbd620941e2b975f48e9071c53cea0a6e28dab1f8fe245ca048e4108351bf16ca2b05494952c202581d36ac
6
+ metadata.gz: 91f9c47478b1054e0efb2380bb623c951d751f10c24a833b7fd380ddaa35bdc825b42b5574f23524accfc0e10ba692857c0597be9805cde1acede6d5959b0730
7
+ data.tar.gz: 2106b17efa000c7d1b44ce667bf3d80fe84a4c59bb7c0772cc8d19396e5fa024e39fc7823064e9531ac9c82037be3bfdc17e8827ae41ae1bdb7b648c15d52abe
data/CHANGELOG.md CHANGED
@@ -1,7 +1,31 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
- ## [0.7.3] - 2020-10-xx
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
5
29
 
6
30
  ### Added
7
31
  - `Ecoportal::API::Common::Content::CollectionModel#delete!` finally scoped how delete should work :)
@@ -33,7 +57,6 @@ All notable changes to this project will be documented in this file.
33
57
  - `Ecoportal::API::V2::Page::Section` more supported properties:
34
58
  * `minimized`
35
59
 
36
-
37
60
  ### Changed
38
61
  - upgraded `ecoportal-api` dependency
39
62
 
@@ -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})"
@@ -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)
@@ -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:)
@@ -66,6 +68,10 @@ module Ecoportal
66
68
  reference_field_class
67
69
  when "law"
68
70
  law_field_class
71
+ when "chart"
72
+ chart_field_class
73
+ when "frequency_rate_chart"
74
+ chart_fr_field_class
69
75
  else
70
76
  self
71
77
  end
@@ -115,3 +121,5 @@ require 'ecoportal/api/v2/page/component/images_field'
115
121
  require 'ecoportal/api/v2/page/component/signature_field'
116
122
  require 'ecoportal/api/v2/page/component/reference_field'
117
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'
@@ -8,12 +8,12 @@ module Ecoportal
8
8
  passthrough :required_number_of_completed_actions
9
9
  passthrough :permits_and_rules_integration, :add_subscribed, :add_subscribed_to_tasks
10
10
 
11
- embeds_multiple :actions, klass: "Ecoportal::API::V2::Page::Component::Action", order_key: :weight
11
+ embeds_many :actions, klass: "Ecoportal::API::V2::Page::Component::Action", order_key: :weight
12
12
 
13
13
  # Adds a task with `name` short description
14
14
  # @return [Ecoportal::API::V2::Page::Component::Action]
15
15
  def add_task (name)
16
- task_doc = Ecoportal::API::V2::Page::Component::Action.new_doc
16
+ task_doc = actions.items_class.new_doc
17
17
  actions.upsert!(task_doc) do |task|
18
18
  task.name = name
19
19
  if prev = previous_task(task)
@@ -0,0 +1,54 @@
1
+ module Ecoportal
2
+ module API
3
+ class V2
4
+ class Page
5
+ class Component
6
+ class ChartField < Page::Component
7
+ passthrough :mode
8
+ passthrough :relative, :relstart, :relbound
9
+ passthrough :bounded, :ubound, :lbound
10
+ passthrough :filter_date_input
11
+ passthrough :user_id, :lock_chart_user
12
+
13
+ embeds_one :series_config, klass: "Ecoportal::API::V2::Page::Component::ChartField::SeriesConfig"
14
+ embeds_one :frequency_config, klass: "Ecoportal::API::V2::Page::Component::ChartField::Frequency"
15
+ embeds_one :heatmap_config, klass: "Ecoportal::API::V2::Page::Component::ChartField::Heatmap"
16
+ embeds_one :sankey_config, klass: "Ecoportal::API::V2::Page::Component::ChartField::Sankey"
17
+ embeds_one :indicator_config, klass: "Ecoportal::API::V2::Page::Component::ChartField::Indicator"
18
+ embeds_one :faceted_series_config, klass: "Ecoportal::API::V2::Page::Component::ChartField::Multiseries"
19
+
20
+ embeds_many :series, klass: "Ecoportal::API::V2::Page::Component::ChartField::Serie"
21
+
22
+ MODES = ["frequency", "series", "heatmap", "sankey", "indicator", "faceted_series"]
23
+
24
+ def config
25
+ case mode
26
+ when "frequency"
27
+ frequency_config
28
+ when "series"
29
+ series_config
30
+ when "heatmap"
31
+ heatmap_config
32
+ when "sankey"
33
+ sankey_config
34
+ when "indicator"
35
+ indicator_config
36
+ when "faceted_series"
37
+ faceted_series_config
38
+ end
39
+ end
40
+
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ require 'ecoportal/api/v2/page/component/chart_field/frequency'
49
+ require 'ecoportal/api/v2/page/component/chart_field/series_config'
50
+ require 'ecoportal/api/v2/page/component/chart_field/serie'
51
+ require 'ecoportal/api/v2/page/component/chart_field/heatmap'
52
+ require 'ecoportal/api/v2/page/component/chart_field/sankey'
53
+ require 'ecoportal/api/v2/page/component/chart_field/indicator'
54
+ require 'ecoportal/api/v2/page/component/chart_field/multiseries'
@@ -0,0 +1,29 @@
1
+ module Ecoportal
2
+ module API
3
+ class V2
4
+ class Page
5
+ class Component
6
+ class ChartField
7
+ class Frequency < Common::Content::DoubleModel
8
+ passkey :id
9
+ passthrough :patch_ver
10
+ passthrough :register_id, :source_type
11
+
12
+ passthrough :mode, :input
13
+ passarray :tags
14
+ passthrough :secondary
15
+
16
+ passthrough :output, :bar_mode
17
+ passthrough :series_size, :skip_zeroes
18
+
19
+ passarray :filters, :people_filters, :task_filters
20
+
21
+ passthrough :color
22
+ passarray :color_map
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,27 @@
1
+ module Ecoportal
2
+ module API
3
+ class V2
4
+ class Page
5
+ class Component
6
+ class ChartField
7
+ class Heatmap < Common::Content::DoubleModel
8
+ passkey :id
9
+ passthrough :patch_ver
10
+ passthrough :register_id, :source_type
11
+
12
+ passthrough :xinput, :xmode
13
+ passthrough :yinput, :ymode
14
+ passarray :xtags, :ytags
15
+
16
+ passthrough :bucket_type
17
+
18
+ passarray :filters, :people_filters, :task_filters
19
+
20
+ passthrough :color
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,26 @@
1
+ module Ecoportal
2
+ module API
3
+ class V2
4
+ class Page
5
+ class Component
6
+ class ChartField
7
+ class Indicator < Common::Content::DoubleModel
8
+ passkey :id
9
+ passthrough :patch_ver
10
+ passthrough :register_id, :source_type
11
+
12
+ passthrough :date_input, :secondary
13
+ passthrough :duration, :math_mode, :currency
14
+
15
+ passthrough :display_previous, :change_format, :invert_colors
16
+
17
+ passarray :filters, :people_filters, :task_filters
18
+
19
+ passthrough :color
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,31 @@
1
+ module Ecoportal
2
+ module API
3
+ class V2
4
+ class Page
5
+ class Component
6
+ class ChartField
7
+ class Multiseries < Common::Content::DoubleModel
8
+ passkey :id
9
+ passthrough :patch_ver
10
+ passthrough :register_id, :source_type
11
+
12
+ passthrough :xinput, :xlabel
13
+ passthrough :interval, :calc_mode
14
+
15
+ passthrough :yinput, :ylabel
16
+ passthrough :facet_by_discrete, :discrete_facet
17
+ passthrough :facet_by_tags
18
+ passarray :facet_tags
19
+
20
+ passarray :filters, :people_filters, :task_filters
21
+
22
+ passthrough :display_mode, :display_type
23
+ passthrough :color
24
+ passarray :color_map
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,27 @@
1
+ module Ecoportal
2
+ module API
3
+ class V2
4
+ class Page
5
+ class Component
6
+ class ChartField
7
+ class Sankey < Common::Content::DoubleModel
8
+ passkey :id
9
+ passthrough :patch_ver
10
+ passthrough :register_id, :source_type
11
+
12
+ passthrough :xinput, :xmode
13
+ passthrough :yinput, :ymode
14
+ passthrough :zinput, :zmode
15
+ passarray :xtags, :ytags, :ztags
16
+
17
+ passarray :filters, :people_filters, :task_filters
18
+
19
+ passthrough :color
20
+ passarray :color_map
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,26 @@
1
+ module Ecoportal
2
+ module API
3
+ class V2
4
+ class Page
5
+ class Component
6
+ class ChartField
7
+ class Serie < Common::Content::DoubleModel
8
+ passkey :id
9
+ passthrough :patch_ver
10
+ passthrough :register_id
11
+
12
+ passthrough :input, :type
13
+ passarray :y_axes
14
+
15
+ passthrough :visual, :stacked
16
+
17
+ passarray :filters, :people_filters, :task_filters
18
+
19
+ passthrough :color
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,23 @@
1
+ module Ecoportal
2
+ module API
3
+ class V2
4
+ class Page
5
+ class Component
6
+ class ChartField
7
+ class SeriesConfig < Common::Content::DoubleModel
8
+ passkey :id
9
+ passthrough :patch_ver
10
+
11
+ passthrough :xlabel, :xtype
12
+ passthrough :interval, :calc_mode, :comparative_year
13
+ passthrough :ylabel
14
+
15
+ passthrough :filled_up_with_zeros, :zero_y, :bounds_rigid
16
+ passthrough :stack_all
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,32 @@
1
+ module Ecoportal
2
+ module API
3
+ class V2
4
+ class Page
5
+ class Component
6
+ class ChartFrField < Page::Component
7
+ passthrough :register_id, :date_input
8
+ passthrough :filter
9
+
10
+ passthrough :facet_by_tags, :facet_by_select
11
+ passthrough :select_input, :select_mapping
12
+ passarray :facet_tags
13
+
14
+ passthrough :relative, :relstart, :relbound
15
+ passthrough :bounded, :ubound, :lbound
16
+
17
+ passthrough :display_mode, :display_type
18
+ passarray :guidelines
19
+ passthrough :cumulative, :cumulative_mode, :cumulative_start
20
+ passthrough :multiplier, :granularity
21
+
22
+ passthrough :color
23
+ passarray :color_map
24
+
25
+ passthrough :chart_user
26
+
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -4,10 +4,10 @@ module Ecoportal
4
4
  class Page
5
5
  class Component
6
6
  class ChecklistField < Page::Component
7
- embeds_multiple :items, klass: "Ecoportal::API::V2::Page::Component::ChecklistItem", order_key: :weight
7
+ embeds_many :items, klass: "Ecoportal::API::V2::Page::Component::ChecklistItem", order_key: :weight
8
8
 
9
9
  def add_item(label:, pos: NOT_USED, before: NOT_USED, after: NOT_USED)
10
- itm_doc = Ecoportal::API::V2::Page::Component::ChecklistItem.new_doc
10
+ itm_doc = items.stops.items_class.new_doc
11
11
  items.upsert!(itm_doc, pos: pos, before: before, after: after) do |item|
12
12
  item.label = label
13
13
  if prev = previous_item(item)
@@ -8,6 +8,24 @@ module Ecoportal
8
8
  passthrough :show_time, :today_button, :past_only
9
9
  passthrough :create_event, :remind_me_in
10
10
  passthrough :renews, :renews_every, :renews_unit, :renews_until
11
+
12
+ ISO8601 = "%Y-%m-%dT%H:%M:00Z" # "%Y-%m-%dT%H:%M:00.00Z"
13
+
14
+ def value=(val)
15
+ doc["value"] = self.class.to_time(val).yield_self do |datetime|
16
+ datetime = datetime.utc.strftime(ISO8601) if datetime
17
+ datetime
18
+ end
19
+ end
20
+
21
+ def value
22
+ if val = doc["value"]
23
+ (Time.parse(val) rescue nil).yield_self do |datetime|
24
+ datetime.localtime if datetime
25
+ end
26
+ end
27
+ end
28
+
11
29
  end
12
30
  end
13
31
  end
@@ -4,8 +4,7 @@ module Ecoportal
4
4
  class Page
5
5
  class Component
6
6
  class FilesField < Page::Component
7
- #class_resolver :file_class, "Ecoportal::API::V2::Page::File"
8
- embeds_multiple :items, klass: "Ecoportal::API::V2::Page::File", order_key: :position
7
+ embeds_many :items, klass: "Ecoportal::API::V2::Page::File", order_key: :position
9
8
  end
10
9
  end
11
10
  end
@@ -7,12 +7,12 @@ module Ecoportal
7
7
  passthrough :value, :max
8
8
  passthrough :active_color
9
9
 
10
- embeds_multiple :stops, klass: "Ecoportal::API::V2::Page::Component::GaugeStop", order_key: :threshold
10
+ embeds_many :stops, klass: "Ecoportal::API::V2::Page::Component::GaugeStop", order_key: :threshold
11
11
 
12
12
  # Adds a stop at `threshold` with `color`
13
13
  # @return [Ecoportal::API::V2::Page::Component::GaugeStop]
14
14
  def add_stop (threshold: 0.0, color: '#e256d1')
15
- stop_doc = Ecoportal::API::V2::Page::Component::GaugeStop.new_doc
15
+ stop_doc = stops.items_class.new_doc
16
16
  stops.upsert!(stop_doc) do |stop|
17
17
  stop.threshold = threshold
18
18
  stop.color = color
@@ -18,6 +18,68 @@ module Ecoportal
18
18
  passkey :id
19
19
  passthrough :patch_ver, :threshold
20
20
  passthrough :color
21
+
22
+ # Assign the color to the stop.
23
+ # @note These are the available colors:
24
+ # - :blue, :blue_greyed, :blue_light
25
+ # - :turquoise, :jade, :green, :pistachio, :avocado
26
+ # - :yellow, :orange, :pumpkin, :red, :magenta, :fuchsia, :purple, :violet
27
+ # @param value [String, Symbol] you can use a `symbol` to specify a color
28
+ def color=(value)
29
+ value = to_color(value) if value.is_a?(Symbol)
30
+ doc["color"] = value
31
+ end
32
+
33
+ # @return [Symbol] to get the `color` sym code
34
+ def color_sym
35
+ color_maps.each do |k, v|
36
+ return k if color == v
37
+ end
38
+ :undefined
39
+ end
40
+
41
+ private
42
+
43
+ def to_color(value)
44
+ return nil unless valid_color?(value)
45
+ return value if value.is_a?(String)
46
+ color_maps[value]
47
+ end
48
+
49
+ def valid_color?(value)
50
+ return true if value.is_a?(String) && colors.any? {|c| c == value}
51
+ return true if value.is_a?(Symbol) && color_syms.any? {|s| s == value}
52
+ end
53
+
54
+ def color_syms
55
+ @color_syms ||= color_maps.keys
56
+ end
57
+
58
+ def colors
59
+ @colors ||= color_maps.values
60
+ end
61
+
62
+ def color_maps
63
+ @color_maps ||= [
64
+ [:blue, "#5656e2"],
65
+ [:blue_greyed, "#568be2"],
66
+ [:blue_light, "#56c0e2"],
67
+ [:turquoise, "#56e2cf"],
68
+ [:jade, "#56e29b"],
69
+ [:green, "#56e267"],
70
+ [:pistachio, "#79e256"],
71
+ [:avocado, "#aee256"],
72
+ [:yellow, "#e2e156"],
73
+ [:orange, "#e2ad56"],
74
+ [:pumpkin, "#e27956"],
75
+ [:red, "#e25667"],
76
+ [:magenta, "#e2569c"],
77
+ [:fuchsia, "#e256d1"],
78
+ [:purple, "#be56e2"],
79
+ [:violet, "#8a56e2"]
80
+ ].to_h
81
+ end
82
+
21
83
  end
22
84
  end
23
85
  end
@@ -4,8 +4,7 @@ module Ecoportal
4
4
  class Page
5
5
  class Component
6
6
  class ImagesField < Page::Component
7
- #class_resolver :image_class, "Ecoportal::API::V2::Page::Image"
8
- embeds_multiple :images, klass: "Ecoportal::API::V2::Page::Image", order_key: :weight
7
+ embeds_many :images, klass: "Ecoportal::API::V2::Page::Image", order_key: :weight
9
8
  end
10
9
  end
11
10
  end
@@ -7,8 +7,7 @@ module Ecoportal
7
7
  passthrough :multiple, :flat
8
8
  passthrough :other, :other_desc
9
9
 
10
- #class_resolver :selection_option_class, "Ecoportal::API::V2::Page::Component::SelectionOption"
11
- embeds_multiple :options, klass: "Ecoportal::API::V2::Page::Component::SelectionOption", order_key: :weight
10
+ embeds_many :options, klass: "Ecoportal::API::V2::Page::Component::SelectionOption", order_key: :weight
12
11
 
13
12
  def select(value)
14
13
  opt = options.find {|opt| opt.value == value}
@@ -35,7 +34,7 @@ module Ecoportal
35
34
  end
36
35
 
37
36
  def add_option(name:, value:, pos: NOT_USED, before: NOT_USED, after: NOT_USED)
38
- opt_doc = Ecoportal::API::V2::Page::Component::SelectionOption.new_doc
37
+ opt_doc = options.items_class.new_doc
39
38
  options.upsert!(opt_doc, pos: pos, before: before, after: after) do |option|
40
39
  option.name = name
41
40
  option.value = value
@@ -21,14 +21,14 @@ module Ecoportal
21
21
 
22
22
  def get_by_name(name, type: nil)
23
23
  pool = type ? get_by_type(type) : self
24
-
24
+
25
25
  pool.select do |comp|
26
26
  comp.label.to_s.strip.downcase == name.to_s.strip.downcase
27
27
  end.first
28
28
  end
29
29
 
30
30
  def add(label:, type:)
31
- fld_doc = Ecoportal::API::V2::Page::Component.new_doc(type: type)
31
+ fld_doc = component_class.new_doc(type: type)
32
32
  upsert!(fld_doc) do |fld|
33
33
  fld.label = label
34
34
  yield(fld) if block_given?
@@ -8,7 +8,7 @@ module Ecoportal
8
8
  self.klass = :section_class
9
9
 
10
10
  def add(name: nil, split: false, pos: NOT_USED, before: NOT_USED, after: NOT_USED)
11
- sec_doc = Ecoportal::API::V2::Page::Section.new_doc(split: split)
11
+ sec_doc = section_class.new_doc(split: split)
12
12
  upsert!(sec_doc, pos: pos, before: before, after: after) do |section|
13
13
  section.heading = name
14
14
  if prev = previous_section(section)
@@ -1,7 +1,7 @@
1
1
  module Ecoportal
2
2
  module API
3
3
  class V2
4
- GEM_VERSION = "0.7.3"
4
+ GEM_VERSION = "0.7.4"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ecoportal-api-oozes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.3
4
+ version: 0.7.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oscar Segura
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-02-01 00:00:00.000000000 Z
11
+ date: 2021-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -183,6 +183,15 @@ files:
183
183
  - lib/ecoportal/api/v2/page/component.rb
184
184
  - lib/ecoportal/api/v2/page/component/action.rb
185
185
  - lib/ecoportal/api/v2/page/component/action_field.rb
186
+ - lib/ecoportal/api/v2/page/component/chart_field.rb
187
+ - lib/ecoportal/api/v2/page/component/chart_field/frequency.rb
188
+ - lib/ecoportal/api/v2/page/component/chart_field/heatmap.rb
189
+ - lib/ecoportal/api/v2/page/component/chart_field/indicator.rb
190
+ - lib/ecoportal/api/v2/page/component/chart_field/multiseries.rb
191
+ - lib/ecoportal/api/v2/page/component/chart_field/sankey.rb
192
+ - lib/ecoportal/api/v2/page/component/chart_field/serie.rb
193
+ - lib/ecoportal/api/v2/page/component/chart_field/series_config.rb
194
+ - lib/ecoportal/api/v2/page/component/chart_fr_field.rb
186
195
  - lib/ecoportal/api/v2/page/component/checklist_field.rb
187
196
  - lib/ecoportal/api/v2/page/component/checklist_item.rb
188
197
  - lib/ecoportal/api/v2/page/component/date_field.rb