ecoportal-api-oozes 0.7.0 → 0.7.5

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 (55) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +103 -1
  3. data/README.md +2 -0
  4. data/ecoportal-api-oozes.gemspec +13 -6
  5. data/lib/ecoportal/api/common/content/class_helpers.rb +35 -0
  6. data/lib/ecoportal/api/common/content/collection_model.rb +25 -3
  7. data/lib/ecoportal/api/common/content/double_model.rb +27 -12
  8. data/lib/ecoportal/api/common/content/hash_diff_patch.rb +8 -2
  9. data/lib/ecoportal/api/common/content/wrapped_response.rb +1 -1
  10. data/lib/ecoportal/api/v2.rb +38 -3
  11. data/lib/ecoportal/api/v2/page.rb +3 -3
  12. data/lib/ecoportal/api/v2/page/component.rb +24 -7
  13. data/lib/ecoportal/api/v2/page/component/action.rb +14 -3
  14. data/lib/ecoportal/api/v2/page/component/action_field.rb +40 -2
  15. data/lib/ecoportal/api/v2/page/component/chart_field.rb +54 -0
  16. data/lib/ecoportal/api/v2/page/component/chart_field/frequency.rb +29 -0
  17. data/lib/ecoportal/api/v2/page/component/chart_field/heatmap.rb +27 -0
  18. data/lib/ecoportal/api/v2/page/component/chart_field/indicator.rb +26 -0
  19. data/lib/ecoportal/api/v2/page/component/chart_field/multiseries.rb +31 -0
  20. data/lib/ecoportal/api/v2/page/component/chart_field/sankey.rb +27 -0
  21. data/lib/ecoportal/api/v2/page/component/chart_field/serie.rb +26 -0
  22. data/lib/ecoportal/api/v2/page/component/chart_field/series_config.rb +23 -0
  23. data/lib/ecoportal/api/v2/page/component/chart_fr_field.rb +32 -0
  24. data/lib/ecoportal/api/v2/page/component/checklist_field.rb +35 -2
  25. data/lib/ecoportal/api/v2/page/component/checklist_item.rb +10 -0
  26. data/lib/ecoportal/api/v2/page/component/date_field.rb +21 -0
  27. data/lib/ecoportal/api/v2/page/component/files_field.rb +1 -2
  28. data/lib/ecoportal/api/v2/page/component/gauge_field.rb +24 -1
  29. data/lib/ecoportal/api/v2/page/component/gauge_stop.rb +88 -0
  30. data/lib/ecoportal/api/v2/page/component/images_field.rb +11 -2
  31. data/lib/ecoportal/api/v2/page/component/people_field.rb +8 -1
  32. data/lib/ecoportal/api/v2/page/component/plain_text_field.rb +2 -0
  33. data/lib/ecoportal/api/v2/page/component/reference_field.rb +4 -0
  34. data/lib/ecoportal/api/v2/page/component/selection_field.rb +4 -5
  35. data/lib/ecoportal/api/v2/page/component/selection_option.rb +1 -0
  36. data/lib/ecoportal/api/v2/page/component/signature_field.rb +12 -1
  37. data/lib/ecoportal/api/v2/page/component/tag_field.rb +2 -0
  38. data/lib/ecoportal/api/v2/page/components.rb +2 -2
  39. data/lib/ecoportal/api/v2/page/section.rb +1 -0
  40. data/lib/ecoportal/api/v2/page/sections.rb +1 -1
  41. data/lib/ecoportal/api/v2/page/stages.rb +6 -0
  42. data/lib/ecoportal/api/v2/pages.rb +17 -15
  43. data/lib/ecoportal/api/v2/pages/page_stage.rb +6 -1
  44. data/lib/ecoportal/api/v2/pages/stages.rb +4 -1
  45. data/lib/ecoportal/api/v2/people.rb +31 -0
  46. data/lib/ecoportal/api/v2/registers.rb +60 -6
  47. data/lib/ecoportal/api/v2/registers/page_result.rb +21 -0
  48. data/lib/ecoportal/api/v2/registers/register.rb +37 -0
  49. data/lib/ecoportal/api/v2/registers/stage_result.rb +14 -0
  50. data/lib/ecoportal/api/v2/registers/stages_result.rb +13 -0
  51. data/lib/ecoportal/api/v2/registers/template.rb +12 -0
  52. data/lib/ecoportal/api/v2/version.rb +1 -1
  53. metadata +70 -36
  54. data/lib/ecoportal/api/v2/register.rb +0 -36
  55. data/lib/ecoportal/api/v2/template.rb +0 -10
