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
Show file tree
Hide file tree
Changes from 49 commits
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
310 changes: 285 additions & 25 deletions ckanext/ontario_theme/fanstatic/common.css
aleeexgreeen marked this conversation as resolved.
Show resolved Hide resolved

Large diffs are not rendered by default.

70 changes: 70 additions & 0 deletions ckanext/ontario_theme/fanstatic/scripts/odc-access-level.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// 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.

/*
* CKAN module function for submitting form on checkbox selection and
* updating callout
*
* accessLevelBoxes
* All the access level checkboxes in the search bar
* openCheckbox
* The checkbox with value open
*/
"use strict";

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);
aleeexgreeen marked this conversation as resolved.
Show resolved Hide resolved
this.openCheckbox = $("#checkbox-option-open");
// "Open" checkbox checked by default
// else get access_level params and check the appropriate boxes
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);
});
}
// Update checkboxes and callout
$(this.accessLevelBoxes).on('change', jQuery.proxy(this._onChange, this));
$(document).ready(jQuery.proxy(this._updateAccessLevelSentence, this));
},
_onChange: function () {
let form = $('form.search-form');
form.submit();
},
_updateAccessLevelSentence: function () {
const selectedBoxes = $('input[name="access_level"]:checked');
const calloutElement = $('#access-level-sentence-value');
const and = this._(' and ');
const all_levels = this._('All levels');

var displayName = "";

// Update callout based on number of checkboxes checked and the value
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) {
calloutElement.text(displayName);
}
}
}
});
44 changes: 25 additions & 19 deletions ckanext/ontario_theme/fanstatic/scripts/odc-clear-filters.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
(function () {
var clearFiltersButton = document.getElementById("clear-filters-button");
var facetsSelected = document.querySelectorAll(".filtered.pill");
// 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.

if (facetsSelected.length >= 2) {
clearFiltersButton.style.display = "inline-block";
clearFiltersButton.addEventListener('click', clearFilters);
}
function clearFilters() {
const url = window.location.href.split('?')[0];
let params = new URLSearchParams(document.location.search);
let array = Array.from(params);
for (const field of array) {
const [key, value] = field;
if ((key != 'q')) {
params.delete(key);
}
}
window.location.href = `${url}?${params}`;
/*
* CKAN module function for submitting form with empty facets once the clear
* filters button is clicked
*/

"use strict";

ckan.module('clear_filters', function ($) {
return {
initialize: function () {
const facetsSelected = $(".filtered.pill");
aleeexgreeen marked this conversation as resolved.
Show resolved Hide resolved
if (facetsSelected.length >= 2) {
this.el.css({ display: "inline-block" });
this.el.on('click', jQuery.proxy(this._onClick, this));
}
},
_onClick: function (event) {
$('#fields').empty();
let form = $('form.search-form');
form.submit();
}
})();
}
});
32 changes: 32 additions & 0 deletions ckanext/ontario_theme/fanstatic/scripts/odc-facet-checkboxes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// 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.

/*
* CKAN module function for submitting form on facet checkbox selection with
* CKAN's hidden form inputs
*/

"use strict";

ckan.module('facet_checkboxes', function ($) {
return {
initialize: function () {
$(".facet-fieldset :checkbox").on('click', jQuery.proxy(this._onChange, this));
},
_onChange: function (event) {
const hiddenFields = $('#fields');
if (event.target.checked) {
$('<input>').attr({
type: 'hidden',
name: event.target.name,
value: event.target.value
}).appendTo(hiddenFields);
} else {
$(`input[name='${event.target.name}'][value='${event.target.value}']`).remove();
}
let form = $('form.search-form');
form.submit();
}
}
});
25 changes: 14 additions & 11 deletions ckanext/ontario_theme/fanstatic/scripts/odc-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,25 @@ const inputIds = [{
inputIds.forEach(input => {
const textId = document.getElementById(input.textId);
const resetId = document.getElementById(input.resetId);
if(textId && textId.value != ""){
searchReset(resetId,textId);
}
if(textId){
var typedText = "";

if (textId && resetId) {
textId.addEventListener("input", function(e) {
typedText = e.target.value; // Update typedText with current input value
});

resetId.addEventListener("click", function (e) {
e.preventDefault();
textId.value = "";
typedText = "";
textId.focus();
});

textId.addEventListener("keyup", function (e) {
if (e.key === "Escape" || e.keyCode === KEYCODE.ESCAPE) {
resetId.click();
}
});
}
});

function searchReset(resetId, textId) {
resetId.addEventListener("click", () => {
textId.defaultValue = "";
textId.focus();
});
}
})();
21 changes: 20 additions & 1 deletion ckanext/ontario_theme/fanstatic/scripts/webassets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,32 @@ ontario_theme_js:
- odc-active-page.js
- odc-active-tab.js
- odc-search-modal.js
- odc-clear-filters.js
- odc-toc-smooth-scroll.js

ontario_theme_form_validators_js:
filters: rjsmin
contents: odc-dataset-form-validators.js
output: ontario_theme_scripts/%(version)s_odc-dataset-form-validators.js
extra:
preload:
- vendor/jquery
- base/main

ontario_theme_facet_checkboxes_js:
filters: rjsmin
contents:
- odc-facet-checkboxes.js
- odc-clear-filters.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
Expand Down
55 changes: 45 additions & 10 deletions ckanext/ontario_theme/i18n/ckanext-ontario_theme.pot
Original file line number Diff line number Diff line change
Expand Up @@ -1318,33 +1318,33 @@ msgid "Please try another search or <a href=\"mailto:[email protected]\">reach
msgstr ""

#: ckanext/ontario_theme/templates/internal/snippets/search_result_text.html:15
msgid "<strong>{number} dataset</strong> found with the keyword(s) <strong>\"{query}\"</strong>"
msgid_plural "<strong>{number} datasets</strong> found with the keyword(s) <strong>\"{query}\"</strong>"
msgid "<strong>{number} total dataset</strong> found with the search term <strong>\"{query}\"</strong>"
msgid_plural "<strong>{number} total datasets</strong> found with the search term <strong>\"{query}\"</strong>"
msgstr[0] ""
msgstr[1] ""

#: ckanext/ontario_theme/templates/internal/snippets/search_result_text.html:17
msgid "<strong>{number} dataset</strong> found"
msgid_plural "<strong>{number} datasets</strong> found"
msgid "<strong>{number} total dataset</strong> found"
msgid_plural "<strong>{number} total datasets</strong> found"
msgstr[0] ""
msgstr[1] ""

#: ckanext/ontario_theme/templates/internal/snippets/search_result_text.html:16
msgid "No datasets found with the keyword(s) <strong>\"{query}\"</strong>"
msgid "No datasets found with the search term <strong>\"{query}\"</strong>"
msgstr ""

#: ckanext/ontario_theme/templates/internal/snippets/search_result_text.html:18
msgid "No datasets found"
msgstr ""

#: ckanext/ontario_theme/templates/internal/snippets/search_result_text.html:21
msgid "<strong>{number} group</strong> found with the keyword(s) <strong>\"{query}\"</strong>"
msgid_plural "<strong>{number} groups</strong> found with the keyword(s) <strong>\"{query}\"</strong>"
msgid "<strong>{number} group</strong> found with the search term <strong>\"{query}\"</strong>"
msgid_plural "<strong>{number} groups</strong> found with the search term <strong>\"{query}\"</strong>"
msgstr[0] ""
msgstr[1] ""

#: ckanext/ontario_theme/templates/internal/snippets/search_result_text.html:22
msgid "No groups found with the keyword(s) <strong>\"{query}\"</strong>"
msgid "No groups found with the search term <strong>\"{query}\"</strong>"
msgstr ""

#: ckanext/ontario_theme/templates/internal/snippets/search_result_text.html:23
Expand All @@ -1359,12 +1359,12 @@ msgstr ""

#: ckanext/ontario_theme/templates/internal/snippets/search_result_text.html:27
msgid "<strong>{number} ministry</strong> found for <strong>\"{query}\"</strong>"
msgid_plural "<strong>{number} ministries</strong> found with the keyword(s) <strong>\"{query}\"</strong>"
msgid_plural "<strong>{number} ministries</strong> found with the search term <strong>\"{query}\"</strong>"
msgstr[0] ""
msgstr[1] ""

#: ckanext/ontario_theme/templates/internal/snippets/search_result_text.html:28
msgid "No ministries found with the keyword(s) <strong>\"{query}\"</strong>"
msgid "No ministries found with the search term <strong>\"{query}\"</strong>"
msgstr ""

#: ckanext/ontario_theme/templates/internal/snippets/search_result_text.html:29
Expand All @@ -1377,6 +1377,16 @@ msgstr[1] ""
msgid "No ministries found"
msgstr ""

#: ckanext/ontario_theme/templates/internal/snippets/access_level_checkboxes.html:26
msgid "{level_count} dataset with access level"
msgid_plural "{level_count} datasets with access level"
msgstr[0] ""
msgstr[1] ""

#: ckanext/ontario_theme/templates/internal/snippets/search_form.html:242
msgid "We also found"
msgstr "Nous avons également trouvé"

#: ckanext/ontario_theme/templates/internal/user/dashboard.html:6
msgid "Edit settings"
msgstr ""
Expand Down Expand Up @@ -1471,6 +1481,31 @@ msgstr ""
msgid "Sort by"
msgstr ""

#: ckanext/ontario_theme/fanstatic/scripts/odc-access.js:72
msgid " and "
msgstr ""

#: ckanext/ontario_theme/fanstatic/scripts/odc-access.js:73
msgid "All levels"
msgstr ""

#: ckanext/ontario_theme/templates/internal/snippets/search_form.html:83
msgid "Showing datasets with access level"
msgstr ""

#: ckanext/ontario_theme/templates/internal/snippets/search_form.html:199
msgid "No datasets with access level"
msgstr ""

#: ckanext/ontario_theme/templates/internal/snippets/search_form.html:195
msgid "No datasets found with search term <strong>\"{query}\"</strong> and access level"
msgstr ""

#: ckanext/ontario_theme/templates/internal/snippets/search_form.html:193
msgid "Showing datasets found with search term <strong>\"{query}\"</strong> and access level"
msgstr ""


#: ckanext/ontario_theme/templates/internal/snippets/search_form.html:111
msgid "Clear filters"
msgstr ""
Expand Down
Binary file not shown.
Loading