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

Tool filter fix for FF (+ some minor) #955

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion themes/bootstrap/layouts/_default/tools.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
Taskwarrior 3 
<em class="bi bi-3-circle-fill"></em>
<span class="tooltip-text">
Include projects intended for Taskwarrior 2.
Include projects intended for Taskwarrior 3.
</span>
</span>
</small>
Expand Down
32 changes: 11 additions & 21 deletions themes/bootstrap/static/js/filter.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
"use strict";

let excludeDormant = false;
let excludeArchived = true;
let excludeDormant = document.getElementById('exclude-dormant').checked
let includeArchived = document.getElementById('include-archived').checked;
let searchTerms = [];
const taskwarrior2Checkbox = document.getElementById('include-taskwarrior2')
const taskwarrior3Checkbox = document.getElementById('include-taskwarrior3')
const taskserverCheckbox = document.getElementById('include-taskserver')
const excludeDormantCheckbox = document.getElementById('exclude-dormant');
const includeArchivedCheckbox = document.getElementById('include-archived');
const searchResultMessage = document.getElementById('search-result-message');
const SEARCH_WAIT_TIME = 400;
const CHECKB0X_WAIT_TIME = 200;
const LOADING_MESSAGE = "Loading...";
let sortedTools = [];
Expand All @@ -33,7 +32,13 @@ fetch('../tools-data.json')
useCategories = sortedTools[0].category !== undefined;
if (useCategories) {
categories = populateCategories(sortedTools)
selectedCategories = new Set(categories);

// filter unchecked categories
selectedCategories = new Set(categories.filter((e) =>
[taskserverCheckbox, taskwarrior2Checkbox, taskwarrior3Checkbox]
.filter((f) => f.checked)
.map((f) => f.id.split('-')[1])
.includes(e)));
}

populateToolsKeywords(sortedTools);
Expand Down Expand Up @@ -139,7 +144,7 @@ function fillToolsTable(tools, selectedLanguages, selectedOwners) {
&& (selectedOwners.size === 0 || ownerMatch)
&& categoryMatch
&& (!excludeDormant || !tool.dormant)
&& (!excludeArchived || !tool.archived)
&& ((includeArchived && tool.archived) || !tool.archived)
&& (searchMatch(searchTerms, tool.keywords))
) {
numMatchingTools++;
Expand Down Expand Up @@ -252,10 +257,6 @@ function updateSearchResultMessage(numTools) {
/** Initialize the form processors. */
function initFormProcessors() {
// Form handlers
search.addEventListener('keyup', (e) => {
searchResultMessage.innerHTML = LOADING_MESSAGE;
debouncedHandleSearch(e);
});
excludeDormantCheckbox.addEventListener('click', (e) => {
searchResultMessage.innerHTML = LOADING_MESSAGE;
debouncedHandleDormantCheckbox(e);
Expand Down Expand Up @@ -296,7 +297,7 @@ function initFormProcessors() {

/** When the archived checkbox is clicked, refill the tools table. */
function handleArchivedCheckbox() {
excludeArchived = !excludeArchived;
includeArchived = !includeArchived;
fillToolsTable(sortedTools, selectedLanguages, selectedOwners);
}
const debouncedHandleArchivedCheckbox = debounce((e) => {
Expand Down Expand Up @@ -327,14 +328,3 @@ function handleCategoryCheckbox(e) {
const debouncedHandleCategoryCheckbox = debounce((e) => {
handleCategoryCheckbox(e);
}, CHECKB0X_WAIT_TIME);


/** On search, refill the tools table. */
function handleSearch(e) {
searchTerms = e.target.value.toLowerCase().trim().split(' ');
if (searchTerms.length === 1 && searchTerms[0] === '') searchTerms = [];
fillToolsTable(sortedTools, selectedLanguages, selectedOwners);
}
const debouncedHandleSearch = debounce((e) => {
handleSearch(e);
}, SEARCH_WAIT_TIME);