metadata_presenter 1.7.2 → 1.8.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: 5ac5fd51e02d3200c324282f394e5d8d3b11e0e440592e627290dfd7b6c767ba
4
- data.tar.gz: bced641e349533c820815867b08bfca21f7d8c0bbd619ed19615e424edcaa2a6
3
+ metadata.gz: 9cd8a230778f6c6613c3929450b98894e27119904bd6c48829f008762b84b625
4
+ data.tar.gz: e8aecfc6eff1d694b09a44ba753e4777dce8c2f42d4f7de6922d9c2d82dd0aa9
5
5
  SHA512:
6
- metadata.gz: d38891660bc18dfe3472b43b84efc4a4752be370ba88decb17aad07aa47d779282214602bd52b10db043ad9aec8cc582e2010828deb8916f4b4b40fe069165d7
7
- data.tar.gz: 289b34c930dd5c2322d6c32bb22d761c2d2f973e8ae8be7edd5104d3af2f429055ac5edbe76a56b9e78b63e48da5958e551f3e1b66a444eaa02572a41ee3febf
6
+ metadata.gz: 0fd423f52af55ecc54ff5c59e7c0f2c3a5032b129b51146bfe71f3f9a4e1ed8440984c3b5914fd87297b5c00d1cc71645d618ca49a277f57b05cb4da2f5f4daa
7
+ data.tar.gz: be951f7baf2331c9e42bdd5f9fbfd1a3adaeb5f3641a2acfb3aab00eb09b77fa5b78908a00f984da8781c6b9fe2997cfa6ef486c5c5bf4c22cb0b79f27259c8d
@@ -15,10 +15,14 @@ module MetadataPresenter
15
15
  def pages_presenters
16
16
  PageAnswersPresenter.map(
17
17
  view: view_context,
18
- pages: service.pages,
18
+ pages: answered_pages,
19
19
  answers: @user_data
20
20
  )
21
21
  end
22
22
  helper_method :pages_presenters
23
+
24
+ def answered_pages
25
+ TraversedPages.new(service, load_user_data, @page).all
26
+ end
23
27
  end
24
28
  end
@@ -1,7 +1,7 @@
1
1
  module MetadataPresenter
2
2
  class Flow < MetadataPresenter::Metadata
3
3
  def branch?
4
- type == 'branch'
4
+ type == 'flow.branch'
5
5
  end
6
6
 
7
7
  def default_next
@@ -49,11 +49,11 @@ module MetadataPresenter
49
49
  end
50
50
 
51
51
  def current_page_flow
52
- service.flow(current_page_uuid)
52
+ service.flow_object(current_page_uuid)
53
53
  end
54
54
 
55
55
  def next_flow
56
- service.flow(current_page_flow.default_next)
56
+ service.flow_object(current_page_flow.default_next)
57
57
  end
58
58
 
59
59
  def next_flow_branch_object?
@@ -9,7 +9,6 @@ module MetadataPresenter
9
9
  _uuid
10
10
  _id
11
11
  _type
12
- steps
13
12
  add_component
14
13
  add_extra_component
15
14
  ].freeze
@@ -7,7 +7,7 @@ module MetadataPresenter
7
7
  # what happens when a user enters in the middle of the flow
8
8
  return if no_current_or_referrer_pages? || service.no_back_link?(current_page)
9
9
 
10
- if flow.present?
10
+ if service.flow.present?
11
11
  return referrer_page if return_to_referrer?
12
12
 
13
13
  TraversedPages.new(service, user_data, current_page).last
@@ -16,10 +16,6 @@ module MetadataPresenter
16
16
  end
17
17
  end
18
18
 
19
- def flow
20
- service.metadata['flow']
21
- end
22
-
23
19
  private
24
20
 
25
21
  def referrer_page
@@ -5,8 +5,8 @@ class MetadataPresenter::Service < MetadataPresenter::Metadata
5
5
  end
6
6
  end
7
7
 
