-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
76 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters