ecoportal-api-v2 0.8.7 → 0.8.11

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -60,6 +60,8 @@ module Ecoportal
60
60
  a == b
61
61
  end
62
62
 
63
+ # Compares `a` as charring changes of `b`
64
+ # @return [Hash] patch data object with only changes
63
65
  def patch_data(a, b = nil, delete: false)
64
66
  {}.tap do |data_hash|
65
67
  if delete
@@ -75,41 +77,59 @@ module Ecoportal
75
77
  data_hash[key] = patch_diff(a_value, b_value)
76
78
  data_hash.delete(key) if data_hash[key] == NO_CHANGES
77
79
  end
80
+ #if (data_hash.keys - ID_KEYS).empty?
78
81
  if (data_hash.keys - META_KEYS).empty?
79
82
  return NO_CHANGES
80
83
  else
81
- patch_ver = (b && b["patch_ver"]) || 1
82
- data_hash["patch_ver"] = patch_ver
84
+ #patch_ver = (b && b["patch_ver"]) || 1
85
+ #data_hash["patch_ver"] = patch_ver
86
+ if b && b.key?("patch_ver")
87
+ data_hash["patch_ver"] = b["patch_ver"]
88
+ elsif a && a.key?("patch_ver")
89
+ data_hash["patch_ver"] = a["patch_ver"]
90
+ end
83
91
  end
84
92
  end
85
93
  end
86
94
 
87
95
  def patch_delete(b)
88
- return NO_CHANGES unless b.is_a?(Hash) && id = get_id(b, exception: false)
89
- {
90
- "id" => id,
91
- "operation" => "deleted",
92
- "data" => patch_data(b, delete: true)
93
- }
96
+ return NO_CHANGES unless b.is_a?(Hash)
97
+ if id = get_id(b, exception: false)
98
+ {
99
+ "id" => id,
100
+ "operation" => "deleted",
101
+ "data" => patch_data(b, delete: true)
102
+ }
103
+ else
104
+ nil
105
+ end
94
106
  end
95
107
 
96
108
  def patch_new(a)
97
- return NO_CHANGES unless a.is_a?(Hash) && id = get_id(a, exception: false)
98
- {
99
- "id" => id,
100
- "operation" => "new",
101
- "data" => patch_data(a)
102
- }
109
+ return NO_CHANGES unless a.is_a?(Hash)
110
+ if id = get_id(a, exception: false)
111
+ {
112
+ "id" => id,
113
+ "operation" => "new",
114
+ "data" => patch_data(a)
115
+ }
116
+ else
117
+ a
118
+ end
103
119
  end
104
120
 
105
121
  def patch_update(a, b)
106
- return NO_CHANGES unless a.is_a?(Hash) && id = get_id(a, exception: false)
107
- {
108
- "id" => id,
109
- "operation" => "changed",
110
- "data" => patch_data(a, b)
111
- }.tap do |update_hash|
112
- return nil unless update_hash["data"] != NO_CHANGES
122
+ return NO_CHANGES unless a.is_a?(Hash)
123
+ if id = get_id(a, exception: false)
124
+ {
125
+ "id" => id,
126
+ "operation" => "changed",
127
+ "data" => patch_data(a, b)
128
+ }.tap do |update_hash|
129
+ return nil unless update_hash["data"] != NO_CHANGES
130
+ end
131
+ else
132
+ a
113
133
  end
114
134
  end
115
135
 
@@ -160,7 +180,9 @@ module Ecoportal
160
180
  arr.any? {|a| nested_array?(a)}
161
181
  when arr.length == 1
162
182
  arr = arr.first
163
- arr.any? {|item| item.is_a?(Hash)}
183
+ arr.any? do |item|
184
+ item.is_a?(Hash) && item.has_key?("patch_ver")
185
+ end
164
186
  else
165
187
  false
166
188
  end
@@ -0,0 +1,36 @@
1
+ module Ecoportal
2
+ module API
3
+ module Common
4
+ module Content
5
+ module ModelHelpers
6
+
7
+ private
8
+
9
+ # Offers multiple ways to compare two strings
10
+ def same_string?(value1, value2, exact: false)
11
+ case
12
+ when value1.is_a?(String) && value2.is_a?(String)
13
+ if exact
14
+ value1 == value2
15
+ else
16
+ value1.to_s.strip.downcase == value2.to_s.strip.downcase
17
+ end
18
+ when value1.is_a?(Regexp) && value2.is_a?(String)
19
+ value2 =~ value1
20
+ when value1.is_a?(String) && value2.is_a?(Regexp)
21
+ value1 =~ value2
22
+ else
23
+ value1 == value2
24
+ end
25
+ end
26
+
27
+ def hash_except(hash, *keys)
28
+ keys.each {|key| hash.delete(key)}
29
+ hash
30
+ end
31
+
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -9,6 +9,7 @@ end
9
9
 
