214 lines
10 KiB
HTML
214 lines
10 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="fr"><head>
|
|
<meta charset="UTF-8">
|
|
<title>Database Dashboard · Live</title>
|
|
<style>
|
|
body{font-family:-apple-system,BlinkMacSystemFont,sans-serif;background:#0a0e27;color:#e4e8f7;margin:0;padding:24px;min-height:100vh}
|
|
h1{color:#6ba3ff;border-bottom:2px solid #1e3a8a;padding-bottom:8px}
|
|
h2{color:#c084fc;margin-top:32px}
|
|
.grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(220px,1fr));gap:16px;margin:16px 0}
|
|
.card{background:#141933;border:1px solid #263161;border-radius:8px;padding:18px}
|
|
.big{font-size:32px;font-weight:bold;color:#6ba3ff}
|
|
.sub{color:#9ca8d3;font-size:12px;margin-top:4px}
|
|
table{width:100%;border-collapse:collapse;margin:12px 0}
|
|
th,td{padding:8px 12px;border-bottom:1px solid #263161;text-align:left;font-size:13px}
|
|
th{background:#1e2549;color:#9ca8d3;font-size:11px;text-transform:uppercase;letter-spacing:0.5px}
|
|
.badge{display:inline-block;padding:2px 8px;border-radius:4px;font-size:10px;font-weight:bold;text-transform:uppercase}
|
|
.active{background:#10b981;color:#fff}
|
|
.empty{background:#ef4444;color:#fff}
|
|
.warn{background:#f59e0b;color:#fff}
|
|
.info{background:#3b82f6;color:#fff}
|
|
.num{font-family:'SF Mono',Monaco,monospace;color:#6ba3ff;text-align:right}
|
|
#toast{position:fixed;bottom:24px;right:24px;padding:16px 24px;background:#ef4444;color:#fff;border-radius:8px;display:none;z-index:1000;box-shadow:0 8px 24px rgba(0,0,0,0.3)}
|
|
.toast-ok{background:#10b981!important}
|
|
.skeleton{display:inline-block;width:80px;height:28px;background:linear-gradient(90deg,#263161 0%,#1e2549 50%,#263161 100%);background-size:200% 100%;animation:skel 1.5s infinite;border-radius:4px}
|
|
@keyframes skel{0%{background-position:200% 0}100%{background-position:-200% 0}}
|
|
.refresh{color:#9ca8d3;font-size:11px;margin-top:24px;text-align:right}
|
|
.bar-container{width:100%;height:8px;background:#1e2549;border-radius:4px;overflow:hidden;margin-top:6px}
|
|
.bar{height:100%;background:linear-gradient(90deg,#6ba3ff 0%,#c084fc 100%);transition:width 0.3s}
|
|
.search-box{padding:12px;background:#141933;border:1px solid #263161;border-radius:6px;color:#e4e8f7;width:100%;max-width:400px;font-size:14px}
|
|
</style></head>
|
|
<body>
|
|
<h1>🗄️ Database Dashboard · Live</h1>
|
|
<p style="color:#9ca8d3">Live data from PostgreSQL admin/ethica/weval schemas · Auto-refresh 30s · 0 hardcode</p>
|
|
|
|
<h2>Overview</h2>
|
|
<div class="grid">
|
|
<div class="card"><h3>Total tables</h3><div class="big" id="total-tables"><span class="skeleton"></span></div><div class="sub" id="total-tables-sub">Initialisation...</div></div>
|
|
<div class="card"><h3>Active (non-empty)</h3><div class="big" id="active-tables"><span class="skeleton"></span></div><div class="sub" id="active-tables-sub">—</div></div>
|
|
<div class="card"><h3>Empty tables</h3><div class="big" id="empty-tables"><span class="skeleton"></span></div><div class="sub" id="empty-tables-sub">—</div></div>
|
|
<div class="card"><h3>Total rows</h3><div class="big" id="total-rows"><span class="skeleton"></span></div><div class="sub">aggregated</div></div>
|
|
</div>
|
|
|
|
<h2>Schemas breakdown</h2>
|
|
<div class="grid" id="schemas-grid"></div>
|
|
|
|
<h2>Critical business tables</h2>
|
|
<div class="card">
|
|
<table>
|
|
<thead><tr><th>Table</th><th>Description</th><th>Rows</th><th>Status</th></tr></thead>
|
|
<tbody id="critical-tbody"><tr><td colspan="4" style="text-align:center;padding:24px"><span class="skeleton"></span></td></tr></tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<h2>Top 20 tables by row count</h2>
|
|
<div class="card">
|
|
<table>
|
|
<thead><tr><th>#</th><th>Table</th><th>Rows</th><th>Bar</th></tr></thead>
|
|
<tbody id="top-tbody"><tr><td colspan="4" style="text-align:center;padding:24px"><span class="skeleton"></span></td></tr></tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<div class="refresh" id="refresh-info">Connecting to /api/db-stats-live.php...</div>
|
|
|
|
<div id="toast"></div>
|
|
|
|
<script>
|
|
function showToast(msg, type='error') {
|
|
const t = document.getElementById('toast');
|
|
t.textContent = msg;
|
|
t.className = type === 'ok' ? 'toast-ok' : '';
|
|
t.style.display = 'block';
|
|
setTimeout(() => t.style.display = 'none', 5000);
|
|
}
|
|
function fmt(n) { return (n || 0).toLocaleString('fr-FR'); }
|
|
|
|
async function loadData() {
|
|
try {
|
|
const resp = await fetch('/api/db-stats-live.php');
|
|
if (!resp.ok) throw new Error('HTTP ' + resp.status);
|
|
const d = await resp.json();
|
|
if (d.error) throw new Error(d.error);
|
|
|
|
// Overview
|
|
const s = d.summary || {};
|
|
document.getElementById('total-tables').textContent = fmt(s.total_tables);
|
|
document.getElementById('total-tables-sub').textContent = 'PostgreSQL admin+ethica+weval';
|
|
document.getElementById('active-tables').textContent = fmt(s.active_tables);
|
|
document.getElementById('active-tables-sub').textContent = 'Tables with data';
|
|
document.getElementById('empty-tables').textContent = fmt(s.empty_tables);
|
|
document.getElementById('empty-tables-sub').textContent = s.total_tables ? (Math.round(100*s.empty_tables/s.total_tables)+'% of total') : '-';
|
|
document.getElementById('total-rows').textContent = fmt(s.total_rows);
|
|
|
|
// Schemas
|
|
const sg = document.getElementById('schemas-grid');
|
|
sg.innerHTML = '';
|
|
for (const [name, sc] of Object.entries(s.schemas || {})) {
|
|
const card = document.createElement('div');
|
|
card.className = 'card';
|
|
card.innerHTML = `<h3>${name}</h3>
|
|
<div class="big">${fmt(sc.rows)}</div>
|
|
<div class="sub">${sc.tables} tables · ${sc.empty} vides · ${sc.tables - sc.empty} actives</div>
|
|
<div class="bar-container"><div class="bar" style="width:${sc.tables ? 100*(sc.tables-sc.empty)/sc.tables : 0}%"></div></div>`;
|
|
sg.appendChild(card);
|
|
}
|
|
|
|
// Critical
|
|
const ct = document.getElementById('critical-tbody');
|
|
ct.innerHTML = '';
|
|
for (const [tbl, info] of Object.entries(d.critical_status || {})) {
|
|
const rows = info.rows;
|
|
let badge = 'info';
|
|
if (rows === null) badge = 'warn';
|
|
else if (rows === 0) badge = 'empty';
|
|
else if (rows > 1000) badge = 'active';
|
|
const status = rows === null ? 'MISSING' : rows === 0 ? 'EMPTY' : rows > 1000 ? 'ACTIVE' : 'SMALL';
|
|
const tr = document.createElement('tr');
|
|
tr.innerHTML = `<td><code>${tbl}</code></td>
|
|
<td style="color:#9ca8d3">${info.desc}</td>
|
|
<td class="num">${rows === null ? '—' : fmt(rows)}</td>
|
|
<td><span class="badge ${badge}">${status}</span></td>`;
|
|
ct.appendChild(tr);
|
|
}
|
|
|
|
// Top 20
|
|
const tt = document.getElementById('top-tbody');
|
|
tt.innerHTML = '';
|
|
const max = d.top_tables?.[0]?.rows || 1;
|
|
(d.top_tables || []).forEach((t, i) => {
|
|
const pct = (t.rows / max) * 100;
|
|
const tr = document.createElement('tr');
|
|
tr.innerHTML = `<td>${i+1}</td><td><code>${t.table}</code></td>
|
|
<td class="num">${fmt(t.rows)}</td>
|
|
<td><div class="bar-container"><div class="bar" style="width:${pct}%"></div></div></td>`;
|
|
tt.appendChild(tr);
|
|
});
|
|
|
|
document.getElementById('refresh-info').textContent =
|
|
'Last refresh: ' + new Date(d.ts).toLocaleString('fr-FR') + ' · Auto-refresh in 30s';
|
|
} catch (e) {
|
|
showToast('Erreur: ' + e.message);
|
|
document.getElementById('refresh-info').textContent = 'Error: ' + e.message + ' · Retry in 30s';
|
|
}
|
|
}
|
|
|
|
loadData();
|
|
setInterval(loadData, 30000);
|
|
</script>
|
|
|
|
<!-- === OPUS UNIVERSAL DRILL-DOWN v1 19avr — append-only, doctrine #14 === -->
|
|
<script>
|
|
(function(){
|
|
if (window.__opusUniversalDrill) return; window.__opusUniversalDrill = true;
|
|
var d = document;
|
|
var m = d.createElement('div');
|
|
m.id = 'opus-udrill';
|
|
m.style.cssText = 'position:fixed;inset:0;background:rgba(0,0,0,0.82);backdrop-filter:blur(6px);display:none;align-items:center;justify-content:center;z-index:99995;padding:20px;cursor:pointer';
|
|
var inner = d.createElement('div');
|
|
inner.id = 'opus-udrill-in';
|
|
inner.style.cssText = 'max-width:900px;width:100%;max-height:90vh;overflow:auto;background:#0b0d15;border:1px solid rgba(99,102,241,0.35);border-radius:14px;padding:28px;cursor:default;box-shadow:0 20px 60px rgba(0,0,0,0.6);color:#e2e8f0;font:14px/1.55 Inter,system-ui,sans-serif';
|
|
inner.addEventListener('click', function(e){ e.stopPropagation(); });
|
|
m.appendChild(inner);
|
|
m.addEventListener('click', function(){ m.style.display='none'; });
|
|
d.addEventListener('keydown', function(e){ if(e.key==='Escape') m.style.display='none'; });
|
|
(d.body || d.documentElement).appendChild(m);
|
|
|
|
function openCard(card) {
|
|
// Clone card content + show close btn + increase font-size
|
|
var html = '<div style="display:flex;justify-content:flex-end;margin-bottom:14px"><button id="opus-udrill-close" style="padding:6px 14px;background:#171b2a;border:1px solid rgba(99,102,241,0.25);color:#e2e8f0;border-radius:8px;cursor:pointer;font-size:12px">✕ Fermer (Esc)</button></div>';
|
|
html += '<div style="transform-origin:top left;font-size:1.05em">' + card.outerHTML + '</div>';
|
|
inner.innerHTML = html;
|
|
d.getElementById('opus-udrill-close').onclick = function(){ m.style.display='none'; };
|
|
m.style.display = 'flex';
|
|
}
|
|
|
|
function wire(root) {
|
|
var sels = '.card,[class*="card"],.kpi,[class*="kpi"],.stat,[class*="stat"],.tile,[class*="tile"],.metric,[class*="metric"],.widget,[class*="widget"]';
|
|
var cards = root.querySelectorAll(sels);
|
|
for (var i = 0; i < cards.length; i++) {
|
|
var c = cards[i];
|
|
if (c.__opusWired) continue;
|
|
if (c.closest('button, a, input, select, textarea, #opus-udrill')) continue;
|
|
var r = c.getBoundingClientRect();
|
|
if (r.width < 60 || r.height < 40) continue;
|
|
c.__opusWired = true;
|
|
c.style.cursor = 'pointer';
|
|
c.setAttribute('role','button');
|
|
c.setAttribute('tabindex','0');
|
|
c.addEventListener('click', function(ev){
|
|
// If a more-specific drill is already active (e.g. pp-card custom), let it handle
|
|
if (ev.target.closest('[data-pp-id]') && window.__opusDrillInit) return;
|
|
if (ev.target.closest('a,button,input,select')) return;
|
|
ev.preventDefault(); ev.stopPropagation();
|
|
openCard(this);
|
|
});
|
|
c.addEventListener('keydown', function(ev){ if(ev.key==='Enter'||ev.key===' '){ev.preventDefault();openCard(this);} });
|
|
}
|
|
}
|
|
|
|
// Initial + mutation observer
|
|
var initRun = function(){ wire(d.body || d.documentElement); };
|
|
if (d.readyState === 'loading') d.addEventListener('DOMContentLoaded', initRun);
|
|
else initRun();
|
|
var mo = new MutationObserver(function(muts){
|
|
var newCard = false;
|
|
for (var i=0;i<muts.length;i++) if (muts[i].addedNodes.length) { newCard = true; break; }
|
|
if (newCard) initRun();
|
|
});
|
|
mo.observe(d.body || d.documentElement, {childList:true, subtree:true});
|
|
})();
|
|
</script>
|
|
<!-- === OPUS UNIVERSAL DRILL-DOWN END === -->
|
|
|
|
</body></html>
|