Étape 10 : interface admin (tableau de bord + gestion utilisateurs)

- DashboardController : stats globales (sources par statut, relevés, utilisateurs, activité mensuelle 6 mois)
- UserController : liste filtrée (nom/email/rôle) + édition de rôle avec protections (auto-demotion, dernier admin)
- Vue admin/dashboard : compteurs par statut cliquables, graphique barres mensuel, sources à valider, relevés récents
- Vue admin/utilisateurs : liste paginée avec sections et sources assignées, page d'édition avec radio-cards
- Dashboard principal enrichi : bloc accès admin, mes sources assignées triées par urgence, mes derniers relevés
- Navigation : ajout Tableau de bord admin et Utilisateurs dans le menu Administration

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-04 17:21:50 +02:00
parent d064f8d28e
commit c790691200
8 changed files with 613 additions and 9 deletions
+139
View File
@@ -0,0 +1,139 @@
<x-app-layout>
<x-slot name="header">
<h2 class="text-xl font-semibold text-gray-800">Tableau de bord Administration</h2>
</x-slot>
<div class="py-8 max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 space-y-8">
{{-- Compteurs globaux --}}
<div class="grid grid-cols-2 md:grid-cols-4 gap-4">
@php
$statusCards = [
['label' => 'À faire', 'key' => 'a_faire', 'color' => 'bg-gray-50 border-gray-200 text-gray-700'],
['label' => 'En cours', 'key' => 'en_cours', 'color' => 'bg-blue-50 border-blue-200 text-blue-700'],
['label' => 'À valider', 'key' => 'a_valider', 'color' => 'bg-yellow-50 border-yellow-200 text-yellow-700'],
['label' => 'Terminé', 'key' => 'termine', 'color' => 'bg-green-50 border-green-200 text-green-700'],
];
@endphp
@foreach($statusCards as $card)
<a href="{{ route('sources.index', ['status' => $card['key']]) }}"
class="border rounded-xl p-5 flex flex-col gap-1 hover:shadow-md transition-shadow {{ $card['color'] }}">
<span class="text-3xl font-bold">{{ $sourcesByStatus[$card['key']] ?? 0 }}</span>
<span class="text-sm font-medium">{{ $card['label'] }}</span>
<span class="text-xs opacity-60">source{{ ($sourcesByStatus[$card['key']] ?? 0) > 1 ? 's' : '' }}</span>
</a>
@endforeach
</div>
{{-- Ligne de métriques secondaires --}}
<div class="grid grid-cols-3 gap-4">
<div class="bg-white border border-gray-200 rounded-xl p-5 flex items-center gap-4">
<div class="p-3 bg-indigo-100 rounded-lg">
<svg class="w-6 h-6 text-indigo-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/>
</svg>
</div>
<div>
<p class="text-2xl font-bold text-gray-900">{{ number_format($totalReleves) }}</p>
<p class="text-sm text-gray-500">relevé{{ $totalReleves > 1 ? 's' : '' }} saisi{{ $totalReleves > 1 ? 's' : '' }}</p>
</div>
</div>
<div class="bg-white border border-gray-200 rounded-xl p-5 flex items-center gap-4">
<div class="p-3 bg-purple-100 rounded-lg">
<svg class="w-6 h-6 text-purple-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0z"/>
</svg>
</div>
<div>
<p class="text-2xl font-bold text-gray-900">{{ $totalUsers }}</p>
<p class="text-sm text-gray-500">utilisateur{{ $totalUsers > 1 ? 's' : '' }}</p>
</div>
</div>
<div class="bg-white border border-gray-200 rounded-xl p-5">
<p class="text-xs font-medium text-gray-500 uppercase mb-3">Répartition des rôles</p>
<div class="space-y-2">
@foreach(\App\Enums\UserRole::cases() as $role)
@php $count = (int)($usersByRole[$role->value] ?? 0); @endphp
<div class="flex items-center justify-between text-sm">
<span class="text-gray-600">{{ $role->label() }}</span>
<span class="font-semibold text-gray-900">{{ $count }}</span>
</div>
@endforeach
</div>
</div>
</div>
{{-- Activité mensuelle (6 derniers mois) --}}
@if($activiteMensuelle->isNotEmpty())
<div class="bg-white border border-gray-200 rounded-xl p-6">
<h3 class="text-sm font-semibold text-gray-700 uppercase tracking-wide mb-4">Relevés saisis 6 derniers mois</h3>
@php $maxReleves = $activiteMensuelle->max('total') ?: 1; @endphp
<div class="flex items-end gap-3 h-24">
@foreach($activiteMensuelle as $mois)
@php $h = max(4, round(($mois->total / $maxReleves) * 96)); @endphp
<div class="flex-1 flex flex-col items-center gap-1">
<span class="text-xs text-gray-500">{{ $mois->total }}</span>
<div class="w-full bg-indigo-500 rounded-t" style="height: {{ $h }}px" title="{{ $mois->mois }} : {{ $mois->total }}"></div>
<span class="text-xs text-gray-400 whitespace-nowrap">{{ $mois->mois }}</span>
</div>
@endforeach
</div>
</div>
@endif
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
{{-- Sources à valider --}}
<div class="bg-white border border-gray-200 rounded-xl p-6">
<div class="flex items-center justify-between mb-4">
<h3 class="text-sm font-semibold text-gray-700 uppercase tracking-wide">En attente de validation</h3>
<a href="{{ route('sources.index', ['status' => 'a_valider']) }}"
class="text-xs text-indigo-600 hover:underline">Voir tout</a>
</div>
@forelse($sourcesAValider as $source)
<div class="flex items-center justify-between py-2 border-b border-gray-100 last:border-0">
<div>
<a href="{{ route('sources.show', $source) }}"
class="text-sm font-medium text-indigo-600 hover:underline">{{ $source->nom }}</a>
<p class="text-xs text-gray-400">{{ $source->sourceType->nom }}</p>
</div>
<span class="text-xs text-gray-400 whitespace-nowrap">
{{ $source->updated_at->diffForHumans() }}
</span>
</div>
@empty
<p class="text-sm text-gray-400 py-4 text-center">Aucune source en attente.</p>
@endforelse
</div>
{{-- Relevés récents --}}
<div class="bg-white border border-gray-200 rounded-xl p-6">
<div class="flex items-center justify-between mb-4">
<h3 class="text-sm font-semibold text-gray-700 uppercase tracking-wide">Derniers relevés saisis</h3>
<a href="{{ route('recherche') }}" class="text-xs text-indigo-600 hover:underline">Recherche</a>
</div>
@forelse($relevesRecents as $releve)
<div class="flex items-center justify-between py-2 border-b border-gray-100 last:border-0">
<div class="min-w-0">
<a href="{{ route('releves.show', $releve) }}"
class="text-sm font-medium text-gray-900 hover:text-indigo-600 truncate block">
{{ $releve->nom ?? '—' }}
@if($releve->prenom) {{ $releve->prenom }} @endif
</a>
<p class="text-xs text-gray-400">
{{ $releve->source->nom }} · {{ $releve->createur?->name ?? '?' }}
</p>
</div>
<span class="text-xs text-gray-400 whitespace-nowrap ml-3">
{{ $releve->created_at->diffForHumans() }}
</span>
</div>
@empty
<p class="text-sm text-gray-400 py-4 text-center">Aucun relevé pour l'instant.</p>
@endforelse
</div>
</div>
</div>
</x-app-layout>
@@ -0,0 +1,82 @@
<x-app-layout>
<x-slot name="header">
<div class="flex items-center gap-3">
<a href="{{ route('admin.utilisateurs.index') }}" class="text-sm text-indigo-600 hover:underline"> Utilisateurs</a>
<span class="text-gray-400">/</span>
<h2 class="text-xl font-semibold text-gray-800">{{ $user->name }}</h2>
</div>
</x-slot>
<div class="py-8 max-w-2xl mx-auto px-4 sm:px-6 lg:px-8 space-y-6">
@if(session('success'))
<div class="p-4 bg-green-50 border border-green-200 text-green-800 rounded-md">{{ session('success') }}</div>
@endif
@if(session('error'))
<div class="p-4 bg-red-50 border border-red-200 text-red-800 rounded-md">{{ session('error') }}</div>
@endif
{{-- Informations --}}
<div class="bg-white shadow rounded-lg p-6 space-y-3">
<h3 class="text-sm font-semibold text-gray-700 uppercase tracking-wide">Informations</h3>
<dl class="grid grid-cols-2 gap-x-6 gap-y-3 text-sm">
<dt class="text-gray-500">Nom</dt>
<dd class="text-gray-900 font-medium">{{ $user->name }}</dd>
<dt class="text-gray-500">E-mail</dt>
<dd class="text-gray-900">{{ $user->email }}</dd>
<dt class="text-gray-500">Inscrit le</dt>
<dd class="text-gray-900">{{ $user->created_at->format('d/m/Y') }}</dd>
<dt class="text-gray-500">Sections</dt>
<dd class="text-gray-900">
@if($user->sections->isNotEmpty())
{{ $user->sections->pluck('nom')->join(', ') }}
@else
@endif
</dd>
<dt class="text-gray-500">Sources assignées</dt>
<dd class="text-gray-900">{{ $user->sourcesAssignees->count() }}</dd>
</dl>
</div>
{{-- Modifier le rôle --}}
<div class="bg-white shadow rounded-lg p-6">
<h3 class="text-sm font-semibold text-gray-700 uppercase tracking-wide mb-4">Rôle</h3>
<form method="POST" action="{{ route('admin.utilisateurs.update', $user) }}">
@csrf @method('PUT')
<div class="space-y-3">
@foreach(\App\Enums\UserRole::cases() as $role)
<label class="flex items-start gap-3 p-3 border rounded-lg cursor-pointer hover:bg-gray-50
{{ $user->role === $role ? 'border-indigo-400 bg-indigo-50' : 'border-gray-200' }}">
<input type="radio" name="role" value="{{ $role->value }}"
{{ $user->role === $role ? 'checked' : '' }}
class="mt-0.5 text-indigo-600">
<div>
<p class="text-sm font-medium text-gray-900">{{ $role->label() }}</p>
<p class="text-xs text-gray-500 mt-0.5">
@if($role === \App\Enums\UserRole::Admin)
Accès complet : gestion des utilisateurs, sections, dépôts, types de sources et statistiques.
@elseif($role === \App\Enums\UserRole::SectionManager)
Peut créer des sources, assigner des membres et valider les relevés de sa section.
@else
Peut saisir des relevés sur les sources auxquelles il est assigné.
@endif
</p>
</div>
</label>
@endforeach
</div>
<div class="mt-5 flex gap-4">
<button type="submit"
class="px-5 py-2 bg-indigo-600 text-white text-sm font-medium rounded-md hover:bg-indigo-700">
Enregistrer
</button>
<a href="{{ route('admin.utilisateurs.index') }}"
class="text-sm text-gray-500 self-center hover:text-gray-700">
Annuler
</a>
</div>
</form>
</div>
</div>
</x-app-layout>
@@ -0,0 +1,116 @@
<x-app-layout>
<x-slot name="header">
<h2 class="text-xl font-semibold text-gray-800">Gestion des utilisateurs</h2>
</x-slot>
<div class="py-8 max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 space-y-6">
{{-- Filtres --}}
@php $hasFilters = request()->anyFilled(['role', 'q']); @endphp
<div class="bg-white shadow rounded-lg p-5">
<form method="GET" action="{{ route('admin.utilisateurs.index') }}" 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 mb-1">Recherche</label>
<input type="text" name="q" value="{{ request('q') }}"
placeholder="Nom ou e-mail…"
class="block w-full rounded-md border-gray-300 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 mb-1">Rôle</label>
<select name="role"
class="block w-full rounded-md border-gray-300 shadow-sm text-sm focus:border-indigo-500 focus:ring-indigo-500">
<option value=""> Tous </option>
@foreach(\App\Enums\UserRole::cases() as $r)
<option value="{{ $r->value }}" {{ request('role') === $r->value ? 'selected' : '' }}>
{{ $r->label() }}
</option>
@endforeach
</select>
</div>
<div class="flex items-center gap-3">
<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('admin.utilisateurs.index') }}"
class="px-4 py-2 border border-gray-300 text-gray-600 text-sm rounded-md hover:bg-gray-50">
Effacer
</a>
@endif
</div>
</form>
</div>
{{-- Tableau --}}
<div class="bg-white shadow rounded-lg overflow-hidden">
<table class="min-w-full divide-y divide-gray-200 text-sm">
<thead class="bg-gray-50">
<tr>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Nom</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">E-mail</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Rôle</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Sections</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Sources assignées</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Inscrit le</th>
<th class="px-6 py-3"></th>
</tr>
</thead>
<tbody class="divide-y divide-gray-200">
@forelse($users as $user)
@php
$roleColors = [
'admin' => 'bg-red-100 text-red-700',
'section_manager' => 'bg-blue-100 text-blue-700',
'member' => 'bg-gray-100 text-gray-600',
];
$color = $roleColors[$user->role->value] ?? 'bg-gray-100 text-gray-600';
@endphp
<tr class="hover:bg-gray-50">
<td class="px-6 py-4 font-medium text-gray-900">
{{ $user->name }}
@if($user->id === auth()->id())
<span class="ml-1 text-xs text-gray-400">(vous)</span>
@endif
</td>
<td class="px-6 py-4 text-gray-500">{{ $user->email }}</td>
<td class="px-6 py-4">
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium {{ $color }}">
{{ $user->role->label() }}
</span>
</td>
<td class="px-6 py-4 text-gray-500">
@if($user->sections->isNotEmpty())
{{ $user->sections->pluck('nom')->join(', ') }}
@else
@endif
</td>
<td class="px-6 py-4 text-gray-500">{{ $user->sources_assignees_count ?: '—' }}</td>
<td class="px-6 py-4 text-gray-500 whitespace-nowrap">
{{ $user->created_at->format('d/m/Y') }}
</td>
<td class="px-6 py-4 text-right">
@if($user->id !== auth()->id())
<a href="{{ route('admin.utilisateurs.edit', $user) }}"
class="text-indigo-600 hover:underline text-sm">
Modifier
</a>
@endif
</td>
</tr>
@empty
<tr>
<td colspan="7" class="px-6 py-10 text-center text-gray-400">
Aucun utilisateur trouvé.
</td>
</tr>
@endforelse
</tbody>
</table>
@if($users->hasPages())
<div class="px-6 py-4 border-t">{{ $users->links() }}</div>
@endif
</div>
</div>
</x-app-layout>