ecoportal-api-v2 0.8.8 → 0.8.9

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 (46) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +38 -3
  3. data/lib/ecoportal/api/common/content.rb +1 -0
  4. data/lib/ecoportal/api/common/content/array_model.rb +8 -6
  5. data/lib/ecoportal/api/common/content/collection_model.rb +10 -4
  6. data/lib/ecoportal/api/common/content/double_model.rb +11 -0
  7. data/lib/ecoportal/api/common/content/hash_diff_patch.rb +31 -19
  8. data/lib/ecoportal/api/common/content/model_helpers.rb +36 -0
  9. data/lib/ecoportal/api/v2/page.rb +1 -0
  10. data/lib/ecoportal/api/v2/page/component.rb +33 -3
  11. data/lib/ecoportal/api/v2/page/component/action.rb +13 -5
  12. data/lib/ecoportal/api/v2/page/component/action_field.rb +37 -2
  13. data/lib/ecoportal/api/v2/page/component/chart_field.rb +39 -5
  14. data/lib/ecoportal/api/v2/page/component/chart_field/benchmark.rb +9 -7
  15. data/lib/ecoportal/api/v2/page/component/chart_field/config.rb +23 -0
  16. data/lib/ecoportal/api/v2/page/component/chart_field/frequency.rb +3 -4
  17. data/lib/ecoportal/api/v2/page/component/chart_field/heatmap.rb +1 -3
  18. data/lib/ecoportal/api/v2/page/component/chart_field/indicator.rb +4 -5
  19. data/lib/ecoportal/api/v2/page/component/chart_field/multiseries.rb +3 -5
  20. data/lib/ecoportal/api/v2/page/component/chart_field/sankey.rb +1 -3
  21. data/lib/ecoportal/api/v2/page/component/chart_field/serie.rb +3 -4
  22. data/lib/ecoportal/api/v2/page/component/chart_field/series_config.rb +5 -7
  23. data/lib/ecoportal/api/v2/page/component/chart_fr_field.rb +7 -5
  24. data/lib/ecoportal/api/v2/page/component/checklist_field.rb +1 -1
  25. data/lib/ecoportal/api/v2/page/component/checklist_item.rb +3 -2
  26. data/lib/ecoportal/api/v2/page/component/date_field.rb +71 -4
  27. data/lib/ecoportal/api/v2/page/component/file.rb +3 -2
  28. data/lib/ecoportal/api/v2/page/component/gauge_field.rb +2 -2
  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/images_field.rb +57 -1
  32. data/lib/ecoportal/api/v2/page/component/people_field.rb +102 -4
  33. data/lib/ecoportal/api/v2/page/component/plain_text_field.rb +34 -2
  34. data/lib/ecoportal/api/v2/page/component/reference_field.rb +32 -3
  35. data/lib/ecoportal/api/v2/page/component/selection_field.rb +59 -3
  36. data/lib/ecoportal/api/v2/page/component/selection_option.rb +2 -1
  37. data/lib/ecoportal/api/v2/page/component/tag_field.rb +31 -1
  38. data/lib/ecoportal/api/v2/page/components.rb +8 -3
  39. data/lib/ecoportal/api/v2/page/permission_flags.rb +67 -0
  40. data/lib/ecoportal/api/v2/page/section.rb +65 -5
  41. data/lib/ecoportal/api/v2/page/sections.rb +64 -6
  42. data/lib/ecoportal/api/v2/page/stage.rb +10 -6
  43. data/lib/ecoportal/api/v2/page/stages.rb +2 -2
  44. data/lib/ecoportal/api/v2/pages/page_stage.rb +0 -1
  45. data/lib/ecoportal/api/v2_version.rb +1 -1
  46. metadata +6 -2
@@ -7,26 +7,84 @@ module Ecoportal
7
7
 
8
8
  self.klass = :section_class
9
9
 
10
+ # Creates a new `section`
10
11
  def add(name: nil, split: false, pos: NOT_USED, before: NOT_USED, after: NOT_USED)
