mirror of
https://github.com/grocy/grocy.git
synced 2025-04-29 01:32:38 +00:00
Allow recipe ingredients to be ignored when putting them on the shopping list (closes #125)
This commit is contained in:
parent
89ad25c904
commit
e9ef7ea6d8
@ -16,7 +16,15 @@ class RecipesApiController extends BaseApiController
|
||||
|
||||
public function AddNotFulfilledProductsToShoppingList(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||
{
|
||||
$this->RecipesService->AddNotFulfilledProductsToShoppingList($args['recipeId']);
|
||||
$requestBody = $request->getParsedBody();
|
||||
$excludedProductIds = null;
|
||||
|
||||
if ($requestBody !== null && array_key_exists('excludedProductIds', $requestBody))
|
||||
{
|
||||
$excludedProductIds = $requestBody['excludedProductIds'];
|
||||
}
|
||||
|
||||
$this->RecipesService->AddNotFulfilledProductsToShoppingList($args['recipeId'], $excludedProductIds);
|
||||
return $this->EmptyApiResponse($response);
|
||||
}
|
||||
|
||||
|
@ -50,6 +50,13 @@ class RecipesController extends BaseController
|
||||
$selectedSubRecipePosition->amount = $selectedSubRecipePosition->amount * ($selectedRecipe->desired_servings / $selectedRecipe->base_servings);
|
||||
}
|
||||
|
||||
$includedRecipeIdsAbsolute = array();
|
||||
$includedRecipeIdsAbsolute[] = $selectedRecipe->id;
|
||||
foreach($selectedRecipeSubRecipes as $subRecipe)
|
||||
{
|
||||
$includedRecipeIdsAbsolute[] = $subRecipe->id;
|
||||
}
|
||||
|
||||
return $this->AppContainer->view->render($response, 'recipes', [
|
||||
'recipes' => $recipes,
|
||||
'recipesFulfillment' => $this->RecipesService->GetRecipesFulfillment(),
|
||||
@ -59,7 +66,8 @@ class RecipesController extends BaseController
|
||||
'products' => $this->Database->products(),
|
||||
'quantityunits' => $this->Database->quantity_units(),
|
||||
'selectedRecipeSubRecipes' => $selectedRecipeSubRecipes,
|
||||
'selectedRecipeSubRecipesPositions' => $selectedRecipeSubRecipesPositions
|
||||
'selectedRecipeSubRecipesPositions' => $selectedRecipeSubRecipesPositions,
|
||||
'includedRecipeIdsAbsolute' => $includedRecipeIdsAbsolute
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -1404,6 +1404,26 @@
|
||||
}
|
||||
}
|
||||
],
|
||||
"requestBody": {
|
||||
"required": false,
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"excludedProductIds": {
|
||||
"type": "array",
|
||||
"items":{
|
||||
"type": "number",
|
||||
"format": "integer"
|
||||
},
|
||||
"description": "An optional array of product ids to exclude them from being put on the shopping list"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"responses": {
|
||||
"204": {
|
||||
"description": "The operation was successful"
|
||||
|
@ -84,7 +84,7 @@ $(document).on('click', '.recipe-order-missing-button', function(e)
|
||||
var objectId = $(e.currentTarget).attr('data-recipe-id');
|
||||
|
||||
bootbox.confirm({
|
||||
message: L('Are you sure to put all missing ingredients for recipe "#1" on the shopping list?', objectName),
|
||||
message: L('Are you sure to put all missing ingredients for recipe "#1" on the shopping list?', objectName) + "<br><br>" + L("Uncheck ingredients to not put them on the shopping list.") + $("#missing-recipe-pos-list")[0].outerHTML.replace("d-none", ""),
|
||||
buttons: {
|
||||
confirm: {
|
||||
label: L('Yes'),
|
||||
@ -101,7 +101,13 @@ $(document).on('click', '.recipe-order-missing-button', function(e)
|
||||
{
|
||||
Grocy.FrontendHelpers.BeginUiBusy();
|
||||
|
||||
Grocy.Api.Post('recipes/' + objectId + '/add-not-fulfilled-products-to-shoppinglist', { },
|
||||
var excludedProductIds = new Array();
|
||||
$(".missing-recipe-pos-product-checkbox:checkbox:not(:checked)").each(function()
|
||||
{
|
||||
excludedProductIds.push($(this).data("product-id"));
|
||||
});
|
||||
|
||||
Grocy.Api.Post('recipes/' + objectId + '/add-not-fulfilled-products-to-shoppinglist', { "excludedProductIds": excludedProductIds },
|
||||
function(result)
|
||||
{
|
||||
window.location.href = U('/recipes');
|
||||
@ -195,6 +201,16 @@ $('#servings-scale').keyup(function(event)
|
||||
);
|
||||
});
|
||||
|
||||
$(document).on("click", ".missing-recipe-pos-select-button", function(e)
|
||||
{
|
||||
e.preventDefault();
|
||||
|
||||
var checkbox = $(this).find(".form-check-input");
|
||||
checkbox.prop("checked", !checkbox.prop("checked"));
|
||||
|
||||
$(this).toggleClass("list-group-item-primary");
|
||||
});
|
||||
|
||||
if (window.location.hash === "#fullscreen")
|
||||
{
|
||||
$("#selectedRecipeToggleFullscreenButton").click();
|
||||
|
@ -26,14 +26,14 @@ class RecipesService extends BaseService
|
||||
return $this->DatabaseService->ExecuteDbQuery($sql)->fetchAll(\PDO::FETCH_OBJ);
|
||||
}
|
||||
|
||||
public function AddNotFulfilledProductsToShoppingList($recipeId)
|
||||
public function AddNotFulfilledProductsToShoppingList($recipeId, $excludedProductIds = null)
|
||||
{
|
||||
$recipe = $this->Database->recipes($recipeId);
|
||||
|
||||
$recipePositions = $this->GetRecipesFulfillment();
|
||||
foreach ($recipePositions as $recipePosition)
|
||||
{
|
||||
if($recipePosition->recipe_id == $recipeId)
|
||||
if($recipePosition->recipe_id == $recipeId && !in_array($recipePosition->product_id, $excludedProductIds))
|
||||
{
|
||||
$product = $this->Database->products($recipePosition->product_id);
|
||||
|
||||
|
@ -162,4 +162,17 @@
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<div id="missing-recipe-pos-list" class="list-group d-none mt-3">
|
||||
@foreach($recipesFulfillment as $recipePos)
|
||||
@if(in_array($recipePos->recipe_id, $includedRecipeIdsAbsolute))
|
||||
<a href="#" class="list-group-item list-group-item-action list-group-item-primary missing-recipe-pos-select-button">
|
||||
<div class="form-check form-check-inline">
|
||||
<input class="form-check-input missing-recipe-pos-product-checkbox" type="checkbox" data-product-id="{{ $recipePos->product_id }}" checked>
|
||||
</div>
|
||||
{{ FindObjectInArrayByPropertyValue($products, 'id', $recipePos->product_id)->name }}
|
||||
</a>
|
||||
@endif
|
||||
@endforeach
|
||||
</div>
|
||||
@stop
|
||||
|
Loading…
x
Reference in New Issue
Block a user