É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:
@@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Admin;
|
||||||
|
|
||||||
|
use App\Enums\SourceStatus;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Models\Releve;
|
||||||
|
use App\Models\Source;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\View\View;
|
||||||
|
|
||||||
|
class DashboardController extends Controller
|
||||||
|
{
|
||||||
|
public function index(): View
|
||||||
|
{
|
||||||
|
// Compteurs sources par statut
|
||||||
|
$sourcesByStatus = Source::selectRaw('status, count(*) as total')
|
||||||
|
->groupBy('status')
|
||||||
|
->pluck('total', 'status')
|
||||||
|
->mapWithKeys(fn ($total, $status) => [
|
||||||
|
SourceStatus::from($status)->value => (int) $total,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$totalSources = $sourcesByStatus->sum();
|
||||||
|
$totalReleves = Releve::count();
|
||||||
|
|
||||||
|
// Utilisateurs par rôle
|
||||||
|
$usersByRole = User::selectRaw('role, count(*) as total')
|
||||||
|
->groupBy('role')
|
||||||
|
->pluck('total', 'role');
|
||||||
|
|
||||||
|
$totalUsers = $usersByRole->sum();
|
||||||
|
|
||||||
|
// Sources en attente de validation
|
||||||
|
$sourcesAValider = Source::with(['sourceType', 'depot'])
|
||||||
|
->where('status', SourceStatus::AValider)
|
||||||
|
->orderByDesc('updated_at')
|
||||||
|
->take(10)
|
||||||
|
->get();
|
||||||
|
|
||||||
|
// Relevés récents (10 derniers)
|
||||||
|
$relevesRecents = Releve::with(['source.sourceType', 'createur'])
|
||||||
|
->orderByDesc('created_at')
|
||||||
|
->take(10)
|
||||||
|
->get();
|
||||||
|
|
||||||
|
// Activité mensuelle des 6 derniers mois
|
||||||
|
$activiteMensuelle = Releve::selectRaw("to_char(date_trunc('month', created_at), 'Mon YYYY') as mois, count(*) as total")
|
||||||
|
->where('created_at', '>=', now()->subMonths(5)->startOfMonth())
|
||||||
|
->groupByRaw("date_trunc('month', created_at)")
|
||||||
|
->orderByRaw("date_trunc('month', created_at)")
|
||||||
|
->get();
|
||||||
|
|
||||||
|
return view('admin.dashboard', compact(
|
||||||
|
'sourcesByStatus', 'totalSources', 'totalReleves',
|
||||||
|
'usersByRole', 'totalUsers',
|
||||||
|
'sourcesAValider', 'relevesRecents', 'activiteMensuelle'
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Admin;
|
||||||
|
|
||||||
|
use App\Enums\UserRole;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Http\RedirectResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Validation\Rules\Enum;
|
||||||
|
use Illuminate\View\View;
|
||||||
|
|
||||||
|
class UserController extends Controller
|
||||||
|
{
|
||||||
|
public function index(Request $request): View
|
||||||
|
{
|
||||||
|
$query = User::withCount('sourcesAssignees')->with('sections')->orderBy('name');
|
||||||
|
|
||||||
|
if ($request->filled('role')) {
|
||||||
|
$query->where('role', $request->input('role'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($request->filled('q')) {
|
||||||
|
$q = trim($request->get('q'));
|
||||||
|
$query->where(fn ($wq) => $wq
|
||||||
|
->where('name', 'ilike', "%{$q}%")
|
||||||
|
->orWhere('email', 'ilike', "%{$q}%")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$users = $query->paginate(25)->withQueryString();
|
||||||
|
|
||||||
|
return view('admin.utilisateurs.index', compact('users'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function edit(User $user): View
|
||||||
|
{
|
||||||
|
$user->load('sections', 'sourcesAssignees');
|
||||||
|
|
||||||
|
return view('admin.utilisateurs.edit', compact('user'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update(Request $request, User $user): RedirectResponse
|
||||||
|
{
|
||||||
|
$data = $request->validate([
|
||||||
|
'role' => ['required', new Enum(UserRole::class)],
|
||||||
|
]);
|
||||||
|
|
||||||
|
if ($user->id === auth()->id()) {
|
||||||
|
return back()->with('error', 'Vous ne pouvez pas modifier votre propre rôle.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($user->role === UserRole::Admin && $data['role'] !== UserRole::Admin->value) {
|
||||||
|
$adminCount = User::where('role', UserRole::Admin->value)->count();
|
||||||
|
if ($adminCount <= 1) {
|
||||||
|
return back()->with('error', 'Impossible de retirer le rôle admin au dernier administrateur.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$user->update(['role' => $data['role']]);
|
||||||
|
|
||||||
|
return back()->with('success', 'Rôle mis à jour.');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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>
|
||||||
@@ -1,17 +1,136 @@
|
|||||||
<x-app-layout>
|
<x-app-layout>
|
||||||
<x-slot name="header">
|
<x-slot name="header">
|
||||||
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
|
<h2 class="text-xl font-semibold text-gray-800">Tableau de bord</h2>
|
||||||
{{ __('Dashboard') }}
|
|
||||||
</h2>
|
|
||||||
</x-slot>
|
</x-slot>
|
||||||
|
|
||||||
<div class="py-12">
|
<div class="py-8 max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 space-y-8">
|
||||||
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
|
|
||||||
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
|
@php $user = auth()->user(); @endphp
|
||||||
<div class="p-6 text-gray-900">
|
|
||||||
{{ __("You're logged in!") }}
|
{{-- 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>
|
</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
|
||||||
|
|
||||||
|
{{-- 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
|
||||||
|
|
||||||
|
@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>
|
||||||
|
<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>
|
||||||
</div>
|
</div>
|
||||||
|
@else
|
||||||
|
<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 saisis --}}
|
||||||
|
@php
|
||||||
|
$mesReleves = \App\Models\Releve::with(['source.sourceType'])
|
||||||
|
->where('created_by', $user->id)
|
||||||
|
->orderByDesc('created_at')
|
||||||
|
->take(8)
|
||||||
|
->get();
|
||||||
|
@endphp
|
||||||
|
|
||||||
|
@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>
|
</div>
|
||||||
</x-app-layout>
|
</x-app-layout>
|
||||||
|
|||||||
@@ -40,7 +40,15 @@
|
|||||||
</button>
|
</button>
|
||||||
|
|
||||||
<div x-show="adminOpen" @click.outside="adminOpen = false" x-cloak
|
<div x-show="adminOpen" @click.outside="adminOpen = false" x-cloak
|
||||||
class="absolute top-14 mt-1 w-48 bg-white rounded-md shadow-lg border border-gray-100 z-50">
|
class="absolute top-14 mt-1 w-56 bg-white rounded-md shadow-lg border border-gray-100 z-50">
|
||||||
|
@if(auth()->user()->isAdmin())
|
||||||
|
<a href="{{ route('admin.dashboard') }}"
|
||||||
|
class="block px-4 py-2 text-sm font-medium text-indigo-700 hover:bg-indigo-50 border-b border-gray-100">
|
||||||
|
Tableau de bord admin
|
||||||
|
</a>
|
||||||
|
<a href="{{ route('admin.utilisateurs.index') }}"
|
||||||
|
class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-50">Utilisateurs</a>
|
||||||
|
@endif
|
||||||
<a href="{{ route('admin.sections.index') }}"
|
<a href="{{ route('admin.sections.index') }}"
|
||||||
class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-50">Sections</a>
|
class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-50">Sections</a>
|
||||||
@if(auth()->user()->isAdmin())
|
@if(auth()->user()->isAdmin())
|
||||||
@@ -135,6 +143,14 @@
|
|||||||
Recherche
|
Recherche
|
||||||
</x-responsive-nav-link>
|
</x-responsive-nav-link>
|
||||||
@if(auth()->user()->isSectionManager())
|
@if(auth()->user()->isSectionManager())
|
||||||
|
@if(auth()->user()->isAdmin())
|
||||||
|
<x-responsive-nav-link :href="route('admin.dashboard')" :active="request()->routeIs('admin.dashboard')">
|
||||||
|
Tableau de bord admin
|
||||||
|
</x-responsive-nav-link>
|
||||||
|
<x-responsive-nav-link :href="route('admin.utilisateurs.index')" :active="request()->routeIs('admin.utilisateurs.*')">
|
||||||
|
Utilisateurs
|
||||||
|
</x-responsive-nav-link>
|
||||||
|
@endif
|
||||||
<x-responsive-nav-link :href="route('admin.sections.index')" :active="request()->routeIs('admin.sections.*')">
|
<x-responsive-nav-link :href="route('admin.sections.index')" :active="request()->routeIs('admin.sections.*')">
|
||||||
Sections
|
Sections
|
||||||
</x-responsive-nav-link>
|
</x-responsive-nav-link>
|
||||||
@@ -145,6 +161,9 @@
|
|||||||
<x-responsive-nav-link :href="route('admin.source-types.index')" :active="request()->routeIs('admin.source-types.*')">
|
<x-responsive-nav-link :href="route('admin.source-types.index')" :active="request()->routeIs('admin.source-types.*')">
|
||||||
Types de sources
|
Types de sources
|
||||||
</x-responsive-nav-link>
|
</x-responsive-nav-link>
|
||||||
|
<x-responsive-nav-link :href="route('admin.lieu-types.index')" :active="request()->routeIs('admin.lieu-types.*')">
|
||||||
|
Types de lieux
|
||||||
|
</x-responsive-nav-link>
|
||||||
@endif
|
@endif
|
||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,12 +1,17 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use App\Http\Controllers\Admin\DashboardController;
|
||||||
use App\Http\Controllers\Admin\DepotController;
|
use App\Http\Controllers\Admin\DepotController;
|
||||||
use App\Http\Controllers\Admin\LieuTypeController;
|
use App\Http\Controllers\Admin\LieuTypeController;
|
||||||
use App\Http\Controllers\Admin\SectionController;
|
use App\Http\Controllers\Admin\SectionController;
|
||||||
use App\Http\Controllers\Admin\SourceTypeController;
|
use App\Http\Controllers\Admin\SourceTypeController;
|
||||||
|
use App\Http\Controllers\Admin\UserController;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
|
|
||||||
Route::middleware(['auth', 'role:admin'])->prefix('admin')->name('admin.')->group(function () {
|
Route::middleware(['auth', 'role:admin'])->prefix('admin')->name('admin.')->group(function () {
|
||||||
|
Route::get('dashboard', [DashboardController::class, 'index'])->name('dashboard');
|
||||||
|
|
||||||
|
Route::resource('utilisateurs', UserController::class)->only(['index', 'edit', 'update']);
|
||||||
Route::resource('lieu-types', LieuTypeController::class)
|
Route::resource('lieu-types', LieuTypeController::class)
|
||||||
->parameters(['lieu-types' => 'lieuType'])
|
->parameters(['lieu-types' => 'lieuType'])
|
||||||
->except(['show']);
|
->except(['show']);
|
||||||
|
|||||||
Reference in New Issue
Block a user