ecoportal-api-v2 0.8.5 → 0.8.9

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 (53) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +60 -25
  3. data/bin/console +1 -1
  4. data/ecoportal-api-v2.gemspec +5 -5
  5. data/lib/ecoportal/api-v2.rb +2 -2
  6. data/lib/ecoportal/api/common.v2.rb +8 -0
  7. data/lib/ecoportal/api/common/content.rb +1 -0
  8. data/lib/ecoportal/api/common/content/array_model.rb +8 -6
  9. data/lib/ecoportal/api/common/content/collection_model.rb +10 -4
  10. data/lib/ecoportal/api/common/content/double_model.rb +15 -4
  11. data/lib/ecoportal/api/common/content/hash_diff_patch.rb +31 -19
  12. data/lib/ecoportal/api/common/content/model_helpers.rb +36 -0
  13. data/lib/ecoportal/api/v2/page.rb +2 -0
  14. data/lib/ecoportal/api/v2/page/component.rb +33 -3
  15. data/lib/ecoportal/api/v2/page/component/action.rb +13 -5
  16. data/lib/ecoportal/api/v2/page/component/action_field.rb +37 -2
  17. data/lib/ecoportal/api/v2/page/component/chart_field.rb +43 -5
  18. data/lib/ecoportal/api/v2/page/component/chart_field/benchmark.rb +30 -0
  19. data/lib/ecoportal/api/v2/page/component/chart_field/config.rb +23 -0
  20. data/lib/ecoportal/api/v2/page/component/chart_field/frequency.rb +3 -4
  21. data/lib/ecoportal/api/v2/page/component/chart_field/heatmap.rb +1 -3
  22. data/lib/ecoportal/api/v2/page/component/chart_field/indicator.rb +4 -5
  23. data/lib/ecoportal/api/v2/page/component/chart_field/multiseries.rb +3 -5
  24. data/lib/ecoportal/api/v2/page/component/chart_field/sankey.rb +1 -3
  25. data/lib/ecoportal/api/v2/page/component/chart_field/serie.rb +3 -4
  26. data/lib/ecoportal/api/v2/page/component/chart_field/series_config.rb +5 -7
  27. data/lib/ecoportal/api/v2/page/component/chart_fr_field.rb +7 -5
  28. data/lib/ecoportal/api/v2/page/component/checklist_field.rb +1 -1
  29. data/lib/ecoportal/api/v2/page/component/checklist_item.rb +3 -2
  30. data/lib/ecoportal/api/v2/page/component/date_field.rb +71 -4
  31. data/lib/ecoportal/api/v2/page/component/file.rb +3 -2
  32. data/lib/ecoportal/api/v2/page/component/gauge_field.rb +2 -2
  33. data/lib/ecoportal/api/v2/page/component/geo_coordinates.rb +13 -0
  34. data/lib/ecoportal/api/v2/page/component/geo_field.rb +4 -1
  35. data/lib/ecoportal/api/v2/page/component/images_field.rb +57 -1
  36. data/lib/ecoportal/api/v2/page/component/people_field.rb +104 -6
  37. data/lib/ecoportal/api/v2/page/component/plain_text_field.rb +34 -2
  38. data/lib/ecoportal/api/v2/page/component/reference_field.rb +32 -3
  39. data/lib/ecoportal/api/v2/page/component/selection_field.rb +71 -4
  40. data/lib/ecoportal/api/v2/page/component/selection_option.rb +12 -2
  41. data/lib/ecoportal/api/v2/page/component/tag_field.rb +31 -1
  42. data/lib/ecoportal/api/v2/page/components.rb +8 -3
  43. data/lib/ecoportal/api/v2/page/permission_flags.rb +67 -0
  44. data/lib/ecoportal/api/v2/page/permit.rb +14 -0
  45. data/lib/ecoportal/api/v2/page/section.rb +65 -5
  46. data/lib/ecoportal/api/v2/page/sections.rb +64 -6
  47. data/lib/ecoportal/api/v2/page/stage.rb +11 -3
  48. data/lib/ecoportal/api/v2/page/stages.rb +7 -7
  49. data/lib/ecoportal/api/v2/pages/page_stage.rb +3 -3
  50. data/lib/ecoportal/api/v2_version.rb +5 -0
  51. metadata +16 -10
  52. data/lib/ecoportal/api/common.rb +0 -18
  53. data/lib/ecoportal/api/v2/version.rb +0 -7
