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

[Story]: Add checkboxes to the items in the search filters #598

Open
wants to merge 57 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
d80966a
Facet option checkboxes, fully functional
aleeexgreeen May 23, 2024
2b31c26
checkboxes and reduce templates on all pages
aleeexgreeen May 31, 2024
8bc04a4
Merge branch 'develop' into DATA-1083_checkboxes
aleeexgreeen Jun 4, 2024
0b53230
Active checkboxes always visible
aleeexgreeen Jun 4, 2024
d4886ce
Removes access level and replaces keywords to search term
aleeexgreeen Jun 4, 2024
fee4a68
Adds access level checkboxes. TODO: remove from facets, set default t…
aleeexgreeen Jun 4, 2024
ab94bf4
access level status bar and checkboxes functionality
aleeexgreeen Jun 5, 2024
3549cef
Merge branch 'develop' into DATA-1083_checkboxes
aleeexgreeen Jun 5, 2024
2244a51
default open and status callout
aleeexgreeen Jun 6, 2024
f6fc444
Condition to remove default open when it is there
aleeexgreeen Jun 6, 2024
a54d2f7
Removes duplicate url params and defaults to open when all checkboxes…
aleeexgreeen Jun 7, 2024
12cb4d2
removes else when on a different page
aleeexgreeen Jun 7, 2024
752babb
preventDefault so checkboxes don't reset
aleeexgreeen Jun 7, 2024
52b1773
Translations and comments
aleeexgreeen Jun 10, 2024
e65f51a
Merge branch 'develop' into DATA-1083_checkboxes
aleeexgreeen Jun 13, 2024
cb06a88
code clean up
aleeexgreeen Jun 14, 2024
3d3e8ab
Replace javascript with jquery CKAN module
aleeexgreeen Jun 17, 2024
11c950e
Minor tweaks for better readability on search page
aleeexgreeen Jun 24, 2024
8b72bc8
Fix for facets that have the same value within different facets
aleeexgreeen Jun 25, 2024
9c638b8
comments and js simplification
aleeexgreeen Jun 25, 2024
d3d9d12
Prevent checkboxes from being reset on reset input click
aleeexgreeen Jun 25, 2024
56db83b
Gets all facets dynamically instead of static list
aleeexgreeen Jun 26, 2024
83fde6a
code clean up
aleeexgreeen Jun 26, 2024
2eb3943
Accessibility fixes for facets
aleeexgreeen Jul 16, 2024
6fea9f3
mobile button fix
aleeexgreeen Jul 16, 2024
144e420
Added content for when there are no datasets, removal of duplicate fo…
aleeexgreeen Jul 19, 2024
0196198
accessibility and content changes
aleeexgreeen Jul 19, 2024
12cc66f
accessibility change
aleeexgreeen Jul 19, 2024
199b9df
reworked checkboxes to submit form
aleeexgreeen Jul 19, 2024
1858537
form submission from checkbox facet options
aleeexgreeen Jul 22, 2024
96a46dc
readding item_name
aleeexgreeen Jul 22, 2024
1e950a3
clear filters resubmits form
aleeexgreeen Jul 22, 2024
90c3a50
Minor fixes
aleeexgreeen Jul 22, 2024
68b8062
Merge branch 'develop' into DATA-1083_checkboxes
aleeexgreeen Jul 22, 2024
65605a8
Merge branch 'develop' into DATA-1083_checkboxes
aleeexgreeen Aug 12, 2024
98b2d74
Translations and positioning of review and restricted datasets
aleeexgreeen Aug 19, 2024
fa9cd8e
Merge branch 'develop' into DATA-1083_checkboxes
aleeexgreeen Aug 19, 2024
cdd68c5
minor translation fixes
aleeexgreeen Aug 19, 2024
3ef3e34
remove facet when checked checkbox is unchecked
aleeexgreeen Aug 20, 2024
bbd4179
Issue with count displaying 0 instead of correct amount resolved
aleeexgreeen Aug 20, 2024
a257aab
Facets don't default to all access levels and all datasets after a fa…
aleeexgreeen Aug 26, 2024
19c5f44
adds condition to append facet_al
aleeexgreeen Aug 26, 2024
f2e70f2
Do not display facets when page dataset count is 0
aleeexgreeen Aug 27, 2024
a1a2a4d
simplify access_level count statement to remove default open status
aleeexgreeen Aug 28, 2024
4a69a98
remove print statements
aleeexgreeen Aug 28, 2024
16e3003
Merge branch 'develop' into DATA-1083_checkboxes
aleeexgreeen Sep 5, 2024
138f6f9
Changes vars to lets and removes redundant brackets
aleeexgreeen Sep 5, 2024
570754a
formatted HTML files
aleeexgreeen Sep 5, 2024
8aa6f8a
Access level checkboxes working when 1 checkbox (not open) is selected
aleeexgreeen Sep 6, 2024
590d290
Condense if statement
aleeexgreeen Sep 10, 2024
330a14a
Removes redundant if statement for single option facets and combines …
aleeexgreeen Sep 12, 2024
d2ff656
Merge branch 'develop' into DATA-1083_checkboxes
aleeexgreeen Sep 12, 2024
ac096a4
escape double quotes in .po file
KatiRG Sep 13, 2024
020d3c4
revert condensing of or statement
KatiRG Sep 16, 2024
fc71315
Remove sort by dropdown on desktop, unnecessary if statement for clea…
aleeexgreeen Sep 30, 2024
ecd03ce
replace or for list
aleeexgreeen Sep 30, 2024
7b241cb
Merge branch 'develop' into DATA-1083_checkboxes
aleeexgreeen Sep 30, 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
Prev Previous commit
Next Next commit
Replace javascript with jquery CKAN module
  • Loading branch information
