metadata_presenter 2.14.0 → 2.15.2

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: 42603519130d7f5029066830adc145fe8800465f38493f5acfe37943623210b9
4
- data.tar.gz: 9cb6b248e8246c2b0145f6d746043680494fd7292a36d2e18dff619cf55af8dc
3
+ metadata.gz: ed17e32c3e0222e86ec8935840dd5830d8ed5390275ec2aa66a667765a2a654c
4
+ data.tar.gz: 33a20608a8f1af401191298821709f81df9da87635daecaf04ff56c03e6f79c0
5
5
  SHA512:
6
- metadata.gz: 354e08330a417e94180c4686e058eac97155e2b62440faabdf1e10b17d469d2e7b93a0fd155d5d3eeb71549f2fc6725c78e048ac442c5a5b6dfeaae3f81c09e9
7
- data.tar.gz: 22011caef879554eb407f7bbda3726b5255178eb51b15e095c3409ec84f97df6ed565382f51651801f0ee9686b895ffc1db92ee9f4e715baa957e4378b88eee9
6
+ metadata.gz: 6def253d26c9e957934d524a0d2dca9c5871cc7867114c7904d739338da7526967853583d8f2274deb7f751cd98aea9de956d2acf1af519b8853a1947784320f
7
+ data.tar.gz: 0e0075aa9e08a231f76ebe37bfa4767a051617606d6a7889d7a515c1dc8d2bfc2b8c65b6b44f901066b8a7fd86b9331f37ee9f02788195b67308d9652d4a0d4b
@@ -9,6 +9,10 @@ module MetadataPresenter
9
9
 
10
10
  def number
11
11
  if service.flow_object(uuid).branch?
12
+ # Even though we are associating the column number to a specific flow object
13
+ # in the Coordinates model we do not use column_number + 1 as we are
14
+ # updating the position for the Spacers that exist for a branch which
15
+ # are always in the same column as the branch object itself.
12
16
  coordinates.set_branch_spacers_column(uuid, column_number)
13
17
  end
14
18
 
@@ -39,7 +39,7 @@ module MetadataPresenter
39
39
  end
40
40
 
41
41
  def set_branch_spacers_column(branch_uuid, column)
42
- branch_spacers[branch_uuid].each do |position|
42
+ branch_spacers[branch_uuid].each do |_, position|
43
43
  position[:column] = column
44
44
  end
45
45
  end
@@ -50,7 +50,7 @@ module MetadataPresenter
50
50
  # to draw an arrow therefore we increment the row number from the branches
51
51
  # calculated starting row
52
52
  def set_branch_spacers_row(branch_uuid, starting_row)
53
- branch_spacers[branch_uuid].each.with_index(starting_row) do |position, row|
53
+ branch_spacers[branch_uuid].each.with_index(starting_row) do |(_, position), row|
54
54
  position[:row] = row
55
55
  end
56
56
  end
@@ -64,12 +64,14 @@ module MetadataPresenter
64
64
  service.flow.keys.index_with { |_uuid| { row: nil, column: nil } }
65
65
  end
66
66
 
67
- # This also takes into account the 'or' expressions which
67
+ # This also takes into account the 'OR' expressions which
68
68
  # need an additional line for an arrow.
69
69
  def setup_branch_spacers
70
70
  service.branches.each.with_object({}) do |branch, hash|
71
71
  destinations = exiting_destinations_from_branch(branch)
72
- hash[branch.uuid] = destinations.map { { row: nil, column: nil } }
72
+ hash[branch.uuid] = destinations.index_with do |_uuid|
73
+ { row: nil, column: nil }
74
+ end
73
75
  end
74
76
  end
75
77
  end
@@ -19,7 +19,7 @@ module MetadataPresenter
19
19
 
20
20
  class Grid
21
21
  include BranchDestinations
22
- attr_reader :start_from
22
+ attr_reader :service, :start_from
23
23
 
24
24
  def initialize(service, start_from: nil, main_flow: [])
25
25
  @service = service
@@ -67,9 +67,13 @@ module MetadataPresenter
67
67
  ordered_pages.map(&:uuid)
68
68
  end
69
69
 
70
+ def show_warning?
71
+ checkanswers_warning.show_warning? || confirmation_warning.show_warning?
72
+ end
73
+
70
74
  private
71
75
 
72
- attr_reader :service, :main_flow
76
+ attr_reader :main_flow
73
77
  attr_accessor :ordered, :traversed, :routes, :coordinates
74
78
 
75
79
  def route_from_start
@@ -277,46 +281,21 @@ module MetadataPresenter
277
281
  # Include a warning if a service does not have a CYA or Confirmation page in the
