metadata_presenter 2.0.0 → 2.1.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: 10a6602fbd7108b4fe94aa7d3dd4037236d051701bc7b9b41b73d5af5598c506
4
- data.tar.gz: e0802516349bf5827a653d756f14c70e827bb7ec7e8a6bfbe6d321bfb565387a
3
+ metadata.gz: 406a99897f2deb6565befd01bdc1fd12f67b3bf9cb71e77fc36b8ab3550c3e31
4
+ data.tar.gz: c2b1e8bdbc48df0357c1f0107f4a619e96bedf17dd110322f43b38e93239685a
5
5
  SHA512:
6
- metadata.gz: 75c775d98418d5b1b52a07210b51b95bc122c191b261bd0c8a8b195768747cc60ad6282d14d770ca11f45eeaa36108c7aa22bd59b24dfb30614fcd012db09a8b
7
- data.tar.gz: 71166dba57d1a2362d60583c57da0bbf7d145fd2f6e338dedf15124d74af3f47c215e72063b3efce5163075b71c33f646c5d94e93a3525dd83c4ae3732b31530
6
+ metadata.gz: 7b80e8327eac16728d8c918f5f32d87a56e4cb506ccd043cfa13e48819ded49da44ec6782e9460872239e7bb7443975dc5a7f1aa36a9d34100a71fa08b3b1d03
7
+ data.tar.gz: dfaf82d1c09c14edaf1e11b382401ef9394fc35686b9e53875263a43516ad6b1735e30d3dcd9201c18e189956898da4b3c1286ccb170369a1db3b7c43609a7cf
@@ -13,6 +13,12 @@ class MetadataPresenter::Component < MetadataPresenter::Metadata
13
13
  end
14
14
  end
15
15
 
16
+ SUPPORTS_BRANCHING = %w[radios checkboxes].freeze
17
+
18
+ def supports_branching?
19
+ type.in?(SUPPORTS_BRANCHING)
20
+ end
21
+
16
22
  def content?
17
23
  type == 'content'
18
24
  end
@@ -8,10 +8,8 @@ module MetadataPresenter
8
8
 
9
9
  if conditionals?
10
10
  evaluate_conditionals
11
- elsif current_page_flow.present?
12
- service.find_page_by_uuid(current_page_flow.default_next)
13
11
  else
14
- service.next_page(from: current_page_url)
12
+ service.find_page_by_uuid(current_page_flow.default_next)
15
13
  end
16
14
  end
17
15
 
@@ -65,8 +65,19 @@ module MetadataPresenter
65
65
  type == 'page.standalone'
66
66
  end
67
67
 
68
+ def title
69
+ return heading if heading?
70
+
71
+ components.first.humanised_title
72
+ end
73
+
68
74
  private
69
75
 
76
+ def heading?
77
+ Array(components).size != 1 ||
78
+ type.in?(['page.content', 'page.checkanswers', 'page.confirmation'])
79
+ end
80
+
70
81
  def to_components(node_components, collection:)
71
82
  node_components&.map do |component|
