Comptes actifs/inactifs + stats de section dans le tableau de bord
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>
This commit is contained in:
@@ -39,6 +39,34 @@
|
||||
</dl>
|
||||
</div>
|
||||
|
||||
{{-- Statut actif / inactif --}}
|
||||
<div class="bg-white shadow rounded-lg p-6 flex items-center justify-between">
|
||||
<div>
|
||||
<p class="text-sm font-medium text-gray-900">Statut du compte</p>
|
||||
<p class="text-sm text-gray-500 mt-0.5">
|
||||
@if($user->is_active)
|
||||
Le compte est <span class="text-green-600 font-medium">actif</span> — l'utilisateur peut se connecter et être assigné à des sources.
|
||||
@else
|
||||
Le compte est <span class="text-red-600 font-medium">inactif</span> — l'utilisateur ne peut pas se connecter.
|
||||
@endif
|
||||
</p>
|
||||
</div>
|
||||
@if($user->id !== auth()->id())
|
||||
<form method="POST" action="{{ route('admin.utilisateurs.toggle-active', $user) }}"
|
||||
x-data
|
||||
@submit.prevent="if(confirm('{{ $user->is_active ? 'Désactiver' : 'Activer' }} ce compte ?')) $el.submit()">
|
||||
@csrf
|
||||
<button type="submit"
|
||||
class="px-4 py-2 text-sm font-medium rounded-md
|
||||
{{ $user->is_active
|
||||
? 'bg-red-50 text-red-700 border border-red-200 hover:bg-red-100'
|
||||
: 'bg-green-50 text-green-700 border border-green-200 hover:bg-green-100' }}">
|
||||
{{ $user->is_active ? 'Désactiver le compte' : 'Activer le compte' }}
|
||||
</button>
|
||||
</form>
|
||||
@endif
|
||||
</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>
|
||||
|
||||
@@ -66,12 +66,17 @@
|
||||
];
|
||||
$color = $roleColors[$user->role->value] ?? 'bg-gray-100 text-gray-600';
|
||||
@endphp
|
||||
<tr class="hover:bg-gray-50">
|
||||
<tr class="hover:bg-gray-50 {{ ! $user->is_active ? 'opacity-60' : '' }}">
|
||||
<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
|
||||
@if(! $user->is_active)
|
||||
<span class="ml-2 inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium bg-red-100 text-red-600">
|
||||
Inactif
|
||||
</span>
|
||||
@endif
|
||||
</td>
|
||||
<td class="px-6 py-4 text-gray-500">{{ $user->email }}</td>
|
||||
<td class="px-6 py-4">
|
||||
@@ -90,12 +95,21 @@
|
||||
<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">
|
||||
<td class="px-6 py-4 text-right space-x-3">
|
||||
@if($user->id !== auth()->id())
|
||||
<a href="{{ route('admin.utilisateurs.edit', $user) }}"
|
||||
class="text-indigo-600 hover:underline text-sm">
|
||||
Modifier
|
||||
</a>
|
||||
<form method="POST" action="{{ route('admin.utilisateurs.toggle-active', $user) }}"
|
||||
class="inline" x-data
|
||||
@submit.prevent="if(confirm('{{ $user->is_active ? 'Désactiver' : 'Activer' }} ce compte ?')) $el.submit()">
|
||||
@csrf
|
||||
<button type="submit"
|
||||
class="text-sm {{ $user->is_active ? 'text-red-500 hover:text-red-700' : 'text-green-600 hover:text-green-700' }}">
|
||||
{{ $user->is_active ? 'Désactiver' : 'Activer' }}
|
||||
</button>
|
||||
</form>
|
||||
@endif
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -21,24 +21,107 @@
|
||||
</div>
|
||||
@endif
|
||||
|
||||
{{-- Mes sources assignées --}}
|
||||
@php
|
||||
$mesSources = $user->sourcesAssignees()
|
||||
->with('sourceType')
|
||||
->withCount('releves')
|
||||
->orderByRaw("CASE status
|
||||
WHEN 'en_cours' THEN 0
|
||||
WHEN 'a_valider' THEN 1
|
||||
WHEN 'a_faire' THEN 2
|
||||
WHEN 'termine' THEN 3
|
||||
ELSE 4 END")
|
||||
->get();
|
||||
@endphp
|
||||
{{-- ── 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</h3>
|
||||
<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">
|
||||
@@ -85,7 +168,7 @@
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
@else
|
||||
@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"
|
||||
@@ -98,15 +181,7 @@
|
||||
</div>
|
||||
@endif
|
||||
|
||||
{{-- Mes derniers relevés saisis --}}
|
||||
@php
|
||||
$mesReleves = \App\Models\Releve::with(['source.sourceType'])
|
||||
->where('created_by', $user->id)
|
||||
->orderByDesc('created_at')
|
||||
->take(8)
|
||||
->get();
|
||||
@endphp
|
||||
|
||||
{{-- ── 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">
|
||||
|
||||
@@ -12,6 +12,23 @@
|
||||
class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500">{{ old('description', $source?->description) }}</textarea>
|
||||
</div>
|
||||
|
||||
{{-- Section propriétaire --}}
|
||||
@if($sections->isNotEmpty())
|
||||
<div>
|
||||
<label for="section_id" class="block text-sm font-medium text-gray-700">Section</label>
|
||||
<select id="section_id" name="section_id"
|
||||
class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 text-sm">
|
||||
<option value="">— Aucune (globale) —</option>
|
||||
@foreach($sections as $sec)
|
||||
<option value="{{ $sec->id }}" {{ old('section_id', $source?->section_id) == $sec->id ? 'selected' : '' }}>
|
||||
{{ $sec->nom }}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
@error('section_id') <p class="mt-1 text-sm text-red-600">{{ $message }}</p> @enderror
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label for="source_type_id" class="block text-sm font-medium text-gray-700">Type de source <span class="text-red-500">*</span></label>
|
||||
|
||||
Reference in New Issue
Block a user