kcal/resources/views/recipes/edit.blade.php

156 lines
10 KiB
PHP

<x-app-layout>
<x-slot name="header">
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
{{ ($recipe->exists ? "Edit {$recipe->name}" : 'Add Recipe') }}
</h2>
</x-slot>
<div class="py-12">
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
<div class="p-6 bg-white border-b border-gray-200">
<form method="POST" action="{{ ($recipe->exists ? route('recipes.update', $recipe) : route('recipes.store')) }}">
@if ($recipe->exists)@method('put')@endif
@csrf
<div class="flex flex-col space-y-4">
<div class="grid grid-cols-5 gap-4">
<!-- Name -->
<div class="col-span-4">
<x-inputs.label for="name" :value="__('Name')" />
<x-inputs.input id="name"
class="block mt-1 w-full"
type="text"
name="name"
:value="old('name', $recipe->name)"
required />
</div>
<!-- Servings -->
<div>
<x-inputs.label for="servings" :value="__('Servings')" />
<x-inputs.input id="servings"
class="block mt-1 w-full"
type="number"
name="servings"
:value="old('servings', $recipe->servings)"
required />
</div>
</div>
<!-- Description -->
<div>
<x-inputs.label for="description" :value="__('Description')" />
<x-inputs.textarea id="description"
class="block mt-1 w-full"
name="description"
:value="old('description', $recipe->description)" />
</div>
<!-- Source -->
<div>
<x-inputs.label for="source" :value="__('Source')" />
<x-inputs.input id="source"
class="block mt-1 w-full"
type="text"
name="source"
:value="old('source', $recipe->source)" />
</div>
</div>
<!-- Ingredients -->
<h3 class="pt-2 mb-2 font-extrabold">Ingredients</h3>
<div x-data="{ ingredients: 0 }">
@foreach($recipe->foodAmounts as $foodAmount)
<div class="flex flex-row space-x-4 mb-4">
<x-inputs.input type="text"
name="ingredients_amount[]"
size="5"
:value="old('ingredients_amount.' . $loop->index, \App\Support\Number::fractionStringFromFloat($foodAmount->amount))" />
<x-inputs.select name="ingredients_unit[]"
:options="$ingredients_units"
:selectedValue="old('ingredients_unit.' . $loop->index, $foodAmount->unit)">
<option value=""></option>
</x-inputs.select>
<x-ingredient-picker :default-id="old('ingredients.' . $loop->index, $foodAmount->food->id)"
:default-name="old('ingredients_name.' . $loop->index, $foodAmount->food->name)"/>
<x-inputs.input type="text"
class="block"
name="ingredients_detail[]"
:value="old('ingredients_detail.' . $loop->index, $foodAmount->detail)" />
<x-inputs.icon-button type="button" color="red" x-on:click="$event.target.parentNode.remove();">
<svg class="h-8 w-8 pointer-events-none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M9 2a1 1 0 00-.894.553L7.382 4H4a1 1 0 000 2v10a2 2 0 002 2h8a2 2 0 002-2V6a1 1 0 100-2h-3.382l-.724-1.447A1 1 0 0011 2H9zM7 8a1 1 0 012 0v6a1 1 0 11-2 0V8zm5-1a1 1 0 00-1 1v6a1 1 0 102 0V8a1 1 0 00-1-1z" clip-rule="evenodd" />
</svg>
</x-inputs.icon-button>
</div>
@endforeach
<!-- TODO: Handle old values!! -->
<template x-for="i in ingredients + 1">
<div class="flex flex-row space-x-4 mb-4">
<x-inputs.input type="text"
name="ingredients_amount[]"
size="5" />
<x-inputs.select name="ingredients_unit[]"
:options="$ingredients_units" >
<option value=""></option>
</x-inputs.select>
<x-ingredient-picker/>
<x-inputs.input type="text"
class="block"
name="ingredients_detail[]" />
<x-inputs.icon-button type="button" color="red" x-on:click="$event.target.parentNode.remove();">
<svg class="h-8 w-8 pointer-events-none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M9 2a1 1 0 00-.894.553L7.382 4H4a1 1 0 000 2v10a2 2 0 002 2h8a2 2 0 002-2V6a1 1 0 100-2h-3.382l-.724-1.447A1 1 0 0011 2H9zM7 8a1 1 0 012 0v6a1 1 0 11-2 0V8zm5-1a1 1 0 00-1 1v6a1 1 0 102 0V8a1 1 0 00-1-1z" clip-rule="evenodd" />
</svg>
</x-inputs.icon-button>
</div>
</template>
<x-inputs.icon-button type="button" color="green" x-on:click="ingredients++;">
<svg class="h-10 w-10" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm1-11a1 1 0 10-2 0v2H7a1 1 0 100 2h2v2a1 1 0 102 0v-2h2a1 1 0 100-2h-2V7z" clip-rule="evenodd" />
</svg>
</x-inputs.icon-button>
</div>
<!-- Steps -->
<h3 class="pt-2 mb-2 font-extrabold">Steps</h3>
@php($step_number = 0)
<div x-data="{steps: 0}">
@foreach($recipe->steps as $step)
<div class="flex flex-row space-x-4 mb-4">
<div class="text-3xl text-gray-400 text-center">{{ $step_number++ }}</div>
<x-inputs.textarea class="block mt-1 w-full"
name="steps[]"
:value="old('steps.' . $loop->index, $step->step)" />
</div>
@endforeach
<template x-for="i in steps + 1">
<div class="flex flex-row space-x-4 mb-4">
<div class="text-3xl text-gray-400 text-center" x-text="{{ $step_number }} + i"></div>
<x-inputs.textarea class="block mt-1 w-full"
name="steps[]" />
</div>
</template>
<x-inputs.icon-button type="button" color="green" x-on:click="steps++;">
<svg class="h-10 w-10" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm1-11a1 1 0 10-2 0v2H7a1 1 0 100 2h2v2a1 1 0 102 0v-2h2a1 1 0 100-2h-2V7z" clip-rule="evenodd" />
</svg>
</x-inputs.icon-button>
</div>
<div class="flex items-center justify-end mt-4">
<x-inputs.button class="ml-3">
{{ ($recipe->exists ? 'Save' : 'Add') }}
</x-inputs.button>
</div>
</form>
</div>
</div>
</div>
</div>
</x-app-layout>