mirror of https://github.com/kcal-app/kcal.git
Add recipe list view
This commit is contained in:
parent
198a32a915
commit
545e4c0b5e
|
@ -18,11 +18,12 @@ class RecipeController extends Controller
|
|||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function index()
|
||||
public function index(): View
|
||||
{
|
||||
//
|
||||
return view('recipes.index')
|
||||
->with('recipes', Recipe::all()->sortBy('name'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -106,7 +106,16 @@ class Recipe extends Model
|
|||
return $this->sumNutrient(substr($method, 0, -5));
|
||||
}
|
||||
elseif (in_array($method, $this->nutrientPerServingMethods)) {
|
||||
return $this->sumNutrient(substr($method, 0, -10)) / $this->servings;
|
||||
$sum = $this->sumNutrient(substr($method, 0, -10)) / $this->servings;
|
||||
|
||||
// Per-serving calculations are rounded, though actual food label
|
||||
// rounding standards are more complex.
|
||||
if ($sum > 1) {
|
||||
return round($sum);
|
||||
}
|
||||
else {
|
||||
return round($sum, 2);
|
||||
}
|
||||
}
|
||||
else {
|
||||
return parent::__call($method, $parameters);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<x-app-layout>
|
||||
<x-slot name="header">
|
||||
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
|
||||
{{ __('List Ingredients') }}
|
||||
{{ __('Ingredients') }}
|
||||
</h2>
|
||||
</x-slot>
|
||||
|
||||
|
@ -15,34 +15,34 @@
|
|||
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
|
||||
<div class="p-6 bg-white border-b border-gray-200">
|
||||
<div class="grid grid-cols-3 gap-4">
|
||||
@foreach ($ingredients as $ingedient)
|
||||
@foreach ($ingredients as $ingredient)
|
||||
<div class="p-2 font-light rounded-lg border-2 border-gray-200">
|
||||
<div class="pb-2 lowercase flex justify-between items-baseline">
|
||||
<div class="text-2xl">
|
||||
{{ $ingedient->name }}@if($ingedient->detail), <span class="text-gray-500">{{ $ingedient->detail }}</span>@endif
|
||||
{{ $ingredient->name }}@if($ingredient->detail), <span class="text-gray-500">{{ $ingredient->detail }}</span>@endif
|
||||
</div>
|
||||
<div class="text-right text-sm">
|
||||
@if ($ingedient->unit_weight)
|
||||
{{ $ingedient->unit_weight }}g each
|
||||
@if ($ingredient->unit_weight)
|
||||
{{ $ingredient->unit_weight }}g each
|
||||
@else
|
||||
{{ $ingedient->cup_weight }}g per cup
|
||||
{{ $ingredient->cup_weight }}g per cup
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
<div class="grid grid-cols-2 text-sm border-t-8 border-black pt-2">
|
||||
<div class="col-span-2 text-xs text-right">Amount per 100g</div>
|
||||
<div class="font-extrabold text-lg border-b-4 border-black">Calories</div>
|
||||
<div class="font-extrabold text-right text-lg border-b-4 border-black">{{$ingedient->calories}}</div>
|
||||
<div class="font-extrabold text-right text-lg border-b-4 border-black">{{$ingredient->calories}}</div>
|
||||
<div class="font-bold border-b border-gray-300">Fat</div>
|
||||
<div class="text-right border-b border-gray-300">{{ $ingedient->fat < 1 ? $ingedient->fat * 1000 . "m" : $ingedient->fat }}g</div>
|
||||
<div class="text-right border-b border-gray-300">{{ $ingredient->fat < 1 ? $ingredient->fat * 1000 . "m" : $ingredient->fat }}g</div>
|
||||
<div class="font-bold border-b border-gray-300">Cholesterol</div>
|
||||
<div class="text-right border-b border-gray-300">{{ $ingedient->cholesterol < 1 ? $ingedient->cholesterol * 1000 . "m" : $ingedient->cholesterol }}g</div>
|
||||
<div class="text-right border-b border-gray-300">{{ $ingredient->cholesterol < 1 ? $ingredient->cholesterol * 1000 . "m" : $ingredient->cholesterol }}g</div>
|
||||
<div class="font-bold border-b border-gray-300">Sodium</div>
|
||||
<div class="text-right border-b border-gray-300">{{ $ingedient->sodium < 1 ? $ingedient->sodium * 1000 . "m" : $ingedient->sodium }}g</div>
|
||||
<div class="text-right border-b border-gray-300">{{ $ingredient->sodium < 1 ? $ingredient->sodium * 1000 . "m" : $ingredient->sodium }}g</div>
|
||||
<div class="font-bold border-b border-gray-300">Carbohydrates</div>
|
||||
<div class="text-right border-b border-gray-300">{{ $ingedient->carbohydrates < 1 ? $ingedient->carbohydrates * 1000 . "m" : $ingedient->carbohydrates }}g</div>
|
||||
<div class="text-right border-b border-gray-300">{{ $ingredient->carbohydrates < 1 ? $ingredient->carbohydrates * 1000 . "m" : $ingredient->carbohydrates }}g</div>
|
||||
<div class="font-bold">Protein</div>
|
||||
<div class="text-right">{{ $ingedient->protein < 1 ? $ingedient->protein * 1000 . "m" : $ingedient->protein }}g</div>
|
||||
<div class="text-right">{{ $ingredient->protein < 1 ? $ingredient->protein * 1000 . "m" : $ingredient->protein }}g</div>
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
<x-app-layout>
|
||||
<x-slot name="header">
|
||||
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
|
||||
{{ __('Recipes') }}
|
||||
</h2>
|
||||
</x-slot>
|
||||
|
||||
<div class="py-12">
|
||||
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
|
||||
@if(session()->has('message'))
|
||||
<div class="bg-green-200 border-2 border-green-600 p-2 mb-2">
|
||||
{{ session()->get('message') }}
|
||||
</div>
|
||||
@endif
|
||||
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
|
||||
<div class="p-6 bg-white border-b border-gray-200">
|
||||
<div class="grid grid-cols-3 gap-4">
|
||||
@foreach ($recipes as $recipe)
|
||||
<div class="p-2 font-light rounded-lg border-2 border-gray-200">
|
||||
<div class="pb-2 lowercase flex justify-between items-baseline">
|
||||
<div class="text-2xl">{{ $recipe->name }}</div>
|
||||
</div>
|
||||
<div class="grid grid-cols-2 text-sm border-t-8 border-black pt-2">
|
||||
<div class="col-span-2 text-xs text-right">Amount per serving</div>
|
||||
<div class="font-extrabold text-lg border-b-4 border-black">Calories</div>
|
||||
<div class="font-extrabold text-right text-lg border-b-4 border-black">{{ $recipe->caloriesPerServing() }}</div>
|
||||
<div class="font-bold border-b border-gray-300">Fat</div>
|
||||
<div class="text-right border-b border-gray-300">{{ $recipe->fatPerServing() < 1 ? $recipe->fatPerServing() * 1000 . "m" : $recipe->fatPerServing() }}g</div>
|
||||
<div class="font-bold border-b border-gray-300">Cholesterol</div>
|
||||
<div class="text-right border-b border-gray-300">{{ $recipe->cholesterolPerServing() < 1 ? $recipe->cholesterolPerServing() * 1000 . "m" : $recipe->cholesterolPerServing() }}g</div>
|
||||
<div class="font-bold border-b border-gray-300">Sodium</div>
|
||||
<div class="text-right border-b border-gray-300">{{ $recipe->sodiumPerServing() < 1 ? $recipe->sodiumPerServing() * 1000 . "m" : $recipe->sodiumPerServing() }}g</div>
|
||||
<div class="font-bold border-b border-gray-300">Carbohydrates</div>
|
||||
<div class="text-right border-b border-gray-300">{{ $recipe->carbohydratesPerServing() < 1 ? $recipe->carbohydratesPerServing() * 1000 . "m" : $recipe->carbohydratesPerServing() }}g</div>
|
||||
<div class="font-bold">Protein</div>
|
||||
<div class="text-right">{{ $recipe->proteinPerServing() < 1 ? $recipe->proteinPerServing() * 1000 . "m" : $recipe->proteinPerServing() }}g</div>
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</x-app-layout>
|
Loading…
Reference in New Issue