Compare commits
2 Commits
main
...
test/edit-
Author | SHA1 | Date | |
---|---|---|---|
a009c34bcd | |||
3fe67fa1fe |
69
app/Http/Controllers/FaultController.php
Normal file
69
app/Http/Controllers/FaultController.php
Normal file
@ -0,0 +1,69 @@
|
||||
<?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');
|
||||
}
|
||||
}
|
@ -5,42 +5,90 @@
|
||||
</h2>
|
||||
</x-slot>
|
||||
|
||||
<h1>{{ $test }}</h1>
|
||||
|
||||
<div class="py-12">
|
||||
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
|
||||
<div class="overflow-x-auto py-4">
|
||||
<table class="min-w-full table-auto border-collapse">
|
||||
<thead>
|
||||
<tr>
|
||||
<!-- <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">ID</th> -->
|
||||
<!-- <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Name</th> -->
|
||||
<!-- <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Direcció</th> -->
|
||||
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">ID</th>
|
||||
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Name</th>
|
||||
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Direcció</th>
|
||||
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Status</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">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>
|
||||
</thead>
|
||||
<tbody class="bg-white divide-y divide-gray-200">
|
||||
@foreach ($faults as $fault)
|
||||
<tr>
|
||||
<!-- <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-500">{{ $fault->address }}</td> -->
|
||||
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">{{ $fault->status }}</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->google_maps_link }}</td> -->
|
||||
@foreach ($faults as $fault)
|
||||
<tr>
|
||||
<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-500">{{ $fault->address }}</td>
|
||||
<td class="px-6 py-4 whitespace-nowrap text-sm font-bold " style="background: {{ $colors[$fault->status] ?? 'white' }};">
|
||||
{{ $fault->status }}
|
||||
</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->google_maps_link }}</td>
|
||||
|
||||
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
|
||||
<button class="text-indigo-600 hover:text-indigo-900">Edit</button>
|
||||
<button class="text-red-600 hover:text-red-900 ml-4">Delete</button>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
<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-red-600 hover:text-red-900 ml-4">Delete</button>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
</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>
|
||||
|
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
use App\Http\Controllers\FaultController;
|
||||
use App\Http\Controllers\ProfileController;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
@ -22,10 +23,12 @@
|
||||
return view('dashboard.users', compact('users'));
|
||||
})->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');
|
||||
|
Loading…
Reference in New Issue
Block a user