@@ -7,7 +7,7 @@ module Ecoportal
7
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 = items.stops.items_class.new_doc
10
+ itm_doc = items.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)
@@ -13,10 +13,11 @@ module Ecoportal
13
13
  }
14
14
  end
15
15
  end
16
-
16
+
17
17
  passkey :id
18
18
  passthrough :patch_ver, :label
19
- passthrough :weight, :checked
19
+ passthrough :weight
20
+ passboolean :checked
20
21
  end
21
22
  end
22
23
  end
@@ -4,10 +4,13 @@ module Ecoportal
4
4
  class Page
5
5
  class Component
6
6
  class DateField < Page::Component
7
- passthrough :value
8
- passthrough :show_time, :today_button, :past_only
9
- passthrough :create_event, :remind_me_in
10
- passthrough :renews, :renews_every, :renews_unit, :renews_until
7
+ passdate :value
8
+ passboolean :show_time, :today_button, :past_only
9
+ passboolean :create_event
10
+ passthrough :remind_me_in
11
+ passboolean :renews
12
+ passthrough :renews_every, :renews_unit
13
+ passdate :renews_until
11
14
 
12
15
  ISO8601 = "%Y-%m-%dT%H:%M:00Z" # "%Y-%m-%dT%H:%M:00.00Z"
13
16
 
@@ -26,6 +29,70 @@ module Ecoportal
26
29
  end
27
30
  end
28
31
 
32
+ def create_event=(value)
33
+ self.past_only = false
34
+ doc["create_event"] = !!value
35
+ end
36
+
37
+ # Quick config helper
38
+ # @param conf [Symbol, Array<Symbol>]
39
+ # - `:time` to show time
40
+ # - `:now_button` to display `NOW` button
41
+ # - `:past` to only allow past dates
42
+ # - `:event` to enable event
43
+ # - `:reminder` to set the reminder (requires `:event`)
44
+ # - `:never`
45
+ # - `:one_day`
46
+ # - `:three_days`
47
+ # - `:one_week`
48
+ # - `:two_weeks`
49
+ # - `:one_month`
50
+ def configure(*conf)
51
+ conf.each_with_object([]) do |cnf, unused|
52
+ case cnf
53
+ when :time
54
+ self.show_time = true
55
+ when :now_button
56
+ self.today_button = true
57
+ when :past
58
+ self.past_only = true
59
+ when :event
60
+ self.create_event = true
61
+ when Hash
62
+ supported = [:reminder]
63
+ unless (rest = hash_except(cnf.dup, *supported)).empty?
64
+ unused.push(rest)
65
+ end
66
+ if cnf.key?(:reminder) then configure_reminder(cnf[:reminder]) end
67
+ else
68
+ unused.push(cnf)
69
+ end
70
+ end.yield_self do |unused|
71
+ super(*unused)
72
+ end
73
+ end
74
+
75
+ private
76
+
77
+ def configure_reminder(value)
78
+ case value
79
+ when :never, NilClass
80
+ self.remind_me_in = "never"
81
+ when :one_day
82
+ self.remind_me_in = "1.day"
83
+ when :three_days
84
+ self.remind_me_in = "3.days"
85
+ when :one_week
86
+ self.remind_me_in = "1.week"
87
+ when :two_weeks
88
+ self.remind_me_in = "2.weeks"
89
+ when :one_month
90
+ self.remind_me_in = "1.month"
91
+ else
92
+ # Unsupported
93
+ end
94
+ end
95
+
29
96
  end
30
97
  end
31
98
  end
@@ -6,8 +6,9 @@ module Ecoportal
6
6
  class File < Common::Content::DoubleModel
