Skip to content

Commit

Permalink
Merge pull request #646 from communitiesuk/FS-3873-cookies-Policy-Pag…
Browse files Browse the repository at this point in the history
…eAndBanner

FS-3873: Cookies page and banner on assessment
  • Loading branch information
hamzabinkhalid committed Jun 24, 2024
2 parents 08d4f2c + dc6e77f commit a079b1c
Show file tree
Hide file tree
Showing 13 changed files with 402 additions and 90 deletions.
18 changes: 3 additions & 15 deletions app/blueprints/assessments/templates/assessor_tool_dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,9 @@ <h2 class="govuk-heading-l">
</h2>

<div class="govuk-accordion" data-module="govuk-accordion" id="accordion-default">
{% if funds %}
<div class="govuk-accordion__controls">
<button type="button" class="govuk-accordion__show-all">
<span class="govuk-accordion-nav__chevron govuk-accordion-nav__chevron--down"></span>
<span class="govuk-accordion__show-all-text" data-qa="show_all_sections">Show all sections</span>
</button>
</div>
{% endif %}
<!-- {% if funds %} -->
<!-- "Show all sections" button being shown by the govuk-frontend automatically -->
<!-- {% endif %} -->
{% for fund_id in funds %}
<div class="govuk-accordion__section">
<div class="govuk-accordion__section-header">
Expand All @@ -50,13 +45,6 @@ <h2 class="govuk-accordion__section-heading">
{{ funds[fund_id].name }} ({{ fund_summaries[fund_id] | length }})
</span>
</span>
<span class="govuk-visually-hidden govuk-accordion__section-heading-divider">, </span>
<span class="govuk-accordion__section-toggle" data-nosnippet="">
<span class="govuk-accordion__section-toggle-focus">
<span class="govuk-accordion-nav__chevron govuk-accordion-nav__chevron--down"></span>
<span class="govuk-accordion__section-toggle-text">Show</span>
</span>
</span>
</button>
</h2>
<div id="accordion-default-content-{{ loop.index }}" class="govuk-accordion__section-content display-none"
Expand Down
10 changes: 10 additions & 0 deletions app/blueprints/shared/routes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from flask import Blueprint
from flask import current_app
from flask import render_template

from app.blueprints.services.data_services import get_default_round_data
Expand All @@ -17,6 +18,15 @@ def index():
)


@shared_bp.route("/cookie_policy", methods=["GET"])
def cookie_policy():
current_app.logger.info("Cookie policy page loaded.")
return render_template(
"cookie_policy.html",
migration_banner_enabled=Config.MIGRATION_BANNER_ENABLED,
)


@shared_bp.route("/help", methods=["GET"])
def get_help():
round_data = get_default_round_data() or {}
Expand Down
54 changes: 54 additions & 0 deletions app/static/src/js/fsd_cookies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@

const DEFAULT_CONSENT = {'ad_storage': 'denied', 'analytics_storage': 'denied', 'personalisation_storage': 'denied',
'functionality_storage': 'denied', 'security_storage': 'denied',}
const COOKIE_FSD_CONSENT = "fsd_cookie_consent";

function readConsentCookie() {
const cookie = document.cookie.split(";").find(c => c.trim().startsWith(`${COOKIE_FSD_CONSENT}=`));
return cookie ? JSON.parse(atob(cookie.split("=")[1])) : null;
}

function updateCookieConsent(value) {
const consentObject = { 'analytics_storage': value };
const currentDomain = window.location.hostname;
const slice = currentDomain.includes("access-funding") ? -4 : -3;
const targetDomain = currentDomain.split('.').slice(slice).join('.');
document.cookie = `${COOKIE_FSD_CONSENT}=${btoa(JSON.stringify(consentObject))};path=` + "/" + `;domain=${targetDomain};secure;SameSite=None`;

const notificationBanner = document.getElementById("cookie-setting-saved-banner")
if (notificationBanner) {
notificationBanner.removeAttribute("hidden");
notificationBanner.scrollIntoView();
}

}
function acceptCookies() {
updateCookieConsent('granted');
document.getElementById("cookies-choice-msg").setAttribute("hidden", "true");
document.getElementById("cookies-accepted-msg").removeAttribute("hidden");
}

function denyCookies() {
updateCookieConsent('denied');
document.getElementById("cookies-choice-msg").setAttribute("hidden", "true");
document.getElementById("cookies-rejected-msg").removeAttribute("hidden");
}

function hideCookiesMessage() {
document.getElementById("cookie-banner").setAttribute("hidden", "true");
}

