metadata_presenter 2.17.7 → 2.17.10

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: f720779f83e51414951678449c9ada6b5dfa9a01dedbd6abc7cfd07d22888e5d
4
- data.tar.gz: '0783ad47052d5bed54f003a6ddf664cefe0e4a198d8cf700909d6ab73e0b1169'
3
+ metadata.gz: 5a6e2dbe0fe23a5e22e74627e7b52a805e4cf84ea3023a8fb73deec9bcd87f1f
4
+ data.tar.gz: 16cd90ea4a6a64a8ddfe9c45a92df39338c2a25594db418a0671b3b6716d48ed
5
5
  SHA512:
6
- metadata.gz: 6fd29385c175133302917639ac3715298690402f2ea5169d00a3e40227de5b6da481ecb3ead7b2d5510bdf3b3686f6badea422156f99565fa08d56b4ecdf92b6
7
- data.tar.gz: c77e5b6d4130c8dc5e157e60d9dd13c2210e9edd04c2d198004024975efb899081dce7ad349b4b145b543d6edee80bb0a6b160bde041fe085f5677a56b75d167
6
+ metadata.gz: f173ec4fffdc2dc76f1defe9e726b5b00dbb5b6a1bff4e0d090fe4ba3d0c07d17b3bb2cd22b665cb0019637688e7c1b8c12a414806e41a8587daaf727bddc0f5
7
+ data.tar.gz: ff67ff698d108e681e631c514c82d716d9c5c000cfa30b03524f8aa34029b9d968b661bb167d69e1741401cb7b37dbafadcf1bb6ff62c3b202d4cfd305513d00
data/README.md CHANGED
@@ -49,6 +49,7 @@ that you need to write the following methods in your controller:
49
49
  2. load_user_data
50
50
  3. editable?
51
51
  4. create_submission
52
+ 5. assign_autocomplete_items
52
53
 
53
54
  The user answers can be accessed via `params[:answers]`.
54
55
 
@@ -80,18 +81,8 @@ mountable app:
80
81
  The `create_submission` is related to process the submission in a backend
81
82
  service.
82
83
 
84
+ The `autocomplete_items` takes the components on a page and retrieves any items for them that may exist. For the Editor it will make an API call, for the Runner it will look it up via an environment variable.
85
+
83
86
  ## Generate documentation
84
87
 
85
88
  Run `rake doc` and open the doc/index.html
86
-
87
- ## Flow diagrams
88
-
89
- You can generate flow diagrams calling a rake task:
90
-
91
- ```
92
- brew install graphviz
93
- SERVICE_METADATA="some-form-metadata" rails metadata:flow
94
- ```
95
-
96
- This will generate an image with the flow for that metadata. Open that image
97
- and profit!
@@ -41,15 +41,22 @@ module MetadataPresenter
41
41
  helper_method :analytics_cookie_name
42
42
 
43
43
  def allow_analytics?
44
- no_analytics_cookie? || cookies[analytics_cookie_name] == 'accepted'
44
+ cookies[analytics_cookie_name] == 'accepted'
45
45
  end
46
46
  helper_method :allow_analytics?
47
47
 
48
48
  def show_cookie_banner?
49
- no_analytics_cookie? && analytics_tags_present?
49
+ no_analytics_cookie?
50
50
  end
51
51
  helper_method :show_cookie_banner?
52
52
 
53
+ def analytics_tags_present?
54
+ Rails.application.config.supported_analytics.values.flatten.any? do |analytic|
55
+ ENV[analytic].present?
56
+ end
57
+ end
58
+ helper_method :analytics_tags_present?
59
+
53
60
  private
54
61
 
55
62
  def not_found
@@ -60,12 +67,6 @@ module MetadataPresenter
60
67
  redirect_to File.join(request.script_name, url)
61
68
  end
62
69
 
63
- def analytics_tags_present?
64
- Rails.application.config.supported_analytics.values.flatten.any? do |analytic|
65
- ENV[analytic].present?
66
- end
67
- end
68
-
69
70
  def no_analytics_cookie?
70
71
  cookies[analytics_cookie_name].blank?
71
72
  end
@@ -5,6 +5,11 @@ module MetadataPresenter
5
5
  @page ||= service.find_page_by_url(request.env['PATH_INFO'])
6
6
 
7
7
  if @page
8
+ if @page.autocomplete_component_present?
9
+ items = autocomplete_items(@page.components)
10
+ @page.assign_autocomplete_items(items)
11
+ end
12
+
8
13
  @page_answers = PageAnswers.new(@page, @user_data)
9
14
  render template: @page.template
10
15
  else