11
12
  sec_doc = section_class.new_doc(split: split)
12
- upsert!(sec_doc, pos: pos, before: before, after: after) do |section|
13
+ upsert!(sec_doc) do |section| #, pos: pos, before: before, after: after) do |section|
13
14
  section.heading = name
14
- if prev = previous_section(section)
15
- section.weight = prev.weight
15
+ if weight = scope_weight(pos: pos, before: before, after: after)
16
+ section.weight = weight
16
17
  end
18
+ fix_weights!
17
19
  yield(section) if block_given?
18
- #fix_weights! # a server bug prevents to set the weight of existing sections
19
20
  end
20
21
  end
21
22
 
23
+ def get_by_type(type)
24
+ ordered.select do |sec|
25
+ sec.type == type
26
+ end
27
+ end
28
+
29
+ def get_by_heading(heading)
30
+ ordered.select do |sec|
31
+ value = heading == :unnamed ? nil : heading
32
+ same_string?(sec.heading, value)
33
+ end
34
+ end
35
+
36
+ # Gets all the sections between `sec1` and `sec2`
37
+ def between(sec1, sec2, included: false)
38
+ sorted_secs = ordered
39
+ pos1 = (sec1 = to_section(sec1)) && sorted_secs.index(sec1)
40
+ pos2 = (sec2 = to_section(sec2)) && sorted_secs.index(sec2)
41
+ if included
42
+ pos1 = pos1 ? pos1 : 0
43
+ pos2 = pos2 ? pos2 : -1
44
+ else
45
+ pos1 = pos1 ? (pos1 + 1) : 0
46
+ pos2 = pos2 ? (pos2 - 1) : -1
47
+ end
48
+ sorted_secs[pos1..pos2]
49
+ end
50
+
51
+ # Gets the sections ordered by `weight` (as they appear in the page)
22
52
  def ordered
23
- each_with_index.sort_by do |section, index|
53
+ self.sort_by.with_index do |section, index|
24
54
  (section.weight >= 9999) ? [index, index] : [section.weight, index]
25
- end.map(&:first)
55
+ end
26
56
  end
27
57
 
28
58
  private
29
59
 
60
+ def scope_weight(pos: NOT_USED, before: NOT_USED, after: NOT_USED)
61
+ case
62
+ when used_param?(pos)
63
+ if pos = to_section(pos)
64
+ pos.weight - 1
65
+ end
66
+ when used_param?(before)
67
+ if before = to_section(before)
68
+ before.weight - 1
69
+ end
70
+ when used_param?(after)
71
+ if after = to_section(after)
72
+ after.weight
73
+ end
74
+ end
75
+ end
76
+
77
+ def to_section(value)
78
+ case value
79
+ when Ecoportal::API::V2::Page::Section
80
+ value
81
+ when Numeric
82
+ ordered[value]
83
+ else
84
+ get_by_heading(value).first
85
+ end
86
+ end
87
+
30
88
  def fix_weights!
31
89
  ordered.each_with_index do |section, index|
32
90
  section.weight = index
@@ -5,13 +5,16 @@ module Ecoportal
5
5
  class Stage < Common::Content::DoubleModel
6
6
  passkey :id
7
7
  passthrough :patch_ver
8
- passthrough :namem, :ordering
8
+ passthrough :name, :ordering
9
9
  passarray :subtags, order_matters: false
10
10
  passarray :section_ids
11
- passthrough :complete, :status, :lock_after_completion
11
+ passthrough :status
12
+ passboolean :complete, :lock_after_completion
13
+
12
14
  embeds_many :permits, klass: "Ecoportal::API::V2::Page::Permit"
13
- passthrough :disable_direct_permissions
14
- passthrough :creator_enabled, :creator_editable, :creator_flags
15
+ passboolean :disable_direct_permissions
16
+ passboolean :creator_enabled, :creator_editable
17
+ embeds_one :creator_flags, klass: "Ecoportal::API::V2::Page::PermissionFlags"
15
18
  passthrough :can
