From 80d7284d72710ff1f4ed15315d13d8ed7f9376c1 Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Sat, 4 Nov 2023 14:11:02 +0100 Subject: [PATCH] Implemented calendar category colors (closes #2368) --- changelog/74_UNRELEASED_xxxx-xx-xx.md | 3 +- config-dist.php | 7 ++ localization/strings.pot | 3 + public/viewjs/calendar.js | 7 ++ services/CalendarService.php | 19 +++-- views/calendar.blade.php | 102 +++++++++++++++++++++++++- 6 files changed, 132 insertions(+), 9 deletions(-) diff --git a/changelog/74_UNRELEASED_xxxx-xx-xx.md b/changelog/74_UNRELEASED_xxxx-xx-xx.md index 11dbff72..ff3d8663 100644 --- a/changelog/74_UNRELEASED_xxxx-xx-xx.md +++ b/changelog/74_UNRELEASED_xxxx-xx-xx.md @@ -35,7 +35,8 @@ ### Calendar -- xxx +- The different event types (due products, chores, tasks and so on) can now have different colors + - => New button "Configure colors" on the calendar page to configure these colors (top right corner) ### Tasks diff --git a/config-dist.php b/config-dist.php index a1795624..79475979 100644 --- a/config-dist.php +++ b/config-dist.php @@ -213,6 +213,13 @@ DefaultUserSetting('batteries_due_soon_days', 5); // The "due soon" days // Tasks settings DefaultUserSetting('tasks_due_soon_days', 5); // The "due soon" days +// Calendar settings +DefaultUserSetting('calendar_color_products', '#007bff'); // The event color (hex code) for due products +DefaultUserSetting('calendar_color_tasks', '#28a745'); // The event color (hex code) for due tasks +DefaultUserSetting('calendar_color_chores', '#ffc107'); // The event color (hex code) for due chores +DefaultUserSetting('calendar_color_batteries', '#17a2b8'); // The event color (hex code) for due battery charge cycles +DefaultUserSetting('calendar_color_meal_plan', '#6c757d'); // The event color (hex code) for meal plan items + // Component configuration for Quagga2 - read https://github.com/ericblade/quagga2#configobject for details // Below is a generic good configuration, // for an iPhone 7 Plus, halfsample = true, patchsize = small, frequency = 5 yields very good results diff --git a/localization/strings.pot b/localization/strings.pot index 92804df8..66f83afd 100644 --- a/localization/strings.pot +++ b/localization/strings.pot @@ -2432,3 +2432,6 @@ msgstr "" msgid "Nothing was found for the given barcode" msgstr "" + +msgid "Configure colors" +msgstr "" diff --git a/public/viewjs/calendar.js b/public/viewjs/calendar.js index 5502f156..9439b8a6 100644 --- a/public/viewjs/calendar.js +++ b/public/viewjs/calendar.js @@ -58,3 +58,10 @@ $(window).one("resize", function() calendar.fullCalendar("changeView", "month"); } }); + +$("#configure-colors-button").on("click", function(e) +{ + e.preventDefault(); + + $("#configure-colors-modal").modal("show"); +}); diff --git a/services/CalendarService.php b/services/CalendarService.php index dc8bc608..9422062d 100644 --- a/services/CalendarService.php +++ b/services/CalendarService.php @@ -15,6 +15,8 @@ class CalendarService extends BaseService public function GetEvents() { + $usersService = $this->getUsersService(); + $stockEvents = []; if (GROCY_FEATURE_FLAG_STOCK_BEST_BEFORE_DATE_TRACKING) { @@ -29,7 +31,8 @@ class CalendarService extends BaseService 'title' => $titlePrefix . FindObjectInArrayByPropertyValue($products, 'id', $currentStockEntry->product_id)->name, 'start' => $currentStockEntry->best_before_date, 'date_format' => 'date', - 'link' => $this->UrlManager->ConstructUrl('/stockoverview') + 'link' => $this->UrlManager->ConstructUrl('/stockoverview'), + 'color' => $usersService->GetUserSettings(GROCY_USER_ID)['calendar_color_products'] ]; } } @@ -46,7 +49,8 @@ class CalendarService extends BaseService 'title' => $titlePrefix . $currentTaskEntry->name, 'start' => $currentTaskEntry->due_date, 'date_format' => 'date', - 'link' => $this->UrlManager->ConstructUrl('/tasks') + 'link' => $this->UrlManager->ConstructUrl('/tasks'), + 'color' => $usersService->GetUserSettings(GROCY_USER_ID)['calendar_color_tasks'] ]; } } @@ -73,7 +77,8 @@ class CalendarService extends BaseService 'start' => $currentChoreEntry->next_estimated_execution_time, 'date_format' => 'datetime', 'link' => $this->UrlManager->ConstructUrl('/choresoverview'), - 'allDay' => $chore->track_date_only == 1 + 'allDay' => $chore->track_date_only == 1, + 'color' => $usersService->GetUserSettings(GROCY_USER_ID)['calendar_color_chores'] ]; } } @@ -90,7 +95,8 @@ class CalendarService extends BaseService 'title' => $titlePrefix . FindObjectInArrayByPropertyValue($batteries, 'id', $currentBatteryEntry->battery_id)->name, 'start' => $currentBatteryEntry->next_estimated_charge_time, 'date_format' => 'datetime', - 'link' => $this->UrlManager->ConstructUrl('/batteriesoverview') + 'link' => $this->UrlManager->ConstructUrl('/batteriesoverview'), + 'color' => $usersService->GetUserSettings(GROCY_USER_ID)['calendar_color_batteries'] ]; } } @@ -98,7 +104,7 @@ class CalendarService extends BaseService $mealPlanRecipeEvents = []; $mealPlanNotesEvents = []; $mealPlanProductEvents = []; - if (GROCY_FEATURE_FLAG_RECIPES) + if (GROCY_FEATURE_FLAG_RECIPES_MEALPLAN) { $mealPlanSections = $this->getDatabase()->meal_plan_sections(); @@ -127,7 +133,8 @@ class CalendarService extends BaseService 'start' => $start, 'date_format' => $dateFormat, 'description' => $this->UrlManager->ConstructUrl('/mealplan' . '?week=' . $mealPlanDayRecipe->day), - 'link' => $this->UrlManager->ConstructUrl('/recipes' . '?recipe=' . $mealPlanDayRecipe->recipe_id . '#fullscreen') + 'link' => $this->UrlManager->ConstructUrl('/recipes' . '?recipe=' . $mealPlanDayRecipe->recipe_id . '#fullscreen'), + 'color' => $usersService->GetUserSettings(GROCY_USER_ID)['calendar_color_meal_plan'] ]; } diff --git a/views/calendar.blade.php b/views/calendar.blade.php index 9511b07b..383e9411 100644 --- a/views/calendar.blade.php +++ b/views/calendar.blade.php @@ -15,13 +15,18 @@ data-target="#related-links"> - @@ -38,4 +43,97 @@
+ + @stop