diff --git a/resources/js/Pages/Dashboard.vue b/resources/js/Pages/Dashboard.vue index 970a4d3..3846810 100644 --- a/resources/js/Pages/Dashboard.vue +++ b/resources/js/Pages/Dashboard.vue @@ -6,12 +6,23 @@ import { computed } from 'vue'; const props = defineProps({ stats: Object, - quizzes: Array + quizzes: Array, + top_candidates: Array }); const page = usePage(); const user = computed(() => page.props.auth.user); -const layout = computed(() => user.value.role === 'admin' ? AdminLayout : AuthenticatedLayout); +const layout = computed(() => user.value?.role === 'admin' ? AdminLayout : AuthenticatedLayout); + +const getStatusColor = (status) => { + const colors = { + 'en_attente': 'bg-slate-100 text-slate-700 dark:bg-slate-800 dark:text-slate-400', + 'en_cours': 'bg-indigo-100 text-indigo-700 dark:bg-indigo-900/30 dark:text-indigo-400', + 'termine': 'bg-emerald-100 text-emerald-700 dark:bg-emerald-900/30 dark:text-emerald-400', + 'refuse': 'bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400' + }; + return colors[status] || colors['en_attente']; +}; -
+
-
-
Total Candidats
+
+
Total Candidats
{{ stats.total_candidates }}
-
-
Tests terminés
+
+
Tests terminés
{{ stats.finished_tests }}
-
-
Moyenne Générale
-
{{ stats.average_score }}
+
+
Moyenne Générale
+
{{ stats.average_score }} / 20
-
-
Meilleur Score
-
{{ stats.best_score }}
+
+
Meilleur Score
+
{{ stats.best_score }} / 20
-
-

Bienvenue dans votre espace d'administration.

+ +
+
+

Top 10 Candidats

+ + Voir tous les candidats → + +
+
+ + + + + + + + + + + + + + + + + + + + +
CandidatScore PondéréStatutActions
+
{{ candidate.name }}
+
{{ candidate.email }}
+
+
+ {{ candidate.weighted_score }} / 20 +
+
+ + {{ candidate.status }} + + + + + + + + +
+ Aucun candidat pour le moment. +
+
diff --git a/routes/web.php b/routes/web.php index 8f02d8b..20090b7 100644 --- a/routes/web.php +++ b/routes/web.php @@ -20,13 +20,32 @@ use App\Models\Attempt; Route::get('/dashboard', function () { $stats = []; $quizzes = []; + $topCandidates = []; + if (auth()->user()->isAdmin()) { + $allCandidates = Candidate::with(['attempts'])->get(); $stats = [ 'total_candidates' => Candidate::count(), 'finished_tests' => Attempt::whereNotNull('finished_at')->count(), - 'average_score' => round(Attempt::whereNotNull('finished_at')->avg('score') ?? 0, 1), - 'best_score' => Attempt::whereNotNull('finished_at')->max('score') ?? 0, + 'average_score' => round($allCandidates->avg('weighted_score') ?? 0, 1), + 'best_score' => round($allCandidates->max('weighted_score') ?? 0, 1), ]; + + $topCandidates = Candidate::with(['user', 'attempts']) + ->get() + ->sortByDesc('weighted_score') + ->take(10) + ->map(function($candidate) { + return [ + 'id' => $candidate->id, + 'name' => $candidate->user->name, + 'email' => $candidate->user->email, + 'status' => $candidate->status, + 'weighted_score' => $candidate->weighted_score + ]; + }) + ->values() + ->all(); } else { $candidate = auth()->user()->candidate; $quizzes = \App\Models\Quiz::all()->map(function($quiz) use ($candidate) { @@ -39,7 +58,8 @@ Route::get('/dashboard', function () { return Inertia::render('Dashboard', [ 'stats' => $stats, - 'quizzes' => $quizzes + 'quizzes' => $quizzes, + 'top_candidates' => $topCandidates ]); })->middleware(['auth', 'verified'])->name('dashboard');