metadata_presenter 0.19.1 → 0.22.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: 927d4a58d76571c185ffc90cae54f4924c1d2f7e67b1b82be7e4dbe07aa3b814
4
- data.tar.gz: ee66e0dc45fb8691146a7b4871c35adcec5c6e1a61e23adf96623889c9cb84d4
3
+ metadata.gz: 79790874d3e01606cda561899935a3161a7a018606ca7c2e1ea37e5675576b4e
4
+ data.tar.gz: 27ae8bc8e77f8e6dd3ca586c14ee2e435c6af695f5924d0de5b44ad6c262e167
5
5
  SHA512:
6
- metadata.gz: 8d80a2047457f6923e4ec424d27617e48bb5b282436dacda25131f15c75727210c6f88cc210abffd9c428a9c487b550fb283695be870c9aa3f90d090eda6a819
7
- data.tar.gz: 21c6276b40984fafc6c861140cad12c2ed4359ea0fb1195cd64f420be2719d7ea5d239fc3db180aaacee6bc9e515cd9c7c45520d21e3b8bda3c37b0ae61ffbf2
6
+ metadata.gz: 571d8aa49dfbe9a66cacf7c92e2bd9b1817146c4d02b56003f737c0e1dbd385f702d59bdb952a76fccff5e97c3adf499183422297cd935d09a955e217917d702
7
+ data.tar.gz: 5b8531e7ec4c675fe2ee9b547a677660712641ac0f634ec9ca023802bec0ab57b5a0f7e897684e378783bc4f0949124de6d19e605a3a687bca54de9201b688dc
@@ -1,14 +1,8 @@
1
1
  module MetadataPresenter
2
2
  module ApplicationHelper
3
3
  def main_title(component:, tag: :h1, classes: 'govuk-heading-xl')
4
- if component.legend.present?
5
- content_tag(:h1, class: 'govuk-heading-xl') do
6
- component.legend
7
- end
8
- else
9
- content_tag(tag, class: classes) do
10
- component.label
11
- end
4
+ content_tag(tag, class: classes) do
5
+ component.humanised_title
12
6
  end
13
7
  end
14
8
 
@@ -12,4 +12,8 @@ class MetadataPresenter::Component < MetadataPresenter::Metadata
12
12
  MetadataPresenter::Item.new(item, editor: editor?)
13
13
  end
14
14
  end
15
+
16
+ def content?
17
+ type == 'content'
18
+ end
15
19
  end
@@ -1,9 +1,10 @@
1
1
  module MetadataPresenter
2
2
  class PageAnswersPresenter
3
3
  FIRST_ANSWER = 0.freeze
4
+ NO_USER_INPUT = %w(page.checkanswers page.confirmation page.content).freeze
4
5
 
5
6
  def self.map(view:, pages:, answers:)
6
- pages.map do |page|
7
+ user_input_pages(pages).map do |page|
7
8
  Array(page.components).map do |component|
