From ac1be1e90f42ff430dda44f6d3614785e15e9868 Mon Sep 17 00:00:00 2001
From: kriddles <54413450+kriddles@users.noreply.github.com>
Date: Sun, 26 Jan 2020 01:50:44 -0600
Subject: [PATCH] 450 updates (#518)
* prevent seeing undefinde if no recipes
* disable weekRecipeConsume if weekCosts are zero
* reword title
* Add meal plan notes and products to Calendar
---
public/viewjs/mealplan.js | 7 ++++---
services/CalendarService.php | 29 +++++++++++++++++++++++++++--
2 files changed, 31 insertions(+), 5 deletions(-)
diff --git a/public/viewjs/mealplan.js b/public/viewjs/mealplan.js
index 18785fa9..960ec7df 100644
--- a/public/viewjs/mealplan.js
+++ b/public/viewjs/mealplan.js
@@ -49,9 +49,9 @@ var calendar = $("#calendar").fullCalendar({
var weekCosts = 0;
var weekRecipeOrderMissingButtonHtml = "";
var weekRecipeConsumeButtonHtml = "";
+ var weekCostsHtml = "";
if (weekRecipe !== null)
{
- var weekCostsHtml = "";
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING)
{
weekCosts = FindObjectInArrayByPropertyValue(recipesResolved, "recipe_id", weekRecipe.id).costs;
@@ -64,12 +64,13 @@ var calendar = $("#calendar").fullCalendar({
weekRecipeOrderMissingButtonDisabledClasses = "disabled";
}
var weekRecipeConsumeButtonDisabledClasses = "";
- if (FindObjectInArrayByPropertyValue(recipesResolved, "recipe_id", weekRecipe.id).need_fulfilled == 0)
+ console.log(weekCosts);
+ if (FindObjectInArrayByPropertyValue(recipesResolved, "recipe_id", weekRecipe.id).need_fulfilled == 0 || weekCosts == 0)
{
weekRecipeConsumeButtonDisabledClasses = "disabled";
}
weekRecipeOrderMissingButtonHtml = ''
- weekRecipeConsumeButtonHtml = ''
+ weekRecipeConsumeButtonHtml = ''
}
$(".fc-header-toolbar .fc-center").html("
" + weekCostsHtml + weekRecipeOrderMissingButtonHtml + weekRecipeConsumeButtonHtml + "
");
},
diff --git a/services/CalendarService.php b/services/CalendarService.php
index e951cb91..310fa117 100644
--- a/services/CalendarService.php
+++ b/services/CalendarService.php
@@ -92,7 +92,7 @@ class CalendarService extends BaseService
$recipes = $this->Database->recipes();
$mealPlanDayRecipes = $this->Database->recipes()->where('type', 'mealplan-day');
- $titlePrefix = $this->LocalizationService->__t('Meal plan') . ': ';
+ $titlePrefix = $this->LocalizationService->__t('Meal plan recipe') . ': ';
$mealPlanRecipeEvents = array();
foreach($mealPlanDayRecipes as $mealPlanDayRecipe)
{
@@ -108,6 +108,31 @@ class CalendarService extends BaseService
}
}
- return array_merge($stockEvents, $taskEvents, $choreEvents, $batteryEvents, $mealPlanRecipeEvents);
+ $mealPlanDayNotes = $this->Database->meal_plan()->where('type', 'note');
+ $titlePrefix = $this->LocalizationService->__t('Meal plan note') . ': ';
+ $mealPlanNotesEvents = array();
+ foreach($mealPlanDayNotes as $mealPlanDayNote)
+ {
+ $mealPlanNotesEvents[] = array(
+ 'title' => $titlePrefix . $mealPlanDayNote->note,
+ 'start' => $mealPlanDayNote->day,
+ 'date_format' => 'date'
+ );
+ }
+
+ $products = $this->Database->products();
+ $mealPlanDayProducts = $this->Database->meal_plan()->where('type', 'product');
+ $titlePrefix = $this->LocalizationService->__t('Meal plan product') . ': ';
+ $mealPlanProductEvents = array();
+ foreach($mealPlanDayProducts as $mealPlanDayProduct)
+ {
+ $mealPlanProductEvents[] = array(
+ 'title' => $titlePrefix . FindObjectInArrayByPropertyValue($products, 'id', $mealPlanDayProduct->product_id)->name,
+ 'start' => $mealPlanDayProduct->day,
+ 'date_format' => 'date'
+ );
+ }
+
+ return array_merge($stockEvents, $taskEvents, $choreEvents, $batteryEvents, $mealPlanRecipeEvents, $mealPlanNotesEvents, $mealPlanProductEvents);
}
}