metadata_presenter 2.6.1 → 2.7.2
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48503ea21820959e21824490a615c78e27fd5b7eece419141b8105a0e91f4ad6
|
4
|
+
data.tar.gz: ad0c43095f40f524e6cec36e339a0deadc490f50d0686324cb9666827fa979ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35b20dc2f7539ae53d0360845513bb0c0859281c54c4dd21542a650636a5fb545132322e325bdc4511e176d60c629f78b46d1cd4a4fc6791c2fe573c9beb9316
|
7
|
+
data.tar.gz: 482185c1044b0013f3875255c4a94482de1882adbecb749352f4cb797c9d5a762ede00f4d3c4348c4d8c124ee5f36ddbd85fc7905ea53765965c0cafe69ff3fb
|
@@ -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
|
-
|
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
|
-
|
59
|
-
|
60
|
-
|
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
|
65
|
-
#
|
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
|
-
|
136
|
-
next if position[:row].nil? || position[:column].nil?
|
166
|
+
next if detached?(position)
|
137
167
|
|
138
|
-
|
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::
|
148
|
-
|
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?
|
@@ -13,6 +13,14 @@ class MetadataPresenter::Service < MetadataPresenter::Metadata
|
|
13
13
|
flow_objects.select { |flow| flow.type == 'flow.branch' }
|
14
14
|
end
|
15
15
|
|
16
|
+
def expressions
|
17
|
+
conditionals.map(&:expressions).flatten
|
18
|
+
end
|
19
|
+
|
20
|
+
def conditionals
|
21
|
+
branches.map(&:conditionals).flatten
|
22
|
+
end
|
23
|
+
|
16
24
|
def flow_object(uuid)
|
17
25
|
MetadataPresenter::Flow.new(uuid, metadata.flow[uuid])
|
18
26
|
rescue StandardError
|
@@ -0,0 +1,134 @@
|
|
1
|
+
{
|
2
|
+
"_id": "service.base",
|
3
|
+
"_type": "service.base",
|
4
|
+
"service_id": "bf0d28cc-d3cf-4511-9589-b360ae34a908",
|
5
|
+
"service_name": "Exit only",
|
6
|
+
"created_by": "81de07c7-461a-4425-9a0f-9ba30294ddfb",
|
7
|
+
"configuration": {
|
8
|
+
"service": {
|
9
|
+
"_id": "config.service",
|
10
|
+
"_type": "config.service"
|
11
|
+
},
|
12
|
+
"meta": {
|
13
|
+
"_id": "config.meta",
|
14
|
+
"_type": "config.meta",
|
15
|
+
"items": [
|
16
|
+
{
|
17
|
+
"_id": "config.meta--link",
|
18
|
+
"_type": "link",
|
19
|
+
"href": "cookies",
|
20
|
+
"text": "Cookies"
|
21
|
+
},
|
22
|
+
{
|
23
|
+
"_id": "config.meta--link--2",
|
24
|
+
"_type": "link",
|
25
|
+
"href": "privacy",
|
26
|
+
"text": "Privacy"
|
27
|
+
},
|
28
|
+
{
|
29
|
+
"_id": "config.meta--link--3",
|
30
|
+
"_type": "link",
|
31
|
+
"href": "accessibility",
|
32
|
+
"text": "Accessibility"
|
33
|
+
}
|
34
|
+
]
|
35
|
+
}
|
36
|
+
},
|
37
|
+
"flow": {
|
38
|
+
"82f5c5bb-a71c-425c-b29b-3fbac4ad0b87": {
|
39
|
+
"_type": "flow.page",
|
40
|
+
"next": {
|
41
|
+
"default": "db86a329-fa2d-4e36-8343-83bdf559cde0"
|
42
|
+
}
|
43
|
+
},
|
44
|
+
"db86a329-fa2d-4e36-8343-83bdf559cde0": {
|
45
|
+
"_type": "flow.page",
|
46
|
+
"next": {
|
47
|
+
"default": "ea36b7ab-9c05-4a19-8336-30936a681614"
|
48
|
+
}
|
49
|
+
},
|
50
|
+
"ea36b7ab-9c05-4a19-8336-30936a681614": {
|
51
|
+
"_type": "flow.page",
|
52
|
+
"next": {
|
53
|
+
"default": "905c3988-b803-4b01-bc38-e1d27cc6027c"
|
54
|
+
}
|
55
|
+
},
|
56
|
+
"905c3988-b803-4b01-bc38-e1d27cc6027c": {
|
57
|
+
"_type": "flow.page",
|
58
|
+
"next": {
|
59
|
+
"default": ""
|
60
|
+
}
|
61
|
+
}
|
62
|
+
},
|
63
|
+
"pages": [
|
64
|
+
{
|
65
|
+
"_id": "page.start",
|
66
|
+
"_type": "page.start",
|
67
|
+
"_uuid": "82f5c5bb-a71c-425c-b29b-3fbac4ad0b87",
|
68
|
+
"heading": "Service name goes here",
|
69
|
+
"lede": "This is your start page first paragraph. You can only have one paragraph here.",
|
70
|
+
"body": "Use this service to:\r\n\r\n* do something\r\n* update your name, address or other details\r\n* do something else\r\n\r\nRegistering takes around 5 minutes.",
|
71
|
+
"url": "/"
|
72
|
+
},
|
73
|
+
{
|
74
|
+
"_id": "page.knowhere",
|
75
|
+
"_type": "page.singlequestion",
|
76
|
+
"_uuid": "db86a329-fa2d-4e36-8343-83bdf559cde0",
|
77
|
+
"components": [
|
78
|
+
{
|
79
|
+
"_id": "page.knowhere--text.auto_knowhere__1",
|
80
|
+
"_type": "text",
|
81
|
+
"label": "Road to knowhere",
|
82
|
+
"name": "knowhere",
|
83
|
+
"validation": {
|
84
|
+
"required": true,
|
85
|
+
"max_length": 10,
|
86
|
+
"min_length": 2
|
87
|
+
}
|
88
|
+
}
|
89
|
+
],
|
90
|
+
"heading": "Road to knowhere",
|
91
|
+
"url": "knowhere"
|
92
|
+
},
|
93
|
+
{
|
94
|
+
"_id": "page.ghost",
|
95
|
+
"_type": "page.singlequestion",
|
96
|
+
"_uuid": "ea36b7ab-9c05-4a19-8336-30936a681614",
|
97
|
+
"components": [
|
98
|
+
{
|
99
|
+
"_id": "page.ghost--text.auto_ghost__1",
|
100
|
+
"_type": "text",
|
101
|
+
"label": "Ghost town",
|
102
|
+
"name": "ghost",
|
103
|
+
"validation": {
|
104
|
+
"required": true,
|
105
|
+
"max_length": 100,
|
106
|
+
"min_length": 2
|
107
|
+
}
|
108
|
+
}
|
109
|
+
],
|
110
|
+
"heading": "Ghost town",
|
111
|
+
"url": "ghost"
|
112
|
+
},
|
113
|
+
{
|
114
|
+
"_id": "page.goodbye",
|
115
|
+
"url": "page-goodbye",
|
116
|
+
"lede": "So long and thanks for all the fish",
|
117
|
+
"_type": "page.exit",
|
118
|
+
"_uuid": "905c3988-b803-4b01-bc38-e1d27cc6027c",
|
119
|
+
"heading": "Goodbye",
|
120
|
+
"components": [
|
121
|
+
{
|
122
|
+
"_id": "exit_content_1",
|
123
|
+
"name": "exit_content_1",
|
124
|
+
"_type": "content",
|
125
|
+
"_uuid": "3b9d2140-888c-4673-907d-5d885ea02143",
|
126
|
+
"content": "Goodbye!"
|
127
|
+
}
|
128
|
+
],
|
129
|
+
"section_heading": "au revoir, auf wiedersehen"
|
130
|
+
}
|
131
|
+
],
|
132
|
+
"standalone_pages": [],
|
133
|
+
"locale": "en"
|
134
|
+
}
|
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.
|
4
|
+
version: 2.7.2
|
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-
|
11
|
+
date: 2021-10-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: govuk_design_system_formbuilder
|
@@ -398,6 +398,7 @@ files:
|
|
398
398
|
- fixtures/branching_7.png
|
399
399
|
- fixtures/branching_8.json
|
400
400
|
- fixtures/branching_8.png
|
401
|
+
- fixtures/exit_only_service.json
|
401
402
|
- fixtures/invalid_content_page.json
|
402
403
|
- fixtures/no_component_page.json
|
403
404
|
- fixtures/non_finished_service.json
|