metadata_presenter 2.0.2 → 2.3.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: 4e13fd4a4a17bf97e91a2e69b59a5c12c3743e0cf38ce40a1c06b9b4b9915898
4
- data.tar.gz: c35ff1dc9a73b802e01f4995a4224ac73077f1a2e00676e67e7a49095d29c6fb
3
+ metadata.gz: 0b021784e55967939a9588d2e9503b1b572668a6015c4fc5021c1b44b85d99b5
4
+ data.tar.gz: 9c6784cab9f797a215100a0c1eeb53586a5fe4c9b7ac2afe0ee0b2fa3a7b252f
5
5
  SHA512:
6
- metadata.gz: 9d456b26ddc24e8e39e586eec91f7bc4acfd2c67506bc59d70fc1fdda8e8e0846dfc27fb965b9cd67653d6cca60ef7262a691cc4e8399486db0626b157f9b789
7
- data.tar.gz: 073523ef858cf90830133c5c8f2cdc3a230b6d79c8b9794c2d156892cfbfbc8a8208f744937aa63f55cefa70d5846a533f4fa492dfbee35b8f2fa06122adbf46
6
+ metadata.gz: 94aeac55e2766b36fece298133e5a4ed8506f849f9b99c3851e3d5733800469c9512717ed666b4573a17a74f60f11a46750512e23af9ef41f2e06a974bba2549
7
+ data.tar.gz: be13444b27be0604b4bb7875dffeafb4b014c20affee27438983197eb2f40a3b5d1ca1ab72695def1e810b86d8dda84397818176ce3b53dd70c3785e0c051bc8
@@ -12,6 +12,7 @@ module MetadataPresenter
12
12
  add_component
13
13
  add_extra_component
14
14
  ].freeze
15
+ QUESTION_PAGES = %w[page.singlequestion page.multiplequestions].freeze
15
16
 
16
17
  def editable_attributes
17
18
  to_h.reject { |k, _| k.in?(NOT_EDITABLE) }
@@ -33,11 +34,19 @@ module MetadataPresenter
33
34
  to_components(metadata.extra_components, collection: :extra_components)
34
35
  end
35
36
 
36
- def components_by_type(type)
37
- supported_components = page_components(raw_type)[type]
37
+ def input_components
38
+ all_components.reject(&:content?)
39
+ end
40
+
41
+ def content_components
42
+ all_components.select(&:content?)
43
+ end
44
+
45
+ def supported_components_by_type(type)
46
+ supported = supported_components(raw_type)[type]
38
47
 
39
48
  all_components.select do |component|
40
- supported_components.include?(component.type)
49
+ supported.include?(component.type)
41
50
  end
42
51
  end
43
52
 
@@ -49,12 +58,12 @@ module MetadataPresenter
49
58
  "metadata_presenter/#{type.gsub('.', '/')}"
50
59
  end
51
60
 
52
- def input_components
53
- page_components(raw_type)[:input]
61
+ def supported_input_components
62
+ supported_components(raw_type)[:input]
54
63
  end
55
64
 
56
- def content_components
57
- page_components(raw_type)[:content]
65
+ def supported_content_components
66
+ supported_components(raw_type)[:content]
58
67
  end
59
68
 
60
69
  def upload_components
@@ -65,6 +74,10 @@ module MetadataPresenter
65
74
  type == 'page.standalone'
66
75
  end
67
76
 
77
+ def question_page?
78
+ type.in?(QUESTION_PAGES)
79
+ end
80
+
68
81
  def title
69
82
  return heading if heading?
70
83
 
@@ -87,10 +100,10 @@ module MetadataPresenter
87
100
  end
88
101
  end
89
102
 
90
- def page_components(page_type)
91
- values = Rails.application.config.page_components[page_type]
103
+ def supported_components(page_type)
104
+ values = Rails.application.config.supported_components[page_type]
92
105
  if values.blank?
93
- raise PageComponentsNotDefinedError, "No page components defined for #{page_type} in config initialiser"
106
+ raise PageComponentsNotDefinedError, "No supported components defined for #{page_type} in config initialiser"
94
107
  end
95
108
 
96
109
  values
@@ -6,24 +6,11 @@ module MetadataPresenter
6
6
  def page
7
7
  return if no_current_or_referrer_pages? || service.no_back_link?(current_page)
8
8
 
9
- return referrer_page if return_to_referrer?
10
-
11
9
  TraversedPages.new(service, user_data, current_page).last
12
10
  end
13
11
 
14
12
  private
15
13
 
16
- def referrer_page
17
- @referrer_page ||= service.find_page_by_url(URI(referrer).path)
18
- end
19
-
20
- def return_to_referrer?
21
- return false unless current_page.standalone?
22
-
23
- current_page.standalone? ||
24
- (referrer_page && referrer_page.standalone?)
25
- end
26
-
27
14
  def no_current_or_referrer_pages?
28
15
  current_page.blank? || referrer.nil?
29
16
  end
@@ -5,6 +5,13 @@ class MetadataPresenter::Service < MetadataPresenter::Metadata
5
5
  end
6
6
  end
7
7
 
8
+ def branches
9
+ collection = flow.map do |_, flow|
10
+ MetadataPresenter::Flow.new(flow)
11
+ end
12
+ collection.select { |flow| flow.type == 'flow.branch' }
13
+ end
14
+
8
15
  def flow_object(uuid)
9
16
  MetadataPresenter::Flow.new(metadata.flow[uuid])
10
17
  rescue StandardError
@@ -38,14 +45,6 @@ class MetadataPresenter::Service < MetadataPresenter::Metadata
38
45
  pages[pages.index(current_page) + 1] if current_page.present?
39
46
  end
40
47
 
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
48
  def confirmation_page
