ecoportal-api-v2 0.8.19 → 0.8.23

Sign up to get free protection for your applications and to get access to all the features.
Files changed (29) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +38 -1
  3. data/ecoportal-api-v2.gemspec +1 -1
  4. data/lib/ecoportal/api/common/content/array_model.rb +4 -0
  5. data/lib/ecoportal/api/v2/page/component/action.rb +13 -0
  6. data/lib/ecoportal/api/v2/page/component/action_field.rb +4 -0
  7. data/lib/ecoportal/api/v2/page/component/checklist_field.rb +4 -0
  8. data/lib/ecoportal/api/v2/page/component/checklist_item.rb +4 -0
  9. data/lib/ecoportal/api/v2/page/component/date_field.rb +4 -0
  10. data/lib/ecoportal/api/v2/page/component/file.rb +4 -0
  11. data/lib/ecoportal/api/v2/page/component/files_field.rb +4 -0
  12. data/lib/ecoportal/api/v2/page/component/gauge_field.rb +3 -0
  13. data/lib/ecoportal/api/v2/page/component/geo_coordinates.rb +4 -0
  14. data/lib/ecoportal/api/v2/page/component/geo_field.rb +4 -0
  15. data/lib/ecoportal/api/v2/page/component/images_field.rb +5 -1
  16. data/lib/ecoportal/api/v2/page/component/people_field.rb +4 -0
  17. data/lib/ecoportal/api/v2/page/component/plain_text_field.rb +4 -0
  18. data/lib/ecoportal/api/v2/page/component/reference_field.rb +11 -0
  19. data/lib/ecoportal/api/v2/page/component/rich_text_field.rb +17 -0
  20. data/lib/ecoportal/api/v2/page/component/selection_field.rb +6 -0
  21. data/lib/ecoportal/api/v2/page/component/tag_field.rb +4 -0
  22. data/lib/ecoportal/api/v2/page/section.rb +2 -3
  23. data/lib/ecoportal/api/v2/page/stage.rb +1 -1
  24. data/lib/ecoportal/api/v2/page/stages.rb +5 -5
  25. data/lib/ecoportal/api/v2/pages/page_stage.rb +2 -2
  26. data/lib/ecoportal/api/v2/pages.rb +1 -1
  27. data/lib/ecoportal/api/v2/registers.rb +51 -19
  28. data/lib/ecoportal/api/v2_version.rb +1 -1
  29. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 11e7f2b8bb7544cb9d99ad0660b3a52ec388725f2fe76018f3b0bc2f8e122c04
4
- data.tar.gz: 31e3858fa5c4d3c632f5d3e04a51a3bc75b64cd719f646f22b5a6e24e42a1a95
3
+ metadata.gz: 95c3cc7227186059ebac670bc0b3ba3637addab3f51dfe22d9303a27088cb2fd
4
+ data.tar.gz: 05c0ee0a0a548081136d328ef1b33a27d6ee4f029752a8a1f3c28308fd05ea82
5
5
  SHA512:
6
- metadata.gz: 4b4eda0998b1f122c2df6480ba283200bd9df1c985fa761f514231e6f6dddd89beff13d2c4bfa52e7e3d8ca39644efef57508caa369eca2b2b13478ac1faea5f
7
- data.tar.gz: 31ab53da2363812cb340c41233eae35efe2c3e4024f77d670c6ffd2fb33f1697eabfacafc6bb85f895e4ef8faeed7b8d65858905fb967330bd181c4061198442
6
+ metadata.gz: 2ad708f7fcec88a0380997bbf493d2186b5853e1eb4884e62c1107a4116337c53939852f99ab3d7cedbf2dddceed5fca63531f985a32a3a67139e150c9b94e7d
7
+ data.tar.gz: aec3d7c8faa9cae78da045b34865da17a5ceb5b548fb9a66a1be51dc2448da92c150f528d9a9b62d1fdb93d1bfbeadbb7ff812ea02a9c7c0d6eb07aadb985f0d
data/CHANGELOG.md CHANGED
@@ -1,9 +1,46 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
- ## [0.8.19] - 2021-09-29
4
+ ## [0.8.23] - 2021-12-24
5
5
 
6
6
  ### Added