10
10
  require 'ecoportal/api/common/content/class_helpers'
11
11
  require 'ecoportal/api/common/content/string_digest'
12
+ require 'ecoportal/api/common/content/model_helpers'
12
13
  require 'ecoportal/api/common/content/double_model'
13
14
  require 'ecoportal/api/common/content/array_model'
14
15
  require 'ecoportal/api/common/content/collection_model'
@@ -7,19 +7,28 @@ module Ecoportal
7
7
  class << self
8
8
  def new_doc
9
9
  {
10
- "id" => new_uuid,
11
- "weight" => 9999
10
+ "id" => new_uuid,
11
+ "weight" => 9999
12
12
  }
13
13
  end
14
14
  end
15
-
15
+
16
16
  passkey :id
17
- passthrough :patch_ver, :name
18
- passthrough :weight, :complete, :other_information
19
- passdate :due_date
20
- pass_reader :overdue
17
+ passforced :patch_ver, default: 1
18
+ passthrough :name
19
+ passthrough :weight, :other_information
20
+ passboolean :complete
21
+
21
22
  passdate :created_at, read_only: true #, :completed_at
22
- pass_reader :created_by, :assigned_person_member_id
23
+ passthrough :created_by, read_only: true
24
+ passthrough :assigned_person_member_id, :assigned_person_member
25
+
26
+ passdate :due_date, :reminder_date
27
+ passboolean :overdue, read_only: true
28
+
29
+ passthrough :duration_in_days, read_only: true
30
+ passarray :file_container_ids
31
+
23
32
  end
24
33
  end
25
34
  end
@@ -4,9 +4,9 @@ module Ecoportal
4
4
  class Page
5
5
  class Component
6
6
  class ActionField < Page::Component
7
- passthrough :create_actions
7
+ passboolean :create_actions
8
8
  passthrough :required_number_of_completed_actions
9
- passthrough :permits_and_rules_integration, :add_subscribed, :add_subscribed_to_tasks
9
+ passboolean :permits_and_rules_integration, :add_subscribed, :add_subscribed_to_tasks
10
10
 
11
11
  embeds_many :actions, klass: "Ecoportal::API::V2::Page::Component::Action", order_key: :weight
12
12
 
@@ -30,8 +30,43 @@ module Ecoportal
30
30
  end.map(&:first)
31
31
  end
32
32
 
33
+ # Quick config helper
34
+ # @param conf [Symbol, Array<Symbol>]
35
+ # - `:requires` required number of completed actions
36
+ # - `:all`
37
+ # - `#Number`
38
+ def configure(*conf)
39
+ self.create_actions = true
40
+ conf.each_with_object([]) do |cnf, unused|
41
+ case cnf
42
+ when Hash
43
+ supported = [:requires]
44
+ unless (rest = hash_except(cnf.dup, *supported)).empty?
45
+ unused.push(rest)
46
+ end
47
+ if cnf.key?(:requires) then configure_required(cnf[:requires]) end
48
+ else
49
+ unused.push(cnf)
50
+ end
51
+ end.yield_self do |unused|
52
+ super(*unused)
53
+ end
54
+ end
55
+
33
56
  private
34
57
 
58
+ def configure_required(req)
59
+ self.required = true
60
+ case req
61
+ when :all, NilClass
62
+ self.required_number_of_completed_actions = "all"
63
+ when Numeric
64
+ self.required_number_of_completed_actions = req
65
+ else
66
+ # Unsupported
67
+ end
68
+ end
69
+
35
70
  def fix_task_weights!
36
71
  ordered_tasks.each_with_index do |task, index|
37
72
  task.weight = index
@@ -0,0 +1,30 @@
1
+ module Ecoportal
2
+ module API
3
+ class V2
4
+ class Page
5
+ class Component
6
+ class ChartField
7
+ class Benchmark < ChartField::Config
8
+ passthrough :register_id, :source_type
9
+
10
+ passthrough :benchmark_field, :benchmark_label
11
+
12
+ passboolean :across
13
+ passthrough :across_field
14
+
15
+ passboolean :grouped
16
+ passthrough :group_field
17
+
18
+ passthrough :against_field, :against_label
19
+
20
+ passthrough :calculation_mode
21
+ passthrough :min, :max
22
+
23
+ passthrough :filters
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ 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 Config < Common::Content::DoubleModel
8
+
9
+ class << self
10
+ def new_doc
11
+ {"id" => new_uuid}
12
+ end
13
+ end
14
+
15
+ passkey :id
16
+ passforced :patch_ver, default: 1
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -4,9 +4,7 @@ module Ecoportal
4
4
  class Page
