mirror of https://github.com/kcal-app/kcal.git
Update basic Goals index
This commit is contained in:
parent
22a80400db
commit
45ce469cdf
|
@ -6,8 +6,6 @@ use App\Http\Requests\UpdateGoalRequest;
|
|||
use App\Models\Goal;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class GoalController extends Controller
|
||||
|
@ -15,17 +13,10 @@ class GoalController extends Controller
|
|||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index(Request $request): View
|
||||
public function index(): View
|
||||
{
|
||||
if ($request->date) {
|
||||
$date = Carbon::createFromFormat('Y-m-d', $request->date);
|
||||
}
|
||||
else {
|
||||
$date = Carbon::now();
|
||||
}
|
||||
return view('goals.index')
|
||||
->with('date', $date)
|
||||
->with('goals', Auth::user()->getGoalsByTime($date));
|
||||
->with('goals', Goal::whereUserId(Auth::user()->id)->get());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -51,10 +42,7 @@ class GoalController extends Controller
|
|||
*/
|
||||
public function show(Goal $goal): View
|
||||
{
|
||||
return view('goals.show')
|
||||
->with('goal', $goal)
|
||||
->with('nameOptions', Goal::getNameOptions())
|
||||
->with('frequencyOptions', Goal::$frequencyOptions);
|
||||
return view('goals.show')->with('goal', $goal);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -62,10 +50,7 @@ class GoalController extends Controller
|
|||
*/
|
||||
public function edit(Goal $goal): View
|
||||
{
|
||||
return view('goals.edit')
|
||||
->with('goal', $goal)
|
||||
->with('nameOptions', Goal::getNameOptions())
|
||||
->with('frequencyOptions', Goal::$frequencyOptions);
|
||||
return view('goals.edit')->with('goal', $goal);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,63 +1,51 @@
|
|||
<x-app-layout>
|
||||
<x-slot name="title">My Goals - {{ $date->format('D, j M Y') }}</x-slot>
|
||||
<x-slot name="title">My Goals</x-slot>
|
||||
<x-slot name="header">
|
||||
<div class="flex justify-between items-center">
|
||||
<h1 class="leading-tight text-center">
|
||||
<div class="text-2xl font-semibold text-gray-800">My Goals</div>
|
||||
<div class="flex items-center space-x-2">
|
||||
<div>
|
||||
<a class="text-gray-500 hover:text-gray-700 hover:border-gray-300"
|
||||
href="{{ route(Route::current()->getName(), ['date' => $date->copy()->subDay(1)->toDateString()]) }}">
|
||||
<svg class="w-6 h-6" 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 16zm.707-10.293a1 1 0 00-1.414-1.414l-3 3a1 1 0 000 1.414l3 3a1 1 0 001.414-1.414L9.414 11H13a1 1 0 100-2H9.414l1.293-1.293z" clip-rule="evenodd" />
|
||||
</svg>
|
||||
</a>
|
||||
</div>
|
||||
<div class="text-base text-gray-500">
|
||||
<form x-data method="GET" action="{{ route('goals.index') }}">
|
||||
<x-inputs.input name="date"
|
||||
type="date"
|
||||
class="border-0 shadow-none p-0 text-center"
|
||||
:value="$date->toDateString()"
|
||||
x-on:change="$el.submit();"
|
||||
required />
|
||||
</form>
|
||||
</div>
|
||||
<div>
|
||||
<a class="text-gray-500 hover:text-gray-700 hover:border-gray-300"
|
||||
href="{{ route(Route::current()->getName(), ['date' => $date->copy()->addDay(1)->toDateString()]) }}">
|
||||
<svg class="w-6 h-6" 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 16zm3.707-8.707l-3-3a1 1 0 00-1.414 1.414L10.586 9H7a1 1 0 100 2h3.586l-1.293 1.293a1 1 0 101.414 1.414l3-3a1 1 0 000-1.414z" clip-rule="evenodd" />
|
||||
</svg>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</h1>
|
||||
<h1 class="font-semibold text-2xl text-gray-800 leading-tight">My Goals</h1>
|
||||
<x-button-link.green href="{{ route('goals.create') }}" class="text-sm">
|
||||
Add Goal
|
||||
</x-button-link.green>
|
||||
</div>
|
||||
</x-slot>
|
||||
<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">
|
||||
<path d="M17.414 2.586a2 2 0 00-2.828 0L7 10.172V13h2.828l7.586-7.586a2 2 0 000-2.828z" />
|
||||
<path fill-rule="evenodd" d="M2 6a2 2 0 012-2h4a1 1 0 010 2H4v10h10v-4a1 1 0 112 0v4a2 2 0 01-2 2H4a2 2 0 01-2-2V6z" clip-rule="evenodd" />
|
||||
</svg>
|
||||
</a>
|
||||
<a class="text-red-500 hover:text-red-700 hover:border-red-300 text-sm"
|
||||
href="{{ route('goals.delete', $goal) }}">
|
||||
<svg class="h-6 w-6" 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>
|
||||
</a>
|
||||
<div class="text-lg font-bold">{{ $goal->summary }}</div>
|
||||
</div>
|
||||
@empty
|
||||
<div>No goals set.</div>
|
||||
@endforelse
|
||||
</div>
|
||||
<table class="min-w-max w-full table-auto">
|
||||
<thead>
|
||||
<tr class="bg-gray-200 text-gray-600 uppercase text-sm leading-normal">
|
||||
<th class="py-3 px-6 text-left">Name</th>
|
||||
<th class="py-3 px-6 text-left">From</th>
|
||||
<th class="py-3 px-6 text-left">To</th>
|
||||
<th class="py-3 px-6 text-left">Days of Week</th>
|
||||
<th class="py-3 px-6 text-left">Goals</th>
|
||||
<th class="py-3 px-6 text-left"> </th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach($goals as $goal)
|
||||
<tr class="border-b border-gray-200">
|
||||
<td class="py-3 px-6">{{ $goal->name }}</td>
|
||||
<td class="py-3 px-6">{{ $goal->from }}</td>
|
||||
<td class="py-3 px-6">{{ $goal->to }}</td>
|
||||
<td class="py-3 px-6">{{ $goal->days }}</td>
|
||||
<td class="py-3 px-6">
|
||||
Calories: {{ $goal->calories }}<br />
|
||||
Carbohydrates: {{ $goal->carbohydrates }}<br />
|
||||
Cholesterol: {{ $goal->cholesterol }}<br />
|
||||
Fat: {{ $goal->fat }}<br />
|
||||
Protein: {{ $goal->Protein }}<br />
|
||||
Sodium: {{ $goal->sodium }}<br />
|
||||
</td>
|
||||
<td class="py-3 px-6">
|
||||
<div class="flex space-x-2 justify-end">
|
||||
<x-button-link.gray href="{{ route('goals.edit', $goal) }}">
|
||||
Edit
|
||||
</x-button-link.gray>
|
||||
<x-button-link.red href="{{ route('goals.delete', $goal) }}">
|
||||
Delete
|
||||
</x-button-link.red>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
</x-app-layout>
|
||||
|
|
Loading…
Reference in New Issue