mirror of
https://github.com/grocy/grocy.git
synced 2025-04-29 09:39:57 +00:00
Optimized week recipe handling in mealplan (fixes #2168)
This commit is contained in:
parent
cc6b01de08
commit
71d44edb8c
@ -52,6 +52,7 @@
|
|||||||
|
|
||||||
- Added a new sub feature flag `FEATURE_FLAG_RECIPES_MEALPLAN` (in `config.php`) to only disable the meal plan if not needed (thanks @webysther)
|
- Added a new sub feature flag `FEATURE_FLAG_RECIPES_MEALPLAN` (in `config.php`) to only disable the meal plan if not needed (thanks @webysther)
|
||||||
- Fixed that consuming a recipe from the meal plan didn't add its "Produces product"-product to stock (if any)
|
- Fixed that consuming a recipe from the meal plan didn't add its "Produces product"-product to stock (if any)
|
||||||
|
- Fixed that the "Put missing products on shopping list"-button in the header (to put all missing products on the shopping list for a whole week) was missing under certain circumstances (related to locale week numbers and turn of the year)
|
||||||
|
|
||||||
### Chores
|
### Chores
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ class RecipesController extends BaseController
|
|||||||
$days = $request->getQueryParams()['days'];
|
$days = $request->getQueryParams()['days'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$mealPlanWhereTimespan = "day BETWEEN DATE('$start') AND DATE('$start', '+$days days')";
|
$mealPlanWhereTimespan = "day BETWEEN DATE('$start', '-$days days') AND DATE('$start', '+$days days')";
|
||||||
|
|
||||||
$recipes = $this->getDatabase()->recipes()->where('type', RecipesService::RECIPE_TYPE_NORMAL)->fetchAll();
|
$recipes = $this->getDatabase()->recipes()->where('type', RecipesService::RECIPE_TYPE_NORMAL)->fetchAll();
|
||||||
$events = [];
|
$events = [];
|
||||||
@ -64,7 +64,8 @@ class RecipesController extends BaseController
|
|||||||
'quantityUnits' => $this->getDatabase()->quantity_units()->orderBy('name', 'COLLATE NOCASE'),
|
'quantityUnits' => $this->getDatabase()->quantity_units()->orderBy('name', 'COLLATE NOCASE'),
|
||||||
'quantityUnitConversionsResolved' => $this->getDatabase()->quantity_unit_conversions_resolved(),
|
'quantityUnitConversionsResolved' => $this->getDatabase()->quantity_unit_conversions_resolved(),
|
||||||
'mealplanSections' => $this->getDatabase()->meal_plan_sections()->orderBy('sort_number'),
|
'mealplanSections' => $this->getDatabase()->meal_plan_sections()->orderBy('sort_number'),
|
||||||
'usedMealplanSections' => $this->getDatabase()->meal_plan_sections()->where("id IN (SELECT section_id FROM meal_plan WHERE $mealPlanWhereTimespan)")->orderBy('sort_number')
|
'usedMealplanSections' => $this->getDatabase()->meal_plan_sections()->where("id IN (SELECT section_id FROM meal_plan WHERE $mealPlanWhereTimespan)")->orderBy('sort_number'),
|
||||||
|
'weekRecipe' => $this->getDatabase()->recipes()->where("type = 'mealplan-week' AND name = LTRIM(STRFTIME('%Y-%W', DATE('$start')), '0')")->fetch()
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
27
migrations/0217.sql
Normal file
27
migrations/0217.sql
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
DROP VIEW meal_plan_internal_recipe_relation;
|
||||||
|
CREATE VIEW meal_plan_internal_recipe_relation
|
||||||
|
AS
|
||||||
|
|
||||||
|
-- Relation between a meal plan (day) and the corresponding internal recipe(s)
|
||||||
|
|
||||||
|
SELECT mp.day, r.id AS recipe_id
|
||||||
|
FROM meal_plan mp
|
||||||
|
JOIN recipes r
|
||||||
|
ON r.name = CAST(mp.day AS TEXT)
|
||||||
|
AND r.type = 'mealplan-day'
|
||||||
|
|
||||||
|
UNION
|
||||||
|
|
||||||
|
SELECT mp.day, r.id AS recipe_id
|
||||||
|
FROM meal_plan mp
|
||||||
|
JOIN recipes r
|
||||||
|
ON r.name = LTRIM(STRFTIME('%Y-%W', mp.day), '0')
|
||||||
|
AND r.type = 'mealplan-week'
|
||||||
|
|
||||||
|
UNION
|
||||||
|
|
||||||
|
SELECT mp.day, r.id AS recipe_id
|
||||||
|
FROM meal_plan mp
|
||||||
|
JOIN recipes r
|
||||||
|
ON r.name = CAST(mp.day AS TEXT) || '#' || CAST(mp.id AS TEXT)
|
||||||
|
AND r.type = 'mealplan-shadow';
|
@ -73,29 +73,28 @@ $(".calendar").each(function()
|
|||||||
</div> \
|
</div> \
|
||||||
</div>');
|
</div>');
|
||||||
|
|
||||||
var weekRecipeName = view.start.year().toString() + "-" + ((view.start.week() - 1).toString().padStart(2, "0")).toString();
|
|
||||||
var weekRecipe = FindObjectInArrayByPropertyValue(internalRecipes, "name", weekRecipeName);
|
|
||||||
|
|
||||||
var weekCosts = 0;
|
var weekCosts = 0;
|
||||||
var weekRecipeOrderMissingButtonHtml = "";
|
var weekRecipeOrderMissingButtonHtml = "";
|
||||||
var weekRecipeConsumeButtonHtml = "";
|
var weekRecipeConsumeButtonHtml = "";
|
||||||
var weekCostsHtml = "";
|
var weekCostsHtml = "";
|
||||||
if (weekRecipe !== null)
|
if (weekRecipe !== null)
|
||||||
{
|
{
|
||||||
|
var weekRecipeResolved = FindObjectInArrayByPropertyValue(recipesResolved, "recipe_id", weekRecipe.id);
|
||||||
|
|
||||||
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING)
|
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING)
|
||||||
{
|
{
|
||||||
weekCosts = FindObjectInArrayByPropertyValue(recipesResolved, "recipe_id", weekRecipe.id).costs;
|
weekCosts = weekRecipeResolved.costs;
|
||||||
weekCostsHtml = __t("Week costs") + ': <span class="locale-number locale-number-currency">' + weekCosts.toString() + "</span> ";
|
weekCostsHtml = __t("Week costs") + ': <span class="locale-number locale-number-currency">' + weekCosts.toString() + "</span> ";
|
||||||
}
|
}
|
||||||
|
|
||||||
var weekRecipeOrderMissingButtonDisabledClasses = "";
|
var weekRecipeOrderMissingButtonDisabledClasses = "";
|
||||||
if (FindObjectInArrayByPropertyValue(recipesResolved, "recipe_id", weekRecipe.id).need_fulfilled_with_shopping_list == 1)
|
if (weekRecipeResolved.need_fulfilled_with_shopping_list == 1)
|
||||||
{
|
{
|
||||||
weekRecipeOrderMissingButtonDisabledClasses = "disabled";
|
weekRecipeOrderMissingButtonDisabledClasses = "disabled";
|
||||||
}
|
}
|
||||||
|
|
||||||
var weekRecipeConsumeButtonDisabledClasses = "";
|
var weekRecipeConsumeButtonDisabledClasses = "";
|
||||||
if (FindObjectInArrayByPropertyValue(recipesResolved, "recipe_id", weekRecipe.id).need_fulfilled == 0 || weekCosts == 0)
|
if (weekRecipeResolved.need_fulfilled == 0 || weekCosts == 0)
|
||||||
{
|
{
|
||||||
weekRecipeConsumeButtonDisabledClasses = "disabled";
|
weekRecipeConsumeButtonDisabledClasses = "disabled";
|
||||||
}
|
}
|
||||||
|
@ -75,9 +75,10 @@
|
|||||||
|
|
||||||
@section('content')
|
@section('content')
|
||||||
<script>
|
<script>
|
||||||
var fullcalendarEventSources = {!! json_encode(array($fullcalendarEventSources)) !!}
|
var fullcalendarEventSources = {!! json_encode(array($fullcalendarEventSources)) !!};
|
||||||
var internalRecipes = {!! json_encode($internalRecipes) !!}
|
var internalRecipes = {!! json_encode($internalRecipes) !!};
|
||||||
var recipesResolved = {!! json_encode($recipesResolved) !!}
|
var recipesResolved = {!! json_encode($recipesResolved) !!};
|
||||||
|
var weekRecipe = {!! json_encode($weekRecipe) !!};
|
||||||
|
|
||||||
Grocy.QuantityUnits = {!! json_encode($quantityUnits) !!};
|
Grocy.QuantityUnits = {!! json_encode($quantityUnits) !!};
|
||||||
Grocy.QuantityUnitConversionsResolved = {!! json_encode($quantityUnitConversionsResolved) !!};
|
Grocy.QuantityUnitConversionsResolved = {!! json_encode($quantityUnitConversionsResolved) !!};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user