metadata_presenter 2.7.0 → 2.9.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 80dfb6023bce9bb54a1517b1d851363f4edcd82546ad93614bdf4efb43f159d6
4
- data.tar.gz: 0402f10c2c4253b73265a3e84c4ab3c1cd736bb37808f5a1f5b1ba17d8b5e7ea
3
+ metadata.gz: 2456166b18ccc3e41ec5387fc88a53643c6ae377caf938c5f30c14684ba5f7aa
4
+ data.tar.gz: 15503786a56b715ba5001288e3f75bb98a06eeafc0629eba3eb4b7d1df420c3c
5
5
  SHA512:
6
- metadata.gz: 2f774c3fbff17f43b4e4df0cb273bad31c1f9596fdd6f16673393c8408926ae81d5a1ed058dc20014489f224d8aa1093ee0a2b2a07a152785cac783ca5ebf6e3
7
- data.tar.gz: 85f6d65d0d5066295c78a2824be48d5d640b1dd24aab41641244a4290f4e5aa136a99d2114ca57a84a265ff993f77cac11d267b876c0850a1df1e64f5915a1b0
6
+ metadata.gz: 542588576d0a629d453e7172340bdb5a6e4b5db091f9a48f7f8e058eec3a143cedc22d1da744580078636d17902302ef100d0e7acaa54eeff3ad82ff792f44c7
7
+ data.tar.gz: 271167513a3fda4ec24f93e0b07137902c30fd6fbac05fc7fe3683422fb0fdbd8a4c6a34fd0fe5fbf797543a855fca236160e63233beae0b4fd902b8ff553d05
@@ -1,10 +1,23 @@
1
1
  module MetadataPresenter
2
2
  class Spacer < OpenStruct
3
+ def type
4
+ 'flow.spacer'
5
+ end
6
+ end
7
+
8
+ class Pointer < OpenStruct
9
+ def type
10
+ 'flow.pointer'
11
+ end
3
12
  end
4
13
 
5
14
  class Grid
6
- def initialize(service)
15
+ attr_reader :start_from
16
+
17
+ def initialize(service, start_from: nil, main_flow: [])
7
18
  @service = service
19
+ @start_from = start_from
20
+ @main_flow = main_flow
8
21
  @ordered = []
9
22
  @routes = []
10
23
  @traversed = []
@@ -21,9 +34,10 @@ module MetadataPresenter
21
34
  add_rows
22
35
  add_by_coordinates
23
36
  insert_expression_spacers
37
+ trim_pointers unless main_flow.empty?
24
38
  trim_spacers
25
39
 
26
- @ordered
40
+ @ordered = @ordered.reject(&:empty?)
27
41
  end
28
42
 
29
43
  def ordered_flow
@@ -32,12 +46,20 @@ module MetadataPresenter
32
46
  end
33
47
 
34
48
  def ordered_pages
35
- ordered_flow.reject(&:branch?)
49
+ @ordered_pages ||= ordered_flow.reject(&:branch?)
50
+ end
51
+
52
+ def flow_uuids
53
+ ordered_flow.map(&:uuid)
54
+ end
55
+
56
+ def page_uuids
57
+ ordered_pages.map(&:uuid)
36
58
  end
37
59
 
38
60
  private
39
61
 
40
- attr_reader :service
62
+ attr_reader :service, :main_flow
41
63
  attr_accessor :ordered, :traversed, :routes, :coordinates
42
64
 
43
65
  def setup_coordinates
@@ -48,21 +70,30 @@ module MetadataPresenter
48
70
  @route_from_start ||=
49
71
  MetadataPresenter::Route.new(
50
72
  service: service,
51
- traverse_from: service.start_page.uuid
73
+ traverse_from: start_from || service.start_page.uuid
52
74
  )
53
75
  end
54
76
 
55
77
  def make_grid
56
78
  traverse_all_routes
57
79
 
