metadata_presenter 2.13.0 → 2.15.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 92db6bbc2b6ecefe9836a96c3014b94cc43c48a2fb4e82152f71bea00d6b3bc4
4
- data.tar.gz: f9a2d946f0bf343f4a20f943f2aed35d3fce8ddbc42cf28997b10f10bfa3f9ba
3
+ metadata.gz: c872a270c9f0dcdaeda241c5f0d2a09d7b01f4f13334d191801f13b6026bca1d
4
+ data.tar.gz: 7da6c96aec0df8801aef5cf1e4d82ae39cfefd417fa47d26cb239a1c3ccd08b9
5
5
  SHA512:
6
- metadata.gz: 4b94a4afee1f43a692360645775bb5555c3c722f93a5c1f2c0cb865af90e43448d5eb1bab458eb022c49d76a39348497f2946ca925afdf11fd8ed5f8749ef0f4
7
- data.tar.gz: 10ad22eada3869215e8d7ef9e00dc578468d142b7c3d151c9ba8590ad001101570e317f1b7b1f2dd5343572608ba4e1464383f8c57acbb317aa160cd2ab85157
6
+ metadata.gz: 24ee1c3b678200fce8eded2be159ea94cc27efed191e542ae0874f141896b5fdea8e6f7355547df367a39319aa6673f6ab22079c3dcb245d87202d33117d8819
7
+ data.tar.gz: d1a4b738bff3e02a61e6e76a3d5c90c32540e084c36faa874e98d8715c1db5cfe0a016023684a5f2e18a7a377acd4b24b6bfcef7a36869b15bde759bb176d13a
@@ -1,18 +1,43 @@
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
- [existing_column, new_column].compact.max
11
+ if service.flow_object(uuid).branch?
12
+ # Even though we are associating the column number to a specific flow object
13
+ # in the Coordinates model we do not use column_number + 1 as we are
14
+ # updating the position for the Spacers that exist for a branch which
15
+ # are always in the same column as the branch object itself.
16
+ coordinates.set_branch_spacers_column(uuid, column_number)
17
+ end
18
+
19
+ column_number
11
20
  end
12
21
 
13
22
  private
14
23
 
15
- attr_reader :uuid, :coordinates, :new_column
24
+ attr_reader :uuid, :coordinates, :new_column, :service
25
+
26
+ def column_number
27
+ @column_number ||= begin
28
+ return latest_column if cya_or_confirmation_page?
29
+
30
+ existing_column || new_column
31
+ end
32
+ end
33
+
34
+ def latest_column
35
+ [existing_column, new_column].compact.max
36
+ end
37
+
38
+ def cya_or_confirmation_page?
39
+ [service.checkanswers_page&.uuid, service.confirmation_page&.uuid].include?(uuid)
40
+ end
16
41
 
17
42
  def existing_column
18
43
  @coordinates.uuid_column(uuid)
@@ -1,11 +1,14 @@
1
1
  module MetadataPresenter
2
2
  class Coordinates
3
- def initialize(flow)
4
- @flow = flow
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,45 @@ 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 :flow
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.index_with do |_uuid|
73
+ { row: nil, column: nil }
74
+ end
75
+ end
49
76
  end
50
77
  end
51
78
  end
@@ -19,7 +19,7 @@ module MetadataPresenter
19
19
 
20
20
  class Grid
21
21
  include BranchDestinations
22
- attr_reader :start_from
22
+ attr_reader :service, :start_from
23
23
 
24
24
  def initialize(service, start_from: nil, main_flow: [])
25
25
  @service = service
@@ -28,7 +28,7 @@ module MetadataPresenter
28
28
  @ordered = []
29
29
  @routes = []
30
30
  @traversed = []
31
- @coordinates = MetadataPresenter::Coordinates.new(service.flow)
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 { |obj| obj.is_a?(MetadataPresenter::Spacer) || obj.is_a?(MetadataPresenter::Warning) }
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
@@ -65,9 +67,13 @@ module MetadataPresenter
65
67
  ordered_pages.map(&:uuid)
