access-manager/public/dashboard.html

179 lines
9.4 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin Dashboard — scottfelten.com</title>
<style>
* { box-sizing: border-box; margin: 0; padding: 0; }
body { background: #0f172a; color: #e2e8f0; font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; min-height: 100vh; }
.container { max-width: 1200px; margin: 0 auto; padding: 24px; }
.header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; padding-bottom: 16px; border-bottom: 1px solid #334155; }
.header h1 { font-size: 22px; font-weight: 700; color: white; }
.header-sub { font-size: 12px; color: #64748b; margin-top: 2px; }
.header-right { display: flex; align-items: center; gap: 12px; }
.btn { padding: 8px 16px; border-radius: 8px; font-weight: 600; font-size: 13px; cursor: pointer; border: none; transition: all 0.15s; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.btn-ghost { background: transparent; color: #94a3b8; border: 1px solid rgba(100,100,140,0.3); }
.btn-ghost:hover { background: #334155; color: white; }
.btn-primary { background: #3b82f6; color: white; }
.btn-primary:hover { background: #2563eb; }
.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 28px; }
.summary-card { background: #1e293b; border: 1px solid #334155; border-radius: 10px; padding: 16px; text-align: center; }
.summary-card .number { font-size: 28px; font-weight: 700; color: white; }
.summary-card .label { font-size: 11px; color: #64748b; text-transform: uppercase; letter-spacing: 0.05em; margin-top: 4px; }
.summary-card .number.ok { color: #22c55e; }
.summary-card .number.warn { color: #eab308; }
.summary-card .number.error { color: #ef4444; }
.section-title { font-size: 12px; font-weight: 600; color: #64748b; text-transform: uppercase; letter-spacing: 0.05em; margin: 24px 0 12px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.card { background: #1e293b; border: 1px solid #334155; border-radius: 12px; padding: 20px; transition: all 0.15s; }
.card:hover { border-color: #475569; }
.card.error { border-color: rgba(239,68,68,0.4); }
.card.loading { opacity: 0.7; }
.card-header { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.card-icon { font-size: 24px; }
.card-title { font-size: 15px; font-weight: 600; color: white; }
.card-category { font-size: 10px; color: #64748b; text-transform: uppercase; letter-spacing: 0.05em; margin-left: auto; padding: 2px 8px; border-radius: 4px; background: rgba(100,100,140,0.15); }
.card-category.internal { background: rgba(59,130,246,0.15); color: #60a5fa; }
.card-category.customer { background: rgba(34,197,94,0.15); color: #4ade80; }
.card-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0; }
.stat { text-align: center; padding: 8px; background: rgba(15,23,42,0.5); border-radius: 8px; }
.stat-value { font-size: 18px; font-weight: 700; color: #e2e8f0; }
.stat-label { font-size: 10px; color: #64748b; text-transform: uppercase; margin-top: 2px; }
.card-footer { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; padding-top: 14px; border-top: 1px solid #334155; }
.status-dot { width: 6px; height: 6px; border-radius: 50%; display: inline-block; }
.status-dot.ok { background: #22c55e; }
.status-dot.error { background: #ef4444; }
.status-text { font-size: 11px; color: #64748b; }
.card-link { color: #3b82f6; font-size: 12px; font-weight: 600; text-decoration: none; }
.card-link:hover { text-decoration: underline; }
.card-error { font-size: 11px; color: #ef4444; margin-top: 8px; }
.skeleton { background: linear-gradient(90deg, #1e293b 25%, #334155 50%, #1e293b 75%); background-size: 200% 100%; animation: shimmer 1.5s infinite; height: 14px; border-radius: 4px; margin: 4px 0; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.footer { text-align: center; margin-top: 40px; padding-top: 20px; border-top: 1px solid #334155; font-size: 11px; color: #475569; }
@media (max-width: 640px) { .cards { grid-template-columns: 1fr; } .summary { grid-template-columns: repeat(2, 1fr); } }
</style>
</head>
<body>
<div class="container">
<div class="header">
<div>
<h1>🏢 Admin Dashboard</h1>
<div class="header-sub">Unified view of all systems</div>
</div>
<div class="header-right">
<a href="https://users.scottfelten.com" class="btn btn-ghost">← Users</a>
<button class="btn btn-primary" onclick="load()" id="refresh-btn">↻ Refresh</button>
</div>
</div>
<div class="summary" id="summary">
<div class="summary-card"><div class="number" id="sum-internal"></div><div class="label">Internal Users</div></div>
<div class="summary-card"><div class="number" id="sum-customer"></div><div class="label">Customer Users</div></div>
<div class="summary-card"><div class="number" id="sum-systems"></div><div class="label">Systems</div></div>
<div class="summary-card"><div class="number" id="sum-healthy"></div><div class="label">Healthy</div></div>
</div>
<div class="section-title">Internal Tools</div>
<div class="cards" id="internal-cards"></div>
<div class="section-title">Customer Apps</div>
<div class="cards" id="customer-cards"></div>
<div class="footer">
<span id="last-updated">Loading...</span>
</div>
</div>
<script>
let cachedData = null;
let lastFetch = 0;
async function load() {
const btn = document.getElementById('refresh-btn');
btn.disabled = true;
btn.textContent = '⟳ Loading...';
try {
// Use cache if < 30 seconds old
const now = Date.now();
if (cachedData && (now - lastFetch) < 30000) {
render(cachedData);
} else {
const res = await fetch('/api/dashboard/stats');
if (!res.ok) throw new Error('Failed to load stats: ' + res.status);
const data = await res.json();
cachedData = data;
lastFetch = now;
render(data);
}
} catch (e) {
document.getElementById('last-updated').textContent = 'Error: ' + e.message;
console.error(e);
} finally {
btn.disabled = false;
btn.textContent = '↻ Refresh';
}
}
function render(data) {
const s = data.summary || {};
document.getElementById('sum-internal').textContent = s.internalUsers || 0;
document.getElementById('sum-customer').textContent = s.customerUsers || 0;
document.getElementById('sum-systems').textContent = s.totalSystems || 0;
const healthy = document.getElementById('sum-healthy');
healthy.textContent = (s.healthySystems || 0) + '/' + (s.totalSystems || 0);
healthy.className = 'number ' + (s.healthySystems === s.totalSystems ? 'ok' : s.healthySystems > 0 ? 'warn' : 'error');
const internal = data.systems?.filter(s => s.category === 'internal') || [];
const customer = data.systems?.filter(s => s.category === 'customer') || [];
document.getElementById('internal-cards').innerHTML = internal.map(s => renderCard(s)).join('');
document.getElementById('customer-cards').innerHTML = customer.map(s => renderCard(s)).join('');
const dt = new Date(data.generatedAt);
document.getElementById('last-updated').textContent = 'Last updated: ' + dt.toLocaleString();
}
function renderCard(sys) {
const isError = sys.status === 'error';
const stats = sys.stats || {};
const statHtml = Object.entries(stats)
.filter(([k]) => k !== 'status' && k !== 'raw')
.map(([k, v]) => {
const label = k.replace(/([A-Z])/g, ' ').replace(/^./, s => s.toUpperCase());
const display = typeof v === 'number' && v > 1000 ? v.toLocaleString() : typeof v === 'number' ? v : String(v);
return '<div class="stat"><div class="stat-value">' + esc(display) + '</div><div class="stat-label">' + esc(label) + '</div></div>';
}).join('');
return '<div class="card ' + (isError ? 'error' : '') + '">' +
'<div class="card-header">' +
'<span class="card-icon">' + esc(sys.icon || '🔧') + '</span>' +
'<span class="card-title">' + esc(sys.name) + '</span>' +
'<span class="card-category ' + esc(sys.category) + '">' + esc(sys.category) + '</span>' +
'</div>' +
(statHtml ? '<div class="card-stats">' + statHtml + '</div>' : '') +
(sys.error ? '<div class="card-error">' + esc(sys.error) + '</div>' : '') +
'<div class="card-footer">' +
'<span><span class="status-dot ' + (isError ? 'error' : 'ok') + '"></span> <span class="status-text">' + (isError ? 'Error' : 'Healthy') + '</span></span>' +
(sys.adminUrl ? '<a href="' + esc(sys.adminUrl) + '" class="card-link" target="_blank">Manage →</a>' : '') +
'</div>' +
'</div>';
}
function esc(s) {
if (!s) return '';
const d = document.createElement('div');
d.textContent = String(s);
return d.innerHTML;
}
// Auto-refresh every 60 seconds
setInterval(() => { if (document.visibilityState === 'visible') load(); }, 60000);
load();
</script>
</body>
</html>