ecoportal-api-v2 0.8.9 → 0.8.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +21 -1
- data/lib/ecoportal/api/common/content/collection_model.rb +35 -16
- data/lib/ecoportal/api/common/content/double_model.rb +83 -5
- data/lib/ecoportal/api/common/content/hash_diff_patch.rb +13 -3
- data/lib/ecoportal/api/v2/page.rb +13 -2
- data/lib/ecoportal/api/v2/page/component.rb +11 -7
- data/lib/ecoportal/api/v2/page/component/action.rb +4 -3
- data/lib/ecoportal/api/v2/page/component/chart_field/config.rb +2 -2
- data/lib/ecoportal/api/v2/page/component/checklist_item.rb +4 -3
- data/lib/ecoportal/api/v2/page/component/file.rb +13 -3
- data/lib/ecoportal/api/v2/page/component/files_field.rb +37 -1
- data/lib/ecoportal/api/v2/page/component/gauge_stop.rb +5 -5
- data/lib/ecoportal/api/v2/page/component/image.rb +2 -1
- data/lib/ecoportal/api/v2/page/component/number_field.rb +1 -0
- data/lib/ecoportal/api/v2/page/component/people_field.rb +14 -2
- data/lib/ecoportal/api/v2/page/component/people_viewable_field.rb +14 -0
- data/lib/ecoportal/api/v2/page/component/selection_option.rb +4 -3
- data/lib/ecoportal/api/v2/page/component/signature_field.rb +3 -2
- data/lib/ecoportal/api/v2/page/permit.rb +2 -1
- data/lib/ecoportal/api/v2/page/section.rb +6 -5
- data/lib/ecoportal/api/v2/page/stage.rb +1 -1
- data/lib/ecoportal/api/v2_version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e8961e37170e3ffe06d26c17daa6672a15d595ff91c5e8fb38253549b166057a
|
4
|
+
data.tar.gz: c9b25eb42cfa9cb45cee3d830067eddc7d4191fa87f0fd4e35620e346ca27922
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a68c58f62600b78745caff84d7e0dbda83e2f79cba8d41ca08ffbcf361060bd614fc6957f38878bb09d41dc6db1fcff3e307dd0072d21d960073683e6881fdbc
|
7
|
+
data.tar.gz: 998e1409fd0674bc409ab2ff1dcfb68f42a0dd37bca8eab040750cc8cc10ca2651fb98dc61adf3d44b0b0dbdc0bccfe384786cdd79ad1fd9ed96d12a00f3a4b4
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,27 @@
|
|
1
1
|
# Change Log
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
-
## [0.8.
|
4
|
+
## [0.8.10] - 2021-08-xx
|
5
|
+
|
6
|
+
### Added
|
7
|
+
- `Ecoportal::API::Common::Content::CollectionModel#[]` now supports position as well
|
8
|
+
- `Ecoportal::API::V2::Page::Component::FilesField#add_file`: support for adding files
|
9
|
+
- `Ecoportal::API::V2::Page::Component::PeopleField#viewable_fields`: support for managing `viewable_fields`
|
10
|
+
|
11
|
+
### Changed
|
12
|
+
|
13
|
+
### Fixed
|
14
|
+
- `Ecoportal::API::V2::Page::Component::FilesField`: was not requiring `File`
|
15
|
+
- `Ecoportal::API::V2::Page::Component::NumberField#value`: it was missing :/
|
16
|
+
- `Ecoportal::API::Common::Content::HashDiffPatch` did not support nested objects in Arrays, where the nested object wouldn't have a `patch_ver`. This **fix** allows for it
|
17
|
+
- `Ecoportal::API::Common::Content::DoubleModel.passforced` to define `methods` that should always be present. This allows to define `patch_ver` as a forced `key` in models that have it
|
18
|
+
- The enforcement (`self.class.enforce!`) happens on `initialize`
|
19
|
+
- `passenforced` subjacent model `forced_model_keys` is inheritable
|
20
|
+
- `Ecoportal::API::Common::Content::CollectionModel`:
|
21
|
+
- Method `upsert!` was not working fine the parameters `pos`, `before` and `after`
|
22
|
+
- Method `delete!` did not support position
|
23
|
+
|
24
|
+
## [0.8.9] - 2021-08-16
|
5
25
|
|
6
26
|
### Added
|
7
27
|
- `Ecoportal::API::Common::Content::ModelHelpers`
|
@@ -143,17 +143,21 @@ module Ecoportal
|
|
143
143
|
end
|
144
144
|
|
145
145
|
# Get an element usign the `key`.
|
146
|
+
# @param value [String, Hash, Ecoportal::API::Common::Content::DoubleModel]
|
147
|
+
# @return [Object] the `items_class` element object
|
146
148
|
def [](value)
|
147
149
|
items_by_key[get_key(value)]
|
148
150
|
end
|
149
151
|
|
152
|
+
# @return [Array<Object>] the `items_class` element object
|
150
153
|
def values_at(*keys)
|
151
154
|
keys.map {|key| self[key]}
|
152
155
|
end
|
153
156
|
|
154
157
|
# Tries to find the element `value`, if it exists, it updates it
|
155
|
-
#
|
156
|
-
# @
|
158
|
+
# Otherwise it pushes it to the end
|
159
|
+
# @value [Hash, Ecoportal::API::Common::Content::DoubleModel] the eleement to be added
|
160
|
+
# @return [Object] the `items_class` element object
|
157
161
|
def upsert!(value, pos: NOT_USED, before: NOT_USED, after: NOT_USED)
|
158
162
|
unless value.is_a?(Hash) || value.is_a?(Content::DoubleModel)
|
159
163
|
raise "'Content::DoubleModel' or 'Hash' doc required"
|
@@ -163,7 +167,7 @@ module Ecoportal
|
|
163
167
|
if item = self[value]
|
164
168
|
item.replace_doc(item_doc)
|
165
169
|
else
|
166
|
-
_doc_upsert(item_doc, pos: pos, before: before, after: after)
|
170
|
+
pos_idx = _doc_upsert(item_doc, pos: pos, before: before, after: after)
|
167
171
|
end
|
168
172
|
(item || self[item_doc]).tap do |item|
|
169
173
|
yield(item) if block_given?
|
@@ -171,8 +175,12 @@ module Ecoportal
|
|
171
175
|
end
|
172
176
|
|
173
177
|
# Deletes `value` from this `CollectionModel` instance
|
178
|
+
# @param value [String, Hash, Ecoportal::API::Common::Content::DoubleModel]
|
179
|
+
# - When used as `String`, the `key` value (i.e. `id` value) is expected
|
180
|
+
# - When used as `Hash`, it should be the `doc` of the target element
|
181
|
+
# - When used as `DoubleModel`, it should be the specific object to be deleted
|
174
182
|
def delete!(value)
|
175
|
-
unless value.is_a?(Hash) || value.is_a?(Content::DoubleModel)
|
183
|
+
unless value.is_a?(Hash) || value.is_a?(Content::DoubleModel) || value.is_a?(String)
|
176
184
|
raise "'Content::DoubleModel' or 'Hash' doc required"
|
177
185
|
end
|
178
186
|
if item = self[value]
|
@@ -199,6 +207,8 @@ module Ecoportal
|
|
199
207
|
value[items_key]
|
200
208
|
when String
|
201
209
|
value
|
210
|
+
when Numeric
|
211
|
+
get_key(self.to_a[value])
|
202
212
|
end
|
203
213
|
end
|
204
214
|
|
@@ -250,18 +260,11 @@ module Ecoportal
|
|
250
260
|
end
|
251
261
|
|
252
262
|
def _doc_upsert(value, pos: NOT_USED, before: NOT_USED, after: NOT_USED)
|
253
|
-
current_pos =
|
254
|
-
|
255
|
-
|
256
|
-
pos
|
257
|
-
when used_param?(before)
|
258
|
-
_doc_key(before)
|
259
|
-
when used_param?(after)
|
260
|
-
if i = _doc_key(after)
|
261
|
-
i + 1
|
262
|
-
end
|
263
|
-
end
|
263
|
+
current_pos = if elem = self[value]
|
264
|
+
_doc_key(elem)
|
265
|
+
end
|
264
266
|
|
267
|
+
pos = scope_position(pos: pos, before: before, after: after)
|
265
268
|
pos ||= current_pos
|
266
269
|
|
267
270
|
if current_pos && pos
|
@@ -270,7 +273,6 @@ module Ecoportal
|
|
270
273
|
end
|
271
274
|
|
272
275
|
pos = (pos && pos < _doc_items.length)? pos : _doc_items.length
|
273
|
-
|
274
276
|
pos.tap do |i|
|
275
277
|
_doc_items.insert(pos, value)
|
276
278
|
on_change
|
@@ -278,6 +280,23 @@ module Ecoportal
|
|
278
280
|
|
279
281
|
end
|
280
282
|
|
283
|
+
def scope_position(pos: NOT_USED, before: NOT_USED, after: NOT_USED)
|
284
|
+
case
|
285
|
+
when used_param?(pos)
|
286
|
+
if elem = self[pos]
|
287
|
+
_doc_key(elem) - 1
|
288
|
+
end
|
289
|
+
when used_param?(before)
|
290
|
+
if elem = self[before]
|
291
|
+
_doc_key(elem) - 1
|
292
|
+
end
|
293
|
+
when used_param?(after)
|
294
|
+
if elem = self[after]
|
295
|
+
_doc_key(elem)
|
296
|
+
end
|
297
|
+
end
|
298
|
+
end
|
299
|
+
|
281
300
|
end
|
282
301
|
end
|
283
302
|
end
|
@@ -37,6 +37,8 @@ module Ecoportal
|
|
37
37
|
|
38
38
|
# Same as `attr_reader` but links to a subjacent `Hash` model property
|
39
39
|
# @note it does **not** create an _instance variable_
|
40
|
+
# @param methods [Array<Symbol>] the method that exposes the value
|
41
|
+
# as well as its `key` in the underlying `Hash` model.
|
40
42
|
def pass_reader(*methods)
|
41
43
|
methods.each do |method|
|
42
44
|
method = method.to_s.freeze
|
@@ -52,6 +54,8 @@ module Ecoportal
|
|
52
54
|
|
53
55
|
# Same as `attr_writer` but links to a subjacent `Hash` model property
|
54
56
|
# @note it does **not** create an _instance variable_
|
57
|
+
# @param methods [Array<Symbol>] the method that exposes the value
|
58
|
+
# as well as its `key` in the underlying `Hash` model.
|
55
59
|
def pass_writer(*methods)
|
56
60
|
methods.each do |method|
|
57
61
|
method = method.to_s.freeze
|
@@ -70,6 +74,8 @@ module Ecoportal
|
|
70
74
|
# no chance you can avoid invinite loop for `get_key` without setting an
|
71
75
|
# instance variable key at the moment of the object creation, when the
|
72
76
|
# `doc` is firstly received
|
77
|
+
# @param method [Symbol] the method that exposes the value
|
78
|
+
# as well as its `key` in the underlying `Hash` model.
|
73
79
|
def passkey(method)
|
74
80
|
method = method.to_s.freeze
|
75
81
|
var = instance_variable_name(method)
|
@@ -91,7 +97,33 @@ module Ecoportal
|
|
91
97
|
self
|
92
98
|
end
|
93
99
|
|
100
|
+
# These are methods that should always be present in patch update
|
101
|
+
# @note
|
102
|
+
# - `DoubleModel` can be used with objects that do not use `patch_ver`
|
103
|
+
# - This ensures that does that do, will get the correct patch update model
|
104
|
+
# @param method [Symbol] the method that exposes the value
|
105
|
+
# as well as its `key` in the underlying `Hash` model.
|
106
|
+
# @param default [Value] the default value that
|
107
|
+
# this `key` will be written in the model when it doesn't exixt
|
108
|
+
def passforced(method, default: , read_only: false)
|
109
|
+
model_forced_keys[method.to_s.freeze] = default
|
110
|
+
passthrough(method, read_only: read_only)
|
111
|
+
end
|
112
|
+
|
113
|
+
# Ensures `doc` has the `model_forced_keys`. If it doesn't, it adds those missing
|
114
|
+
# with the defined `default` values
|
115
|
+
def enforce!(doc)
|
116
|
+
return unless doc && doc.is_a?(Hash)
|
117
|
+
return if model_forced_keys.empty?
|
118
|
+
model_forced_keys.each do |key, default|
|
119
|
+
doc[key] = default unless doc.key?(key)
|
120
|
+
end
|
121
|
+
doc
|
122
|
+
end
|
123
|
+
|
94
124
|
# Same as `attr_accessor` but links to a subjacent `Hash` model property
|
125
|
+
# @param methods [Array<Symbol>] the method that exposes the value
|
126
|
+
# as well as its `key` in the underlying `Hash` model.
|
95
127
|
# @param read_only [Boolean] should it only define the reader?
|
96
128
|
def passthrough(*methods, read_only: false)
|
97
129
|
pass_reader *methods
|
@@ -101,6 +133,8 @@ module Ecoportal
|
|
101
133
|
|
102
134
|
# To link as a `Time` date to a subjacent `Hash` model property
|
103
135
|
# @see Ecoportal::API::Common::Content::DoubleModel#passthrough
|
136
|
+
# @param methods [Array<Symbol>] the method that exposes the value
|
137
|
+
# as well as its `key` in the underlying `Hash` model.
|
104
138
|
# @param read_only [Boolean] should it only define the reader?
|
105
139
|
def passdate(*methods, read_only: false)
|
106
140
|
pass_reader(*methods) {|value| to_time(value)}
|
@@ -111,6 +145,8 @@ module Ecoportal
|
|
111
145
|
end
|
112
146
|
|
113
147
|
# To link as a `Boolean` to a subjacent `Hash` model property
|
148
|
+
# @param methods [Array<Symbol>] the method that exposes the value
|
149
|
+
# as well as its `key` in the underlying `Hash` model.
|
114
150
|
# @param read_only [Boolean] should it only define the reader?
|
115
151
|
def passboolean(*methods, read_only: false)
|
116
152
|
pass_reader(*methods) {|value| value}
|
@@ -121,6 +157,8 @@ module Ecoportal
|
|
121
157
|
end
|
122
158
|
|
123
159
|
# To link as plain `Array` to a subjacent `Hash` model property
|
160
|
+
# @param methods [Array<Symbol>] the method that exposes the value
|
161
|
+
# as well as its `key` in the underlying `Hash` model.
|
124
162
|
# @param order_matters [Boolean] does the order matter
|
125
163
|
# @param uniq [Boolean] should it contain unique elements
|
126
164
|
def passarray(*methods, order_matters: true, uniq: true)
|
@@ -142,6 +180,10 @@ module Ecoportal
|
|
142
180
|
end
|
143
181
|
|
144
182
|
# Helper to embed one nested object under one property
|
183
|
+
# @param method [Symbol] the method that exposes the embeded object
|
184
|
+
# @param key [Symbol] the `key` that embeds it to the underlying `Hash` model
|
185
|
+
# @nullable [Boolean] to specify if this object can be `nil`
|
186
|
+
# @param klass [Class, String] the class of the embedded object
|
145
187
|
def embeds_one(method, key: method, nullable: false, klass:)
|
146
188
|
embed(method, key: key, nullable: nullable, multiple: false, klass: klass)
|
147
189
|
end
|
@@ -149,7 +191,11 @@ module Ecoportal
|
|
149
191
|
# @note
|
150
192
|
# - if you have a dedicated `Enumerable` class to manage `many`, you should use `:enum_class`
|
151
193
|
# - otherwise, just indicate the child class in `:klass` and it will auto generate the class
|
152
|
-
# @param
|
194
|
+
# @param method [Symbol] the method that exposes the embeded object
|
195
|
+
# @param key [Symbol] the `key` that embeds it to the underlying `Hash` model
|
196
|
+
# @param order_matters [Boolean] to state if the order will matter
|
197
|
+
# @param klass [Class, String] the class of the individual elements it embeds
|
198
|
+
# @param enum_class [Class, String] the class of the collection that will hold the individual elements
|
153
199
|
def embeds_many(method, key: method, order_matters: false, order_key: nil, klass: nil, enum_class: nil)
|
154
200
|
if enum_class
|
155
201
|
eclass = enum_class
|
@@ -186,8 +232,15 @@ module Ecoportal
|
|
186
232
|
end
|
187
233
|
end
|
188
234
|
|
235
|
+
# The list of keys that will be forced in the model
|
236
|
+
def model_forced_keys
|
237
|
+
@forced_model_keys ||= {}
|
238
|
+
end
|
239
|
+
|
189
240
|
end
|
190
241
|
|
242
|
+
inheritable_class_vars :forced_model_keys
|
243
|
+
|
191
244
|
attr_reader :_parent, :_key
|
192
245
|
|
193
246
|
def initialize(doc = {}, parent: self, key: nil)
|
@@ -195,6 +248,8 @@ module Ecoportal
|
|
195
248
|
@_parent = parent || self
|
196
249
|
@_key = key || self
|
197
250
|
|
251
|
+
self.class.enforce!(doc)
|
252
|
+
|
198
253
|
if _parent == self
|
199
254
|
@doc = doc
|
200
255
|
@original_doc = JSON.parse(@doc.to_json)
|
@@ -211,11 +266,13 @@ module Ecoportal
|
|
211
266
|
_parent.root
|
212
267
|
end
|
213
268
|
|
269
|
+
# @return [String] the `value` of the `key` method (i.e. `id` value)
|
214
270
|
def key
|
215
271
|
raise "No key_method defined for #{self.class}" unless key_method?
|
216
272
|
self.method(key_method).call
|
217
273
|
end
|
218
274
|
|
275
|
+
# @param [String] the `value` of the `key` method (i.e. `id` value)
|
219
276
|
def key=(value)
|
220
277
|
raise "No key_method defined for #{self.class}" unless key_method?
|
221
278
|
method = "#{key_method}="
|
@@ -234,16 +291,25 @@ module Ecoportal
|
|
234
291
|
end
|
235
292
|
end
|
236
293
|
|
294
|
+
# @return [nil, Hash] the underlying `Hash` model as is (carrying current changes)
|
237
295
|
def doc
|
238
296
|
raise UnlinkedModel.new(from: "#{self.class}#doc", key: _key) unless linked?
|
239
|
-
|
240
|
-
|
297
|
+
if is_root?
|
298
|
+
@doc
|
299
|
+
else
|
300
|
+
_parent.doc.dig(*[_doc_key(_key)].flatten)
|
301
|
+
end
|
241
302
|
end
|
242
303
|
|
304
|
+
# The `original_doc` holds the model as is now on server-side.
|
305
|
+
# @return [nil, Hash] the underlying `Hash` model as after last `consolidate!` changes
|
243
306
|
def original_doc
|
244
307
|
raise UnlinkedModel.new(from: "#{self.class}#original_doc", key: _key) unless linked?
|
245
|
-
|
246
|
-
|
308
|
+
if is_root?
|
309
|
+
@original_doc
|
310
|
+
else
|
311
|
+
_parent.original_doc.dig(*[_doc_key(_key)].flatten)
|
312
|
+
end
|
247
313
|
end
|
248
314
|
|
249
315
|
def as_json
|
@@ -254,19 +320,31 @@ module Ecoportal
|
|
254
320
|
doc.to_json(*args)
|
255
321
|
end
|
256
322
|
|
323
|
+
# @return [nil, Hash] the patch `Hash` model including only the changes between
|
324
|
+
# `original_doc` and `doc`
|
257
325
|
def as_update
|
258
326
|
new_doc = as_json
|
259
327
|
Common::Content::HashDiffPatch.patch_diff(new_doc, original_doc)
|
260
328
|
end
|
261
329
|
|
330
|
+
# @return [Boolean] stating if there are changes
|
262
331
|
def dirty?
|
263
332
|
as_update != {}
|
264
333
|
end
|
265
334
|
|
335
|
+
# It makes `original_doc` to be like `doc`
|
336
|
+
# @note
|
337
|
+
# - after executing it, there will be no pending changes
|
338
|
+
# - you should technically run this command, after a successful update request to the server
|
266
339
|
def consolidate!
|
267
340
|
replace_original_doc(JSON.parse(doc.to_json))
|
268
341
|
end
|
269
342
|
|
343
|
+
# It makes `doc` to be like `original`
|
344
|
+
# @note
|
345
|
+
# - after executing it, changes in `doc` will be lost
|
346
|
+
# - you should technically run this command only if you want to remove certain changes
|
347
|
+
# @key [Symbol] the specific part of the model you want to `reset`
|
270
348
|
def reset!(key = nil)
|
271
349
|
if key
|
272
350
|
keys = [key].flatten.compact
|
@@ -60,6 +60,8 @@ module Ecoportal
|
|
60
60
|
a == b
|
61
61
|
end
|
62
62
|
|
63
|
+
# Compares `a` as charring changes of `b`
|
64
|
+
# @return [Hash] patch data object with only changes
|
63
65
|
def patch_data(a, b = nil, delete: false)
|
64
66
|
{}.tap do |data_hash|
|
65
67
|
if delete
|
@@ -75,11 +77,17 @@ module Ecoportal
|
|
75
77
|
data_hash[key] = patch_diff(a_value, b_value)
|
76
78
|
data_hash.delete(key) if data_hash[key] == NO_CHANGES
|
77
79
|
end
|
80
|
+
#if (data_hash.keys - ID_KEYS).empty?
|
78
81
|
if (data_hash.keys - META_KEYS).empty?
|
79
82
|
return NO_CHANGES
|
80
83
|
else
|
81
|
-
patch_ver = (b && b["patch_ver"]) || 1
|
82
|
-
data_hash["patch_ver"] = patch_ver
|
84
|
+
#patch_ver = (b && b["patch_ver"]) || 1
|
85
|
+
#data_hash["patch_ver"] = patch_ver
|
86
|
+
if b && b.key?("patch_ver")
|
87
|
+
data_hash["patch_ver"] = b["patch_ver"]
|
88
|
+
elsif a && a.key?("patch_ver")
|
89
|
+
data_hash["patch_ver"] = a["patch_ver"]
|
90
|
+
end
|
83
91
|
end
|
84
92
|
end
|
85
93
|
end
|
@@ -172,7 +180,9 @@ module Ecoportal
|
|
172
180
|
arr.any? {|a| nested_array?(a)}
|
173
181
|
when arr.length == 1
|
174
182
|
arr = arr.first
|
175
|
-
arr.any?
|
183
|
+
arr.any? do |item|
|
184
|
+
item.is_a?(Hash) && item.has_key?("patch_ver")
|
185
|
+
end
|
176
186
|
else
|
177
187
|
false
|
178
188
|
end
|
@@ -2,9 +2,19 @@ module Ecoportal
|
|
2
2
|
module API
|
3
3
|
class V2
|
4
4
|
class Page < Common::Content::DoubleModel
|
5
|
-
ALLOWED_KEYS =
|
5
|
+
ALLOWED_KEYS = [
|
6
|
+
"id", "patch_ver", "name", "template_id",
|
7
|
+
"base_tags", "tags",
|
8
|
+
"time_zone", "created_at", "updated_at",
|
9
|
+
"components", "sections", "stages",
|
10
|
+
"permits", "mould_counter", "mould",
|
11
|
+
"state", "task_priority",
|
12
|
+
"votes_enabled", "upvotes", "downvotes",
|
13
|
+
"force_errors", "subtags"
|
14
|
+
]
|
15
|
+
|
6
16
|
passkey :id
|
7
|
-
|
17
|
+
passforced :patch_ver, default: 1
|
8
18
|
passthrough :name, :template_id
|
9
19
|
passarray :base_tags, :tags, order_matters: false
|
10
20
|
passthrough :time_zone
|
@@ -25,6 +35,7 @@ module Ecoportal
|
|
25
35
|
hash["data"].select! do |key, value|
|
26
36
|
ALLOWED_KEYS.include?(key)
|
27
37
|
end
|
38
|
+
return nil if (hash["data"].keys - ["patch_ver"]).empty?
|
28
39
|
end
|
29
40
|
end
|
30
41
|
end
|
@@ -26,13 +26,16 @@ module Ecoportal
|
|
26
26
|
|
27
27
|
class << self
|
28
28
|
def new_doc(type: nil)
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
29
|
+
{
|
30
|
+
"id" => new_uuid
|
31
|
+
}.tap do |base_doc|
|
32
|
+
if type
|
33
|
+
base_doc.merge!({"type" => type})
|
34
|
+
if klass = get_class(base_doc)
|
35
|
+
base_doc.merge!(klass.new_doc || {})
|
36
|
+
end
|
37
|
+
end
|
33
38
|
end
|
34
|
-
return base_doc if base_doc&.key?("id")
|
35
|
-
(base_doc || {}).merge("id" => new_uuid)
|
36
39
|
end
|
37
40
|
|
38
41
|
def get_class(doc)
|
@@ -82,7 +85,8 @@ module Ecoportal
|
|
82
85
|
end
|
83
86
|
|
84
87
|
passkey :id
|
85
|
-
|
88
|
+
passforced :patch_ver, default: 1
|
89
|
+
passboolean :undeletable
|
86
90
|
passthrough :type, :label, :tooltip, :global_binding
|
87
91
|
passboolean :hidden, :deindex, :required
|
88
92
|
passthrough :accent
|
@@ -7,14 +7,15 @@ module Ecoportal
|
|
7
7
|
class << self
|
8
8
|
def new_doc
|
9
9
|
{
|
10
|
-
"id"
|
11
|
-
"weight"
|
10
|
+
"id" => new_uuid,
|
11
|
+
"weight" => 9999
|
12
12
|
}
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
16
|
passkey :id
|
17
|
-
|
17
|
+
passforced :patch_ver, default: 1
|
18
|
+
passthrough :name
|
18
19
|
passthrough :weight, :other_information
|
19
20
|
passboolean :complete
|
20
21
|
|
@@ -8,14 +8,15 @@ module Ecoportal
|
|
8
8
|
class << self
|
9
9
|
def new_doc
|
10
10
|
{
|
11
|
-
"id"
|
12
|
-
"weight"
|
11
|
+
"id" => new_uuid,
|
12
|
+
"weight" => 9999
|
13
13
|
}
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
17
|
passkey :id
|
18
|
-
|
18
|
+
passforced :patch_ver, default: 1
|
19
|
+
passthrough :label
|
19
20
|
passthrough :weight
|
20
21
|
passboolean :checked
|
21
22
|
end
|
@@ -4,10 +4,20 @@ 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
|
-
|
9
|
-
passthrough :
|
10
|
-
passthrough :content_type, :
|
17
|
+
passforced :patch_ver, default: 1
|
18
|
+
passthrough :position
|
19
|
+
passthrough :file_size, :content_type, :token, read_only: true
|
20
|
+
passthrough :file_container_id
|
11
21
|
passdate :file_update_at, read_only: true
|
12
22
|
end
|
13
23
|
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'
|
@@ -8,16 +8,16 @@ module Ecoportal
|
|
8
8
|
class << self
|
9
9
|
def new_doc
|
10
10
|
{
|
11
|
-
"id"
|
12
|
-
"threshold"
|
13
|
-
"color"
|
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
|
-
|
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:
|
@@ -5,7 +5,8 @@ module Ecoportal
|
|
5
5
|
class Component
|
6
6
|
class Image < Common::Content::DoubleModel
|
7
7
|
passkey :id
|
8
|
-
|
8
|
+
passforced :patch_ver, default: 1
|
9
|
+
passthrough :weight
|
9
10
|
passthrough :height, :width, :caption
|
10
11
|
passthrough :dimensions, :styles
|
11
12
|
end
|
@@ -7,7 +7,7 @@ module Ecoportal
|
|
7
7
|
passboolean :is_me_button
|
8
8
|
passthrough :attach_mode
|
9
9
|
passthrough :person_schema_id
|
10
|
-
|
10
|
+
embeds_many :viewable_fields, klass: "Ecoportal::API::V2::Page::Component::PeopleViewableField"
|
11
11
|
|
12
12
|
passboolean :singular
|
13
13
|
passthrough :requires_number
|
@@ -30,6 +30,16 @@ module Ecoportal
|
|
30
30
|
people_ids.reject! {|id| ids.include?(id)}
|
31
31
|
end
|
32
32
|
|
33
|
+
# Adds a field to the `viewable_fields`
|
34
|
+
def add_viewable(field_id, pos: NOT_USED, before: NOT_USED, after: NOT_USED)
|
35
|
+
viewable_fields.upsert!({"id" => field_id}, pos: pos, before: before, after: after)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Deletes a field from the `viewable_fields`
|
39
|
+
def delete_viewable(field_id)
|
40
|
+
viewable_fields.delete!(field_id)
|
41
|
+
end
|
42
|
+
|
33
43
|
# Quick config helper
|
34
44
|
# @param conf [Symbol, Array<Symbol>]
|
35
45
|
# - `:snapshot` to set mode to `snapshot`
|
@@ -64,7 +74,7 @@ module Ecoportal
|
|
64
74
|
unless (rest = hash_except(cnf.dup, *supported)).empty?
|
65
75
|
unused.push(rest)
|
66
76
|
end
|
67
|
-
|
77
|
+
|
68
78
|
if cnf.key?(:singular) then self.singular = !!cnf[:singular] end
|
69
79
|
if cnf.key?(:permits)
|
70
80
|
if permits = cnf[:permits]
|
@@ -121,3 +131,5 @@ module Ecoportal
|
|
121
131
|
end
|
122
132
|
end
|
123
133
|
end
|
134
|
+
|
135
|
+
require 'ecoportal/api/v2/page/component/people_viewable_field'
|
@@ -8,14 +8,15 @@ module Ecoportal
|
|
8
8
|
class << self
|
9
9
|
def new_doc
|
10
10
|
{
|
11
|
-
"id"
|
12
|
-
"weight"
|
11
|
+
"id" => new_uuid,
|
12
|
+
"weight" => 9999
|
13
13
|
}
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
17
|
passkey :id
|
18
|
-
|
18
|
+
passforced :patch_ver, default: 1
|
19
|
+
passthrough :name, :value
|
19
20
|
passthrough :weight
|
20
21
|
passboolean :selected
|
21
22
|
|
@@ -13,8 +13,9 @@ module Ecoportal
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
passthrough :signed_by_id, :signed_by_name, :
|
17
|
-
|
16
|
+
passthrough :signed_by_id, :signed_by_name, read_only: true
|
17
|
+
passthrough :signature_url, read_only: true
|
18
|
+
passdate :signature_updated_at, read_only: true
|
18
19
|
passthrough :signature_content, :color
|
19
20
|
|
20
21
|
end
|
@@ -4,9 +4,10 @@ module Ecoportal
|
|
4
4
|
class Page
|
5
5
|
class Permit < Common::Content::DoubleModel
|
6
6
|
passkey :id
|
7
|
-
|
7
|
+
passforced :patch_ver, default: 1
|
8
8
|
passthrough :user_id, :user_name
|
9
9
|
passthrough :editable, :flags
|
10
|
+
embeds_one :flags, klass: "Ecoportal::API::V2::Page::PermissionFlags"
|
10
11
|
end
|
11
12
|
end
|
12
13
|
end
|
@@ -6,9 +6,9 @@ module Ecoportal
|
|
6
6
|
class << self
|
7
7
|
def new_doc(split: false)
|
8
8
|
{
|
9
|
-
"id"
|
10
|
-
"type"
|
11
|
-
"weight"
|
9
|
+
"id" => new_uuid,
|
10
|
+
"type" => split ? "split" : "content",
|
11
|
+
"weight" => 800
|
12
12
|
}.tap do |out|
|
13
13
|
component_ids = if split
|
14
14
|
{
|
@@ -26,10 +26,11 @@ module Ecoportal
|
|
26
26
|
end
|
27
27
|
|
28
28
|
passkey :id
|
29
|
-
|
29
|
+
passforced :patch_ver, default: 1
|
30
|
+
passthrough :weight, :type
|
30
31
|
passthrough :heading, :left_heading, :right_heading
|
31
32
|
passarray :component_ids, :left_component_ids, :right_component_ids
|
32
|
-
|
33
|
+
passboolean :minimized
|
33
34
|
|
34
35
|
def split?
|
35
36
|
doc && doc["type"] == "split"
|
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.
|
4
|
+
version: 0.8.10
|
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-
|
11
|
+
date: 2021-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -209,6 +209,7 @@ files:
|
|
209
209
|
- lib/ecoportal/api/v2/page/component/law_field.rb
|
210
210
|
- lib/ecoportal/api/v2/page/component/number_field.rb
|
211
211
|
- lib/ecoportal/api/v2/page/component/people_field.rb
|
212
|
+
- lib/ecoportal/api/v2/page/component/people_viewable_field.rb
|
212
213
|
- lib/ecoportal/api/v2/page/component/plain_text_field.rb
|
213
214
|
- lib/ecoportal/api/v2/page/component/reference_field.rb
|
214
215
|
- lib/ecoportal/api/v2/page/component/rich_text_field.rb
|