@@ -4,8 +4,41 @@ module Ecoportal
4
4
  class Page
5
5
  class Component
6
6
  class ChecklistField < Page::Component
7
- #class_resolver :checklist_item_class, "Ecoportal::API::V2::Page::Component::ChecklistItem"
8
- embeds_multiple :items, klass: "Ecoportal::API::V2::Page::Component::ChecklistItem", order_key: :weight
7
+ embeds_many :items, klass: "Ecoportal::API::V2::Page::Component::ChecklistItem", order_key: :weight
8
+
9
+ def add_item(label:, pos: NOT_USED, before: NOT_USED, after: NOT_USED)
10
+ itm_doc = items.stops.items_class.new_doc
11
+ items.upsert!(itm_doc, pos: pos, before: before, after: after) do |item|
12
+ item.label = label
13
+ if prev = previous_item(item)
14
+ item.weight = prev.weight
15
+ end
16
+ yield(item) if block_given?
17
+ fix_item_weights!
18
+ end
19
+ end
20
+
21
+ def ordered_items
22
+ items.each_with_index.sort_by do |item, index|
23
+ (item.weight >= 9999) ? [index, index] : [item.weight, index]
24
+ end.map(&:first)
25
+ end
26
+
27
+ private
28
+
29
+ def fix_item_weights!
30
+ ordered_items.each_with_index do |item, index|
31
+ item.weight = index
32
+ end
33
+ end
34
+
35
+ def previous_item(value)
36
+ itms = ordered_items
37
+ pos = itms.index(value) - 1
38
+ return if pos < 0
39
+ itms[pos]
40
+ end
41
+
9
42
  end
10
43
  end
11
44
  end
@@ -4,6 +4,16 @@ module Ecoportal
4
4
  class Page
5
5
  class Component
6
6
  class ChecklistItem < Common::Content::DoubleModel
7
+
8
+ class << self
9
+ def new_doc
10
+ {
11
+ "id" => new_uuid,
12
+ "weight" => 9999
13
+ }
14
+ end
15
+ end
16
+
7
17
  passkey :id
8
18
  passthrough :patch_ver, :label
9
19
  passthrough :weight, :checked
@@ -5,6 +5,27 @@ module Ecoportal
5
5
  class Component
6
6
  class DateField < Page::Component
7
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
11
+
12
+ ISO8601 = "%Y-%m-%dT%H:%M:00Z" # "%Y-%m-%dT%H:%M:00.00Z"
13
+
14
+ def value=(val)
15
+ doc["value"] = self.class.to_time(val).yield_self do |datetime|
16
+ datetime = datetime.utc.strftime(ISO8601) if datetime
17
+ datetime
18
+ end
19
+ end
20
+
21
+ def value
22
+ if val = doc["value"]
23
+ (Time.parse(val) rescue nil).yield_self do |datetime|
24
+ datetime.localtime if datetime
25
+ end
26
+ end
27
+ end
28
+
8
29
  end
9
30
  end
10
31
  end
@@ -4,8 +4,7 @@ module Ecoportal
4
4
  class Page
5
5
  class Component
6
6
  class FilesField < Page::Component
7
- #class_resolver :file_class, "Ecoportal::API::V2::Page::File"
8
- embeds_multiple :items, klass: "Ecoportal::API::V2::Page::File", order_key: :position
7
+ embeds_many :items, klass: "Ecoportal::API::V2::Page::File", order_key: :position
9
8
  end
10
9
  end
11
10
  end
@@ -4,10 +4,33 @@ module Ecoportal
4
4
  class Page
5
5
  class Component
6
6
  class GaugeField < Page::Component
