From 346f8e9908a83b2a95d42da2e7ffa837a7590aa7 Mon Sep 17 00:00:00 2001 From: FrederikBaerentsen Date: Thu, 6 Nov 2025 18:53:19 +0100 Subject: [PATCH] feat: added clear filter button to sets/parts/problems/minifigures --- static/scripts/collapsible-state.js | 32 ++++++++++++++++ static/scripts/minifigures.js | 8 ++++ static/scripts/parts.js | 8 ++++ static/scripts/problems.js | 8 ++++ static/scripts/sets.js | 57 +++++++++++++++++++++++++++++ templates/minifigures.html | 3 ++ templates/parts.html | 3 ++ templates/problem.html | 3 ++ templates/sets.html | 3 ++ 9 files changed, 125 insertions(+) diff --git a/static/scripts/collapsible-state.js b/static/scripts/collapsible-state.js index 7722b54..adc3633 100644 --- a/static/scripts/collapsible-state.js +++ b/static/scripts/collapsible-state.js @@ -434,6 +434,38 @@ window.applyFiltersAndKeepState = function(tableId, storageKey) { } }; +// Shared function to clear all filters for a page (works in both pagination and client-side modes) +window.clearPageFilters = function(tableId, filterParams) { + const isPaginationMode = window.isPaginationModeForPage(tableId); + + if (isPaginationMode) { + // SERVER-SIDE PAGINATION MODE: Remove filter parameters from URL + const currentUrl = new URL(window.location); + + // Remove all filter parameters + filterParams.forEach(param => { + currentUrl.searchParams.delete(param); + }); + + // Reset to page 1 + currentUrl.searchParams.set('page', '1'); + + // Navigate to cleaned URL + window.location.href = currentUrl.toString(); + } else { + // CLIENT-SIDE MODE: Reset all filter dropdowns to "all" + filterParams.forEach(param => { + const select = document.getElementById(`filter-${param}`); + if (select) { + select.value = 'all'; + } + }); + + // Trigger filter application (will use existing filter logic) + window.applyPageFilters(tableId); + } +}; + // Shared initialization for table pages (parts, problems, minifigures) window.initializeTablePage = function(config) { const { diff --git a/static/scripts/minifigures.js b/static/scripts/minifigures.js index 584a100..d9a6035 100644 --- a/static/scripts/minifigures.js +++ b/static/scripts/minifigures.js @@ -166,6 +166,14 @@ document.addEventListener("DOMContentLoaded", () => { const currentOrder = urlParams.get('order'); window.initializeSortButtonStates(currentSort, currentOrder); } + + // Initialize clear filters button + const clearButton = document.getElementById('table-filter-clear'); + if (clearButton) { + clearButton.addEventListener('click', () => { + window.clearPageFilters('minifigures', ['owner', 'problems', 'theme', 'year']); + }); + } }); function setupSortButtons() { diff --git a/static/scripts/parts.js b/static/scripts/parts.js index e8df5d4..95d5cb9 100644 --- a/static/scripts/parts.js +++ b/static/scripts/parts.js @@ -23,5 +23,13 @@ document.addEventListener("DOMContentLoaded", () => { }, hasColorDropdown: true }); + + // Initialize clear filters button + const clearButton = document.getElementById('table-filter-clear'); + if (clearButton) { + clearButton.addEventListener('click', () => { + window.clearPageFilters('parts', ['owner', 'color', 'theme', 'year']); + }); + } }); diff --git a/static/scripts/problems.js b/static/scripts/problems.js index dd4a88a..4e8397e 100644 --- a/static/scripts/problems.js +++ b/static/scripts/problems.js @@ -23,4 +23,12 @@ document.addEventListener("DOMContentLoaded", () => { }, hasColorDropdown: true }); + + // Initialize clear filters button + const clearButton = document.getElementById('table-filter-clear'); + if (clearButton) { + clearButton.addEventListener('click', () => { + window.clearPageFilters('problems', ['owner', 'color', 'theme', 'year', 'storage', 'tag']); + }); + } }); \ No newline at end of file diff --git a/static/scripts/sets.js b/static/scripts/sets.js index 68aad76..443fa17 100644 --- a/static/scripts/sets.js +++ b/static/scripts/sets.js @@ -22,6 +22,9 @@ document.addEventListener("DOMContentLoaded", () => { // Initialize duplicate filter functionality initializeDuplicateFilter(); + // Initialize clear filters button + initializeClearFiltersButton(); + if (searchInput && searchClear) { if (isPaginationMode()) { // PAGINATION MODE - Server-side search @@ -704,4 +707,58 @@ function triggerGridRefresh() { } } } +} + +// Initialize clear filters button functionality +function initializeClearFiltersButton() { + const clearFiltersButton = document.getElementById('grid-filter-clear'); + if (!clearFiltersButton) return; + + clearFiltersButton.addEventListener('click', () => { + if (isPaginationMode()) { + // SERVER-SIDE PAGINATION MODE: Remove filter parameters from URL + const currentUrl = new URL(window.location); + + // Remove all filter parameters + const filterParams = ['status', 'theme', 'year', 'owner', 'purchase_location', 'storage', 'tag', 'duplicate']; + filterParams.forEach(param => { + currentUrl.searchParams.delete(param); + }); + + // Reset to page 1 + currentUrl.searchParams.set('page', '1'); + + // Navigate to cleaned URL + window.location.href = currentUrl.toString(); + } else { + // CLIENT-SIDE MODE: Reset all filter dropdowns to empty string + const filterDropdowns = [ + 'grid-status', + 'grid-theme', + 'grid-year', + 'grid-owner', + 'grid-purchase-location', + 'grid-storage', + 'grid-tag' + ]; + + filterDropdowns.forEach(dropdownId => { + const dropdown = document.getElementById(dropdownId); + if (dropdown) { + dropdown.value = ''; + } + }); + + // Clear duplicate filter if active + const duplicateButton = document.getElementById('duplicate-filter-toggle'); + if (duplicateButton && duplicateButton.classList.contains('btn-secondary')) { + duplicateButton.classList.remove('btn-secondary'); + duplicateButton.classList.add('btn-outline-secondary'); + applyDuplicateFilter(false); + } + + // Trigger filtering if grid instance exists + triggerGridRefresh(); + } + }); } \ No newline at end of file diff --git a/templates/minifigures.html b/templates/minifigures.html index 402538e..77a4fc9 100644 --- a/templates/minifigures.html +++ b/templates/minifigures.html @@ -23,6 +23,9 @@ + diff --git a/templates/parts.html b/templates/parts.html index c9d2d1a..9b12355 100644 --- a/templates/parts.html +++ b/templates/parts.html @@ -24,6 +24,9 @@ + diff --git a/templates/problem.html b/templates/problem.html index 13c193c..06384db 100644 --- a/templates/problem.html +++ b/templates/problem.html @@ -24,6 +24,9 @@ + diff --git a/templates/sets.html b/templates/sets.html index 7d25bb3..21016c3 100644 --- a/templates/sets.html +++ b/templates/sets.html @@ -22,6 +22,9 @@ + {% if config['SHOW_SETS_DUPLICATE_FILTER'] %}