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 @@ -
- <%= link_to(link[:title], link[:url]) %> -
- <%= link[:description] %> ++ <%= 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? %> -- <% email_group[:v_card].each do |v_card_part| %> + <% if @content_item.email.any? %> +
+ <% email_group[:v_card].each do |v_card_part| %>
<%= v_card_part[:value] %>
- <% end %>
- <%= mail_to email_group[:email], email_group[:email], class: 'email' %>
-
<%= number[:label] %>:
<%= number[:number] %>
Opening times:
- <%= phone_group[:opening_times] %> - <% end %> + <% if @content_item.phone.any? %> +<%= number[:label] %>:
<%= number[:number] %>
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_group[:v_card].each do |v_card_part| %> + <% if @content_item.post.any? %> +
+ <% post_group[:v_card].each do |v_card_part| %>
<%= v_card_part[:value] %>
- <% end %>
-