function unhideCookiesMessage() {
document.getElementById("cookie-banner").removeAttribute("hidden");
}


function saveAnalyticsPrefs(){
if (document.getElementById("cookies-analytics").checked) {
updateCookieConsent('granted');
hideCookiesMessage();
} else {
updateCookieConsent('denied');
hideCookiesMessage();
}
}
58 changes: 0 additions & 58 deletions app/static/src/js/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,61 +66,3 @@ Array.from(tabAnchors).forEach(tabAnchor => {
}
});
})


function toggleAccordionOff(accordion, index) {
const content = document.getElementById(`accordion-default-content-${index}`);
content.style.display = ''; // Set display to empty to hide the content
const textSpan = accordion.querySelector('.govuk-accordion__section-toggle-text');
textSpan.textContent = 'Show'; // Change the text to 'Show'
const chavron = accordion.querySelector('.govuk-accordion-nav__chevron');
chavron.classList.add('govuk-accordion-nav__chevron--down'); // Add the class to change the chevron direction
}

function toggleAccordionOn(accordion, index) {
const content = document.getElementById(`accordion-default-content-${index}`);
content.style.display = 'block'; // Set display to 'block' to show the content
const textSpan = accordion.querySelector('.govuk-accordion__section-toggle-text');
textSpan.textContent = 'Hide'; // Change the text to 'Hide'
const chavron = accordion.querySelector('.govuk-accordion-nav__chevron');
chavron.classList.remove('govuk-accordion-nav__chevron--down'); // Remove the class to change the chevron direction
}

function toggleAccordion(accordion, index) {
const content = document.getElementById(`accordion-default-content-${index}`);
if (content.style.display) {
toggleAccordionOff(accordion, index);
} else {
toggleAccordionOn(accordion, index);
}
}

const closedAccordionButtons = Array.from(document.getElementsByClassName('landing-accordion'))
closedAccordionButtons.forEach((accordion, index) => {
accordion.onclick = (_e) => {
toggleAccordion(accordion, index + 1);
}
})

const showAllAccordion = document.querySelector('.govuk-accordion__show-all');
if (showAllAccordion) {
showAllAccordion.toggledOn = false;
showAllAccordion.onclick = (_e) => {
showAllAccordion.toggledOn = !showAllAccordion.toggledOn;
const showAllText = showAllAccordion.querySelector('.govuk-accordion__show-all-text');
const showAllChavron = showAllAccordion.querySelector('.govuk-accordion-nav__chevron');
if (showAllAccordion.toggledOn) {
closedAccordionButtons.forEach((accordion, index) => {
toggleAccordionOn(accordion, index + 1);
})
showAllText.textContent = 'Hide all sections';
showAllChavron.classList.remove('govuk-accordion-nav__chevron--down');
} else {
closedAccordionButtons.forEach((accordion, index) => {
toggleAccordionOff(accordion, index + 1);
})
showAllText.textContent = 'Show all sections';
showAllChavron.classList.add('govuk-accordion-nav__chevron--down');
}
}
}
11 changes: 10 additions & 1 deletion app/static/src/styles/govuk-overrides.css
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,6 @@ list-style-type: upper-roman;
margin: auto;
}


.govuk-link__white_font {
color: white !important;
}
Expand Down Expand Up @@ -404,3 +403,13 @@ a.govuk-link.deactivate {
/* .govuk-summary-list:first-of-type {
border-top: 1px solid #b1b4b6;
} */

#accept_cookies_btn, #deny_cookies_btn, #cookies-accepted-msg > div.govuk-button-group > button {
background-color: #00703c;
}

.govuk-main-wrapper-cookies-page {
display: block;
padding-top: 20px;
padding-bottom: 20px
}
167 changes: 167 additions & 0 deletions app/templates/cookie_policy.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
{% extends "base.html" %}

{%- from 'govuk_frontend_jinja/components/inset-text/macro.html' import govukInsetText -%}
{% from "macros/migration_banner.html" import migration_banner %}
{%- from "govuk_frontend_jinja/components/radios/macro.html" import govukRadios %}
{% set pageHeading %}Cookies{% endset %}
{% block content %}

<div class="govuk-main-wrapper-cookies-page">
<div class="govuk-grid-column-two-thirds">
{% if migration_banner_enabled %}
{{ migration_banner() }}
{% endif %}

<div id="cookie-setting-saved-banner" class="govuk-notification-banner govuk-notification-banner--success js-cookies-page-success" role="alert" aria-labelledby="govuk-notification-banner-title" data-module="govuk-notification-banner" hidden>
<div class="govuk-notification-banner__header">
<h2 class="govuk-notification-banner__title" id="govuk-notification-banner-title">
Success
</h2>
</div>
<div class="govuk-notification-banner__content">
<p class="govuk-notification-banner__heading">Your cookie settings were saved</p>
</div>
</div>

