Skip to content

Commit

Permalink
Merge 1ab81a0 into 50bb378
Browse files Browse the repository at this point in the history
  • Loading branch information
megawubs committed Oct 20, 2022
2 parents 50bb378 + 1ab81a0 commit bb6cc9f
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 24 deletions.
6 changes: 5 additions & 1 deletion app/Http/Requests/StoreJournalEntryRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ public function rules(): array
new InArray(Auth::user()->meals_enabled->pluck('value')->toArray())
],
'ingredients.amount' => ['required', 'array', new ArrayNotEmpty],
'ingredients.amount.*' => ['required_with:ingredients.id.*', 'nullable', new StringIsPositiveDecimalOrFraction],
'ingredients.amount.*' => [
'required_with:ingredients.id.*',
'nullable',
new StringIsPositiveDecimalOrFraction
],
'ingredients.unit' => ['required', 'array'],
'ingredients.unit.*' => ['required_with:ingredients.id.*'],
'ingredients.id.*' => 'required_with:ingredients.amount.*|nullable',
Expand Down
2 changes: 1 addition & 1 deletion public/css/app.css

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions resources/views/components/log-journalable.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<form class="border-2 border-black p-2" 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 my-2 w-full" 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 w-full 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>
1 change: 1 addition & 0 deletions resources/views/foods/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
</div>
</section>
<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) }}">
Edit Food
</x-button-link.gray>
Expand Down
60 changes: 38 additions & 22 deletions resources/views/recipes/show.blade.php
Original file line number Diff line number Diff line change
@@ -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-slot name="title">{{ $recipe->name }}</x-slot>
@if(!empty($feature_image))
Expand Down Expand Up @@ -34,49 +38,59 @@
<section x-data="{ showNutrientsSummary: false }">
<h1 class="mb-2 font-bold text-2xl">
Ingredients
<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>
<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>
<div class="prose prose-lg">
<ul class="space-y-2">
@foreach($recipe->ingredientsList->sortBy('weight') as $item)
@if($item::class === \App\Models\IngredientAmount::class)
@if($item::class === IngredientAmount::class)
<li>
<span>
{{-- Prevent food with serving size > 1 from incorrectly using formatted
serving unit with number of servings. E.g., for a recipe calling for 1
serving of a food with 4 tbsp. to a serving size show "1 serving" instead
of "1 tbsp." (incorrect). --}}
@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 }}
<span class="text-gray-500">({{ \App\Support\Number::rationalStringFromFloat($item->amount) }} {{ \Illuminate\Support\Str::plural('serving', $item->amount ) }})</span>
{{ Number::rationalStringFromFloat($item->amount * $item->ingredient->serving_size) }} {{ $item->unitFormatted }}
<span
class="text-gray-500">({{ Number::rationalStringFromFloat($item->amount) }} {{ \Illuminate\Support\Str::plural('serving', $item->amount ) }})</span>
@else
{{ \App\Support\Number::rationalStringFromFloat($item->amount) }}
@if($item->unitFormatted){{ $item->unitFormatted }}@endif
{{ Number::rationalStringFromFloat($item->amount) }}
@if($item->unitFormatted)
{{ $item->unitFormatted }}
@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"
href="{{ route('recipes.show', $item->ingredient) }}">
{{ $item->ingredient->name }}
</a>
@else
{{ $item->ingredient->name }}@if($item->ingredient->detail), {{ $item->ingredient->detail }}@endif
{{ $item->ingredient->name }}@if($item->ingredient->detail)
, {{ $item->ingredient->detail }}
@endif
@endif
@if($item->detail)<span class="text-gray-500">{{ $item->detail }}</span>@endif
<div x-show="showNutrientsSummary" class="text-sm text-gray-500">{{ $item->nutrients_summary }}</div>
@if($item->detail)
<span class="text-gray-500">{{ $item->detail }}</span>
@endif
<div x-show="showNutrientsSummary"
class="text-sm text-gray-500">{{ $item->nutrients_summary }}</div>
</span>
</li>
@elseif($item::class === \App\Models\RecipeSeparator::class)
</ul></div>
@if($item->text)
<h2 class="mt-3 font-bold">{{ $item->text }}</h2>
@else
<hr class="mt-3 lg:w-1/2" />
@endif
<div class="prose prose-lg">
<ul class="space-y-2">
@endif
@elseif($item::class === RecipeSeparator::class)
</ul>
</div>
@if($item->text)
<h2 class="mt-3 font-bold">{{ $item->text }}</h2>
@else
<hr class="mt-3 lg:w-1/2"/>
@endif
<div class="prose prose-lg">
<ul class="space-y-2">
@endif
@endforeach
</ul>
</div>
Expand All @@ -97,7 +111,8 @@
<h1 class="mb-2 font-bold text-2xl">Tags</h1>
<div class="flex flex-wrap">
@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
</div>
</section>
Expand Down Expand Up @@ -164,6 +179,7 @@
</div>
</div>
<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) }}">
Edit Recipe
</x-button-link.gray>
Expand Down

0 comments on commit bb6cc9f

Please sign in to comment.