metadata_presenter 0.1.6 → 0.3.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: ec5c5a811a4ff57b7306a6876ce1db7b8ab8dc38a11db49e5922e05bf7b81308
4
- data.tar.gz: f4dda5fe741a8fdd349d053cfa746b82d62798a32cc306a4d2249bf0db514358
3
+ metadata.gz: da4d7d444ed39c7f2f0815e1c7a6034893106531275dd4de9f97f655e5b6615f
4
+ data.tar.gz: 3e952b54e9652043c6f56d601a82e6bdc414f0c76a932cd17209be26a0914933
5
5
  SHA512:
6
- metadata.gz: 0b2546d19e21b30e80d37416cfeb92a3c77ecb4afdcf062dde4bfe8b29be20e9b8e592c2790cd6985b4b4c12a78236f9b6f43a506fcdfa20c646255f3eddaf51
7
- data.tar.gz: 40ab623c319681fa1e65d0fb612c19fea09a87cf299b8bc9f7d1ab94a103c3b715c7169efc610c361d041120a8141f2e85cd98cf68b5da77ba029ae8ae6a433c
6
+ metadata.gz: e0fd8beaea7b9141a1d58b94083b1757efeaee7160df08f347a5a47d1253736c3cdc7912e17fc0da28cd4ce8c0e8ad210c594a2bd4287c39e9ce0f8477977909
7
+ data.tar.gz: 1e768d8037be04a9e6f94c20a901cd3e29a9196cdcde94addd206ce468d2cc1ceaf19991daf22f02a2e1f42415f9a355e0e9b666f905a7f947c9d0345fa12ce5
data/README.md CHANGED
@@ -47,6 +47,7 @@ that you need to write the following methods in your controller:
47
47
 
48
48
  1. save_user_data
49
49
  2. load_user_data
50
+ 3. editable?
50
51
 
51
52
  The user answers can be accessed via `params[:answers]`.
52
53
 
@@ -63,6 +64,18 @@ An example of implementation:
63
64
  end
