ecoportal-api-v2 1.1.7 → 1.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +54 -15
- data/CHANGELOG.md +6 -3
- data/lib/ecoportal/api/common/content/array_model.rb +81 -78
- data/lib/ecoportal/api/common/content/class_helpers.rb +25 -26
- data/lib/ecoportal/api/common/content/collection_model.rb +76 -64
- data/lib/ecoportal/api/common/content/double_model.rb +105 -87
- data/lib/ecoportal/api/v2/page/component.rb +60 -64
- data/lib/ecoportal/api/v2/page/components.rb +9 -9
- data/lib/ecoportal/api/v2/page/force.rb +5 -6
- data/lib/ecoportal/api/v2/page.rb +13 -14
- data/lib/ecoportal/api/v2_version.rb +1 -1
- metadata +2 -2
@@ -30,65 +30,64 @@ module Ecoportal
|
|
30
30
|
class << self
|
31
31
|
def new_doc(type: nil)
|
32
32
|
{
|
33
|
-
"id"
|
33
|
+
"id" => new_uuid
|
34
34
|
}.tap do |base_doc|
|
35
35
|
if type
|
36
36
|
base_doc.merge!({"type" => type})
|
37
|
-
if klass = get_class(base_doc)
|
37
|
+
if (klass = get_class(base_doc))
|
38
38
|
base_doc.merge!(klass.new_doc || {})
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
-
def get_class(doc)
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
end
|
44
|
+
def get_class(doc) # rubocop:disable Metrics/AbcSize
|
45
|
+
return nil unless doc.is_a?(Hash)
|
46
|
+
case doc["type"]
|
47
|
+
when "tag_field"
|
48
|
+
tag_field_class
|
49
|
+
when "geo"
|
50
|
+
geo_field_class
|
51
|
+
when "select"
|
52
|
+
selection_field_class
|
53
|
+
when "date"
|
54
|
+
date_field_class
|
55
|
+
when "number"
|
56
|
+
number_field_class
|
57
|
+
when "gauge"
|
58
|
+
gauge_field_class
|
59
|
+
when "plain_text"
|
60
|
+
plain_text_field_class
|
61
|
+
when "rich_text"
|
62
|
+
rich_text_field_class
|
63
|
+
when "people"
|
64
|
+
people_field_class
|
65
|
+
when "contractor_entities"
|
66
|
+
contractor_entities_field_class
|
67
|
+
when "checklist"
|
68
|
+
checklist_field_class
|
69
|
+
when "page_action", "checklist_task"
|
70
|
+
action_field_class
|
71
|
+
when "actions_list"
|
72
|
+
actions_field_class
|
73
|
+
when "file"
|
74
|
+
files_field_class
|
75
|
+
when "image_gallery"
|
76
|
+
images_field_class
|
77
|
+
when "signature"
|
78
|
+
signature_field_class
|
79
|
+
when "cross_reference"
|
80
|
+
reference_field_class
|
81
|
+
when "law"
|
82
|
+
law_field_class
|
83
|
+
when "mailbox"
|
84
|
+
mailbox_field_class
|
85
|
+
when "chart"
|
86
|
+
chart_field_class
|
87
|
+
when "frequency_rate_chart"
|
88
|
+
chart_fr_field_class
|
89
|
+
else
|
90
|
+
self
|
92
91
|
end
|
93
92
|
end
|
94
93
|
end
|
@@ -103,7 +102,7 @@ module Ecoportal
|
|
103
102
|
passarray :refs
|
104
103
|
|
105
104
|
def ooze
|
106
|
-
|
105
|
+
_parent.ooze
|
107
106
|
end
|
108
107
|
|
109
108
|
def ref_backend
|
@@ -111,9 +110,9 @@ module Ecoportal
|
|
111
110
|
end
|
112
111
|
|
113
112
|
def ref(any_length: false)
|
114
|
-
|
115
|
-
|
116
|
-
|
113
|
+
digest = self.class.hash_label(label, any_length: any_length)
|
114
|
+
return unless digest
|
115
|
+
[type, digest].join(".")
|
117
116
|
end
|
118
117
|
|
119
118
|
# Looks up the section that this component belongs to.
|
@@ -159,7 +158,7 @@ module Ecoportal
|
|
159
158
|
|
160
159
|
# @return [Boolean] `true` if the component is bound to any force, `false` otherwise
|
161
160
|
def bindings?
|
162
|
-
forces.count
|
161
|
+
forces.count&.positive?
|
163
162
|
end
|
164
163
|
|
165
164
|
# If the field has bindings they are replaced by this new field
|
@@ -168,10 +167,10 @@ module Ecoportal
|
|
168
167
|
if fld.section
|
169
168
|
fld.move(section: self.section, before: self)
|
170
169
|
else
|
171
|
-
|
170
|
+
section.add(fld, before: self)
|
172
171
|
end
|
173
172
|
replace_bindings(fld)
|
174
|
-
|
173
|
+
delete!
|
175
174
|
end
|
176
175
|
|
177
176
|
def replace_bindings(fld)
|
@@ -180,12 +179,12 @@ module Ecoportal
|
|
180
179
|
|
181
180
|
def delete!
|
182
181
|
bindings.each {|b| b.delete!}
|
183
|
-
|
184
|
-
|
182
|
+
unattach!
|
183
|
+
_parent.delete!(self)
|
185
184
|
end
|
186
185
|
|
187
186
|
def move(section:, before: nil, after: nil, side: nil)
|
188
|
-
|
187
|
+
unattach!
|
189
188
|
section.add_component(self, before: before, after: after, side: side)
|
190
189
|
end
|
191
190
|
|
@@ -212,9 +211,7 @@ module Ecoportal
|
|
212
211
|
when :hide_reports
|
213
212
|
self.hidden_on_reports = true
|
214
213
|
when Hash
|
215
|
-
if cnf.key?(:global)
|
216
|
-
self.global_binding = cnf[:global]
|
217
|
-
end
|
214
|
+
self.global_binding = cnf[:global] if cnf.key?(:global)
|
218
215
|
else
|
219
216
|
unused.push(cnf)
|
220
217
|
end
|
@@ -222,7 +219,6 @@ module Ecoportal
|
|
222
219
|
raise "Unsupported configuration options '#{unused}' for #{self.class}" unless unused.empty?
|
223
220
|
end
|
224
221
|
end
|
225
|
-
|
226
222
|
end
|
227
223
|
end
|
228
224
|
end
|
@@ -5,28 +5,28 @@ module Ecoportal
|
|
5
5
|
class Components < Common::Content::CollectionModel
|
6
6
|
class_resolver :component_class, "Ecoportal::API::V2::Page::Component"
|
7
7
|
|
8
|
-
|
8
|
+
klass do |doc|
|
9
9
|
component_class.get_class(doc).tap do |klass|
|
10
10
|
klass.key = :id
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
order_matters = true
|
14
|
+
#self.order_matters = true
|
15
15
|
|
16
16
|
def ooze
|
17
|
-
|
17
|
+
_parent.ooze
|
18
18
|
end
|
19
19
|
|
20
20
|
# @return [Ecoportal::API::V2::Page::Component] the field with `id`
|
21
21
|
def get_by_id(id)
|
22
|
-
|
22
|
+
find do |comp|
|
23
23
|
comp.id == id
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
27
|
# @return [Array<Ecoportal::API::V2::Page::Component>] the fields of that `type`
|
28
28
|
def get_by_type(type)
|
29
|
-
|
29
|
+
select do |comp|
|
30
30
|
comp.type.downcase == type.to_s.strip.downcase
|
31
31
|
end
|
32
32
|
end
|
@@ -53,19 +53,19 @@ module Ecoportal
|
|
53
53
|
def add(doc: nil, label: doc && doc["label"], type: doc && doc["type"])
|
54
54
|
fld_doc = doc ? JSON.parse(doc.to_json) : component_class.new_doc(type: type)
|
55
55
|
upsert!(fld_doc) do |fld|
|
56
|
-
fld.label
|
57
|
-
yield(fld)
|
56
|
+
fld.label = label unless doc
|
57
|
+
yield(fld) if block_given?
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
61
|
# @return [Array<Ecoportal::API::V2::Page::Component>] **orphaned** fields (with no section).
|
62
62
|
def unattached
|
63
|
-
|
63
|
+
reject(&:attached?)
|
64
64
|
end
|
65
65
|
|
66
66
|
# @return [Array<Ecoportal::API::V2::Page::Component>] fields belonging to more than one section.
|
67
67
|
def multi_section
|
68
|
-
select
|
68
|
+
select(&:multi_section?)
|
69
69
|
end
|
70
70
|
end
|
71
71
|
end
|
@@ -8,8 +8,8 @@ module Ecoportal
|
|
8
8
|
class << self
|
9
9
|
def new_doc
|
10
10
|
{
|
11
|
-
"id"
|
12
|
-
"weight"
|
11
|
+
"id" => new_uuid,
|
12
|
+
"weight" => INITIAL_WEIGHT
|
13
13
|
}
|
14
14
|
end
|
15
15
|
end
|
@@ -23,11 +23,11 @@ module Ecoportal
|
|
23
23
|
passdate :last_synced_at
|
24
24
|
passthrough :custom_script
|
25
25
|
passthrough :script, read_only: true
|
26
|
-
embeds_many :bindings,
|
27
|
-
embeds_many :helpers,
|
26
|
+
embeds_many :bindings, enum_class: :bindings_class
|
27
|
+
embeds_many :helpers, klass: :helper_class
|
28
28
|
|
29
29
|
def ooze
|
30
|
-
|
30
|
+
_parent.ooze
|
31
31
|
end
|
32
32
|
|
33
33
|
# @see Ecoportal::API::V2::Page::Force::Bindings#add
|
@@ -39,7 +39,6 @@ module Ecoportal
|
|
39
39
|
def custom_script=(value)
|
40
40
|
doc["custom_script"] = value
|
41
41
|
update_script
|
42
|
-
value
|
43
42
|
end
|
44
43
|
|
45
44
|
# It sets the `script` value by using `custom_script` and `helpers[N..1].script`
|
@@ -2,16 +2,16 @@ module Ecoportal
|
|
2
2
|
module API
|
3
3
|
class V2
|
4
4
|
class Page < Common::Content::DoubleModel
|
5
|
-
ALLOWED_KEYS
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
]
|
5
|
+
ALLOWED_KEYS = %w[
|
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
|
+
forces force_errors subtags
|
14
|
+
].freeze
|
15
15
|
|
16
16
|
passkey :id
|
17
17
|
passforced :patch_ver, default: 1
|
@@ -41,7 +41,7 @@ module Ecoportal
|
|
41
41
|
|
42
42
|
def as_update
|
43
43
|
super.tap do |hash|
|
44
|
-
|
44
|
+
if hash
|
45
45
|
hash["data"].select! do |key, value|
|
46
46
|
ALLOWED_KEYS.include?(key)
|
47
47
|
end
|
@@ -51,14 +51,14 @@ module Ecoportal
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def stages?
|
54
|
-
|
54
|
+
doc["stages"] && stages.count.positive?
|
55
55
|
end
|
56
56
|
|
57
57
|
# @return [String] with feedback, if for this page instance, there are any of:
|
58
58
|
# 1. components multi-section (fields belonging to more than one section)
|
59
59
|
def validate
|
60
60
|
msg = ""
|
61
|
-
if (multi = components.multi_section).length
|
61
|
+
if (multi = components.multi_section).length.positive?
|
62
62
|
msg += "There are fields attached to more than one section:\n • "
|
63
63
|
msg += multi.map do |fld|
|
64
64
|
fld.label
|
@@ -96,7 +96,6 @@ module Ecoportal
|
|
96
96
|
end
|
97
97
|
end
|
98
98
|
end
|
99
|
-
|
100
99
|
end
|
101
100
|
end
|
102
101
|
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: 1.1.
|
4
|
+
version: 1.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oscar Segura
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-03-
|
11
|
+
date: 2024-03-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|