feat: admin dashboard — статистика сообщений/сессий/пользователей
/api/admin/stats — totals + daily breakdown (14 дней) /admin — карточки с метриками + таблица по дням + сессии Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
+23
-1
@@ -20,7 +20,10 @@ a:hover { text-decoration: underline; }
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>Сессии пользователей</h1>
|
||||
<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>
|
||||
@@ -29,6 +32,25 @@ a:hover { text-decoration: underline; }
|
||||
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 => {
|
||||
|
||||
Reference in New Issue
Block a user