5
5
  class Component
6
6
  class ChartField
7
- class Frequency < Common::Content::DoubleModel
8
- passkey :id
9
- passthrough :patch_ver
7
+ class Frequency < ChartField::Config
10
8
  passthrough :register_id, :source_type
11
9
 
12
10
  passthrough :mode, :input
@@ -14,7 +12,8 @@ module Ecoportal
14
12
  passthrough :secondary
15
13
 
16
14
  passthrough :output, :bar_mode
17
- passthrough :series_size, :skip_zeroes
15
+ passthrough :series_size
16
+ passboolean :skip_zeroes
18
17
 
19
18
  passarray :filters, :people_filters, :task_filters, order_matters: false
20
19
 
@@ -4,9 +4,7 @@ module Ecoportal
4
4
  class Page
5
5
  class Component
6
6
  class ChartField
7
- class Heatmap < Common::Content::DoubleModel
8
- passkey :id
9
- passthrough :patch_ver
7
+ class Heatmap < ChartField::Config
10
8
  passthrough :register_id, :source_type
11
9
 
12
10
  passthrough :xinput, :xmode
@@ -4,15 +4,14 @@ module Ecoportal
4
4
  class Page
5
5
  class Component
6
6
  class ChartField
7
- class Indicator < Common::Content::DoubleModel
8
- passkey :id
9
- passthrough :patch_ver
7
+ class Indicator < ChartField::Config
10
8
  passthrough :register_id, :source_type
11
9
 
12
10
  passthrough :date_input, :secondary
13
- passthrough :duration, :math_mode, :currency
11
+ passthrough :duration, :math_mode
14
12
 
15
- passthrough :display_previous, :change_format, :invert_colors
13
+ passboolean :currency, :display_previous, :invert_colors
14
+ passthrough :change_format
16
15
 
17
16
  passarray :filters, :people_filters, :task_filters, order_matters: false
18
17
 
@@ -4,17 +4,15 @@ module Ecoportal
4
4
  class Page
5
5
  class Component
6
6
  class ChartField
7
- class Multiseries < Common::Content::DoubleModel
8
- passkey :id
9
- passthrough :patch_ver
7
+ class Multiseries < ChartField::Config
10
8
  passthrough :register_id, :source_type
11
9
 
12
10
  passthrough :xinput, :xlabel
13
11
  passthrough :interval, :calc_mode
14
12
 
15
13
  passthrough :yinput, :ylabel
16
- passthrough :facet_by_discrete, :discrete_facet
17
- passthrough :facet_by_tags
14
+ passboolean :facet_by_discrete, :facet_by_tags
15
+ passthrough :discrete_facet
18
16
  passarray :facet_tags
19
17
 
20
18
  passarray :filters, :people_filters, :task_filters, order_matters: false
@@ -4,9 +4,7 @@ module Ecoportal
4
4
  class Page
5
5
  class Component
6
6
  class ChartField
7
- class Sankey < Common::Content::DoubleModel
8
- passkey :id
9
- passthrough :patch_ver
7
+ class Sankey < ChartField::Config
10
8
  passthrough :register_id, :source_type
11
9
 
12
10
  passthrough :xinput, :xmode
@@ -4,15 +4,14 @@ module Ecoportal
4
4
  class Page
5
5
  class Component
6
6
  class ChartField
7
- class Serie < Common::Content::DoubleModel
8
- passkey :id
9
- passthrough :patch_ver
7
+ class Serie < ChartField::Config
10
8
  passthrough :register_id
11
9
 
12
10
  passthrough :input, :type
13
11
  passarray :y_axes
14
12
 
15
- passthrough :visual, :stacked
13
+ passthrough :visual
14
+ passboolean :stacked
16
15
 
17
16
  passarray :filters, :people_filters, :task_filters, order_matters: false
18
17
 
@@ -4,16 +4,14 @@ module Ecoportal
4
4
  class Page
5
5
  class Component
6
6
  class ChartField
7
- class SeriesConfig < Common::Content::DoubleModel
8
- passkey :id
9
- passthrough :patch_ver
10
-
7
+ class SeriesConfig < ChartField::Config
11
8
  passthrough :xlabel, :xtype
