Files
mesreleves-php/resources/views/admin/dashboard.blade.php
T
yann64 ba7fe10329 Versioning, déploiement et mise à jour automatique
Gestion des versions :
- Fichier VERSION (1.0.0) comme source de vérité
- config/update.php : URL Gitea, AUTO_UPDATE (false par défaut), rétention des sauvegardes

Artisan commands :
- app:check-update  : interroge l'API Gitea, cache Redis 1h, déclenche app:update si AUTO_UPDATE=true
- app:update        : télécharge l'archive, sauvegarde pg_dump, rsync, composer install, migrate, reload php-fpm
- app:rollback      : liste les sauvegardes et restaure via psql

UpdateService :
- Téléchargement via Http::sink() (streaming, pas de charge mémoire)
- Sauvegarde pg_dump dans storage/app/backups/ avant chaque mise à jour
- Rechargement php-fpm gracieux (kill -USR2 1) sans downtime
- Purge automatique des anciennes sauvegardes (configurable)

Docker (refactor pour volume-mount) :
- Dockerfile : runtime seulement (PHP + extensions + composer + rsync + pg_client)
  Le code n'est plus copié dans l'image → les mises à jour ne nécessitent pas de rebuild
- entrypoint.sh : composer install + key:generate + caches au démarrage du container
- docker-compose.prod.yml : montage du code comme volume (.:/var/www/html)

Scripts de déploiement :
- bin/build-release.sh : rsync + tar.gz + sha256, exclut vendor/node_modules/tests
- install.sh : guide d'installation Docker complète (première mise en service)

Interface admin :
- Bandeau "mise à jour disponible" dans le dashboard admin (version courante + cible)
- Badge version + icône "à jour" en pied de tableau de bord
- Commande à copier-coller pour appliquer depuis le container

Planification :
- routes/console.php : Schedule::command('app:check-update')->daily()
- .env.example : variables GITEA_*, AUTO_UPDATE, UPDATE_BACKUPS_TO_KEEP

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-04 17:38:39 +02:00

178 lines
10 KiB
PHP

<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">
{{-- Bandeau mise à jour disponible --}}
@if($updateAvailable)
<div class="bg-indigo-50 border border-indigo-300 rounded-xl p-4 flex items-center justify-between gap-4">
<div class="flex items-center gap-3">
<svg class="w-5 h-5 text-indigo-500 shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-8l-4-4m0 0L8 8m4-4v12"/>
</svg>
<div>
<p class="text-sm font-semibold text-indigo-800">
Mise à jour disponible : v{{ $latestRelease['version'] }}
<span class="ml-2 font-normal text-indigo-600">(installé : v{{ $installedVersion }})</span>
</p>
<p class="text-xs text-indigo-600 mt-0.5 font-mono">
docker compose exec app php artisan app:update
</p>
</div>
</div>
@if($latestRelease['published_at'])
<span class="text-xs text-indigo-400 whitespace-nowrap">
Publié {{ \Carbon\Carbon::parse($latestRelease['published_at'])->diffForHumans() }}
</span>
@endif
</div>
@endif
{{-- 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>
{{-- Version --}}
<div class="flex items-center justify-end gap-2 text-xs text-gray-400 pt-2">
<span>MesRelevés v{{ $installedVersion }}</span>
@if(! $updateAvailable)
<span class="inline-flex items-center gap-1 text-green-600">
<svg class="w-3 h-3" fill="currentColor" viewBox="0 0 20 20">
<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z" clip-rule="evenodd"/>
</svg>
à jour
</span>
@endif
</div>
</div>
</x-app-layout>