7
+ - `Ecoportal::API::V2::Registers#search` added more feedback on what is going on
8
+
9
+ ### Changed
10
+ ### Fixed
11
+
12
+ ## [0.8.22] - 2021-12-23
13
+
14
+ ### Fixed
15
+ - `Ecoportal::API::V2::Page::Section#add_component` was not using correctly `before` and `after`
16
+ - It was not correctly translating them into the existing component
17
+
18
+ ## [0.8.21] - 2021-12-15
19
+
20
+ ### Added
21
+ - To children of `Ecoportal::API::V2::Page::Component` added method `#to_s` (for exporting)
22
+ - `Ecoportal::API::V2::Page::Component::ReferenceField`
23
+ - added `#references` (the lookup results)
24
+ - added `#reference_ids` (the `ids` of the referenced oozes)
25
+
26
+ ### Changed
27
+ - Re-exposed `Ecoportal::API::V2::Stages#ordered`
28
+
29
+ ### Fixed
30
+ - `Ecoportal::API::V2::Page::Component::ImagesField#images` typo in `klass`
31
+
32
+ ## [0.8.20] - 2021-12-09
33
+
34
+ ### Changed
35
+ - `Ecoportal::API::V2::Pages::PageStage#permits` removed
36
+ - The reason is that it should be changed using the `Stage#permits` instead
37
+ - Upgraded `ecoportal-api` gem dependency
38
+
39
+ ### Fixed
40
+ - `Ecoportal::API::V2::Page::Stage#sections` typo
41
+
42
+ ## [0.8.19] - 2021-09-29
43
+
7
44
  ### Changed
8
45
  - Moved validation of components multi-section from `PageStage` to `Page`
9
46
  - Removed validation from `PageStage#as_update`
@@ -29,5 +29,5 @@ Gem::Specification.new do |spec|
29
29
  spec.add_development_dependency "redcarpet", ">= 3.5.1", "< 3.6"
30
30
  spec.add_development_dependency "pry" , ">= 0.14"
31
31
 
32
- spec.add_dependency 'ecoportal-api', '>= 0.8.3', '< 0.9'
32
+ spec.add_dependency 'ecoportal-api', '>= 0.8.4', '< 0.9'
33
33
  end
@@ -55,6 +55,10 @@ module Ecoportal
55
55
  doc.tap {|d| d.uniq! if uniq?}
56
56
  end
57
57
 
58
+ def to_s(delimiter: "|")
59
+ map(&:to_s).join(delimiter)
60
+ end
61
+
58
62
  # @see #_items
59
63
  # @return [Array] a **copy** of the `Array` elements
60
64
  def to_a
@@ -29,6 +29,19 @@ module Ecoportal
29
29
  passthrough :duration_in_days, read_only: true
30
30
  passarray :file_container_ids
31
31
 
32
+ def to_s
33
+ stat = case
34
+ when overdue
35
+ "Overdue"
36
+ when complete
37
+ "Complete"
38
+ else
39
+ "Pending"
40
+ end
41
+ assignee = assigned_person_member["name"] || assigned_person_member["email"]
42
+ "#{name}, #{created_at.to_s}, #{stat}, #{assignee}"
43
+ end
44
+
32
45
  end
33
46
  end
34
47
  end
@@ -30,6 +30,10 @@ module Ecoportal
30
30
  end
31
31
  end
32
32
 
33
+ def to_s(delimiter: "\n")
34
+ ordered_tasks.map(&:to_s).join(delimiter)
35
+ end
36
+
33
37
  # Quick config helper
34
38
  # @param conf [Symbol, Array<Symbol>]
35
39
  # - `:requires` required number of completed actions
@@ -24,6 +24,10 @@ module Ecoportal
24
24
  end
25
25
  end
26
26
 
27
+ def to_s(delimiter: "\n")
28
+ ordered_items.map(&:to_s).compact.join(delimiter)
29
+ end
30
+
27
31
  private
28
32
 
29
33
  def fix_item_weights!
@@ -19,6 +19,10 @@ module Ecoportal
19
19
  passthrough :label
20
20
  passthrough :weight
21
21
  passboolean :checked
22
+
23
+ def to_s
24
+ checked ? label : nil
25
+ end
22
26
  end
23
27
  end
24
28
  end
@@ -34,6 +34,10 @@ module Ecoportal
34
34
  doc["create_event"] = !!value
35
35
  end
36
36
 
37
+ def to_s
38
+ value.to_s
39
+ end
40
+
37
41
  # Quick config helper
38
42
  # @param conf [Symbol, Array<Symbol>]
39
43
  # - `:time` to show time
@@ -19,6 +19,10 @@ module Ecoportal
19
19
  passthrough :file_size, :content_type, :token, read_only: true
20
20
  passthrough :file_container_id
21
21
  passdate :file_update_at, read_only: true
22
+
23
+ def to_s
24
+ file_container_id
25
+ end
22
26
  end
23
27
  end
24
28
  end