7
- passthrough :value
7
+ passthrough :value, :max
8
+ passthrough :active_color
9
+
10
+ embeds_many :stops, klass: "Ecoportal::API::V2::Page::Component::GaugeStop", order_key: :threshold
11
+
12
+ # Adds a stop at `threshold` with `color`
13
+ # @return [Ecoportal::API::V2::Page::Component::GaugeStop]
14
+ def add_stop (threshold: 0.0, color: '#e256d1')
15
+ stop_doc = stops.items_class.new_doc
16
+ stops.upsert!(stop_doc) do |stop|
17
+ stop.threshold = threshold
18
+ stop.color = color
19
+ yield(stop) if block_given?
20
+ end
21
+ end
22
+
23
+ def ordered_stops
24
+ stops.each_with_index.sort_by do |stop, index|
25
+ (stop.threshold >= 9999) ? [index, index] : [stop.threshold, index]
26
+ end.map(&:first)
27
+ end
28
+
8
29
  end
9
30
  end
10
31
  end
11
32
  end
12
33
  end
13
34
  end
35
+
36
+ require 'ecoportal/api/v2/page/component/gauge_stop'
@@ -0,0 +1,88 @@
1
+ module Ecoportal
2
+ module API
3
+ class V2
4
+ class Page
5
+ class Component
6
+ class GaugeStop < Common::Content::DoubleModel
7
+
8
+ class << self
9
+ def new_doc
10
+ {
11
+ "id" => new_uuid,
12
+ "threshold" => nil,
13
+ "color" => nil
14
+ }
15
+ end
16
+ end
17
+
18
+ passkey :id
19
+ passthrough :patch_ver, :threshold
20
+ passthrough :color
21
+
22
+ # Assign the color to the stop.
23
+ # @note These are the available colors:
24
+ # - :blue, :blue_greyed, :blue_light
25
+ # - :turquoise, :jade, :green, :pistachio, :avocado
26
+ # - :yellow, :orange, :pumpkin, :red, :magenta, :fuchsia, :purple, :violet
27
+ # @param value [String, Symbol] you can use a `symbol` to specify a color
28
+ def color=(value)
29
+ value = to_color(value) if value.is_a?(Symbol)
30
+ doc["color"] = value
31
+ end
32
+
33
+ # @return [Symbol] to get the `color` sym code
34
+ def color_sym
35
+ color_maps.each do |k, v|
36
+ return k if color == v
37
+ end
38
+ :undefined
39
+ end
40
+
41
+ private
42
+
43
+ def to_color(value)
44
+ return nil unless valid_color?(value)
45
+ return value if value.is_a?(String)
46
+ color_maps[value]
47
+ end
48
+
49
+ def valid_color?(value)
50
+ return true if value.is_a?(String) && colors.any? {|c| c == value}
51
+ return true if value.is_a?(Symbol) && color_syms.any? {|s| s == value}
52
+ end
53
+
54
+ def color_syms
55
+ @color_syms ||= color_maps.keys
56
+ end
57
+
58
+ def colors
59
+ @colors ||= color_maps.values
60
+ end
61
+
62
+ def color_maps
63
+ @color_maps ||= [
64
+ [:blue, "#5656e2"],
65
+ [:blue_greyed, "#568be2"],
66
+ [:blue_light, "#56c0e2"],
67
+ [:turquoise, "#56e2cf"],
68
+ [:jade, "#56e29b"],
69
+ [:green, "#56e267"],
70
+ [:pistachio, "#79e256"],
71
+ [:avocado, "#aee256"],
72
+ [:yellow, "#e2e156"],
73
+ [:orange, "#e2ad56"],
74
+ [:pumpkin, "#e27956"],
75
+ [:red, "#e25667"],
76
+ [:magenta, "#e2569c"],
77
+ [:fuchsia, "#e256d1"],
78
+ [:purple, "#be56e2"],
79
+ [:violet, "#8a56e2"]
80
+ ].to_h
81
+ end
82
+
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
@@ -4,8 +4,17 @@ module Ecoportal
4
4
  class Page
5
5
  class Component
6
6
  class ImagesField < Page::Component
7
- #class_resolver :image_class, "Ecoportal::API::V2::Page::Image"
8
- embeds_multiple :images, klass: "Ecoportal::API::V2::Page::Image", order_key: :weight
7
+
8
+ class << self
9
+ def new_doc
10
+ {
11
+ "layout" => "third"
12
+ }
13
+ end
14
+ end
15
+
16
+ passthrough :layout, :strech, :no_popup, :hide_options
17
+ embeds_many :images, klass: "Ecoportal::API::V2::Page::Image", order_key: :weight
9
18
  end