7
7
  passkey :id
8
8
  passthrough :patch_ver, :position
9
- passthrough :content_type, :file_size, :file_container_id
10
- passdate :file_update_at
9
+ passthrough :file_size, :token, read_only: true
10
+ passthrough :content_type, :file_container_id
11
+ passdate :file_update_at, read_only: true
11
12
  end
12
13
  end
13
14
  end
@@ -5,13 +5,13 @@ module Ecoportal
5
5
  class Component
6
6
  class GaugeField < Page::Component
7
7
  passthrough :value, :max
8
- passthrough :active_color
8
+ passthrough :active_color, read_only: true
9
9
 
10
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
- def add_stop (threshold: 0.0, color: '#e256d1')
14
+ def add_stop(threshold: 0.0, color: '#e256d1')
15
15
  stop_doc = stops.items_class.new_doc
16
16
  stops.upsert!(stop_doc) do |stop|
17
17
  stop.threshold = threshold
@@ -0,0 +1,13 @@
1
+ module Ecoportal
2
+ module API
3
+ class V2
4
+ class Page
5
+ class Component
6
+ class GeoCoordinates < Common::Content::DoubleModel
7
+ passthrough :lat, :lon
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -4,10 +4,13 @@ module Ecoportal
4
4
  class Page
5
5
  class Component
6
6
  class GeoField < Page::Component
7
- passthrough :address, :coordinates
7
+ passthrough :address
8
+ embeds_one :coordinates, klass: "Ecoportal::API::V2::Page::Component::GeoCoordinates"
8
9
  end
9
10
  end
10
11
  end
11
12
  end
12
13
  end
13
14
  end
15
+
16
+ require 'ecoportal/api/v2/page/component/geo_coordinates'
@@ -13,11 +13,67 @@ module Ecoportal
13
13
  end
14
14
  end
15
15
 
16
- passthrough :layout, :strech, :no_popup, :hide_options
16
+ passthrough :layout
17
+ passboolean :strech, :no_popup, :hide_options
17
18
  embeds_many :images, klass: "Ecoportal::API::V2::Page::Image", order_key: :weight
19
+
20
+ # Quick config helper
21
+ # @param conf [Symbol, Array<Symbol>]
22
+ # - `:strech` to make the image fit the full size of the image field
23
+ # - `:popup` to set to enable disable poupup on `click`
24
+ # - `:layout_button` to offer layout options to user
25
+ # - `:layout` with the following available values
26
+ # - `:three_crop` to specify _3 across_ by cutting the image to equalize size
27
+ # - `:three` to specify _3 across_
28
+ # - `:two` to specify _2 across_
29
+ # - `:one` to specify _Full width (1 Across)_
30
+ def configure(*conf)
31
+ conf.each_with_object([]) do |cnf, unused|
32
+ case cnf
33
+ when :strech
34
+ self.strech = true
35
+ when :popup
36
+ self.no_popup = false
37
+ when :layout_button
38
+ self.hide_options = false
39
+ when Hash
40
+ supported = [:layout_button, :layout]
41
+ unless (rest = hash_except(cnf.dup, *supported)).empty?
42
+ unused.push(rest)
43
+ end
44
+
45
+ if cnf.key?(:layout_button) then self.hide_options = !cnf[:layout_button] end
46
+ if cnf.key?(:layout) then configure_layour cnf[:layout] end
47
+ else
48
+ unused.push(cnf)
49
+ end
50
+ end.yield_self do |unused|
51
+ super(*unused)
52
+ end
53
+ end
54
+
55
+ private
56
+
57
+ def configure_layout(value)
58
+ case value
59
+ when :three
60
+ self.layout = "third"
61
+ when :two
62
+ self.layout = "half"
63
+ when :one
64
+ self.layout = "fill"
65
+ when :three_crop
66
+ self.layout = "third_crop"
67
+ else
68
+ # Unsupported
69
+ end
70
+ end
71
+
18
72
  end
19
73
  end