16
19
 
17
20
  def sections
@@ -22,8 +25,9 @@ module Ecoportal
22
25
  end.sort_by {|sec| sec.weight}
23
26
  end
24
27
 
25
- def attach_section(section)
26
- section_ids.insert_one(section.id)
28
+ def add_section(*secs)
29
+ secs.each {|sec| section_ids.insert_one(sec.id)}
30
+ self
27
31
  end
28
32
 
29
33
  end
@@ -8,8 +8,8 @@ module Ecoportal
8
8
  self.klass = :stage_class
9
9
 
10
10
  def get_by_name(name)
11
- find do |stage|
12
- stage.name.strip.downcase == name.to_s.strip.downcase
11
+ self.find do |stage|
12
+ same_string?(stage.name, name)
13
13
  end
14
14
  end
15
15
 
@@ -9,7 +9,6 @@ module Ecoportal
9
9
 
10
10
  embeds_many :permits, klass: "Ecoportal::API::V2::Page::Permit"
11
11
  passarray :force_errors, :subtags, order_matters: false
12
- #passthrough :evolution
13
12
  end
14
13
  end
15
14
  end
@@ -1,5 +1,5 @@
1
1
  module Ecoportal
2
2
  module API
3
- GEM2_VERSION = "0.8.8"
3
+ GEM2_VERSION = "0.8.9"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ecoportal-api-v2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.8
4
+ version: 0.8.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oscar Segura
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-08-03 00:00:00.000000000 Z
11
+ date: 2021-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -176,6 +176,7 @@ files:
176
176
  - lib/ecoportal/api/common/content/doc_helpers.rb
177
177
  - lib/ecoportal/api/common/content/double_model.rb
178
178
  - lib/ecoportal/api/common/content/hash_diff_patch.rb
179
+ - lib/ecoportal/api/common/content/model_helpers.rb
179
180
  - lib/ecoportal/api/common/content/string_digest.rb
180
181
  - lib/ecoportal/api/common/content/wrapped_response.rb
181
182
  - lib/ecoportal/api/v2.rb
@@ -185,6 +186,7 @@ files:
185
186
  - lib/ecoportal/api/v2/page/component/action_field.rb
186
187
  - lib/ecoportal/api/v2/page/component/chart_field.rb
187
188
  - lib/ecoportal/api/v2/page/component/chart_field/benchmark.rb
189
+ - lib/ecoportal/api/v2/page/component/chart_field/config.rb
188
190
  - lib/ecoportal/api/v2/page/component/chart_field/frequency.rb
189
191
  - lib/ecoportal/api/v2/page/component/chart_field/heatmap.rb
190
192
  - lib/ecoportal/api/v2/page/component/chart_field/indicator.rb
@@ -200,6 +202,7 @@ files:
200
202
  - lib/ecoportal/api/v2/page/component/files_field.rb
201
203
  - lib/ecoportal/api/v2/page/component/gauge_field.rb
202
204
  - lib/ecoportal/api/v2/page/component/gauge_stop.rb
205
+ - lib/ecoportal/api/v2/page/component/geo_coordinates.rb
203
206
  - lib/ecoportal/api/v2/page/component/geo_field.rb
204
207
  - lib/ecoportal/api/v2/page/component/image.rb
205
208
  - lib/ecoportal/api/v2/page/component/images_field.rb
@@ -214,6 +217,7 @@ files:
214
217
  - lib/ecoportal/api/v2/page/component/signature_field.rb
215
218
  - lib/ecoportal/api/v2/page/component/tag_field.rb
216
219
  - lib/ecoportal/api/v2/page/components.rb
220
+ - lib/ecoportal/api/v2/page/permission_flags.rb
217
221
  - lib/ecoportal/api/v2/page/permit.rb
218
222
  - lib/ecoportal/api/v2/page/section.rb
219
223
  - lib/ecoportal/api/v2/page/sections.rb