metadata_presenter 2.17.8 → 2.17.11

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: fd76b81cc2912dc02d76759ad2ea32cf276786d08a54a3c8b2eab163bc039139
4
- data.tar.gz: 283d0486ab6d17e3258ddf7da5603a70adc3591aac3c43c3d646c259b20800a0
3
+ metadata.gz: 5c0fc8809f2ded3ff926abae242977d1e502bb49f2dfecc64c91c8fd43e3ca8d
4
+ data.tar.gz: afaf9751bf92bfccdfb9b5ca8362b179b6999acab4efb1e098f51873ef15149e
5
5
  SHA512:
6
- metadata.gz: eb930c0728e2c01a503f66074258365110dceb236770dd17598b974fdedb803596937003da48f7079d486e91e67788a0cafd24b522948f6c69dfeaface16a0db
7
- data.tar.gz: 0670fa58f9d8076f49c89c6f4e8df5d33b8075fd72a2b0be1f0fd84df0024cc0257566ea7fccfea914d4dee175e2a56a77f96abd90a216d91507b4f90af2ab9f
6
+ metadata.gz: e738295503ef40d85ea5129be00bd0896e8f0b7273a27bce1f8203a3b12e7d2e4f50cc5d214f9503c308aa0d3033bbe69f31499b5584da64725ea90b77066fc9
7
+ data.tar.gz: 0c4d1f59c8809212399ea14d8446dff1088d26446463a3eabf9ba6c0435df16c4a05901f2d66c5fde4ae969d16a0149b6b71505fda987bad2b4f13529a4bcaf7
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,6 +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
@@ -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
+ (Rails.application.config.respond_to?(:global_ga4) || analytics_tags_present?) && 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 %>
@@ -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.8'.freeze
2
+ VERSION = '2.17.11'.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.8
4
+ version: 2.17.11
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-13 00:00:00.000000000 Z
11
+ date: 2022-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: govuk_design_system_formbuilder
@@ -262,6 +262,7 @@ files:
262
262
  - app/helpers/metadata_presenter/application_helper.rb
263
263
  - app/helpers/metadata_presenter/default_text.rb
264
264
  - app/jobs/metadata_presenter/application_job.rb
265
+ - app/models/metadata_presenter/autocomplete_item.rb
265
266
  - app/models/metadata_presenter/branch_destinations.rb
266
267
  - app/models/metadata_presenter/column_number.rb
267
268
  - app/models/metadata_presenter/component.rb