Log a recipe or food from their show pages

This commit is contained in:
Bram Wubs 2022-10-09 21:04:01 +02:00
parent 2b03c92892
commit 017a840d56
9 changed files with 59032 additions and 29 deletions

View File

@ -18,6 +18,7 @@ class StoreJournalEntryRequest extends FormRequest
*/ */
public function rules(): array public function rules(): array
{ {
// dd($this->all());
return [ return [
'ingredients.date' => ['required', 'array', new ArrayNotEmpty], 'ingredients.date' => ['required', 'array', new ArrayNotEmpty],
'ingredients.date.*' => ['nullable', 'date', 'required_with:ingredients.id.*'], 'ingredients.date.*' => ['nullable', 'date', 'required_with:ingredients.id.*'],

2380
public/css/app.css vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

23259
public/js/app.js vendored

File diff suppressed because one or more lines are too long

7703
public/js/draggable.js vendored

File diff suppressed because one or more lines are too long

24297
public/js/quill.js vendored

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,18 @@
<form class="" method="POST" action="{{ route('journal-entries.store') }}">
@csrf
<input type="hidden" name="ingredients[date][0]" id="date" value="{{ now()->format('Y-m-d') }}">
<input type="hidden" name="ingredients[amount][0]" value="1">
<input type="hidden" name="ingredients[id][0]" value="{{ $journalable->getKey() }}">
<input type="hidden" name="ingredients[type][0]" value="{{$journalable::class}}">
<input type="hidden" name="ingredients[unit][0]" value="serving">
<x-inputs.select class="px-4 py-1" name="ingredients[meal][0]"
:options="Auth::user()->meals_enabled->toArray()"
:selectedValue="old('meal')"
:hasError="$errors->has('meal')"
required>
<option value=""></option>
</x-inputs.select>
<button class="px-4 py-2 border border-transparent rounded-md font-semibold text-xs text-center uppercase tracking-widest focus:outline-none focus:ring disabled:opacity-25 transition ease-in-out duration-150 cursor-pointer text-white bg-green-800 hover:bg-green-700 active:bg-green-900 focus:border-green-900 ring-green-300" type="submit">
Log
</button>
</form>

View File

@ -100,6 +100,7 @@
</div> </div>
</section> </section>
<section class="flex flex-row space-x-2 justify-around md:flex-col md:space-y-2 md:space-x-0"> <section class="flex flex-row space-x-2 justify-around md:flex-col md:space-y-2 md:space-x-0">
<x-log-journalable :journalable="$food"></x-log-journalable>
<x-button-link.gray href="{{ route('foods.edit', $food) }}"> <x-button-link.gray href="{{ route('foods.edit', $food) }}">
Edit Food Edit Food
</x-button-link.gray> </x-button-link.gray>

View File

@ -1,3 +1,7 @@
@php use App\Models\IngredientAmount; @endphp
@php use App\Support\Number; @endphp
@php use App\Models\Recipe; @endphp
@php use App\Models\RecipeSeparator; @endphp
<x-app-layout> <x-app-layout>
<x-slot name="title">{{ $recipe->name }}</x-slot> <x-slot name="title">{{ $recipe->name }}</x-slot>
@if(!empty($feature_image)) @if(!empty($feature_image))
@ -34,13 +38,14 @@
<section x-data="{ showNutrientsSummary: false }"> <section x-data="{ showNutrientsSummary: false }">
<h1 class="mb-2 font-bold text-2xl"> <h1 class="mb-2 font-bold text-2xl">
Ingredients Ingredients
<span class="text-sm text-gray-500 hover:text-gray-700 hover:border-gray-300 font-normal cursor-pointer" <span
x-on:click="showNutrientsSummary = !showNutrientsSummary">[toggle nutrients]</span> class="text-sm text-gray-500 hover:text-gray-700 hover:border-gray-300 font-normal cursor-pointer"
x-on:click="showNutrientsSummary = !showNutrientsSummary">[toggle nutrients]</span>
</h1> </h1>
<div class="prose prose-lg"> <div class="prose prose-lg">
<ul class="space-y-2"> <ul class="space-y-2">
@foreach($recipe->ingredientsList->sortBy('weight') as $item) @foreach($recipe->ingredientsList->sortBy('weight') as $item)
@if($item::class === \App\Models\IngredientAmount::class) @if($item::class === IngredientAmount::class)
<li> <li>
<span> <span>
{{-- Prevent food with serving size > 1 from incorrectly using formatted {{-- Prevent food with serving size > 1 from incorrectly using formatted
@ -48,35 +53,44 @@
serving of a food with 4 tbsp. to a serving size show "1 serving" instead serving of a food with 4 tbsp. to a serving size show "1 serving" instead
of "1 tbsp." (incorrect). --}} of "1 tbsp." (incorrect). --}}
@if($item->unit === 'serving' && $item->ingredient->serving_size > 1 && ($item->ingredient->serving_unit || $item->ingredient->serving_unit_name)) @if($item->unit === 'serving' && $item->ingredient->serving_size > 1 && ($item->ingredient->serving_unit || $item->ingredient->serving_unit_name))
{{ \App\Support\Number::rationalStringFromFloat($item->amount * $item->ingredient->serving_size) }} {{ $item->unitFormatted }} {{ Number::rationalStringFromFloat($item->amount * $item->ingredient->serving_size) }} {{ $item->unitFormatted }}
<span class="text-gray-500">({{ \App\Support\Number::rationalStringFromFloat($item->amount) }} {{ \Illuminate\Support\Str::plural('serving', $item->amount ) }})</span> <span
class="text-gray-500">({{ Number::rationalStringFromFloat($item->amount) }} {{ \Illuminate\Support\Str::plural('serving', $item->amount ) }})</span>
@else @else
{{ \App\Support\Number::rationalStringFromFloat($item->amount) }} {{ Number::rationalStringFromFloat($item->amount) }}
@if($item->unitFormatted){{ $item->unitFormatted }}@endif @if($item->unitFormatted)
{{ $item->unitFormatted }}
@endif
@endif @endif
@if($item->ingredient->type === \App\Models\Recipe::class) @if($item->ingredient->type === Recipe::class)
<a class="text-gray-500 hover:text-gray-700 hover:border-gray-300" <a class="text-gray-500 hover:text-gray-700 hover:border-gray-300"
href="{{ route('recipes.show', $item->ingredient) }}"> href="{{ route('recipes.show', $item->ingredient) }}">
{{ $item->ingredient->name }} {{ $item->ingredient->name }}
</a> </a>
@else @else
{{ $item->ingredient->name }}@if($item->ingredient->detail), {{ $item->ingredient->detail }}@endif {{ $item->ingredient->name }}@if($item->ingredient->detail)
, {{ $item->ingredient->detail }}
@endif
@endif @endif
@if($item->detail)<span class="text-gray-500">{{ $item->detail }}</span>@endif @if($item->detail)
<div x-show="showNutrientsSummary" class="text-sm text-gray-500">{{ $item->nutrients_summary }}</div> <span class="text-gray-500">{{ $item->detail }}</span>
@endif
<div x-show="showNutrientsSummary"
class="text-sm text-gray-500">{{ $item->nutrients_summary }}</div>
</span> </span>
</li> </li>
@elseif($item::class === \App\Models\RecipeSeparator::class) @elseif($item::class === RecipeSeparator::class)
</ul></div> </ul>
@if($item->text) </div>
<h2 class="mt-3 font-bold">{{ $item->text }}</h2> @if($item->text)
@else <h2 class="mt-3 font-bold">{{ $item->text }}</h2>
<hr class="mt-3 lg:w-1/2" /> @else
@endif <hr class="mt-3 lg:w-1/2"/>
<div class="prose prose-lg"> @endif
<ul class="space-y-2"> <div class="prose prose-lg">
@endif <ul class="space-y-2">
@endif
@endforeach @endforeach
</ul> </ul>
</div> </div>
@ -97,7 +111,8 @@
<h1 class="mb-2 font-bold text-2xl">Tags</h1> <h1 class="mb-2 font-bold text-2xl">Tags</h1>
<div class="flex flex-wrap"> <div class="flex flex-wrap">
@foreach($recipe->tags as $tag) @foreach($recipe->tags as $tag)
<span class="m-1 bg-gray-200 rounded-full px-2 leading-loose cursor-default">{{ $tag->name }}</span> <span
class="m-1 bg-gray-200 rounded-full px-2 leading-loose cursor-default">{{ $tag->name }}</span>
@endforeach @endforeach
</div> </div>
</section> </section>
@ -164,6 +179,7 @@
</div> </div>
</div> </div>
<section class="flex flex-row space-x-2 justify-around md:flex-col md:space-y-2 md:space-x-0"> <section class="flex flex-row space-x-2 justify-around md:flex-col md:space-y-2 md:space-x-0">
<x-log-journalable :journalable="$recipe"></x-log-journalable>
<x-button-link.gray href="{{ route('recipes.edit', $recipe) }}"> <x-button-link.gray href="{{ route('recipes.edit', $recipe) }}">
Edit Recipe Edit Recipe
</x-button-link.gray> </x-button-link.gray>