@@ -0,0 +1,9 @@
1
+ class MetadataPresenter::AutocompleteItem < MetadataPresenter::Metadata
2
+ def id
3
+ value
4
+ end
5
+
6
+ def name
7
+ text
8
+ end
9
+ end
@@ -20,10 +20,14 @@ class MetadataPresenter::Component < MetadataPresenter::Metadata
20
20
 
21
21
  def items
22
22
  Array(metadata.items).map do |item|
23
- MetadataPresenter::Item.new(item, editor: editor?)
23
+ item_klass.new(item, editor: editor?)
24
24
  end
25
25
  end
26
26
 
27
+ def item_klass
28
+ type == 'autocomplete' ? MetadataPresenter::AutocompleteItem : MetadataPresenter::Item
29
+ end
30
+
27
31
  SUPPORTS_BRANCHING = %w[radios checkboxes].freeze
28
32
 
29
33
  def supports_branching?
@@ -39,7 +39,8 @@ module MetadataPresenter
39
39
  end
40
40
 
41
41
  def components
42
- to_components(metadata.components, collection: :components)
42
+ @components ||=
43
+ to_components(metadata.components, collection: :components)
43
44
  end
44
45
 
45
46
  def extra_components
@@ -104,6 +105,17 @@ module MetadataPresenter
104
105
  type == 'page.multiplequestions'
105
106
  end
106
107
 
108
+ def autocomplete_component_present?
109
+ components.any? { |component| component.type == 'autocomplete' }
110
+ end
111
+
112
+ def assign_autocomplete_items(items)
113
+ component_uuids = items.keys
114
+ components.each do |component|
115
+ component.items = items[component.uuid] if component.uuid.in?(component_uuids)
116
+ end
117
+ end
118
+
107
119
  private
108
120
 
109
121
  def heading?
@@ -111,7 +123,7 @@ module MetadataPresenter
111
123
  end
112
124
 
113
125
  def to_components(node_components, collection:)
114
- node_components&.map do |component|
126
+ Array(node_components).map do |component|
115
127
  MetadataPresenter::Component.new(
116
128
  component.merge(collection: collection),
117
129
  editor: editor?
@@ -38,8 +38,7 @@
38
38
  </main>
39
39
  </div>
40
40
  <%= render template: 'metadata_presenter/footer/footer' %>
41
-
42
- <%= javascript_pack_tag 'application' %>
41
+ <%= javascript_pack_tag 'runner_application' %>
43
42
  <%= javascript_pack_tag 'govuk' %>
44
43
  </body>
45
44
  </html>
@@ -1,16 +1,8 @@
1
- <!-- Google Analytics 4 -->
1
+ <!-- Form Owner Google Analytics 4 -->
2
2
  <% if Rails.application.config.respond_to?(:global_ga4) %>
3
- <script>
4
- gtag('config', '<%= measurement_id %>');
5
- </script>
6
- <% else %>
7
- <script async src="https://www.googletagmanager.com/gtag/js?id=<%= measurement_id %>"></script>
8
- <script>
9
- window.dataLayer = window.dataLayer || [];
10
- function gtag(){dataLayer.push(arguments);}
11
- gtag('js', new Date());
12
-
13
- gtag('config', '<%= measurement_id %>');
14
- </script>
3
+ <%# Global Google Analytics (GA4) should be included before this point so we only need a config setting %>
4
+ <script>
5
+ gtag('config', '<%= measurement_id %>');
6
+ </script>
15
7
  <% end %>
16
- <!-- End Google Analytics 4 -->
8
+ <!-- End Form Owner Google Analytics 4 -->
@@ -1,10 +1,9 @@
1
1
  <!-- Global MoJ Forms site tag (gtag.js) - Google Analytics 4 -->
2
- <script async src="https://www.googletagmanager.com/gtag/js?id=<%= measurement_id %>"></script>
2
+ <script async src="https://www.googletagmanager.com/gtag/js?id=#{global_measurement_id}"></script>
3
3
  <script>
4
4
  window.dataLayer = window.dataLayer || [];
5
5
  function gtag(){dataLayer.push(arguments);}
6
6
  gtag('js', new Date());
7
-
8
- gtag('config', '<%= measurement_id %>');
7
+ gtag('config', '<%= global_measurement_id %>');
9
8
  </script>
10
9
  <!-- End Global MoJ Forms site tag (gtag.js) - Google Analytics 4 -->
@@ -1,7 +1,7 @@
1
- <!-- Google Tag Manager -->
1
+ <!-- Google Tag Manager for Form Owner -->
2
2
  <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
3
3
  new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
4
4
  j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
5
5
  'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
6
6
  })(window,document,'script','dataLayer','<%= measurement_id %>');</script>
