Files
mesreleves-php/resources/views/lieux/index.blade.php
T
yann64 aaf0fc2cd9 Import/export CSV des lieux
Export (GET lieux/export/csv) :
- Colonnes : nom, code, type, lieu_parent (nom_long), latitude, longitude, note
- BOM UTF-8, séparateur point-virgule

Import (GET/POST lieux/import) :
- Correspondance par nom de colonne (colonne nom obligatoire)
- Résolution du parent par nom_long exact
- Résolution du type par nom exact
- Détection automatique du séparateur ; ou ,
- nom_long recalculé automatiquement par le modèle

Boutons ↓ CSV, ↑ Importer CSV et + Nouveau lieu dans la liste des lieux.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-05 20:06:46 +02:00

161 lines
9.2 KiB
PHP

<x-app-layout>
<x-slot name="header">
<div class="flex items-center justify-between">
<h2 class="text-xl font-semibold text-gray-800 dark:text-gray-200">Lieux</h2>
<div class="flex items-center gap-2">
<a href="{{ route('lieux.export.csv') }}"
class="px-4 py-2 bg-white dark:bg-gray-800 border border-gray-300 dark:border-gray-600 text-gray-700 dark:text-gray-300 text-sm rounded-md hover:bg-gray-50 dark:hover:bg-gray-700">
CSV
</a>
@can('create', App\Models\Lieu::class)
<a href="{{ route('lieux.import.create') }}"
class="px-4 py-2 bg-white dark:bg-gray-800 border border-gray-300 dark:border-gray-600 text-gray-700 dark:text-gray-300 text-sm rounded-md hover:bg-gray-50 dark:hover:bg-gray-700">
Importer CSV
</a>
<a href="{{ route('lieux.create') }}"
class="px-4 py-2 bg-indigo-600 text-white text-sm rounded-md hover:bg-indigo-700">
+ Nouveau lieu
</a>
@endcan
</div>
</div>
</x-slot>
<div class="py-8 max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 space-y-6">
@if(session('success'))
<div class="p-4 bg-green-50 dark:bg-green-900/30 border border-green-200 dark:border-green-700 text-green-800 dark:text-green-200 rounded-md">{{ session('success') }}</div>
@endif
@if(session('error'))
<div class="p-4 bg-red-50 dark:bg-red-900/30 border border-red-200 dark:border-red-700 text-red-800 dark:text-red-200 rounded-md">{{ session('error') }}</div>
@endif
{{-- Filtres --}}
@php $hasFilters = request()->anyFilled(['lieu_type_id', 'q', 'lieu_id']); @endphp
<div class="bg-white dark:bg-gray-800 shadow rounded-lg p-5">
<form method="GET" action="{{ route('lieux.index') }}">
<div class="flex flex-wrap items-end gap-4">
<div class="flex-1 min-w-[200px]">
<label class="block text-xs font-medium text-gray-600 dark:text-gray-400 mb-1">Recherche</label>
<input type="text" name="q" value="{{ request('q') }}"
placeholder="Nom, code INSEE…"
class="block w-full rounded-md border-gray-300 dark:border-gray-600 shadow-sm text-sm focus:border-indigo-500 focus:ring-indigo-500">
</div>
<div class="w-52">
<label class="block text-xs font-medium text-gray-600 dark:text-gray-400 mb-1">Type de lieu</label>
<select name="lieu_type_id"
class="block w-full rounded-md border-gray-300 dark:border-gray-600 shadow-sm text-sm focus:border-indigo-500 focus:ring-indigo-500">
<option value=""> Tous les types </option>
@foreach($lieuTypes as $lt)
<option value="{{ $lt->id }}" {{ request('lieu_type_id') == $lt->id ? 'selected' : '' }}>
{{ $lt->nom }}
</option>
@endforeach
</select>
</div>
<div class="flex items-center gap-3 self-end">
<button type="submit"
class="px-5 py-2 bg-indigo-600 text-white text-sm font-medium rounded-md hover:bg-indigo-700">
Filtrer
</button>
@if($hasFilters)
<a href="{{ route('lieux.index') }}"
class="px-4 py-2 border border-gray-300 dark:border-gray-600 text-gray-600 dark:text-gray-400 text-sm rounded-md hover:bg-gray-50 dark:hover:bg-gray-700">
Effacer
</a>
<span class="inline-flex items-center px-2 py-0.5 rounded-full text-xs bg-indigo-100 dark:bg-indigo-900/50 text-indigo-700">
filtres actifs
</span>
@endif
</div>
</div>
{{-- Filtre par lieu parent --}}
<div class="mt-4 max-w-sm">
<x-lieu-picker
name="lieu_id"
label="Lieu (et ses subdivisions)"
:value="request('lieu_id')"
:display-value="$lieuSelectionne?->nom_long ?? $lieuSelectionne?->nom ?? ''"
placeholder="— Tous les lieux —"
/>
</div>
</form>
</div>
{{-- Tableau --}}
<div class="bg-white dark:bg-gray-800 shadow rounded-lg overflow-hidden">
<table class="min-w-full divide-y divide-gray-200 dark:divide-gray-700">
<thead class="bg-gray-50 dark:bg-gray-700">
<tr>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider">Lieu</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider">Type</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider">Code</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider">Parent</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider">Coordonnées</th>
<th class="px-6 py-3"></th>
</tr>
</thead>
<tbody class="divide-y divide-gray-200 dark:divide-gray-700">
@forelse($lieux as $lieu)
<tr class="hover:bg-gray-50 dark:hover:bg-gray-700">
<td class="px-6 py-4">
<a href="{{ route('lieux.show', $lieu) }}" class="font-medium text-indigo-600 hover:underline">
{{ $lieu->nom }}
</a>
</td>
<td class="px-6 py-4 text-sm text-gray-500 dark:text-gray-400">{{ $lieu->lieuType?->nom ?? '—' }}</td>
<td class="px-6 py-4 text-sm text-gray-500 dark:text-gray-400">{{ $lieu->code ?? '—' }}</td>
<td class="px-6 py-4 text-sm text-gray-500 dark:text-gray-400">
@if($lieu->parent)
<a href="{{ route('lieux.show', $lieu->parent) }}" class="text-indigo-600 hover:underline">
{{ $lieu->parent->nom }}
</a>
@else
@endif
</td>
<td class="px-6 py-4 text-sm text-gray-500 dark:text-gray-400">
@if($lieu->latitude && $lieu->longitude)
{{ number_format($lieu->latitude, 4) }}, {{ number_format($lieu->longitude, 4) }}
@else
@endif
</td>
<td class="px-6 py-4 text-right text-sm space-x-3">
@can('update', $lieu)
<a href="{{ route('lieux.edit', $lieu) }}" class="text-gray-600 dark:text-gray-400 hover:text-indigo-600">Modifier</a>
@endcan
@can('delete', $lieu)
<form method="POST" action="{{ route('lieux.destroy', $lieu) }}" class="inline"
x-data
@submit.prevent="if(confirm('Supprimer ce lieu ?')) $el.submit()">
@csrf @method('DELETE')
<button type="submit" class="text-red-500 hover:text-red-700">Supprimer</button>
</form>
@endcan
</td>
</tr>
@empty
<tr>
<td colspan="6" class="px-6 py-10 text-center text-gray-400 dark:text-gray-500">
@if($hasFilters) Aucun lieu ne correspond aux filtres.
@else Aucun lieu enregistré. @endif
</td>
</tr>
@endforelse
</tbody>
</table>
@if($lieux->hasPages())
<div class="px-6 py-4 border-t border-gray-200 dark:border-gray-700">
{{ $lieux->links() }}
</div>
@endif
</div>
</div>
</x-app-layout>