mirror of
https://github.com/grocy/grocy.git
synced 2025-04-29 09:39:57 +00:00
Include product_group in recipe ingredient list (#556)
* Include product_group in recipe ingredient list * Delete 0098.sql Co-authored-by: Bernd Bestel <bernd@berrnd.de>
This commit is contained in:
parent
6b8169a1f1
commit
c5f38689fa
@ -108,6 +108,9 @@ DefaultUserSetting('batteries_due_soon_days', 5);
|
||||
# Tasks settings
|
||||
DefaultUserSetting('tasks_due_soon_days', 5);
|
||||
|
||||
# Recipe settings
|
||||
DefaultUserSetting('recipe_ingredient_display_product_group', false); // Display the product group information in the ingredient list
|
||||
|
||||
# If the page should be automatically reloaded when there was
|
||||
# an external change
|
||||
DefaultUserSetting('auto_reload_on_db_change', true);
|
||||
|
@ -30,20 +30,20 @@ class RecipesController extends BaseController
|
||||
if (isset($request->getQueryParams()['recipe']))
|
||||
{
|
||||
$selectedRecipe = $this->Database->recipes($request->getQueryParams()['recipe']);
|
||||
$selectedRecipePositionsResolved = $this->Database->recipes_pos_resolved()->where('recipe_id = :1 AND is_nested_recipe_pos = 0', $request->getQueryParams()['recipe'])->orderBy('ingredient_group');
|
||||
$selectedRecipePositionsResolved = $this->Database->recipes_pos_resolved()->where('recipe_id = :1 AND is_nested_recipe_pos = 0', $request->getQueryParams()['recipe'])->orderBy('ingredient_group', 'ASC', 'product_group', 'ASC');
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach ($recipes as $recipe)
|
||||
{
|
||||
$selectedRecipe = $recipe;
|
||||
$selectedRecipePositionsResolved = $this->Database->recipes_pos_resolved()->where('recipe_id = :1 AND is_nested_recipe_pos = 0', $recipe->id)->orderBy('ingredient_group');
|
||||
$selectedRecipePositionsResolved = $this->Database->recipes_pos_resolved()->where('recipe_id = :1 AND is_nested_recipe_pos = 0', $recipe->id)->orderBy('ingredient_group', 'ASC', 'product_group', 'ASC');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$selectedRecipeSubRecipes = $this->Database->recipes()->where('id IN (SELECT includes_recipe_id FROM recipes_nestings_resolved WHERE recipe_id = :1 AND includes_recipe_id != :1)', $selectedRecipe->id)->orderBy('name')->fetchAll();
|
||||
$selectedRecipeSubRecipesPositions = $this->Database->recipes_pos_resolved()->where('recipe_id = :1', $selectedRecipe->id)->orderBy('ingredient_group')->fetchAll();
|
||||
$selectedRecipeSubRecipesPositions = $this->Database->recipes_pos_resolved()->where('recipe_id = :1', $selectedRecipe->id)->orderBy('ingredient_group', 'ASC', 'product_group', 'ASC')->fetchAll();
|
||||
|
||||
$includedRecipeIdsAbsolute = array();
|
||||
$includedRecipeIdsAbsolute[] = $selectedRecipe->id;
|
||||
@ -125,6 +125,11 @@ class RecipesController extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
public function RecipesSettings(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||
{
|
||||
return $this->AppContainer->view->render($response, 'recipessettings');
|
||||
}
|
||||
|
||||
public function MealPlan(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||
{
|
||||
$recipes = $this->Database->recipes()->where('type', RecipesService::RECIPE_TYPE_NORMAL)->fetchAll();
|
||||
|
4
public/viewjs/recipessettings.js
Normal file
4
public/viewjs/recipessettings.js
Normal file
@ -0,0 +1,4 @@
|
||||
if (BoolVal(Grocy.UserSettings.recipe_ingredient_display_product_group))
|
||||
{
|
||||
$("#recipe_ingredient_display_product_group").prop("checked", true);
|
||||
}
|
@ -70,6 +70,7 @@ $app->group('', function()
|
||||
$this->get('/recipe/{recipeId}', '\Grocy\Controllers\RecipesController:RecipeEditForm');
|
||||
$this->get('/recipe/{recipeId}/pos/{recipePosId}', '\Grocy\Controllers\RecipesController:RecipePosEditForm');
|
||||
$this->get('/mealplan', '\Grocy\Controllers\RecipesController:MealPlan');
|
||||
$this->get('/recipessettings', '\Grocy\Controllers\RecipesController:RecipesSettings');
|
||||
}
|
||||
|
||||
// Chore routes
|
||||
|
@ -404,6 +404,9 @@
|
||||
@if(GROCY_FEATURE_FLAG_TASKS)
|
||||
<a class="dropdown-item discrete-link" href="{{ $U('/taskssettings') }}"><i class="fas fa-tasks"></i> {{ $__t('Tasks settings') }}</a>
|
||||
@endif
|
||||
@if(GROCY_FEATURE_FLAG_RECIPES)
|
||||
<a class="dropdown-item discrete-link" href="{{ $U('/recipessettings') }}"><i class="fas fa-cocktail"></i> {{ $__t('Recipes settings') }}</a>
|
||||
@endif
|
||||
<div class="dropdown-divider"></div>
|
||||
<a class="dropdown-item discrete-link" href="{{ $U('/users') }}"><i class="fas fa-users"></i> {{ $__t('Manage users') }}</a>
|
||||
<div class="dropdown-divider"></div>
|
||||
|
@ -195,12 +195,16 @@
|
||||
@if(count($selectedRecipeSubRecipePositionsFiltered) > 0)
|
||||
<h5 class="mb-0">{{ $__t('Ingredients') }}</h5>
|
||||
<ul class="list-group list-group-flush">
|
||||
@php $lastGroup = 'undefined'; @endphp
|
||||
@php $lastIngredientGroup = 'undefined'; @endphp
|
||||
@php $lastProductGroup = 'undefined'; @endphp
|
||||
@foreach($selectedRecipeSubRecipePositionsFiltered as $selectedRecipePosition)
|
||||
@if($lastGroup != $selectedRecipePosition->ingredient_group)
|
||||
<h5 class="mb-2 mt-2 ml-4"><strong>{{ $selectedRecipePosition->ingredient_group }}</strong></h5>
|
||||
@if($lastIngredientGroup != $selectedRecipePosition->ingredient_group)
|
||||
<h5 class="mb-2 mt-2 ml-2"><strong>{{ $selectedRecipePosition->ingredient_group }}</strong></h5>
|
||||
@endif
|
||||
<li class="list-group-item px-0">
|
||||
@if(boolval($userSettings['recipe_ingredient_display_product_group']) && $lastProductGroup != $selectedRecipePosition->product_group)
|
||||
<h6 class="mb-2 mt-2 ml-4"><strong>{{ $selectedRecipePosition->product_group }}</strong></h6>
|
||||
@endif
|
||||
<li class="list-group-item px-0 ml-5">
|
||||
@php
|
||||
$product = FindObjectInArrayByPropertyValue($products, 'id', $selectedRecipePosition->product_id);
|
||||
$productQuConversions = FindAllObjectsInArrayByPropertyValue($quantityUnitConversionsResolved, 'product_id', $product->id);
|
||||
@ -228,7 +232,8 @@
|
||||
<div class="text-muted">{!! nl2br($selectedRecipePosition->note) !!}</div>
|
||||
@endif
|
||||
</li>
|
||||
@php $lastGroup = $selectedRecipePosition->ingredient_group; @endphp
|
||||
@php $lastProductGroup = $selectedRecipePosition->product_group; @endphp
|
||||
@php $lastIngredientGroup = $selectedRecipePosition->ingredient_group; @endphp
|
||||
@endforeach
|
||||
</ul>
|
||||
@endif
|
||||
@ -247,12 +252,16 @@
|
||||
@if($selectedRecipePositionsResolved->count() > 0)
|
||||
<h5 class="mb-0">{{ $__t('Ingredients') }}</h5>
|
||||
<ul class="list-group list-group-flush">
|
||||
@php $lastGroup = 'undefined'; @endphp
|
||||
@php $lastIngredientGroup = 'undefined'; @endphp
|
||||
@php $lastProductGroup = 'undefined'; @endphp
|
||||
@foreach($selectedRecipePositionsResolved as $selectedRecipePosition)
|
||||
@if($lastGroup != $selectedRecipePosition->ingredient_group)
|
||||
<h5 class="mb-2 mt-2 ml-4"><strong>{{ $selectedRecipePosition->ingredient_group }}</strong></h5>
|
||||
@if($lastIngredientGroup != $selectedRecipePosition->ingredient_group)
|
||||
<h5 class="mb-2 mt-2 ml-2"><strong>{{ $selectedRecipePosition->ingredient_group }}</strong></h5>
|
||||
@endif
|
||||
<li class="list-group-item px-0">
|
||||
@if(boolval($userSettings['recipe_ingredient_display_product_group']) && $lastProductGroup != $selectedRecipePosition->product_group)
|
||||
<h6 class="mb-2 mt-2 ml-4"><strong>{{ $selectedRecipePosition->product_group }}</strong></h6>
|
||||
@endif
|
||||
<li class="list-group-item px-0 ml-5">
|
||||
@php
|
||||
$product = FindObjectInArrayByPropertyValue($products, 'id', $selectedRecipePosition->product_id);
|
||||
$productQuConversions = FindAllObjectsInArrayByPropertyValue($quantityUnitConversionsResolved, 'product_id', $product->id);
|
||||
@ -280,7 +289,8 @@
|
||||
<div class="text-muted">{!! nl2br($selectedRecipePosition->note) !!}</div>
|
||||
@endif
|
||||
</li>
|
||||
@php $lastGroup = $selectedRecipePosition->ingredient_group; @endphp
|
||||
@php $lastProductGroup = $selectedRecipePosition->product_group; @endphp
|
||||
@php $lastIngredientGroup = $selectedRecipePosition->ingredient_group; @endphp
|
||||
@endforeach
|
||||
</ul>
|
||||
@endif
|
||||
|
24
views/recipessettings.blade.php
Normal file
24
views/recipessettings.blade.php
Normal file
@ -0,0 +1,24 @@
|
||||
@extends('layout.default')
|
||||
|
||||
@section('title', $__t('Recipes settings'))
|
||||
|
||||
@section('viewJsName', 'recipessettings')
|
||||
|
||||
@section('content')
|
||||
<div class="row">
|
||||
<div class="col-lg-6 col-xs-12">
|
||||
<h1>@yield('title')</h1>
|
||||
|
||||
<h4 class="mt-2">{{ $__t('Recipe card ingredients') }}</h4>
|
||||
<div class="form-group">
|
||||
<div class="checkbox">
|
||||
<label for="recipe_ingredient_display_product_group">
|
||||
<input type="checkbox" class="user-setting-control" id="recipe_ingredient_display_product_group" name="recipe_ingredient_display_product_group" data-setting-key="recipe_ingredient_display_product_group"> {{ $__t('In the recipe card ingredients, display product groups') }}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<a href="{{ $U('/recipes') }}" class="btn btn-success">{{ $__t('OK') }}</a>
|
||||
</div>
|
||||
</div>
|
||||
@stop
|
Loading…
x
Reference in New Issue
Block a user