ecoportal-api-v2 0.8.7 → 0.8.11

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 (56) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +82 -1
  3. data/lib/ecoportal/api/common/content/array_model.rb +8 -6
  4. data/lib/ecoportal/api/common/content/collection_model.rb +45 -20
  5. data/lib/ecoportal/api/common/content/double_model.rb +94 -5
  6. data/lib/ecoportal/api/common/content/hash_diff_patch.rb +44 -22
  7. data/lib/ecoportal/api/common/content/model_helpers.rb +36 -0
  8. data/lib/ecoportal/api/common/content.rb +1 -0
  9. data/lib/ecoportal/api/v2/page/component/action.rb +17 -8
  10. data/lib/ecoportal/api/v2/page/component/action_field.rb +37 -2
  11. data/lib/ecoportal/api/v2/page/component/chart_field/benchmark.rb +30 -0
  12. data/lib/ecoportal/api/v2/page/component/chart_field/config.rb +23 -0
  13. data/lib/ecoportal/api/v2/page/component/chart_field/frequency.rb +3 -4
  14. data/lib/ecoportal/api/v2/page/component/chart_field/heatmap.rb +1 -3
  15. data/lib/ecoportal/api/v2/page/component/chart_field/indicator.rb +4 -5
  16. data/lib/ecoportal/api/v2/page/component/chart_field/multiseries.rb +3 -5
  17. data/lib/ecoportal/api/v2/page/component/chart_field/sankey.rb +1 -3
  18. data/lib/ecoportal/api/v2/page/component/chart_field/serie.rb +3 -4
  19. data/lib/ecoportal/api/v2/page/component/chart_field/series_config.rb +5 -7
  20. data/lib/ecoportal/api/v2/page/component/chart_field.rb +43 -5
  21. data/lib/ecoportal/api/v2/page/component/chart_fr_field.rb +7 -5
  22. data/lib/ecoportal/api/v2/page/component/checklist_field.rb +1 -1
  23. data/lib/ecoportal/api/v2/page/component/checklist_item.rb +7 -5
  24. data/lib/ecoportal/api/v2/page/component/date_field.rb +71 -4
  25. data/lib/ecoportal/api/v2/page/component/file.rb +14 -3
  26. data/lib/ecoportal/api/v2/page/component/files_field.rb +37 -1
  27. data/lib/ecoportal/api/v2/page/component/gauge_field.rb +2 -2
  28. data/lib/ecoportal/api/v2/page/component/gauge_stop.rb +5 -5
  29. data/lib/ecoportal/api/v2/page/component/geo_coordinates.rb +13 -0
  30. data/lib/ecoportal/api/v2/page/component/geo_field.rb +4 -1
  31. data/lib/ecoportal/api/v2/page/component/image.rb +2 -1
  32. data/lib/ecoportal/api/v2/page/component/images_field.rb +57 -1
  33. data/lib/ecoportal/api/v2/page/component/number_field.rb +1 -0
  34. data/lib/ecoportal/api/v2/page/component/people_field.rb +115 -5
  35. data/lib/ecoportal/api/v2/page/component/people_viewable_field.rb +14 -0
  36. data/lib/ecoportal/api/v2/page/component/plain_text_field.rb +34 -2
  37. data/lib/ecoportal/api/v2/page/component/reference_field.rb +32 -3
  38. data/lib/ecoportal/api/v2/page/component/selection_field.rb +65 -7
  39. data/lib/ecoportal/api/v2/page/component/selection_option.rb +16 -5
  40. data/lib/ecoportal/api/v2/page/component/signature_field.rb +3 -2
  41. data/lib/ecoportal/api/v2/page/component/tag_field.rb +31 -1
  42. data/lib/ecoportal/api/v2/page/component.rb +44 -10
  43. data/lib/ecoportal/api/v2/page/components.rb +8 -3
  44. data/lib/ecoportal/api/v2/page/permission_flags.rb +67 -0
  45. data/lib/ecoportal/api/v2/page/permit.rb +15 -0
  46. data/lib/ecoportal/api/v2/page/section.rb +70 -9
  47. data/lib/ecoportal/api/v2/page/sections.rb +64 -6
  48. data/lib/ecoportal/api/v2/page/stage.rb +12 -4
  49. data/lib/ecoportal/api/v2/page/stages.rb +7 -7
  50. data/lib/ecoportal/api/v2/page.rb +19 -2
  51. data/lib/ecoportal/api/v2/pages/page_stage.rb +9 -3
  52. data/lib/ecoportal/api/v2/pages.rb +6 -2
  53. data/lib/ecoportal/api/v2/registers/search_results.rb +13 -0
  54. data/lib/ecoportal/api/v2/registers.rb +13 -0
  55. data/lib/ecoportal/api/v2_version.rb +1 -1
  56. metadata +10 -2