72
83
  MetadataPresenter::Component.new(
@@ -4,29 +4,13 @@ module MetadataPresenter
4
4
  attr_accessor :service, :user_data, :current_page, :referrer
5
5
 
6
6
  def page
7
- # what happens when a user enters in the middle of the flow
8
7
  return if no_current_or_referrer_pages? || service.no_back_link?(current_page)
9
8
 
10
- if service.flow.present?
11
- return referrer_page if return_to_referrer?
12
-
13
- TraversedPages.new(service, user_data, current_page).last
14
- else
15
- service.previous_page(current_page: current_page, referrer: referrer)
16
- end
9
+ TraversedPages.new(service, user_data, current_page).last
17
10
  end
18
11
 
19
12
  private
20
13
 
21
- def referrer_page
22
- @referrer_page ||= service.find_page_by_url(URI(referrer).path)
23
- end
24
-
25
- def return_to_referrer?
26
- current_page.standalone? ||
27
- (referrer_page && referrer_page.standalone?)
28
- end
29
-
30
14
  def no_current_or_referrer_pages?
31
15
  current_page.blank? || referrer.nil?
32
16
  end
@@ -38,14 +38,6 @@ class MetadataPresenter::Service < MetadataPresenter::Metadata
38
38
  pages[pages.index(current_page) + 1] if current_page.present?
39
39
  end
40
40
 
41
- def previous_page(current_page:, referrer:)
42
- return if current_page.nil? || referrer.nil?
43
-
44
- unless no_back_link?(current_page)
45
- flow_page(current_page) || referrer_page(referrer)
46
- end
47
- end
48
-
49
41
  def confirmation_page
50
42
  @confirmation_page ||= pages.find do |page|
51
43
  page.type == 'page.confirmation'
@@ -57,7 +49,15 @@ class MetadataPresenter::Service < MetadataPresenter::Metadata
57
49
  end
58
50
 
59
51
  def no_back_link?(current_page)
60
- current_page == start_page || current_page == confirmation_page
52
+ current_page == start_page ||
53
+ current_page == confirmation_page ||
54
+ current_page.standalone?
55
+ end
56
+
57
+ def page_with_component(uuid)
58
+ pages.find do |page|
59
+ Array(page.components).any? { |component| component.uuid == uuid }
60
+ end
61
61
  end
62
62
 
63
63
  private
@@ -12,8 +12,6 @@ module MetadataPresenter
12
12
  delegate :last, to: :all
13
13
 
14
14
  def all
15
- return latest_pages if service.flow.blank?
16
-
17
15
  page_uuid = service.start_page.uuid
18
16
 
19
17
  service.flow.size.times do
@@ -33,6 +33,20 @@
33
33
  ]
34
34
  }
35
35
  },
36
+ "flow": {
37
+ "9626b2e9-5ef0-4070-8331-ac55151b22c4": {
38
+ "_type": "flow.page",
39
+ "next": {
40
+ "default": "1ed3e4ad-5098-41c9-b4b6-426e89f7804e"
41
+ }
42
+ },
43
+ "1ed3e4ad-5098-41c9-b4b6-426e89f7804e": {
44
+ "_type": "flow.page",
45
+ "next": {
46
+ "default": ""
47
+ }
48
+ }
49
+ },
36
50
  "pages": [
37
51
  {
38
52
  "_uuid": "9626b2e9-5ef0-4070-8331-ac55151b22c4",
@@ -42,7 +56,6 @@
42
56
  "lede": "Use this service to:",
43
57
  "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.",
44
58
  "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.",
45
- "steps": [],
46
59
  "url": "/"
47
60
  },
48
61
  {
@@ -33,6 +33,20 @@
33
33
  ]
34
34
  }
35
35
  },
36
+ "flow": {
37
+ "9626b2e9-5ef0-4070-8331-ac55151b22c4": {
38
+ "_type": "flow.page",
39
+ "next": {
40
+ "default": "1ed3e4ad-5098-41c9-b4b6-426e89f7804e"
41
+ }
42
+ },
43
+ "b238a22f-c180-48d0-a7d9-8aad2036f1f2": {
44
+ "_type": "flow.page",
45
+ "next": {
46
+ "default": ""
47
+ }
48
+ }
49
+ },
36
50
  "pages": [
37
51
  {
38
52
  "_uuid": "9626b2e9-5ef0-4070-8331-ac55151b22c4",
@@ -42,7 +56,6 @@
42
56
  "lede": "Use this service to:",
43
57
  "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.",
44
58
  "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.",
45
- "steps": [],
46
59
  "url": "/"
47
60
  },
48
61
  {
@@ -34,23 +34,46 @@
34
34
  ]
35
35
  }
36
36
  },
