From 5ab31f726acd5bb377bd84f033d49ce6301f94d2 Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Mon, 1 May 2023 14:49:02 +0200 Subject: [PATCH] Support dynamic "today" for MEAL_PLAN_FIRST_DAY_OF_WEEK (closes #2205) --- changelog/70_UNRELEASED_xxxx.xx.xx.md | 1 + config-dist.php | 1 + helpers/ConfigurationValidator.php | 2 +- public/viewjs/mealplan.js | 5 +++++ 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/changelog/70_UNRELEASED_xxxx.xx.xx.md b/changelog/70_UNRELEASED_xxxx.xx.xx.md index 0f2e2ee8..582763e9 100644 --- a/changelog/70_UNRELEASED_xxxx.xx.xx.md +++ b/changelog/70_UNRELEASED_xxxx.xx.xx.md @@ -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) diff --git a/config-dist.php b/config-dist.php index 9154c0a5..21c4a95a 100644 --- a/config-dist.php +++ b/config-dist.php @@ -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, diff --git a/helpers/ConfigurationValidator.php b/helpers/ConfigurationValidator.php index 2d079769..c507867e 100644 --- a/helpers/ConfigurationValidator.php +++ b/helpers/ConfigurationValidator.php @@ -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'); } diff --git a/public/viewjs/mealplan.js b/public/viewjs/mealplan.js index e5241a24..ff15eaba 100644 --- a/public/viewjs/mealplan.js +++ b/public/viewjs/mealplan.js @@ -9,6 +9,11 @@ if (Grocy.CalendarFirstDayOfWeek) if (Grocy.MealPlanFirstDayOfWeek) { firstDay = Number.parseInt(Grocy.MealPlanFirstDayOfWeek); + + if (firstDay == -1) + { + firstDay = moment().day(); + } } $(".calendar").each(function()