7
- <!-- End Google Tag Manager -->
7
+ <!-- End Google Tag Manager for Form Owner -->
@@ -1,4 +1,4 @@
1
- <!-- Google Universal Analytics -->
1
+ <!-- Google Universal Analytics for Form Owner -->
2
2
  <script>
3
3
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
4
4
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
@@ -8,4 +8,4 @@
8
8
  ga('create', '<%= measurement_id %>', 'auto');
9
9
  ga('send', 'pageview');
10
10
  </script>
11
- <!-- End Google Universal Analytics -->
11
+ <!-- End Google Universal Analytics for Form Owner -->
@@ -1,7 +1,11 @@
1
+ <%# MoJ Forms Google Analytic Reporting %>
1
2
  <% if Rails.application.config.respond_to?(:global_ga4) %>
2
- <%= render partial: 'metadata_presenter/analytics/global_analytics', locals: { measurement_id: Rails.application.config.global_ga4 } %>
3
+ <%= render partial: 'metadata_presenter/analytics/global_analytics', locals: { global_measurement_id: Rails.application.config.global_ga4 } %>
3
4
  <% end %>
4
5
 
5
- <% Rails.application.config.supported_analytics.each do |provider, analytics| %>
6
- <%= render partial: "metadata_presenter/analytics/#{provider}", locals: { analytics: analytics } %>
6
+ <%# Analytic reporting set by form owners %>
7
+ <% if analytics_tags_present? %>
8
+ <% Rails.application.config.supported_analytics.each do |provider, analytics| %>
9
+ <%= render partial: "metadata_presenter/analytics/#{provider}", locals: { analytics: analytics } %>
10
+ <% end %>
7
11
  <% end %>
@@ -11,4 +11,6 @@
11
11
  class: "govuk-!-width-two-thirds"
12
12
  %>
13
13
 
14
- <button type="button" class="fb-govuk-button fb-govuk-button-inverted"><%=t('actions.upload_options')%></button>
14
+ <% if editable? %>
15
+ <%= render partial: '/partials/editable_autocomplete', locals: { component: component } %>
16
+ <% end %>
@@ -21,7 +21,7 @@ Rails.application.config.supported_components =
21
21
  content: %w(content)
22
22
  },
23
23
  singlequestion: {
24
- input: %w(text textarea number date radios checkboxes email upload),
24
+ input: %w(text textarea number date radios checkboxes email upload autocomplete),
25
25
  content: %w()
26
26
  }
27
27
  })
@@ -69,6 +69,12 @@
69
69
  }
70
70
  },
71
71
  "2ef7d11e-0307-49e9-9fe2-345dc528dd66": {
72
+ "_type": "flow.page",
73
+ "next": {
74
+ "default": "c7755991-436b-4495-afa6-803db58cefbc"
75
+ }
76
+ },
77
+ "c7755991-436b-4495-afa6-803db58cefbc": {
72
78
  "_type": "flow.page",
73
79
  "next": {
74
80
  "default": "e337070b-f636-49a3-a65c-f506675265f0"
@@ -568,6 +574,33 @@
568
574
  }
569
575
  ]
570
576
  },
