From 274c842e7b7d1136ab14838df3c2caa88e6af9e4 Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Thu, 14 May 2026 18:02:19 +0200 Subject: [PATCH] Fixed status filter (master data/products) after page reload (Chrome/Edge only problem) (fixes #2782) --- changelog/82_UNRELEASED_xxxx-xx-xx.md | 3 +- controllers/StockController.php | 15 +++++---- public/viewjs/products.js | 46 ++++++++++++--------------- views/products.blade.php | 4 +-- 4 files changed, 34 insertions(+), 34 deletions(-) diff --git a/changelog/82_UNRELEASED_xxxx-xx-xx.md b/changelog/82_UNRELEASED_xxxx-xx-xx.md index 8be4d6ab..392aec89 100644 --- a/changelog/82_UNRELEASED_xxxx-xx-xx.md +++ b/changelog/82_UNRELEASED_xxxx-xx-xx.md @@ -10,10 +10,11 @@ ### Stock +- The product picker now searches product names accent insensitive - Fixed that changing the location on the purchase page re-initialized the due date based on product defaults (if any) - Fixed that when undoing a product consume or transfer transaction, the store of the corresponding stock entry wasn't restored - This will only apply to new consume / transfer transactions, not when undoing transactions made before using this release -- The product picker now searches product names accent insensitive +- Fixed that the status filter on the master data products page always displayed "All" after selection (only affected Chrome/Edge) ### Shopping list diff --git a/controllers/StockController.php b/controllers/StockController.php index cbf0b81c..074eceac 100644 --- a/controllers/StockController.php +++ b/controllers/StockController.php @@ -289,13 +289,16 @@ class StockController extends BaseController $products = $products->where('active = 1'); } - if (isset($request->getQueryParams()['only_in_stock'])) + if (isset($request->getQueryParams()['filter'])) { - $products = $products->where('id IN (SELECT product_id from stock_current WHERE amount_aggregated > 0)'); - } - if (isset($request->getQueryParams()['only_out_of_stock'])) - { - $products = $products->where('id NOT IN (SELECT product_id from stock_current WHERE amount_aggregated > 0)'); + if ($request->getQueryParams()['filter'] == 'only_in_stock') + { + $products = $products->where('id IN (SELECT product_id from stock_current WHERE amount_aggregated > 0)'); + } + elseif ($request->getQueryParams()['filter'] == 'only_out_of_stock') + { + $products = $products->where('id NOT IN (SELECT product_id from stock_current WHERE amount_aggregated > 0)'); + } } $products = $products->orderBy('name', 'COLLATE NOCASE'); diff --git a/public/viewjs/products.js b/public/viewjs/products.js index 1f0ddaa9..4f76ad6e 100644 --- a/public/viewjs/products.js +++ b/public/viewjs/products.js @@ -12,7 +12,7 @@ $('#products-table tbody').removeClass("d-none"); productsTable.columns.adjust().draw(); -$("#search").on("keyup", Delay(function() +$("#search").on("keyup", Delay(function () { var value = $(this).val(); if (value === "all") @@ -23,7 +23,7 @@ $("#search").on("keyup", Delay(function() productsTable.search(value).draw(); }, Grocy.FormFocusDelay)); -$("#product-group-filter").on("change", function() +$("#product-group-filter").on("change", function () { var value = $("#product-group-filter option:selected").text(); if (value === __t("All")) @@ -37,7 +37,7 @@ $("#product-group-filter").on("change", function() }); -$("#clear-filter-button").on("click", function() +$("#clear-filter-button").on("click", function () { $("#search").val(""); $("#product-group-filter").val("all"); @@ -65,7 +65,7 @@ if (typeof GetUriParam("product-group") !== "undefined") $("#product-group-filter").trigger("change"); } -$(document).on('click', '.product-delete-button', function(e) +$(document).on('click', '.product-delete-button', function (e) { var objectName = $(e.currentTarget).attr('data-product-name'); var objectId = $(e.currentTarget).attr('data-product-id'); @@ -83,18 +83,18 @@ $(document).on('click', '.product-delete-button', function(e) className: 'btn-danger' } }, - callback: function(result) + callback: function (result) { if (result === true) { jsonData = {}; jsonData.active = 0; Grocy.Api.Delete('objects/products/' + objectId, {}, - function(result) + function (result) { window.location.href = U('/products'); }, - function(xhr) + function (xhr) { console.error(xhr); } @@ -104,7 +104,7 @@ $(document).on('click', '.product-delete-button', function(e) }); }); -$("#show-disabled").change(function() +$("#show-disabled").change(function () { if (this.checked) { @@ -118,25 +118,17 @@ $("#show-disabled").change(function() window.location.reload(); }); -$("#status-filter").change(function() +$("#status-filter").change(function () { var value = $(this).val(); - if (value == "all") + if (value != "all") { - UpdateUriParam("only_in_stock", "true"); - RemoveUriParam("only_in_stock"); - RemoveUriParam("only_out_of_stock"); + UpdateUriParam("filter", value); } - else if (value == "out-of-stock") + else { - RemoveUriParam("only_in_stock"); - UpdateUriParam("only_out_of_stock", "true"); - } - else if (value == "in-stock") - { - RemoveUriParam("only_out_of_stock"); - UpdateUriParam("only_in_stock", "true"); + RemoveUriParam("filter"); } window.location.reload(); @@ -147,8 +139,12 @@ if (GetUriParam('include_disabled')) $("#show-disabled").prop('checked', true); } +if (GetUriParam("filter")) +{ + $("#status-filter").val(GetUriParam("filter")); +} -$(".merge-products-button").on("click", function(e) +$(".merge-products-button").on("click", function (e) { var productId = $(e.currentTarget).attr("data-product-id"); $("#merge-products-keep").val(productId); @@ -156,7 +152,7 @@ $(".merge-products-button").on("click", function(e) $("#merge-products-modal").modal("show"); }); -$("#merge-products-save-button").on("click", function(e) +$("#merge-products-save-button").on("click", function (e) { e.preventDefault(); @@ -169,11 +165,11 @@ $("#merge-products-save-button").on("click", function(e) var productIdToRemove = $("#merge-products-remove").val(); Grocy.Api.Post("stock/products/" + productIdToKeep.toString() + "/merge/" + productIdToRemove.toString(), {}, - function(result) + function (result) { window.location.href = U('/products'); }, - function(xhr) + function (xhr) { Grocy.FrontendHelpers.ShowGenericError('Error while merging', xhr.response); } diff --git a/views/products.blade.php b/views/products.blade.php index 2d40c310..0fa3b3c1 100644 --- a/views/products.blade.php +++ b/views/products.blade.php @@ -79,8 +79,8 @@