diff --git a/Gemfile b/Gemfile index aa1b76acf..845e17e44 100644 --- a/Gemfile +++ b/Gemfile @@ -6,6 +6,7 @@ gem "dalli" gem "gds-api-adapters" gem "govuk_ab_testing" gem "govuk_app_config" +gem "govuk_personalisation" gem "govuk_publishing_components" gem "htmlentities" gem "plek" diff --git a/Gemfile.lock b/Gemfile.lock index 8be96ea9a..fe461bf97 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -127,6 +127,8 @@ GEM sentry-raven (~> 3.1.1) statsd-ruby (~> 1.5.0) unicorn (>= 5.4, < 5.9) + govuk_personalisation (0.5.0) + rails (~> 6) govuk_publishing_components (24.13.5) govuk_app_config kramdown @@ -381,6 +383,7 @@ DEPENDENCIES gds-api-adapters govuk_ab_testing govuk_app_config + govuk_personalisation govuk_publishing_components govuk_schemas govuk_test diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 061e71397..c58d48c87 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -39,6 +39,7 @@ $govuk-use-legacy-palette: false; @import 'govuk_publishing_components/components/step-by-step-nav-header'; @import 'govuk_publishing_components/components/step-by-step-nav-related'; @import 'govuk_publishing_components/components/subscription-links'; +@import 'govuk_publishing_components/components/success-alert'; @import 'govuk_publishing_components/components/title'; @import 'govuk_publishing_components/components/translation-nav'; @import 'govuk_publishing_components/components/warning-text'; diff --git a/app/assets/stylesheets/components/_save-this-page.scss b/app/assets/stylesheets/components/_save-this-page.scss index 93c15d9f9..de0da05c9 100644 --- a/app/assets/stylesheets/components/_save-this-page.scss +++ b/app/assets/stylesheets/components/_save-this-page.scss @@ -2,4 +2,8 @@ border: 1px solid govuk-colour('mid-grey'); border-top: 2px solid govuk-colour('blue'); padding: govuk-spacing(4) govuk-spacing(4) 0; + + @include govuk-media-query($from: desktop) { + display: inline-block; + } } diff --git a/app/controllers/content_items_controller.rb b/app/controllers/content_items_controller.rb index 1e3bbc6d1..f7c0bea41 100644 --- a/app/controllers/content_items_controller.rb +++ b/app/controllers/content_items_controller.rb @@ -1,4 +1,5 @@ class ContentItemsController < ApplicationController + include GovukPersonalisation::AccountConcern rescue_from GdsApi::HTTPForbidden, with: :error_403 rescue_from GdsApi::HTTPNotFound, with: :error_notfound rescue_from GdsApi::HTTPGone, with: :error_410 @@ -199,4 +200,23 @@ def error_redirect(exception) ) redirect_to destination, status: status_code end + + def save_this_page_enabled? + ENV["FEATURE_FLAG_SAVE_A_PAGE"] == "enabled" + end + helper_method :save_this_page_enabled? + + helper_method :logged_in? + + def user_has_saved_page? + GdsApi.account_api.get_saved_page( + page_path: request.path, + govuk_account_session: @account_session_header, + ).to_hash["saved_page"].present? + rescue GdsApi::HTTPNotFound + false + rescue GdsApi::HTTPUnauthorized + logout! + end + helper_method :user_has_saved_page? end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 274bdd347..ae3d63249 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -28,6 +28,18 @@ def current_path_without_query_string request.original_fullpath.split("?", 2).first end + def has_saved_page_confirmation? + return false unless save_this_page_enabled? + + personalisation_param.present? + end + + def personalisation_param + return unless %w[page_saved page_removed].include?(params["personalisation"]) + + params["personalisation"] + end + private def active_proposition_mapping diff --git a/app/helpers/save_this_page_helper.rb b/app/helpers/save_this_page_helper.rb index b6ff6a7fc..0a443d1be 100644 --- a/app/helpers/save_this_page_helper.rb +++ b/app/helpers/save_this_page_helper.rb @@ -2,8 +2,8 @@ module SaveThisPageHelper attr_reader :page_is_saved, :signed_in, :page_path PAGE_IS_SAVED_LINK_HREF = { - true => "/account/saved-pages/remove?page_path=", - false => "/account/saved-pages/add?page_path=", + true => "#{Plek.new.website_root}/account/saved-pages/remove?page_path=", + false => "#{Plek.new.website_root}/account/saved-pages/add?page_path=", }.freeze SEE_SAVED_PAGES_LOGGED_IN = { @@ -27,6 +27,6 @@ def link_href(options) def additional_text(options) signed_in = options[:signed_in] || false - I18n.t(SEE_SAVED_PAGES_LOGGED_IN[signed_in], link: "/account/saved-pages") + I18n.t(SEE_SAVED_PAGES_LOGGED_IN[signed_in], link: "#{Plek.new.website_root}/account/saved-pages", additional_class: options[:additional_class]) end end diff --git a/app/views/content_items/_body_with_related_links.html.erb b/app/views/content_items/_body_with_related_links.html.erb index 92547232c..d9049a898 100644 --- a/app/views/content_items/_body_with_related_links.html.erb +++ b/app/views/content_items/_body_with_related_links.html.erb @@ -7,22 +7,25 @@ -
+
- <%= render 'govuk_publishing_components/components/govspeak', { - direction: page_text_direction, - disable_youtube_expansions: true, - } do %> +
+ <%= render 'govuk_publishing_components/components/govspeak', { + direction: page_text_direction, + disable_youtube_expansions: true, + } do %> <%= raw(@content_item.body) %> - <% end %> + <% end %> - <% if @content_item.last_updated && @content_item.schema_name == "help_page" %> + <% if @content_item.last_updated && @content_item.schema_name == "help_page" %> <%= render "components/published-dates", { last_updated: @content_item.last_updated } %> - <% end %> -
+ <% end %> +
+ <%= render 'content_items/save_page' %> +
<%= render 'shared/sidebar_navigation' %>
diff --git a/app/views/content_items/_save_page.html.erb b/app/views/content_items/_save_page.html.erb new file mode 100644 index 000000000..5489159cd --- /dev/null +++ b/app/views/content_items/_save_page.html.erb @@ -0,0 +1,7 @@ +<%= content_tag(:div, class: "responsive-bottom-margin") do %> + <%= render 'components/save_this_page', { + page_path: request.path, + signed_in: logged_in?, + page_is_saved: user_has_saved_page?, + } %> +<% end if save_this_page_enabled? %> diff --git a/app/views/content_items/case_study.html.erb b/app/views/content_items/case_study.html.erb index 0a66b9404..ed2cba897 100644 --- a/app/views/content_items/case_study.html.erb +++ b/app/views/content_items/case_study.html.erb @@ -18,26 +18,30 @@ <%= render 'govuk_publishing_components/components/notice', @content_item.withdrawal_notice_component %>
-
-
- <%= render 'components/figure', +
+
+
+ <%= render 'components/figure', src: @content_item.image["url"], alt: @content_item.image["alt_text"], credit: @content_item.image["credit"], caption: @content_item.image["caption"] if @content_item.image %> - <%= render 'govuk_publishing_components/components/govspeak', { - direction: page_text_direction, - } do %> - <%= raw(@content_item.body) %> - <% end %> -
+ <%= render 'govuk_publishing_components/components/govspeak', { + direction: page_text_direction, + } do %> + <%= raw(@content_item.body) %> + <% end %> +
- <%= render 'components/published-dates', { + <%= render 'components/published-dates', { published: @content_item.published, last_updated: @content_item.updated, history: @content_item.history } %> +
+ + <%= render 'content_items/save_page' %>
<%= render 'shared/sidebar_navigation' %> diff --git a/app/views/content_items/consultation.html.erb b/app/views/content_items/consultation.html.erb index 7043e7b38..40c2e1ec1 100644 --- a/app/views/content_items/consultation.html.erb +++ b/app/views/content_items/consultation.html.erb @@ -200,6 +200,8 @@ history: @content_item.history } %>
+ + <%= render 'content_items/save_page' %>
<%= render 'shared/sidebar_navigation' %> diff --git a/app/views/content_items/contact.html.erb b/app/views/content_items/contact.html.erb index 297a50c8d..5fb76aa50 100644 --- a/app/views/content_items/contact.html.erb +++ b/app/views/content_items/contact.html.erb @@ -14,94 +14,97 @@
- - <% body = capture do %> - <% if @content_item.online_form_links.any? %> -

<%= t("contact.online") %>

- <% @content_item.online_form_links.each do |link| %> -

- <%= link_to(link[:title], link[:url]) %> -

- <%= link[:description] %> +
+ <% body = capture do %> + <% if @content_item.online_form_links.any? %> +

<%= t("contact.online") %>

+ <% @content_item.online_form_links.each do |link| %> +

+ <%= link_to(link[:title], link[:url]) %> +

+ <%= link[:description] %> + <% end %> + <%= @content_item.online_form_body %> <% end %> - <%= @content_item.online_form_body %> - <% end %> - <% if @content_item.show_webchat? %> -

<%= t("contact.webchat") %>

- <%= render 'shared/webchat' %> - <% end %> + <% if @content_item.show_webchat? %> +

<%= t("contact.webchat") %>

+ <%= render 'shared/webchat' %> + <% end %> - <% if @content_item.email.any? %> -

<%= t("contact.email") %>

- <% @content_item.email.each do |email_group| %> -

- <% email_group[:v_card].each do |v_card_part| %> + <% if @content_item.email.any? %> +

<%= t("contact.email") %>

+ <% @content_item.email.each do |email_group| %> +

+ <% email_group[:v_card].each do |v_card_part| %> <%= v_card_part[:value] %>
- <% end %> - <%= mail_to email_group[:email], email_group[:email], class: 'email' %> -

+ <% end %> + <%= mail_to email_group[:email], email_group[:email], class: 'email' %> +

- <%= email_group[:description] %> + <%= email_group[:description] %> + <% end %> + <%= @content_item.email_body %> <% end %> - <%= @content_item.email_body %> - <% end %> - <% if @content_item.phone.any? %> -

<%= t("contact.phone") %>

- <% @content_item.phone.each do |phone_group| %> - <% if @content_item.phone.size > 1 %> -

<%= phone_group[:title] %>

- <% end %> - <%= phone_group[:description] %> - <% if phone_group[:numbers].any? %> -
- <% phone_group[:numbers].each do |number| %> -

<%= number[:label] %>:
<%= number[:number] %>

- <% end%> -
- <% end %> - <% if phone_group[:opening_times].present? %> -

Opening times:

- <%= phone_group[:opening_times] %> - <% end %> + <% if @content_item.phone.any? %> +

<%= t("contact.phone") %>

+ <% @content_item.phone.each do |phone_group| %> + <% if @content_item.phone.size > 1 %> +

<%= phone_group[:title] %>

+ <% end %> + <%= phone_group[:description] %> + <% if phone_group[:numbers].any? %> +
+ <% phone_group[:numbers].each do |number| %> +

<%= number[:label] %>:
<%= number[:number] %>

+ <% end%> +
+ <% end %> + <% if phone_group[:opening_times].present? %> +

Opening times:

+ <%= phone_group[:opening_times] %> + <% end %> - <% if phone_group[:best_time_to_call].present? %> -

Best time to call:

- <%= phone_group[:best_time_to_call] %> + <% if phone_group[:best_time_to_call].present? %> +

Best time to call:

+ <%= phone_group[:best_time_to_call] %> + <% end %> <% end %> - <% end %> - <%= @content_item.phone_body %> + <%= @content_item.phone_body %> -

- <%= link_to t("contact.find_call_charges"), "/call-charges" %> -

- <% end %> +

+ <%= link_to t("contact.find_call_charges"), "/call-charges" %> +

+ <% end %> - <% if @content_item.post.any? %> -

Post

- <% @content_item.post.each do |post_group| %> - <%= post_group[:description] %> -
-

- <% post_group[:v_card].each do |v_card_part| %> + <% if @content_item.post.any? %> +

Post

+ <% @content_item.post.each do |post_group| %> + <%= post_group[:description] %> +
+

+ <% post_group[:v_card].each do |v_card_part| %> <%= v_card_part[:value] %>
- <% end %> -

-
+ <% end %> +

+
+ <% end %> + <%= @content_item.post_body %> <% end %> - <%= @content_item.post_body %> <% end %> - <% end %> - <%= render 'govuk_publishing_components/components/govspeak' do %> - <%= body %> - <% end %> + <%= render 'govuk_publishing_components/components/govspeak' do %> + <%= body %> + <% end %> +
+ + <%= render 'content_items/save_page' %>
<%= render 'shared/sidebar_navigation' %>
diff --git a/app/views/content_items/corporate_information_page.html.erb b/app/views/content_items/corporate_information_page.html.erb index 4e3bc45dc..6fcf8127c 100644 --- a/app/views/content_items/corporate_information_page.html.erb +++ b/app/views/content_items/corporate_information_page.html.erb @@ -56,3 +56,10 @@ +<% if save_this_page_enabled? %> +
+
+ <%= render 'content_items/save_page' %> +
+
+<% end %> diff --git a/app/views/content_items/detailed_guide.html.erb b/app/views/content_items/detailed_guide.html.erb index b7d3bfaa1..8193c07f6 100644 --- a/app/views/content_items/detailed_guide.html.erb +++ b/app/views/content_items/detailed_guide.html.erb @@ -68,8 +68,9 @@ margin_top: 0, margin_bottom: 6, } unless brexit_child_taxon %> + + <%= render 'content_items/save_page' %> <%= render 'shared/sidebar_navigation' %> - <%= render 'shared/footer_navigation' %> diff --git a/app/views/content_items/document_collection.html.erb b/app/views/content_items/document_collection.html.erb index 08273a19f..964e39839 100644 --- a/app/views/content_items/document_collection.html.erb +++ b/app/views/content_items/document_collection.html.erb @@ -38,6 +38,8 @@ } %> <% end %> + + <%= render 'content_items/save_page' %> <%= render 'shared/sidebar_navigation' %> diff --git a/app/views/content_items/fatality_notice.html.erb b/app/views/content_items/fatality_notice.html.erb index 1091d87d7..1bc1db406 100644 --- a/app/views/content_items/fatality_notice.html.erb +++ b/app/views/content_items/fatality_notice.html.erb @@ -18,27 +18,29 @@ <%= render 'govuk_publishing_components/components/notice', @content_item.withdrawal_notice_component %>
-
-
- <%= render 'components/important-metadata', +
+
+
+ <%= render 'components/important-metadata', items: @content_item.important_metadata %> - <%= render 'components/figure', + <%= render 'components/figure', src: @content_item.image["url"], alt: @content_item.image["alt_text"], credit: @content_item.image["credit"], caption: @content_item.image["caption"] if @content_item.image %> - <%= render 'govuk_publishing_components/components/govspeak', { - direction: page_text_direction, - } do %> - <%= raw(@content_item.body) %> - <% end %> -
- - <%= render 'components/published-dates', { + <%= render 'govuk_publishing_components/components/govspeak', { + direction: page_text_direction, + } do %> + <%= raw(@content_item.body) %> + <% end %> +
+ <%= render 'components/published-dates', { published: @content_item.published, last_updated: @content_item.updated, history: @content_item.history } %> +
+ <%= render 'content_items/save_page' %>
<%= render 'shared/sidebar_navigation' %>
diff --git a/app/views/content_items/html_publication.html.erb b/app/views/content_items/html_publication.html.erb index 765fed835..7fb5b29cc 100644 --- a/app/views/content_items/html_publication.html.erb +++ b/app/views/content_items/html_publication.html.erb @@ -59,6 +59,7 @@ <%= render "govuk_publishing_components/components/govspeak_html_publication", {} do %> <%= raw(@content_item.govspeak_body[:content]) %> <% end %> + <%= render 'content_items/save_page' %>
diff --git a/app/views/content_items/news_article.html.erb b/app/views/content_items/news_article.html.erb index 345cdde18..caeb0c7eb 100644 --- a/app/views/content_items/news_article.html.erb +++ b/app/views/content_items/news_article.html.erb @@ -19,33 +19,37 @@ <%= render 'govuk_publishing_components/components/notice', @content_item.withdrawal_notice_component %>
-
-
- <%= render 'components/figure', +
+
+
+ <%= render 'components/figure', src: @content_item.image["url"], alt: @content_item.image["alt_text"], credit: @content_item.image["credit"], caption: @content_item.image["caption"] if @content_item.image %> - <%= render "govuk_publishing_components/components/govspeak", { - direction: page_text_direction, - } do %> - <%= raw(@content_item.body) %> - <% end %> -
+ <%= render "govuk_publishing_components/components/govspeak", { + direction: page_text_direction, + } do %> + <%= raw(@content_item.body) %> + <% end %> +
-
- <%= render 'govuk_publishing_components/components/share_links', - links: @content_item.share_links, - track_as_sharing: true, - title: t('components.share_links.share_this_page') - %> -
+
+ <%= render 'govuk_publishing_components/components/share_links', + links: @content_item.share_links, + track_as_sharing: true, + title: t('components.share_links.share_this_page') + %> +
- <%= render 'components/published-dates', { + <%= render 'components/published-dates', { published: @content_item.published, last_updated: @content_item.updated, history: @content_item.history } %> +
+ + <%= render 'content_items/save_page' %>
<%= render 'shared/sidebar_navigation' %> diff --git a/app/views/content_items/publication.html.erb b/app/views/content_items/publication.html.erb index e266ef5fe..0211200a8 100644 --- a/app/views/content_items/publication.html.erb +++ b/app/views/content_items/publication.html.erb @@ -25,34 +25,37 @@ <%= render 'govuk_publishing_components/components/notice', @content_item.withdrawal_notice_component %>
-
- <%= render 'components/important-metadata', items: @content_item.important_metadata %> +
- <%= render "attachments", + <%= render 'components/important-metadata', items: @content_item.important_metadata %> +
+ <%= render "attachments", title: t("publication.documents", count: 5), # This should always be pluralised. legacy_pre_rendered_documents: @content_item.documents, - attachments: @content_item.featured_attachments %> - - -
- <%= render "govuk_publishing_components/components/heading", { - text: t("publication.details"), - mobile_top_margin: true, - } %> - - <%= render "govuk_publishing_components/components/govspeak", { - direction: page_text_direction, - } do %> - <%= raw(@content_item.details) %> - <% end %> -
-
- - <%= render 'components/published-dates', { + attachments: @content_item.featured_attachments + %> + +
+ <%= render "govuk_publishing_components/components/heading", { + text: t("publication.details"), + mobile_top_margin: true, + } %> + + <%= render "govuk_publishing_components/components/govspeak", { + direction: page_text_direction, + } do %> + <%= raw(@content_item.details) %> + <% end %> +
+
+ + <%= render 'components/published-dates', { published: @content_item.published, last_updated: @content_item.updated, history: @content_item.history } %> +
+ <%= render 'content_items/save_page' %>
<%= render 'shared/sidebar_navigation' %>
diff --git a/app/views/content_items/specialist_document.html.erb b/app/views/content_items/specialist_document.html.erb index 3c396dfd1..15db1aa93 100644 --- a/app/views/content_items/specialist_document.html.erb +++ b/app/views/content_items/specialist_document.html.erb @@ -61,8 +61,9 @@ <%= @content_item.finder_link %>
<% end %> - <% end %> + + <%= render 'content_items/save_page' %>
<%= render 'shared/sidebar_navigation' %>
diff --git a/app/views/content_items/speech.html.erb b/app/views/content_items/speech.html.erb index 9d303431c..b0374f2da 100644 --- a/app/views/content_items/speech.html.erb +++ b/app/views/content_items/speech.html.erb @@ -19,29 +19,33 @@ <%= render 'govuk_publishing_components/components/notice', @content_item.withdrawal_notice_component %>
-
-
- <%= render 'components/important-metadata', - items: @content_item.important_metadata %> +
+
+
+ <%= render 'components/important-metadata', + items: @content_item.important_metadata %> - <%= render 'components/figure', + <%= render 'components/figure', src: @content_item.image["url"], alt: @content_item.image["alt_text"], credit: @content_item.image["credit"], caption: @content_item.image["caption"] if @content_item.image %> - <%= render "govuk_publishing_components/components/govspeak", { + <%= render "govuk_publishing_components/components/govspeak", { direction: page_text_direction, } do %> <%= raw(@content_item.body) %> <% end %> -
+
- <%= render 'components/published-dates', { + <%= render 'components/published-dates', { published: @content_item.published, last_updated: @content_item.updated, history: @content_item.history } %> +
+ + <%= render 'content_items/save_page' %>
<%= render 'shared/sidebar_navigation' %> diff --git a/app/views/content_items/statistical_data_set.html.erb b/app/views/content_items/statistical_data_set.html.erb index ebb61fcd6..f639cfa88 100644 --- a/app/views/content_items/statistical_data_set.html.erb +++ b/app/views/content_items/statistical_data_set.html.erb @@ -25,22 +25,23 @@ <%= render 'components/important-metadata', items: @content_item.important_metadata %> <%= render "components/contents-list-with-body", contents: @content_item.contents do %> -
- <%= render "govuk_publishing_components/components/govspeak", { - direction: page_text_direction, - } do %> - <% raw(@content_item.body) %> - <% end %> +
+ <%= render "govuk_publishing_components/components/govspeak", { + direction: page_text_direction, + } do %> + <% raw(@content_item.body) %> + <% end %> -
-
- <%= render 'components/published-dates', { - published: @content_item.published, - last_updated: @content_item.updated, - history: @content_item.history - } %> -
+
+
+ <%= render 'components/published-dates', { + published: @content_item.published, + last_updated: @content_item.updated, + history: @content_item.history + } %> +
<% end %> + <%= render 'content_items/save_page' %>
<%= render 'shared/sidebar_navigation' %>
diff --git a/app/views/content_items/statistics_announcement.html.erb b/app/views/content_items/statistics_announcement.html.erb index 97b640aa6..3e750fac2 100644 --- a/app/views/content_items/statistics_announcement.html.erb +++ b/app/views/content_items/statistics_announcement.html.erb @@ -42,6 +42,8 @@ <%= render 'govuk_publishing_components/components/notice', title: nbsp_between_last_two_words(@content_item.forthcoming_notice_title) %> <% end %> + + <%= render 'content_items/save_page' %>
<%= render 'govuk_publishing_components/components/related_navigation', content_item: @content_item.content_item.parsed_content, context: :sidebar %> diff --git a/app/views/content_items/take_part.html.erb b/app/views/content_items/take_part.html.erb index f8f0c1b33..1a066c4c8 100644 --- a/app/views/content_items/take_part.html.erb +++ b/app/views/content_items/take_part.html.erb @@ -14,18 +14,21 @@
-
- <%= render 'components/figure', - src: @content_item.image["url"], - alt: @content_item.image["alt_text"], - credit: @content_item.image["credit"], - caption: @content_item.image["caption"] if @content_item.image %> +
+
+ <%= render 'components/figure', + src: @content_item.image["url"], + alt: @content_item.image["alt_text"], + credit: @content_item.image["credit"], + caption: @content_item.image["caption"] if @content_item.image %> - <%= render "govuk_publishing_components/components/govspeak", { - direction: page_text_direction - } do %> + <%= render "govuk_publishing_components/components/govspeak", { + direction: page_text_direction + } do %> <%= raw(@content_item.body) %> - <% end %> + <% end %> +
+ <%= render 'content_items/save_page' %>
<%= render 'shared/sidebar_navigation' %>
diff --git a/app/views/content_items/topical_event_about_page.html.erb b/app/views/content_items/topical_event_about_page.html.erb index a1886a48d..4b00bfab3 100644 --- a/app/views/content_items/topical_event_about_page.html.erb +++ b/app/views/content_items/topical_event_about_page.html.erb @@ -23,6 +23,8 @@ <%= raw(@content_item.body) %> <% end %> <% end %> + + <%= render 'content_items/save_page' %>
<%= render 'shared/sidebar_navigation' %> diff --git a/app/views/content_items/travel_advice.html.erb b/app/views/content_items/travel_advice.html.erb index 4c2b21dff..79cdfd0fb 100644 --- a/app/views/content_items/travel_advice.html.erb +++ b/app/views/content_items/travel_advice.html.erb @@ -60,7 +60,11 @@ <%= render 'govuk_publishing_components/components/previous_and_next_navigation', @content_item.previous_and_next_navigation %> - <%= render 'govuk_publishing_components/components/print_link', href: @content_item.print_link, text: t("multi_page.print_entire_guide") %> +
+ <%= render 'govuk_publishing_components/components/print_link', href: @content_item.print_link, text: t("multi_page.print_entire_guide") %> +
+ + <%= render 'content_items/save_page' %> <%= render 'shared/sidebar_navigation' %> diff --git a/app/views/content_items/working_group.html.erb b/app/views/content_items/working_group.html.erb index 35d9d89b9..46a619f99 100644 --- a/app/views/content_items/working_group.html.erb +++ b/app/views/content_items/working_group.html.erb @@ -35,5 +35,7 @@ <%= raw(@additional_body) %> <% end %> <% end %> + + <%= render 'content_items/save_page' %> diff --git a/app/views/content_items/world_location_news_article.html.erb b/app/views/content_items/world_location_news_article.html.erb index a2a794ab3..350b151c8 100644 --- a/app/views/content_items/world_location_news_article.html.erb +++ b/app/views/content_items/world_location_news_article.html.erb @@ -19,34 +19,38 @@ <%= render 'govuk_publishing_components/components/notice', @content_item.withdrawal_notice_component %>
-
-
- <%= render 'components/figure', +
+
+
+ <%= render 'components/figure', src: @content_item.image["url"], alt: @content_item.image["alt_text"], credit: @content_item.image["credit"], caption: @content_item.image["caption"] if @content_item.image %> - <%= render 'govuk_publishing_components/components/govspeak', { - direction: page_text_direction, - } do %> - <%= raw(@content_item.body) %> - <% end %> -
- -
- <%= render 'govuk_publishing_components/components/share_links', - links: @content_item.share_links, - track_as_sharing: true, - title: t('components.share_links.share_this_page') - %> -
- - <%= render 'components/published-dates', { + <%= render 'govuk_publishing_components/components/govspeak', { + direction: page_text_direction, + } do %> + <%= raw(@content_item.body) %> + <% end %> +
+ +
+ <%= render 'govuk_publishing_components/components/share_links', + links: @content_item.share_links, + track_as_sharing: true, + title: t('components.share_links.share_this_page') + %> +
+ + <%= render 'components/published-dates', { published: @content_item.published, last_updated: @content_item.updated, history: @content_item.history } %> +
+ + <%= render 'content_items/save_page' %>
<%= render 'shared/sidebar_navigation' %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 335711159..dc8d3f9ab 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -2,7 +2,7 @@ - <%if content_for?(:title) %> + <% if content_for?(:title) %> <%= yield :title %> - GOV.UK <% else %> <%= @content_item.page_title %> - GOV.UK @@ -39,6 +39,8 @@ <%= render 'govuk_publishing_components/components/phase_banner', phase: @content_item.phase %> <% end %> + <%= render 'shared/save_page_confirmation' %> + <% unless @do_not_show_breadcrumbs %> <% if @content_item.try(:back_link) %> <%= render 'govuk_publishing_components/components/back_link', href: @content_item.back_link %> diff --git a/app/views/shared/_save_page_confirmation.html.erb b/app/views/shared/_save_page_confirmation.html.erb new file mode 100644 index 000000000..c9e68a92e --- /dev/null +++ b/app/views/shared/_save_page_confirmation.html.erb @@ -0,0 +1,15 @@ +<% if has_saved_page_confirmation? %> + <div class="govuk-grid-row"> + <div class="govuk-grid-column-two-thirds"> + <div class="govuk-!-margin-top-4"> + <%= render "govuk_publishing_components/components/success_alert", { + message: t("components.save_this_page.confirmations.#{personalisation_param}.message"), + description: sanitize(additional_text({ + additional_class: "govuk-notification-banner__link", + signed_in: logged_in?, + })), + } %> + </div> + </div> + </div> +<% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index d4bd310fe..a327c38bf 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -22,8 +22,13 @@ en: page_was_saved_heading: You’ve saved this page add_page_button: Add to your saved pages remove_page_button: Remove from your saved pages - see_saved_pages_signed_in: <a href="%{link}" class="govuk-link">See your saved pages</a> - see_saved_pages_signed_out: <a href="%{link}" class="govuk-link">Sign in</a> to see your saved pages. + see_saved_pages_signed_in: <a href="%{link}" class="govuk-link %{additional_class}">See your saved pages</a> + see_saved_pages_signed_out: <a href="%{link}" class="govuk-link %{additional_class}">Sign in</a> to see your saved pages. + confirmations: + page_saved: + message: "You’ve added this to your saved pages" + page_removed: + message: "You’ve removed this from your saved pages" share_links: share_this_page: Share this page consultation: diff --git a/test/components/save_this_page_test.rb b/test/components/save_this_page_test.rb index d1237bf5f..b70e98a0d 100644 --- a/test/components/save_this_page_test.rb +++ b/test/components/save_this_page_test.rb @@ -15,7 +15,7 @@ def component_name test "renders signed out state by default" do render_component(page_path: "/test") - assert_select ".app-c-save-this-page a.govuk-button", text: "Add to your saved pages", href: "/account/saved-pages/add?page_path=/test" + assert_select ".app-c-save-this-page a.govuk-button", text: "Add to your saved pages", href: "#{Plek.new.website_root}/account/saved-pages/add?page_path=/test" assert_select ".app-c-save-this-page .govuk-link", text: "Sign in" end @@ -24,7 +24,7 @@ def component_name page_path: "/test", signed_in: false, ) - assert_select ".app-c-save-this-page a.govuk-button", text: "Add to your saved pages", href: "/account/saved-pages/add?page_path=/test" + assert_select ".app-c-save-this-page a.govuk-button", text: "Add to your saved pages", href: "#{Plek.new.website_root}/account/saved-pages/add?page_path=/test" assert_select ".app-c-save-this-page .govuk-link", text: "Sign in" end @@ -33,7 +33,7 @@ def component_name page_path: "/test", signed_in: true, ) - assert_select ".app-c-save-this-page a.govuk-button", text: "Add to your saved pages", href: "/account/saved-pages/add?page_path=/test" + assert_select ".app-c-save-this-page a.govuk-button", text: "Add to your saved pages", href: "#{Plek.new.website_root}/account/saved-pages/add?page_path=/test" assert_select ".app-c-save-this-page .govuk-link", text: "See your saved pages" end diff --git a/test/controllers/save_a_page_test.rb b/test/controllers/save_a_page_test.rb new file mode 100644 index 000000000..cd2c48cee --- /dev/null +++ b/test/controllers/save_a_page_test.rb @@ -0,0 +1,75 @@ +require "test_helper" +require "gds_api/test_helpers/account_api" + +class ContentItemsControllerTest < ActionController::TestCase + include GdsApi::TestHelpers::AccountApi + include GdsApi::TestHelpers::ContentStore + include GovukPersonalisation::TestHelpers::Requests + + SAVE_A_PAGE_CSS_SELECTOR = ".app-c-save-this-page".freeze + + test "does not show the save-page button when the feature flag is off" do + stub_feature_flag_off + set_up_and_visit_content_item("detailed_guide", "detailed_guide") + + assert_not has_save_this_page_button_css_selector + end + + test "logged out - shows the add_page_button when the feature flag is on" do + stub_feature_flag_on + stub_account_api_unauthorized_get_saved_page(page_path: "/guidance/salary-sacrifice-and-the-effects-on-paye") + set_up_and_visit_content_item("detailed_guide", "detailed_guide") + + assert has_save_page_button("/guidance/salary-sacrifice-and-the-effects-on-paye") + end + + test "logged in - shows the add_page_button when the feature flag is on and page is not saved" do + stub_feature_flag_on + mock_logged_in_session + stub_account_api_does_not_have_saved_page(page_path: "/guidance/salary-sacrifice-and-the-effects-on-paye") + set_up_and_visit_content_item("detailed_guide", "detailed_guide") + + assert has_save_page_button("/guidance/salary-sacrifice-and-the-effects-on-paye") + end + + test "logged in - shows the remove_page_button when the feature flag is on and page is saved" do + stub_feature_flag_on + mock_logged_in_session + stub_account_api_get_saved_page(page_path: "/guidance/salary-sacrifice-and-the-effects-on-paye") + set_up_and_visit_content_item("detailed_guide", "detailed_guide") + + assert has_remove_this_page_button("/guidance/salary-sacrifice-and-the-effects-on-paye") + end + +private + + def stub_feature_flag_on + @controller.stubs(:save_this_page_enabled?).returns(true) + end + + def stub_feature_flag_off + @controller.stubs(:save_this_page_enabled?).returns(false) + end + + def set_up_and_visit_content_item(document_type, example_name) + content_item = content_store_has_schema_example(document_type, example_name) + stub_content_store_has_item(content_item["base_path"], content_item) + path = content_item["base_path"][1..] + + get :show, params: { path: path } + end + + def has_save_this_page_button_css_selector + response.body.include?(SAVE_A_PAGE_CSS_SELECTOR) + end + + def has_save_page_button(page_path = "/test") + response.body.include?(I18n.t("components.save_this_page.add_page_button")) && + response.body.include?("#{Plek.new.website_root}/account/saved-pages/add?page_path=#{page_path}") + end + + def has_remove_this_page_button(page_path = "/test") + response.body.include?(I18n.t("components.save_this_page.remove_page_button")) && + response.body.include?("#{Plek.new.website_root}/account/saved-pages/remove?page_path=#{page_path}") + end +end diff --git a/test/helpers/save_this_page_helper_test.rb b/test/helpers/save_this_page_helper_test.rb index 467cfca5c..62f0fcdc9 100644 --- a/test/helpers/save_this_page_helper_test.rb +++ b/test/helpers/save_this_page_helper_test.rb @@ -31,12 +31,12 @@ class SaveThisPageHelperTest < ActionView::TestCase def has_save_this_page_button(params) assert_equal I18n.t("components.save_this_page.add_page_button"), link_text(params) - assert_equal "/account/saved-pages/add?page_path=/test", link_href(params) + assert_equal "#{Plek.new.website_root}/account/saved-pages/add?page_path=/test", link_href(params) end def has_remove_this_page_button(params) assert_equal I18n.t("components.save_this_page.remove_page_button"), link_text(params) - assert_equal "/account/saved-pages/remove?page_path=/test", link_href(params) + assert_equal "#{Plek.new.website_root}/account/saved-pages/remove?page_path=/test", link_href(params) end def has_page_not_saved_heading(params) @@ -48,10 +48,10 @@ def has_page_was_saved_heading(params) end def has_signed_in_additional_text(params) - assert_equal I18n.t("components.save_this_page.see_saved_pages_signed_in", link: "/account/saved-pages"), additional_text(params) + assert_equal I18n.t("components.save_this_page.see_saved_pages_signed_in", link: "#{Plek.new.website_root}/account/saved-pages", additional_class: ""), additional_text(params) end def has_signed_out_additional_text(params) - assert_equal I18n.t("components.save_this_page.see_saved_pages_signed_out", link: "/account/saved-pages"), additional_text(params) + assert_equal I18n.t("components.save_this_page.see_saved_pages_signed_out", link: "#{Plek.new.website_root}/account/saved-pages", additional_class: ""), additional_text(params) end end