8
9
  new(
9
10
  view: view,
@@ -15,6 +16,10 @@ module MetadataPresenter
15
16
  end.reject { |page| page.empty? }
16
17
  end
17
18
 
19
+ def self.user_input_pages(pages)
20
+ pages.reject { |page| page.type.in?(NO_USER_INPUT) }
21
+ end
22
+
18
23
  attr_reader :view, :component, :page, :answers
19
24
  delegate :url, to: :page
20
25
  delegate :humanised_title, to: :component
@@ -7,6 +7,11 @@ class MetadataPresenter::ValidateSchema
7
7
  return unless controller.request.post?
8
8
 
9
9
  validate(controller.request.params, 'request.service')
10
+
11
+ metadata = controller.request.params['metadata']
12
+ Array(metadata['pages']).each do |page|
13
+ validate(page, page['_type'])
14
+ end
10
15
  rescue JSON::Schema::ValidationError, JSON::Schema::SchemaError, SchemaNotFoundError => e
11
16
  controller.render(
12
17
  json: ErrorsSerializer.new(message: e.message).attributes,
@@ -0,0 +1,7 @@
1
+ <% if @page.heading %>
2
+ <h1 class="fb-editable govuk-heading-xl"
3
+ data-fb-content-id="page[heading]"
4
+ data-fb-content-type="element">
5
+ <%= @page.heading %>
6
+ </h1>
7
+ <%- end %>
@@ -0,0 +1,20 @@
1
+ <% @page.components.each_with_index do |component, index| %>
2
+ <div class="fb-editable"
3
+ id="<%= component.id %>"
4
+ data-fb-content-type="<%= component.type %>"
5
+ data-fb-content-id="<%= "page[components[#{index}]]" %>"
6
+ data-fb-content-data="<%= component.to_json %>">
7
+
8
+ <%= render partial: component, locals: {
9
+ f: f,
10
+ component: component,
11
+ component_id: "page[components[#{index}]]",
12
+ input_title: main_title(
13
+ component: component,
14
+ tag: :h2,
15
+ classes: classes
16
+ )
17
+ }
18
+ %>
19
+ </div>
20
+ <% end %>
@@ -11,10 +11,6 @@
11
11
  </h1>
12
12
  <% end %>
13
13
 
14
- <%= render 'metadata_presenter/attribute/lede' %>
15
-
16
- <%= render 'metadata_presenter/attribute/body' %>
17
-
18
14
  <%= form_for @page, url: reserved_submissions_path do |f| %>
19
15
  <div data-block-id="page.checkanswers.answers" data-block-type="answers">
20
16
  <dl class="fb-block fb-block-answers govuk-summary-list">
@@ -68,6 +64,14 @@
68
64
  </div>
69
65
  <% end %>
70
66
 
67
+ <%= render partial: 'metadata_presenter/component/components',
68
+ locals: {
69
+ f: f,
70
+ components: @page.components,
71
+ tag: nil,
72
+ classes: nil
73
+ } %>
74
+
71
75
  <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">
72
76
  Accept and send application
73
77
  </button>
@@ -13,3 +13,11 @@
13
13
  <%= render 'metadata_presenter/attribute/body' %>
14
14
  </div>
15
15
  </div>
16
+
17
+ <%= render partial: 'metadata_presenter/component/components',
18
+ locals: {
19
+ f: nil,
20
+ components: @page.components,
21
+ tag: nil,
22
+ classes: nil
23
+ } %>
@@ -17,20 +17,14 @@
17
17
  <%= render 'metadata_presenter/attribute/body' %>
18
18
 
19
19
  <%= form_for @page_answers, as: :answers, url: @page.url, method: :post do |f| %>
20
- <%= f.govuk_error_summary %>
21
20
 
22
- <% @page.components.each_with_index do |component, index| %>
23
- <div class="fb-editable"
24
- data-fb-content-type="<%= component._type %>"
25
- data-fb-content-id="<%= "page[components[#{index}]]" %>"
26
- data-fb-content-data="<%= component.to_json %>">
27
- <%= render partial: component, locals: {
28
- component: component,
29
- f: f,
30
- input_title: main_title(component: component) }
31
- %>
32
- </div>
33
- <% end %>
21
+ <%= render partial: 'metadata_presenter/component/components',
22
+ locals: {
23
+ f: f,
24
+ components: @page.components,
25
+ tag: nil,
26
+ classes: nil
27
+ } %>
34
28
 
35
29
  <%= f.govuk_submit(disabled: editable?) %>
36
30
  <% end %>
@@ -3,23 +3,18 @@
3
3
  <div class="govuk-grid-column-two-thirds">
4
4
 
5
5
  <%= render 'metadata_presenter/attribute/section_heading' %>
6
-
7
- <h1 class="govuk-heading-xl"><%= @page.heading %></h1>
6
+ <%= render 'metadata_presenter/attribute/heading' %>
8
7
 
9
8
  <%= form_for @page_answers, as: :answers, url: @page.url, method: :post do |f| %>
10
9
  <%= f.govuk_error_summary %>
11
- <% @page.components.each_with_index do |component, index| %>
12
- <%= render partial: component, locals: {
13
- component: component,
14
- component_id: "page[components[#{index}]]",
10
+
11
+ <%= render partial: 'metadata_presenter/component/components', locals: {
15
12
  f: f,
16
- input_title: main_title(
17
- component: component,
18
- tag: :h2,
19
- classes: 'govuk-heading-m govuk-!-margin-top-8'
20
- ) }
21
- %>
22
- <% end %>
13
+ components: @page.components,
14
+ tag: :h2,
15
+ classes: 'govuk-heading-m govuk-!-margin-top-8'
16
+ }
17
+ %>
23
18
 
24
19
  <%= f.govuk_submit(disabled: editable?) %>
25
20
  <% end %>
@@ -2,18 +2,9 @@
2
2
  <div class="govuk-grid-row">
3
3
  <div class="govuk-grid-column-two-thirds">
4
4
 
5
- <%= render 'metadata_presenter/attribute/section_heading' %>
6
-
7
- <% if @page.heading %>
8
- <h1 class="fb-editable govuk-heading-xl"
9
- data-fb-content-id="page[heading]"
10
- data-fb-content-type="element">
11
- <%= @page.heading %>
12
- </h1>
13
- <% end %>
14
-
5
+ <%= render 'metadata_presenter/attribute/section_heading' %>
6
+ <%= render 'metadata_presenter/attribute/heading' %>
15
7
  <%= render 'metadata_presenter/attribute/lede' %>
16
-
17
8
  <%= render 'metadata_presenter/attribute/body' %>
18
9
 
19
10
  <%= form_tag(root_path, method: :post) do %>
@@ -20,5 +20,8 @@
20
20
  }
21
21
  ],
22
22
  "name": "component-name",
23
- "legend": "Question"
23
+ "legend": "Question",
24
+ "validation": {
25
+ "required": true
26
+ }
24
27
  }
@@ -7,6 +7,7 @@
7
7
  "name": "component-name",
8
8
  "date_type": "day-month-year",
9
9
  "validation": {
10
+ "required": true,
10
11
  "date": true
11
12
  }
12
13
  }
@@ -7,6 +7,7 @@
7
7
  "name": "component-name",
8
8
  "width_class_input": "10",
9
9
  "validation": {
10
+ "required": true,
10
11
  "number": true
11
12
  }
12
13
  }
@@ -20,5 +20,8 @@
20
20
  }