@@ -7,16 +7,18 @@ module Ecoportal
7
7
  passthrough :register_id, :date_input
8
8
  passthrough :filter
9
9
 
10
- passthrough :facet_by_tags, :facet_by_select
11
- passthrough :select_input, :select_mapping
10
+ passboolean :facet_by_tag, :facet_by_select
12
11
  passarray :facet_tags
12
+ passthrough :select_input, :select_mapping
13
13
 
14
- passthrough :relative, :relstart, :relbound
15
- passthrough :bounded, :ubound, :lbound
14
+ passboolean :relative, :bounded
15
+ passthrough :relstart, :relbound
16
+ passthrough :ubound, :lbound
16
17
 
17
18
  passthrough :display_mode, :display_type
18
19
  passarray :guidelines
19
- passthrough :cumulative, :cumulative_mode, :cumulative_start
20
+ passboolean :cumulative
21
+ passthrough :cumulative_mode, :cumulative_start
20
22
  passthrough :multiplier, :granularity
21
23
 
22
24
  passthrough :color
@@ -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)
@@ -8,15 +8,17 @@ module Ecoportal
8
8
  class << self
9
9
  def new_doc
10
10
  {
11
- "id" => new_uuid,
12
- "weight" => 9999
11
+ "id" => new_uuid,
12
+ "weight" => 9999
13
13
  }
14
14
  end
15
15
  end
16
-
16
+
17
17
  passkey :id
18
- passthrough :patch_ver, :label
19
- passthrough :weight, :checked
18
+ passforced :patch_ver, default: 1
19
+ passthrough :label
20
+ passthrough :weight
21
+ passboolean :checked
20
22
  end
21
23
  end
22
24
  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
@@ -4,10 +4,21 @@ module Ecoportal
4
4
  class Page
5
5
  class Component
6
6
  class File < Common::Content::DoubleModel
7
+ class << self
8
+ def new_doc
9
+ {
10
+ "id" => new_uuid,
11
+ "position" => 9999
12
+ }
13
+ end
14
+ end
15
+
7
16
  passkey :id
8
- passthrough :patch_ver, :position
9
- passthrough :content_type, :file_size, :file_container_id
10
- passdate :file_update_at
17
+ passforced :patch_ver, default: 1
18
+ passthrough :position
19
+ passthrough :file_size, :content_type, :token, read_only: true
20
+ passthrough :file_container_id
21
+ passdate :file_update_at, read_only: true
11
22
  end
12
23
  end
13
24
  end
@@ -4,10 +4,46 @@ module Ecoportal
4
4
  class Page
5
5
  class Component
6
6
  class FilesField < Page::Component
7
- embeds_many :items, klass: "Ecoportal::API::V2::Page::File", order_key: :position
7
+ embeds_many :items, klass: "Ecoportal::API::V2::Page::Component::File", order_key: :position
8
+
9
+ def add_file(container_id, pos: NOT_USED, before: NOT_USED, after: NOT_USED)
10
+ file_doc = items.items_class.new_doc
11
+ items.upsert!(file_doc, pos: pos, before: before, after: after) do |file|
12
+ file.file_container_id = container_id
13
+ if prev = previous_file(file)
14
+ file.position = prev.position
15
+ end
16
+ yield(file) if block_given?
17
+ fix_file_positions!
18
+ end
19
+ end
20
+
21
+ def ordered_files
22
+ items.each_with_index.sort_by do |file, index|
23
+ (file.position >= 9999) ? [index, index] : [file.position, index]
24
+ end.map(&:first)
25
+ end
26
+
27
+ private
28
+
29
+ def fix_file_positions!
30
+ ordered_files.each_with_index do |file, index|
31
+ file.position = index
32
+ end
33
+ end
34
+
35
+ def previous_file(value)
36
+ fls = ordered_files
37
+ pos = fls.index(value) - 1
38
+ return if pos < 0
39
+ fls[pos]
40
+ end
41
+
8
42
  end
9
43
  end
10
44
  end
11
45
  end
12
46
  end
13
47
  end
48
+
49
+ require 'ecoportal/api/v2/page/component/file'
@@ -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
@@ -8,16 +8,16 @@ module Ecoportal
8
8
  class << self
9
9
  def new_doc
10
10
  {
11
- "id" => new_uuid,
12
- "threshold" => nil,
13
- "color" => nil
11
+ "id" => new_uuid,
12
+ "threshold" => nil,
13
+ "color" => nil
14
14
  }
15
15
  end
16
16
  end
17
17
 
18
18
  passkey :id
19
- passthrough :patch_ver, :threshold
20
- passthrough :color
19
+ passforced :patch_ver, default: 1
20
+ passthrough :threshold, :color
21
21
 
22
22
  # Assign the color to the stop.
23
23
  # @note These are the available colors:
