Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Advanced filters and New homepage layout #706

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
19f6b3d
[Scorecards][General] Tidy up utils.scss
lucascumsille Oct 10, 2024
bad7443
[Scorecards][General] Make year version more noticeable
lucascumsille Oct 14, 2024
d096c9f
[Scorecards] 'Go to council page' element fixed to the top
lucascumsille Nov 5, 2024
b3816c3
[Scorecards] Moved year version to top left corner homepage hero section
lucascumsille Nov 5, 2024
f18f6ef
[Scorecards] Reduced padding-y for hero section homepage
lucascumsille Nov 5, 2024
837c6f0
[Scorecards] Added background-color to btn-outline class
lucascumsille Nov 5, 2024
8c0e0a9
[Scorecards] Reduced emphasis of buttons in homepage hero section
lucascumsille Nov 5, 2024
54c5fc2
[Scorecards] Improve contrast for nav-links
lucascumsille Nov 5, 2024
5a6fd8c
[Scorecards] Added jump to council template
lucascumsille Nov 5, 2024
f494ff8
[Scorecards] Scorecards table new layout
lucascumsille Nov 5, 2024
e89f84f
[Scorecards] Added height to logo
lucascumsille Nov 5, 2024
e94aca5
[Scorecards] Merge advanced and main filter
lucascumsille Nov 7, 2024
772546c
[Scorecards] Improve links accessibility
lucascumsille Nov 7, 2024
8e57d6e
[Scorecards] If advanced filters are active then we display them by d…
lucascumsille Nov 7, 2024
7bf50e6
fixup! [Scorecards] Merge advanced and main filter
zarino Nov 18, 2024
efa0035
fixup! [Scorecards] Merge advanced and main filter
zarino Nov 18, 2024
8dfff2f
fixup! [Scorecards] Merge advanced and main filter
zarino Nov 19, 2024
0d202ef
fixup! [Scorecards] Merge advanced and main filter
zarino Nov 19, 2024
17ee076
fixup! [Scorecards] Merge advanced and main filter
zarino Nov 19, 2024
a53da68
fixup! [Scorecards] Merge advanced and main filter
zarino Nov 19, 2024
fdb2ffa
[Scorecards] More obvious styling for active advanced filters
zarino Nov 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
140 changes: 102 additions & 38 deletions scoring/static/scoring/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,57 +382,121 @@ forEachElement('.js-section-council-autocomplete', function(input){
});