21
21
  ],
22
22
  "name": "component-name",
23
- "legend": "Question"
23
+ "legend": "Question",
24
+ "validation": {
25
+ "required": true
26
+ }
24
27
  }
@@ -1,5 +1,6 @@
1
1
  {
2
2
  "_id": "page.confirmation",
3
3
  "_type": "page.confirmation",
4
- "heading": "Application complete"
4
+ "heading": "Application complete",
5
+ "components": []
5
6
  }
@@ -0,0 +1,7 @@
1
+ {
2
+ "section_heading": "[Optional section heading]",
3
+ "lede": "[Optional lede paragraph]",
4
+ "body": "[Optional content]",
5
+ "html": "[Optional content]",
6
+ "hint": "[Optional hint text]"
7
+ }
@@ -0,0 +1,72 @@
1
+ {
2
+ "_id": "service.base",
3
+ "_type": "service.base",
4
+ "service_name": "Service name",
5
+ "created_by": "4634ec01-5618-45ec-a4e2-bb5aa587e751",
6
+ "configuration": {
7
+ "service": {
8
+ "_id": "config.service",
9
+ "_type": "config.service"
10
+ },
11
+ "meta": {
12
+ "_id": "config.meta",
13
+ "_type": "config.meta",
14
+ "items": [
15
+ {
16
+ "_id": "config.meta--link",
17
+ "_type": "link",
18
+ "href": "/cookies",
19
+ "text": "Cookies"
20
+ },
21
+ {
22
+ "_id": "config.meta--link--2",
23
+ "_type": "link",
24
+ "href": "/privacy",
25
+ "text": "Privacy"
26
+ },
27
+ {
28
+ "_id": "config.meta--link--3",
29
+ "_type": "link",
30
+ "href": "/accessibility",
31
+ "text": "Accessibility"
32
+ }
33
+ ]
34
+ }
35
+ },
36
+ "pages": [
37
+ {
38
+ "_uuid": "9626b2e9-5ef0-4070-8331-ac55151b22c4",
39
+ "_id": "page.start",
40
+ "_type": "page.start",
41
+ "heading": "Service name goes here",
42
+ "lede": "Use this service to:",
43
+ "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
+ "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
+ "url": "/"
47
+ },
48
+ {
49
+ "_uuid": "1ed3e4ad-5098-41c9-b4b6-426e89f7804e",
50
+ "_id": "page.how-many-lights",
51
+ "_type": "page.content",
52
+ "section_heading": "Chain of Command",
53
+ "heading": "Tell me how many lights you see",
54
+ "body": "There are four lights!",
55
+ "components": [
56
+ {
57
+ "_id": "name_text_1",
58
+ "_type": "text",
59
+ "label": "Full name",
60
+ "name": "name_text_1",
61
+ "validation": {
62
+ "required": true,
63
+ "max_length": 10,
64
+ "min_length": 2
65
+ }
66
+ }
67
+ ],
68
+ "url": "how-many-lights"
69
+ }
70
+ ],
71
+ "locale": "en"
72
+ }
@@ -0,0 +1,60 @@
1
+ {
2
+ "_id": "service.base",
3
+ "_type": "service.base",
4
+ "service_name": "Service name",
5
+ "created_by": "4634ec01-5618-45ec-a4e2-bb5aa587e751",
6
+ "configuration": {
7
+ "service": {
8
+ "_id": "config.service",
9
+ "_type": "config.service"
10
+ },
11
+ "meta": {
12
+ "_id": "config.meta",
13
+ "_type": "config.meta",
14
+ "items": [
15
+ {
16
+ "_id": "config.meta--link",
17
+ "_type": "link",
18
+ "href": "/cookies",
19
+ "text": "Cookies"
20
+ },
21
+ {
22
+ "_id": "config.meta--link--2",
23
+ "_type": "link",
24
+ "href": "/privacy",
25
+ "text": "Privacy"
26
+ },
27
+ {
28
+ "_id": "config.meta--link--3",
29
+ "_type": "link",
30
+ "href": "/accessibility",
31
+ "text": "Accessibility"
32
+ }
33
+ ]
34
+ }
35
+ },
36
+ "pages": [
37
+ {
38
+ "_uuid": "9626b2e9-5ef0-4070-8331-ac55151b22c4",
39
+ "_id": "page.start",
40
+ "_type": "page.start",
41
+ "heading": "Service name goes here",
42
+ "lede": "Use this service to:",
43
+ "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
+ "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
+ "url": "/"
47
+ },
48
+ {
49
+ "_uuid": "b238a22f-c180-48d0-a7d9-8aad2036f1f2",
50
+ "_id": "page._confirmation",
51
+ "_type": "page.confirmation",
52
+ "body": "You'll receive a confirmation email",
53
+ "heading": "Complaint sent",
54
+ "lede": "Optional lede",
55
+ "url": "/confirmation",
56
+ "components": []
57
+ }
58
+ ],
59
+ "locale": "en"
60
+ }
@@ -326,20 +326,31 @@
326
326
  "section_heading": "Chain of Command",
