From 7133c85deb12062666938ec594d8928beb786b5d Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Sun, 27 Jun 2021 20:28:12 +0200 Subject: [PATCH] Persist filters on reload (recipe selection change) on the /recipes page (fixes #1455) --- public/viewjs/recipes.js | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/public/viewjs/recipes.js b/public/viewjs/recipes.js index 1ec045c0..d67a0fbe 100644 --- a/public/viewjs/recipes.js +++ b/public/viewjs/recipes.js @@ -48,6 +48,15 @@ if (GetUriParam("search") !== undefined) }, 50); } +if (GetUriParam("status") !== undefined) +{ + $("#status-filter").val(GetUriParam("status")); + setTimeout(function() + { + $("#status-filter").trigger("change"); + }, 50); +} + $("a[data-toggle='tab']").on("shown.bs.tab", function(e) { var tabId = $(e.target).attr("id"); @@ -60,8 +69,16 @@ $("#search").on("keyup", Delay(function() recipesTables.search(value).draw(); - $(".recipe-gallery-item").removeClass("d-none"); + if (value.isEmpty()) + { + RemoveUriParam("search"); + } + else + { + UpdateUriParam("search", value); + } + $(".recipe-gallery-item").removeClass("d-none"); $(".recipe-gallery-item .card-title:not(:contains_case_insensitive(" + value + "))").parent().parent().parent().addClass("d-none"); }, 200)); @@ -99,6 +116,15 @@ $("#status-filter").on("change", function() $('.recipe-gallery-item').not('.recipe-notenoughinstock').addClass('d-none'); } } + + if (value.isEmpty()) + { + RemoveUriParam("status"); + } + else + { + UpdateUriParam("status", value); + } }); $(".recipe-delete").on('click', function(e) @@ -236,7 +262,8 @@ recipesTables.on('select', function(e, dt, type, indexes) var currentRecipeId = location.search.split('recipe=')[1]; if (selectedRecipeId.toString() !== currentRecipeId) { - window.location.href = U('/recipes?recipe=' + selectedRecipeId.toString()); + UpdateUriParam("recipe", selectedRecipeId.toString()); + window.location.reload(); } } });