278
282
  # main flow. The warning should always be in the first row, last column.
279
283
  def insert_warning
280
- if cya_and_confirmation_pages_not_in_service? ||
281
- cya_and_confirmation_pages_detached?
282
- @ordered.append([MetadataPresenter::Warning.new])
283
- end
284
- end
285
-
286
- def cya_and_confirmation_pages_not_in_service?
287
- (checkanswers_not_in_service? && confirmation_not_in_service?) ||
288
- checkanswers_not_in_service? ||
289
- confirmation_not_in_service?
290
- end
291
-
292
- def checkanswers_not_in_service?
293
- service.checkanswers_page.blank?
284
+ @ordered.append([MetadataPresenter::Warning.new]) if show_warning?
294
285
  end
295
286
 
296
- def confirmation_not_in_service?
297
- service.confirmation_page.blank?
287
+ def checkanswers_warning
288
+ MetadataPresenter::PageWarning.new(
289
+ page: service.checkanswers_page,
290
+ main_flow_uuids: flow_uuids
291
+ )
298
292
  end
299
293
 
300
- def cya_and_confirmation_pages_detached?
301
- (checkanswers_detached? && confirmation_detached?) ||
302
- checkanswers_detached? ||
303
- confirmation_detached?
304
- end
305
-
306
- def checkanswers_detached?
307
- if service.checkanswers_page.present?
308
- uuid = service.checkanswers_page.uuid
309
- position = coordinates.positions[uuid]
310
- detached?(position)
311
- end
312
- end
313
-
314
- def confirmation_detached?
315
- if service.confirmation_page.present?
316
- uuid = service.confirmation_page.uuid
317
- position = coordinates.positions[uuid]
318
- detached?(position)
319
- end
294
+ def confirmation_warning
295
+ MetadataPresenter::PageWarning.new(
296
+ page: service.confirmation_page,
297
+ main_flow_uuids: flow_uuids
298
+ )
320
299
  end
321
300
 
322
301
  # Any destinations exiting the branch that have not already been traversed.
@@ -0,0 +1,24 @@
1
+ module MetadataPresenter
2
+ class PageWarning
3
+ def initialize(page:, main_flow_uuids:)
4
+ @page = page
5
+ @main_flow_uuids = main_flow_uuids
6
+ end
7
+
8
+ def show_warning?
9
+ missing? || detached?
10
+ end
11
+
12
+ def missing?
13
+ page.blank?
14
+ end
15
+
16
+ def detached?
17
+ main_flow_uuids.exclude?(page&.uuid)
18
+ end
19
+
20
+ private
21
+
22
+ attr_reader :page, :main_flow_uuids
23
+ end
24
+ end
@@ -28,7 +28,7 @@ module MetadataPresenter
28
28
 
29
29
  return ROW_ZERO if place_on_row_zero?
30
30
 
31
- existing_row || [current_row, potential_row].compact.max
31
+ existing_row || [current_row, potential_row, branch_spacer_row].compact.max
32
32
  end
33
33
  end
34
34
 
@@ -36,27 +36,60 @@ module MetadataPresenter
36
36
  @existing_row ||= coordinates.uuid_row(uuid)
37
37
  end
38
38
 
39
+ # This looks for any branches in the current column and checks that there is
40
+ # enough space for the any branch conditionals before returning a row number.
39
41
  def potential_row
40
42
  return if branches_in_column.empty?
41
43
 
42
- row_numbers = branches_in_column.map do |uuid, _|
43
- coordinates.branch_spacers[uuid].map { |position| position[:row] }
44
+ row_numbers = branches_in_column.map do |branch_uuid, _|
45
+ coordinates.branch_spacers[branch_uuid].map { |_, position| position[:row] }
44
46
  end
45
47
  row_numbers.flatten.max + 1
46
48
  end
47
49
 
50
+ # This looks at the previous column and finds any branches that link to the
51
+ # current object. If any are found it checks for rows numbers that relate
52
+ # to the current objects UUID in the branch spacers hash and defaults to
53
+ # returning the highest row number.
54
+ def branch_spacer_row
55
+ return if spacers_for_current_object.empty?
56
+
57
+ spacers_for_current_object.map { |position| position[:row] }.max
58
+ end
59
+
48
60
  def first_row?
49
61
  @first_row ||= route.row.zero?
50
62
  end
51
63
 
52
64
  def branches_in_column