66
68
  end
67
69
 
70
+ def show_warning?
71
+ checkanswers_warning.show_warning? || confirmation_warning.show_warning?
72
+ end
73
+
68
74
  private
69
75
 
70
- attr_reader :service, :main_flow
76
+ attr_reader :main_flow
71
77
  attr_accessor :ordered, :traversed, :routes, :coordinates
72
78
 
73
79
  def route_from_start
@@ -136,7 +142,8 @@ module MetadataPresenter
136
142
  column_number = MetadataPresenter::ColumnNumber.new(
137
143
  uuid: uuid,
138
144
  new_column: new_column,
139
- coordinates: @coordinates
145
+ coordinates: @coordinates,
146
+ service: service
140
147
  ).number
141
148
  @coordinates.set_column(uuid, column_number)
142
149
  end
@@ -189,7 +196,7 @@ module MetadataPresenter
189
196
 
190
197
  def add_by_coordinates
191
198
  service.flow.each_key do |uuid|
192
- position = coordinates.position(uuid)
199
+ position = coordinates.positions[uuid]
193
200
  next if detached?(position)
194
201
 
195
202
  column = position[:column]
@@ -251,8 +258,9 @@ module MetadataPresenter
251
258
  end
252
259
 
253
260
  # Each branch has a certain number of exits that require their own line
254
- # and arrow. Insert any spacers into the necessary row in the column after
255
- # the one the branch is located in.
261
+ # and arrow. When there are 'OR' conditions we need to insert additional
262
+ # spacers into the necessary row in the column after the one the branch is
263
+ # located in.
256
264
  def insert_expression_spacers
257
265
  service.branches.each do |branch|
258
266
  next if coordinates.uuid_column(branch.uuid).nil?
@@ -273,46 +281,21 @@ module MetadataPresenter
273
281
  # Include a warning if a service does not have a CYA or Confirmation page in the
274
282
  # main flow. The warning should always be in the first row, last column.
275
283
  def insert_warning
276
- if cya_and_confirmation_pages_not_in_service? ||
277
- cya_and_confirmation_pages_detached?
278
- @ordered.append([MetadataPresenter::Warning.new])
279
- end
280
- end
281
-
282
- def cya_and_confirmation_pages_not_in_service?
283
- (checkanswers_not_in_service? && confirmation_not_in_service?) ||
284
- checkanswers_not_in_service? ||
285
- confirmation_not_in_service?
284
+ @ordered.append([MetadataPresenter::Warning.new]) if show_warning?
286
285
  end
287
286
 
288
- def checkanswers_not_in_service?
289
- service.checkanswers_page.blank?
287
+ def checkanswers_warning
288
+ MetadataPresenter::PageWarning.new(
289
+ page: service.checkanswers_page,
290
+ main_flow_uuids: flow_uuids
291
+ )
290
292
  end
291
293
 
292
- def confirmation_not_in_service?
293
- service.confirmation_page.blank?
294
- end
295
-
296
- def cya_and_confirmation_pages_detached?
297
- (checkanswers_detached? && confirmation_detached?) ||
298
- checkanswers_detached? ||
299
- confirmation_detached?
300
- end
301
-
302
- def checkanswers_detached?
303
- if service.checkanswers_page.present?
304
- uuid = service.checkanswers_page.uuid
305
- position = coordinates.position(uuid)
306
- detached?(position)
307
- end
308
- end
309
-
310
- def confirmation_detached?
311
- if service.confirmation_page.present?
312
- uuid = service.confirmation_page.uuid
313
- position = coordinates.position(uuid)
314
- detached?(position)
315
- end
294
+ def confirmation_warning
295
+ MetadataPresenter::PageWarning.new(
296
+ page: service.confirmation_page,
297
+ main_flow_uuids: flow_uuids
298
+ )
316
299
  end
317
300
 