@@ -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'
@@ -5,7 +5,8 @@ module Ecoportal
5
5
  class Component
6
6
  class Image < Common::Content::DoubleModel
7
7
  passkey :id
8
- passthrough :patch_ver, :weight
8
+ passforced :patch_ver, default: 1
9
+ passthrough :weight
9
10
  passthrough :height, :width, :caption
10
11
  passthrough :dimensions, :styles
11
12
  end
@@ -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,6 +4,7 @@ module Ecoportal
4
4
  class Page
5
5
  class Component
6
6
  class NumberField < Page::Component
7
+ passthrough :value
7
8
  end
8
9
  end
9
10
  end
@@ -4,22 +4,132 @@ 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
- pass_reader :viewable_fields
10
- passthrough :singular, :requires_number
10
+ embeds_many :viewable_fields, klass: "Ecoportal::API::V2::Page::Component::PeopleViewableField"
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
 
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
16
24
  def add(*ids)
17
25
  people_ids << ids
18
26
  end
19
27
 
28
+ # Deletes people
29
+ def delete(*ids)
30
+ people_ids.reject! {|id| ids.include?(id)}
31
+ end
32
+
33
+ # Adds a field to the `viewable_fields`
34
+ def add_viewable(field_id, pos: NOT_USED, before: NOT_USED, after: NOT_USED)
35
+ viewable_fields.upsert!({"id" => field_id}, pos: pos, before: before, after: after)
36
+ end
37
+
38
+ # Deletes a field from the `viewable_fields`
39
+ def delete_viewable(field_id)
40
+ viewable_fields.delete!(field_id)
41
+ end
42
+
43
+ # Quick config helper
44
+ # @param conf [Symbol, Array<Symbol>]
45
+ # - `:snapshot` to set mode to `snapshot`
46
+ # - `:live` to set mode to `live`
47
+ # - `:me_button` to display `ME` button
48
+ # - `:permits` to define the permissions
49
+ # - `:all` for _entire page/all stages_
50
+ # - `:stages` for _all stages containing this field_
51
+ # - `:page` for _page only_
52
+ # - `:stage` for _only the stage containing this field when attached_
53
+ # - `:restructure`
54
+ # - `:configure`
55
+ # - `:can_permission`
56
+ # - `:create_actions`
57
+ # - `:admin_actions`
58
+ # - `:subscribed`
59
+ # - `:subscribed_to_tasks`
60
+ # - `requires: number` to fine the number of required people to be attached
61
+ def configure(*conf)
62
+ conf.each_with_object([]) do |cnf, unused|
63
+ case cnf
64
+ when :snapshot
65
+ self.attach_mode = "snapshot"
66
+ when :live
67
+ self.attach_mode = "live"
68
+ when :me_button
69
+ self.is_me_button = true
70
+ when :singular
71
+ self.singular = true
72
+ when Hash
73
+ supported = [:singular, :permits, :requires]
74
+ unless (rest = hash_except(cnf.dup, *supported)).empty?
75
+ unused.push(rest)
76
+ end
77
+
78
+ if cnf.key?(:singular) then self.singular = !!cnf[:singular] end
79
+ if cnf.key?(:permits)
80
+ if permits = cnf[:permits]
81
+ self.attached_people_permissions_enabled = true
82
+ configure_permits(*[permits].flatten.compact)
83
+ else
84
+ self.attached_people_permissions_enabled = false
85
+ end
86
+ end
87
+ if cnf.key?(:requires)
88
+ self.singular = false
89
+ if requires = cnf[:requires]
90
+ self.required = true
91
+ self.requires_number = requires
92
+ else
93
+ self.required = false
94
+ self.requires_number = nil
95
+ end
96
+ end
97
+ else
98
+ unused.push(cnf)
99
+ end
100
+ end.yield_self do |unused|
101
+ super(*unused)
102
+ end
103
+ end
104
+
105
+ private
106
+
107
+ def configure_permits(*conf)
108
+ conf.each_with_object([]) do |cnf, flags|
109
+ case cnf
110
+ when :all
111
+ self.apply_attached_people_permissions_to = "page"
112
+ when :stages
113
+ self.apply_attached_people_permissions_to = "all_stages"
114
+ when :page
115
+ self.apply_attached_people_permissions_to = "page_only"
116
+ when :stage
117
+ self.apply_attached_people_permissions_to = "current_stage"
118
+ when :can_edit
119
+ self.attached_people_permissions_editable = true
120
+ else
121
+ flags.push(cnf)
122
+ end
123
+ end.yield_self do |flags|
124
+ self.attached_people_permissions_flags.configure *flags
125
+ end
126
+ end
127
+
20
128
  end
21
129
  end
22
130
  end
23
131
  end
24
132
  end
25
133
  end
134
+
135
+ require 'ecoportal/api/v2/page/component/people_viewable_field'