From cf641b3199efb6573251e4f40d0085228fc422a4 Mon Sep 17 00:00:00 2001 From: Gregoo <versatile.mailbox@gmail.com> Date: Thu, 30 Jan 2025 21:57:42 +0100 Subject: [PATCH] Separate the filters from the search and sort in the set grid --- static/scripts/grid.js | 14 +++++------ templates/sets.html | 53 ++++++++++++++++++++++++------------------ 2 files changed, 37 insertions(+), 30 deletions(-) diff --git a/static/scripts/grid.js b/static/scripts/grid.js index 42b8ac3..7f40b0a 100644 --- a/static/scripts/grid.js +++ b/static/scripts/grid.js @@ -57,7 +57,7 @@ class BrickGrid { this.html_grid = document.getElementById(this.id); this.html_sort = document.getElementById(`${this.id}-sort`); this.html_search = document.getElementById(`${this.id}-search`); - this.html_filter = document.getElementById(`${this.id}-filter`); + this.html_status = document.getElementById(`${this.id}-status`); this.html_theme = document.getElementById(`${this.id}-theme`); // Sort buttons @@ -83,8 +83,8 @@ class BrickGrid { })(this)); } - if (this.html_filter) { - this.html_filter.addEventListener("change", ((grid) => () => { + if (this.html_status) { + this.html_status.addEventListener("change", ((grid) => () => { grid.filter(); })(this)); } @@ -147,12 +147,12 @@ class BrickGrid { } // Check if there is a set filter - if (this.html_filter && this.html_filter.value != "") { - if (this.html_filter.value.startsWith("-")) { - filters["filter"] = this.html_filter.value.substring(1); + if (this.html_status && this.html_status.value != "") { + if (this.html_status.value.startsWith("-")) { + filters["filter"] = this.html_status.value.substring(1); filters["filter-target"] = "0"; } else { - filters["filter"] = this.html_filter.value; + filters["filter"] = this.html_status.value; filters["filter-target"] = "1"; } } diff --git a/templates/sets.html b/templates/sets.html index c43925f..e7003c3 100644 --- a/templates/sets.html +++ b/templates/sets.html @@ -13,28 +13,6 @@ <input id="grid-search" class="form-control form-control-sm" type="text" placeholder="Set name, set number, set theme or number of parts..." value=""> </div> </div> - <div class="col-12 flex-grow-1"> - <label class="visually-hidden" for="grid-filter">Filter</label> - <div class="input-group"> - <span class="input-group-text"><i class="ri-dropdown-list"></i><span class="ms-1 d-none d-xl-inline"> Filter</span></span> - <select id="grid-filter" class="form-select form-select-sm" autocomplete="off"> - <option value="" selected>All sets</option> - <option value="-has-missing">Set is complete</option> - <option value="has-missing">Set has missing pieces</option> - <option value="has-missing-instructions">Set has missing instructions</option> - {% for status in brickset_statuses %} - <option value="{{ status.as_dataset() }}">{{ status.fields.name }}</option> - <option value="-{{ status.as_dataset() }}">NOT: {{ status.fields.name }}</option> - {% endfor %} - </select> - <select id="grid-theme" class="form-select form-select-sm" autocomplete="off"> - <option value="" selected>All themes</option> - {% for theme in collection.themes %} - <option value="{{ theme | lower }}">{{ theme }}</option> - {% endfor %} - </select> - </div> - </div> <div class="col-12"> <div id="grid-sort" class="input-group"> <span class="input-group-text"><i class="ri-sort-asc"></i><span class="ms-1 d-none d-xxl-inline"> Sort</span></span> @@ -57,7 +35,36 @@ </div> </div> </div> - + <div class="row row-cols-lg-auto g-1 justify-content-center align-items-center pb-2"> + <div class="col-12 flex-grow-1"> + <label class="visually-hidden" for="grid-status">Status</label> + <div class="input-group"> + <span class="input-group-text"><i class="ri-checkbox-line"></i><span class="ms-1 d-none d-xl-inline"> Status</span></span> + <select id="grid-status" class="form-select form-select-sm" autocomplete="off"> + <option value="" selected>All</option> + <option value="-has-missing">Set is complete</option> + <option value="has-missing">Set has missing pieces</option> + <option value="has-missing-instructions">Set has missing instructions</option> + {% for status in brickset_statuses %} + <option value="{{ status.as_dataset() }}">{{ status.fields.name }}</option> + <option value="-{{ status.as_dataset() }}">NOT: {{ status.fields.name }}</option> + {% endfor %} + </select> + </div> + </div> + <div class="col-12 flex-grow-1"> + <label class="visually-hidden" for="grid-theme">Theme</label> + <div class="input-group"> + <span class="input-group-text"><i class="ri-price-tag-3-line"></i><span class="ms-1 d-none d-xl-inline"> Theme</span></span> + <select id="grid-theme" class="form-select form-select-sm" autocomplete="off"> + <option value="" selected>All</option> + {% for theme in collection.themes %} + <option value="{{ theme | lower }}">{{ theme }}</option> + {% endfor %} + </select> + </div> + </div> + </div> <div class="row" data-grid="true" id="grid"> {% for item in collection %} <div class="col-md-6 col-xl-3 d-flex align-items-stretch">