From a009c34bcdebc610720e5575a3e60919eb3c314e Mon Sep 17 00:00:00 2001 From: Pedro Losas Date: Sat, 9 Nov 2024 19:35:22 +0100 Subject: [PATCH] test:eit-status-fault handle edit status fault and create modal --- app/Http/Controllers/FaultController.php | 69 +++++++++++++++++++ resources/views/dashboard/faults.blade.php | 78 +++++++++++++++++----- routes/web.php | 11 +-- 3 files changed, 139 insertions(+), 19 deletions(-) create mode 100644 app/Http/Controllers/FaultController.php diff --git a/app/Http/Controllers/FaultController.php b/app/Http/Controllers/FaultController.php new file mode 100644 index 0000000..09d7e98 --- /dev/null +++ b/app/Http/Controllers/FaultController.php @@ -0,0 +1,69 @@ + '#8cf5a8', + 'in_progress' => '#f3f58c', + 'resolved' => '#8cdaf5', + ]; + $modalData = session('modalData', null); + $isModalOpen = session('isModalOpen', false); + $updateStatus = session('updateStatus', false); + + return view('dashboard.faults', compact('faults', 'test', 'modalData', 'isModalOpen','updateStatus', 'colors')); + } + + public function openModal($id) + { + // Obtener los datos de la avería desde la base de datos + $fault = Fault::find($id); + + // Guardar el estado del modal y la información en la sesión + session([ + 'modalData' => $fault, + 'isModalOpen' => true + ]); + + return redirect()->route('dashboard.faults'); + } + + public function closeModal() + { + // Cerrar el modal al limpiar la sesión + session([ + 'isModalOpen' => false, + 'modalData' => null + ]); + + return redirect()->route('dashboard.faults'); + } + + public function updateStatus(Request $request, $id) + { + // Validar los datos del formulario + $request->validate([ + 'status' => 'required|in:open,in_progress,resolved' + ]); + + + $fault = Fault::find($id); + $fault->status = $request->status; + $fault->save(); + $this->closeModal(); + + return redirect()->route('dashboard.faults'); + } +} diff --git a/resources/views/dashboard/faults.blade.php b/resources/views/dashboard/faults.blade.php index c16e2e2..4ccf943 100644 --- a/resources/views/dashboard/faults.blade.php +++ b/resources/views/dashboard/faults.blade.php @@ -4,6 +4,8 @@ {{ __('Averías') }} + +

{{ $test }}

@@ -18,29 +20,75 @@ Ciutat Telefon Google Maps + Actions - @foreach ($faults as $fault) - - {{ $fault->id }} - {{ $fault->contact_name }} - {{ $fault->address }} - {{ $fault->status }} - {{ $fault->city }} - {{ $fault->contact_phone }} - {{ $fault->google_maps_link }} + @foreach ($faults as $fault) + + {{ $fault->id }} + {{ $fault->contact_name }} + {{ $fault->address }} + + {{ $fault->status }} + {{ $fault->city }} + {{ $fault->contact_phone }} + {{ $fault->google_maps_link }} - - - - - - @endforeach + + Edit + + + + @endforeach
+ + +@if($isModalOpen) +
+
+ @csrf + @method('PATCH') +
+

Fault Details

+
+ +

ID: {{ $modalData->id }}

+

Name: {{ $modalData->contact_name }}

+

Address: {{ $modalData->address }}

+
+

Status:

+ + +
+ +

City: {{ $modalData->city }}

+

Phone: {{ $modalData->contact_phone }}

+

Google Maps: {{ $modalData->google_maps_link }}

+ + +
+
+ Close + + +
+ +
+
+
+@endif + + diff --git a/routes/web.php b/routes/web.php index f43fffe..9c88555 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,5 +1,6 @@ name('dashboard.users'); -Route::get('/dashboard/faults', function () { - $faults = \App\Models\Fault::all(); - return view('dashboard.faults', compact('faults')); -})->name('dashboard.faults'); + +Route::get('/dashboard/faults', [FaultController::class, 'index'])->name('dashboard.faults'); +Route::get('/dashboard/faults/open-modal/{id}', [FaultController::class, 'openModal'])->name('dashboard.openModal'); +Route::get('/dashboard/faults/close-modal', [FaultController::class, 'closeModal'])->name('dashboard.closeModal'); +Route::patch('/dashboard/faults/{id}/update-status', [FaultController::class, 'updateStatus'])->name('dashboard.updateStatus'); + Route::middleware('auth')->group(function () { Route::get('/profile', [ProfileController::class, 'edit'])->name('profile.edit');