dbf0465b0a
Utilisateurs actifs/inactifs : - Migration : colonne is_active (boolean, default true) sur users - Middleware EnsureUserIsActive : déconnecte les utilisateurs désactivés sur chaque requête - LoginRequest : bloque la connexion si is_active=false (message explicite) - Admin : bouton Activer/Désactiver dans la liste et la page d'édition Protections : impossible de désactiver son propre compte ou le dernier admin actif - Badge « Inactif » + opacité réduite sur la ligne dans la liste admin - Sélection de membres (sources) : filtre is_active=true Sources liées aux sections : - Migration : colonne section_id nullable FK sur sources - Source::section() BelongsTo + Section::sources() HasMany - Formulaire sources/_form : sélecteur de section (sections de l'utilisateur ou toutes pour admin) - SourceController : passe les sections disponibles aux vues create/edit Tableau de bord enrichi (DashboardController) : - Membres et responsables : stats par section (sources par statut, total relevés) compteurs cliquables → liste filtrée, sources récentes de la section - Mes sources assignées (tri par urgence) + mes derniers relevés (inchangés) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
212 lines
13 KiB
PHP
212 lines
13 KiB
PHP
<x-app-layout>
|
|
<x-slot name="header">
|
|
<h2 class="text-xl font-semibold text-gray-800">Tableau de bord</h2>
|
|
</x-slot>
|
|
|
|
<div class="py-8 max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 space-y-8">
|
|
|
|
@php $user = auth()->user(); @endphp
|
|
|
|
{{-- Bloc admin : lien vers le dashboard admin --}}
|
|
@if($user->isAdmin())
|
|
<div class="bg-indigo-50 border border-indigo-200 rounded-xl p-5 flex items-center justify-between">
|
|
<div>
|
|
<p class="text-sm font-semibold text-indigo-800">Accès administrateur</p>
|
|
<p class="text-xs text-indigo-600 mt-0.5">Statistiques globales, gestion des utilisateurs et des sections.</p>
|
|
</div>
|
|
<a href="{{ route('admin.dashboard') }}"
|
|
class="px-4 py-2 bg-indigo-600 text-white text-sm font-medium rounded-md hover:bg-indigo-700">
|
|
Tableau de bord admin →
|
|
</a>
|
|
</div>
|
|
@endif
|
|
|
|
{{-- ── Stats de section (membres et responsables) ───────────────────── --}}
|
|
@if($sectionsStats && $sectionsStats->isNotEmpty())
|
|
@foreach($sectionsStats as $stat)
|
|
@php
|
|
$statusColors = [
|
|
'a_faire' => ['bg' => 'bg-gray-100', 'text' => 'text-gray-700'],
|
|
'en_cours' => ['bg' => 'bg-blue-100', 'text' => 'text-blue-700'],
|
|
'a_valider' => ['bg' => 'bg-yellow-100', 'text' => 'text-yellow-700'],
|
|
'termine' => ['bg' => 'bg-green-100', 'text' => 'text-green-700'],
|
|
];
|
|
$statusLabels = [
|
|
'a_faire' => 'À faire',
|
|
'en_cours' => 'En cours',
|
|
'a_valider' => 'À valider',
|
|
'termine' => 'Terminé',
|
|
];
|
|
@endphp
|
|
<div class="space-y-4">
|
|
<h3 class="text-base font-semibold text-gray-800 flex items-center gap-2">
|
|
<span>Section — {{ $stat['section']->nom }}</span>
|
|
@if($user->isManagerOfSection($stat['section']))
|
|
<span class="text-xs px-2 py-0.5 bg-blue-100 text-blue-700 rounded-full">Responsable</span>
|
|
@endif
|
|
</h3>
|
|
|
|
{{-- Compteurs par statut --}}
|
|
<div class="grid grid-cols-2 sm:grid-cols-4 gap-3">
|
|
@foreach($stat['by_status'] as $statusVal => $count)
|
|
@php $c = $statusColors[$statusVal] ?? ['bg' => 'bg-gray-100', 'text' => 'text-gray-700']; @endphp
|
|
<a href="{{ route('sources.index', ['status' => $statusVal]) }}"
|
|
class="rounded-xl border p-4 flex flex-col gap-1 hover:shadow-md transition-shadow
|
|
{{ $c['bg'] }} border-transparent">
|
|
<span class="text-2xl font-bold {{ $c['text'] }}">{{ $count }}</span>
|
|
<span class="text-xs font-medium {{ $c['text'] }}">{{ $statusLabels[$statusVal] ?? $statusVal }}</span>
|
|
<span class="text-xs opacity-60 {{ $c['text'] }}">source{{ $count > 1 ? 's' : '' }}</span>
|
|
</a>
|
|
@endforeach
|
|
</div>
|
|
|
|
{{-- Métriques globales section --}}
|
|
<div class="grid grid-cols-2 gap-4">
|
|
<div class="bg-white border border-gray-200 rounded-xl px-5 py-4 flex items-center gap-4">
|
|
<div class="p-2 bg-indigo-100 rounded-lg">
|
|
<svg class="w-5 h-5 text-indigo-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 8h14M5 8a2 2 0 110-4h14a2 2 0 110 4M5 8v10a2 2 0 002 2h10a2 2 0 002-2V8"/>
|
|
</svg>
|
|
</div>
|
|
<div>
|
|
<p class="text-xl font-bold text-gray-900">{{ $stat['total_sources'] }}</p>
|
|
<p class="text-xs text-gray-500">source{{ $stat['total_sources'] > 1 ? 's' : '' }} au total</p>
|
|
</div>
|
|
</div>
|
|
<div class="bg-white border border-gray-200 rounded-xl px-5 py-4 flex items-center gap-4">
|
|
<div class="p-2 bg-green-100 rounded-lg">
|
|
<svg class="w-5 h-5 text-green-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-xl font-bold text-gray-900">{{ number_format($stat['total_releves']) }}</p>
|
|
<p class="text-xs text-gray-500">relevé{{ $stat['total_releves'] > 1 ? 's' : '' }} saisi{{ $stat['total_releves'] > 1 ? 's' : '' }}</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
{{-- Sources récentes de la section --}}
|
|
@if($stat['sources_recentes']->isNotEmpty())
|
|
<div class="bg-white border border-gray-200 rounded-xl p-5">
|
|
<p class="text-xs font-semibold text-gray-500 uppercase mb-3">Sources récentes</p>
|
|
<div class="divide-y divide-gray-100">
|
|
@foreach($stat['sources_recentes'] as $src)
|
|
@php
|
|
$sc = $statusColors[$src->status->value] ?? ['bg' => 'bg-gray-100', 'text' => 'text-gray-600'];
|
|
@endphp
|
|
<div class="flex items-center justify-between py-2.5">
|
|
<div class="min-w-0">
|
|
<a href="{{ route('sources.show', $src) }}"
|
|
class="text-sm font-medium text-indigo-600 hover:underline truncate block">
|
|
{{ $src->nom }}
|
|
</a>
|
|
<p class="text-xs text-gray-400">
|
|
{{ $src->sourceType->nom }} · {{ $src->releves_count }} relevé{{ $src->releves_count > 1 ? 's' : '' }}
|
|
</p>
|
|
</div>
|
|
<span class="ml-4 shrink-0 inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium {{ $sc['bg'] }} {{ $sc['text'] }}">
|
|
{{ $src->status->label() }}
|
|
</span>
|
|
</div>
|
|
@endforeach
|
|
</div>
|
|
</div>
|
|
@endif
|
|
</div>
|
|
@endforeach
|
|
@endif
|
|
|
|
{{-- ── Mes sources assignées ────────────────────────────────────────── --}}
|
|
@if($mesSources->isNotEmpty())
|
|
<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">Mes sources assignées</h3>
|
|
<a href="{{ route('sources.index') }}" class="text-xs text-indigo-600 hover:underline">Voir toutes</a>
|
|
</div>
|
|
<div class="overflow-x-auto">
|
|
<table class="min-w-full text-sm divide-y divide-gray-100">
|
|
<thead>
|
|
<tr>
|
|
<th class="pb-2 text-left text-xs font-medium text-gray-500 uppercase">Source</th>
|
|
<th class="pb-2 text-left text-xs font-medium text-gray-500 uppercase">Type</th>
|
|
<th class="pb-2 text-left text-xs font-medium text-gray-500 uppercase">Statut</th>
|
|
<th class="pb-2 text-left text-xs font-medium text-gray-500 uppercase">Relevés</th>
|
|
<th class="pb-2"></th>
|
|
</tr>
|
|
</thead>
|
|
<tbody class="divide-y divide-gray-50">
|
|
@foreach($mesSources as $source)
|
|
@php
|
|
$colors = [
|
|
'a_faire' => 'bg-gray-100 text-gray-600',
|
|
'en_cours' => 'bg-blue-100 text-blue-700',
|
|
'a_valider' => 'bg-yellow-100 text-yellow-700',
|
|
'termine' => 'bg-green-100 text-green-700',
|
|
];
|
|
$c = $colors[$source->status->value] ?? 'bg-gray-100 text-gray-600';
|
|
@endphp
|
|
<tr class="hover:bg-gray-50">
|
|
<td class="py-2.5 pr-4">
|
|
<a href="{{ route('sources.show', $source) }}"
|
|
class="font-medium text-indigo-600 hover:underline">{{ $source->nom }}</a>
|
|
</td>
|
|
<td class="py-2.5 pr-4 text-gray-500">{{ $source->sourceType->nom }}</td>
|
|
<td class="py-2.5 pr-4">
|
|
<span class="inline-flex px-2 py-0.5 rounded-full text-xs font-medium {{ $c }}">
|
|
{{ $source->status->label() }}
|
|
</span>
|
|
</td>
|
|
<td class="py-2.5 pr-4 text-gray-500">{{ $source->releves_count }}</td>
|
|
<td class="py-2.5 text-right">
|
|
<a href="{{ route('sources.releves.index', $source) }}"
|
|
class="text-xs text-indigo-600 hover:underline">Saisir →</a>
|
|
</td>
|
|
</tr>
|
|
@endforeach
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
@elseif(! $sectionsStats || $sectionsStats->isEmpty())
|
|
<div class="bg-white border border-gray-200 rounded-xl p-10 text-center text-gray-400">
|
|
<svg class="mx-auto w-10 h-10 mb-3 text-gray-300" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5"
|
|
d="M5 8h14M5 8a2 2 0 110-4h14a2 2 0 110 4M5 8v10a2 2 0 002 2h10a2 2 0 002-2V8"/>
|
|
</svg>
|
|
<p class="text-sm">Vous n'êtes assigné à aucune source pour l'instant.</p>
|
|
<a href="{{ route('sources.index') }}" class="mt-2 inline-block text-sm text-indigo-600 hover:underline">
|
|
Voir les sources disponibles
|
|
</a>
|
|
</div>
|
|
@endif
|
|
|
|
{{-- ── Mes derniers relevés ─────────────────────────────────────────── --}}
|
|
@if($mesReleves->isNotEmpty())
|
|
<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">Mes derniers relevés</h3>
|
|
<a href="{{ route('recherche') }}" class="text-xs text-indigo-600 hover:underline">Recherche</a>
|
|
</div>
|
|
<div class="space-y-0 divide-y divide-gray-100">
|
|
@foreach($mesReleves as $releve)
|
|
<div class="flex items-center justify-between py-2.5">
|
|
<div class="min-w-0">
|
|
<a href="{{ route('releves.show', $releve) }}"
|
|
class="text-sm font-medium text-gray-900 hover:text-indigo-600">
|
|
{{ $releve->nom ?? '—' }}{{ $releve->prenom ? ', ' . $releve->prenom : '' }}
|
|
</a>
|
|
<p class="text-xs text-gray-400">{{ $releve->source->nom }}</p>
|
|
</div>
|
|
<span class="text-xs text-gray-400 whitespace-nowrap ml-4">
|
|
{{ $releve->created_at->diffForHumans() }}
|
|
</span>
|
|
</div>
|
|
@endforeach
|
|
</div>
|
|
</div>
|
|
@endif
|
|
|
|
</div>
|
|
</x-app-layout>
|