ecoportal-api-v2 0.8.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +20 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +55 -0
  5. data/.travis.yml +5 -0
  6. data/.yardopts +10 -0
  7. data/CHANGELOG.md +171 -0
  8. data/Gemfile +6 -0
  9. data/LICENSE +21 -0
  10. data/README.md +22 -0
  11. data/Rakefile +27 -0
  12. data/bin/console +14 -0
  13. data/bin/setup +8 -0
  14. data/ecoportal-api-v2.gemspec +34 -0
  15. data/lib/ecoportal/api-v2.rb +10 -0
  16. data/lib/ecoportal/api/common.rb +18 -0
  17. data/lib/ecoportal/api/common/content.rb +18 -0
  18. data/lib/ecoportal/api/common/content/array_model.rb +286 -0
  19. data/lib/ecoportal/api/common/content/class_helpers.rb +146 -0
  20. data/lib/ecoportal/api/common/content/client.rb +40 -0
  21. data/lib/ecoportal/api/common/content/collection_model.rb +279 -0
  22. data/lib/ecoportal/api/common/content/doc_helpers.rb +67 -0
  23. data/lib/ecoportal/api/common/content/double_model.rb +356 -0
  24. data/lib/ecoportal/api/common/content/hash_diff_patch.rb +183 -0
  25. data/lib/ecoportal/api/common/content/string_digest.rb +27 -0
  26. data/lib/ecoportal/api/common/content/wrapped_response.rb +42 -0
  27. data/lib/ecoportal/api/v2.rb +82 -0
  28. data/lib/ecoportal/api/v2/page.rb +42 -0
  29. data/lib/ecoportal/api/v2/page/component.rb +133 -0
  30. data/lib/ecoportal/api/v2/page/component/action.rb +28 -0
  31. data/lib/ecoportal/api/v2/page/component/action_field.rb +54 -0
  32. data/lib/ecoportal/api/v2/page/component/chart_field.rb +54 -0
  33. data/lib/ecoportal/api/v2/page/component/chart_field/frequency.rb +29 -0
  34. data/lib/ecoportal/api/v2/page/component/chart_field/heatmap.rb +27 -0
  35. data/lib/ecoportal/api/v2/page/component/chart_field/indicator.rb +26 -0
  36. data/lib/ecoportal/api/v2/page/component/chart_field/multiseries.rb +31 -0
  37. data/lib/ecoportal/api/v2/page/component/chart_field/sankey.rb +27 -0
  38. data/lib/ecoportal/api/v2/page/component/chart_field/serie.rb +26 -0
  39. data/lib/ecoportal/api/v2/page/component/chart_field/series_config.rb +23 -0
  40. data/lib/ecoportal/api/v2/page/component/chart_fr_field.rb +32 -0
  41. data/lib/ecoportal/api/v2/page/component/checklist_field.rb +49 -0
  42. data/lib/ecoportal/api/v2/page/component/checklist_item.rb +25 -0
  43. data/lib/ecoportal/api/v2/page/component/date_field.rb +34 -0
  44. data/lib/ecoportal/api/v2/page/component/file.rb +16 -0
  45. data/lib/ecoportal/api/v2/page/component/files_field.rb +13 -0
  46. data/lib/ecoportal/api/v2/page/component/gauge_field.rb +36 -0
  47. data/lib/ecoportal/api/v2/page/component/gauge_stop.rb +88 -0
  48. data/lib/ecoportal/api/v2/page/component/geo_field.rb +13 -0
  49. data/lib/ecoportal/api/v2/page/component/image.rb +16 -0
  50. data/lib/ecoportal/api/v2/page/component/images_field.rb +23 -0
  51. data/lib/ecoportal/api/v2/page/component/law_field.rb +12 -0
  52. data/lib/ecoportal/api/v2/page/component/number_field.rb +12 -0
  53. data/lib/ecoportal/api/v2/page/component/people_field.rb +25 -0
  54. data/lib/ecoportal/api/v2/page/component/plain_text_field.rb +15 -0
  55. data/lib/ecoportal/api/v2/page/component/reference_field.rb +16 -0
  56. data/lib/ecoportal/api/v2/page/component/rich_text_field.rb +13 -0
  57. data/lib/ecoportal/api/v2/page/component/selection_field.rb +78 -0
  58. data/lib/ecoportal/api/v2/page/component/selection_option.rb +25 -0
  59. data/lib/ecoportal/api/v2/page/component/signature_field.rb +25 -0
  60. data/lib/ecoportal/api/v2/page/component/tag_field.rb +14 -0
  61. data/lib/ecoportal/api/v2/page/components.rb +42 -0
  62. data/lib/ecoportal/api/v2/page/section.rb +59 -0
  63. data/lib/ecoportal/api/v2/page/sections.rb +47 -0
  64. data/lib/ecoportal/api/v2/page/stage.rb +29 -0
  65. data/lib/ecoportal/api/v2/page/stages.rb +26 -0
  66. data/lib/ecoportal/api/v2/pages.rb +92 -0
  67. data/lib/ecoportal/api/v2/pages/page_stage.rb +16 -0
  68. data/lib/ecoportal/api/v2/pages/stages.rb +55 -0
  69. data/lib/ecoportal/api/v2/people.rb +31 -0
  70. data/lib/ecoportal/api/v2/registers.rb +89 -0
  71. data/lib/ecoportal/api/v2/registers/page_result.rb +21 -0
  72. data/lib/ecoportal/api/v2/registers/register.rb +37 -0
  73. data/lib/ecoportal/api/v2/registers/stage_result.rb +14 -0
  74. data/lib/ecoportal/api/v2/registers/stages_result.rb +13 -0
  75. data/lib/ecoportal/api/v2/registers/template.rb +12 -0
  76. data/lib/ecoportal/api/v2/version.rb +7 -0
  77. metadata +254 -0