318
301
  # Any destinations exiting the branch that have not already been traversed.
@@ -0,0 +1,24 @@
1
+ module MetadataPresenter
2
+ class PageWarning
3
+ def initialize(page:, main_flow_uuids:)
4
+ @page = page
5
+ @main_flow_uuids = main_flow_uuids
6
+ end
7
+
8
+ def show_warning?
9
+ missing? || detached?
10
+ end
11
+
12
+ def missing?
13
+ page.blank?
14
+ end
15
+
16
+ def detached?
17
+ main_flow_uuids.exclude?(page&.uuid)
18
+ end
19
+
20
+ private
21
+
22
+ attr_reader :page, :main_flow_uuids
23
+ end
24
+ 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,83 @@ module MetadataPresenter
13
11
  ROW_ZERO = 0
14
12
 
15
13
  def number
16
- return route.row if first_row? && existing_row.nil?
17
-
18
- return ROW_ZERO if place_on_row_zero?
14
+ if service.flow_object(uuid).branch?
15
+ coordinates.set_branch_spacers_row(uuid, calculated_row)
16
+ end
19
17
 
20
- [current_row, existing_row, potential_row].compact.max
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, branch_spacer_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
 
39
+ # This looks for any branches in the current column and checks that there is
40
+ # enough space for the any branch conditionals before returning a row number.
31
41
  def potential_row
32
- return unless object_above.branch? && uuid != object_above.uuid
42
+ return if branches_in_column.empty?
33
43
 
34
- coordinates.uuid_row(object_above.uuid) + number_of_destinations
44
+ row_numbers = branches_in_column.map do |branch_uuid, _|
45
+ coordinates.branch_spacers[branch_uuid].map { |_, position| position[:row] }
46
+ end
47
+ row_numbers.flatten.max + 1
48
+ end
49
+
50
+ # This looks at the previous column and finds any branches that link to the
51
+ # current object. If any are found it checks for rows numbers that relate
52
+ # to the current objects UUID in the branch spacers hash and defaults to
53
+ # returning the highest row number.
54
+ def branch_spacer_row
55
+ return if spacers_for_current_object.empty?
56
+
57
+ spacers_for_current_object.map { |position| position[:row] }.max
35
58
  end
36
59
 
37
60
  def first_row?
38
61
  @first_row ||= route.row.zero?
39
62
  end
40
63
 
41
- def object_above
42
- @object_above ||=
43
- service.flow_object(
44
- coordinates.uuid_at_position(uuid_column, row_number_for_object_above)
45
- )
64
+ def branches_in_column
65
+ @branches_in_column ||= branches(uuid_column)
46
66
  end
47
67
 
48
- def row_number_for_object_above
49
- column_objects.map { |_, p| p[:row] if p[:row] < current_row }.compact.max.to_i
68
+ def branches_in_previous_column
69
+ @branches_in_previous_column ||= branches(uuid_column - 1)
50
70
  end
51
71
 
52
- def column_objects
53
- objects_in_column = coordinates.positions_in_column(uuid_column).reject do |u, p|
54
- u == uuid || p[:row].nil?
72
+ def branches(column_number)
73
+ coordinates.positions_in_column(column_number).select do |key, position|
74
+ next if uuid == key || position[:row].blank?
75
+
76
+ service.flow_object(key).branch?
55
77
  end
56
- objects_in_column.sort_by { |_, p| p[:row] }
57
78
  end
58
79
 
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
80
+ def spacers_for_current_object
81
+ @spacers_for_current_object ||= begin
82
+ spacer_positions = branches_in_previous_column.select do |key, _|
83
+ coordinates.branch_spacers[key]
84
+ end
85
+
86
+ current_object_spacers = spacer_positions.map do |branch_uuid, _|
87
+ coordinates.branch_spacers[branch_uuid][uuid]
88
+ end
89
+ current_object_spacers.compact
90
+ end
63
91
  end
64
92
 
65
93
  def uuid_column
@@ -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",