Compare commits

..

1 Commits

Author SHA1 Message Date
albert
9862396145 all info for admins
All checks were successful
Build, push and deploy / builds (push) Successful in 5s
2024-11-08 18:49:32 +01:00
3 changed files with 19 additions and 139 deletions

View File

@ -1,69 +0,0 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Fault;
class FaultController extends Controller
{
public function index()
{
$faults = Fault::all();
$test = 'hola que tal?';
$colors = [
'open' => '#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');
}
}

View File

@ -5,8 +5,6 @@
</h2> </h2>
</x-slot> </x-slot>
<h1>{{ $test }}</h1>
<div class="py-12"> <div class="py-12">
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8"> <div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
<div class="overflow-x-auto py-4"> <div class="overflow-x-auto py-4">
@ -20,7 +18,6 @@
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Ciutat</th> <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Ciutat</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Telefon</th> <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Telefon</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Google Maps</th> <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Google Maps</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Actions</th>
</tr> </tr>
</thead> </thead>
<tbody class="bg-white divide-y divide-gray-200"> <tbody class="bg-white divide-y divide-gray-200">
@ -29,14 +26,13 @@
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">{{ $fault->id }}</td> <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">{{ $fault->id }}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">{{ $fault->contact_name }}</td> <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">{{ $fault->contact_name }}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">{{ $fault->address }}</td> <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">{{ $fault->address }}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm font-bold " style="background: {{ $colors[$fault->status] ?? 'white' }};"> <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">{{ $fault->status }}</td>
{{ $fault->status }} <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">{{ $fault->city }}</td>
</td> <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">{{ $fault->city }}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">{{ $fault->contact_phone }}</td> <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">{{ $fault->contact_phone }}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">{{ $fault->google_maps_link }}</td> <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">{{ $fault->google_maps_link }}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500"> <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
<a href="{{ route('dashboard.openModal', $fault->id) }}" class="text-indigo-600 hover:text-indigo-900">Edit</a> <button class="text-indigo-600 hover:text-indigo-900">Edit</button>
<button class="text-red-600 hover:text-red-900 ml-4">Delete</button> <button class="text-red-600 hover:text-red-900 ml-4">Delete</button>
</td> </td>
</tr> </tr>
@ -47,48 +43,4 @@
</div> </div>
</div> </div>
<!-- Modal -->
<!-- Modal -->
@if($isModalOpen)
<div class="fixed inset-0 flex justify-center items-center bg-slate-200 bg-opacity-90 ">
<form action="{{ route('dashboard.updateStatus', $modalData->id) }}" method="POST">
@csrf
@method('PATCH')
<div class="bg-white p-6 rounded-lg flex flex-col justify-center gap-3">
<h3 class="text-xl">Fault Details</h3>
<div class="border-t border-gray-300 my-4"></div>
<p>ID: {{ $modalData->id }}</p>
<p>Name: {{ $modalData->contact_name }}</p>
<p>Address: {{ $modalData->address }}</p>
<div class="flex justify-around items-center gap-2">
<p>Status:</p>
<select name="status" class="border-gray-300 rounded-md p-0" >
<option class="mx-6" value="open" {{ $modalData->status == 'open' ? 'selected' : '' }}>Open</option>
<option class="mx-6" value="in_progress" {{ $modalData->status == 'in_progress' ? 'selected' : '' }}>In Progress</option>
<option class="mx-6" value="resolved" {{ $modalData->status == 'resolved' ? 'selected' : '' }}>Resolved</option>
</select>
</div>
<p>City: {{ $modalData->city }}</p>
<p>Phone: {{ $modalData->contact_phone }}</p>
<p>Google Maps: <a href="{{ $modalData->google_maps_link }}" target="_blank">{{ $modalData->google_maps_link }}</a></p>
<div class="border-t border-gray-300 my-4"></div>
<div
class="flex justify-between items-center mt-4"
>
<a href="{{ route('dashboard.closeModal') }}" class="text-red-600 hover:text-red-900">Close</a>
<button type="submit" class="text-blue-500 hover:text-blue-700">Update Status</button>
</div>
</div>
</form>
</div>
@endif
</x-app-layout> </x-app-layout>

View File

@ -1,6 +1,5 @@
<?php <?php
use App\Http\Controllers\FaultController;
use App\Http\Controllers\ProfileController; use App\Http\Controllers\ProfileController;
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
@ -23,12 +22,10 @@
return view('dashboard.users', compact('users')); return view('dashboard.users', compact('users'));
})->name('dashboard.users'); })->name('dashboard.users');
Route::get('/dashboard/faults', function () {
Route::get('/dashboard/faults', [FaultController::class, 'index'])->name('dashboard.faults'); $faults = \App\Models\Fault::all();
Route::get('/dashboard/faults/open-modal/{id}', [FaultController::class, 'openModal'])->name('dashboard.openModal'); return view('dashboard.faults', compact('faults'));
Route::get('/dashboard/faults/close-modal', [FaultController::class, 'closeModal'])->name('dashboard.closeModal'); })->name('dashboard.faults');
Route::patch('/dashboard/faults/{id}/update-status', [FaultController::class, 'updateStatus'])->name('dashboard.updateStatus');
Route::middleware('auth')->group(function () { Route::middleware('auth')->group(function () {
Route::get('/profile', [ProfileController::class, 'edit'])->name('profile.edit'); Route::get('/profile', [ProfileController::class, 'edit'])->name('profile.edit');