ecoportal-api-v2 0.8.8 → 0.8.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +85 -3
  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/doc_helpers.rb +2 -2
  6. data/lib/ecoportal/api/common/content/double_model.rb +94 -5
  7. data/lib/ecoportal/api/common/content/hash_diff_patch.rb +44 -22
  8. data/lib/ecoportal/api/common/content/model_helpers.rb +36 -0
  9. data/lib/ecoportal/api/common/content.rb +1 -0
  10. data/lib/ecoportal/api/v2/page/component/action.rb +17 -8
  11. data/lib/ecoportal/api/v2/page/component/action_field.rb +37 -2
  12. data/lib/ecoportal/api/v2/page/component/chart_field/benchmark.rb +9 -7
  13. data/lib/ecoportal/api/v2/page/component/chart_field/config.rb +23 -0
  14. data/lib/ecoportal/api/v2/page/component/chart_field/frequency.rb +3 -4
  15. data/lib/ecoportal/api/v2/page/component/chart_field/heatmap.rb +1 -3
  16. data/lib/ecoportal/api/v2/page/component/chart_field/indicator.rb +4 -5
  17. data/lib/ecoportal/api/v2/page/component/chart_field/multiseries.rb +3 -5
  18. data/lib/ecoportal/api/v2/page/component/chart_field/sankey.rb +1 -3
  19. data/lib/ecoportal/api/v2/page/component/chart_field/serie.rb +3 -4
  20. data/lib/ecoportal/api/v2/page/component/chart_field/series_config.rb +5 -7
  21. data/lib/ecoportal/api/v2/page/component/chart_field.rb +39 -5
  22. data/lib/ecoportal/api/v2/page/component/chart_fr_field.rb +7 -5
  23. data/lib/ecoportal/api/v2/page/component/checklist_field.rb +1 -1
  24. data/lib/ecoportal/api/v2/page/component/checklist_item.rb +7 -5
  25. data/lib/ecoportal/api/v2/page/component/date_field.rb +71 -4
  26. data/lib/ecoportal/api/v2/page/component/file.rb +14 -3
  27. data/lib/ecoportal/api/v2/page/component/files_field.rb +37 -1
  28. data/lib/ecoportal/api/v2/page/component/gauge_field.rb +2 -2
  29. data/lib/ecoportal/api/v2/page/component/gauge_stop.rb +5 -5
  30. data/lib/ecoportal/api/v2/page/component/geo_coordinates.rb +13 -0
  31. data/lib/ecoportal/api/v2/page/component/geo_field.rb +4 -1
  32. data/lib/ecoportal/api/v2/page/component/image.rb +2 -1
  33. data/lib/ecoportal/api/v2/page/component/images_field.rb +57 -1
  34. data/lib/ecoportal/api/v2/page/component/number_field.rb +1 -0
  35. data/lib/ecoportal/api/v2/page/component/people_field.rb +115 -5
  36. data/lib/ecoportal/api/v2/page/component/people_viewable_field.rb +14 -0
  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 +59 -3
  40. data/lib/ecoportal/api/v2/page/component/selection_option.rb +6 -4
  41. data/lib/ecoportal/api/v2/page/component/signature_field.rb +3 -2
  42. data/lib/ecoportal/api/v2/page/component/tag_field.rb +31 -1
  43. data/lib/ecoportal/api/v2/page/component.rb +44 -10
  44. data/lib/ecoportal/api/v2/page/components.rb +8 -3
  45. data/lib/ecoportal/api/v2/page/permission_flags.rb +67 -0
  46. data/lib/ecoportal/api/v2/page/permit.rb +2 -1
  47. data/lib/ecoportal/api/v2/page/section.rb +70 -9
  48. data/lib/ecoportal/api/v2/page/sections.rb +64 -6
  49. data/lib/ecoportal/api/v2/page/stage.rb +11 -7
  50. data/lib/ecoportal/api/v2/page/stages.rb +2 -2
  51. data/lib/ecoportal/api/v2/page.rb +18 -2
  52. data/lib/ecoportal/api/v2/pages/page_stage.rb +13 -1
  53. data/lib/ecoportal/api/v2/pages.rb +3 -0
  54. data/lib/ecoportal/api/v2/registers/search_results.rb +13 -0
  55. data/lib/ecoportal/api/v2/registers.rb +15 -2
  56. data/lib/ecoportal/api/v2_version.rb +1 -1
  57. metadata +8 -2
@@ -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,8 +4,8 @@ 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
@@ -44,7 +44,7 @@ module Ecoportal
44
44
  end
45
45
  end
46
46
 
47
- 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)
48
48
  opt_doc = options.items_class.new_doc
