ecoportal-api-v2 0.8.6 → 0.8.10

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 (59) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +73 -28
  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 +45 -20
  10. data/lib/ecoportal/api/common/content/double_model.rb +98 -9
  11. data/lib/ecoportal/api/common/content/hash_diff_patch.rb +44 -22
  12. data/lib/ecoportal/api/common/content/model_helpers.rb +36 -0
  13. data/lib/ecoportal/api/v2/page.rb +15 -2
  14. data/lib/ecoportal/api/v2/page/component.rb +44 -10
  15. data/lib/ecoportal/api/v2/page/component/action.rb +17 -8
  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 +7 -5
  30. data/lib/ecoportal/api/v2/page/component/date_field.rb +71 -4
  31. data/lib/ecoportal/api/v2/page/component/file.rb +14 -3
  32. data/lib/ecoportal/api/v2/page/component/files_field.rb +37 -1
  33. data/lib/ecoportal/api/v2/page/component/gauge_field.rb +2 -2
  34. data/lib/ecoportal/api/v2/page/component/gauge_stop.rb +5 -5
  35. data/lib/ecoportal/api/v2/page/component/geo_coordinates.rb +13 -0
  36. data/lib/ecoportal/api/v2/page/component/geo_field.rb +4 -1
  37. data/lib/ecoportal/api/v2/page/component/image.rb +2 -1
  38. data/lib/ecoportal/api/v2/page/component/images_field.rb +57 -1
  39. data/lib/ecoportal/api/v2/page/component/number_field.rb +1 -0
  40. data/lib/ecoportal/api/v2/page/component/people_field.rb +117 -7
  41. data/lib/ecoportal/api/v2/page/component/people_viewable_field.rb +14 -0
  42. data/lib/ecoportal/api/v2/page/component/plain_text_field.rb +34 -2
  43. data/lib/ecoportal/api/v2/page/component/reference_field.rb +32 -3
  44. data/lib/ecoportal/api/v2/page/component/selection_field.rb +65 -7
  45. data/lib/ecoportal/api/v2/page/component/selection_option.rb +16 -5
  46. data/lib/ecoportal/api/v2/page/component/signature_field.rb +3 -2
  47. data/lib/ecoportal/api/v2/page/component/tag_field.rb +31 -1
  48. data/lib/ecoportal/api/v2/page/components.rb +8 -3
  49. data/lib/ecoportal/api/v2/page/permission_flags.rb +67 -0
  50. data/lib/ecoportal/api/v2/page/permit.rb +15 -0
  51. data/lib/ecoportal/api/v2/page/section.rb +70 -9
  52. data/lib/ecoportal/api/v2/page/sections.rb +64 -6
  53. data/lib/ecoportal/api/v2/page/stage.rb +12 -4
  54. data/lib/ecoportal/api/v2/page/stages.rb +7 -7
  55. data/lib/ecoportal/api/v2/pages/page_stage.rb +3 -3
  56. data/lib/ecoportal/api/v2_version.rb +5 -0
  57. metadata +17 -10
  58. data/lib/ecoportal/api/common.rb +0 -18
  59. data/lib/ecoportal/api/v2/version.rb +0 -7
@@ -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,17 +4,125 @@ 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
 
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
+ # 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
18
126
  end
19
127
 
20
128
  end
@@ -23,3 +131,5 @@ module Ecoportal
23
131
  end
24
132
  end
25
133
  end
134
+
135
+ require 'ecoportal/api/v2/page/component/people_viewable_field'
@@ -0,0 +1,14 @@
1
+ module Ecoportal
2
+ module API
3
+ class V2
4
+ class Page
5
+ class Component
6
+ class PeopleViewableField < Common::Content::DoubleModel
7
+ passkey :id
8
+ passthrough :type, read_only: true
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
14
+ 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
@@ -4,18 +4,20 @@ module Ecoportal
4
4
  class Page
5
5
  class Component
6
6
  class SelectionField < Page::Component