58
- rows = @routes.map(&:row).max
59
- columns = @routes.map { |r| r.column + r.flow_uuids.count }.max
60
- columns.times.map { rows.times.map { MetadataPresenter::Spacer.new } }
80
+ max_potential_columns.times.map do
81
+ max_potential_rows.times.map { MetadataPresenter::Spacer.new }
82
+ end
83
+ end
84
+
85
+ def max_potential_rows
86
+ @max_potential_rows ||= @routes.map(&:row).max + 1
87
+ end
88
+
89
+ def max_potential_columns
90
+ @routes.map { |r| r.column + r.flow_uuids.count }.max + 1
61
91
  end
62
92
 
63
93
  def traverse_all_routes
64
- # Always traverse the route that begins from the start page first and get
65
- # the potential routes from any branching points that exist.
94
+ # Always traverse the route from the start_from uuid. Defaulting to the
95
+ # start page of the form unless otherwise specified.
96
+ # Get all the potential routes from any branching points that exist.
66
97
  route_from_start.traverse
67
98
  @routes.append(route_from_start)
68
99
  traversed_routes = route_from_start.routes
@@ -132,23 +163,58 @@ module MetadataPresenter
132
163
 
133
164
  def add_by_coordinates
134
165
  @coordinates.each do |uuid, position|
135
- # If row and column are nil then the object is detached
136
- next if position[:row].nil? || position[:column].nil?
166
+ next if detached?(position)
137
167
 
138
- flow_object = service.flow_object(uuid)
139
- @ordered[position[:column]][position[:row]] = flow_object
168
+ @ordered[position[:column]][position[:row]] = get_flow_object(uuid)
140
169
  end
141
170
  end
142
171
 
172
+ def detached?(position)
173
+ position[:row].nil? || position[:column].nil?
174
+ end
175
+
176
+ def get_flow_object(uuid)
177
+ # main_flow is always empty if the Grid is _actually_ building the main flow
178
+ return MetadataPresenter::Pointer.new(uuid: uuid) if main_flow.include?(uuid)
179
+
180
+ service.flow_object(uuid)
181
+ end
182
+
183
+ # A row should end at the first Pointer object it finds.
184
+ # Therefore replace any Pointers after the first one with Spacers.
185
+ def trim_pointers
186
+ max_potential_rows.times do |row|
187
+ first_index_of = first_pointer(row)
188
+ next unless first_index_of
189
+
190
+ next_column = first_index_of + 1
191
+ @ordered.drop(next_column).each do |column|
192
+ column[row] = MetadataPresenter::Spacer.new
193
+ end
194
+ end
195
+ end
196
+
197
+ def first_pointer(row)
198
+ row_objects = @ordered.map { |column| column[row] }
199
+ row_objects.find_index { |obj| obj.is_a?(MetadataPresenter::Pointer) }
200
+ end
201
+
143
202
  # Find the very last MetadataPresenter::Flow object in every column and
144
203
  # remove any Spacer objects after that.
145
204
  def trim_spacers
146
205
  @ordered.each_with_index do |column, index|
147
- last_index_of = column.rindex { |item| item.is_a?(MetadataPresenter::Flow) }
148
- @ordered[index] = @ordered[index][0..last_index_of]
206
+ last_index_of = column.rindex { |item| !item.is_a?(MetadataPresenter::Spacer) }
207
+ trimmed_column = @ordered[index][0..last_index_of]
208
+
209
+ # We do not need any columns that only contain Spacer objects
210
+ @ordered[index] = only_spacers?(trimmed_column) ? [] : trimmed_column
149
211
  end
150
212
  end
151
213
 
214
+ def only_spacers?(trimmed_column)
215
+ trimmed_column.all? { |item| item.is_a?(MetadataPresenter::Spacer) }
216
+ end
217
+
152
218
  # Each branch has a certain number of exits that require their own line
153
219
  # and arrow. Insert any spacers into the necessary row in the column after
154
220
  # the one the branch is located in.
@@ -20,6 +20,11 @@ module MetadataPresenter
20
20
  page.multiplequestions
21
21
  page.exit
22
22
  ].freeze
23
+ END_OF_ROUTE_PAGES = %w[
24
+ page.checkanswers
25
+ page.confirmation
26
+ page.exit
27
+ ].freeze
23
28
 
24
29
  def editable_attributes