8
- def flow(page_uuid)
9
- MetadataPresenter::Flow.new(metadata.flow[page_uuid])
8
+ def flow_object(uuid)
9
+ MetadataPresenter::Flow.new(metadata.flow[uuid])
10
10
  rescue StandardError
11
11
  nil
12
12
  end
@@ -12,12 +12,14 @@ module MetadataPresenter
12
12
  delegate :last, to: :all
13
13
 
14
14
  def all
15
+ return latest_pages if service.flow.blank?
16
+
15
17
  page_uuid = service.start_page.uuid
16
18
 
17
- service.metadata['flow'].size.times do
19
+ service.flow.size.times do
18
20
  break if page_uuid == current_page.uuid
19
21
 
20
- flow_object = service.flow(page_uuid)
22
+ flow_object = service.flow_object(page_uuid)
21
23
 
22
24
  if flow_object.branch?
23
25
  page = EvaluateConditions.new(
@@ -36,5 +38,11 @@ module MetadataPresenter
36
38
 
37
39
  @pages
38
40
  end
41
+
42
+ def latest_pages
43
+ index = service.pages.index(current_page).to_i - 1
44
+
45
+ service.pages[0..index]
46
+ end
39
47
  end
40
48
  end
@@ -6,8 +6,11 @@ Rails.logger.info('Loading default metadata')
6
6
  default_metadata = Dir.glob("#{Rails.application.config.default_metadata_directory}/*/**")
7
7
  default_metadata.each do |metadata_file|
8
8
  metadata = JSON.parse(File.read(metadata_file))
9
- Rails.logger.info(metadata['_id'])
10
- Rails.application.config.default_metadata[metadata['_id']] = metadata
9
+
10
+ key = metadata['_id'] || metadata['_type']
11
+ Rails.logger.info(key)
12
+
13
+ Rails.application.config.default_metadata[key] = metadata
11
14
  end
12
15
 
13
16
  Rails.logger.info(
@@ -0,0 +1,7 @@
1
+ {
2
+ "_type": "flow.branch",
3
+ "next": {
4
+ "default": "",
5
+ "conditions": []
6
+ }
7
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "condition_type": "",
3
+ "next": "",
4
+ "criterias": []
5
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "operator": "",
3
+ "page": "",
4
+ "component": "",
5
+ "field": ""
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "_type": "flow.page",
3
+ "next": {
4
+ "default": ""
5
+ }
6
+ }
@@ -5,6 +5,5 @@
5
5
  "lede": "",
6
6
  "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.",
7
7
  "before_you_start": "###Before you start\r\nYou can also register by post.\r\n\r\nThe online service is also available in Welsh (Cymraeg).\r\n\r\nYou cannot register for this service if you’re in the UK illegally.",
8
- "steps": [],
9
8
  "url": "/"
10
9
  }
@@ -3,6 +3,7 @@
3
3
  "_type": "service.base",
4
4
  "service_name": "Service name",
5
5
  "configuration": {},
6
+ "flow": {},
6
7
  "pages": [],
7
8
  "standalone_pages": [],
8
9
  "locale": "en"
@@ -3,25 +3,25 @@
3
3
  "_type": "service.base",
4
4
  "flow": {
5
5
  "cf6dc32f-502c-4215-8c27-1151a45735bb": {
6
- "_type": "page",
6
+ "_type": "flow.page",
7
7
  "next": {
8
8
  "default": "9e1ba77f-f1e5-42f4-b090-437aa9af7f73"
9
9
  }
10
10
  },
11
11
  "9e1ba77f-f1e5-42f4-b090-437aa9af7f73": {
12
- "_type": "page",
12
+ "_type": "flow.page",
13
13
  "next": {
14
14
  "default": "68fbb180-9a2a-48f6-9da6-545e28b8d35a"
15
15
  }
16
16
  },
17
17
  "68fbb180-9a2a-48f6-9da6-545e28b8d35a": {
18
- "_type": "page",
18
+ "_type": "flow.page",
19
19
  "next": {
20
20
  "default": "09e91fd9-7a46-4840-adbc-244d545cfef7"
21
21
  }
22
22
  },
23
23
  "09e91fd9-7a46-4840-adbc-244d545cfef7": {
24
- "_type": "branch",
24
+ "_type": "flow.branch",
25
25
  "next": {
26
26
  "default": "0b297048-aa4d-49b6-ac74-18e069118185",
27
27
  "conditions": [
@@ -41,19 +41,19 @@
41
41
  }
42
42
  },
43
43
  "e8708909-922e-4eaf-87a5-096f7a713fcb": {
44
- "_type": "page",
44
+ "_type": "flow.page",
45
45
  "next": {
46
46
  "default": "0b297048-aa4d-49b6-ac74-18e069118185"
47
47
  }
48
48
  },
49
49
  "0b297048-aa4d-49b6-ac74-18e069118185": {
50
- "_type": "page",
50
+ "_type": "flow.page",
51
51
  "next": {
52
52
  "default": "ffadeb22-063b-4e4f-9502-bd753c706b1d"
53
53
  }
54
54
  },
55
55
  "ffadeb22-063b-4e4f-9502-bd753c706b1d": {
56
- "_type": "branch",
56
+ "_type": "flow.branch",
57
57
  "next": {
58
58
  "default": "05c3306c-0a39-42d2-9e0f-93fd49248f4e",
59
59
  "conditions": [
@@ -85,25 +85,25 @@
85
85
  }
86
86
  },
87
87
  "d4342dfd-0d09-4a91-a0ea-d7fd67e706cc": {
88
- "_type": "page",
88
+ "_type": "flow.page",
89
89
  "next": {
90
90
  "default": "05c3306c-0a39-42d2-9e0f-93fd49248f4e"
91
91
  }
92
92
  },
93
93
  "91e9f7c6-2f75-4b7d-9eb5-0cf352f7be66": {
94
- "_type": "page",
94
+ "_type": "flow.page",
95
95
  "next": {
96
96
  "default": "05c3306c-0a39-42d2-9e0f-93fd49248f4e"
97
97
  }
98
98
  },
99
99
  "05c3306c-0a39-42d2-9e0f-93fd49248f4e": {
100
- "_type": "page",
100
+ "_type": "flow.page",
101
101
  "next": {
102
102
  "default": "1d02e508-5953-4eca-af2f-9d67511c8648"
103
103
  }
104
104
  },
105
105
  "1d02e508-5953-4eca-af2f-9d67511c8648": {
106
- "_type": "branch",
106
+ "_type": "flow.branch",
107
107
  "next": {
108
108
  "default": "ef2cafe3-37e2-4533-9b0c-09a970cd38d4",
109
109
  "conditions": [
@@ -123,19 +123,19 @@
123
123
  }
124
124
  },
125
125
  "8002df6e-29ab-4cdf-b520-1d7bb931a28f": {
126
- "_type": "page",
126
+ "_type": "flow.page",
127
127
  "next": {
128
128
  "default": "ef2cafe3-37e2-4533-9b0c-09a970cd38d4"
129
129
  }
130
130
  },
131
131
  "ef2cafe3-37e2-4533-9b0c-09a970cd38d4": {
132
- "_type": "page",
132
+ "_type": "flow.page",
133
133
  "next": {
134
134
  "default": "cf8b3e18-dacf-4e91-92e1-018035961003"
135
135
  }
136
136
  },
137
137
  "cf8b3e18-dacf-4e91-92e1-018035961003": {
138
- "_type": "branch",
138
+ "_type": "flow.branch",
139
139
  "next": {
140
140
  "default": "0c022e95-0748-4dda-8ba5-12fd1d2f596b",
141
141
  "conditions": [
@@ -155,19 +155,19 @@
155
155
  }
156
156
  },
157
157
  "b5efc09c-ece7-45ae-b0b3-8a7905e25040": {
158
- "_type": "page",
158
+ "_type": "flow.page",
159
159
  "next": {
160
160
  "default": "0c022e95-0748-4dda-8ba5-12fd1d2f596b"
161
161
  }
162
162
  },
163
163
  "0c022e95-0748-4dda-8ba5-12fd1d2f596b": {
164
- "_type": "page",
164
+ "_type": "flow.page",
165
165
  "next": {
166
166
  "default": "618b7537-b42b-4551-ae7d-053afa4d9ca9"
167
167
  }
168
168
  },
169
169
  "618b7537-b42b-4551-ae7d-053afa4d9ca9": {
170
- "_type": "branch",
170
+ "_type": "flow.branch",
171
171
  "next": {
172
172
  "default": "dc7454f9-4186-48d7-b055-684d57bbcdc7",
173
173
  "conditions": [
@@ -199,25 +199,25 @@
199
199
  }
200
200
  },
201
201
  "bc666714-c0a2-4674-afe5-faff2e20d847": {
202
- "_type": "page",
202
+ "_type": "flow.page",
203
203
  "next": {
204
204
  "default": "dc7454f9-4186-48d7-b055-684d57bbcdc7"
205
205
  }
206
206
  },
207
207
  "e2887f44-5e8d-4dc0-b1de-496ab6039430": {
208
- "_type": "page",
208
+ "_type": "flow.page",
209
209
  "next": {
210
210
  "default": "dc7454f9-4186-48d7-b055-684d57bbcdc7"
211
211
  }
212
212
  },
213
213
  "dc7454f9-4186-48d7-b055-684d57bbcdc7": {
214
- "_type": "page",
214
+ "_type": "flow.page",
215
215
  "next": {
216
216
  "default": "84a347fc-8d4b-486a-9996-6a86fa9544c5"
217
217
  }
218
218
  },
219
219
  "84a347fc-8d4b-486a-9996-6a86fa9544c5": {
220
- "_type": "branch",
220
+ "_type": "flow.branch",
221
221
  "next": {
222
222
  "default": "48357db5-7c06-4e85-94b1-5e1c9d8f39eb",
223
223
  "conditions": [
@@ -261,25 +261,25 @@
261
261
  }
262
262
  },
263
263
  "2cc66e51-2c14-4023-86bf-ded49887cdb2": {
264
- "_type": "page",
264
+ "_type": "flow.page",
265
265
  "next": {
266
266
  "default": "48357db5-7c06-4e85-94b1-5e1c9d8f39eb"
267
267
  }
268
268
  },
269
269
  "f6c51f88-7be8-4cb7-bbfc-6c905727a051": {
270
- "_type": "page",
270
+ "_type": "flow.page",
271
271
  "next": {
272
272
  "default": "48357db5-7c06-4e85-94b1-5e1c9d8f39eb"
273
273
  }
274
274
  },
275
275
  "48357db5-7c06-4e85-94b1-5e1c9d8f39eb": {
276
- "_type": "page",
276
+ "_type": "flow.page",
277
277
  "next": {
278
278
  "default": "1079b5b8-abd0-4bf6-aaac-1f01e69e3b39"
279
279
  }
280
280
  },
281
281
  "1079b5b8-abd0-4bf6-aaac-1f01e69e3b39": {
282
- "_type": "branch",
282
+ "_type": "flow.branch",
283
283
  "next": {
284
284
  "default": "941137d7-a1da-43fd-994a-98a4f9ea6d46",
285
285
  "conditions": [
@@ -329,31 +329,31 @@
329
329
  }
330
330
  },
331
331
  "941137d7-a1da-43fd-994a-98a4f9ea6d46": {
332
- "_type": "page",
332
+ "_type": "flow.page",
333
333
  "next": {
334
334
  "default": "e337070b-f636-49a3-a65c-f506675265f0"
335
335
  }
336
336
  },
337
337
  "56e80942-d0a4-405a-85cd-bd1b100013d6": {
338
- "_type": "page",
338
+ "_type": "flow.page",
339
339
  "next": {
340
340
  "default": "e337070b-f636-49a3-a65c-f506675265f0"
341
341
  }
342
342
  },
343
343
  "6324cca4-7770-4765-89b9-1cdc41f49c8b": {
344
- "_type": "page",
344
+ "_type": "flow.page",
345
345
  "next": {
346
346
  "default": "e337070b-f636-49a3-a65c-f506675265f0"
347
347
  }
348
348
  },
349
349
  "e337070b-f636-49a3-a65c-f506675265f0": {
350
- "_type": "page",
350
+ "_type": "flow.page",
351
351
  "next": {
352
352
  "default": "778e364b-9a7f-4829-8eb2-510e08f156a3"
353
353
  }
354
354
  },
355
355
  "778e364b-9a7f-4829-8eb2-510e08f156a3": {
356
- "_type": "page",
356
+ "_type": "flow.page",
357
357
  "next": {
358
358
  "default": ""
359
359
  }
@@ -367,13 +367,6 @@
367
367
  "lede": "",
368
368
  "_type": "page.start",
369
369
  "_uuid": "cf6dc32f-502c-4215-8c27-1151a45735bb",
370
- "steps": [
371
- "page.name",
372
- "page.do-you-like-star-wars",
373
- "page.star-wars-knowledge",
374
- "page.check-answers",
375
- "page.confirmation"
376
- ],
377
370
  "heading": "Service name goes here",
378
371
  "before_you_start": "###Before you start\r\nYou can also register by post.\r\n\r\nThe online service is also available in Welsh (Cymraeg).\r\n\r\nYou cannot register for this service if you’re in the UK illegally."
379
372
  },
@@ -0,0 +1,190 @@
1
+ {
2
+ "_id": "service.base",
3
+ "_type": "service.base",
4
+ "pages": [
5
+ {
6
+ "_id": "page.start",
7
+ "url": "/",
8
+ "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.",
9
+ "lede": "",
10
+ "_type": "page.start",
11
+ "_uuid": "cf6dc32f-502c-4215-8c27-1151a45735bb",
12
+ "steps": [
13
+ "page.name",
14
+ "page.email-address",
15
+ "page.parent-name",
16
+ "page.check-answers",
17
+ "page.confirmation"
18
+ ],
19
+ "heading": "Service name goes here",
20
+ "before_you_start": "###Before you start\r\nYou can also register by post.\r\n\r\nThe online service is also available in Welsh (Cymraeg).\r\n\r\nYou cannot register for this service if you’re in the UK illegally."
21
+ },
22
+ {
23
+ "_id": "page.name",
24
+ "url": "name",
25
+ "body": "Body section",
26
+ "lede": "",
27
+ "_type": "page.singlequestion",
28
+ "_uuid": "9e1ba77f-f1e5-42f4-b090-437aa9af7f73",
29
+ "heading": "Question",
30
+ "components": [
31
+ {
32
+ "_id": "name_text_1",
33
+ "hint": "",
34
+ "name": "name_text_1",
35
+ "_type": "text",
36
+ "_uuid": "27d377a2-6828-44ca-87d1-b83ddac98284",
37
+ "label": "Full name",
38
+ "errors": {},
39
+ "collection": "components",
40
+ "validation": {
41
+ "required": true,
42
+ "max_length": 10,
43
+ "min_length": 2
44
+ }
45
+ }
46
+ ]
47
+ },
48
+ {
49
+ "_id": "page.email-address",
50
+ "url": "email-address",
51
+ "body": "Body section",
52
+ "lede": "",
53
+ "_type": "page.singlequestion",
54
+ "_uuid": "df1ba645-f748-46d0-ad75-f34112653e37",
55
+ "heading": "Question",
56
+ "components": [
57
+ {
58
+ "_id": "email-address_text_1",
59
+ "hint": "",
60
+ "name": "email-address_text_1",
61
+ "_type": "text",
62
+ "_uuid": "f27e5788-e784-4bfd-8b21-2fab8ce95abb",
63
+ "label": "Email address",
64
+ "errors": {
65
+ "format": {},
66
+ "required": {
67
+ "any": "Enter an email address"
68
+ },
69
+ "max_length": {
70
+ "any": "%{control} is too long."
71
+ },
72
+ "min_length": {
73
+ "any": "%{control} is too short."
74
+ }
75
+ },
76
+ "collection": "components",
77
+ "validation": {
78
+ "required": true,
79
+ "max_length": 30,
80
+ "min_length": 2
81
+ }
82
+ }
83
+ ]
84
+ },
85
+ {
86
+ "_id": "page.parent-name",
87
+ "url": "parent-name",
88
+ "body": "Body section",
89
+ "lede": "",
90
+ "_type": "page.singlequestion",
91
+ "_uuid": "4b8c6bf3-878a-4446-9198-48351b3e2185",
92
+ "heading": "Question",
93
+ "components": [
94
+ {
95
+ "_id": "parent-name_text_1",
96
+ "hint": "",
97
+ "name": "parent-name_text_1",
98
+ "_type": "text",
99
+ "_uuid": "5ad372fa-ed35-477f-b471-4d444f991210",
100
+ "label": "Parent name",
101
+ "errors": {},
102
+ "collection": "components",
103
+ "validation": {
104
+ "required": false,
105
+ "max_length": 10,
106
+ "min_length": 2
107
+ }
108
+ }
109
+ ]
110
+ },
111
+ {
112
+ "_id": "page.check-answers",
113
+ "url": "check-answers",
114
+ "_type": "page.checkanswers",
115
+ "_uuid": "e337070b-f636-49a3-a65c-f506675265f0",
116
+ "heading": "Check your answers",
117
+ "send_body": "By submitting this application you confirm that, to the best of your knowledge, the details you are providing are correct.",
118
+ "components": [
119
+ {
120
+ "_id": "check-answers_content_2",
121
+ "name": "check-answers_content_2",
122
+ "_type": "content",
123
+ "_uuid": "b065ff4f-90c5-4ba2-b4ac-c984a9dd2470",
124
+ "content": "Take the cannoli.",
125
+ "collection": "components"
126
+ }
127
+ ],
128
+ "send_heading": "Now send your application",
129
+ "add_component": "content",
130
+ "extra_components": [
131
+ {
132
+ "_id": "check-answers_content_1",
133
+ "name": "check-answers_content_1",
134
+ "_type": "content",
135
+ "_uuid": "3e6ef27e-91a6-402f-8291-b7ce669e824e",
136
+ "content": "Check yourself before you wreck yourself.",
137
+ "collection": "extra_components"
138
+ }
139
+ ],
140
+ "add_extra_component": "content"
141
+ },
142
+ {
143
+ "_id": "page.confirmation",
144
+ "url": "confirmation",
145
+ "body": "Some day I will be the most powerful Jedi ever!",
146
+ "lede": "",
147
+ "_type": "page.confirmation",
148
+ "_uuid": "778e364b-9a7f-4829-8eb2-510e08f156a3",
149
+ "heading": "Complaint sent",
150
+ "components": []
151
+ }
152
+ ],
153
+ "locale": "en",
154
+ "created_at": "2021-04-21T13:10:19Z",
155
+ "created_by": "099d5bf5-5f7b-444c-86ee-9e189cc1a369",
156
+ "service_id": "488edccd-8411-4ffb-a38b-6a96c6ac28d6",
157
+ "version_id": "27dc30c9-f7b8-4dec-973a-bd153f6797df",
158
+ "service_name": "No Flow Service Fixture",
159
+ "configuration": {
160
+ "meta": {
161
+ "_id": "config.meta",
162
+ "_type": "config.meta",
163
+ "items": [
164
+ {
165
+ "_id": "config.meta--link",
166
+ "href": "cookies",
167
+ "text": "Cookies",
168
+ "_type": "link"
169
+ },
170
+ {
171
+ "_id": "config.meta--link--2",
172
+ "href": "privacy",
173
+ "text": "Privacy",
174
+ "_type": "link"
175
+ },
176
+ {
177
+ "_id": "config.meta--link--3",
178
+ "href": "accessibility",
179
+ "text": "Accessibility",
180
+ "_type": "link"
181
+ }
182
+ ]
183
+ },
184
+ "service": {
185
+ "_id": "config.service",
186
+ "_type": "config.service"
187
+ }
188
+ },
189
+ "standalone_pages": []
190
+ }