Skip to content

Commit

Permalink
Update cookie setting page
Browse files Browse the repository at this point in the history
  • Loading branch information
martikat committed Apr 15, 2024
1 parent a92a8bc commit 7342770
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 6 deletions.
4 changes: 4 additions & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ main img {
margin-bottom: govuk-spacing(8);
}

#flash .govuk-notification-banner {
margin-bottom: govuk-spacing(4);
}

@include govuk-media-query($until: tablet) {

.govuk-grid-column-one-half>p,
Expand Down
50 changes: 44 additions & 6 deletions app/controllers/settings_controller.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,57 @@
class SettingsController < ApplicationController
def show
if template_valid?
track('static_page')
render template
else
render 'errors/not_found'
end
end

def create
set_cookie_pref
redirect_to params[:return_url]
end

private
if settings_params[:settings_updated].present?
flash[:notice] = t(:flash, scope: 'cookie_policy')
end

def track_analytics
params.fetch(:track_analytics, 'No')
redirect_to request_path
end

private

def set_cookie_pref
cookies[:track_analytics] = { value: track_analytics, expires: 6.months.from_now }
cookies[:track_analytics] = {
value: settings_params[:track_analytics],
expires: 6.months.from_now,
}

if params.fetch(:notify_if_successful, false)
flash[:notice] = t(:preferences_saved_html, return_url: helpers.root_path, scope: :settings)
end
end

def request_path
if params[:request_path]
params[:request_path]
else
params[:return_url]
end
end

def settings_params
params.permit(:request_path, :track_analytics, :settings_updated)
end

def track_analytics
params.fetch(:track_analytics, 'No')
end

def template
page_params[:id].underscore
end

def page_params
params.permit(:id)
end
end
4 changes: 4 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ def menu
def footer_menu
@footer_menu ||= Page.footer.pages
end

def track_analytics?
cookies[:track_analytics] == 'Yes'
end
end
5 changes: 5 additions & 0 deletions app/views/layouts/_flash.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- if flash.any?
#flash.govuk-grid-row
.govuk-grid-column-full
- flash.each do |variant, message|
= govuk_notification_banner title_text: t("banners.#{variant}"), text: m(message), success: %w[notice].include?(variant), classes: "govuk-notification-banner--#{variant}"
5 changes: 5 additions & 0 deletions app/views/pages/index.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@
.govuk-grid-row class=('govuk-!-margin-bottom-6' unless index == (page.pages.count / 3.0 - 1).ceil)
= render partial: 'shared/card', collection: row

= render 'layouts/flash'

= m(page.body)

if page.slug == 'cookie-policy'
= render 'settings/cookie_policy'

= render 'shared/ctas'

= render 'shared/other_resources'
10 changes: 10 additions & 0 deletions app/views/settings/_cookie_policy.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.govuk-grid-row class='govuk-!-margin-bottom-7'
.govuk-grid-column-two-thirds-from-desktop
= form_with url: settings_path, method: :post, local: true do |f|
= f.hidden_field :request_path, value: request.path
= f.hidden_field :settings_updated, value: 'Yes'
= f.govuk_radio_buttons_fieldset(:checked, legend: { size: 'm', text: t('cookie_policy.legend') }, inline: true ) do
= f.govuk_radio_button :track_analytics, 'Yes', label: { text: 'Yes' }, checked: track_analytics?
= f.govuk_radio_button :track_analytics, 'No', label: { text: 'No' }, checked: !track_analytics?

= f.govuk_submit 'Save cookie settings'
4 changes: 4 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ en:
blank: First name must not be blank
last_name:
blank: Last name must not be blank
cookie_policy:
title: Cookie policy
legend: Do you want to accept analytics cookies?
flash: Your cookie settings were saved</br><a class='govuk-link' href='%{return_url}'>Go back to Help for early years providers</a>
settings:
cookie-policy: Cookies
preferences_saved_html: Your cookie settings were saved</br><a class='govuk-link' href='%{return_url}'>Go back to Help for early years providers</a>

0 comments on commit 7342770

Please sign in to comment.