diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index bc20637d1..8bdaabee1 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -6,6 +6,7 @@ //= require govuk_publishing_components/components/govspeak //= require govuk_publishing_components/components/print-link //= require govuk_publishing_components/components/radio +//= require govuk_publishing_components/components/single-page-notification-button //= require govuk_publishing_components/components/step-by-step-nav //= require_tree ./modules diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index c88216d2f..a65851cc5 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -42,6 +42,7 @@ $govuk-new-link-styles: true; @import 'govuk_publishing_components/components/radio'; @import 'govuk_publishing_components/components/related-navigation'; @import 'govuk_publishing_components/components/share-links'; +@import 'govuk_publishing_components/components/single-page-notification-button'; @import 'govuk_publishing_components/components/step-by-step-nav'; @import 'govuk_publishing_components/components/step-by-step-nav-header'; @import 'govuk_publishing_components/components/step-by-step-nav-related'; diff --git a/app/controllers/content_items_controller.rb b/app/controllers/content_items_controller.rb index 8f93584eb..7ba6b1b89 100644 --- a/app/controllers/content_items_controller.rb +++ b/app/controllers/content_items_controller.rb @@ -134,6 +134,10 @@ def render_template return end + # use these and `@content_item.base_path` in the template + @notification_button_visible = in_single_page_notifications_trial? + @include_single_page_notification_button_js = account_session_header.present? + request.variant = :print if params[:variant] == "print" respond_to do |format| @@ -205,6 +209,13 @@ def error_redirect(exception) def set_account_vary_header # Override the default from GovukPersonalisation::ControllerConcern so pages are cached on each flash message # variation, rather than caching pages per user - response.headers["Vary"] = [response.headers["Vary"], "GOVUK-Account-Session-Flash"].compact.join(", ") + response.headers["Vary"] = [response.headers["Vary"], "GOVUK-Account-Session-Exists", "GOVUK-Account-Session-Flash"].compact.join(", ") + end + + def in_single_page_notifications_trial? + %w[ + /government/publications/open-standards-for-government + /government/publications/identity-proofing-and-verification-of-an-individual + ].include? @content_item.base_path end end diff --git a/app/views/components/_published-dates.html.erb b/app/views/components/_published-dates.html.erb index d25e57e50..98caa7b43 100644 --- a/app/views/components/_published-dates.html.erb +++ b/app/views/components/_published-dates.html.erb @@ -4,10 +4,13 @@ history = Array(history) last_updated ||= false link_to_history ||= false - history_class = "app-c-published-dates--history" if history.any? + shared_helper = GovukPublishingComponents::Presenters::SharedHelper.new(local_assigns) + classes = %w(app-c-published-dates) + classes << "app-c-published-dates--history" if history.any? + classes << shared_helper.get_margin_bottom if local_assigns[:margin_bottom] %> <% if published || last_updated %> -
id="history" data-module="gem-toggle"<% end %> lang="en"> +
id="history" data-module="gem-toggle"<% end %> lang="en"> <% if published %> <%= t('components.published_dates.published', date: published) %> <% end %> diff --git a/app/views/components/docs/published-dates.yml b/app/views/components/docs/published-dates.yml index d7f5652aa..ba57ef3f6 100644 --- a/app/views/components/docs/published-dates.yml +++ b/app/views/components/docs/published-dates.yml @@ -40,3 +40,9 @@ examples: - display_time: 14th October 2000 note: Updated information on pupil premium reviews and what information schools need to publish on their websites. timestamp: 2000-10-14T15:42:37.000+00:00 + with_custom_margin_bottom: + description: | + The component accepts a number for margin bottom from 0 to 9 (0px to 60px) using the [GOV.UK Frontend spacing scale](https://design-system.service.gov.uk/styles/spacing/#the-responsive-spacing-scale). By default, the component does not have a bottom margin. + data: + published: 1st January 1990 + margin_bottom: 8 diff --git a/app/views/content_items/publication.html.erb b/app/views/content_items/publication.html.erb index cc3c181c4..a3d944432 100644 --- a/app/views/content_items/publication.html.erb +++ b/app/views/content_items/publication.html.erb @@ -18,6 +18,12 @@
<%= render 'shared/publisher_metadata_with_logo' %> +<%= render 'govuk_publishing_components/components/single_page_notification_button', { + base_path: @content_item.base_path, + js_enhancement: @include_single_page_notification_button_js, + margin_bottom: 6, + button_location: "top", +} if @notification_button_visible %> <%= render 'shared/history_notice', content_item: @content_item %> <%= render 'govuk_publishing_components/components/notice', @content_item.withdrawal_notice_component %> @@ -53,8 +59,15 @@ <%= render 'components/published-dates', { published: @content_item.published, last_updated: @content_item.updated, - history: @content_item.history + history: @content_item.history, + margin_bottom: 3 } %> + + <%= render 'govuk_publishing_components/components/single_page_notification_button', { + base_path: @content_item.base_path, + js_enhancement: @include_single_page_notification_button_js, + button_location: "bottom", + } if @notification_button_visible %>
<%= render 'shared/sidebar_navigation' %> diff --git a/app/views/shared/_publisher_metadata_with_logo.html.erb b/app/views/shared/_publisher_metadata_with_logo.html.erb index 4048a0c90..be4175dcb 100644 --- a/app/views/shared/_publisher_metadata_with_logo.html.erb +++ b/app/views/shared/_publisher_metadata_with_logo.html.erb @@ -1,7 +1,11 @@ +<% + metadata_component_options = @content_item.publisher_metadata + metadata_component_options[:margin_bottom] = 3 if @notification_button_visible +%>
<% if @content_item.try(:logo) %> diff --git a/test/components/published_dates_test.rb b/test/components/published_dates_test.rb index 59426b2b7..5727d0129 100644 --- a/test/components/published_dates_test.rb +++ b/test/components/published_dates_test.rb @@ -86,4 +86,9 @@ def component_name assert_select ".app-c-published-dates--history a[href=\"#full-history\"][data-controls=\"full-history\"]" assert_select ".app-c-published-dates--history a[href=\"#full-history\"][data-expanded=\"false\"]" end + + test "applies a custom margin-bottom class if margin_bottom is specified" do + render_component(published: "1st November 2000", margin_bottom: 5) + assert_select '.app-c-published-dates.govuk-\!-margin-bottom-5' + end end