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
@@ -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
@@ -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'