327
327
  "heading": "Tell me how many lights you see",
328
328
  "body": "There are four lights!",
329
- "components": [],
329
+ "components": [
330
+ {
331
+ "_id": "how-many-lights_content_1",
332
+ "_type": "content",
333
+ "html": "What lights?"
334
+ }
335
+ ],
330
336
  "url": "how-many-lights"
331
337
  },
332
338
  {
333
339
  "_uuid": "e819d0c2-7062-4997-89cf-44d26d098404",
334
340
  "_id": "page._check-answers",
335
341
  "_type": "page.checkanswers",
336
- "body": "Optional content",
337
342
  "heading": "Review your answer",
338
- "lede": "First paragraph",
339
343
  "section_heading": "This section is optional",
340
344
  "send_body": "By submitting this answer you confirm all your answers",
341
345
  "send_heading": "Send your answer",
342
- "url": "/check-answers"
346
+ "url": "/check-answers",
347
+ "components": [
348
+ {
349
+ "_id": "check-answers_content_1",
350
+ "_type": "content",
351
+ "html": "Check yourself before you wreck yourself."
352
+ }
353
+ ]
343
354
  },
344
355
  {
345
356
  "_uuid": "b238a22f-c180-48d0-a7d9-8aad2036f1f2",
@@ -348,7 +359,14 @@
348
359
  "body": "You'll receive a confirmation email",
349
360
  "heading": "Complaint sent",
350
361
  "lede": "Optional lede",
351
- "url": "/confirmation"
362
+ "url": "/confirmation",
363
+ "components": [
364
+ {
365
+ "_id": "confirmation_content_1",
366
+ "_type": "content",
367
+ "html": "Some day I will be the most powerful Jedi ever!"
368
+ }
369
+ ]
352
370
  }
353
371
  ],
354
372
  "locale": "en"
@@ -11,7 +11,6 @@ module MetadataPresenter
11
11
 