50
49
  @confirmation_page ||= pages.find do |page|
51
50
  page.type == 'page.confirmation'
@@ -57,7 +56,15 @@ class MetadataPresenter::Service < MetadataPresenter::Metadata
57
56
  end
58
57
 
59
58
  def no_back_link?(current_page)
60
- current_page == start_page || current_page == confirmation_page
59
+ current_page == start_page ||
60
+ current_page == confirmation_page ||
61
+ current_page.standalone?
62
+ end
63
+
64
+ def page_with_component(uuid)
65
+ pages.find do |page|
66
+ Array(page.components).any? { |component| component.uuid == uuid }
67
+ end
61
68
  end
62
69
 
63
70
  private
@@ -10,7 +10,7 @@ module MetadataPresenter
10
10
 
11
11
  def self.map(view:, pages:, answers:)
12
12
  user_input_pages(pages).map { |page|
13
- Array(page.components_by_type(:input)).map do |component|
13
+ Array(page.supported_components_by_type(:input)).map do |component|
14
14
  new(
15
15
  view: view,
16
16
  component: component,
@@ -16,8 +16,8 @@
16
16
  components: @page.extra_components,
17
17
  tag: nil,
18
18
  classes: nil,
19
- input_components: @page.input_components,
20
- content_components: @page.content_components
19
+ input_components: @page.supported_input_components,
20
+ content_components: @page.supported_content_components
21
21
  } %>
22
22
 
23
23
  <dl class="fb-block fb-block-answers govuk-summary-list">
@@ -80,8 +80,8 @@
80
80
  components: @page.components,
81
81
  tag: nil,
82
82
  classes: nil,
83
- input_components: @page.input_components,
84
- content_components: @page.content_components
83
+ input_components: @page.supported_input_components,
84
+ content_components: @page.supported_content_components
85
85
  } %>
86
86
 
87
87
  <button <%= 'disabled' if editable? %> data-prevent-double-click="true" class="fb-block fb-block-actions govuk-button" data-module="govuk-button" data-block-id="actions" data-block-type="actions">
@@ -29,7 +29,7 @@
29
29
  components: @page.components,
30
30
  tag: nil,
31
31
  classes: nil,
32
- input_components: @page.input_components,
33
- content_components: @page.content_components
32
+ input_components: @page.supported_input_components,
33
+ content_components: @page.supported_content_components
34
34
  } %>
35
35
  </div>
@@ -21,8 +21,8 @@
21
21
  components: @page.components,
22
22
  tag: nil,
23
23
  classes: nil,
24
- input_components: @page.input_components,
25
- content_components: @page.content_components
24
+ input_components: @page.supported_input_components,
25
+ content_components: @page.supported_content_components
26
26
  } %>
27
27
 
28
28
  <%= f.govuk_submit(disabled: editable?) %>
@@ -13,8 +13,8 @@
13
13
  components: @page.components,
14
14
  tag: :h2,
15
15
  classes: 'govuk-heading-m govuk-!-margin-top-8',
16
- input_components: @page.input_components,
17
- content_components: @page.content_components
16
+ input_components: @page.supported_input_components,
17
+ content_components: @page.supported_content_components
18
18
  }
19
19
  %>
20
20
 
@@ -1,4 +1,4 @@
1
- Rails.application.config.page_components =
1
+ Rails.application.config.supported_components =
2
2
  ActiveSupport::HashWithIndifferentAccess.new({
3
3
  checkanswers: {
4
4
  input: %w(),
@@ -1,5 +1,6 @@
1
1
  {
2
2
  "_type": "flow.branch",
3
+ "title": "",
3
4
  "next": {
4
5
  "default": "",
5
6
  "conditionals": []
@@ -1,3 +1,3 @@
1
1
  module MetadataPresenter
2
- VERSION = '2.0.2'.freeze
2
+ VERSION = '2.3.0'.freeze
3
3
  end
@@ -9,6 +9,9 @@
9
9
  "type": "string",
10
10
  "const": "flow.branch"
11
11
  },
12
+ "title": {
13
+ "type": "string"
14
+ },
12
15
  "next": {
13
16
  "type": "object",
14
17
  "properties": {
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.2
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
- - MoJ Online
7
+ - MoJ Forms
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-27 00:00:00.000000000 Z
11
+ date: 2021-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: govuk_design_system_formbuilder
@@ -254,9 +254,9 @@ dependencies:
254
254
  - - ">="
255
255
  - !ruby/object:Gem::Version
256
256
  version: '0'
257
- description: Service Metadata Presenter for the Form Builder product
257
+ description: Service Metadata Presenter for the MoJ Forms product
258
258
  email:
259
- - moj-online@digital.justice.gov.uk
259
+ - moj-forms@digital.justice.gov.uk
260
260
  executables: []
261
261
  extensions: []
262
262
  extra_rdoc_files: []
@@ -343,8 +343,8 @@ files:
343
343
  - config/initializers/default_metadata.rb
344
344
  - config/initializers/default_text.rb
345
345
  - config/initializers/inflections.rb
346
- - config/initializers/page_components.rb
347
346
  - config/initializers/schemas.rb
347
+ - config/initializers/supported_components.rb
348
348
  - config/routes.rb
349
349
  - default_metadata/component/checkboxes.json
350
350
  - default_metadata/component/content.json
@@ -453,7 +453,7 @@ files:
453
453
  - schemas/service/configuration.json
454
454
  - schemas/service/locale.json
455
455
  - schemas/validations/validations.json
456
- homepage: https://moj-online.service.justice.gov.uk
456
+ homepage: https://moj-forms.service.justice.gov.uk/
457
457
  licenses:
458
458
  - MIT
459
459
  metadata: {}