64
65
  ```
65
66
 
67
+ The `editable?` is related if the pages and components could be editable in the
68
+ mountable app:
69
+
70
+ ```ruby
71
+ class MyAwesomeController
72
+ def editable?
73
+ false
74
+ end
75
+ helper_method :editable?
76
+ end
77
+ ```
78
+
66
79
  ## Generate documentation
67
80
 
68
81
  Run `rake doc` and open the doc/index.html
@@ -1,5 +1,7 @@
1
1
  module MetadataPresenter
2
2
  class AnswersController < EngineController
3
+ before_action :check_page_exists
4
+
3
5
  def create
4
6
  if page.validate_answers(answers_params)
5
7
  save_user_data # method signature
@@ -12,15 +14,16 @@ module MetadataPresenter
12
14
  private
13
15
 
14
16
  def page
15
- @page ||= MetadataPresenter::Page.new(
16
- service.find_page(params[:page_url]).metadata
17
- )
17
+ @page ||= begin
18
+ current_page = service.find_page_by_url(page_url)
19
+ MetadataPresenter::Page.new(current_page.metadata) if current_page
20
+ end
18
21
  end
19
22
 
20
23
  def redirect_to_next_page
21
24
  next_page = NextPage.new(service).find(
22
25
  session: session,
23
- current_page_url: params[:page_url]
26
+ current_page_url: page_url
24
27
  )
25
28
 
26
29
  if next_page.present?
@@ -38,5 +41,13 @@ module MetadataPresenter
38
41
  def answers_params
39
42
  params[:answers] ? params[:answers].permit! : {}
40
43
  end
44
+
45
+ def page_url
46
+ request.env['PATH_INFO']
47
+ end
48
+
49
+ def check_page_exists
50
+ not_found if page.blank?
51
+ end
41
52
  end
42
53
  end
@@ -2,7 +2,7 @@ module MetadataPresenter
2
2
  class PagesController < EngineController
3
3
  def show
4
4
  @user_data = load_user_data # method signature
5
- @page ||= service.find_page(request.env['PATH_INFO'])
5
+ @page ||= service.find_page_by_url(request.env['PATH_INFO'])
6
6
 
7
7
  if @page
8
8
  render template: @page.template
@@ -1,5 +1,23 @@
1
1
  module MetadataPresenter
2
2
  module ApplicationHelper
3
+ ## Display user answers on the view
4
+ ## When the user doesn't answered yet the component will be blank
5
+ # or with data otherwise, so doing the if in every output is not
6
+ # pratical.
7
+ #
8
+ # The below example search for 'first_name' in the user data instance
9
+ # variable as long your load_user_data in the controller sets the variable.
10
+ #
11
+ # @example
12
+ # <%= a('first_name') %>
13
+ #
14
+ def a(component_key)
15
+ if @user_data.present?
16
+ @user_data[component_key]
17
+ end
18
+ end
19
+ alias answer a
20
+
3
21
  def to_markdown(text)
4
22
  (Kramdown::Document.new(text).to_html).html_safe
5
23
  end
@@ -1,5 +1,5 @@
1
1
  class MetadataPresenter::Component < MetadataPresenter::Metadata
2
2
  def to_partial_path
3
- "component/#{type}"
3
+ "metadata_presenter/component/#{type}"
4
4
  end
5
5
  end
@@ -9,7 +9,7 @@ module MetadataPresenter
9
9
  def find(session:, current_page_url:)
10
10
  if session[:return_to_check_you_answer].present?
11
11
  session[:return_to_check_you_answer] = nil
12
- service.pages.find { |page| page.type == 'page.summary' }
12
+ service.pages.find { |page| page.type == 'page.checkanswers' }
13
13
  else
14
14
  service.next_page(from: current_page_url)
15
15
  end
@@ -6,10 +6,18 @@ module MetadataPresenter
6
6
  ValidateAnswers.new(page: self, answers: answers).valid?
7
7
  end
8
8
 
9
+ def uuid
10
+ _uuid
11
+ end
12
+
9
13
  def ==(other)
10
14
  id == other.id if other.respond_to? :id
11
15
  end
12
16
 
17
+ def editable_attributes
18
+ self.to_h.reject { |k,_| k.in?([:_id, :_type, :steps]) }
19
+ end
20
+
13
21
  def components
14
22
  metadata.components&.map do |component|
15
23
  MetadataPresenter::Component.new(component)
@@ -7,12 +7,16 @@ class MetadataPresenter::Service < MetadataPresenter::Metadata
7
7
  pages.first
8
8
  end
9
9
 
10
- def find_page(path)
11
- pages.find { |page| page.url == path }
10
+ def find_page_by_url(url)
11
+ pages.find { |page| page.url == url }
12
+ end
13
+
14
+ def find_page_by_uuid(uuid)
15
+ pages.find { |page| page.uuid == uuid }
12
16
  end
13
17
 
14
18
  def next_page(from:)
15
- current_page = find_page(from)
19
+ current_page = find_page_by_url(from)
16
20
  pages[pages.index(current_page) + 1] if current_page.present?
17
21
  end
18
22
 
@@ -3,5 +3,5 @@
3
3
  label: { text: component.label },
4
4
  hint: { text: component.hint },
5
5
  name: "answers[#{component.name}]",
6
- value: @user_data[component.name]
6
+ value: answer(component.name)
7
7
  %>
@@ -25,7 +25,7 @@
25
25
  <% end %>
26
26
 
27
27
  <%= form_for @page, url: reserved_submissions_path do |f| %>
28
- <div data-block-id="page.summary.answers" data-block-type="answers">
28
+ <div data-block-id="page.checkanswers.answers" data-block-type="answers">
29
29
  <dl class="fb-block fb-block-answers govuk-summary-list">
30
30
  <% @service.pages.each do |page| %>
31
31
  <% Array(page.components).each do |component| %>
@@ -35,7 +35,7 @@
35
35
  </dt>
36
36
 
37
37
  <dd class="govuk-summary-list__value">
38
- <%= @user_data[component.name] %>
38
+ <%=a component.name %>
39
39
  </dd>
40
40
  <dd class="govuk-summary-list__actions">
41
41
  <%= link_to(
@@ -66,7 +66,7 @@
66
66
  </div>
67
67
  <% end %>
68
68
 
69
- <button 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">
69
+ <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">
70
70
  Accept and send application
71
71
  </button>
72
72
  <% end %>
@@ -5,13 +5,13 @@
5
5
  <%= @page.heading.html_safe %>
6
6
  </h1>
7
7
 
8
- <%= form_for @page, url: reserved_answers_path(@page.url) do |f| %>
8
+ <%= form_for @page, url: @page.url, method: :post do |f| %>
9
9
  <%= f.govuk_error_summary %>
10
10
  <% @page.components.each do |component| %>
11
11
  <%= render partial: component, locals: { component: component, f: f } %>
12
12
  <% end %>
13
13
 
14
- <%= f.govuk_submit %>
14
+ <%= f.govuk_submit(disabled: editable?) %>
15
15
  <% end %>
16
16
  </div>
17
17
  </div>
@@ -25,14 +25,20 @@
25
25
  </p>
26
26
  <%- end %>
27
27
 
28
- <%= form_tag(reserved_answers_path(@page.url), method: :post) do %>
29
- <button class='govuk-button govuk-button--start govuk-!-margin-top-2'>
28
+ <%= form_tag(@page.url, method: :post) do %>
29
+ <button <%= 'disabled' if editable? %> class='govuk-button govuk-button--start govuk-!-margin-top-2'>
30
30
  Start
31
31
  <svg class="govuk-button__start-icon" xmlns="http://www.w3.org/2000/svg" width="17.5" height="19" viewBox="0 0 33 40" aria-hidden="true" focusable="false">
32
32
  <path fill="currentColor" d="M0 0h13l20 20-20 20H0l20-20z" />
33
33
  </svg>
34
34
  </button>
35
35
  <% end %>
36
+
37
+ <% if @page.before_you_start %>
38
+ <p class="govuk-body-l" data-block-id="<%= @page.id %>" data-block-property="before-you-start">
39
+ <%= to_markdown(@page.before_you_start) %>
40
+ </p>
41
+ <%- end %>
36
42
  </div>
37
43
  </div>
38
44
  </div>
@@ -1,8 +1,10 @@
1
1
  MetadataPresenter::Engine.routes.draw do
2
2
  root to: 'service#start'
3
3
 
4
- post '/reserved/:page_url/answers', to: 'answers#create', as: :reserved_answers
5
4
  post '/reserved/submissions', to: 'submissions#create', as: :reserved_submissions
6
5
  get '/reserved/change-answer', to: 'change_answer#create', as: :change_answer
6
+
7
+ post '/', to: 'answers#create'
8
+ match '*path', to: 'answers#create', via: :post
7
9
  match '*path', to: 'pages#show', via: :all
8
10
  end
@@ -0,0 +1,8 @@
1
+ {
2
+ "_id": "component.text",
3
+ "_type": "text",
4
+ "errors": {},
5
+ "hint": "Component hint",
6
+ "label": "Component label",
7
+ "name": "component-name"
8
+ }
@@ -1,6 +1,8 @@
1
1
  {
2
- "_id": "page.summary",
2
+ "_id": "page.checkanswers",
3
+ "_type": "page.checkanswers",
3
4
  "heading": "Check your answers",
4
5
  "send_heading": "Now send your application",
5
- "send_body": "By submitting this application you confirm that, to the best of your knowledge, the details you are providing are correct."
6
+ "send_body": "By submitting this application you confirm that, to the best of your knowledge, the details you are providing are correct.",
7
+ "components": []
6
8
  }
@@ -1,4 +1,5 @@
1
1
  {
2
2
  "_id": "page.confirmation",
3
+ "_type": "page.confirmation",
3
4
  "heading": "Required - Confirmation"
4
5
  }
@@ -0,0 +1,9 @@
1
+ {
2
+ "_id": "page.singlequestion",
3
+ "_type": "page.singlequestion",
4
+ "heading": "Question",
5
+ "lede": "This is the lede",
6
+ "body": "Body section",
7
+ "components": [],
8
+ "url": ""
9
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "_id": "page.start",
3
+ "_type": "page.start",
4
+ "heading": "Service name goes here",
5
+ "lede": "This is your start page first paragraph. You can only have one paragraph here.",
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
+ "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
+ "url": "/"
10
+ }
@@ -3,16 +3,6 @@
3
3
  "_type": "service.base",
4
4
  "service_name": "Service name",
5
5
  "configuration": {},
6
- "pages": [
7
- {
8
- "_id": "page.start",
9
- "_type": "page.start",
10
- "heading": "Service name goes here",
11
- "lede": "This is your start page first paragraph. You can only have one paragraph here.",
12
- "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.",
13
- "steps": [],
14
- "url": "/"
15
- }
16
- ],
6
+ "pages": [],
17
7
  "locale": "en"
18
8
  }
@@ -35,11 +35,13 @@
35
35
  },
36
36
  "pages": [
37
37
  {
38
+ "_uuid": "9626b2e9-5ef0-4070-8331-ac55151b22c4",
38
39
  "_id": "page.start",
39
40
  "_type": "page.start",
40
41
  "heading": "Service name goes here",
41
42
  "lede": "Use this service to:",
42
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.",
43
45
  "steps": [],
44
46
  "url": "/"
45
47
  }
@@ -36,11 +36,13 @@
36
36
  },
37
37
  "pages": [
38
38
  {
39
+ "_uuid": "fa391697-ae82-4416-adc3-3433e54ce535",
39
40
  "_id": "page.start",
40
41
  "_type": "page.start",
41
42
  "heading": "Service name goes here",
42
43
  "lede": "This is your start page first paragraph. You can only have one paragraph here.",
43
44
  "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.",
45
+ "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.",
44
46
  "steps": [
45
47
  "page.name",
46
48
  "page.email-address",
@@ -51,6 +53,7 @@
51
53
  "url": "/"
52
54
  },
53
55
  {
56
+ "_uuid": "847c4a0c-1c5f-4391-8847-42c8d82f1d0b",
54
57
  "_id": "page.name",
55
58
  "_type": "page.singlequestion",
56
59
  "components": [
@@ -70,6 +73,7 @@
70
73
  "url": "/name"
71
74
  },
72
75
  {
76
+ "_uuid": "ccf49acb-ad33-4fd3-8a7e-f0594b86cc96",
73
77
  "_id": "page.email-address",
74
78
  "_type": "page.singlequestion",
75
79
  "heading": "Email address",
@@ -101,6 +105,7 @@
101
105
  "url": "/email-address"
102
106
  },
103
107
  {
108
+ "_uuid": "7b748584-100e-4d81-a54a-5049190136cc",
104
109
  "_id": "page.parent_name",
105
110
  "_type": "page.singlequestion",
106
111
  "components": [
@@ -120,8 +125,9 @@
120
125
  "url": "/parent-name"
121
126
  },
122
127
  {
128
+ "_uuid": "e819d0c2-7062-4997-89cf-44d26d098404",
123
129
  "_id": "page._check-answers",
124
- "_type": "page.summary",
130
+ "_type": "page.checkanswers",
125
131
  "body": "Optional content",
126
132
  "heading": "Review your answer",
127
133
  "lede": "First paragraph",
@@ -131,6 +137,7 @@
131
137
  "url": "/check-answers"
132
138
  },
133
139
  {
140
+ "_uuid": "b238a22f-c180-48d0-a7d9-8aad2036f1f2",
134
141
  "_id": "page._confirmation",
135
142
  "_type": "page.confirmation",
136
143
  "body": "You'll receive a confirmation email",
@@ -0,0 +1,21 @@
1
+ module MetadataPresenter
2
+ module TestHelpers
3
+ def service
4
+ MetadataPresenter::Service.new(service_metadata)
5
+ end
6
+
7
+ def fixtures_directory
8
+ @_fixtures_directory ||=
9
+ Pathname.new(MetadataPresenter::Engine.root.join('fixtures'))
10
+ end
11
+
12
+ def service_metadata
13
+ metadata_fixture(:version)
14
+ JSON.parse(File.read(fixtures_directory.join('version.json')))
15
+ end
16
+
17
+ def metadata_fixture(fixture_name)
18
+ JSON.parse(File.read(fixtures_directory.join("#{fixture_name}.json")))
19
+ end
20
+ end
21
+ end
@@ -1,3 +1,3 @@
1
1
  module MetadataPresenter
2
- VERSION = '0.1.6'
2
+ VERSION = '0.3.1'
3
3
  end
@@ -4,6 +4,10 @@
4
4
  "id_seed": "url",
5
5
  "title": "Page definition",
6
6
  "properties": {
7
+ "_uuid": {
8
+ "title": "Unique identifier of the page",
9
+ "description": "Used internally in the editor and the runner."
10
+ },
7
11
  "url": {
8
12
  "title": "URL",
9
13
  "description": "The page’s relative url - it must not contain any spaces",
@@ -95,6 +99,7 @@
95
99
  }
96
100
  ],
97
101
  "required": [
102
+ "_uuid",
98
103
  "url"
99
104
  ],
100
105
  "category": [
@@ -1,12 +1,12 @@
1
1
  {
2
- "$id": "http://gov.uk/schema/v1.0.0/page/summary",
3
- "_name": "page.summary",
2
+ "$id": "http://gov.uk/schema/v1.0.0/page/checkanswers",
3
+ "_name": "page.checkanswers",
4
4
  "title": "Check answers",
5
5
  "description": "Let users check and change their answers before submitting",
6
6
  "type": "object",
7
7
  "properties": {
8
8
  "_type": {
9
- "const": "page.summary"
9
+ "const": "page.checkanswers"
10
10
  },
11
11
  "section_heading": {
12
12
  "title": "Section heading",
@@ -5,9 +5,16 @@
5
5
  "description": "Let users start using a service",
6
6
  "type": "object",
7
7
  "properties": {
8
+ "_id": {
9
+ "const": "page.start"
10
+ },
8
11
  "_type": {
9
12
  "const": "page.start"
10
13
  },
14
+ "before_you_start": {
15
+ "title": "Before you start",
16
+ "description": "A body of text that goes after the Start button"
17
+ },
11
18
  "enable_steps": {
12
19
  "const": true
13
20
  },
@@ -25,10 +32,14 @@
25
32
  "ui_category": {
26
33
  "main": [
27
34
  "lede",
28
- "body"
35
+ "body",
36
+ "before_you_start"
29
37
  ]
30
38
  },
31
39
  "required": [
40
+ "_id",
41
+ "_type",
42
+ "heading",
32
43
  "steps"
33
44
  ]
34
45
  }
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.1.6
4
+ version: 0.3.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-01-12 00:00:00.000000000 Z
11
+ date: 2021-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -247,18 +247,21 @@ files:
247
247
  - app/views/layouts/metadata_presenter/application.html.erb
248
248
  - app/views/metadata_presenter/component/_text.html.erb
249
249
  - app/views/metadata_presenter/header/show.html.erb
250
+ - app/views/metadata_presenter/page/checkanswers.html.erb
250
251
  - app/views/metadata_presenter/page/confirmation.html.erb
251
252
  - app/views/metadata_presenter/page/form.html.erb
252
253
  - app/views/metadata_presenter/page/singlequestion.html.erb
253
254
  - app/views/metadata_presenter/page/start.html.erb
254
- - app/views/metadata_presenter/page/summary.html.erb
255
255
  - config/initializers/default_metadata.rb
256
256
  - config/initializers/schemas.rb
257
257
  - config/routes.rb
258
+ - default_metadata/component/text.json
258
259
  - default_metadata/config/meta.json
259
260
  - default_metadata/config/service.json
261
+ - default_metadata/page/checkanswers.json
260
262
  - default_metadata/page/confirmation.json
261
- - default_metadata/page/summary.json
263
+ - default_metadata/page/singlequestion.json
264
+ - default_metadata/page/start.json
262
265
  - default_metadata/service/base.json
263
266
  - default_metadata/string/error.max_length.json
264
267
  - default_metadata/string/error.min_length.json
@@ -268,6 +271,7 @@ files:
268
271
  - fixtures/version.json
269
272
  - lib/metadata_presenter.rb
270
273
  - lib/metadata_presenter/engine.rb
274
+ - lib/metadata_presenter/test_helpers.rb
271
275
  - lib/metadata_presenter/version.rb
272
276
  - lib/tasks/metadata_presenter_tasks.rake
273
277
  - schemas/condition/condition.json
@@ -305,9 +309,9 @@ files:
305
309
  - schemas/definition/width_class.json
306
310
  - schemas/errors/errors.json
307
311
  - schemas/link/link.json
312
+ - schemas/page/checkanswers.json
308
313
  - schemas/page/confirmation.json
309
314
  - schemas/page/start.json
310
- - schemas/page/summary.json
311
315
  - schemas/request/service.json
312
316
  - schemas/service/base.json
313
317
  - schemas/service/configuration.json