metadata_presenter 2.15.13 → 2.16.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6d5969bdf63685481109ae4b1f13741f637aae7671ef3df47517ca75402d8b12
4
- data.tar.gz: d3cf1e318637c4dac336ad105c94f20a725d4bf2ef632b67c570a58dc59adf01
3
+ metadata.gz: aea27b189ffc9aa32b2eaa0e82687641c85cee5c0838f76eab923ef914528228
4
+ data.tar.gz: fa9a46743dd960cb6b870ef3399f792dc721baa407a4a70f6b3d9445b87c88ea
5
5
  SHA512:
6
- metadata.gz: e62424c6c90d6b003d02850926a5267f9e80c42a1909912708c60873dfc8ce5ef7eeed82b5866dbf6ee4626762de938bdfaed065a684bc51e5ac944c4f7266c8
7
- data.tar.gz: 3ff1608e45d6eed1433084d1145a781e81091b313fd389e01a74e7760946f3f1eac07012ff5e6bb2ded42072ec8f066e295bf5f2e4a2ae1782cd2c513e0078d2
6
+ metadata.gz: e7181c2097257a9d518cb104e64a8922a586e53c14731e7e1cad87c979904a953968e8c7efe927ae576ec9635bfa824b8c5dc1a886d6ca5ce02bc24d0380a9e3
7
+ data.tar.gz: '09653947ee618d2b69ad8114f0271166cac37b290a222a219aeab548159c914d89ecc07d4829d52da935d45b56129949384ca60902b589a913854e30959cacaf'
@@ -61,7 +61,9 @@ module MetadataPresenter
61
61
  attr_writer :positions, :branch_spacers
62
62
 
63
63
  def setup_positions
64
- service.flow.keys.index_with { |_uuid| { row: nil, column: nil } }
64
+ service.flow.keys.index_with do |_uuid|
65
+ { row: nil, column: nil, previous_flow_uuid: nil, conditional_uuid: nil }
66
+ end
65
67
  end
66
68
 
67
69
  # This also takes into account the 'OR' expressions which
@@ -19,7 +19,7 @@ module MetadataPresenter
19
19
 
20
20
  class Grid
21
21
  include BranchDestinations
22
- attr_reader :service, :start_from
22
+ attr_reader :service, :start_from, :previous_uuids
23
23
 
24
24
  def initialize(service, start_from: nil, main_flow: [])
25
25
  @service = service
@@ -29,6 +29,7 @@ module MetadataPresenter
29
29
  @routes = []
30
30
  @traversed = []
31
31
  @coordinates = MetadataPresenter::Coordinates.new(service)
32
+ @previous_uuids = {}
32
33
  end
33
34
 
34
35
  ROW_ZERO = 0
@@ -39,6 +40,7 @@ module MetadataPresenter
39
40
  @ordered = make_grid
40
41
  set_column_numbers
41
42
  set_row_numbers
43
+ set_previous_uuids
42
44
  add_by_coordinates
43
45
  insert_expression_spacers
44
46
  trim_pointers unless main_flow.empty? # only used by detached grids
@@ -71,10 +73,23 @@ module MetadataPresenter
71
73
  checkanswers_warning.show_warning? || confirmation_warning.show_warning?
72
74
  end
73
75
 
76
+ def previous_uuid_for_object(uuid)
77
+ return unless previous_uuids.key?(uuid)
78
+
79
+ previous_uuids[uuid][:previous_flow_uuid]
80
+ end
81
+
82
+ def conditional_uuid_for_object(uuid)
83
+ return unless previous_uuids.key?(uuid)
84
+
85
+ previous_uuids[uuid][:conditional_uuid]
86
+ end
87
+
74
88
  private
75
89
 
76
90
  attr_reader :main_flow
77
91
  attr_accessor :ordered, :traversed, :routes, :coordinates
92
+ attr_writer :previous_uuids
78
93
 
79
94
  def route_from_start
80
95
  @route_from_start ||=
@@ -352,6 +367,16 @@ module MetadataPresenter
352
367
  trimmed_column.all?(MetadataPresenter::Spacer)
353
368
  end
354
369
 
370
+ def set_previous_uuids
371
+ @routes.each do |route|
372
+ route.flow_uuids.each do |uuid|
373
+ if previous_uuids[uuid].blank?
374
+ previous_uuids[uuid] = route.previous_uuids[uuid]
375
+ end
376
+ end
377
+ end
378
+ end
379
+
355
380
  # Each branch has a certain number of exits that require their own line
356
381
  # and arrow. When there are 'OR' conditions we need to insert additional
357
382
  # spacers into the necessary row in the column after the one the branch is
@@ -1,21 +1,27 @@
1
1
  module MetadataPresenter
2
2
  class Route
3
3
  attr_reader :traverse_from
4
- attr_accessor :flow_uuids, :routes, :row, :column
4
+ attr_accessor :flow_uuids, :routes, :row, :column, :previous_flow_uuid,
5
+ :conditional_uuid, :previous_uuids
5
6
 
6
- def initialize(service:, traverse_from:, row: 0, column: 0)
7
+ def initialize(service:, traverse_from:, row: 0, column: 0,
8
+ previous_flow_uuid: nil, conditional_uuid: nil)
7
9
  @service = service
8
10
  @traverse_from = traverse_from
9
11
  @row = row
10
12
  @column = column