37
+ "flow": {
38
+ "cf6dc32f-502c-4215-8c27-1151a45735bb": {
39
+ "_type": "flow.page",
40
+ "next": {
41
+ "default": "9e1ba77f-f1e5-42f4-b090-437aa9af7f73"
42
+ }
43
+ },
44
+ "9e1ba77f-f1e5-42f4-b090-437aa9af7f73": {
45
+ "_type": "flow.page",
46
+ "next": {
47
+ "default": "68fbb180-9a2a-48f6-9da6-545e28b8d35a"
48
+ }
49
+ },
50
+ "68fbb180-9a2a-48f6-9da6-545e28b8d35a": {
51
+ "_type": "flow.page",
52
+ "next": {
53
+ "default": "09e91fd9-7a46-4840-adbc-244d545cfef7"
54
+ }
55
+ },
56
+ "09e91fd9-7a46-4840-adbc-244d545cfef7": {
57
+ "_type": "flow.page",
58
+ "next": {
59
+ "default": ""
60
+ }
61
+ }
62
+ },
37
63
  "pages": [
38
64
  {
39
65
  "_id": "page.start",
40
66
  "_type": "page.start",
67
+ "_uuid": "cf6dc32f-502c-4215-8c27-1151a45735bb",
41
68
  "heading": "Service name goes here",
42
69
  "lede": "This is your start page first paragraph. You can only have one paragraph here.",
43
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.",
44
- "steps": [
45
- "page.name",
46
- "page.email-address",
47
- "page.parent_name"
48
- ],
49
71
  "url": "/"
50
72
  },
51
73
  {
52
74
  "_id": "page.name",
53
75
  "_type": "page.singlequestion",
76
+ "_uuid": "9e1ba77f-f1e5-42f4-b090-437aa9af7f73",
54
77
  "components": [
55
78
  {
56
79
  "_id": "page.name--text.auto_name__1",
@@ -70,6 +93,7 @@
70
93
  {
71
94
  "_id": "page.email-address",
72
95
  "_type": "page.singlequestion",
96
+ "_uuid": "68fbb180-9a2a-48f6-9da6-545e28b8d35a",
73
97
  "heading": "Email address",
74
98
  "components": [
75
99
  {
@@ -101,6 +125,7 @@
101
125
  {
102
126
  "_id": "page.parent_name",
103
127
  "_type": "page.singlequestion",
128
+ "_uuid": "09e91fd9-7a46-4840-adbc-244d545cfef7",
104
129
  "components": [
105
130
  {
106
131
  "_id": "page.parent-name--text.auto_name__3",
@@ -1,6 +1,14 @@
1
1
  {
2
2
  "_id": "service.base",
3
3
  "_type": "service.base",
4
+ "flow": {
5
+ "86ed04ac-1727-4172-8dd2-608009f1a656": {
6
+ "_type": "flow.page",
7
+ "next": {
8
+ "default": ""
9
+ }
10
+ }
11
+ },
4
12
  "pages": [
5
13
  {
6
14
  "_id": "page.start",
@@ -9,7 +17,6 @@
9
17
  "lede": "",
10
18
  "_type": "page.start",
11
19
  "_uuid": "86ed04ac-1727-4172-8dd2-608009f1a656",
12
- "steps": [],
13
20
  "heading": "Service name goes here",
14
21
  "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."
15
22
  }
@@ -1,6 +1,92 @@
1
1
  {
2
2
  "_id": "service.base",
3
3
  "_type": "service.base",
4
+ "flow": {
5
+ "cf6dc32f-502c-4215-8c27-1151a45735bb": {
6
+ "_type": "flow.page",
7
+ "next": {
8
+ "default": "9e1ba77f-f1e5-42f4-b090-437aa9af7f73"
9
+ }
10
+ },
11
+ "9e1ba77f-f1e5-42f4-b090-437aa9af7f73": {
12
+ "_type": "flow.page",
13
+ "next": {
14
+ "default": "df1ba645-f748-46d0-ad75-f34112653e37"
15
+ }
16
+ },
17
+ "df1ba645-f748-46d0-ad75-f34112653e37": {
18
+ "_type": "flow.page",
19
+ "next": {
20
+ "default": "4b8c6bf3-878a-4446-9198-48351b3e2185"
21
+ }
22
+ },
23
+ "4b8c6bf3-878a-4446-9198-48351b3e2185": {
24
+ "_type": "flow.page",
25
+ "next": {
26
+ "default": "54ccc6cd-60c0-4749-947b-a97af1bc0aa2"
27
+ }
28
+ },
29
+ "54ccc6cd-60c0-4749-947b-a97af1bc0aa2": {
30
+ "_type": "flow.page",
31
+ "next": {
32
+ "default": "b8335af2-6642-4e2f-8192-0dd12279eec7"
33
+ }
34
+ },
35
+ "b8335af2-6642-4e2f-8192-0dd12279eec7": {
36
+ "_type": "flow.page",
37
+ "next": {
38
+ "default": "68fbb180-9a2a-48f6-9da6-545e28b8d35a"
39
+ }
40
+ },
41
+ "68fbb180-9a2a-48f6-9da6-545e28b8d35a": {
42
+ "_type": "flow.page",
43
+ "next": {
44
+ "default": "7806cd64-0c05-450e-ba6f-2325c8b22d46"
45
+ }
46
+ },
47
+ "7806cd64-0c05-450e-ba6f-2325c8b22d46": {
48
+ "_type": "flow.page",
49
+ "next": {
50
+ "default": "0c022e95-0748-4dda-8ba5-12fd1d2f596b"
51
+ }
52
+ },
53
+ "0c022e95-0748-4dda-8ba5-12fd1d2f596b": {
54
+ "_type": "flow.page",
55
+ "next": {
56
+ "default": "e8708909-922e-4eaf-87a5-096f7a713fcb"
57
+ }
58
+ },
59
+ "e8708909-922e-4eaf-87a5-096f7a713fcb": {
60
+ "_type": "flow.page",
61
+ "next": {
62
+ "default": "80420693-d6f2-4fce-a860-777ca774a6f5"
63
+ }
64
+ },
65
+ "80420693-d6f2-4fce-a860-777ca774a6f5": {
66
+ "_type": "flow.page",
67
+ "next": {
68
+ "default": "2ef7d11e-0307-49e9-9fe2-345dc528dd66"
69
+ }
70
+ },
71
+ "2ef7d11e-0307-49e9-9fe2-345dc528dd66": {
72
+ "_type": "flow.page",
73
+ "next": {
74
+ "default": "e337070b-f636-49a3-a65c-f506675265f0"
75
+ }
76
+ },
77
+ "e337070b-f636-49a3-a65c-f506675265f0": {
78
+ "_type": "flow.page",
79
+ "next": {
80
+ "default": "778e364b-9a7f-4829-8eb2-510e08f156a3"
81
+ }
82
+ },
83
+ "778e364b-9a7f-4829-8eb2-510e08f156a3": {
84
+ "_type": "flow.page",
85
+ "next": {
86
+ "default": ""
87
+ }
88
+ }
89
+ },
4
90
  "pages": [
5
91
  {
6
92
  "_id": "page.start",
@@ -9,21 +95,6 @@
9
95
  "lede": "",
10
96
  "_type": "page.start",
11
97
  "_uuid": "cf6dc32f-502c-4215-8c27-1151a45735bb",
12
- "steps": [
13
- "page.name",
14
- "page.email-address",
15
- "page.parent-name",
16
- "page.your-age",
17
- "page.family-hobbies",
18
- "page.do-you-like-star-wars",
19
- "page.holiday",
20
- "page.burgers",
21
- "page.star-wars-knowledge",
22
- "page.how-many-lights",
23
- "page.dog-picture",
24
- "page.check-answers",
25
- "page.confirmation"
26
- ],
27
98
  "heading": "Service name goes here",
28
99
  "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."
29
100
  },
@@ -1,3 +1,3 @@
1
1
  module MetadataPresenter
2
- VERSION = '2.0.0'.freeze
2
+ VERSION = '2.1.1'.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.0.0
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - MoJ Online
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-14 00:00:00.000000000 Z
11
+ date: 2021-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: govuk_design_system_formbuilder
@@ -382,12 +382,9 @@ files:
382
382
  - fixtures/branching.json
383
383
  - fixtures/invalid_content_page.json
384
384
  - fixtures/no_component_page.json
385
- - fixtures/no_flow_service.json
386
385
  - fixtures/non_finished_service.json
387
386
  - fixtures/service.json
388
- - fixtures/service_with_flow.json
389
387
  - fixtures/version.json
390
- - fixtures/version_with_flow.json
391
388
  - lib/metadata_presenter.rb
392
389
  - lib/metadata_presenter/engine.rb
393
390
  - lib/metadata_presenter/test_helpers.rb
@@ -1,190 +0,0 @@
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
- }