@@ -24,6 +24,10 @@ module Ecoportal
24
24
  end
25
25
  end
26
26
 
27
+ def to_s(delimiter: "\n")
28
+ ordered_files.map(&:to_s).join(delimiter)
29
+ end
30
+
27
31
  private
28
32
 
29
33
  def fix_file_positions!
@@ -26,6 +26,9 @@ module Ecoportal
26
26
  end
27
27
  end
28
28
 
29
+ def to_s
30
+ value.to_s
31
+ end
29
32
  end
30
33
  end
31
34
  end
@@ -5,6 +5,10 @@ module Ecoportal
5
5
  class Component
6
6
  class GeoCoordinates < Common::Content::DoubleModel
7
7
  passthrough :lat, :lon
8
+
9
+ def to_s
10
+ "#{lat},#{lon}" if lat & lon
11
+ end
8
12
  end
9
13
  end
10
14
  end
@@ -6,6 +6,10 @@ module Ecoportal
6
6
  class GeoField < Page::Component
7
7
  passthrough :address
8
8
  embeds_one :coordinates, klass: "Ecoportal::API::V2::Page::Component::GeoCoordinates"
9
+
10
+ def to_s
11
+ coordinates.to_s
12
+ end
9
13
  end
10
14
  end
11
15
  end
@@ -15,7 +15,11 @@ module Ecoportal
15
15
 
16
16
  passthrough :layout
17
17
  passboolean :strech, :no_popup, :hide_options
18
- embeds_many :images, klass: "Ecoportal::API::V2::Page::Image", order_key: :weight
18
+ embeds_many :images, klass: "Ecoportal::API::V2::Page::Component::Image", order_key: :weight
19
+
20
+ def to_s
21
+ images.count
22
+ end
19
23
 
20
24
  # Quick config helper
21
25
  # @param conf [Symbol, Array<Symbol>]
@@ -40,6 +40,10 @@ module Ecoportal
40
40
  viewable_fields.delete!(field_id)
41
41
  end
42
42
 
43
+ def to_s(delimiter: "\n")
44
+ people_ids.join(delimiter)
45
+ end
46
+
43
47
  # Quick config helper
44
48
  # @param conf [Symbol, Array<Symbol>]
45
49
  # - `:snapshot` to set mode to `snapshot`
@@ -9,6 +9,10 @@ module Ecoportal
9
9
  passthrough :max_length
10
10
  passboolean :exact_index
11
11
 
12
+ def to_s
13
+ value
14
+ end
15
+
12
16
  # Quick config helper
13
17
  # @param conf [Symbol, Array<Symbol>]
14
18
  # - `:multiline` multi line mode
@@ -5,10 +5,21 @@ module Ecoportal
5
5
  class Component
6
6
  class ReferenceField < Page::Component
7
7
  passthrough :register_id
8
+ passarray :references
8
9
  passboolean :hide_create, :hide_attach
9
10
  passboolean :hide_metadata, :hide_dashboards
10
11
  passboolean :display_fields, :display_fields_in_lookup
11
12
 
13
+ def reference_ids
14
+ references.map do |ref|
15
+ ref["id"]
16
+ end
17
+ end
18
+
19
+ def to_s(delimiter: "\n")
20
+ reference_ids.to_a.join(delimiter)
21
+ end
22
+
12
23
  # Quick config helper
13
24
  # @param conf [Symbol, Array<Symbol>]
14
25
  # - `:show_fields` specify if the public register fields should be shown (requires `register_id`)
@@ -5,6 +5,23 @@ module Ecoportal
5
5
  class Component
6
6
  class RichTextField < Page::Component
7
7
  passthrough :content
8
+
9
+ HTML_TAGS_REX = /<("[^"]*"|'[^']*'|[^'">])*>/
10
+
11
+ def to_s
12
+ remove_html_tags(content)
13
+ end
14
+
15
+ private
16
+
17
+ def remove_html_tags(str)
18
+ str = str.gsub(HTML_TAGS_REX, ' ') if str
19
+ str = str.gsub(/[^[:print:]]/, '') if str
20
+ str = str.gsub(":&nbsp;", ' ') if str
21
+ str = str.gsub("&#34;", '"') if str
22
+ str = str.gsub("&amp;", '&') if str
23
+ str
24
+ end
8
25
  end
9
26
  end
10
27
  end
@@ -63,6 +63,12 @@ module Ecoportal
63
63
  end
64
64
  end
65
65
 
66
+ def to_s(name: true, delimiter: "\n")
67
+ [selected].flatten.compact.map do |opt|
68
+ name ? opt.name : opt.value
69
+ end.join(delimiter)
70
+ end
71
+
66
72
  # Quick config helper