7
- passthrough :multiple, :flat
8
- passthrough :other, :other_desc
7
+ passboolean :multiple, :flat, :other
8
+ passthrough :other_desc
9
9
  passthrough :data_type
10
10
 
11
11
  embeds_many :options, klass: "Ecoportal::API::V2::Page::Component::SelectionOption", order_key: :weight
12
12
 
13
- def numeric!
14
- data_type = "num"
13
+ def numeric!(&block)
14
+ ordered_options.each {|opt| opt.numeric!(&block)}
15
+ self.data_type = "num"
15
16
  end
16
17
 
17
- def text!
18
- data_type = "str"
18
+ def text!(&block)
19
+ ordered_options.each {|opt| opt.text!(&block)}
20
+ self.data_type = "str"
19
21
  end
20
22
 
21
23
  def select(value)
@@ -42,7 +44,7 @@ module Ecoportal
42
44
  end
43
45
  end
44
46
 
45
- def add_option(name:, value:, pos: NOT_USED, before: NOT_USED, after: NOT_USED)
47
+ def add_option(value:, name: nil, pos: NOT_USED, before: NOT_USED, after: NOT_USED)
46
48
  opt_doc = options.items_class.new_doc
47
49
  options.upsert!(opt_doc, pos: pos, before: before, after: after) do |option|
48
50
  option.name = name
@@ -61,8 +63,64 @@ module Ecoportal
61
63
  end.map(&:first)
62
64
  end
63
65
 
66
+ # Quick config helper
67
+ # @param conf [Symbol, Array<Symbol>]
68
+ # - `:flat` to display in flat mode
69
+ # - `:multiple` to allow multiple selection
70
+ # - `:single` to set to singular selection
71
+ # - `:other` to enable `other` button
72
+ # - `:options` to add options (`Hash<value, name>`)
73
+ # - `:type` to define the type
74
+ # - `:num`
75
+ # - `:str`
76
+ def configure(*conf)
77
+ conf.each_with_object([]) do |cnf, unused|
78
+ case cnf
79
+ when :flat
80
+ self.flat = true
81
+ when :multiple
82
+ self.multiple = true
83
+ when :single
84
+ self.multiple = false
85
+ when :other
86
+ self.other = true
87
+ when Hash
88
+ supported = [:flat, :options, :type]
89
+ unless (rest = hash_except(cnf.dup, *supported)).empty?
90
+ unused.push(rest)
91
+ end
92
+
93
+ if cnf.key?(:flat) then self.flat = cnf[:flat] end
94
+ if cnf.key?(:options)
95
+ if opts = cnf[:options]
96
+ configure_options opts
97
+ end
98
+ end
99
+ if cnf.key?(:type)
100
+ if cnf[:type] == :str
101
+ self.text!
102
+ elsif cnf[:type] == :num
103
+ self.numeric!
104
+ else
105
+ # Unknown type
106
+ end
107
+ end
108
+ else
109
+ unused.push(cnf)
110
+ end
111
+ end.yield_self do |unused|
112
+ super(*unused)
113
+ end
114
+ end
115
+
64
116
  private
65
117
 
118
+ def configure_options(opts)
119
+ opts.each do |val, nm|
120
+ add_option(value: val, name: nm)
121
+ end
122
+ end
123
+
66
124
  def fix_option_weights!
67
125
  ordered_options.each_with_index do |option, index|
68
126
  option.weight = index
@@ -4,19 +4,30 @@ module Ecoportal
4
4
  class Page
5
5
  class Component
6
6
  class SelectionOption < Common::Content::DoubleModel
7
-
7
+
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, :name, :value
19
- passthrough :weight, :selected
18
+ passforced :patch_ver, default: 1
19
+ passthrough :name, :value
20
+ passthrough :weight
21
+ passboolean :selected
22
+
23
+ def numeric!
24
+ self.value = block_given?? yield(value) : value.to_i
25
+ end
26
+
27
+ def text!
28
+ self.value = block_given?? yield(value) : value.to_s
29
+ end
30
+
20
31
  end
21
32
  end
22
33
  end