aleeexgreeen committed Jun 17, 2024
commit 3d3e8abdfbc6748a5d783adc5407b0975fa6011e
138 changes: 75 additions & 63 deletions ckanext/ontario_theme/fanstatic/scripts/odc-access-level.js
Original file line number Diff line number Diff line change
@@ -1,73 +1,85 @@
// Enable JavaScript's strict mode. Strict mode catches some common
// programming errors and throws exceptions, prevents some unsafe actions from
// being taken, and disables some confusing and bad JavaScript features.

/*
* Function for changing URL parameters when an access level
* checkbox is clicked.
* CKAN module function for changing URL parameters on checkbox selection and
* updating callout
*
* accessLevelBoxes
* All the access level checkboxes in the search bar
* openCheckbox
* The checkbox with value open
*/
"use strict";

(function () {
var accessLevelBoxes = document.querySelectorAll('input[name="access_level"][type="checkbox"]');
let params = new URLSearchParams(document.location.search);
var openCheckbox = document.getElementById("checkbox-option-open");
if (!params.has("access_level") && openCheckbox) {
openCheckbox.checked = true;
} else if (params.has("access_level")) {
let selected_levels = params.getAll("access_level");
selected_levels.forEach((e) => {
document.getElementById(`checkbox-option-${e}`).checked = true
});
}

accessLevelBoxes.forEach(element => {
element.addEventListener('change', showAccessLevel)
})

function showAccessLevel() {
let params = new URLSearchParams(document.location.search);
const isChecked = this.checked;
const paramName = this.name;
const paramValue = this.value;
if (openCheckbox.checked && !params.has(paramName)) {
params.append(paramName, openCheckbox.value)
}

if (isChecked) {
if (params.has('page')) {
params.delete('page');
ckan.module('access_level_checkboxes', function ($) {
return {
options: {
accessLevelBoxes: null,
openCheckbox: null,
},
initialize: function () {
this.accessLevelBoxes = $('input[name="access_level"][type="checkbox"]');
var params = new URLSearchParams(document.location.search);
this.openCheckbox = $("#checkbox-option-open");
if (!params.has("access_level") && this.openCheckbox) {
this.openCheckbox.prop('checked', true);
} else if (params.has("access_level")) {
var selected_levels = params.getAll("access_level");
selected_levels.forEach(function(e) {
$(`#checkbox-option-${e}`).prop('checked', true);
});
}
params.append(paramName, paramValue);
} else {
if (params.has(paramName, paramValue)) {
params.delete(paramName, paramValue);
$(this.accessLevelBoxes).on('change', jQuery.proxy(this._onChange, this));
$(document).ready(jQuery.proxy(this._updateAccessLevelSentence, this));
},
_onChange: function (event) {
var target = event.target;
var isChecked = $(target).prop('checked');
const paramName = $(target).attr('name');
var paramValue = $(target).val();
var params = new URLSearchParams(document.location.search);

if (this.openCheckbox.is(':checked') && !params.has(paramName)) {
params.append(paramName, this.openCheckbox.val());
}
}
window.location.search = params;
}

window.addEventListener('load', updateAccessLevelSentence)

function updateAccessLevelSentence() {
const selectedBoxes = document.querySelectorAll('input[name="access_level"]:checked');
const allLevels = document.getElementById('access-level-checkboxes');
const calloutElement = document.getElementById('access-level-sentence-value');

let displayName = "";

if (selectedBoxes.length === accessLevelBoxes.length) {
displayName = allLevels.dataset.value;
} else if (selectedBoxes.length === 1) {
displayName = selectedBoxes[0].getAttribute('data-display-name');
} else {
selectedBoxes.forEach((box, index) => {
displayName += box.getAttribute('data-display-name');
if (index < selectedBoxes.length - 1) {
displayName += calloutElement.dataset.and;
if (isChecked) {
if (params.has('page')) {
params.delete('page');
}
});
}

if (calloutElement) {
calloutElement.textContent = displayName;
params.append(paramName, paramValue);
} else {
if (params.has(paramName, paramValue)) {
params.delete(paramName, paramValue);
}
}
window.location.search = params;
},
_updateAccessLevelSentence: function (event) {
var selectedBoxes = $('input[name="access_level"]:checked');
var calloutElement = $('#access-level-sentence-value');
const and = this._(' and ');
const all_levels = this._('All levels');

var displayName = "";

if (selectedBoxes.length === this.accessLevelBoxes.length) {
displayName = all_levels;
} else if (selectedBoxes.length === 1) {
displayName = selectedBoxes.first().data('display-name');
} else {
selectedBoxes.each(function(index) {
displayName += $(this).data('display-name');
if (index < selectedBoxes.length - 1) {
displayName += and
}
});
}
if (calloutElement.length > 0) {
calloutElement.text(displayName);
}
}
}

})();
});
10 changes: 9 additions & 1 deletion ckanext/ontario_theme/fanstatic/scripts/webassets.yml
Original file line number Diff line number Diff line change
@@ -9,7 +9,6 @@ ontario_theme_js:
- odc-search-modal.js
- odc-clear-filters.js
- odc-toc-smooth-scroll.js
- odc-access-level.js

ontario_theme_form_validators_js:
filters: rjsmin
@@ -24,6 +23,15 @@ ontario_theme_facet_checkboxes_js:
filters: rjsmin
contents: odc-facet-checkboxes.js
output: ontario_theme_scripts/%(version)s_odc-facet-checkboxes.js
extra:
preload:
- vendor/jquery
- base/main

ontario_theme_access_level_js:
filters: rjsmin
contents: odc-access-level.js
output: ontario_theme_scripts/%(version)s_odc-access-level.js
extra:
preload:
- vendor/jquery
8 changes: 4 additions & 4 deletions ckanext/ontario_theme/i18n/ckanext-ontario_theme.pot
Original file line number Diff line number Diff line change
@@ -1483,12 +1483,12 @@ msgstr ""
msgid "Sort by"
msgstr ""

#: ckanext/ontario_theme/templates/internal/snippets/access_level_checkboxes.html:7
msgid "All levels"
#: ckanext/ontario_theme/fanstatic/scripts/odc-access.js:72
msgid " and "
msgstr ""

#: ckanext/ontario_theme/templates/internal/snippets/search_form.html:169
msgid "and"
#: ckanext/ontario_theme/fanstatic/scripts/odc-access.js:73
msgid "All levels"
msgstr ""

#: ckanext/ontario_theme/templates/internal/snippets/search_form.html:83
Original file line number Diff line number Diff line change
@@ -2069,11 +2069,11 @@ msgstr "Juridiction"
msgid "Showing datasets with access level"
msgstr "Jeux de données avec niveau d’accès"

#: ckanext/ontario_theme/templates/internal/snippets/access_level_checkboxes.html:7
#: ckanext/ontario_theme/fanstatic/scripts/odc-access.js:73
msgid "All levels"
msgstr "Tous les niveaux"

#: ckanext/ontario_theme/templates/internal/snippets/search_form.html:169
#: ckanext/ontario_theme/fanstatic/scripts/odc-access.js:87
msgid " and "
msgstr " et "

Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{% set schema_dict = h.scheming_get_dataset_schema('dataset')['dataset_fields'] %}
{% set name = "access_level" %}
<div class="access-level ontario-form-group">
{%- asset "ontario_theme_scripts/ontario_theme_access_level_js" -%}
<div class="access-level ontario-form-group" data-module="access_level_checkboxes">
<fieldset class="ontario-fieldset">
<legend class="ontario-fieldset__legend">{{ _('Access level') }}{{ _(':') }}</legend>
<div id="access-level-checkboxes" class="ontario-checkboxes" data-value="{{ _('All levels') }}">
<div id="access-level-checkboxes" class="ontario-checkboxes">
{# Checking selected checkboxes #}
{% with access_levels = h.scheming_field_by_name(schema_dict, name).choices %}
{% for levels in access_levels %}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are indentation irregularities in this file that are not caught by djlint for some reason. e.g. in block {% block search_facets %} and onwards.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may have a different version of djlint or what you are using is not specifically tailored for this repo. There are files which the command pre-commit run --hook-stage manual format works from (see .djlintrc and djlint_rules.yaml). I say this because when running pre-commit run --hook-stage manual format there are no formatting errors in the search_form.html

Original file line number Diff line number Diff line change
@@ -180,7 +180,7 @@ <h2 class="ontario-label">
{% set border_highlight = "ontario-border-highlight--dark-blue" if count !=0 else "ontario-border-highlight--dark-taupe" %}
<div class="ontario-callout {{ border_highlight }} access-level-status ontario-small-12 ontario-large-7 ontario-columns">
<p id="access-level-sentence-id">
{{ _('Showing datasets with access level') }}{{ _(':') }} <span id="access-level-sentence-value" data-and="{{ _(' and ') }}"></span>
{{ _('Showing datasets with access level') }}{{ _(':') }} <span id="access-level-sentence-value"></span>
</p>
</div>
{% endif %}