Support dynamic "today" for MEAL_PLAN_FIRST_DAY_OF_WEEK (closes #2205)

This commit is contained in:
Bernd Bestel 2023-05-01 14:49:02 +02:00
parent 7ee79ec56c
commit 5ab31f726a
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
4 changed files with 8 additions and 1 deletions

View File

@ -54,6 +54,7 @@
### Meal plan
- Added a new sub feature flag `FEATURE_FLAG_RECIPES_MEALPLAN` (in `config.php`) to only disable the meal plan if not needed (thanks @webysther)
- The `config.php` setting `MEAL_PLAN_FIRST_DAY_OF_WEEK` can now be set to `-1` to dynamically start the meal plan week on _today_
- 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)

View File

@ -33,6 +33,7 @@ Setting('CALENDAR_SHOW_WEEK_OF_YEAR', true);
// Set this if you want to have a different start day for the weekly meal plan view,
// leave empty to use CALENDAR_FIRST_DAY_OF_WEEK (see above)
// Needs to be a number where Sunday = 0, Monday = 1 and so forth
// Can also be set to -1 to dynamically start the meal plan week on "today"
Setting('MEAL_PLAN_FIRST_DAY_OF_WEEK', '');
// To keep it simple: grocy does not handle any currency conversions,

View File

@ -63,7 +63,7 @@ class ConfigurationValidator
private function checkMealplanFirstDayOfWeek()
{
if (!(GROCY_MEAL_PLAN_FIRST_DAY_OF_WEEK == '' ||
(is_numeric(GROCY_MEAL_PLAN_FIRST_DAY_OF_WEEK) && GROCY_MEAL_PLAN_FIRST_DAY_OF_WEEK >= 0 && GROCY_MEAL_PLAN_FIRST_DAY_OF_WEEK <= 6)))
(is_numeric(GROCY_MEAL_PLAN_FIRST_DAY_OF_WEEK) && GROCY_MEAL_PLAN_FIRST_DAY_OF_WEEK >= -1 && GROCY_MEAL_PLAN_FIRST_DAY_OF_WEEK <= 6)))
{
throw new EInvalidConfig('Invalid value for MEAL_PLAN_FIRST_DAY_OF_WEEK');
}

View File

@ -9,6 +9,11 @@ if (Grocy.CalendarFirstDayOfWeek)
if (Grocy.MealPlanFirstDayOfWeek)
{
firstDay = Number.parseInt(Grocy.MealPlanFirstDayOfWeek);
if (firstDay == -1)
{
firstDay = moment().day();
}
}
$(".calendar").each(function()