mirror of https://github.com/kcal-app/kcal.git
Add ability to delete journal entries
This commit is contained in:
parent
195ca1648d
commit
9a60dbbe6e
|
@ -195,13 +195,22 @@ class JournalEntryController extends Controller
|
|||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\JournalEntry $journalEntry
|
||||
* @return \Illuminate\Http\Response
|
||||
* Confirm removal of the specified resource.
|
||||
*/
|
||||
public function destroy(JournalEntry $journalEntry)
|
||||
public function delete(JournalEntry $journalEntry): View
|
||||
{
|
||||
//
|
||||
return view('journal-entries.delete')->with('entry', $journalEntry);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(JournalEntry $journalEntry): RedirectResponse
|
||||
{
|
||||
$journalEntry->delete();
|
||||
session()->flash('message', 'Journal entry deleted!');
|
||||
return redirect(route('journal-entries.index', [
|
||||
'date' => $journalEntry->date->toDateString()
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,11 @@ class Nutrients
|
|||
return $amount;
|
||||
}
|
||||
|
||||
if (empty($fromUnit) || $food->serving_unit === $fromUnit) {
|
||||
if (
|
||||
empty($fromUnit)
|
||||
|| empty($food->serving_unit)
|
||||
|| $food->serving_unit === $fromUnit
|
||||
) {
|
||||
$multiplier = 1;
|
||||
}
|
||||
elseif ($fromUnit === 'tsp') {
|
||||
|
|
|
@ -12,9 +12,9 @@
|
|||
<div class="grid grid-cols-3 gap-4">
|
||||
@foreach ($foods as $food)
|
||||
<div class="p-2 font-light rounded-t border-2 border-gray-400">
|
||||
<a class="text-gray-500 hover:text-gray-700 hover:border-gray-300 float-right text-sm"
|
||||
<a class="h-6 w-6 text-gray-500 hover:text-gray-700 hover:border-gray-300 float-right text-sm"
|
||||
href="{{ route('foods.edit', $food) }}">
|
||||
<svg class="h-6 w-6" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
|
||||
<svg 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>
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
<x-app-layout>
|
||||
<x-slot name="header">
|
||||
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
|
||||
Delete {{ $entry->summary }}?
|
||||
</h2>
|
||||
</x-slot>
|
||||
|
||||
<div class="py-12">
|
||||
<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">
|
||||
<form method="POST" action="{{ route('journal-entries.destroy', $entry) }}">
|
||||
@method('delete')
|
||||
@csrf
|
||||
<div class="text-lg">Are you sure what to delete this journal entry?</div>
|
||||
<div class="flex flex-col space-y-2 mt-4 mb-4 text-lg">
|
||||
<div>
|
||||
<span class="font-bold">Summay:</span>
|
||||
<span>{{ $entry->summary }}</span>
|
||||
</div>
|
||||
<div>
|
||||
<span class="font-bold">Date:</span>
|
||||
<span>{{ $entry->date->format('D, j M Y') }}</span>
|
||||
</div>
|
||||
<div>
|
||||
<span class="font-bold">Meal:</span>
|
||||
<span>{{ $entry->meal }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<x-inputs.button class="bg-red-800 hover:bg-red-700">
|
||||
Yes, delete
|
||||
</x-inputs.button>
|
||||
<a class="ml-3 text-gray-500 hover:text-gray-700 hover:border-gray-300"
|
||||
href="{{ route('journal-entries.index') }}">No, do not delete</a>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</x-app-layout>
|
|
@ -49,6 +49,14 @@
|
|||
<details>
|
||||
<summary>{{ $entry->summary }}</summary>
|
||||
<div class="border-blue-100 border-2 p-2 ml-4">
|
||||
<div class="float-right">
|
||||
<a class="h-6 w-6 text-red-500 hover:text-red-700 hover:border-red-300 float-right text-sm"
|
||||
href="{{ route('journal-entries.delete', $entry) }}">
|
||||
<svg 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>
|
||||
<div>
|
||||
<span class="font-bold">nutrients:</span>
|
||||
@foreach($nutrients as $nutrient)
|
||||
|
|
|
@ -30,5 +30,8 @@ Route::get('/foods/{food}/delete', [FoodController::class, 'delete'])
|
|||
->name('foods.delete');
|
||||
Route::resource('recipes', RecipeController::class)->middleware(['auth']);
|
||||
Route::resource('journal-entries', JournalEntryController::class)->middleware(['auth']);
|
||||
Route::get('/journal-entries/{journalEntry}/delete', [JournalEntryController::class, 'delete'])
|
||||
->middleware(['auth'])
|
||||
->name('journal-entries.delete');
|
||||
|
||||
require __DIR__.'/auth.php';
|
||||
|
|
Loading…
Reference in New Issue