<h1 class="govuk-heading-l">{{ pageHeading }}</h1>
<p class="govuk-body">
Cookies are small files saved on your phone, tablet or computer when you visit a website.
</p>
<p class="govuk-body">We use cookies to make the {{ service_title }} service work.</p>

<h2 class="govuk-heading-m" id="essential-cookies">Essential cookies</h2>
<p class="govuk-body">Essential cookies keep your information secure while you use the {{ service_title }} service. We do not need to ask permission to use them.</p>
<table class="govuk-table">
<caption class="govuk-visually-hidden">Essential cookies</caption>
<thead class="govuk-table__head">
<tr>
<th class="govuk-table__header">Name</th>
<th class="govuk-table__header">Purpose</th>
<th class="govuk-table__header">Expires</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<td class="govuk-table__cell">
session_cookie
</td>
<td width="50%" class="govuk-table__cell">
Used to keep you connected to your current session
</td>
<td class="govuk-table__cell">
When you close your browser
</td>
</tr>
<tr class="govuk-table__row">
<td class="govuk-table__cell">
fsd_user_token
</td>
<td width="50%" class="govuk-table__cell">
Used to keep you signed in
</td>
<td class="govuk-table__cell">
24 hours
</td>
</tr>
<tr class="govuk-table__row">
<td class="govuk-table__cell">
session
</td>
<td width="50%" class="govuk-table__cell">
Set to remember information you’ve entered into a form
</td>
<td class="govuk-table__cell">
When you close your browser
</td>
</tr>
</tbody>
</table>

<h2 class="govuk-heading-m" id="essential-cookies">Analytics cookies (optional)</h2>
<p class="govuk-body">With your permission, we use Google Analytics to collect data about how you use this service. This information helps us to improve our service.</p>
<p class="govuk-body">Google is not allowed to use or share our analytics data with anyone.</p>
<p class="govuk-body">Google Analytics stores anonymised information about:</p>
<ul class="govuk-list govuk-list--bullet">
<li>how you got to {{ service_title }}</li>
<li>the pages you visit on {{ service_title }} and how long you spend on them</li>
<li>any errors you see while using {{ service_title }}</li>
</ul>
<table class="govuk-table">
<caption class="govuk-visually-hidden">Analytics cookies (optional)</caption>
<thead class="govuk-table__head">
<tr>
<th class="govuk-table__header">Name</th>
<th class="govuk-table__header">Purpose</th>
<th class="govuk-table__header">Expires</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<td class="govuk-table__cell">
_ga
</td>
<td class="govuk-table__cell">
Checks if you have visited {{ service_title }} before. This helps us count how many people visit our site.
</td>
<td class="govuk-table__cell">
2 years
</td>
</tr>
<tr class="govuk-table__row">
<td class="govuk-table__cell">
_ga_GTM-M5J9Q8HV
</td>
<td class="govuk-table__cell">
Checks if you have visited {{ service_title }} before. This helps us to count how many people visit our site and persist a session state.
</td>
<td class="govuk-table__cell">
2 years
</td>
</tr>
</tbody>
</table>
<div class="govuk-body" id="cookie-settings">
{{ govukRadios({
"id": "cookies-analytics",
"name": "cookies-analytics",
"fieldset": {
"legend": {
"text": "Do you want to accept analytics cookies?",
"isPageHeading": false,
"classes": "govuk-fieldset__legend--s"
}
},
"items": [
{"value":"granted", "text":"Yes"},{"value": "denied", "text":"No"}
]})
}}
<button class="govuk-button" data-module="govuk-button" id="cookie-settings-save">
Save cookie settings
</button>
</div>

</div>
</div>
<script nonce="{{ csp_nonce() }}" type="text/javascript" src="{{ url_for('static', filename='js/fsd_cookies.js') }}"></script>
<script nonce="{{ csp_nonce() }}">

window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments) }

function initCookieRadios(){
localConsentMode = readConsentCookie();
if (localConsentMode != null){
if (localConsentMode.analytics_storage == 'granted'){
document.getElementById("cookies-analytics").checked = true;
} else {
document.getElementById("cookies-analytics-2").checked = true;
}
}
document.getElementById("cookie-settings-save").addEventListener("click", saveAnalyticsPrefs);


}

initCookieRadios();
</script>
{% endblock content %}
Loading

0 comments on commit a079b1c

Please sign in to comment.