20
74
  end
21
75
  end
22
76
  end
23
77
  end
78
+
79
+ require 'ecoportal/api/v2/page/component/image'
@@ -4,17 +4,115 @@ module Ecoportal
4
4
  class Page
5
5
  class Component
6
6
  class PeopleField < Page::Component
7
- passthrough :is_me_button, :attach_mode
7
+ passboolean :is_me_button
8
+ passthrough :attach_mode
8
9
  passthrough :person_schema_id
9
10
  pass_reader :viewable_fields
10
- passthrough :singular, :requires_number
11
+
12
+ passboolean :singular
13
+ passthrough :requires_number
14
+
11
15
  passarray :people_ids
12
16
  pass_reader :cached_people
13
- passthrough :attached_people_permissions_enabled, :apply_attached_people_permissions_to
14
- passthrough :attached_people_permissions_editable, :attached_people_permissions_flags
15
17
 
16
- def add(id)
17
- people_ids << id
18
+ passboolean :attached_people_permissions_enabled, :attached_people_permissions_editable
19
+ passthrough :apply_attached_people_permissions_to
20
+
21
+ embeds_one :attached_people_permissions_flags, klass: "Ecoportal::API::V2::Page::PermissionFlags"
22
+
23
+ # Attaches people
24
+ def add(*ids)
25
+ people_ids << ids
26
+ end
27
+
28
+ # Deletes people
29
+ def delete(*ids)
30
+ people_ids.reject! {|id| ids.include?(id)}
31
+ end
32
+
33
+ # Quick config helper
34
+ # @param conf [Symbol, Array<Symbol>]
35
+ # - `:snapshot` to set mode to `snapshot`
36
+ # - `:live` to set mode to `live`
37
+ # - `:me_button` to display `ME` button
38
+ # - `:permits` to define the permissions
39
+ # - `:all` for _entire page/all stages_
40
+ # - `:stages` for _all stages containing this field_
41
+ # - `:page` for _page only_
42
+ # - `:stage` for _only the stage containing this field when attached_
43
+ # - `:restructure`
44
+ # - `:configure`
45
+ # - `:can_permission`
46
+ # - `:create_actions`
47
+ # - `:admin_actions`
48
+ # - `:subscribed`
49
+ # - `:subscribed_to_tasks`
50
+ # - `requires: number` to fine the number of required people to be attached
51
+ def configure(*conf)
52
+ conf.each_with_object([]) do |cnf, unused|
53
+ case cnf
54
+ when :snapshot
55
+ self.attach_mode = "snapshot"
56
+ when :live
57
+ self.attach_mode = "live"
58
+ when :me_button
59
+ self.is_me_button = true
60
+ when :singular
61
+ self.singular = true
62
+ when Hash
63
+ supported = [:singular, :permits, :requires]
64
+ unless (rest = hash_except(cnf.dup, *supported)).empty?
65
+ unused.push(rest)
66
+ end
67
+
68
+ if cnf.key?(:singular) then self.singular = !!cnf[:singular] end
69
+ if cnf.key?(:permits)
70
+ if permits = cnf[:permits]
71
+ self.attached_people_permissions_enabled = true
72
+ configure_permits(*[permits].flatten.compact)
73
+ else
74
+ self.attached_people_permissions_enabled = false
75
+ end
76
+ end
77
+ if cnf.key?(:requires)
78
+ self.singular = false
79
+ if requires = cnf[:requires]
80
+ self.required = true
81
+ self.requires_number = requires
82
+ else
83
+ self.required = false
84
+ self.requires_number = nil
85
+ end
86
+ end
87
+ else
88
+ unused.push(cnf)
89
+ end
90
+ end.yield_self do |unused|
91
+ super(*unused)
92
+ end
93
+ end
94
+
95
+ private
96
+
97
+ def configure_permits(*conf)
98
+ conf.each_with_object([]) do |cnf, flags|
99
+ case cnf
100
+ when :all
101
+ self.apply_attached_people_permissions_to = "page"
102
+ when :stages
103
+ self.apply_attached_people_permissions_to = "all_stages"
104
+ when :page
105
+ self.apply_attached_people_permissions_to = "page_only"
106
+ when :stage
107
+ self.apply_attached_people_permissions_to = "current_stage"
108
+ when :can_edit
109
+ self.attached_people_permissions_editable = true
110
+ else
111
+ flags.push(cnf)
112
+ end
113
+ end.yield_self do |flags|
114
+ self.attached_people_permissions_flags.configure *flags
115
+ end
18
116
  end
