metadata_presenter 2.13.0 → 2.14.0
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/app/models/metadata_presenter/column_number.rb +24 -3
- data/app/models/metadata_presenter/coordinates.rb +35 -10
- data/app/models/metadata_presenter/grid.rb +12 -8
- data/app/models/metadata_presenter/row_number.rb +23 -28
- data/fixtures/branching_10.json +1 -1
- data/fixtures/branching_11.json +1142 -0
- data/fixtures/branching_11.png +0 -0
- data/fixtures/branching_9.json +1 -1
- data/lib/metadata_presenter/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 42603519130d7f5029066830adc145fe8800465f38493f5acfe37943623210b9
|
4
|
+
data.tar.gz: 9cb6b248e8246c2b0145f6d746043680494fd7292a36d2e18dff619cf55af8dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 354e08330a417e94180c4686e058eac97155e2b62440faabdf1e10b17d469d2e7b93a0fd155d5d3eeb71549f2fc6725c78e048ac442c5a5b6dfeaae3f81c09e9
|
7
|
+
data.tar.gz: 22011caef879554eb407f7bbda3726b5255178eb51b15e095c3409ec84f97df6ed565382f51651801f0ee9686b895ffc1db92ee9f4e715baa957e4378b88eee9
|
@@ -1,18 +1,39 @@
|
|
1
1
|
module MetadataPresenter
|
2
2
|
class ColumnNumber
|
3
|
-
def initialize(uuid:, coordinates:, new_column:)
|
3
|
+
def initialize(uuid:, coordinates:, new_column:, service:)
|
4
4
|
@uuid = uuid
|
5
5
|
@coordinates = coordinates
|
6
6
|
@new_column = new_column
|
7
|
+
@service = service
|
7
8
|
end
|
8
9
|
|
9
10
|
def number
|
10
|
-
|
11
|
+
if service.flow_object(uuid).branch?
|
12
|
+
coordinates.set_branch_spacers_column(uuid, column_number)
|
13
|
+
end
|
14
|
+
|
15
|
+
column_number
|
11
16
|
end
|
12
17
|
|
13
18
|
private
|
14
19
|
|
15
|
-
attr_reader :uuid, :coordinates, :new_column
|
20
|
+
attr_reader :uuid, :coordinates, :new_column, :service
|
21
|
+
|
22
|
+
def column_number
|
23
|
+
@column_number ||= begin
|
24
|
+
return latest_column if cya_or_confirmation_page?
|
25
|
+
|
26
|
+
existing_column || new_column
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def latest_column
|
31
|
+
[existing_column, new_column].compact.max
|
32
|
+
end
|
33
|
+
|
34
|
+
def cya_or_confirmation_page?
|
35
|
+
[service.checkanswers_page&.uuid, service.confirmation_page&.uuid].include?(uuid)
|
36
|
+
end
|
16
37
|
|
17
38
|
def existing_column
|
18
39
|
@coordinates.uuid_column(uuid)
|
@@ -1,11 +1,14 @@
|
|
1
1
|
module MetadataPresenter
|
2
2
|
class Coordinates
|
3
|
-
|
4
|
-
|
3
|
+
include BranchDestinations
|
4
|
+
|
5
|
+
def initialize(service)
|
6
|
+
@service = service
|
5
7
|
@positions = setup_positions
|
8
|
+
@branch_spacers = setup_branch_spacers
|
6
9
|
end
|
7
10
|
|
8
|
-
attr_reader :positions
|
11
|
+
attr_reader :positions, :branch_spacers
|
9
12
|
|
10
13
|
def set_column(uuid, number)
|
11
14
|
positions[uuid][:column] = number
|
@@ -31,21 +34,43 @@ module MetadataPresenter
|
|
31
34
|
end
|
32
35
|
end
|
33
36
|
|
34
|
-
def position(uuid)
|
35
|
-
positions[uuid]
|
36
|
-
end
|
37
|
-
|
38
37
|
def positions_in_column(column_number)
|
39
38
|
positions.select { |_, position| position[:column] == column_number }
|
40
39
|
end
|
41
40
|
|
41
|
+
def set_branch_spacers_column(branch_uuid, column)
|
42
|
+
branch_spacers[branch_uuid].each do |position|
|
43
|
+
position[:column] = column
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# The first conditional will always attempt to draw an arrow on the same row
|
48
|
+
# as the branch object.
|
49
|
+
# Each following conditional needs to have a spacers in order for the frontend
|
50
|
+
# to draw an arrow therefore we increment the row number from the branches
|
51
|
+
# calculated starting row
|
52
|
+
def set_branch_spacers_row(branch_uuid, starting_row)
|
53
|
+
branch_spacers[branch_uuid].each.with_index(starting_row) do |position, row|
|
54
|
+
position[:row] = row
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
42
58
|
private
|
43
59
|
|
44
|
-
attr_reader :
|
45
|
-
attr_writer :positions
|
60
|
+
attr_reader :service
|
61
|
+
attr_writer :positions, :branch_spacers
|
46
62
|
|
47
63
|
def setup_positions
|
48
|
-
flow.keys.index_with { |_uuid| { row: nil, column: nil } }
|
64
|
+
service.flow.keys.index_with { |_uuid| { row: nil, column: nil } }
|
65
|
+
end
|
66
|
+
|
67
|
+
# This also takes into account the 'or' expressions which
|
68
|
+
# need an additional line for an arrow.
|
69
|
+
def setup_branch_spacers
|
70
|
+
service.branches.each.with_object({}) do |branch, hash|
|
71
|
+
destinations = exiting_destinations_from_branch(branch)
|
72
|
+
hash[branch.uuid] = destinations.map { { row: nil, column: nil } }
|
73
|
+
end
|
49
74
|
end
|
50
75
|
end
|
51
76
|
end
|
@@ -28,7 +28,7 @@ module MetadataPresenter
|
|
28
28
|
@ordered = []
|
29
29
|
@routes = []
|
30
30
|
@traversed = []
|
31
|
-
@coordinates = MetadataPresenter::Coordinates.new(service
|
31
|
+
@coordinates = MetadataPresenter::Coordinates.new(service)
|
32
32
|
end
|
33
33
|
|
34
34
|
ROW_ZERO = 0
|
@@ -50,7 +50,9 @@ module MetadataPresenter
|
|
50
50
|
|
51
51
|
def ordered_flow
|
52
52
|
@ordered_flow ||=
|
53
|
-
build.flatten.reject
|
53
|
+
build.flatten.reject do |obj|
|
54
|
+
obj.is_a?(MetadataPresenter::Spacer) || obj.is_a?(MetadataPresenter::Warning)
|
55
|
+
end
|
54
56
|
end
|
55
57
|
|
56
58
|
def ordered_pages
|
@@ -136,7 +138,8 @@ module MetadataPresenter
|
|
136
138
|
column_number = MetadataPresenter::ColumnNumber.new(
|
137
139
|
uuid: uuid,
|
138
140
|
new_column: new_column,
|
139
|
-
coordinates: @coordinates
|
141
|
+
coordinates: @coordinates,
|
142
|
+
service: service
|
140
143
|
).number
|
141
144
|
@coordinates.set_column(uuid, column_number)
|
142
145
|
end
|
@@ -189,7 +192,7 @@ module MetadataPresenter
|
|
189
192
|
|
190
193
|
def add_by_coordinates
|
191
194
|
service.flow.each_key do |uuid|
|
192
|
-
position = coordinates.
|
195
|
+
position = coordinates.positions[uuid]
|
193
196
|
next if detached?(position)
|
194
197
|
|
195
198
|
column = position[:column]
|
@@ -251,8 +254,9 @@ module MetadataPresenter
|
|
251
254
|
end
|
252
255
|
|
253
256
|
# Each branch has a certain number of exits that require their own line
|
254
|
-
# and arrow.
|
255
|
-
# the one the branch is
|
257
|
+
# and arrow. When there are 'OR' conditions we need to insert additional
|
258
|
+
# spacers into the necessary row in the column after the one the branch is
|
259
|
+
# located in.
|
256
260
|
def insert_expression_spacers
|
257
261
|
service.branches.each do |branch|
|
258
262
|
next if coordinates.uuid_column(branch.uuid).nil?
|
@@ -302,7 +306,7 @@ module MetadataPresenter
|
|
302
306
|
def checkanswers_detached?
|
303
307
|
if service.checkanswers_page.present?
|
304
308
|
uuid = service.checkanswers_page.uuid
|
305
|
-
position = coordinates.
|
309
|
+
position = coordinates.positions[uuid]
|
306
310
|
detached?(position)
|
307
311
|
end
|
308
312
|
end
|
@@ -310,7 +314,7 @@ module MetadataPresenter
|
|
310
314
|
def confirmation_detached?
|
311
315
|
if service.confirmation_page.present?
|
312
316
|
uuid = service.confirmation_page.uuid
|
313
|
-
position = coordinates.
|
317
|
+
position = coordinates.positions[uuid]
|
314
318
|
detached?(position)
|
315
319
|
end
|
316
320
|
end
|
@@ -1,7 +1,5 @@
|
|
1
1
|
module MetadataPresenter
|
2
2
|
class RowNumber
|
3
|
-
include BranchDestinations
|
4
|
-
|
5
3
|
def initialize(uuid:, route:, current_row:, coordinates:, service:)
|
6
4
|
@uuid = uuid
|
7
5
|
@route = route
|
@@ -13,53 +11,50 @@ module MetadataPresenter
|
|
13
11
|
ROW_ZERO = 0
|
14
12
|
|
15
13
|
def number
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
if service.flow_object(uuid).branch?
|
15
|
+
coordinates.set_branch_spacers_row(uuid, calculated_row)
|
16
|
+
end
|
19
17
|
|
20
|
-
|
18
|
+
calculated_row
|
21
19
|
end
|
22
20
|
|
23
21
|
private
|
24
22
|
|
25
23
|
attr_reader :uuid, :route, :current_row, :coordinates, :service
|
26
24
|
|
25
|
+
def calculated_row
|
26
|
+
@calculated_row ||= begin
|
27
|
+
return route.row if first_row? && existing_row.nil?
|
28
|
+
|
29
|
+
return ROW_ZERO if place_on_row_zero?
|
30
|
+
|
31
|
+
existing_row || [current_row, potential_row].compact.max
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
27
35
|
def existing_row
|
28
36
|
@existing_row ||= coordinates.uuid_row(uuid)
|
29
37
|
end
|
30
38
|
|
31
39
|
def potential_row
|
32
|
-
return
|
40
|
+
return if branches_in_column.empty?
|
33
41
|
|
34
|
-
|
42
|
+
row_numbers = branches_in_column.map do |uuid, _|
|
43
|
+
coordinates.branch_spacers[uuid].map { |position| position[:row] }
|
44
|
+
end
|
45
|
+
row_numbers.flatten.max + 1
|
35
46
|
end
|
36
47
|
|
37
48
|
def first_row?
|
38
49
|
@first_row ||= route.row.zero?
|
39
50
|
end
|
40
51
|
|
41
|
-
def
|
42
|
-
@
|
43
|
-
|
44
|
-
coordinates.uuid_at_position(uuid_column, row_number_for_object_above)
|
45
|
-
)
|
46
|
-
end
|
52
|
+
def branches_in_column
|
53
|
+
@branches_in_column ||= coordinates.positions_in_column(uuid_column).select do |key, position|
|
54
|
+
next if uuid == key || position[:row].blank?
|
47
55
|
|
48
|
-
|
49
|
-
column_objects.map { |_, p| p[:row] if p[:row] < current_row }.compact.max.to_i
|
50
|
-
end
|
51
|
-
|
52
|
-
def column_objects
|
53
|
-
objects_in_column = coordinates.positions_in_column(uuid_column).reject do |u, p|
|
54
|
-
u == uuid || p[:row].nil?
|
56
|
+
service.flow_object(key).branch?
|
55
57
|
end
|
56
|
-
objects_in_column.sort_by { |_, p| p[:row] }
|
57
|
-
end
|
58
|
-
|
59
|
-
# Takes into account the 'or' type of conditionals which requires an
|
60
|
-
# additional spacer
|
61
|
-
def number_of_destinations
|
62
|
-
exiting_destinations_from_branch(object_above).count
|
63
58
|
end
|
64
59
|
|
65
60
|
def uuid_column
|
data/fixtures/branching_10.json
CHANGED
@@ -1202,7 +1202,7 @@
|
|
1202
1202
|
"created_by": "30b04817-8997-43ac-8f34-2ad817a966ea",
|
1203
1203
|
"service_id": "14959589-1731-404d-a4c4-c3e8d85ed22c",
|
1204
1204
|
"version_id": "7279554f-2d0a-4eec-b168-a0156d980bd2",
|
1205
|
-
"service_name": "Branching 10 ",
|
1205
|
+
"service_name": "Branching Fixture 10 ",
|
1206
1206
|
"configuration": {
|
1207
1207
|
"meta": {
|
1208
1208
|
"_id": "config.meta",
|