577
+ {
578
+ "_id": "page.countries",
579
+ "url": "countries",
580
+ "body": "Body section",
581
+ "lede": "",
582
+ "_type": "page.singlequestion",
583
+ "_uuid": "c7755991-436b-4495-afa6-803db58cefbc",
584
+ "heading": "",
585
+ "components": [
586
+ {
587
+ "_id": "countries_autocomplete_1",
588
+ "hint": "",
589
+ "name": "countries_autocomplete_1",
590
+ "_type": "autocomplete",
591
+ "_uuid": "4dc23b9c-9757-4526-813d-b43efbe07dad",
592
+ "items": [
593
+ ],
594
+ "errors": {
595
+ },
596
+ "legend": "Countries",
597
+ "validation": {
598
+ "required": true
599
+ }
600
+ }
601
+ ],
602
+ "section_heading": ""
603
+ },
571
604
  {
572
605
  "_id": "page.check-answers",
573
606
  "url": "check-answers",
@@ -1,3 +1,3 @@
1
1
  module MetadataPresenter
2
- VERSION = '2.17.7'.freeze
2
+ VERSION = '2.17.10'.freeze
3
3
  end
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.17.7
4
+ version: 2.17.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - MoJ Forms
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-05 00:00:00.000000000 Z
11
+ date: 2022-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: govuk_design_system_formbuilder
@@ -128,20 +128,6 @@ dependencies:
128
128
  - - ">="
129
129
  - !ruby/object:Gem::Version
130
130
  version: '0'
131
- - !ruby/object:Gem::Dependency
132
- name: ruby-graphviz
133
- requirement: !ruby/object:Gem::Requirement
134
- requirements:
135
- - - ">="
136
- - !ruby/object:Gem::Version
137
- version: '0'
138
- type: :development
139
- prerelease: false
140
- version_requirements: !ruby/object:Gem::Requirement
141
- requirements:
142
- - - ">="
143
- - !ruby/object:Gem::Version
144
- version: '0'
145
131
  - !ruby/object:Gem::Dependency
146
132
  name: rspec-rails
147
133
  requirement: !ruby/object:Gem::Requirement
@@ -276,6 +262,7 @@ files:
276
262
  - app/helpers/metadata_presenter/application_helper.rb
277
263
  - app/helpers/metadata_presenter/default_text.rb
278
264
  - app/jobs/metadata_presenter/application_job.rb
265
+ - app/models/metadata_presenter/autocomplete_item.rb
279
266
  - app/models/metadata_presenter/branch_destinations.rb
280
267
  - app/models/metadata_presenter/column_number.rb
281
268
  - app/models/metadata_presenter/component.rb
@@ -458,7 +445,6 @@ files:
458
445
  - lib/metadata_presenter/engine.rb
459
446
  - lib/metadata_presenter/test_helpers.rb
460
447
  - lib/metadata_presenter/version.rb
461
- - lib/tasks/metadata_presenter_tasks.rake
462
448
  - schemas/component/autocomplete.json
463
449
  - schemas/component/checkboxes.json
464
450
  - schemas/component/content.json
@@ -1,89 +0,0 @@
1
- require 'metadata_presenter/test_helpers'
2
-
3
- namespace :metadata do
4
- include MetadataPresenter::TestHelpers
5
-
6
- desc 'Represent the flow objects in human readable form'
7
- task flow: :environment do
8
- require 'ruby-graphviz'
9
- metadata = ENV['SERVICE_METADATA'] || metadata_fixture('branching')
10
- service = MetadataPresenter::Service.new(metadata)
11
-
12
- graph = MetadataPresenter::Graph.new(service)
13
-
14
- graph.draw.generate_image
15
- puts "Generated file #{graph.filename}"
16
- system("open #{graph.filename}")
17
- end
18
- end
19
-
20
- module MetadataPresenter
21
- class Graph
22
- attr_reader :service, :filename, :nodes
23
-
24
- delegate :metadata, :start_page, :find_page_by_uuid, :service_slug, to: :service
25
-
26
- def initialize(service)
27
- @service = service
28
- @graphviz = GraphViz.new(:G, type: :digraph)
29
- @filename = Rails.root.join('tmp', "#{service_slug}.png")
30
- @nodes = {}
31
- end
32
-
33
- def draw
34
- draw_nodes
35
- draw_edges
36
-
37
- self
38
- end
39
-
40
- def generate_image
41
- @graphviz.output(png: filename)
42
- end
43
-
44
- private
45
-
46
- def draw_nodes
47
- flow.each do |id, _value|
48
- flow_object = service.flow_object(id)
49
-
50
- if flow_object.branch?
51
- full_description = flow_object.conditionals.map.each_with_index do |conditional, _index|
52
- conditional.expressions.map { |expression|
53
- expression.service = service
54
-
55
- "#{expression.expression_component.humanised_title} #{expression.operator} #{expression.field_label}"
56
- }.join(" #{conditional.type} ")
57
- end
58
- nodes[id] = @graphviz.add_nodes(full_description.flatten.join(' / '))
59
- else
60
- current_page = find_page_by_uuid(id)
61
- nodes[id] = @graphviz.add_nodes(current_page.url)
62
- end
63
- end
64
- end
65
-
66
- def draw_edges
67
- flow.each do |id, _value|
68
- flow_object = service.flow_object(id)
69
- current_node = nodes[id]
70
- node_next = nodes[flow_object.default_next]
71
-
72
- if flow_object.branch?
73
- @graphviz.add_edges(current_node, node_next, label: 'Conditions are not met', labelfontsize: 8) if node_next
74
-
75
- flow_object.group_by_page.each do |page_uuid, _conditionals|
76
- conditionals_node = nodes[page_uuid]
77
- @graphviz.add_edges(current_node, conditionals_node, label: 'Conditions are met', labelfontsize: 8) if conditionals_node
78
- end
79
- elsif node_next
80
- @graphviz.add_edges(current_node, node_next)
81
- end
82
- end
83
- end
84
-
85
- def flow
86
- service.flow
87
- end
88
- end
89
- end