49
49
  options.upsert!(opt_doc, pos: pos, before: before, after: after) do |option|
50
50
  option.name = name
@@ -63,8 +63,64 @@ module Ecoportal
63
63
  end.map(&:first)
64
64
  end
65
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
+
66
116
  private
67
117
 
118
+ def configure_options(opts)
119
+ opts.each do |val, nm|
120
+ add_option(value: val, name: nm)
121
+ end
122
+ end
123
+
68
124
  def fix_option_weights!
69
125
  ordered_options.each_with_index do |option, index|
70
126
  option.weight = index
@@ -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, :name, :value
19
- passthrough :weight, :selected
18
+ passforced :patch_ver, default: 1
19
+ passthrough :name, :value
20
+ passthrough :weight
21
+ passboolean :selected
20
22
 
21
23
  def numeric!
22
24
  self.value = block_given?? yield(value) : value.to_i
@@ -13,8 +13,9 @@ module Ecoportal
13
13
  end
14
14
  end
15
15
 
16
- passthrough :signed_by_id, :signed_by_name, :signature_url
17
- passdate :signature_updated_at
16
+ passthrough :signed_by_id, :signed_by_name, read_only: true
17
+ passthrough :signature_url, read_only: true
18
+ passdate :signature_updated_at, read_only: true
18
19
  passthrough :signature_content, :color
19
20
 
20
21
  end
@@ -4,8 +4,38 @@ module Ecoportal
4
4
  class Page
5
5
  class Component
6
6
  class TagField < Page::Component
7
- passthrough :single_select, :use_defaults
7
+ passboolean :single_select, :use_defaults
8
8
  passthrough :tag_tree_id, :button_text
9
+
10
+ # Quick config helper
11
+ # @param conf [Symbol, Array<Symbol>]
12
+ # - `:multiple` to allow multiple selection
13
+ # - `:single` to set to singular selection
14
+ # - `:default_tag` to prepopulate using users's `default_tag`
15
+ # - `:button_text` to define the button description
16
+ def configure(*conf)
17
+ conf.each_with_object([]) do |cnf, unused|
18
+ case cnf
19
+ when :single
20
+ self.single_select = true
21
+ when :multiple
22
+ self.single_select = false
23
+ when :default_tag
24
+ self.use_defaults = true
25
+ when Hash
26
+ supported = [:button_text]
27
+ unless (rest = hash_except(cnf.dup, *supported)).empty?
28
+ unused.push(rest)
29
+ end
30
+ if cnf.key?(:button_text) then self.button_text = cnf[:button_text] end
31
+ else
32
+ unused.push(cnf)
33
+ end
34
+ end.yield_self do |unused|
35
+ super(*unused)
36
+ end
37
+ end
38
+
9
39
  end
10
40
  end
11
41
  end
@@ -26,13 +26,16 @@ module Ecoportal
26
26
 
27
27
  class << self
28
28
  def new_doc(type: nil)
29
- if type
30
- type_doc = {"type" => type}
31
- base_doc = get_class(type_doc)&.new_doc || {}
32
- base_doc.merge!(type_doc)
29
+ {
30
+ "id" => new_uuid
31
+ }.tap do |base_doc|
32
+ if type
33
+ base_doc.merge!({"type" => type})
34
+ if klass = get_class(base_doc)
35
+ base_doc.merge!(klass.new_doc || {})
36
+ end
37
+ end
33
38
  end
34
- return base_doc if base_doc&.key?("id")
35
- (base_doc || {}).merge("id" => new_uuid)
36
39
  end
37
40
 
38
41
  def get_class(doc)
@@ -59,7 +62,6 @@ module Ecoportal
59
62
  when "checklist"
60
63
  checklist_field_class
61
64
  when "page_action","checklist_task"
62
- #doc["type"] = "checklist_task"
63
65
  action_field_class
64
66
  when "file"
65
67
  files_field_class
@@ -83,10 +85,12 @@ module Ecoportal
83
85
  end
84
86
 
85
87
  passkey :id
86
- passthrough :patch_ver, :undeletable
88
+ passforced :patch_ver, default: 1
89
+ passboolean :undeletable
87
90
  passthrough :type, :label, :tooltip, :global_binding
88
- passthrough :hidden, :accent, :deindex, :required
89
- passthrough :hide_view, :hidden_on_reports, :hidden_on_mobile
91
+ passboolean :hidden, :deindex, :required
92
+ passthrough :accent
93
+ passboolean :hide_view, :hidden_on_reports, :hidden_on_mobile
90
94
  passarray :refs
91
95
 
92
96
  def ref_backend