25
30
  to_h.reject { |k, _| k.in?(NOT_EDITABLE) }
@@ -91,6 +96,10 @@ module MetadataPresenter
91
96
  components.first.humanised_title
92
97
  end
93
98
 
99
+ def end_of_route?
100
+ type.in?(END_OF_ROUTE_PAGES)
101
+ end
102
+
94
103
  private
95
104
 
96
105
  def heading?
@@ -1,4 +1,5 @@
1
1
  {
2
+ "_uuid": "",
2
3
  "_type": "",
3
4
  "next": "",
4
5
  "expressions": []
@@ -27,6 +27,7 @@
27
27
  "default": "0b297048-aa4d-49b6-ac74-18e069118185",
28
28
  "conditionals": [
29
29
  {
30
+ "_uuid": "ecd60ac9-c3ea-47b1-8f79-c4e42df9a9dd",
30
31
  "_type": "if",
31
32
  "next": "e8708909-922e-4eaf-87a5-096f7a713fcb",
32
33
  "expressions": [
@@ -60,6 +61,7 @@
60
61
  "default": "05c3306c-0a39-42d2-9e0f-93fd49248f4e",
61
62
  "conditionals": [
62
63
  {
64
+ "_uuid": "51b4eda2-a08d-4ab3-a8cb-565091f39424",
63
65
  "_type": "if",
64
66
  "next": "d4342dfd-0d09-4a91-a0ea-d7fd67e706cc",
65
67
  "expressions": [
@@ -72,6 +74,7 @@
72
74
  ]
73
75
  },
74
76
  {
77
+ "_uuid": "0a799cea-f5a4-4b89-9ffe-78515b5cb1d7",
75
78
  "_type": "if",
76
79
  "next": "91e9f7c6-2f75-4b7d-9eb5-0cf352f7be66",
77
80
  "expressions": [
@@ -111,6 +114,7 @@
111
114
  "default": "ef2cafe3-37e2-4533-9b0c-09a970cd38d4",
112
115
  "conditionals": [
113
116
  {
117
+ "_uuid": "0d3410db-1d05-4a32-bafb-65b52408b89b",
114
118
  "_type": "if",
115
119
  "next": "8002df6e-29ab-4cdf-b520-1d7bb931a28f",
116
120
  "expressions": [
@@ -144,6 +148,7 @@
144
148
  "default": "0c022e95-0748-4dda-8ba5-12fd1d2f596b",
145
149
  "conditionals": [
146
150
  {
151
+ "_uuid": "88b97d53-1da7-4464-a0a5-633a9ffd3d3d",
147
152
  "_type": "if",
148
153
  "next": "b5efc09c-ece7-45ae-b0b3-8a7905e25040",
149
154
  "expressions": [
@@ -177,6 +182,7 @@
177
182
  "default": "dc7454f9-4186-48d7-b055-684d57bbcdc7",
178
183
  "conditionals": [
179
184
  {
185
+ "_uuid": "8a0c225f-b078-4728-a181-c3bdd343801c",
180
186
  "_type": "if",
181
187
  "next": "bc666714-c0a2-4674-afe5-faff2e20d847",
182
188
  "expressions": [
@@ -189,6 +195,7 @@
189
195
  ]
190
196
  },
191
197
  {
198
+ "_uuid": "7d1b29ac-f310-4246-bab9-957c9b2a20f2",
192
199
  "_type": "if",
193
200
  "next": "e2887f44-5e8d-4dc0-b1de-496ab6039430",
194
201
  "expressions": [
@@ -228,6 +235,7 @@
228
235
  "default": "48357db5-7c06-4e85-94b1-5e1c9d8f39eb",
229
236
  "conditionals": [
230
237
  {
238
+ "_uuid": "15e8076f-75ac-4310-89b3-d2b5962babd4",
231
239
  "_type": "or",
232
240
  "next": "2cc66e51-2c14-4023-86bf-ded49887cdb2",
233
241
  "expressions": [
@@ -246,6 +254,7 @@
246
254
  ]
247
255
  },
248
256
  {
257
+ "_uuid": "0811ac93-a73e-4a2d-a8f1-68cc8a52ca69",
249
258
  "_type": "and",
250
259
  "next": "f6c51f88-7be8-4cb7-bbfc-6c905727a051",
251
260
  "expressions": [
@@ -291,6 +300,7 @@
291
300
  "default": "941137d7-a1da-43fd-994a-98a4f9ea6d46",
292
301
  "conditionals": [
293
302
  {
303
+ "_uuid": "5ce78103-3935-4c57-9278-79bf2b8b93b1",
294
304
  "_type": "and",
295
305
  "next": "56e80942-d0a4-405a-85cd-bd1b100013d6",
296
306
  "expressions": [
@@ -315,6 +325,7 @@
315
325
  ]
316
326
  },
317
327
  {
328
+ "_uuid": "d45c65c7-a9b4-4128-8562-89bd4f0167ec",
318
329
  "_type": "or",
319
330
  "next": "6324cca4-7770-4765-89b9-1cdc41f49c8b",
320
331
  "expressions": [
@@ -21,6 +21,7 @@
21
21
  "default": "f475d6fd-0ea4-45d5-985e-e1a7c7a5b992",
22
22
  "conditionals": [
23
23
  {
24
+ "_uuid": "b753b3f0-188e-4435-a84d-894557ba2007",
24
25
  "_type": "if",
25
26
  "next": "e8708909-922e-4eaf-87a5-096f7a713fcb",
26
27
  "expressions": [
@@ -33,6 +34,7 @@
33
34
  ]
34
35
  },
35
36
  {
37
+ "_uuid": "2622668f-7ad2-4130-9d4f-274ff540b7e8",
36
38
  "_type": "if",
37
39
  "next": "3a584d15-6805-4a21-bc05-b61c3be47857",
38
40
  "expressions": [
@@ -102,6 +104,7 @@
102
104
  "default": "d80a2225-63c3-4944-873f-504b61311a15",
103
105
  "conditionals": [
104
106
  {
107
+ "_uuid": "f51a3793-53dc-4537-b84b-399a59c103f4",
105
108
  "_type": "if",
106
109
  "next": "be130ac1-f33d-4845-807d-89b23b90d205",
107
110
  "expressions": [
@@ -21,6 +21,7 @@
21
21
  "default": "be130ac1-f33d-4845-807d-89b23b90d205",
22
22
  "conditionals": [
23
23
  {
24
+ "_uuid": "39bab61b-93d5-486c-8e02-cea0aeb48215",
24
25
  "_type": "if",
25
26
  "next": "e8708909-922e-4eaf-87a5-096f7a713fcb",
26
27
  "expressions": [
@@ -33,6 +34,7 @@
33
34
  ]
34
35
  },
35
36
  {
37
+ "_uuid": "96810acb-b5e6-45c1-bacb-6b7a10c0d3a0",
36
38
  "_type": "if",
37
39
  "next": "3a584d15-6805-4a21-bc05-b61c3be47857",
38
40
  "expressions": [
@@ -33,6 +33,7 @@
33
33
  "default": "520fde26-8124-4c67-a550-cd38d2ef304d",
34
34
  "conditionals": [
35
35
  {
36
+ "_uuid": "457ca1ed-b188-4980-bf9b-01f8dde5ffe9",
36
37
  "_type": "if",
37
38
  "next": "37a94466-97fa-427f-88b2-09b369435d0d",
38
39
  "expressions": [
@@ -21,6 +21,7 @@
21
21
  "default": "f475d6fd-0ea4-45d5-985e-e1a7c7a5b992",
22
22
  "conditionals": [
23
23
  {
24
+ "_uuid": "91965137-99bd-4bcf-b9c3-61afaa7fc5c0",
24
25
  "_type": "if",
25
26
  "next": "e8708909-922e-4eaf-87a5-096f7a713fcb",
26
27
  "expressions": [
@@ -33,6 +34,7 @@
33
34
  ]
34
35
  },
35
36
  {
37
+ "_uuid": "10396fae-c28c-445c-a633-14d6439271a8",
36
38
  "_type": "if",
37
39
  "next": "3a584d15-6805-4a21-bc05-b61c3be47857",
38
40
  "expressions": [
@@ -90,6 +92,7 @@
90
92
  "default": "d80a2225-63c3-4944-873f-504b61311a15",
91
93
  "conditionals": [
92
94
  {
95
+ "_uuid": "a2312258-bcbe-48b0-b30c-37d51caaf756",
93
96
  "_type": "if",
94
97
  "next": "be130ac1-f33d-4845-807d-89b23b90d205",
95
98
  "expressions": [
@@ -33,6 +33,7 @@
33
33
  "default": "520fde26-8124-4c67-a550-cd38d2ef304d",
34
34
  "conditionals": [
35
35
  {
36
+ "_uuid": "b65ad907-d415-4139-8955-9e9a3d119b50",
36
37
  "_type": "if",
37
38
  "next": "37a94466-97fa-427f-88b2-09b369435d0d",
38
39
  "expressions": [
@@ -33,6 +33,7 @@
33
33
  "default": "520fde26-8124-4c67-a550-cd38d2ef304d",
34
34
  "conditionals": [
35
35
  {
36
+ "_uuid": "2d87a4bf-d532-48f5-956c-31ba5d046f63",
36
37
  "_type": "if",
37
38
  "next": "37a94466-97fa-427f-88b2-09b369435d0d",
38
39
  "expressions": [
@@ -96,6 +97,7 @@
96
97
  "default": "3a584d15-6805-4a21-bc05-b61c3be47857",
97
98
  "conditionals": [
98
99
  {
100
+ "_uuid": "daccbe9d-f0dc-41eb-8182-c542bfaa015c",
99
101
  "_type": "if",
100
102
  "next": "13ecf9bd-5064-4cad-baf8-3dfa091928cb",
101
103
  "expressions": [
@@ -108,6 +110,7 @@
108
110
  ]
109
111
  },
110
112
  {
113
+ "_uuid": "b4eaf825-a523-4372-a15b-072b016b0ead",
111
114
  "_type": "if",
112
115
  "next": "be130ac1-f33d-4845-807d-89b23b90d205",
113
116
  "expressions": [
@@ -33,6 +33,7 @@
33
33
  "default": "520fde26-8124-4c67-a550-cd38d2ef304d",
34
34
  "conditionals": [
35
35
  {
36
+ "_uuid": "830295ec-8758-4128-a8ae-c90d2fb3b840",
36
37
  "_type": "if",
37
38
  "next": "37a94466-97fa-427f-88b2-09b369435d0d",
38
39
  "expressions": [
@@ -84,6 +85,7 @@
84
85
  "default": "3a584d15-6805-4a21-bc05-b61c3be47857",
85
86
  "conditionals": [
86
87
  {
88
+ "_uuid": "957e523e-663f-4cc9-9e8a-36b15bcbcaec",
87
89
  "_type": "if",
88
90
  "next": "13ecf9bd-5064-4cad-baf8-3dfa091928cb",
89
91
  "expressions": [
@@ -96,6 +98,7 @@
96
98
  ]
97
99
  },
98
100
  {
101
+ "_uuid": "b89817e7-c426-4a9a-8814-6ca2ce56f643",
99
102
  "_type": "if",
100
103
  "next": "be130ac1-f33d-4845-807d-89b23b90d205",
101
104
  "expressions": [
@@ -1,3 +1,3 @@
1
1
  module MetadataPresenter
2
- VERSION = '2.7.0'.freeze
2
+ VERSION = '2.9.0'.freeze
3
3
  end
@@ -31,6 +31,11 @@
31
31
  "items": {
32
32
  "type": "object",
33
33
  "properties": {
34
+ "_uuid": {
35
+ "type": "string",
36
+ "title": "Unique identifier of the conditional",
37
+ "description": "Used internally in the editor and the runner"
38
+ },
34
39
  "_type": {
35
40
  "type": "string",
36
41
  "enum": [
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.7.0
4
+ version: 2.9.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: 2021-10-07 00:00:00.000000000 Z
11
+ date: 2021-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: govuk_design_system_formbuilder