67
73
  # @param conf [Symbol, Array<Symbol>]
68
74
  # - `:flat` to display in flat mode
@@ -7,6 +7,10 @@ module Ecoportal
7
7
  passboolean :single_select, :use_defaults
8
8
  passthrough :tag_tree_id, :button_text
9
9
 
10
+ def to_s(delimiter: "\n")
11
+ root.tags.to_s(delimiter: delimiter)
12
+ end
13
+
10
14
  # Quick config helper
11
15
  # @param conf [Symbol, Array<Symbol>]
12
16
  # - `:multiple` to allow multiple selection
@@ -137,7 +137,7 @@ module Ecoportal
137
137
  if before
138
138
  before_fld = to_component(before, side: side)
139
139
  elsif after
140
- after_fld = to_component(afterm, side: side)
140
+ after_fld = to_component(after, side: side)
141
141
  end
142
142
 
143
143
  if split?
@@ -145,7 +145,6 @@ module Ecoportal
145
145
  else
146
146
  ids_ary = component_ids
147
147
  end
148
-
149
148
  ids_ary.insert_one(field.id, before: before_fld&.id, after: after_fld&.id)
150
149
  self
151
150
  end
@@ -168,7 +167,7 @@ module Ecoportal
168
167
 
169
168
  fields.find do |fld|
170
169
  found = nil
171
- found ||= !!value if value.is_a?(Ecoportal::API::V2::Page::Component)
170
+ found ||= fld.id == value.id if value.is_a?(Ecoportal::API::V2::Page::Component)
172
171
  found ||= fld.id == value
173
172
  found ||= same_string?(fld.label, value)
174
173
  end
@@ -28,7 +28,7 @@ module Ecoportal
28
28
  sec_ids = section_ids.to_a
29
29
  root.sections.values_at(*sec_ids).select.with_index do |sec, i|
30
30
  puts "Warning: section #{id} points to missing section #{sec_ids[i]}" if !sec
31
- fld && (!block_given? || yield(sec))
31
+ sec && (!block_given? || yield(sec))
32
32
  end.sort_by.with_index {|sec, index| [sec.weight, index]}
33
33
  end
34
34
 
@@ -19,11 +19,11 @@ module Ecoportal
19
19
  end
20
20
  end
21
21
 
22
- #def ordered
23
- # self.sort_by.with_index do |stage, index|
24
- # [stage.ordering, index]
25
- # end
26
- #end
22
+ def ordered
23
+ self.sort_by.with_index do |stage, index|
24
+ [stage.ordering, index]
25
+ end
26
+ end
27
27
 
28
28
  end
29
29
  end
@@ -7,7 +7,7 @@ module Ecoportal
7
7
  passthrough :task_priority, :state, :status
8
8
  passthrough :votes_enabled, :upvotes, :downvotes
9
9
 
10
- embeds_many :permits, klass: "Ecoportal::API::V2::Page::Permit"
10
+ #embeds_many :permits, klass: "Ecoportal::API::V2::Page::Permit"
11
11
  passarray :force_errors, :subtags, order_matters: false
12
12
 
13
13
  # @return [String] `id` of the stage we got the data of.
@@ -21,7 +21,7 @@ module Ecoportal
21
21
  stages[stage_id]
22
22
  end
23
23
  end
24
-
24
+
25
25
  # @return [String] with feedback, if for this page instance, there are any of:
26
26
  # 1. orphaned components (fields not belonging to any section)
27
27
  # 2. orphaned sections (sections not belonging to any stage)
@@ -49,7 +49,7 @@ module Ecoportal
49
49
  # Requests to update an existing page via api.
50
50
  # @note It won't launch the update unless there are changes
51
51
  # @param doc [Hash, Page] data that at least contains an `id` (internal or external) of the target page.
52
- # @return [Response] an object with the api response.
52
+ # @return [Ecoportal::API::Common::Response] an object with the api response.
53
53
  def update(doc)
54
54
  body = get_body(doc) # , level: "page"
55
55
  # Launch only if there are changes
@@ -1,3 +1,4 @@
1
+ require 'base64'
1
2
  module Ecoportal
2
3
  module API
3
4
  class V2
@@ -42,18 +43,7 @@ module Ecoportal
42
43
  # @return [Ecoportal::API::V2::Registers, Ecoportal::API::V2::Registers::SearchResults]
43
44
  def search(register_id, options = {})
44
45
  only_first = options.delete(:only_first)
