ecoportal-api-v2 2.0.16 → 3.1.1
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +24 -1
- data/ecoportal-api-v2.gemspec +1 -1
- data/lib/ecoportal/api/common/concerns.rb +2 -2
- data/lib/ecoportal/api/common/content/class_helpers.rb +42 -7
- data/lib/ecoportal/api/common/content/client.rb +2 -1
- data/lib/ecoportal/api/common/content/collection_model/doc/rooted_key.rb +8 -8
- data/lib/ecoportal/api/common/content/collection_model/doc.rb +2 -2
- data/lib/ecoportal/api/common/content/collection_model/doc_mutation.rb +3 -3
- data/lib/ecoportal/api/common/content/collection_model/model.rb +6 -6
- data/lib/ecoportal/api/common/content/collection_model/modifiers.rb +3 -3
- data/lib/ecoportal/api/common/content/collection_model/mutation.rb +3 -3
- data/lib/ecoportal/api/common/content/collection_model.rb +5 -5
- data/lib/ecoportal/api/common/content/double_model/attributable/nesting/cascaded_callback.rb +203 -98
- data/lib/ecoportal/api/common/content/double_model/attributable/nesting/embeddable.rb +49 -59
- data/lib/ecoportal/api/common/content/double_model/attributable/nesting/keyable.rb +102 -114
- data/lib/ecoportal/api/common/content/double_model/attributable/nesting.rb +5 -3
- data/lib/ecoportal/api/common/content/double_model/attributable.rb +5 -5
- data/lib/ecoportal/api/common/content/double_model/diffable/diff_service.rb +33 -0
- data/lib/ecoportal/api/common/content/double_model/{diffable_model.rb → diffable.rb} +12 -5
- data/lib/ecoportal/api/common/content/double_model/double_doc/linkable_doc.rb +9 -4
- data/lib/ecoportal/api/common/content/double_model/double_doc/replaceable_doc.rb +10 -2
- data/lib/ecoportal/api/common/content/double_model/double_doc/reset_consolidate.rb +1 -1
- data/lib/ecoportal/api/common/content/double_model/double_doc/rooted_key.rb +10 -3
- data/lib/ecoportal/api/common/content/double_model/double_doc.rb +5 -5
- data/lib/ecoportal/api/common/content/double_model/hash_helpers.rb +23 -4
- data/lib/ecoportal/api/common/content/double_model/modifiers.rb +2 -2
- data/lib/ecoportal/api/common/content/double_model.rb +9 -9
- data/lib/ecoportal/api/common/content/hash_diff_patch.rb +21 -7
- data/lib/ecoportal/api/common/content/model_helpers.rb +1 -1
- data/lib/ecoportal/api/common/content.rb +11 -11
- data/lib/ecoportal/api/common.v2.rb +2 -2
- data/lib/ecoportal/api/v2/page/component/action.rb +13 -11
- data/lib/ecoportal/api/v2/page/component/action_field.rb +14 -12
- data/lib/ecoportal/api/v2/page/component/actions_field.rb +2 -1
- data/lib/ecoportal/api/v2/page/component/chart_field/config.rb +1 -2
- data/lib/ecoportal/api/v2/page/component/chart_field.rb +48 -44
- data/lib/ecoportal/api/v2/page/component/chart_fr_field.rb +0 -1
- data/lib/ecoportal/api/v2/page/component/checklist_field.rb +9 -6
- data/lib/ecoportal/api/v2/page/component/checklist_item.rb +2 -3
- data/lib/ecoportal/api/v2/page/component/contractor_entities_field.rb +18 -17
- data/lib/ecoportal/api/v2/page/component/date_field.rb +19 -18
- data/lib/ecoportal/api/v2/page/component/file.rb +3 -3
- data/lib/ecoportal/api/v2/page/component/files_field.rb +9 -6
- data/lib/ecoportal/api/v2/page/component/gauge_field.rb +3 -2
- data/lib/ecoportal/api/v2/page/component/gauge_stop.rb +26 -26
- data/lib/ecoportal/api/v2/page/component/geo_field.rb +2 -2
- data/lib/ecoportal/api/v2/page/component/image.rb +6 -5
- data/lib/ecoportal/api/v2/page/component/images_field.rb +21 -20
- data/lib/ecoportal/api/v2/page/component/law.rb +3 -4
- data/lib/ecoportal/api/v2/page/component/law_field.rb +2 -2
- data/lib/ecoportal/api/v2/page/component/number_field.rb +1 -1
- data/lib/ecoportal/api/v2/page/component/people_field.rb +19 -19
- data/lib/ecoportal/api/v2/page/component/plain_text_field.rb +6 -7
- data/lib/ecoportal/api/v2/page/component/reference_field.rb +1 -1
- data/lib/ecoportal/api/v2/page/component/rich_text_field.rb +3 -3
- data/lib/ecoportal/api/v2/page/component/selection_field.rb +32 -35
- data/lib/ecoportal/api/v2/page/component/selection_options.rb +12 -7
- data/lib/ecoportal/api/v2/page/component/tag_field.rb +5 -4
- data/lib/ecoportal/api/v2/page/component.rb +21 -21
- data/lib/ecoportal/api/v2/page/force/bindings.rb +49 -39
- data/lib/ecoportal/api/v2/page/force.rb +9 -9
- data/lib/ecoportal/api/v2/page/forces.rb +1 -1
- data/lib/ecoportal/api/v2/page/permit.rb +3 -3
- data/lib/ecoportal/api/v2/page/sections.rb +19 -14
- data/lib/ecoportal/api/v2/page/stage.rb +27 -20
- data/lib/ecoportal/api/v2/page/stages.rb +1 -1
- data/lib/ecoportal/api/v2/page.rb +13 -12
- data/lib/ecoportal/api/v2/pages/page_stage.rb +2 -2
- data/lib/ecoportal/api/v2/pages.rb +2 -2
- data/lib/ecoportal/api/v2/registers/page_result.rb +3 -3
- data/lib/ecoportal/api/v2/registers/register.rb +4 -5
- data/lib/ecoportal/api/v2/registers/search_results.rb +1 -1
- data/lib/ecoportal/api/v2/registers/stages_result.rb +1 -1
- data/lib/ecoportal/api/v2/registers.rb +6 -6
- data/lib/ecoportal/api/v2/s3/files/batch_upload.rb +1 -0
- data/lib/ecoportal/api/v2/s3/files.rb +3 -3
- data/lib/ecoportal/api/v2.rb +4 -4
- data/lib/ecoportal/api/v2_version.rb +1 -1
- data/lib/ecoportal/api-v2.rb +4 -5
- metadata +6 -5
@@ -7,28 +7,28 @@ module Ecoportal
|
|
7
7
|
passboolean :multiple, :flat, :other
|
8
8
|
passthrough :other_desc
|
9
9
|
passthrough :data_type
|
10
|
-
embeds_many :options, enum_class:
|
10
|
+
embeds_many :options, enum_class: 'Ecoportal::API::V2::Page::Component::SelectionOptions'
|
11
11
|
|
12
12
|
def empty?
|
13
13
|
values.empty?
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
def numeric?
|
17
|
-
|
17
|
+
data_type == 'num'
|
18
18
|
end
|
19
19
|
|
20
20
|
def text?
|
21
|
-
|
21
|
+
data_type == 'txt'
|
22
22
|
end
|
23
23
|
|
24
24
|
def numeric!(&block)
|
25
25
|
options.ordered.each {|opt| opt.numeric!(&block)}
|
26
|
-
self.data_type =
|
26
|
+
self.data_type = 'num'
|
27
27
|
end
|
28
28
|
|
29
29
|
def text!(&block)
|
30
30
|
options.ordered.each {|opt| opt.text!(&block)}
|
31
|
-
self.data_type =
|
31
|
+
self.data_type = 'str'
|
32
32
|
end
|
33
33
|
|
34
34
|
def switch_type!(&block)
|
@@ -39,40 +39,38 @@ module Ecoportal
|
|
39
39
|
opt = options.find_option(value_name, by_name: by_name)
|
40
40
|
sel = selected
|
41
41
|
return true if !multiple && opt == sel
|
42
|
+
|
42
43
|
sel.selected = false if !multiple && sel
|
43
|
-
opt.selected = true
|
44
|
+
opt.selected = true if opt
|
44
45
|
end
|
45
46
|
|
46
47
|
def deselect(value_name, by_name: false)
|
47
|
-
|
48
|
-
|
49
|
-
|
48
|
+
return unless (opt = options.find_option(value_name, by_name: by_name))
|
49
|
+
|
50
|
+
opt.selected = false
|
50
51
|
end
|
51
52
|
|
52
53
|
def selected(by_name: false, by_value: false, value: false, name: false)
|
53
|
-
|
54
|
-
when by_value
|
54
|
+
if by_value
|
55
55
|
elems = [selected].flatten.compact
|
56
56
|
options.hash(elems) do |option|
|
57
57
|
name ? option.name : option
|
58
58
|
end
|
59
|
-
|
59
|
+
elsif by_name
|
60
60
|
elems = [selected].flatten.compact
|
61
61
|
options.hash(elems, by_name: true) do |option|
|
62
62
|
value ? option.value : option
|
63
63
|
end
|
64
|
+
elsif multiple
|
65
|
+
options.ordered.select(&:selected)
|
64
66
|
else
|
65
|
-
|
66
|
-
options.ordered.select {|opt| opt.selected}
|
67
|
-
else
|
68
|
-
options.find {|opt| opt.selected}
|
69
|
-
end
|
67
|
+
options.find(&:selected)
|
70
68
|
end
|
71
69
|
end
|
72
70
|
|
73
71
|
def value
|
74
72
|
if multiple
|
75
|
-
selected.map
|
73
|
+
selected.map(&:value)
|
76
74
|
else
|
77
75
|
selected&.value
|
78
76
|
end
|
@@ -84,7 +82,7 @@ module Ecoportal
|
|
84
82
|
|
85
83
|
def name
|
86
84
|
if multiple
|
87
|
-
selected.map
|
85
|
+
selected.map(&:name)
|
88
86
|
else
|
89
87
|
selected&.name
|
90
88
|
end
|
@@ -133,7 +131,7 @@ module Ecoportal
|
|
133
131
|
conf.each_with_object([]) do |cnf, unused|
|
134
132
|
case cnf
|
135
133
|
when :flat
|
136
|
-
self.flat
|
134
|
+
self.flat = true
|
137
135
|
when :multiple
|
138
136
|
self.multiple = true
|
139
137
|
when :single
|
@@ -141,30 +139,28 @@ module Ecoportal
|
|
141
139
|
when :other
|
142
140
|
self.other = true
|
143
141
|
when Hash
|
144
|
-
supported = [
|
145
|
-
unless (rest = hash_except(cnf.dup, *supported)).empty?
|
142
|
+
supported = %i[flat options type]
|
143
|
+
unless (rest = hash_except!(cnf.dup, *supported)).empty?
|
146
144
|
unused.push(rest)
|
147
145
|
end
|
148
146
|
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
end
|
147
|
+
self.flat = cnf[:flat] if cnf.key?(:flat)
|
148
|
+
|
149
|
+
if cnf.key?(:options) && (opts = cnf[:options])
|
150
|
+
configure_options opts
|
154
151
|
end
|
152
|
+
|
155
153
|
if cnf.key?(:type)
|
156
154
|
if cnf[:type] == :str
|
157
|
-
|
155
|
+
text!
|
158
156
|
elsif cnf[:type] == :num
|
159
|
-
|
160
|
-
else
|
161
|
-
# Unknown type
|
157
|
+
numeric!
|
162
158
|
end
|
163
159
|
end
|
164
160
|
else
|
165
161
|
unused.push(cnf)
|
166
162
|
end
|
167
|
-
end.
|
163
|
+
end.then do |unused|
|
168
164
|
super(*unused)
|
169
165
|
end
|
170
166
|
end
|
@@ -172,9 +168,10 @@ module Ecoportal
|
|
172
168
|
private
|
173
169
|
|
174
170
|
def configure_options(opts)
|
175
|
-
hopts =
|
171
|
+
hopts = options_by_value
|
172
|
+
|
176
173
|
opts.each do |val, nm|
|
177
|
-
if option = hopts[val]
|
174
|
+
if (option = hopts[val])
|
178
175
|
option.name = nm
|
179
176
|
else
|
180
177
|
add_option(value: val, name: nm)
|
@@ -4,13 +4,13 @@ module Ecoportal
|
|
4
4
|
class Page
|
5
5
|
class Component
|
6
6
|
class SelectionOptions < Ecoportal::API::Common::Content::CollectionModel
|
7
|
-
class_resolver :option_class,
|
7
|
+
class_resolver :option_class, 'Ecoportal::API::V2::Page::Component::SelectionOption'
|
8
8
|
|
9
9
|
self.klass = :option_class
|
10
10
|
self.order_key = :weight
|
11
11
|
|
12
12
|
def component
|
13
|
-
|
13
|
+
_parent
|
14
14
|
end
|
15
15
|
|
16
16
|
def ooze
|
@@ -19,27 +19,31 @@ module Ecoportal
|
|
19
19
|
|
20
20
|
def add(value:, name: nil, pos: NOT_USED, before: NOT_USED, after: NOT_USED)
|
21
21
|
opt_doc = items_class.new_doc
|
22
|
+
|
22
23
|
upsert!(opt_doc, pos: pos, before: before, after: after) do |option|
|
23
24
|
option.name = name
|
24
25
|
option.value = value
|
25
|
-
|
26
|
+
|
27
|
+
if (prev = previous_option(option))
|
26
28
|
option.weight = prev.weight
|
27
29
|
end
|
30
|
+
|
28
31
|
yield(option) if block_given?
|
32
|
+
|
29
33
|
fix_weights!
|
30
34
|
end
|
31
35
|
end
|
32
36
|
|
33
37
|
def find_option(value_name, by_name: false)
|
34
38
|
if by_name
|
35
|
-
|
39
|
+
find {|opt| same_string?(opt.name, value_name)}
|
36
40
|
else
|
37
|
-
|
41
|
+
find {|opt| opt.value == value_name}
|
38
42
|
end
|
39
43
|
end
|
40
44
|
|
41
45
|
def ordered
|
42
|
-
|
46
|
+
sort_by.with_index do |option, index|
|
43
47
|
[option.weight, index]
|
44
48
|
end
|
45
49
|
end
|
@@ -82,7 +86,8 @@ module Ecoportal
|
|
82
86
|
def previous_option(value)
|
83
87
|
opts = ordered
|
84
88
|
pos = opts.index(value) - 1
|
85
|
-
return if pos
|
89
|
+
return if pos.negative?
|
90
|
+
|
86
91
|
opts[pos]
|
87
92
|
end
|
88
93
|
end
|
@@ -28,18 +28,19 @@ module Ecoportal
|
|
28
28
|
self.use_defaults = true
|
29
29
|
when Hash
|
30
30
|
supported = [:button_text]
|
31
|
-
|
31
|
+
|
32
|
+
unless (rest = hash_except!(cnf.dup, *supported)).empty?
|
32
33
|
unused.push(rest)
|
33
34
|
end
|
34
|
-
|
35
|
+
|
36
|
+
self.button_text = cnf[:button_text] if cnf.key?(:button_text)
|
35
37
|
else
|
36
38
|
unused.push(cnf)
|
37
39
|
end
|
38
|
-
end.
|
40
|
+
end.then do |unused|
|
39
41
|
super(*unused)
|
40
42
|
end
|
41
43
|
end
|
42
|
-
|
43
44
|
end
|
44
45
|
end
|
45
46
|
end
|
@@ -228,24 +228,24 @@ module Ecoportal
|
|
228
228
|
end
|
229
229
|
end
|
230
230
|
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
231
|
+
require_relative 'component/tag_field'
|
232
|
+
require_relative 'component/geo_field'
|
233
|
+
require_relative 'component/selection_field'
|
234
|
+
require_relative 'component/date_field'
|
235
|
+
require_relative 'component/number_field'
|
236
|
+
require_relative 'component/gauge_field'
|
237
|
+
require_relative 'component/plain_text_field'
|
238
|
+
require_relative 'component/rich_text_field'
|
239
|
+
require_relative 'component/people_field'
|
240
|
+
require_relative 'component/contractor_entities_field'
|
241
|
+
require_relative 'component/checklist_field'
|
242
|
+
require_relative 'component/action_field'
|
243
|
+
require_relative 'component/actions_field'
|
244
|
+
require_relative 'component/files_field'
|
245
|
+
require_relative 'component/images_field'
|
246
|
+
require_relative 'component/signature_field'
|
247
|
+
require_relative 'component/reference_field'
|
248
|
+
require_relative 'component/law_field'
|
249
|
+
require_relative 'component/mailbox_field'
|
250
|
+
require_relative 'component/chart_field'
|
251
|
+
require_relative 'component/chart_fr_field'
|
@@ -4,26 +4,27 @@ module Ecoportal
|
|
4
4
|
class Page
|
5
5
|
class Force
|
6
6
|
class Bindings < Ecoportal::API::Common::Content::CollectionModel
|
7
|
-
class_resolver :binding_class,
|
7
|
+
class_resolver :binding_class, 'Ecoportal::API::V2::Page::Force::Binding'
|
8
8
|
|
9
9
|
self.klass = :binding_class
|
10
10
|
self.order_matters = true
|
11
11
|
|
12
12
|
def ooze
|
13
|
-
|
13
|
+
_parent.ooze
|
14
14
|
end
|
15
15
|
|
16
16
|
def force
|
17
|
-
|
17
|
+
_parent
|
18
18
|
end
|
19
19
|
|
20
20
|
# @note first local binding name will shadow later ones
|
21
|
-
# @param only_winner [Boolean] specifies if retrieving multiple bindings
|
21
|
+
# @param only_winner [Boolean] specifies if retrieving multiple bindings
|
22
|
+
# with same name or just the winner
|
22
23
|
# @return [Hash] where **key** is `name` and **value** is
|
23
24
|
# 1. a single _binding_, if `only_winner` is `true`
|
24
25
|
# 2. an `Array` of _bindings_ with same _name_, otherwise
|
25
26
|
def by_name(only_winner: false)
|
26
|
-
|
27
|
+
each_with_object({}) do |binding, hash|
|
27
28
|
if winner_only
|
28
29
|
hash[binding.name] ||= binding
|
29
30
|
else
|
@@ -33,13 +34,14 @@ module Ecoportal
|
|
33
34
|
end
|
34
35
|
end
|
35
36
|
|
36
|
-
|
37
37
|
# @note first local binding name will shadow later ones.
|
38
|
-
# @param only_winner [Boolean] specifies if shadowed bindings (inactive)
|
39
|
-
#
|
38
|
+
# @param only_winner [Boolean] specifies if shadowed bindings (inactive)
|
39
|
+
# should be excluded (`true`)
|
40
|
+
# @return [Hash] where **key** is a _section_ or a _component_ and **value**
|
41
|
+
# is eitheran `Array` of _bindings_.
|
40
42
|
def by_reference(only_winner: false)
|
41
43
|
if only_winner
|
42
|
-
by_name(only_winner: true).each_with_object({}) do |(
|
44
|
+
by_name(only_winner: true).each_with_object({}) do |(_name, binds), hash|
|
43
45
|
if binds.is_a?(Array)
|
44
46
|
binds.each {|binding| (hash[binding.reference] ||= []).push(binding)}
|
45
47
|
else
|
@@ -47,23 +49,28 @@ module Ecoportal
|
|
47
49
|
end
|
48
50
|
end
|
49
51
|
else
|
50
|
-
|
52
|
+
each_with_object({}) do |binding, hash|
|
51
53
|
(hash[binding.reference] ||= []).push(binding)
|
52
54
|
end
|
53
55
|
end
|
54
56
|
end
|
55
57
|
|
56
|
-
# @param obj [Ecoportal::API::V2::Page::Section, Ecoportal::API::V2::Page::Component)]
|
58
|
+
# @param obj [Ecoportal::API::V2::Page::Section, Ecoportal::API::V2::Page::Component)]
|
59
|
+
# the referred component or section.
|
57
60
|
# @return [Boolean] `true` if `obj` is referred in the bindings, `false` otherwise
|
58
61
|
def reference?(obj)
|
59
|
-
get_by_reference(obj).count
|
62
|
+
get_by_reference(obj).count.positive?
|
60
63
|
end
|
61
64
|
|
62
|
-
# @param obj [Ecoportal::API::V2::Page::Section, Ecoportal::API::V2::Page::Component)]
|
65
|
+
# @param obj [Ecoportal::API::V2::Page::Section, Ecoportal::API::V2::Page::Component)]
|
66
|
+
# the referred component or section.
|
63
67
|
# @return [Array<Ecoportal::API::V2::Page::Force::Binding>] binding to the component or section.
|
64
68
|
def get_by_reference(obj)
|
65
69
|
unless obj.is_a?(Ecoportal::API::V2::Page::Section) || obj.is_a?(Ecoportal::API::V2::Page::Component)
|
66
|
-
|
70
|
+
msg = 'Expected either a Ecoportal::API::V2::Page::Section '
|
71
|
+
msg << 'or a Ecoportal::API::V2::Page::Component. '
|
72
|
+
msg << "Given: #{obj.class}"
|
73
|
+
raise ArgumentError, msg
|
67
74
|
end
|
68
75
|
self.select do |bind|
|
69
76
|
bind.reference == obj
|
@@ -73,7 +80,7 @@ module Ecoportal
|
|
73
80
|
# @param id [String] the `id` of the binding to find.
|
74
81
|
# @return [Ecoportal::API::V2::Page::Force::Binding] binding with `id`
|
75
82
|
def get_by_id(id)
|
76
|
-
|
83
|
+
find do |bind|
|
77
84
|
bind.id == id
|
78
85
|
end
|
79
86
|
end
|
@@ -114,31 +121,34 @@ module Ecoportal
|
|
114
121
|
def add(reference, name:, pos: NOT_USED, before: NOT_USED, after: NOT_USED)
|
115
122
|
binding_doc = binding_class.new_doc
|
116
123
|
|
117
|
-
type =
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
124
|
+
type =
|
125
|
+
case reference
|
126
|
+
when Ecoportal::API::V2::Page::Component
|
127
|
+
unless ooze.components.include?(reference)
|
128
|
+
msg = "The field '#{reference.label}' (#{reference.id}) is not present in ooze.components.\n"
|
129
|
+
msg << 'Review your script (i.e. @var where you store previous ooze runs).'
|
130
|
+
raise msg
|
131
|
+
end
|
132
|
+
Ecoportal::API::V2::Page::Force::Binding::COMPONENT_TYPE
|
133
|
+
when Ecoportal::API::V2::Page::Section
|
134
|
+
unless ooze.sections.include?(reference)
|
135
|
+
msg = "The section '#{reference.heading}' (#{reference.id}) is not present in ooze.sections.\n"
|
136
|
+
msg << 'Review your script (i.e. @var where you store previous ooze runs).'
|
137
|
+
raise msg
|
138
|
+
end
|
139
|
+
Ecoportal::API::V2::Page::Force::Binding::SECTION_TYPE
|
140
|
+
else
|
141
|
+
msg = "You can only create bindings with Component and Section. Given: #{reference.class}"
|
142
|
+
raise ArgumentError, msg
|
143
|
+
end
|
136
144
|
|
137
145
|
position = scope_position(pos: pos, before: before, after: after)
|
146
|
+
|
138
147
|
upsert!(binding_doc, pos: position) do |bind|
|
139
148
|
bind.name = name
|
140
149
|
bind.reference_id = reference.id
|
141
150
|
bind.type = type
|
151
|
+
|
142
152
|
yield(bind) if block_given?
|
143
153
|
end
|
144
154
|
end
|
@@ -148,19 +158,19 @@ module Ecoportal
|
|
148
158
|
def scope_position(pos: NOT_USED, before: NOT_USED, after: NOT_USED)
|
149
159
|
case
|
150
160
|
when used_param?(pos)
|
151
|
-
if pos
|
161
|
+
if (pos = to_binding(pos))
|
152
162
|
_doc_pos(pos) - 1
|
153
163
|
end
|
154
164
|
when used_param?(before)
|
155
|
-
if before = to_binding(before)
|
165
|
+
if (before = to_binding(before))
|
156
166
|
_doc_pos(before) - 1
|
157
167
|
end
|
158
168
|
when used_param?(after)
|
159
|
-
if after
|
169
|
+
if (after = to_binding(after))
|
160
170
|
_doc_pos(after) - 1
|
161
171
|
end
|
162
|
-
end.
|
163
|
-
position
|
172
|
+
end.then do |position|
|
173
|
+
position || count
|
164
174
|
end
|
165
175
|
end
|
166
176
|
|
@@ -8,14 +8,14 @@ module Ecoportal
|
|
8
8
|
class << self
|
9
9
|
def new_doc
|
10
10
|
{
|
11
|
-
|
12
|
-
|
11
|
+
'id' => new_uuid,
|
12
|
+
'weight' => INITIAL_WEIGHT
|
13
13
|
}
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
class_resolver :bindings_class,
|
18
|
-
class_resolver :helper_class,
|
17
|
+
class_resolver :bindings_class, 'Ecoportal::API::V2::Page::Force::Bindings'
|
18
|
+
class_resolver :helper_class, 'Ecoportal::API::V2::Page::Force::Helper'
|
19
19
|
|
20
20
|
passkey :id
|
21
21
|
passforced :patch_ver, default: 1
|
@@ -37,13 +37,13 @@ module Ecoportal
|
|
37
37
|
|
38
38
|
# It updates `script` by using `helpers`
|
39
39
|
def custom_script=(value)
|
40
|
-
doc[
|
40
|
+
doc['custom_script'] = value
|
41
41
|
update_script
|
42
42
|
end
|
43
43
|
|
44
44
|
# It sets the `script` value by using `custom_script` and `helpers[N..1].script`
|
45
45
|
def update_script
|
46
|
-
doc[
|
46
|
+
doc['script'] = helpers.to_a.reverse.map(&:script).push(custom_script).join("\n")
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
@@ -51,6 +51,6 @@ module Ecoportal
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
|
55
|
-
|
56
|
-
|
54
|
+
require_relative 'force/helper'
|
55
|
+
require_relative 'force/binding'
|
56
|
+
require_relative 'force/bindings'
|
@@ -3,7 +3,7 @@ module Ecoportal
|
|
3
3
|
class V2
|
4
4
|
class Page
|
5
5
|
class Forces < Ecoportal::API::Common::Content::CollectionModel
|
6
|
-
class_resolver :force_class,
|
6
|
+
class_resolver :force_class, 'Ecoportal::API::V2::Page::Force'
|
7
7
|
|
8
8
|
self.klass = :force_class
|
9
9
|
self.order_matters = true
|
@@ -6,8 +6,8 @@ module Ecoportal
|
|
6
6
|
class << self
|
7
7
|
def new_doc
|
8
8
|
{
|
9
|
-
|
10
|
-
|
9
|
+
'id' => new_uuid,
|
10
|
+
'editable' => false
|
11
11
|
}
|
12
12
|
end
|
13
13
|
end
|
@@ -16,7 +16,7 @@ module Ecoportal
|
|
16
16
|
passforced :patch_ver, default: 1
|
17
17
|
passthrough :user_id, :user_name
|
18
18
|
passthrough :editable
|
19
|
-
embeds_one :flags, klass:
|
19
|
+
embeds_one :flags, klass: 'Ecoportal::API::V2::Page::PermissionFlags'
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
@@ -3,18 +3,18 @@ module Ecoportal
|
|
3
3
|
class V2
|
4
4
|
class Page
|
5
5
|
class Sections < Ecoportal::API::Common::Content::CollectionModel
|
6
|
-
class_resolver :section_class,
|
6
|
+
class_resolver :section_class, 'Ecoportal::API::V2::Page::Section'
|
7
7
|
|
8
8
|
self.klass = :section_class
|
9
9
|
self.order_key = :weight
|
10
10
|
|
11
11
|
def ooze
|
12
|
-
|
12
|
+
_parent.ooze
|
13
13
|
end
|
14
14
|
|
15
15
|
# @return [Boolean] `true` if there is one or more sections shared, `false` otherwise
|
16
16
|
def any_shared?
|
17
|
-
|
17
|
+
any?(&:shared?)
|
18
18
|
end
|
19
19
|
|
20
20
|
# Creates a new `section`
|
@@ -24,16 +24,19 @@ module Ecoportal
|
|
24
24
|
# as shared sections could change order in other stages
|
25
25
|
def add(name: nil, split: false, pos: NOT_USED, before: NOT_USED, after: NOT_USED)
|
26
26
|
sec_doc = section_class.new_doc(split: split)
|
27
|
+
|
27
28
|
upsert!(sec_doc) do |section| #, pos: pos, before: before, after: after) do |section|
|
28
|
-
section.heading
|
29
|
+
section.heading = name
|
30
|
+
|
29
31
|
move(section, pos: pos, before: before, after: after)
|
32
|
+
|
30
33
|
yield(section) if block_given?
|
31
34
|
end
|
32
35
|
end
|
33
36
|
|
34
37
|
# Moves an existing `section`
|
35
38
|
def move(section, pos: NOT_USED, before: NOT_USED, after: NOT_USED)
|
36
|
-
if weight = scope_weight(section, pos: pos, before: before, after: after)
|
39
|
+
if (weight = scope_weight(section, pos: pos, before: before, after: after))
|
37
40
|
section.weight = weight
|
38
41
|
end
|
39
42
|
fix_weights!
|
@@ -41,7 +44,7 @@ module Ecoportal
|
|
41
44
|
|
42
45
|
# @return [Ecoportal::API::V2::Page::Section]
|
43
46
|
def get_by_id(id)
|
44
|
-
|
47
|
+
find do |sec|
|
45
48
|
sec.id == id
|
46
49
|
end
|
47
50
|
end
|
@@ -81,7 +84,7 @@ module Ecoportal
|
|
81
84
|
# Gets the sections ordered by `weight` (as they appear in the page)
|
82
85
|
# @return [Array<Ecoportal::API::V2::Page::Section>] section sorted by `weight`
|
83
86
|
def ordered
|
84
|
-
|
87
|
+
sort_by.with_index do |section, index|
|
85
88
|
[section.weight, index]
|
86
89
|
end
|
87
90
|
end
|
@@ -96,22 +99,23 @@ module Ecoportal
|
|
96
99
|
def scope_weight(section, pos: NOT_USED, before: NOT_USED, after: NOT_USED)
|
97
100
|
case
|
98
101
|
when used_param?(pos)
|
99
|
-
if pos
|
102
|
+
if (pos = to_section(pos))
|
100
103
|
pos.weight - 1
|
101
104
|
end
|
102
105
|
when used_param?(before)
|
103
|
-
if before = to_section(before)
|
106
|
+
if (before = to_section(before))
|
104
107
|
before.weight - 1
|
105
108
|
end
|
106
109
|
when used_param?(after)
|
107
|
-
if after = to_section(after)
|
110
|
+
if (after = to_section(after))
|
108
111
|
after.weight
|
109
112
|
end
|
110
|
-
end.
|
113
|
+
end.then do |weight|
|
111
114
|
weight ||= ordered.reject do |sec|
|
112
115
|
sec.id == section.id
|
113
116
|
end.last&.weight
|
114
|
-
|
117
|
+
|
118
|
+
weight || section_class.const_get(:INITIAL_WEIGHT)
|
115
119
|
end
|
116
120
|
end
|
117
121
|
|
@@ -127,7 +131,7 @@ module Ecoportal
|
|
127
131
|
end
|
128
132
|
|
129
133
|
def fix_weights!
|
130
|
-
unless
|
134
|
+
unless any_shared? && _parent.is_a?(Ecoportal::API::V2::Pages::PageStage)
|
131
135
|
ordered.each_with_index do |section, index|
|
132
136
|
section.weight = index
|
133
137
|
end
|
@@ -137,7 +141,8 @@ module Ecoportal
|
|
137
141
|
def previous_section(value)
|
138
142
|
secs = ordered
|
139
143
|
pos = secs.index(value) - 1
|
140
|
-
return if pos
|
144
|
+
return if pos.negative?
|
145
|
+
|
141
146
|
secs[pos]
|
142
147
|
end
|
143
148
|
end
|