19
117
 
20
118
  end
@@ -5,8 +5,40 @@ module Ecoportal
5
5
  class Component
6
6
  class PlainTextField < Page::Component
7
7
  passthrough :value
8
- passthrough :multiline, :max_length
9
- pass_reader :exact_index
8
+ passboolean :multiline
9
+ passthrough :max_length
10
+ passboolean :exact_index
11
+
12
+ # Quick config helper
13
+ # @param conf [Symbol, Array<Symbol>]
14
+ # - `:multiline` multi line mode
15
+ # - `:singleline` signle line mode
16
+ # - `:exact_index` to make the `value` indexed as a **whole** (as opposite to its parts or n-grams)
17
+ # - `:max_length` specify the maximum length of the `value`
18
+ def configure(*conf)
19
+ conf.each_with_object([]) do |cnf, unused|
20
+ case cnf
21
+ when :multiline
22
+ self.multiline = true
23
+ when :singleline
24
+ self.multiline = false
25
+ when :exact_index
26
+ self.exact_index = true
27
+ when Hash
28
+ supported = [:multiline, :max_length]
29
+ unless (rest = hash_except(cnf.dup, *supported)).empty?
30
+ unused.push(rest)
31
+ end
32
+ if cnf.key?(:multiline) then self.multiline = !!cnf[:multiline] end
33
+ if cnf.key?(:max_length) then self.max_length = cnf[:max_length] end
34
+ else
35
+ unused.push(cnf)
36
+ end
37
+ end.yield_self do |unused|
38
+ super(*unused)
39
+ end
40
+ end
41
+
10
42
  end
11
43
  end
12
44
  end
@@ -5,9 +5,38 @@ module Ecoportal
5
5
  class Component
6
6
  class ReferenceField < Page::Component
7
7
  passthrough :register_id
8
- passthrough :hide_create, :hide_attach
9
- passthrough :hide_metadata, :hide_dashboards
10
- passthrough :display_fields, :display_fields_in_lookup
8
+ passboolean :hide_create, :hide_attach
9
+ passboolean :hide_metadata, :hide_dashboards
10
+ passboolean :display_fields, :display_fields_in_lookup
11
+
12
+ # Quick config helper
13
+ # @param conf [Symbol, Array<Symbol>]
14
+ # - `:show_fields` specify if the public register fields should be shown (requires `register_id`)
15
+ # - `:create` specify if the `NEW` button should appear
16
+ # - `:attach` specify if the `ATTACH` button should appear
17
+ # - `:metadata` specify if `metadata` should be shown (i.e. status)
18
+ def configure(*conf)
19
+ conf.each_with_object([]) do |cnf, unused|
20
+ case cnf
21
+ when :show_fields
22
+ self.display_fields = true
23
+ self.display_fields_in_lookup = true
24
+ when Hash
25
+ supported = [:create, :attach, :metadata]
26
+ unless (rest = hash_except(cnf.dup, *supported)).empty?
27
+ unused.push(rest)
28
+ end
29
+ if cnf.key?(:create) then self.hide_create = !cnf[:create] end
30
+ if cnf.key?(:attach) then self.hide_attach = !cnf[:attach] end
31
+ if cnf.key?(:metadata) then self.hide_metadata = !cnf[:metadata] end
32
+ else
33
+ unused.push(cnf)
34
+ end
35
+ end.yield_self do |unused|
36
+ super(*unused)
37
+ end
38
+ end
39
+
11
40
  end
12
41
  end
13
42
  end