45
- # supply a query string
46
- # or a filter array (copy/paste from dev tools in the browser)
47
- options = {query: nil, filters: []}.update(options)
48
- options = {}.tap do |ret|
49
- options.each do |key, value|
50
- if key == :filters && value.any?
51
- ret[key] = {filters: value}.to_json
52
- else
53
- ret[key] = value if key
54
- end
55
- end
56
- end
46
+ options = build_options(options)
57
47
 
58
48
  if only_first
59
49
  response = client.get("/registers/#{register_id}/search", params: options)
@@ -62,19 +52,23 @@ module Ecoportal
62
52
  end
63
53
 
64
54
  cursor_id = nil
65
- results = 0
55
+ results = 0; total = nil
66
56
  loop do
67
57
  options.update(cursor_id: cursor_id) if cursor_id
68
58
  response = client.get("/registers/#{register_id}/search", params: options)
69
59
  raise "Request failed - Status #{response.status}: #{response.body}" unless response.success?
70
60
 
71
- data = response.body["data"]
72
- unless (total = data["total"]) == 0
61
+ data = response.body["data"]
62
+ total ||= data["total"]
63
+ if total != data["total"]
64
+ msg = "Change of total in search results. Probably due to changes that affect the filter (register: #{register_id}):"
65
+ print_search_status(msg, total, results, cursor_id, data)
66
+ #total = data["total"]
67
+ end
68
+
69
+ unless total == 0
73
70
  results += data["results"].length
74
- percent = results * 100 / total
75
- msg = "Registers SEARCH"
76
- print "#{msg}: #{percent.round}% (of #{total})\r"
77
- $stdout.flush
71
+ print_progress(results, total)
78
72
  end
79
73
 
80
74
  data["results"].each do |result|
@@ -83,12 +77,50 @@ module Ecoportal
83
77
  end
84
78
 
85
79
  break if total <= results
80
+ unless data["cursor_id"]
81
+ msg = "Possible error... finishing search for lack of cursor_id in response:"
82
+ print_search_status(msg, total, results, cursor_id, data)
83
+ end
86
84
  break unless (cursor_id = data["cursor_id"])
87
85
  end
88
86
  self
89
87
  end
90
88
 
89
+ private
90
+
91
+ def build_options(options)
92
+ # supply a query string
93
+ # or a filter array (copy/paste from dev tools in the browser)
94
+ options = {query: nil, filters: []}.update(options)
95
+ {}.tap do |ret|
96
+ options.each do |key, value|
97
+ if key == :filters && value.any?
98
+ ret[key] = {filters: value}.to_json
99
+ else
100
+ ret[key] = value if key
101
+ end
102
+ end
103
+ end
104
+ end
105
+
106
+ def print_search_status(msg, total, results, cursor_id, data)
107
+ msg += "\n"
108
+ msg += " • Original total: #{total}\n"
109
+ msg += " • Total results retrieved: #{results}\n"
110
+ msg += " • Cursor id: #{cursor_id} (#{Base64.decode64(cursor_id)})\n"
111
+ msg += " • Current cursor results: #{data["results"]&.length}\n"
112
+ msg += " • Next id: #{data["cursor_id"]} (#{Base64.decode64(data["cursor_id"])})\n" if data["cursor_id"]
113
+ msg += " • Options:"
114
+ puts msg
115
+ pp options
116
+ end
91
117
 
118
+ def print_progress(results, total)
119
+ percent = results * 100 / total
120
+ msg = "Registers SEARCH"
121
+ print "#{msg}: #{percent.round}% (of #{total})\r"
122
+ $stdout.flush
123
+ end
92
124
  end
93
125
  end
94
126
  end
@@ -1,5 +1,5 @@
1
1
  module Ecoportal
2
2
  module API
3
- GEM2_VERSION = "0.8.19"
3
+ GEM2_VERSION = "0.8.23"
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.19
4
+ version: 0.8.23
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-09-28 00:00:00.000000000 Z
11
+ date: 2021-12-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -130,7 +130,7 @@ dependencies:
130
130
  requirements:
131
131
  - - ">="
132
132
  - !ruby/object:Gem::Version
133
- version: 0.8.3
133
+ version: 0.8.4
134
134
  - - "<"
135
135
  - !ruby/object:Gem::Version
136
136
  version: '0.9'
@@ -140,7 +140,7 @@ dependencies:
140
140
  requirements:
141
141
  - - ">="
142
142
  - !ruby/object:Gem::Version
143
- version: 0.8.3
143
+ version: 0.8.4
144
144
  - - "<"
145
145
  - !ruby/object:Gem::Version
146
146
  version: '0.9'