ecoportal-api-v2 0.8.5 → 0.8.9

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -34,6 +34,8 @@ module Ecoportal
34
34
  end
35
35
  end
36
36
 
37
+ require 'ecoportal/api/v2/page/permission_flags'
38
+ require 'ecoportal/api/v2/page/permit'
37
39
  require 'ecoportal/api/v2/page/component'
38
40
  require 'ecoportal/api/v2/page/components'
39
41
  require 'ecoportal/api/v2/page/section'
@@ -59,7 +59,6 @@ module Ecoportal
59
59
  when "checklist"
60
60
  checklist_field_class
61
61
  when "page_action","checklist_task"
62
- #doc["type"] = "checklist_task"
63
62
  action_field_class
64
63
  when "file"
65
64
  files_field_class
@@ -85,8 +84,9 @@ module Ecoportal
85
84
  passkey :id
86
85
  passthrough :patch_ver, :undeletable
87
86
  passthrough :type, :label, :tooltip, :global_binding
88
- passthrough :hidden, :accent, :deindex, :required
89
- passthrough :hide_view, :hidden_on_reports, :hidden_on_mobile
87
+ passboolean :hidden, :deindex, :required
88
+ passthrough :accent
89
+ passboolean :hide_view, :hidden_on_reports, :hidden_on_mobile
90
90
  passarray :refs
91
91
 
92
92
  def ref_backend
@@ -107,6 +107,36 @@ module Ecoportal
107
107
  self.class.indexable_label(label)
108
108
  end
109
109
 
110
+ # Quick config helper
111
+ # @param conf [Symbol, Array<Symbol>]
112
+ # - `:required`
113
+ # - `:hide_view` to hide in view mode
114
+ # - `:hide_mobile` to hide in mobile app
115
+ # - `:hide_reports` to hide in reports
116
+ # - `:global` to define a global binding
117
+ def configure(*conf)
118
+ conf.each_with_object([]) do |cnf, unused|
119
+ case cnf
120
+ when :required
121
+ self.required = true
122
+ when :hide_view
123
+ self.hide_view = true
124
+ when :hide_mobile
125
+ self.hidden_on_mobile = true
126
+ when :hide_reports
127
+ self.hidden_on_reports = true
128
+ when Hash
129
+ if cnf.key?(:global)
130
+ self.global_binding = cnf[:global]
131
+ end
132
+ else
133
+ unused.push(cnf)
134
+ end
135
+ end.tap do |unused|
136
+ raise "Unsupported configuration options '#{unused}' for #{self.class}" unless unused.empty?
137
+ end
138
+ end
139
+
110
140
  end
111
141
  end
112
142
  end
@@ -12,14 +12,22 @@ module Ecoportal
12
12
  }
13
13
  end
14
14
  end
15
-
15
+
16
16
  passkey :id
17
17
  passthrough :patch_ver, :name
18
- passthrough :weight, :complete, :other_information
19
- passdate :due_date
20
- pass_reader :overdue
18
+ passthrough :weight, :other_information
19
+ passboolean :complete
20
+
21
21
  passdate :created_at, read_only: true #, :completed_at
22
- pass_reader :created_by, :assigned_person_member_id
22
+ passthrough :created_by, read_only: true
23
+ passthrough :assigned_person_member_id, :assigned_person_member
24
+
25
+ passdate :due_date, :reminder_date
26
+ passboolean :overdue, read_only: true
27
+
28
+ passthrough :duration_in_days, read_only: true
29
+ passarray :file_container_ids
30
+
23
31
  end
24
32
  end
25
33
  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
@@ -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'
@@ -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
+ passthrough :patch_ver
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
@@ -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