10
19
  end
11
20
  end
@@ -4,7 +4,14 @@ module Ecoportal
4
4
  class Page
5
5
  class Component
6
6
  class PeopleField < Page::Component
7
- passarray :people_ids
7
+ passthrough :is_me_button, :attach_mode
8
+ passthrough :person_schema_id
9
+ pass_reader :viewable_fields
10
+ passthrough :singular, :requires_number
11
+ passarray :people_ids
12
+ 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
8
15
 
9
16
  def add(id)
10
17
  people_ids << id
@@ -5,6 +5,8 @@ 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
10
  end
9
11
  end
10
12
  end
@@ -4,6 +4,10 @@ module Ecoportal
4
4
  class Page
5
5
  class Component
6
6
  class ReferenceField < Page::Component
7
+ passthrough :register_id
8
+ passthrough :hide_create, :hide_attach
9
+ passthrough :hide_metadata, :hide_dashboards
10
+ passthrough :display_fields, :display_fields_in_lookup
7
11
  end
8
12
  end
9
13
  end
@@ -4,10 +4,10 @@ module Ecoportal
4
4
  class Page
5
5
  class Component
6
6
  class SelectionField < Page::Component
7
- passthrough :multiple, :other, :other_desc
7
+ passthrough :multiple, :flat
8
+ passthrough :other, :other_desc
8
9
 
9
- #class_resolver :selection_option_class, "Ecoportal::API::V2::Page::Component::SelectionOption"
10
- embeds_multiple :options, klass: "Ecoportal::API::V2::Page::Component::SelectionOption", order_key: :weight
10
+ embeds_many :options, klass: "Ecoportal::API::V2::Page::Component::SelectionOption", order_key: :weight
11
11
 
12
12
  def select(value)
13
13
  opt = options.find {|opt| opt.value == value}
@@ -33,9 +33,8 @@ module Ecoportal
33
33
  end
34
34
  end
35
35
 
36
- # a server bug prevents to add new options to an existing field
37
36
  def add_option(name:, value:, pos: NOT_USED, before: NOT_USED, after: NOT_USED)
38
- opt_doc = Ecoportal::API::V2::Page::Component::SelectionOption.new_doc
37
+ opt_doc = options.items_class.new_doc
39
38
  options.upsert!(opt_doc, pos: pos, before: before, after: after) do |option|
40
39
  option.name = name
41
40
  option.value = value
@@ -4,6 +4,7 @@ module Ecoportal
4
4
  class Page
5
5
  class Component
6
6
  class SelectionOption < Common::Content::DoubleModel
7
+
7
8
  class << self
8
9
  def new_doc