13
+ @previous_flow_uuid = previous_flow_uuid
14
+ @conditional_uuid = conditional_uuid
15
+ @previous_uuids = setup_previous_uuids
11
16
  @routes = []
12
17
  @flow_uuids = []
13
18
  end
14
19
 
15
20
  def traverse
16
21
  @flow_uuid = traverse_from
17
-
18
22
  index = column
23
+ previous_uuid = previous_flow_uuid || ''
24
+
19
25
  until @flow_uuid.blank?
20
26
  if index > service.flow.size
21
27
  ActiveSupport::Notifications.instrument(
@@ -29,36 +35,27 @@ module MetadataPresenter
29
35
  flow_object = service.flow_object(@flow_uuid)
30
36
 
31
37
  if flow_object.branch?
32
- destinations = destination_uuids(flow_object)
38
+ destinations = branch_destinations(flow_object)
33
39
  # Take the first conditional destination and follow that until the end
34
40
  # of the route.
35
- @flow_uuid = destinations.shift
36
-
37
- # The remaining conditional destinations and the branch's default next
38
- # (otherwise) will be the starting point for a new Route object to be
39
- # traversed.
40
- # The default behaviour is that the next destination will be on the row
41
- # below this current route's row. This can be changed under certain
42
- # conditions in the Grid model.
43
- # Each of the destinations need to be placed in the column after the
44
- # current column.
45
- row_number = row + 1
46
- column_number = index + 1
47
- destinations.each do |uuid|
48
- @routes.push(
49
- MetadataPresenter::Route.new(
50
- service: service,
51
- traverse_from: uuid,
52
- row: row_number,
53
- column: column_number
54
- )
55
- )
56
- row_number += 1
57
- end
41
+ first_conditional = destinations.shift
42
+ set_first_conditional_previous_flow(flow_object.uuid, first_conditional)
43
+ create_destination_routes(
44
+ previous_flow_uuid: flow_object.uuid,
45
+ destinations: destinations,
46
+ row: row,
47
+ column: index
48
+ )
49
+
50
+ @flow_uuid = first_conditional[:next]
58
51
  else
59
52
  @flow_uuid = flow_object.default_next
60
53
  end
61
54
 
55
+ unless previous_uuids.key?(flow_object.uuid)
56
+ set_previous_flow(uuid: flow_object.uuid, previous_flow_uuid: previous_uuid)
57
+ end
58
+ previous_uuid = flow_object.uuid
62
59
  index += 1
63
60
  end
64
61
 
@@ -69,8 +66,64 @@ module MetadataPresenter
69
66
 
70
67
  attr_reader :service
71
68
 
72
- def destination_uuids(flow_object)
73
- flow_object.conditionals.map(&:next).push(flow_object.default_next)
69
+ def branch_destinations(flow_object)
70
+ conditionals = flow_object.conditionals.map do |conditional|
71
+ { next: conditional.next, conditional_uuid: conditional.uuid }
72
+ end
73
+
74
+ conditionals.push({ next: flow_object.default_next })
75
+ conditionals
76
+ end
77
+
78
+ def set_first_conditional_previous_flow(previous_flow_uuid, first_conditional)
79
+ set_previous_flow(
80
+ uuid: first_conditional[:next],
81
+ previous_flow_uuid: previous_flow_uuid,
82
+ conditional_uuid: first_conditional[:conditional_uuid]
83
+ )
84
+ end
85
+
86
+ def set_previous_flow(uuid:, previous_flow_uuid:, conditional_uuid: nil)
87
+ previous_uuids[uuid] = {
88
+ previous_flow_uuid: previous_flow_uuid,
89
+ conditional_uuid: conditional_uuid
90
+ }
91
+ end
92
+
93
+ # The remaining conditional destinations and the branch's default next
94
+ # (otherwise) will be the starting point for a new Route object to be
95
+ # traversed.
96
+ # The default behaviour is that the next destination will be on the row
97
+ # below this current route's row. This can be changed under certain
98
+ # conditions in the Grid model.
99
+ # Each of the destinations need to be placed in the column after the
100
+ # current column.
101
+ def create_destination_routes(previous_flow_uuid:, destinations:, row:, column:)
102
+ row_number = row + 1
103
+ column_number = column + 1
104
+ destinations.each do |destination|
105
+ @routes.push(
106
+ MetadataPresenter::Route.new(
107
+ service: service,
108
+ traverse_from: destination[:next],
109
+ previous_flow_uuid: previous_flow_uuid,
110
+ conditional_uuid: destination[:conditional_uuid],
111
+ row: row_number,
112
+ column: column_number
113
+ )
114
+ )
115
+ row_number += 1
116
+ end
117
+ end
118
+
119
+ def setup_previous_uuids
120
+ Hash[
121
+ traverse_from,
122
+ {
123
+ previous_flow_uuid: previous_flow_uuid,
124
+ conditional_uuid: conditional_uuid
125
+ }
126
+ ]
74
127
  end
75
128
  end
76
129
  end
@@ -1,3 +1,3 @@
1
1
  module MetadataPresenter
2
- VERSION = '2.15.13'.freeze
2
+ VERSION = '2.16.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metadata_presenter
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.15.13
4
+ version: 2.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - MoJ Forms
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-23 00:00:00.000000000 Z
11
+ date: 2022-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: govuk_design_system_formbuilder