From 776f80fab54075fad9162008f7c4b4074e904610 Mon Sep 17 00:00:00 2001 From: Jack Date: Mon, 13 Jul 2020 23:28:33 +0100 Subject: [PATCH] added a button to set the filters to the current settings --- public/js/account.js | 61 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 58 insertions(+), 3 deletions(-) diff --git a/public/js/account.js b/public/js/account.js index 5ca05d939..fa6cbbee2 100644 --- a/public/js/account.js +++ b/public/js/account.js @@ -398,14 +398,14 @@ var resultHistoryChart = new Chart($(".pageAccount #resultHistoryChart"), { Object.keys(words).forEach((language) => { $(".pageAccount .content .filterButtons .buttons.languages").append( - `
${language.replace( + `
${language.replace( "_", " " )}
` ); if (language === "english_expanded") { $(".pageAccount .content .filterButtons .buttons.languages").append( - `
english 10k
` + `
english 10k
` ); } }); @@ -580,6 +580,61 @@ $(".pageAccount .filterButtons").click(".button", (e) => { saveConfigToCookie(); }); +$(".pageAccount #currentConfigFilter").click((e) => { + let disableGroups = [ + "globalFilters", + "difficultyFilters", + "modeFilters", + "punctuationFilter", + "wordsFilter", + "timeFilter", + "languages", + "tags", + ]; + disableGroups.forEach((group) => { + $.each( + $(`.pageAccount .filterButtons .buttons.${group} .button`), + (index, button) => { + let fl = $(button).attr("filter"); + disableFilterButton(fl); + config.resultFilters = config.resultFilters.filter((f) => f !== fl); + } + ); + }); + updateActiveFilters(); + + //rewrite this monstrosity soon pls + config.resultFilters.push(`difficulty_${config.difficulty}`); + toggleFilterButton(`difficulty_${config.difficulty}`); + config.resultFilters.push(`mode_${config.mode}`); + toggleFilterButton(`mode_${config.mode}`); + config.resultFilters.push(`words_${config.words}`); + toggleFilterButton(`words_${config.words}`); + config.resultFilters.push(`time_${config.time}`); + toggleFilterButton(`time_${config.time}`); + let puncfilter = config.punctuation ? "punc_on" : "punc_off"; + config.resultFilters.push(puncfilter); + toggleFilterButton(puncfilter); + config.resultFilters.push(`lang_${config.language}`); + toggleFilterButton(`lang_${config.language}`); + + let activeTags = []; + try { + dbSnapshot.tags.forEach((tag) => { + if (tag.active === true) { + activeTags.push(tag.id); + } + }); + } catch (e) {} + + activeTags.forEach((tag) => { + config.resultFilters.push(`tag_${tag}`); + toggleFilterButton(`tag_${tag}`); + }); + + saveConfigToCookie(); +}); + let filteredResults = []; let visibleTableLines = 0; @@ -749,7 +804,7 @@ function refreshAccountPage() { if (!activeFilters.includes(wordfilter)) return; } - if (!activeFilters.includes(result.language)) return; + if (!activeFilters.includes("lang_" + result.language)) return; let puncfilter = "punc_off"; if (result.punctuation) {