9
10
  {
@@ -4,8 +4,19 @@ module Ecoportal
4
4
  class Page
5
5
  class Component
6
6
  class SignatureField < Page::Component
7
- passthrough :signed_by_id, :signature_url
7
+
8
+ class << self
9
+ def new_doc
10
+ {
11
+ "color" => "#000000"
12
+ }
13
+ end
14
+ end
15
+
16
+ passthrough :signed_by_id, :signed_by_name, :signature_url
8
17
  passdate :signature_updated_at
18
+ passthrough :signature_content, :color
19
+
9
20
  end
10
21
  end
11
22
  end
@@ -4,6 +4,8 @@ module Ecoportal
4
4
  class Page
5
5
  class Component
6
6
  class TagField < Page::Component
7
+ passthrough :single_select, :use_defaults
8
+ passthrough :tag_tree_id, :button_text
7
9
  end
8
10
  end
9
11
  end
@@ -21,14 +21,14 @@ module Ecoportal
21
21
 
22
22
  def get_by_name(name, type: nil)
23
23
  pool = type ? get_by_type(type) : self
24
-
24
+
25
25
  pool.select do |comp|
26
26
  comp.label.to_s.strip.downcase == name.to_s.strip.downcase
27
27
  end.first
28
28
  end
29
29
 
30
30
  def add(label:, type:)
31
- fld_doc = Ecoportal::API::V2::Page::Component.new_doc(type: type)
31
+ fld_doc = component_class.new_doc(type: type)
32
32
  upsert!(fld_doc) do |fld|
33
33
  fld.label = label
34
34
  yield(fld) if block_given?
@@ -29,6 +29,7 @@ module Ecoportal
29
29
  passthrough :patch_ver, :weight, :type
30
30
  passthrough :heading, :left_heading, :right_heading
31
31
  passarray :component_ids, :left_component_ids, :right_component_ids
32
+ passthrough :minimized
32
33
 
33
34
  def split?
34
35
  doc && doc["type"] == "split"
@@ -8,7 +8,7 @@ module Ecoportal
8
8
  self.klass = :section_class
9
9
 
10
10
  def add(name: nil, split: false, pos: NOT_USED, before: NOT_USED, after: NOT_USED)
11
- sec_doc = Ecoportal::API::V2::Page::Section.new_doc(split: split)
11
+ sec_doc = section_class.new_doc(split: split)
12
12
  upsert!(sec_doc, pos: pos, before: before, after: after) do |section|
13
13
  section.heading = name
14
14
  if prev = previous_section(section)
@@ -13,6 +13,12 @@ module Ecoportal
13
13
  end
14
14
  end
15
15
 
16
+ def ordered_stages
17
+ stages.each_with_index.sort_by do |stage, index|
18
+ (stage.ordering >= 9999) ? [index, index] : [stage.ordering, index]
19
+ end.map(&:first)
20
+ end
21
+
16
22
  end
17
23
  end
18
24
  end
@@ -28,22 +28,33 @@ module Ecoportal
28
28
  # @note
29
29
  # - if the request has `success?` the returned `object.result` gives an object with that `Page`.
30
30
  # - if it failed to obtain the full page, it returns a `PageStage` with the active stage data.
31
- # @param doc [String, Hash, Page] data containing an `id` of the target page.
31
+ # @param id [String, Hash, Stage] the `id` of the target **page**.
32
+ # @param stage_id [String] the `id` of the target **stage**.
32
33
  # @return [Ecoportal::API::V2::Page, Ecoportal::API::V2::Pages::PageStage] the target page.
33
- def get(doc)
34
- pid = get_id(doc)
35
- response = client.get("/pages/#{CGI.escape(pid)}")
34
+ def get(id, stage_id: nil)
35
+ return stages.get(pid: id, sid: stage_id) if stage_id
36
+ id = get_id(id)
37
+ response = client.get("/pages/#{CGI.escape(id)}")
36
38
  wrapped = Common::Content::WrappedResponse.new(response, page_class)
37
39
 
38
40
  return wrapped.result if wrapped.success?
39
41
  if (response.status == 302) && (url = response.body["data"])
40
- if sid = url_to_stage_id(url)
41
- return stages.get(pid: pid, sid: sid)
42
+ if stage_id = url_to_stage_id(url)
43
+ return stages.get(pid: id, sid: stage_id)
42
44
  end
43
45
  end
44
46
  raise "Could not get page #{pid} - Error #{response.status}: #{response.body}"
45
47
  end
46
48
 
49
+ # Requests to update an existing page via api.
50
+ # @param doc [Hash, Page] data that at least contains an `id` (internal or external) of the target page.
51
+ # @return [Response] an object with the api response.
52
+ def update(doc)
53
+ body = get_body(doc) # , level: "page"
54
+ id = get_id(doc)
55
+ client.patch("/pages/#{CGI.escape(id)}", data: body)
56
+ end
57
+
47
58
  # Gets a `new` non-existing page via api with all the ids initialized.
48
59
  # @param from [String, Hash, Page] template or `id` of the template
49
60
  # @return [Ecoportal::API::V2::Page] the new page object.
@@ -66,15 +77,6 @@ module Ecoportal
66
77
  client.post("/pages", data: body, params: {template_id: id})
67
78
  end
68
79
 
69
- # Requests to update an existing page via api.
70
- # @param doc [Hash, Page] data that at least contains an `id` (internal or external) of the target page.
71
- # @return [Response] an object with the api response.
72
- def update(doc)
73
- body = get_body(doc) # , level: "page"
74
- id = get_id(doc)
75
- client.patch("/pages/#{CGI.escape(id)}", data: body)
76
- end
77
-
78
80
  private
79
81
 
80
82
  def url_to_stage_id(url)