function ajaxLoadCouncilTypeScorecard(url) {
var selectors = [
'#council-type-filter',
'#advancedFilter .modal-body',
'.table-header h3',
'.scorecard-table'
const selectors = [
'#home-page-main-filter',
'.scorecard-table'
];

selectors.forEach(function(selector){
document.querySelector(selector).classList.add('loading-shimmer');
selectors.forEach(selector => {
document.querySelector(selector)?.classList.add('loading-shimmer');
});

fetch(url)
.then(function(response) {
return response.text()
})
.then(function(html) {
var parser = new DOMParser();
var doc = parser.parseFromString(html, "text/html");
selectors.forEach(function(selector){
document.querySelector(selector).replaceWith(doc.querySelector(selector));
.then(response => response.text())
.then(html => {
const parser = new DOMParser();
const doc = parser.parseFromString(html, "text/html");

selectors.forEach(selector => {
const newElement = doc.querySelector(selector);
const currentElement = document.querySelector(selector);
if (newElement && currentElement) {
currentElement.replaceWith(newElement);
}
});

setUpTableSorting();
})
.catch(function(err) {

const advancedFilter = document.querySelector('#advancedFilter');
if (advancedFilter) {
new bootstrap.Collapse(advancedFilter, {
toggle: false
});
}
})
.catch(err => {
window.location.href = url;
});
});
}

function handleFilterChange(e) {
e.preventDefault();

const mainForm = document.getElementById('home-page-main-filter');
if (!mainForm) return;
const formData = new FormData(mainForm);

// Convert FormData to URLSearchParams
const params = new URLSearchParams(formData);

// Get the base URL (current path without query parameters)
const baseUrl = window.location.pathname;
const url = `${baseUrl}?${params.toString()}`;
history.pushState({}, '', url);

ajaxLoadCouncilTypeScorecard(url);
}

if ( typeof window.fetch !== 'undefined' ) {
document.addEventListener('click', function(e){
if ( e.target.matches('#council-type-filter a') ) {
e.preventDefault();
var href = e.target.href;
history.pushState({}, '', href);
ajaxLoadCouncilTypeScorecard(href);
if (typeof window.fetch !== 'undefined') {
document.addEventListener('click', e => {
if (e.target.matches('#council-type-filter a')) {
e.preventDefault();
const href = e.target.href;
history.pushState({}, '', href);
ajaxLoadCouncilTypeScorecard(href);
}
});

// Handle form submission (Apply filters button)
document.addEventListener('submit', e => {
if (e.target.matches('#home-page-main-filter')) {
handleFilterChange(e);
}
});

// Handle radio buttons and select changes
document.addEventListener('change', e => {
if (e.target.matches('#home-page-main-filter input[type="radio"]') ||
e.target.matches('#home-page-main-filter select')) {
handleFilterChange(new Event('submit'));
}
});

// Handle reset button
document.addEventListener('click', e => {
if (e.target.matches('#resetButton')) {
e.preventDefault();

const mainForm = document.getElementById('home-page-main-filter');
if (mainForm) {
// Reset radio buttons
mainForm.querySelectorAll('input[type="radio"]').forEach(radio => {
radio.checked = radio.defaultChecked;
});

// Reset select elements
mainForm.querySelectorAll('select').forEach(select => {
select.selectedIndex = 0;
});

handleFilterChange(new Event('submit'));
}
}
});

var councilTypePaths = [
'/',
'/scoring/district/',
'/scoring/county/',
'/scoring/combined/',
'/scoring/northern-ireland/'
const councilTypePaths = [
'/',
'/scoring/district/',
'/scoring/county/',
'/scoring/combined/',
'/scoring/northern-ireland/'
];

window.addEventListener('popstate', function(e){
var url = new URL(window.location.href);
if ( councilTypePaths.indexOf(url.pathname) != -1 ) {
ajaxLoadCouncilTypeScorecard(window.location.href);
}
window.addEventListener('popstate', e => {
const url = new URL(window.location.href);
if (councilTypePaths.includes(url.pathname)) {
ajaxLoadCouncilTypeScorecard(window.location.href);
}
});
}

Expand Down
46 changes: 29 additions & 17 deletions scoring/static/scoring/scss/_utils.scss
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,31 @@ $utilities: map-merge(
map-get($utilities, "position"),
(
responsive: true
)
),
"row-gap": (
responsive: true,
property: row-gap,
class: row-gap,
values: $spacers
),
"column-gap": (
responsive: true,
property: column-gap,
class: column-gap,
values: $spacers
),
"width": map-merge(
map-get($utilities, "width"),
(
values: map-merge(
map-get(map-get($utilities, "width"), "values"),
(
10: 10%,
15: 15%
),
),
),
),
),
);
Expand All @@ -69,20 +93,8 @@ $utilities: map-merge(
}
}

$utilities: map-merge(
$utilities,
(
"width": map-merge(
map-get($utilities, "width"),
(
values: map-merge(
map-get(map-get($utilities, "width"), "values"),
(
10: 10%,
15: 15%
),
),
),
),
)
);
@each $color, $value in $theme-colors {
.btn-outline-#{$color} {
--bs-btn-bg: rgba(255, 255, 255, 0.3) !important;
}
}
2 changes: 1 addition & 1 deletion scoring/static/scoring/scss/awesomplete.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
& > ul {
position: absolute;
left: 0;
z-index: 10;
z-index: 32;
min-width: 100%;
box-sizing: border-box;
list-style: none;
Expand Down
2 changes: 2 additions & 0 deletions scoring/static/scoring/scss/buttons.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ a,
.btn,
.link-light,
button {
text-decoration-skip-ink: none; // Prevents the underline to get cut off
text-underline-offset: 0.2rem; // Improve readability of links
&:focus {
outline: 0 !important;
color: $black !important;
Expand Down
8 changes: 8 additions & 0 deletions scoring/static/scoring/scss/input.scss
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,11 @@
background-repeat: no-repeat;
background-position: right 10px center;
}

// When anything other than the first <option> is selected,
// style the <select> to look like an "active" button.
.form-select-show-modifications:has(option ~ option[selected]) {
background-color: $primary;
background-image: url("../img/bootstrap/form-select-indicator-white.svg");
color: color-contrast($primary);
}
12 changes: 11 additions & 1 deletion scoring/static/scoring/scss/navbar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
display: flex;
flex-direction: column;
padding-bottom: 1.5rem;
margin: 1rem 0;
margin: 1rem -1rem;
border-bottom: 1px solid $border-color;

label {
Expand All @@ -49,6 +49,16 @@
margin: 0 0 0.25rem 0;
border-bottom: none;

.home-page &{
background-color: $primary;
color: $white;
position: fixed;
top: 0;
right: 2rem;
width: fit-content;
z-index: 999;
}

label {
margin-bottom: 0;
margin-right: 1rem;
Expand Down
14 changes: 10 additions & 4 deletions scoring/static/scoring/scss/scoring-table.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ $border-table: 1px solid transparentize($color: $black, $amount: 1);
width: 100%;
max-height: 97vh;
overflow: auto;
border-radius: $border-radius;

.highlight {
th, td {
Expand All @@ -35,13 +34,21 @@ $border-table: 1px solid transparentize($color: $black, $amount: 1);
z-index: 0;
min-width: 200px;
font-weight: 400;
padding: 1rem 0.7rem;
padding: 1rem 0.5rem;
}

th {
background-color: $white;
font-size: 0.85rem;
vertical-align: top;
vertical-align: middle;

.section-title {
display: flex;
flex-direction: row-reverse;
justify-content: flex-end;
align-items: center;
gap: 0.5rem;
}
}

@media only screen and (max-width: $table-desktop-breakpoint) {
Expand Down Expand Up @@ -162,7 +169,6 @@ $score-bar-vertical-padding: 8px;
// Sort icon
.sort-icon {
@include transition(background-image, color, background-color 0.3s ease-in-out);
margin-right: 0.5rem;
background-image: url("../img/chevron-down-purple.svg");
background-size: 15px;
background-position: center;
Expand Down
22 changes: 11 additions & 11 deletions scoring/templates/scoring/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@
<nav class="navbar navbar-expand-lg site-nav">
<div class="d-flex flex-row align-items-center">
<a class="navbar-brand" href="{% url 'scoring:home' %}">
{% include 'caps/icons/council-climate-logo-2023.html' with classes='text-dark' width='7em' height='auto' role='presentation' %}
{% include 'caps/icons/council-climate-logo-2023.html' with classes='text-dark' width='7em' height='2.5em' role='presentation' %}
<span class="visually-hidden">Council Climate Action Scorecards</span>
</a>

<div class="navbar-nav">
<div class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" role="button" id="scorecardsVersion" data-bs-toggle="dropdown" aria-expanded="false">
<a class="dropdown-toggle btn btn-primary" href="#" role="button" id="scorecardsVersion" data-bs-toggle="dropdown" aria-expanded="false">
2023
</a>
<ul class="dropdown-menu position-absolute ms-n3 shadow-lg" aria-labelledby="scorecardsVersion">
Expand All @@ -66,29 +66,29 @@
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse flex-column align-items-end" id="navbarSupportedContent">
<form action="{% url 'scoring:location_results' %}" class="navbar-location-search-form">
<label for="navbarLocationSearch">Jump to a council</label>
<form action="{% url 'scoring:location_results' %}" class="navbar-location-search-form p-3 p-lg-2 rounded-bottom">
<label for="navbarLocationSearch">Go to a council's page</label>
<input class="form-control form-control-sm searchbar js-location-search-autocomplete" type="search" name="pc" id="navbarLocationSearch" placeholder="Postcode">
<button type="submit" class="visually-hidden">Search</button>
</form>
<ul class="navbar-nav">
<ul class="navbar-nav {% if current_page == 'home-page' %}mt-lg-4{% endif %}">
<li id="home-page" class="nav-item">
<a class="nav-link" href="{% url 'scoring:home' %}">Scorecards</a>
<a class="nav-link link-primary" href="{% url 'scoring:home' %}">Scorecards</a>
</li>
<li id="methodology-page" class="nav-item">
<a class="nav-link" href="{% url 'scoring:sections' %}">Sections</a>
<a class="nav-link link-primary" href="{% url 'scoring:sections' %}">Sections</a>
</li>
<li id="methodology-page" class="nav-item">
<a class="nav-link" href="{% url 'scoring:methodology' %}">2025 Draft Methodology</a>
<a class="nav-link link-primary" href="{% url 'scoring:methodology' %}">2025 Draft Methodology</a>
</li>
<li id="how-to-page" class="nav-item">
<a class="nav-link" href="{% url 'generic:how-to-use-the-scorecards' %}">How to use the Scorecards</a>
<a class="nav-link link-primary" href="{% url 'generic:how-to-use-the-scorecards' %}">How to use the Scorecards</a>
</li>
<li id="about-page" class="nav-item">
<a class="nav-link" href="{% url 'generic:about' %}">About</a>
<a class="nav-link link-primary" href="{% url 'generic:about' %}">About</a>
</li>
<li id="contact-page" class="nav-item">
<a class="nav-link" href="{% url 'generic:contact' %}">Contact</a>
<a class="nav-link link-primary" href="{% url 'generic:contact' %}">Contact</a>
</li>
</ul>
</div>
Expand Down
Loading
Loading