metadata_presenter 0.7.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/helpers/metadata_presenter/application_helper.rb +14 -0
- data/app/validators/metadata_presenter/base_validator.rb +18 -0
- data/app/validators/metadata_presenter/max_length_validator.rb +1 -1
- data/app/validators/metadata_presenter/min_length_validator.rb +1 -1
- data/app/validators/metadata_presenter/number_validator.rb +7 -0
- data/app/validators/metadata_presenter/required_validator.rb +1 -1
- data/app/validators/metadata_presenter/validate_answers.rb +1 -12
- data/app/views/metadata_presenter/component/_number.html.erb +8 -0
- data/app/views/metadata_presenter/component/_text.html.erb +1 -1
- data/app/views/metadata_presenter/component/_textarea.html.erb +1 -1
- data/app/views/metadata_presenter/page/singlequestion.html.erb +6 -6
- data/default_metadata/component/number.json +12 -0
- data/default_metadata/component/radios.json +10 -0
- data/default_metadata/definition/radio.json +6 -0
- data/default_metadata/string/error.number.json +6 -0
- data/fixtures/version.json +53 -0
- data/lib/metadata_presenter/version.rb +1 -1
- data/schemas/component/number.json +29 -0
- data/schemas/component/radios.json +37 -0
- data/schemas/definition/conditionalcomponent.json +12 -0
- data/schemas/definition/fieldset.json +37 -0
- data/schemas/definition/grouping.json +27 -0
- data/schemas/definition/option.json +35 -0
- data/schemas/definition/radio.json +30 -0
- data/schemas/{definition/page.singlequestion.json → page/singlequestion.json} +0 -0
- metadata +16 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5bbf3dc29244816bf09f72e822f69608e9f558dcbf658191c6a655eaa86b890d
|
4
|
+
data.tar.gz: 9a15f8dea3df85ce18dff8341fc565325f23e1dd4813abce5000d200635b691d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58b6f7444ac4fe98236b773a953b4c8cda5d65f3187eacd819108baeb43a121e7ceb78c6863e2fa3ab162434ce9684c4c314be45ab86e4924704004785a83989
|
7
|
+
data.tar.gz: ae79d645b8c9b080c8cf11cd62b4036e30a0325c4c879591631476071f2192654fa6714ab070e712a4dc8bc1612df49a04ef486dd36f7cc8920046f7137ebc56
|
@@ -1,5 +1,19 @@
|
|
1
1
|
module MetadataPresenter
|
2
2
|
module ApplicationHelper
|
3
|
+
def main_h1(component)
|
4
|
+
if component.legend.present?
|
5
|
+
content_tag(:legend, class: 'govuk-fieldset__legend govuk-fieldset__legend--l') do
|
6
|
+
content_tag(:h1, class: 'govuk-fieldset__heading') do
|
7
|
+
component.legend
|
8
|
+
end
|
9
|
+
end
|
10
|
+
else
|
11
|
+
content_tag(:h1, class: 'govuk-heading-xl') do
|
12
|
+
component.label
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
3
17
|
## Display user answers on the view
|
4
18
|
## When the user doesn't answered yet the component will be blank
|
5
19
|
# or with data otherwise, so doing the if in every output is not
|
@@ -42,6 +42,8 @@ module MetadataPresenter
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def valid?
|
45
|
+
return true if user_answer.blank? && allow_blank?
|
46
|
+
|
45
47
|
if invalid_answer?
|
46
48
|
error_message = custom_error_message || default_error_message
|
47
49
|
page.errors.add(component.id, error_message)
|
@@ -62,6 +64,12 @@ module MetadataPresenter
|
|
62
64
|
message % error_message_hash if message.present?
|
63
65
|
end
|
64
66
|
|
67
|
+
# @return [String] user answer for the specific component
|
68
|
+
#
|
69
|
+
def user_answer
|
70
|
+
answers[component.name]
|
71
|
+
end
|
72
|
+
|
65
73
|
# The default error message will be look using the schema key.
|
66
74
|
# Assuming the schema key is 'grogu' then the default message
|
67
75
|
# will look for 'error.grogu.value'.
|
@@ -115,5 +123,15 @@ module MetadataPresenter
|
|
115
123
|
schema_key.to_sym => component.validation[schema_key]
|
116
124
|
}
|
117
125
|
end
|
126
|
+
|
127
|
+
# Method signature to be overwrite in the subclass if you do not want to allow
|
128
|
+
# blank values. We should not allow blank when performing the required
|
129
|
+
# validation.
|
130
|
+
#
|
131
|
+
# @return [TrueClass]
|
132
|
+
#
|
133
|
+
def allow_blank?
|
134
|
+
true unless self.class.name.demodulize.include?('RequiredValidator')
|
135
|
+
end
|
118
136
|
end
|
119
137
|
end
|
@@ -31,18 +31,7 @@ module MetadataPresenter
|
|
31
31
|
def component_validations(component)
|
32
32
|
return [] if component.validation.blank?
|
33
33
|
|
34
|
-
component.validation.
|
35
|
-
value.blank? ||
|
36
|
-
(optional_question?(component) && question_not_answered?)
|
37
|
-
end.keys
|
38
|
-
end
|
39
|
-
|
40
|
-
def optional_question?(component)
|
41
|
-
component.validation['required'] == false
|
42
|
-
end
|
43
|
-
|
44
|
-
def question_not_answered?
|
45
|
-
answers.values.any?(&:blank?)
|
34
|
+
component.validation.select { |_,value| value.present? }.keys
|
46
35
|
end
|
47
36
|
end
|
48
37
|
end
|
@@ -1,14 +1,14 @@
|
|
1
1
|
<div class="fb-main-grid-wrapper" data-block-id="<%= @page.id %>" data-block-type="page" data-block-pagetype="<%= @page.type %>">
|
2
2
|
<div class="govuk-grid-row">
|
3
3
|
<div class="govuk-grid-column-two-thirds">
|
4
|
-
|
5
|
-
<%= @page.heading.html_safe %>
|
6
|
-
</h1>
|
7
|
-
|
8
|
-
<%= form_for @page, url: @page.url, method: :post do |f| %>
|
4
|
+
<%= form_for @page, as: :answers, url: @page.url, method: :post do |f| %>
|
9
5
|
<%= f.govuk_error_summary %>
|
10
6
|
<% @page.components.each do |component| %>
|
11
|
-
<%= render partial: component, locals: {
|
7
|
+
<%= render partial: component, locals: {
|
8
|
+
component: component,
|
9
|
+
f: f,
|
10
|
+
input_title: main_h1(component) }
|
11
|
+
%>
|
12
12
|
<% end %>
|
13
13
|
|
14
14
|
<%= f.govuk_submit(disabled: editable?) %>
|
data/fixtures/version.json
CHANGED
@@ -124,6 +124,28 @@
|
|
124
124
|
"heading": "Parent name",
|
125
125
|
"url": "/parent-name"
|
126
126
|
},
|
127
|
+
{
|
128
|
+
"_id": "page.your_age",
|
129
|
+
"url": "your-age",
|
130
|
+
"_type":"page.singlequestion",
|
131
|
+
"_uuid":"59d1326c-32e6-45e9-b57a-bcc8e2fb6b2c",
|
132
|
+
"heading":"Your age",
|
133
|
+
"components": [
|
134
|
+
{
|
135
|
+
"_id": "your_age_number_1",
|
136
|
+
"hint": "Component hint",
|
137
|
+
"name": "your_age_number_1",
|
138
|
+
"_type": "number",
|
139
|
+
"label": "Your age",
|
140
|
+
"errors": {},
|
141
|
+
"validation": {
|
142
|
+
"number": true,
|
143
|
+
"required": true
|
144
|
+
},
|
145
|
+
"width_class_input": "10"
|
146
|
+
}
|
147
|
+
]
|
148
|
+
},
|
127
149
|
{
|
128
150
|
"_uuid": "7b748584-100e-4d81-a54a-5049190136cc",
|
129
151
|
"_id": "page.family_hobbies",
|
@@ -143,6 +165,37 @@
|
|
143
165
|
"heading": "Family Hobbies",
|
144
166
|
"url": "/family-hobbies"
|
145
167
|
},
|
168
|
+
{
|
169
|
+
"_uuid": "4251b25e-08de-4dcb-8f2f-dd9848dcdca6",
|
170
|
+
"_id": "page.radio-buttons",
|
171
|
+
"_type": "page.singlequestion",
|
172
|
+
"components": [
|
173
|
+
{
|
174
|
+
"_id": "radio-buttons_radios_1",
|
175
|
+
"_type": "radios",
|
176
|
+
"errors": {},
|
177
|
+
"hint": "Component hint",
|
178
|
+
"label": "Component label",
|
179
|
+
"items": [
|
180
|
+
{
|
181
|
+
"_id": "radio-buttons_radio_1",
|
182
|
+
"_type": "radio",
|
183
|
+
"label": "Yes",
|
184
|
+
"value": "radio_value_1"
|
185
|
+
},
|
186
|
+
{
|
187
|
+
"_id": "radio-buttons_radio_2",
|
188
|
+
"_type": "radio",
|
189
|
+
"label": "No",
|
190
|
+
"value": "radio_value_2"
|
191
|
+
}
|
192
|
+
],
|
193
|
+
"name": "radio-buttons_radios_1"
|
194
|
+
}
|
195
|
+
],
|
196
|
+
"heading": "Parent name",
|
197
|
+
"url": "/radio-buttons"
|
198
|
+
},
|
146
199
|
{
|
147
200
|
"_uuid": "e819d0c2-7062-4997-89cf-44d26d098404",
|
148
201
|
"_id": "page._check-answers",
|
@@ -0,0 +1,29 @@
|
|
1
|
+
{
|
2
|
+
"$id": "http://gov.uk/schema/v1.0.0/number",
|
3
|
+
"_name": "component.number",
|
4
|
+
"title": "Number",
|
5
|
+
"description": "Let users enter a number",
|
6
|
+
"type": "object",
|
7
|
+
"properties": {
|
8
|
+
"_type": {
|
9
|
+
"const": "number"
|
10
|
+
},
|
11
|
+
"name": {
|
12
|
+
"inputType": "number"
|
13
|
+
},
|
14
|
+
"width_class_input": {
|
15
|
+
"default": "10"
|
16
|
+
}
|
17
|
+
},
|
18
|
+
"allOf": [
|
19
|
+
{
|
20
|
+
"$ref": "definition.field"
|
21
|
+
},
|
22
|
+
{
|
23
|
+
"$ref": "validations#/definitions/number_bundle"
|
24
|
+
},
|
25
|
+
{
|
26
|
+
"$ref": "definition.width_class.input"
|
27
|
+
}
|
28
|
+
]
|
29
|
+
}
|
@@ -0,0 +1,37 @@
|
|
1
|
+
{
|
2
|
+
"$id": "http://gov.uk/schema/v1.0.0/radios",
|
3
|
+
"_name": "component.radios",
|
4
|
+
"title": "Radios",
|
5
|
+
"description": "Let users select one option from a list",
|
6
|
+
"type": "object",
|
7
|
+
"properties": {
|
8
|
+
"_type": {
|
9
|
+
"const": "radios"
|
10
|
+
},
|
11
|
+
"items": {
|
12
|
+
"title": "Options",
|
13
|
+
"description": "Items that users can select",
|
14
|
+
"type": "array",
|
15
|
+
"items": {
|
16
|
+
"$ref": "definition.radio"
|
17
|
+
}
|
18
|
+
}
|
19
|
+
},
|
20
|
+
"allOf": [
|
21
|
+
{
|
22
|
+
"$ref": "definition.fieldset"
|
23
|
+
},
|
24
|
+
{
|
25
|
+
"$ref": "definition.name"
|
26
|
+
}
|
27
|
+
],
|
28
|
+
"transforms": {
|
29
|
+
"namespace": {
|
30
|
+
"propagation": "items[*].conditional_component"
|
31
|
+
}
|
32
|
+
},
|
33
|
+
"required": [
|
34
|
+
"name",
|
35
|
+
"items"
|
36
|
+
]
|
37
|
+
}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
{
|
2
|
+
"$id": "http://gov.uk/schema/v1.0.0/definition/conditionalcomponent",
|
3
|
+
"_name": "definition.conditionalcomponent",
|
4
|
+
"nestable": true,
|
5
|
+
"title": "Conditional component",
|
6
|
+
"description": "Component revealed when user chooses option",
|
7
|
+
"allOf": [
|
8
|
+
{
|
9
|
+
"$ref": "definition.component"
|
10
|
+
}
|
11
|
+
]
|
12
|
+
}
|
@@ -0,0 +1,37 @@
|
|
1
|
+
{
|
2
|
+
"$id": "http://gov.uk/schema/v1.0.0/definition/fieldset",
|
3
|
+
"_name": "definition.fieldset",
|
4
|
+
"title": "Fieldset",
|
5
|
+
"description": "Group related form inputs",
|
6
|
+
"type": "object",
|
7
|
+
"category": [
|
8
|
+
"control",
|
9
|
+
"fieldset"
|
10
|
+
],
|
11
|
+
"properties": {
|
12
|
+
"_type": {
|
13
|
+
"const": "fieldset"
|
14
|
+
},
|
15
|
+
"legend": {
|
16
|
+
"title": "Legend",
|
17
|
+
"description": "Text to use in fieldset legend",
|
18
|
+
"type": "string"
|
19
|
+
},
|
20
|
+
"hint": {
|
21
|
+
"title": "Hint",
|
22
|
+
"description": "Text to help users answer a question - appears in grey under the legend",
|
23
|
+
"type": "string"
|
24
|
+
}
|
25
|
+
},
|
26
|
+
"allOf": [
|
27
|
+
{
|
28
|
+
"$ref": "definition.repeatable"
|
29
|
+
},
|
30
|
+
{
|
31
|
+
"$ref": "definition.grouping"
|
32
|
+
}
|
33
|
+
],
|
34
|
+
"required": [
|
35
|
+
"legend"
|
36
|
+
]
|
37
|
+
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
{
|
2
|
+
"$id": "http://gov.uk/schema/v1.0.0/definition/grouping",
|
3
|
+
"_name": "definition.grouping",
|
4
|
+
"title": "Grouping definition",
|
5
|
+
"allOf": [
|
6
|
+
{
|
7
|
+
"$ref": "definition.component"
|
8
|
+
},
|
9
|
+
{
|
10
|
+
"$ref": "definition.components"
|
11
|
+
},
|
12
|
+
{
|
13
|
+
"$ref": "definition.namespace"
|
14
|
+
},
|
15
|
+
{
|
16
|
+
"$ref": "definition.html_attributes"
|
17
|
+
}
|
18
|
+
],
|
19
|
+
"category": [
|
20
|
+
"grouping"
|
21
|
+
],
|
22
|
+
"transforms": {
|
23
|
+
"namespace": {
|
24
|
+
"propagation": "components[?(@.$control || @.$grouping)]"
|
25
|
+
}
|
26
|
+
}
|
27
|
+
}
|
@@ -0,0 +1,35 @@
|
|
1
|
+
{
|
2
|
+
"$id": "http://gov.uk/schema/v1.0.0/definition/option",
|
3
|
+
"_name": "definition.option",
|
4
|
+
"title": "Option definition",
|
5
|
+
"properties": {
|
6
|
+
"value": {
|
7
|
+
"title": "Option value",
|
8
|
+
"description": "Value captured by system when users choose this option",
|
9
|
+
"type": "string"
|
10
|
+
},
|
11
|
+
"hasDivider": {
|
12
|
+
"title": "Option divider",
|
13
|
+
"description": "Whether to display a textual divider before the option - defaults to ‘or’",
|
14
|
+
"type": "boolean"
|
15
|
+
}
|
16
|
+
},
|
17
|
+
"allOf": [
|
18
|
+
{
|
19
|
+
"$ref": "definition.block"
|
20
|
+
},
|
21
|
+
{
|
22
|
+
"$ref": "definition.label"
|
23
|
+
},
|
24
|
+
{
|
25
|
+
"$ref": "definition.namespace"
|
26
|
+
}
|
27
|
+
],
|
28
|
+
"required": [
|
29
|
+
"value"
|
30
|
+
],
|
31
|
+
"category": [
|
32
|
+
"component",
|
33
|
+
"option"
|
34
|
+
]
|
35
|
+
}
|
@@ -0,0 +1,30 @@
|
|
1
|
+
{
|
2
|
+
"$id": "http://gov.uk/schema/v1.0.0/definition/radio",
|
3
|
+
"_name": "definition.radio",
|
4
|
+
"idSeed": "value",
|
5
|
+
"title": "Radio option",
|
6
|
+
"description": "Component that provides a radio option",
|
7
|
+
"type": "object",
|
8
|
+
"properties": {
|
9
|
+
"_type": {
|
10
|
+
"const": "radio"
|
11
|
+
},
|
12
|
+
"hint": {
|
13
|
+
"title": "Hint text",
|
14
|
+
"description": "Text to help users understand an option - appears in grey under the label",
|
15
|
+
"type": "string",
|
16
|
+
"content": true
|
17
|
+
},
|
18
|
+
"conditional_component": {
|
19
|
+
"$ref": "definition.conditionalcomponent"
|
20
|
+
}
|
21
|
+
},
|
22
|
+
"allOf": [
|
23
|
+
{
|
24
|
+
"$ref": "definition.option"
|
25
|
+
}
|
26
|
+
],
|
27
|
+
"required": [
|
28
|
+
"label"
|
29
|
+
]
|
30
|
+
}
|
File without changes
|
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.
|
4
|
+
version: 0.9.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-02-
|
11
|
+
date: 2021-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -240,11 +240,13 @@ files:
|
|
240
240
|
- app/validators/metadata_presenter/base_validator.rb
|
241
241
|
- app/validators/metadata_presenter/max_length_validator.rb
|
242
242
|
- app/validators/metadata_presenter/min_length_validator.rb
|
243
|
+
- app/validators/metadata_presenter/number_validator.rb
|
243
244
|
- app/validators/metadata_presenter/required_validator.rb
|
244
245
|
- app/validators/metadata_presenter/validate_answers.rb
|
245
246
|
- app/validators/metadata_presenter/validate_schema.rb
|
246
247
|
- app/views/errors/404.html
|
247
248
|
- app/views/layouts/metadata_presenter/application.html.erb
|
249
|
+
- app/views/metadata_presenter/component/_number.html.erb
|
248
250
|
- app/views/metadata_presenter/component/_text.html.erb
|
249
251
|
- app/views/metadata_presenter/component/_textarea.html.erb
|
250
252
|
- app/views/metadata_presenter/header/show.html.erb
|
@@ -256,10 +258,13 @@ files:
|
|
256
258
|
- config/initializers/default_metadata.rb
|
257
259
|
- config/initializers/schemas.rb
|
258
260
|
- config/routes.rb
|
261
|
+
- default_metadata/component/number.json
|
262
|
+
- default_metadata/component/radios.json
|
259
263
|
- default_metadata/component/text.json
|
260
264
|
- default_metadata/component/textarea.json
|
261
265
|
- default_metadata/config/meta.json
|
262
266
|
- default_metadata/config/service.json
|
267
|
+
- default_metadata/definition/radio.json
|
263
268
|
- default_metadata/page/checkanswers.json
|
264
269
|
- default_metadata/page/confirmation.json
|
265
270
|
- default_metadata/page/singlequestion.json
|
@@ -267,6 +272,7 @@ files:
|
|
267
272
|
- default_metadata/service/base.json
|
268
273
|
- default_metadata/string/error.max_length.json
|
269
274
|
- default_metadata/string/error.min_length.json
|
275
|
+
- default_metadata/string/error.number.json
|
270
276
|
- default_metadata/string/error.required.json
|
271
277
|
- fixtures/non_finished_service.json
|
272
278
|
- fixtures/service.json
|
@@ -276,6 +282,8 @@ files:
|
|
276
282
|
- lib/metadata_presenter/test_helpers.rb
|
277
283
|
- lib/metadata_presenter/version.rb
|
278
284
|
- lib/tasks/metadata_presenter_tasks.rake
|
285
|
+
- schemas/component/number.json
|
286
|
+
- schemas/component/radios.json
|
279
287
|
- schemas/component/text.json
|
280
288
|
- schemas/component/textarea.json
|
281
289
|
- schemas/condition/condition.json
|
@@ -292,22 +300,26 @@ files:
|
|
292
300
|
- schemas/definition/condition.text.json
|
293
301
|
- schemas/definition/condition.value_type.json
|
294
302
|
- schemas/definition/conditional.boolean.json
|
303
|
+
- schemas/definition/conditionalcomponent.json
|
295
304
|
- schemas/definition/conditions.all.json
|
296
305
|
- schemas/definition/conditions.any.json
|
297
306
|
- schemas/definition/conditions.exactly.json
|
298
307
|
- schemas/definition/control.json
|
299
308
|
- schemas/definition/data.json
|
300
309
|
- schemas/definition/field.json
|
310
|
+
- schemas/definition/fieldset.json
|
311
|
+
- schemas/definition/grouping.json
|
301
312
|
- schemas/definition/html_attributes.json
|
302
313
|
- schemas/definition/label.json
|
303
314
|
- schemas/definition/link_list.json
|
304
315
|
- schemas/definition/name.json
|
305
316
|
- schemas/definition/namespace.json
|
306
317
|
- schemas/definition/next_page.json
|
318
|
+
- schemas/definition/option.json
|
307
319
|
- schemas/definition/page.content.json
|
308
320
|
- schemas/definition/page.form.json
|
309
321
|
- schemas/definition/page.json
|
310
|
-
- schemas/definition/
|
322
|
+
- schemas/definition/radio.json
|
311
323
|
- schemas/definition/repeatable.json
|
312
324
|
- schemas/definition/width_class.input.json
|
313
325
|
- schemas/definition/width_class.json
|
@@ -315,6 +327,7 @@ files:
|
|
315
327
|
- schemas/link/link.json
|
316
328
|
- schemas/page/checkanswers.json
|
317
329
|
- schemas/page/confirmation.json
|
330
|
+
- schemas/page/singlequestion.json
|
318
331
|
- schemas/page/start.json
|
319
332
|
- schemas/request/service.json
|
320
333
|
- schemas/service/base.json
|