Add better placeholder content for goals

This commit is contained in:
Christopher C. Wells 2021-02-15 14:18:33 -08:00
parent c642111c20
commit a5d42fa8e5
7 changed files with 66 additions and 41 deletions

View File

@ -50,7 +50,10 @@ class GoalController extends Controller
*/
public function show(Goal $goal): View
{
return view('goals.show')->with('goal', $goal);
return view('goals.show')
->with('goal', $goal)
->with('nameOptions', Goal::getNameOptions())
->with('frequencyOptions', Goal::$frequencyOptions);
}
/**

View File

@ -43,7 +43,7 @@ final class Goal extends Model
* Supported options for thr frequency attribute.
*/
public static array $frequencyOptions = [
['value' => 'daily', 'label' => 'daily'],
'daily' => ['value' => 'daily', 'label' => 'daily'],
];
/**

View File

@ -10,21 +10,21 @@ class Nutrients
public static float $gramsPerOunce = 28.349523125;
public static array $all = [
['value' => 'calories', 'label' => 'calories', 'unit' => null],
['value' => 'carbohydrates', 'label' => 'carbohydrates', 'unit' => 'g'],
['value' => 'cholesterol', 'label' => 'cholesterol', 'unit' => 'mg'],
['value' => 'fat', 'label' => 'fat', 'unit' => 'g'],
['value' => 'protein', 'label' => 'protein', 'unit' => 'g'],
['value' => 'sodium', 'label' => 'sodium', 'unit' => 'mg'],
'calories' => ['value' => 'calories', 'label' => 'calories', 'unit' => null],
'carbohydrates' => ['value' => 'carbohydrates', 'label' => 'carbohydrates', 'unit' => 'g'],
'cholesterol' => ['value' => 'cholesterol', 'label' => 'cholesterol', 'unit' => 'mg'],
'fat' => ['value' => 'fat', 'label' => 'fat', 'unit' => 'g'],
'protein' => ['value' => 'protein', 'label' => 'protein', 'unit' => 'g'],
'sodium' => ['value' => 'sodium', 'label' => 'sodium', 'unit' => 'mg'],
];
public static array $units = [
['value' => 'cup', 'label' => 'cup'],
['value' => 'gram', 'label' => 'grams'],
['value' => 'oz', 'label' => 'oz'],
['value' => 'serving', 'label' => 'servings'],
['value' => 'tbsp', 'label' => 'tbsp.'],
['value' => 'tsp', 'label' => 'tsp.'],
'cup' => ['value' => 'cup', 'label' => 'cup'],
'gram' => ['value' => 'gram', 'label' => 'grams'],
'oz' => ['value' => 'oz', 'label' => 'oz'],
'serving' => ['value' => 'serving', 'label' => 'servings'],
'tbsp' => ['value' => 'tbsp', 'label' => 'tbsp.'],
'tsp' => ['value' => 'tsp', 'label' => 'tsp.'],
];
/**

View File

@ -20,7 +20,7 @@
<x-inputs.input name="from"
type="date"
class="block w-full"
:value="old('from', $goal->from)" />
:value="old('from', $goal->from?->toDateString())" />
</div>
<!-- To -->
@ -29,7 +29,7 @@
<x-inputs.input name="to"
type="date"
class="block w-full"
:value="old('to', $goal->to)" />
:value="old('to', $goal->to?->toDateString())" />
</div>
<!-- Frequency -->

View File

@ -36,11 +36,9 @@
<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">
@forelse($goals['present'] as $goal)
<details>
<summary>{{ $goal->summary }}</summary>
TODO: Details for the day!
<div class="flex">
<div class="space-y-4">
@forelse($goals['present'] as $goal)
<div class="flex space-x-2 items-center">
<a class="text-gray-500 hover:text-gray-700 hover:border-gray-300 text-sm"
href="{{ route('goals.edit', $goal) }}">
<svg class="h-6 w-6" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
@ -54,11 +52,12 @@
<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>
</a>
<div class="text-lg font-bold">{{ $goal->summary }}</div>
</div>
</details>
@empty
<div>No goals set.</div>
@endforelse
@empty
<div>No goals set.</div>
@endforelse
</div>
</div>
</div>
</div>

View File

@ -21,7 +21,18 @@
<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">
TODO: GOAL SHOW PAGE
<div class="grid grid-cols-2 gap-y-1 gap-x-3 max-w-md inline-grid">
<div class="font-bold">From</div>
<div>{{ $goal->from?->toDateString() ?? 'Any' }}</div>
<div class="font-bold">To</div>
<div>{{ $goal->to?->toDateString() ?? 'Any' }}</div>
<div class="font-bold">Frequency</div>
<div>{{ \Illuminate\Support\Str::ucfirst($frequencyOptions[$goal->frequency]['label']) }}</div>
<div class="font-bold">Trackable</div>
<div>{{ \Illuminate\Support\Str::ucfirst($nameOptions[$goal->name]['label']) }}</div>
<div class="font-bold">Goal</div>
<div>{{ $goal->goal }}{{ $nameOptions[$goal->name]['unit'] }}</div>
</div>
</div>
</div>
</div>

View File

@ -37,46 +37,58 @@
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
<div class="p-6 bg-white border-b border-gray-200">
<div class="flex align-top flex-col space-y-4 sm:flex-row sm:space-x-4 sm:space-y-0">
<div class="w-full sm:w-5/12 md:w-5/12">
<h3 class="font-semibold text-xl text-gray-800">{{ $date->format('D, j M Y') }}</h3>
<div class="text-gray-700">{{ $entries->count() }} {{ \Illuminate\Support\Pluralizer::plural('entry', $entries->count()) }}</div>
<div class="text-right border-t-8 border-black pt-2">% Daily goal</div>
<div class="grid grid-cols-2 text-sm">
<div class="border-b-4 border-black">
<div class="w-full sm:w-5/12 lg:w-4/12">
<div class="flex justify-between items-baseline">
<h3 class="font-semibold text-lg text-gray-800">{{ $date->format('D, j M Y') }}</h3>
<div class="text-gray-700">{{ $entries->count() }} {{ \Illuminate\Support\Pluralizer::plural('entry', $entries->count()) }}</div>
</div>
<div class="text-right border-t-8 border-black text-sm pt-2">% Daily goal</div>
<div class="flex justify-between items-baseline border-b-4 border-black">
<div>
<span class="font-extrabold text-2xl">Calories</span>
<span class="text-lg">{{ number_format($sums['calories']) }}</span>
</div>
<div class="font-extrabold text-right text-lg border-b-4 border-black">
<div class="font-extrabold text-right text-lg">
{{ $dailyGoals['calories'] ?? 'N/A' }}
</div>
<div class="border-b border-gray-300">
</div>
<div class="flex justify-between items-baseline border-b border-gray-300 text-sm">
<div>
<span class="font-bold">Fat</span>
{{ number_format($sums['fat']) }}g
</div>
<div class="text-right border-b border-gray-300">
<div class="text-right">
{{ $dailyGoals['fat'] ?? 'N/A' }}
</div>
<div class="border-b border-gray-300">
</div>
<div class="flex justify-between items-baseline border-b border-gray-300 text-sm">
<div>
<span class="font-bold">Cholesterol</span>
{{ number_format($sums['cholesterol']) }}mg
</div>
<div class="text-right border-b border-gray-300">
<div class="text-right">
{{ $dailyGoals['cholesterol'] ?? 'N/A' }}
</div>
<div class="border-b border-gray-300">
</div>
<div class="flex justify-between items-baseline border-b border-gray-300 text-sm">
<div>
<span class="font-bold">Sodium</span>
{{ number_format($sums['sodium']) }}mg
</div>
<div class="text-right border-b border-gray-300">
<div class="text-right">
{{ $dailyGoals['sodium'] ?? 'N/A' }}
</div>
<div class="border-b border-gray-300">
</div>
<div class="flex justify-between items-baseline border-b border-gray-300 text-sm">
<div>
<span class="font-bold">Carbohydrates</span>
{{ number_format($sums['carbohydrates']) }}g
</div>
<div class="text-right border-b border-gray-300">
<div class="text-right">
{{ $dailyGoals['carbohydrates'] ?? 'N/A' }}
</div>
</div>
<div class="flex justify-between items-baseline text-sm">
<div>
<span class="font-bold">Protein</span>
{{ number_format($sums['protein']) }}g