12
12
  def service_metadata
13
13
  metadata_fixture(:version)
14
- JSON.parse(File.read(fixtures_directory.join('version.json')))
15
14
  end
16
15
 
17
16
  def metadata_fixture(fixture_name)
@@ -1,3 +1,3 @@
1
1
  module MetadataPresenter
2
- VERSION = '0.19.1'
2
+ VERSION = '0.22.0'
3
3
  end
@@ -17,16 +17,6 @@
17
17
  "type": "string",
18
18
  "default": "Check your answers"
19
19
  },
20
- "lede": {
21
- "title": "Lede",
22
- "type": "string",
23
- "description": "Content before the body"
24
- },
25
- "body": {
26
- "title": "Body",
27
- "type": "string",
28
- "description": "Optional content before showing the summary"
29
- },
30
20
  "summary_of": {
31
21
  "title": "Summary of",
32
22
  "description": "Page/section that summary summarises"
@@ -45,6 +35,14 @@
45
35
  "content": true,
46
36
  "multiline": true,
47
37
  "default": "By submitting this application you confirm that, to the best of your knowledge, the details you are providing are correct."
38
+ },
39
+ "components": {
40
+ "title": "Components",
41
+ "description": "The form or content elements used on the page",
42
+ "type": "array",
43
+ "items": {
44
+ "$ref": "component.content"
45
+ }
48
46
  }
49
47
  },
50
48
  "required": [
@@ -19,6 +19,14 @@
19
19
  },
20
20
  "lede": {
21
21
  "multiline": true
22
+ },
23
+ "components": {
24
+ "title": "Components",
25
+ "description": "The form or content elements used on the page",
26
+ "type": "array",
27
+ "items": {
28
+ "$ref": "component.content"
29
+ }
22
30
  }
23
31
  },
24
32
  "required": [
@@ -7,6 +7,14 @@
7
7
  "properties": {
8
8
  "_type": {
9
9
  "const": "page.content"
10
+ },
11
+ "components": {
12
+ "title": "Components",
13
+ "description": "The form or content elements used on the page",
14
+ "type": "array",
15
+ "items": {
16
+ "$ref": "component.content"
17
+ }
10
18
  }
11
19
  },
12
20
  "allOf": [
@@ -35,7 +35,26 @@
35
35
  "pages": {
36
36
  "type": "array",
37
37
  "items": {
38
- "$ref": "definition.page"
38
+ "anyOf": [
39
+ {
40
+ "$ref": "page.start"
41
+ },
42
+ {
43
+ "$ref": "page.checkanswers"
44
+ },
45
+ {
46
+ "$ref": "page.confirmation"
47
+ },
48
+ {
49
+ "$ref": "page.content"
50
+ },
51
+ {
52
+ "$ref": "page.multiplequestions"
53
+ },
54
+ {
55
+ "$ref": "page.singlequestion"
56
+ }
57
+ ]
39
58
  }
40
59
  }
41
60
  },
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: 0.19.1
4
+ version: 0.22.0
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-03-18 00:00:00.000000000 Z
11
+ date: 2021-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -253,9 +253,11 @@ files:
253
253
  - app/views/errors/404.html
254
254
  - app/views/layouts/metadata_presenter/application.html.erb
255
255
  - app/views/metadata_presenter/attribute/_body.html.erb
256
+ - app/views/metadata_presenter/attribute/_heading.html.erb
256
257
  - app/views/metadata_presenter/attribute/_lede.html.erb
257
258
  - app/views/metadata_presenter/attribute/_section_heading.html.erb
258
259
  - app/views/metadata_presenter/component/_checkboxes.html.erb
260
+ - app/views/metadata_presenter/component/_components.html.erb
259
261
  - app/views/metadata_presenter/component/_content.html.erb
260
262
  - app/views/metadata_presenter/component/_date.html.erb
261
263
  - app/views/metadata_presenter/component/_number.html.erb
@@ -298,6 +300,9 @@ files:
298
300
  - default_metadata/string/error.min_length.json
299
301
  - default_metadata/string/error.number.json
300
302
  - default_metadata/string/error.required.json
303
+ - default_text/content.json
304
+ - fixtures/invalid_content_page.json
305
+ - fixtures/no_component_page.json
301
306
  - fixtures/non_finished_service.json
302
307
  - fixtures/service.json
303
308
  - fixtures/version.json