53
- @branches_in_column ||= coordinates.positions_in_column(uuid_column).select do |key, position|
65
+ @branches_in_column ||= branches(uuid_column)
66
+ end
67
+
68
+ def branches_in_previous_column
69
+ @branches_in_previous_column ||= branches(uuid_column - 1)
70
+ end
71
+
72
+ def branches(column_number)
73
+ coordinates.positions_in_column(column_number).select do |key, position|
54
74
  next if uuid == key || position[:row].blank?
55
75
 
56
76
  service.flow_object(key).branch?
57
77
  end
58
78
  end
59
79
 
80
+ def spacers_for_current_object
81
+ @spacers_for_current_object ||= begin
82
+ spacer_positions = branches_in_previous_column.select do |key, _|
83
+ coordinates.branch_spacers[key]
84
+ end
85
+
86
+ current_object_spacers = spacer_positions.map do |branch_uuid, _|
87
+ coordinates.branch_spacers[branch_uuid][uuid]
88
+ end
89
+ current_object_spacers.compact
90
+ end
91
+ end
92
+
60
93
  def uuid_column
61
94
  @uuid_column ||= coordinates.uuid_column(uuid)
62
95
  end
@@ -0,0 +1,8 @@
1
+ module MetadataPresenter
2
+ class EmailValidator < BaseValidator
3
+ def invalid_answer?
4
+ regex = URI::MailTo::EMAIL_REGEXP
5
+ user_answer.match(regex).nil?
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,11 @@
1
+ <%=
2
+ f.govuk_email_field component.id.to_sym,
3
+ label: { text: input_title },
4
+ hint: {
5
+ data: { "fb-default-text" => default_text('hint') },
6
+ text: component.hint
7
+ },
8
+ name: "answers[#{component.name}]",
9
+ spellcheck: "false",
10
+ autocomplete: "email"
11
+ %>
@@ -17,11 +17,11 @@ Rails.application.config.supported_components =
17
17
  content: %w(content)
18
18
  },
19
19
  multiplequestions: {
20
- input: %w(text textarea number date radios checkboxes),
20
+ input: %w(text textarea number date radios checkboxes email),
21
21
  content: %w(content)
22
22
  },
23
23
  singlequestion: {
24
- input: %w(text textarea number date radios checkboxes upload),
24
+ input: %w(text textarea number date radios checkboxes email upload),
25
25
  content: %w()
26
26
  }
27
27
  })
@@ -0,0 +1,12 @@
1
+ {
2
+ "_id": "component.email",
3
+ "_type": "email",
4
+ "errors": {},
5
+ "label": "Question",
6
+ "hint": "",
7
+ "name": "component-name",
8
+ "validation": {
9
+ "email": true,
10
+ "required": true
11
+ }
12
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "_id": "error.email",
3
+ "_type": "string.error",
4
+ "description": "Input (email) is not a valid email",
5
+ "value": "Enter an email address in the correct format, like name@example.com"
6
+ }
@@ -63,6 +63,12 @@
63
63
  }
64
64
  },