12
- passthrough :interval, :calc_mode, :comparative_year
13
9
  passthrough :ylabel
10
+ passthrough :interval, :calc_mode
11
+ passboolean :comparative_year
14
12
 
15
- passthrough :filled_up_with_zeros, :zero_y, :bounds_rigid
16
- passthrough :stack_all
13
+ passboolean :filled_up_with_zeros, :zero_y, :bounds_rigid
14
+ passboolean :stack_all
17
15
  end
18
16
  end
19
17
  end
@@ -5,10 +5,14 @@ module Ecoportal
5
5
  class Component
6
6
  class ChartField < Page::Component
7
7
  passthrough :mode
8
- passthrough :relative, :relstart, :relbound
9
- passthrough :bounded, :ubound, :lbound
8
+ passboolean :relative, :bounded
9
+ passthrough :relstart, :relbound
10
+ passthrough :ubound, :lbound
11
+
10
12
  passthrough :filter_date_input
11
- passthrough :user_id, :lock_chart_user
13
+
14
+ passthrough :user_id, :user_lookup
15
+ passboolean :lock_chart_user
12
16
 
13
17
  embeds_one :series_config, klass: "Ecoportal::API::V2::Page::Component::ChartField::SeriesConfig"
14
18
  embeds_one :frequency_config, klass: "Ecoportal::API::V2::Page::Component::ChartField::Frequency"
@@ -16,13 +20,22 @@ module Ecoportal
16
20
  embeds_one :sankey_config, klass: "Ecoportal::API::V2::Page::Component::ChartField::Sankey"
17
21
  embeds_one :indicator_config, klass: "Ecoportal::API::V2::Page::Component::ChartField::Indicator"
18
22
  embeds_one :faceted_series_config, klass: "Ecoportal::API::V2::Page::Component::ChartField::Multiseries"
23
+ embeds_one :benchmark_config, klass: "Ecoportal::API::V2::Page::Component::ChartField::Benchmark"
19
24
 
20
25
  embeds_many :series, klass: "Ecoportal::API::V2::Page::Component::ChartField::Serie"
21
26
 
22
- MODES = ["frequency", "series", "heatmap", "sankey", "indicator", "faceted_series"]
27
+ MODES = ["frequency", "series", "heatmap", "sankey", "indicator", "faceted_series", "benchmark"]
28
+
29
+ def mode=(value)
30
+ raise "Unsuported mode #{value}. Should be one of #{MODES}" unless MODES.include?(value)
31
+ config_doc(nil)
32
+ doc["mode"] = value
33
+ config_doc(config.class.new_doc)
34
+ self.mode
35
+ end
23
36
 
24
37
  def config
25
- case mode
38
+ case self.mode
26
39
  when "frequency"
27
40
  frequency_config
28
41
  when "series"
@@ -35,6 +48,29 @@ module Ecoportal
35
48
  indicator_config
36
49
  when "faceted_series"
37
50
  faceted_series_config
51
+ when "benchmark"
52
+ benchmark_config
53
+ end
54
+ end
55
+
56
+ private
57
+
58
+ def config_doc(value)
59
+ case self.mode
60
+ when "frequency"
61
+ doc["frequency_config"] = value
62
+ when "series"
63
+ doc["series_config"] = value
64
+ when "heatmap"
65
+ doc["heatmap_config"] = value
66
+ when "sankey"
67
+ doc["sankey_config"] = value
68
+ when "indicator"
69
+ doc["indicator_config"] = value
70
+ when "faceted_series"
71
+ doc["faceted_series_config"] = value
72
+ when "benchmark"
73
+ doc["benchmark_config"] = value
38
74
  end
39
75
  end
40
76
 
@@ -45,6 +81,7 @@ module Ecoportal
45
81
  end
46
82
  end
47
83
 
84
+ require 'ecoportal/api/v2/page/component/chart_field/config'
48
85
  require 'ecoportal/api/v2/page/component/chart_field/frequency'
49
86
  require 'ecoportal/api/v2/page/component/chart_field/series_config'
50
87
  require 'ecoportal/api/v2/page/component/chart_field/serie'
@@ -52,3 +89,4 @@ require 'ecoportal/api/v2/page/component/chart_field/heatmap'
52
89
  require 'ecoportal/api/v2/page/component/chart_field/sankey'
53
90
  require 'ecoportal/api/v2/page/component/chart_field/indicator'
54
91
  require 'ecoportal/api/v2/page/component/chart_field/multiseries'
92
+ require 'ecoportal/api/v2/page/component/chart_field/benchmark'