diff --git a/changelog/70_UNRELEASED_xxxx.xx.xx.md b/changelog/70_UNRELEASED_xxxx.xx.xx.md index ca002c49..ad02e3c0 100644 --- a/changelog/70_UNRELEASED_xxxx.xx.xx.md +++ b/changelog/70_UNRELEASED_xxxx.xx.xx.md @@ -27,6 +27,7 @@ ### Recipes +- Added a new entry "Add to meal plan" in the context/more menu per recipe to directly add a recipe to the meal plan from the recipes page - Changed that when a ingredient has a "Variable amount" set, the text entered there now also replaces the unit when displaying the recipe (not only the amount as before) - Fixed that hiding the "Requirements fulfilled" column (table options) on the recipes page didn't work - Fixed that ingredient costs and calories were wrong when product substitution and unit conversions were involved at the same time diff --git a/controllers/RecipesController.php b/controllers/RecipesController.php index 8c6df6c1..fdf9edfc 100644 --- a/controllers/RecipesController.php +++ b/controllers/RecipesController.php @@ -95,7 +95,7 @@ class RecipesController extends BaseController $totalCalories = FindObjectInArrayByPropertyValue($recipesResolved, 'recipe_id', $selectedRecipe->id)->calories; } - $renderArray = [ + $viewData = [ 'recipes' => $recipes, 'recipesResolved' => $recipesResolved, 'recipePositionsResolved' => $this->getDatabase()->recipes_pos_resolved()->where('recipe_id', $selectedRecipe->id), @@ -106,7 +106,8 @@ class RecipesController extends BaseController 'userfieldValues' => $this->getUserfieldsService()->GetAllValues('recipes'), 'quantityUnitConversionsResolved' => $this->getDatabase()->quantity_unit_conversions_resolved(), 'selectedRecipeTotalCosts' => $totalCosts, - 'selectedRecipeTotalCalories' => $totalCalories + 'selectedRecipeTotalCalories' => $totalCalories, + 'mealplanSections' => $this->getDatabase()->meal_plan_sections()->orderBy('sort_number') ]; if ($selectedRecipe) @@ -137,12 +138,12 @@ class RecipesController extends BaseController } } - $renderArray['selectedRecipeSubRecipes'] = $selectedRecipeSubRecipes; - $renderArray['includedRecipeIdsAbsolute'] = $includedRecipeIdsAbsolute; - $renderArray['allRecipePositions'] = $allRecipePositions; + $viewData['selectedRecipeSubRecipes'] = $selectedRecipeSubRecipes; + $viewData['includedRecipeIdsAbsolute'] = $includedRecipeIdsAbsolute; + $viewData['allRecipePositions'] = $allRecipePositions; } - return $this->renderPage($response, 'recipes', $renderArray); + return $this->renderPage($response, 'recipes', $viewData); } public function RecipeEditForm(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args) diff --git a/localization/strings.pot b/localization/strings.pot index 7d90e980..f3b96dbc 100644 --- a/localization/strings.pot +++ b/localization/strings.pot @@ -2350,3 +2350,9 @@ msgstr "" msgid "This is the default quantity unit used when consuming this product" msgstr "" + +msgid "Add to meal plan" +msgstr "" + +msgid "Successfully added the recipe to the meal plan" +msgstr "" diff --git a/public/viewjs/recipes.js b/public/viewjs/recipes.js index ff0c4205..830b8f90 100644 --- a/public/viewjs/recipes.js +++ b/public/viewjs/recipes.js @@ -442,3 +442,58 @@ $(document).on('click', '.ingredient-done-button', function(e) $(e.currentTarget).parent().toggleClass("text-strike-through"); }); + +$(document).on("click", ".add-to-mealplan-button", function(e) +{ + Grocy.Components.DateTimePicker.Init(true); + Grocy.Components.DateTimePicker.SetValue(moment().format("YYYY-MM-DD")); + Grocy.Components.RecipePicker.Clear(); + $("#add-to-mealplan-modal").modal("show"); + $('#recipe_id').val($(e.currentTarget).attr("data-recipe-id")); + $('#recipe_id').data('combobox').refresh(); + $('#recipe_id').trigger('change'); + Grocy.FrontendHelpers.ValidateForm("add-to-mealplan-form"); + $("#recipe_servings").focus(); +}); + +$('#save-add-to-mealplan-button').on('click', function(e) +{ + e.preventDefault(); + + if (!Grocy.FrontendHelpers.ValidateForm("add-to-mealplan-form", true) || $(".combobox-menu-visible").length) + { + return false; + } + + var formData = $('#add-to-mealplan-form').serializeJSON(); + formData.day = Grocy.Components.DateTimePicker.GetValue(); + + Grocy.Api.Post('objects/meal_plan', formData, + function(result) + { + toastr.success(__t("Successfully added the recipe to the meal plan")); + $("#add-to-mealplan-modal").modal("hide"); + }, + function(xhr) + { + Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response) + } + ); +}); + +$('#add-to-mealplan-form input').keydown(function(event) +{ + if (event.keyCode === 13) // Enter + { + event.preventDefault(); + + if (!Grocy.FrontendHelpers.ValidateForm('add-to-mealplan-form')) + { + return false; + } + else + { + $("#save-add-to-mealplan-button").click(); + } + } +}); diff --git a/views/mealplan.blade.php b/views/mealplan.blade.php index aee9a38c..d573132f 100644 --- a/views/mealplan.blade.php +++ b/views/mealplan.blade.php @@ -70,7 +70,6 @@ width: 200px !important; } } - @endpush @@ -244,7 +243,7 @@
- + + @foreach($mealplanSections as $mealplanSection) + + @endforeach + +
+ + + + + + + + @stop