65
65
  "80420693-d6f2-4fce-a860-777ca774a6f5": {
66
+ "_type": "flow.page",
67
+ "next": {
68
+ "default": "adcb61c3-52b1-479b-be51-1bb610876d54"
69
+ }
70
+ },
71
+ "adcb61c3-52b1-479b-be51-1bb610876d54" : {
66
72
  "_type": "flow.page",
67
73
  "next": {
68
74
  "default": "2ef7d11e-0307-49e9-9fe2-345dc528dd66"
@@ -503,6 +509,31 @@
503
509
  "add_component": "content",
504
510
  "section_heading": "Chain of Command"
505
511
  },
512
+ {
513
+ "_id": "page.email",
514
+ "url": "email",
515
+ "body": "Body section",
516
+ "_type": "page.singlequestion",
517
+ "_uuid": "adcb61c3-52b1-479b-be51-1bb610876d54",
518
+ "heading": "Email",
519
+ "components": [
520
+ {
521
+ "_id": "email-address_email_1",
522
+ "hint": "",
523
+ "name": "email-address_email_1",
524
+ "_type": "email",
525
+ "_uuid": "482cb2d0-fda7-4e5c-9591-96dcb546e181",
526
+ "label": "Email address",
527
+ "errors": {},
528
+ "collection": "components",
529
+ "validation": {
530
+ "required": true,
531
+ "email": true,
532
+ "max_length": 256
533
+ }
534
+ }
535
+ ]
536
+ },
506
537
  {
507
538
  "_id": "page.dog-picture",
508
539
  "url": "dog-picture",
@@ -1,3 +1,3 @@
1
1
  module MetadataPresenter
2
- VERSION = '2.14.0'.freeze
2
+ VERSION = '2.15.2'.freeze
3
3
  end
@@ -0,0 +1,23 @@
1
+ {
2
+ "$id": "http://gov.uk/schema/v1.0.0/email",
3
+ "_name": "component.email",
4
+ "title": "Email",
5
+ "description": "Let users enter an email address",
6
+ "type": "object",
7
+ "properties": {
8
+ "_type": {
9
+ "const": "email"
10
+ }
11
+ },
12
+ "allOf": [
13
+ {
14
+ "$ref": "http://gov.uk/schema/v1.0.0/definition/field"
15
+ },
16
+ {
17
+ "$ref": "http://gov.uk/schema/v1.0.0/definition/widthclass/input"
18
+ }
19
+ ],
20
+ "validation": {
21
+ "format": "email"
22
+ }
23
+ }
@@ -13,9 +13,6 @@
13
13
  {
14
14
  "$ref": "definition.field"
15
15
  },
16
- {
17
- "$ref": "validations#/definitions/string_bundle"
18
- },
19
16
  {
20
17
  "$ref": "definition.width_class.input"
21
18
  }
@@ -45,9 +45,6 @@
45
45
  {
46
46
  "$ref": "definition.field"
47
47
  },
48
- {
49
- "$ref": "validations#/definitions/string_bundle"
50
- },
51
48
  {
52
49
  "$ref": "definition.width_class.input"
53
50
  }
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: 2.14.0
4
+ version: 2.15.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - MoJ Forms
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-20 00:00:00.000000000 Z
11
+ date: 2022-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: govuk_design_system_formbuilder
@@ -295,6 +295,7 @@ files:
295
295
  - app/models/metadata_presenter/offline_upload_adapter.rb
296
296
  - app/models/metadata_presenter/page.rb
297
297
  - app/models/metadata_presenter/page_answers.rb
298
+ - app/models/metadata_presenter/page_warning.rb
298
299
  - app/models/metadata_presenter/previous_page.rb
299
300
  - app/models/metadata_presenter/route.rb
300
301
  - app/models/metadata_presenter/row_number.rb
@@ -311,6 +312,7 @@ files:
311
312
  - app/validators/metadata_presenter/accept_validator.rb
312
313
  - app/validators/metadata_presenter/base_validator.rb
313
314
  - app/validators/metadata_presenter/date_validator.rb
315
+ - app/validators/metadata_presenter/email_validator.rb
314
316
  - app/validators/metadata_presenter/max_length_validator.rb
315
317
  - app/validators/metadata_presenter/max_size_validator.rb
316
318
  - app/validators/metadata_presenter/min_length_validator.rb
@@ -330,6 +332,7 @@ files:
330
332
  - app/views/metadata_presenter/component/_components.html.erb
331
333
  - app/views/metadata_presenter/component/_content.html.erb
332
334
  - app/views/metadata_presenter/component/_date.html.erb
335
+ - app/views/metadata_presenter/component/_email.html.erb
333
336
  - app/views/metadata_presenter/component/_number.html.erb
334
337
  - app/views/metadata_presenter/component/_radios.html.erb
335
338
  - app/views/metadata_presenter/component/_text.html.erb
@@ -356,6 +359,7 @@ files:
356
359
  - default_metadata/component/checkboxes.json
357
360
  - default_metadata/component/content.json
358
361
  - default_metadata/component/date.json
362
+ - default_metadata/component/email.json
359
363
  - default_metadata/component/number.json
360
364
  - default_metadata/component/radios.json
361
365
  - default_metadata/component/text.json
@@ -380,6 +384,7 @@ files:
380
384
  - default_metadata/service/base.json
381
385
  - default_metadata/string/error.accept.json
382
386
  - default_metadata/string/error.date.json
387
+ - default_metadata/string/error.email.json
383
388
  - default_metadata/string/error.max_length.json
384
389
  - default_metadata/string/error.max_size.json
385
390
  - default_metadata/string/error.min_length.json
@@ -422,6 +427,7 @@ files:
422
427
  - schemas/component/checkboxes.json
423
428
  - schemas/component/content.json
424
429
  - schemas/component/date.json
430
+ - schemas/component/email.json
425
431
  - schemas/component/number.json
426
432
  - schemas/component/radios.json
427
433
  - schemas/component/text.json
@@ -502,7 +508,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
502
508
  - !ruby/object:Gem::Version
503
509
  version: '0'
504
510
  requirements: []
505
- rubygems_version: 3.2.15
511
+ rubygems_version: 3.2.32
506
512
  signing_key:
507
513
  specification_version: 4
508
514
  summary: Service Metadata Presenter