@@ -107,6 +111,36 @@ module Ecoportal
107
111
  self.class.indexable_label(label)
108
112
  end
109
113
 
114
+ # Quick config helper
115
+ # @param conf [Symbol, Array<Symbol>]
116
+ # - `:required`
117
+ # - `:hide_view` to hide in view mode
118
+ # - `:hide_mobile` to hide in mobile app
119
+ # - `:hide_reports` to hide in reports
120
+ # - `:global` to define a global binding
121
+ def configure(*conf)
122
+ conf.each_with_object([]) do |cnf, unused|
123
+ case cnf
124
+ when :required
125
+ self.required = true
126
+ when :hide_view
127
+ self.hide_view = true
128
+ when :hide_mobile
129
+ self.hidden_on_mobile = true
130
+ when :hide_reports
131
+ self.hidden_on_reports = true
132
+ when Hash
133
+ if cnf.key?(:global)
134
+ self.global_binding = cnf[:global]
135
+ end
136
+ else
137
+ unused.push(cnf)
138
+ end
139
+ end.tap do |unused|
140
+ raise "Unsupported configuration options '#{unused}' for #{self.class}" unless unused.empty?
141
+ end
142
+ end
143
+
110
144
  end
111
145
  end
112
146
  end
@@ -13,6 +13,12 @@ module Ecoportal
13
13
 
14
14
  order_matters = true
15
15
 
16
+ def get_by_id(id)
17
+ self.find do |comp|
18
+ comp.id == id
19
+ end
20
+ end
21
+
16
22
  def get_by_type(type)
17
23
  self.select do |comp|
18
24
  comp.type.downcase == type.to_s.strip.downcase
@@ -21,10 +27,9 @@ module Ecoportal
21
27
 
22
28
  def get_by_name(name, type: nil)
23
29
  pool = type ? get_by_type(type) : self
24
-
25
30
  pool.select do |comp|
26
- comp.label.to_s.strip.downcase == name.to_s.strip.downcase
27
- end.first
31
+ same_string?(comp.label, name)
32
+ end
28
33
  end
29
34
 
30
35
  def add(label:, type:)
@@ -0,0 +1,67 @@
1
+ module Ecoportal
2
+ module API
3
+ class V2
4
+ class Page
5
+ class PermissionFlags < Common::Content::DoubleModel
6
+ class << self
7
+ def new_doc
8
+ {
9
+ "can_restructure" => false,
10
+ "can_configure" => false,
11
+ "can_permission" => false,
12
+ "can_create_actions" => false,
13
+ "can_administrate_actions" => false,
14
+ "subscribed" => false,
15
+ "subscribed_to_tasks" => false
16
+ }
17
+ end
18
+ end
19
+
20
+ passboolean :can_restructure, :can_configure
21
+ passboolean :can_permission, :can_create_actions, :can_administrate_actions
22
+ passboolean :subscribed, :subscribed_to_tasks
23
+
24
+ def reset!
25
+ doc.merge!(self.class.new_doc)
26
+ end
27
+
28
+ # Quick config helper
29
+ # @param conf [Symbol, Array<Symbol>]
30
+ # - `:restructure`
31
+ # - `:configure`
32
+ # - `:can_permission`
33
+ # - `:create_actions`
34
+ # - `:admin_actions`
35
+ # - `:subscribed`
36
+ # - `:subscribed_to_tasks`
37
+ def configure(*conf)
38
+ conf.each_with_object([]) do |cnf, unused|
39
+ case cnf
40
+ when :restructure
41
+ self.can_restructure = true
42
+ when :configure
43
+ self.can_configure = true
44
+ when :can_permission
45
+ self.can_permission = true
46
+ when :create_actions
47
+ self.can_create_actions = true
48
+ when :admin_actions
49
+ self.can_administrate_actions = true
50
+ when :subscribed
51
+ self.subscribed = true
52
+ when :subscribed_to_tasks
53
+ self.subscribed_to_tasks = true
54
+ else
55
+ unused.push(cnf)
56
+ end
57
+ end.yield_self do |unused|
58
+ raise "Unknown configuaration options #{unused}" unless unused.empty?
59
+ end
60
+
61
+ end
62
+
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -4,9 +4,10 @@ module Ecoportal
4
4
  class Page
5
5
  class Permit < Common::Content::DoubleModel
6
6
  passkey :id
7
- passthrough :patch_ver
7
+ passforced :patch_ver, default: 1
8
8
  passthrough :user_id, :user_name
9
9
  passthrough :editable, :flags
10
+ embeds_one :flags, klass: "Ecoportal::API::V2::Page::PermissionFlags"
10
11
  end
11
12
  end
12
13
  end