mirror of https://github.com/kcal-app/kcal.git
Combine ingredients and separators handler in recipe edit
This commit is contained in:
parent
47a8f5675f
commit
8288a73faa
|
|
@ -88,6 +88,7 @@ class RecipeController extends Controller
|
|||
continue;
|
||||
}
|
||||
$ingredients[] = [
|
||||
'type' => 'ingredient',
|
||||
'key' => $old['key'][$key],
|
||||
'weight' => $old['weight'][$key],
|
||||
'amount' => $old['amount'][$key],
|
||||
|
|
@ -102,6 +103,7 @@ class RecipeController extends Controller
|
|||
else {
|
||||
foreach ($recipe->ingredientAmounts as $key => $ingredientAmount) {
|
||||
$ingredients[] = [
|
||||
'type' => 'ingredient',
|
||||
'key' => $key,
|
||||
'weight' => $ingredientAmount->weight,
|
||||
'amount' => $ingredientAmount->amount_formatted,
|
||||
|
|
@ -114,6 +116,31 @@ class RecipeController extends Controller
|
|||
}
|
||||
}
|
||||
|
||||
$separators = [];
|
||||
if ($old = old('separators')) {
|
||||
foreach ($old['key'] as $index => $key) {
|
||||
if (empty($key)) {
|
||||
continue;
|
||||
}
|
||||
$separators[] = [
|
||||
'type' => 'separator',
|
||||
'key' => $old['key'][$index],
|
||||
'weight' => $old['weight'][$index],
|
||||
'text' => $old['text'][$index],
|
||||
];
|
||||
}
|
||||
}
|
||||
else {
|
||||
foreach ($recipe->ingredientSeparators as $key => $ingredientSeparator) {
|
||||
$ingredients[] = [
|
||||
'type' => 'separator',
|
||||
'key' => $key,
|
||||
'weight' => $ingredientSeparator->weight,
|
||||
'text' => $ingredientSeparator->text,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$steps = [];
|
||||
if ($old = old('steps')) {
|
||||
foreach ($old['step'] as $key => $step) {
|
||||
|
|
@ -144,7 +171,7 @@ class RecipeController extends Controller
|
|||
return view('recipes.edit')
|
||||
->with('recipe', $recipe)
|
||||
->with('recipe_tags', $recipe_tags)
|
||||
->with('ingredients', $ingredients)
|
||||
->with('ingredients_list', new Collection([...$ingredients, ...$separators]))
|
||||
->with('steps', $steps)
|
||||
->with('ingredients_units', Nutrients::$units);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -126,8 +126,12 @@
|
|||
<!-- Ingredients -->
|
||||
<h3 class="mt-6 mb-2 font-extrabold text-lg">Ingredients</h3>
|
||||
<div x-data class="ingredients space-y-4">
|
||||
@forelse($ingredients as $ingredient)
|
||||
@include('recipes.partials.ingredient-input', $ingredient)
|
||||
@forelse($ingredients_list->sortBy('weight') as $item)
|
||||
@if($item['type'] === 'ingredient')
|
||||
@include('recipes.partials.ingredient-input', $item)
|
||||
@elseif($item['type'] === 'separator')
|
||||
@include('recipes.partials.separator-input', $item)
|
||||
@endif
|
||||
@empty
|
||||
@include('recipes.partials.ingredient-input')
|
||||
@endforelse
|
||||
|
|
|
|||
Loading…
Reference in New Issue