modification mineures, ajout de la latence bdd dans la page superadmin

This commit is contained in:
jeremy bayse
2026-02-24 10:57:49 +01:00
parent 41caefece3
commit f25f4acaaf
3 changed files with 55 additions and 13 deletions

View File

@@ -5,6 +5,8 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Inertia\Inertia;
use App\Models\Structure;
use Illuminate\Support\Facades\DB;
class SuperAdminController extends Controller
{
@@ -15,16 +17,23 @@ class SuperAdminController extends Controller
abort(403, 'Accès refusé. Vous devez être SuperAdmin.');
}
$structures = Structure::withCount(['users' => function ($query) {
$query->withoutGlobalScope('structure');
}])->get();
return Inertia::render('SuperAdmin/Index', [
'structures' => $structures,
'current_structure_id' => session('target_structure_id')
'structures' => fn() => Structure::withCount(['users' => function ($query) {
$query->withoutGlobalScope('structure');
}])->get(),
'current_structure_id' => session('target_structure_id'),
'db_latency' => fn() => $this->calculateDbLatency(),
'db_type' => DB::connection()->getDriverName()
]);
}
private function calculateDbLatency()
{
$start = microtime(true);
DB::select('SELECT 1');
return round((microtime(true) - $start) * 1000, 2);
}
public function create()
{
if (!auth()->user()->hasRole('SuperAdmin')) { abort(403); }

View File

@@ -20,7 +20,7 @@ const showingNavigationDropdown = ref(false);
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z" clip-rule="evenodd" />
</svg>
<span>MODE SIMULATION ACTIF : Vous modifiez actuellement le locataire "{{ $page.props.tenant.current ? $page.props.tenant.current.name : 'VUE GLOBALE' }}"</span>
<span>MODE SIMULATION ACTIF : Vous modifiez actuellement le locataire "{{ $page.props.tenant?.current?.name || 'VUE GLOBALE' }}"</span>
</div>
<Link :href="route('superadmin.reset')" method="post" as="button" class="bg-white text-amber-600 px-3 py-1 rounded-md hover:bg-amber-50 transition-colors">
Arrêter la simulation
@@ -43,7 +43,7 @@ const showingNavigationDropdown = ref(false);
/>
</Link>
<span class="text-lg font-bold text-gray-800 dark:text-gray-200">
{{ $page.props.tenant.current ? $page.props.tenant.current.name : ($page.props.auth.user.structure ? $page.props.auth.user.structure.name : '') }}
{{ $page.props.tenant?.current?.name || $page.props.auth?.user?.structure?.name || '' }}
</span>
</div>

View File

@@ -1,11 +1,14 @@
<script setup>
import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout.vue';
import { Head, Link, router } from '@inertiajs/vue3';
import { ref } from 'vue';
import { ref, onMounted, onUnmounted } from 'vue';
const props = defineProps({
structures: Array,
current_structure_id: Number
current_structure_id: Number,
db_latency: Number,
db_type: String
});
const switchTo = (id) => {
@@ -21,6 +24,25 @@ const deleteStructure = (id) => {
router.delete(route('superadmin.destroy', id));
}
};
let refreshInterval = null;
onMounted(() => {
refreshInterval = setInterval(() => {
router.reload({
only: ['db_latency'],
preserveScroll: true,
preserveState: true
});
}, 30000); // 30 seconds
});
onUnmounted(() => {
if (refreshInterval) {
clearInterval(refreshInterval);
}
});
</script>
<template>
@@ -29,9 +51,20 @@ const deleteStructure = (id) => {
<AuthenticatedLayout>
<template #header>
<div class="flex justify-between items-center">
<div class="flex items-center space-x-4">
<h2 class="text-xl font-semibold leading-tight text-gray-800 dark:text-gray-200">
Super Administration SaaS
</h2>
<span v-if="db_type" class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-blue-100 text-blue-800 dark:bg-blue-900/30 dark:text-blue-400 border border-blue-200 dark:border-blue-800">
Type : {{ db_type.toUpperCase() }}
</span>
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-400 border border-green-200 dark:border-green-800">
<svg class="mr-1.5 h-2 w-2 text-green-400" fill="currentColor" viewBox="0 0 8 8">
<circle cx="4" cy="4" r="3" />
</svg>
Latence BDD : {{ db_latency }}ms
</span>
</div>
<div class="flex space-x-4">
<Link :href="route('superadmin.create')" class="px-4 py-2 bg-indigo-600 text-white rounded-md text-sm hover:bg-indigo-700">
+ Créer une Structure