metadata_presenter 0.6.1 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- 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/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/{text → component}/text.json +1 -1
- data/schemas/{textarea → component}/textarea.json +2 -2
- 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 +18 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9281493cf00e63b59db192a9dcc1f47192ed7d6443df62d74c326f742c90719a
|
4
|
+
data.tar.gz: a97f03eebbaa1a4bdd86ee988344705acab5197cebaccae1d756b0f841cceb10
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce1d3450e7c8daf6957c8c961436cd33438f03ec9d760952bae673e8dacc32b0fa5f451fc17fc0e9e22da6501656c5062cdb221482bffb68bcd77356e4bf16d4
|
7
|
+
data.tar.gz: 312895b3acf5acb4dd7c7de5ffa13a54f2888745a59a13f83b2f6aaa2d97cacbe91107d5abfaad46f724b04401335817a9380d22b9a5067d8e42f53f21eeb425
|
@@ -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
|
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.8.2
|
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,10 @@ 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
|
287
|
+
- schemas/component/text.json
|
288
|
+
- schemas/component/textarea.json
|
279
289
|
- schemas/condition/condition.json
|
280
290
|
- schemas/config/meta.json
|
281
291
|
- schemas/config/service.json
|
@@ -290,22 +300,26 @@ files:
|
|
290
300
|
- schemas/definition/condition.text.json
|
291
301
|
- schemas/definition/condition.value_type.json
|
292
302
|
- schemas/definition/conditional.boolean.json
|
303
|
+
- schemas/definition/conditionalcomponent.json
|
293
304
|
- schemas/definition/conditions.all.json
|
294
305
|
- schemas/definition/conditions.any.json
|
295
306
|
- schemas/definition/conditions.exactly.json
|
296
307
|
- schemas/definition/control.json
|
297
308
|
- schemas/definition/data.json
|
298
309
|
- schemas/definition/field.json
|
310
|
+
- schemas/definition/fieldset.json
|
311
|
+
- schemas/definition/grouping.json
|
299
312
|
- schemas/definition/html_attributes.json
|
300
313
|
- schemas/definition/label.json
|
301
314
|
- schemas/definition/link_list.json
|
302
315
|
- schemas/definition/name.json
|
303
316
|
- schemas/definition/namespace.json
|
304
317
|
- schemas/definition/next_page.json
|
318
|
+
- schemas/definition/option.json
|
305
319
|
- schemas/definition/page.content.json
|
306
320
|
- schemas/definition/page.form.json
|
307
321
|
- schemas/definition/page.json
|
308
|
-
- schemas/definition/
|
322
|
+
- schemas/definition/radio.json
|
309
323
|
- schemas/definition/repeatable.json
|
310
324
|
- schemas/definition/width_class.input.json
|
311
325
|
- schemas/definition/width_class.json
|
@@ -313,13 +327,12 @@ files:
|
|
313
327
|
- schemas/link/link.json
|
314
328
|
- schemas/page/checkanswers.json
|
315
329
|
- schemas/page/confirmation.json
|
330
|
+
- schemas/page/singlequestion.json
|
316
331
|
- schemas/page/start.json
|
317
332
|
- schemas/request/service.json
|
318
333
|
- schemas/service/base.json
|
319
334
|
- schemas/service/configuration.json
|
320
335
|
- schemas/service/locale.json
|
321
|
-
- schemas/text/text.json
|
322
|
-
- schemas/textarea/textarea.json
|
323
336
|
- schemas/validations/validations.json
|
324
337
|
homepage: https://moj-online.service.justice.gov.uk
|
325
338
|
licenses:
|