@@ -0,0 +1,34 @@
1
+ module Ecoportal
2
+ module API
3
+ class V2
4
+ class Page
5
+ class Component
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
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
+
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,16 @@
1
+ module Ecoportal
2
+ module API
3
+ class V2
4
+ class Page
5
+ class Component
6
+ class File < Common::Content::DoubleModel
7
+ passkey :id
8
+ passthrough :patch_ver, :position
9
+ passthrough :content_type, :file_size, :file_container_id
10
+ passdate :file_update_at
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,13 @@
1
+ module Ecoportal
2
+ module API
3
+ class V2
4
+ class Page
5
+ class Component
6
+ class FilesField < Page::Component
7
+ embeds_many :items, klass: "Ecoportal::API::V2::Page::File", order_key: :position
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,36 @@
1
+ module Ecoportal
2
+ module API
3
+ class V2
4
+ class Page
5
+ class Component
6
+ class GaugeField < Page::Component
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
+
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
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
@@ -0,0 +1,13 @@
1
+ module Ecoportal
2
+ module API
3
+ class V2
4
+ class Page
5
+ class Component
6
+ class GeoField < Page::Component
7
+ passthrough :address, :coordinates
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,16 @@
1
+ module Ecoportal
2
+ module API
3
+ class V2
4
+ class Page
5
+ class Component
6
+ class Image < Common::Content::DoubleModel
7
+ passkey :id
8
+ passthrough :patch_ver, :weight
9
+ passthrough :height, :width, :caption
10
+ passthrough :dimensions, :styles
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,23 @@
1
+ module Ecoportal
2
+ module API
3
+ class V2
4
+ class Page
5
+ class Component
6
+ class ImagesField < Page::Component
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
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,12 @@
1
+ module Ecoportal
2
+ module API
3
+ class V2
4
+ class Page
5
+ class Component
6
+ class LawField < Page::Component
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ module Ecoportal
2
+ module API
3
+ class V2
4
+ class Page
5
+ class Component
6
+ class NumberField < Page::Component
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,25 @@
1
+ module Ecoportal
2
+ module API
3
+ class V2
4
+ class Page
5
+ class Component
6
+ class PeopleField < Page::Component
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
15
+
16
+ def add(id)
17
+ people_ids << id
18
+ end
19
+
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,15 @@
1
+ module Ecoportal
2
+ module API
3
+ class V2
4
+ class Page
5
+ class Component
6
+ class PlainTextField < Page::Component
7
+ passthrough :value
8
+ passthrough :multiline, :max_length
9
+ pass_reader :exact_index
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,16 @@
1
+ module Ecoportal
2
+ module API
3
+ class V2
4
+ class Page
5
+ class Component
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
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,13 @@
1
+ module Ecoportal
2
+ module API
3
+ class V2
4
+ class Page
5
+ class Component
6
+ class RichTextField < Page::Component
7
+ passthrough :content
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,78 @@
1
+ module Ecoportal
2
+ module API
3
+ class V2
4
+ class Page
5
+ class Component
6
+ class SelectionField < Page::Component
7
+ passthrough :multiple, :flat
8
+ passthrough :other, :other_desc
9
+
10
+ embeds_many :options, klass: "Ecoportal::API::V2::Page::Component::SelectionOption", order_key: :weight
11
+
12
+ def select(value)
13
+ opt = options.find {|opt| opt.value == value}
14
+ sel = selected
15
+ return true if !multiple && opt == sel
16
+ sel.selected = false if !multiple && sel
17
+ opt.selected = true unless !opt
18
+ end
19
+
20
+ def selected
21
+ if multiple
22
+ options.select {|opt| opt.selected}
23
+ else
24
+ options.find {|opt| opt.selected}
25
+ end
26
+ end
27
+
28
+ def value
29
+ if multiple
30
+ selected.map {|opt| opt.value}
31
+ else
32
+ selected&.value
33
+ end
34
+ end
35
+
36
+ def add_option(name:, value:, pos: NOT_USED, before: NOT_USED, after: NOT_USED)
37
+ opt_doc = options.items_class.new_doc
38
+ options.upsert!(opt_doc, pos: pos, before: before, after: after) do |option|
39
+ option.name = name
40
+ option.value = value
41
+ if prev = previous_option(option)
42
+ option.weight = prev.weight
43
+ end
44
+ yield(option) if block_given?
45
+ fix_option_weights!
46
+ end
47
+ end
48
+
49
+ def ordered_options
50
+ options.each_with_index.sort_by do |option, index|
51
+ (option.weight >= 9999) ? [index, index] : [option.weight, index]
52
+ end.map(&:first)
53
+ end
54
+
55
+ private
56
+
57
+ def fix_option_weights!
58
+ ordered_options.each_with_index do |option, index|
59
+ option.weight = index
60
+ end
61
+ end
62
+
63
+ def previous_option(value)
64
+ opts = ordered_options
65
+ pos = opts.index(value) - 1
66
+ return if pos < 0
67
+ opts[pos]
68
+ end
69
+
70
+
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
77
+
78
+ require 'ecoportal/api/v2/page/component/selection_option'
@@ -0,0 +1,25 @@
1
+ module Ecoportal
2
+ module API
3
+ class V2
4
+ class Page
5
+ class Component
6
+ class SelectionOption < 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
+
17
+ passkey :id
18
+ passthrough :patch_ver, :name, :value
19
+ passthrough :weight, :selected
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end