metadata_presenter 0.2.0 → 0.5.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: 4502db8905d70f018c8229e2fffb8f1c392415ee4ee8214bfc9bde851e563c8e
4
- data.tar.gz: ddaacc9a8520bdb2df646150e3f10001d06c9865a0008e68b8e117320b8e0d85
3
+ metadata.gz: f2da2dc7dc8a336839fc104af384535691bf1c4f1c1426152f53b943f2497a33
4
+ data.tar.gz: d8d1c7f55e4f5e116c16df0deaedbdf19a6b349bec430e2c2a30cc011bed7fe3
5
5
  SHA512:
6
- metadata.gz: f21f6779bf1c90b4a09a7042f2117b5b2712fc72d2eb331226bd6142452abf2a6eac9f1c3b221c12bef9c2d46584f6f514b4918ba3f90381ffaf6d6daebbf9a4
7
- data.tar.gz: dd6bcd473cdd65ace450ec00e1c4431d7844bf99201471e330752254b2eb2193cf15ad2ed0936a31c5483b97a3b7c4e4924c0b63d1d4a6aea21a5905279d530c
6
+ metadata.gz: d13092db05639eb3086e3bae5b56fc83204b932ddb0aa448f38ffdda0e28be743b7e2812a25c41f9a7aec8d3ea8f51b5ea20866458282d4f8c3cbf4c8f95d6ab
7
+ data.tar.gz: '06796c8b4edc4e017a76b0e7cdaeafdf612638f89729211a4ed880b59bbf5c66880785a4da018285d951de7cdf5bed7169081999d77ed7ac78b7b567104bf2f4'
@@ -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,7 +1,31 @@
1
1
  module MetadataPresenter
2
2
  module ApplicationHelper
3
- def to_markdown(text)
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
+
21
+ # Renders markdown given a text.
22
+ #
23
+ # @example
24
+ # <%=m '# Some markdown' %>
25
+ #
26
+ def m(text)
4
27
  (Kramdown::Document.new(text).to_html).html_safe
5
28
  end
29
+ alias to_markdown m
6
30
  end
7
31
  end
@@ -8,6 +8,10 @@ class MetadataPresenter::Metadata
8
8
  @metadata = OpenStruct.new(metadata)
9
9
  end
10
10
 
11
+ def to_json
12
+ self.to_h.to_json
13
+ end
14
+
11
15
  def id
12
16
  metadata._id
13
17
  end
@@ -6,6 +6,10 @@ 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
@@ -7,12 +7,20 @@ 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 service_slug
11
+ service_name.parameterize
12
+ end
13
+
14
+ def find_page_by_url(url)
15
+ pages.find { |page| strip_slash(page.url) == strip_slash(url) }
16
+ end
17
+
18
+ def find_page_by_uuid(uuid)
19
+ pages.find { |page| page.uuid == uuid }
12
20
  end
13
21
 
14
22
  def next_page(from:)
15
- current_page = find_page(from)
23
+ current_page = find_page_by_url(from)
16
24
  pages[pages.index(current_page) + 1] if current_page.present?
17
25
  end
18
26
 
@@ -25,4 +33,12 @@ class MetadataPresenter::Service < MetadataPresenter::Metadata
25
33
  page.type == 'page.confirmation'
26
34
  end
27
35
  end
36
+
37
+ private
38
+
39
+ def strip_slash(url)
40
+ return url if url == '/'
41
+
42
+ url.gsub(/^\//, '')
43
+ end
28
44
  end
@@ -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 ? @user_data[component.name] : nil
6
+ value: answer(component.name)
7
7
  %>
@@ -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,7 +5,7 @@
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 } %>
@@ -25,7 +25,7 @@
25
25
  </p>
26
26
  <%- end %>
27
27
 
28
- <%= form_tag(reserved_answers_path(@page.url), method: :post) do %>
28
+ <%= form_tag(@page.url, method: :post) do %>
29
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">
data/config/routes.rb CHANGED
@@ -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,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,17 +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
- "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.",
14
- "steps": [],
15
- "url": "/"
16
- }
17
- ],
6
+ "pages": [],
18
7
  "locale": "en"
19
8
  }
@@ -35,6 +35,7 @@
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",
@@ -36,6 +36,7 @@
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",
@@ -52,6 +53,7 @@
52
53
  "url": "/"
53
54
  },
54
55
  {
56
+ "_uuid": "847c4a0c-1c5f-4391-8847-42c8d82f1d0b",
55
57
  "_id": "page.name",
56
58
  "_type": "page.singlequestion",
57
59
  "components": [
@@ -71,6 +73,7 @@
71
73
  "url": "/name"
72
74
  },
73
75
  {
76
+ "_uuid": "ccf49acb-ad33-4fd3-8a7e-f0594b86cc96",
74
77
  "_id": "page.email-address",
75
78
  "_type": "page.singlequestion",
76
79
  "heading": "Email address",
@@ -102,6 +105,7 @@
102
105
  "url": "/email-address"
103
106
  },
104
107
  {
108
+ "_uuid": "7b748584-100e-4d81-a54a-5049190136cc",
105
109
  "_id": "page.parent_name",
106
110
  "_type": "page.singlequestion",
107
111
  "components": [
@@ -121,6 +125,7 @@
121
125
  "url": "/parent-name"
122
126
  },
123
127
  {
128
+ "_uuid": "e819d0c2-7062-4997-89cf-44d26d098404",
124
129
  "_id": "page._check-answers",
125
130
  "_type": "page.checkanswers",
126
131
  "body": "Optional content",
@@ -132,6 +137,7 @@
132
137
  "url": "/check-answers"
133
138
  },
134
139
  {
140
+ "_uuid": "b238a22f-c180-48d0-a7d9-8aad2036f1f2",
135
141
  "_id": "page._confirmation",
136
142
  "_type": "page.confirmation",
137
143
  "body": "You'll receive a confirmation email",
@@ -1,3 +1,3 @@
1
1
  module MetadataPresenter
2
- VERSION = '0.2.0'
2
+ VERSION = '0.5.0'
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": [
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.2.0
4
+ version: 0.5.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-01-22 00:00:00.000000000 Z
11
+ date: 2021-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -261,6 +261,7 @@ files:
261
261
  - default_metadata/page/checkanswers.json
262
262
  - default_metadata/page/confirmation.json
263
263
  - default_metadata/page/singlequestion.json
264
+ - default_metadata/page/start.json
264
265
  - default_metadata/service/base.json
265
266
  - default_metadata/string/error.max_length.json
266
267
  - default_metadata/string/error.min_length.json