Fixed "Search for recipes containing this product" (fixes #1842)

This commit is contained in:
Bernd Bestel 2022-04-05 18:21:25 +02:00
parent adaa54ba8b
commit 03bba4b9e5
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
4 changed files with 32 additions and 6 deletions

View File

@ -61,6 +61,7 @@
- Fixed that calories of recipe ingredients were displayed with an indefinite number of decimal places
- Fixed that ingredient amounts were wrong for multi-nested (> 2 levels) recipes, when the included recipe used an serving amount other than 1
- Fixed that searching/filtering the recipe gallery view did not work correctly
- Fixed that searching/filtering recipes by products did not work (e.g. via the context-/more menu option "Search for recipes containing this product" on the stock overview page)
### Meal plan

View File

@ -72,7 +72,8 @@ SELECT
WHEN 'overdue' THEN 10
WHEN 'expired' THEN 20
END AS due_score,
IFNULL(pcs.product_id_effective, rp.product_id) AS product_id_effective
IFNULL(pcs.product_id_effective, rp.product_id) AS product_id_effective,
p.name AS product_name
FROM recipes r
JOIN recipes_nestings_resolved rnr
ON r.id = rnr.recipe_id
@ -138,7 +139,8 @@ SELECT
WHEN 'overdue' THEN 10
WHEN 'expired' THEN 20
END AS due_score,
IFNULL(pcs.product_id_effective, rp.product_id) AS product_id_effective
IFNULL(pcs.product_id_effective, rp.product_id) AS product_id_effective,
p.name AS product_name
FROM recipes r
JOIN recipes_nestings_resolved rnr
ON r.id = rnr.recipe_id
@ -170,3 +172,24 @@ LEFT JOIN products_current_price pcp
LEFT JOIN products p_effective
ON IFNULL(pcs.product_id_effective, rp.product_id) = p_effective.id
WHERE rp.not_check_stock_fulfillment = 1;
DROP VIEW recipes_resolved;
CREATE VIEW recipes_resolved
AS
SELECT
1 AS id, -- Dummy, LessQL needs an id column
r.id AS recipe_id,
IFNULL(MIN(rpr.need_fulfilled), 1) AS need_fulfilled,
IFNULL(MIN(rpr.need_fulfilled_with_shopping_list), 1) AS need_fulfilled_with_shopping_list,
IFNULL(rmpc.missing_products_count, 0) AS missing_products_count,
IFNULL(SUM(rpr.costs), 0) AS costs,
IFNULL(SUM(rpr.costs) / CASE WHEN IFNULL(r.desired_servings, 0) = 0 THEN 1 ELSE r.desired_servings END, 0) AS costs_per_serving,
IFNULL(SUM(rpr.calories), 0) AS calories,
IFNULL(SUM(rpr.due_score), 0) AS due_score,
GROUP_CONCAT(rpr.product_name) AS product_names_comma_separated
FROM recipes r
LEFT JOIN recipes_pos_resolved rpr
ON r.id = rpr.recipe_id
LEFT JOIN recipes_missing_product_counts rmpc
ON r.id = rmpc.recipe_id
GROUP BY r.id;

View File

@ -82,7 +82,7 @@ $("#search").on("keyup", Delay(function()
}
$(".recipe-gallery-item").removeClass("d-none");
$(".recipe-gallery-item .card-title:not(:contains_case_insensitive(" + value + "))").parent().parent().parent().addClass("d-none");
$(".recipe-gallery-item .card-title-search:not(:contains_case_insensitive(" + value + "))").parent().parent().parent().addClass("d-none");
}, 200));
$("#clear-filter-button").on("click", function()

View File

@ -207,9 +207,7 @@
@if(FindObjectInArrayByPropertyValue($recipesResolved, 'recipe_id', $recipe->id)->need_fulfilled == 1) Xenoughinstock @elseif(FindObjectInArrayByPropertyValue($recipesResolved, 'recipe_id', $recipe->id)->need_fulfilled_with_shopping_list == 1) enoughinstockwithshoppinglist @else notenoughinstock @endif
</td>
<td class="d-none">
@foreach(FindAllObjectsInArrayByPropertyValue($recipePositionsResolved, 'recipe_id', $recipe->id) as $recipePos)
{{ FindObjectInArrayByPropertyValue($products, 'id', $recipePos->product_id)->name . ' ' }}
@endforeach
{{ FindObjectInArrayByPropertyValue($recipesResolved, 'recipe_id', $recipe->id)->product_names_comma_separated }}
</td>
<td class="d-none">
@if(FindObjectInArrayByPropertyValue($recipesResolved, 'recipe_id', $recipe->id)->need_fulfilled == 1) {{ $__t('Enough in stock') }} @elseif(FindObjectInArrayByPropertyValue($recipesResolved, 'recipe_id', $recipe->id)->need_fulfilled_with_shopping_list == 1) {{ $__t('Not enough in stock, but already on the shopping list') }} @else {{ $__t('Not enough in stock') }} @endif
@ -241,6 +239,10 @@
@endif
<div class="card-body text-center">
<h5 class="card-title mb-1">{{ $recipe->name }}</h5>
<span class="card-title-search d-none">
{{ $recipe->name }}
{{ FindObjectInArrayByPropertyValue($recipesResolved, 'recipe_id', $recipe->id)->product_names_comma_separated }}
</span>
<p class="card-text">
@if(FindObjectInArrayByPropertyValue($recipesResolved, 'recipe_id', $recipe->id)->need_fulfilled == 1)<i class="fa-solid fa-check text-success"></i>@elseif(FindObjectInArrayByPropertyValue($recipesResolved, 'recipe_id', $recipe->id)->need_fulfilled_with_shopping_list == 1)<i class="fa-solid fa-exclamation text-warning"></i>@else<i class="fa-solid fa-times text-danger"></i>@endif
<span class="timeago-contextual">@if(FindObjectInArrayByPropertyValue($recipesResolved, 'recipe_id', $recipe->id)->need_fulfilled == 1){{ $__t('Enough in stock') }}@elseif(FindObjectInArrayByPropertyValue($recipesResolved, 'recipe_id', $recipe->id)->need_fulfilled_with_shopping_list == 1){{ $__n(FindObjectInArrayByPropertyValue($recipesResolved, 'recipe_id', $recipe->id)->missing_products_count, 'Not enough in stock, %s ingredient missing but already on the shopping list', 'Not enough in stock, %s ingredients missing but already on the shopping list') }}@else{{ $__n(FindObjectInArrayByPropertyValue($recipesResolved, 'recipe_id', $recipe->id)->missing_products_count, 'Not enough in stock, %s ingredient missing', 'Not enough in stock, %s ingredients missing') }}@endif</span>