Files
smeta-web/static/admin.html
T
anorandClaude Opus 4.6 d05e680a98 feat: admin dashboard — статистика сообщений/сессий/пользователей
/api/admin/stats — totals + daily breakdown (14 дней)
/admin — карточки с метриками + таблица по дням + сессии

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 03:48:53 +10:00

70 lines
3.8 KiB
HTML

<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<title>Admin — Сессии</title>
<style>
:root { --bg: #f5f0eb; --card: #fff; --text: #3a3a3a; --muted: #6b6b6b; --accent: #c4463a; --border: #d4c5b2; }
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Inter', -apple-system, sans-serif; background: var(--bg); color: var(--text); padding: 2rem; }
.container { max-width: 900px; margin: 0 auto; }
h1 { font-size: 1.2rem; margin-bottom: 1rem; }
table { width: 100%; border-collapse: collapse; background: var(--card); border-radius: 8px; overflow: hidden; box-shadow: 0 1px 4px rgba(0,0,0,.06); }
th { background: #ede5db; text-align: left; padding: 8px 12px; font-size: .8rem; font-weight: 600; }
td { padding: 6px 12px; border-top: 1px solid #eee; font-size: .85rem; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.time { color: var(--muted); font-size: .75rem; }
.q { color: var(--muted); font-size: .8rem; max-width: 350px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
</style>
</head>
<body>
<div class="container">
<h1>Dashboard</h1>
<div id="stats" style="display:flex;gap:1rem;margin-bottom:1.5rem;flex-wrap:wrap"></div>
<div id="daily" style="margin-bottom:1.5rem"></div>
<h2 style="font-size:1rem;margin-bottom:.5rem">Сессии</h2>
<table id="sessions">
<tr><th>Время</th><th>Пользователь</th><th>Сообщений</th><th>Последний вопрос</th><th></th></tr>
</table>
</div>
<script>
const token = localStorage.getItem('token');
if (!token) window.location.href = '/';
// Stats
fetch('/api/admin/stats', {headers: {'Authorization': 'Bearer ' + token}})
.then(r => r.json())
.then(data => {
const t = data.totals;
const box = (label, val) => `<div style="background:var(--card);padding:1rem;border-radius:8px;box-shadow:0 1px 4px rgba(0,0,0,.06);min-width:120px"><div style="font-size:1.5rem;font-weight:700">${val}</div><div style="font-size:.75rem;color:var(--muted)">${label}</div></div>`;
document.getElementById('stats').innerHTML = box('Сообщений', t.messages) + box('Сессий', t.sessions) + box('Пользователей', t.users);
// Daily chart
if (data.daily && data.daily.length > 0) {
let html = '<table style="width:100%;border-collapse:collapse;background:var(--card);border-radius:8px;overflow:hidden;box-shadow:0 1px 4px rgba(0,0,0,.06)"><tr><th style="background:#ede5db;padding:6px;font-size:.75rem">Дата</th><th style="background:#ede5db;padding:6px;font-size:.75rem">Вопросов</th><th style="background:#ede5db;padding:6px;font-size:.75rem">Ответов</th></tr>';
for (const d of data.daily) {
html += `<tr><td style="padding:4px 8px;border-top:1px solid #eee;font-size:.8rem">${d.day}</td><td style="padding:4px 8px;border-top:1px solid #eee;font-size:.8rem">${d.questions}</td><td style="padding:4px 8px;border-top:1px solid #eee;font-size:.8rem">${d.answers}</td></tr>`;
}
html += '</table>';
document.getElementById('daily').innerHTML = html;
}
});
// Sessions
fetch('/api/admin/sessions', {headers: {'Authorization': 'Bearer ' + token}})
.then(r => r.json())
.then(sessions => {
const table = document.getElementById('sessions');
for (const s of sessions) {
const d = new Date(s.last_ts < 1e12 ? s.last_ts * 1000 : s.last_ts);
const ts = d.toLocaleString('ru-RU', {day:'2-digit',month:'2-digit',year:'2-digit',hour:'2-digit',minute:'2-digit'});
const tr = document.createElement('tr');
const q = (s.last_question || '').slice(0, 80);
tr.innerHTML = `<td class="time">${ts}</td><td>${s.username}</td><td>${s.msg_count}</td><td class="q" title="${q}">${q}</td><td><a href="/?tab=${s.tab_id}" target="_blank">Открыть</a></td>`;
table.appendChild(tr);
}
});
</script>
</body>
</html>