feat: add password-protected calculation admin
This commit is contained in:
1 parent
0cb5889ce2
commit
3d58b4fc9b
10 files changed
+169
-4
No files matched your search
@@ -0,0 +1,65 @@
|
||||
<!doctype html>
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Беличья нора — админка</title>
|
||||
<style>
|
||||
:root { color-scheme: dark; font-family: system-ui, sans-serif; }
|
||||
body { margin: 0; background: #171516; color: #f4eeee; }
|
||||
main { width: min(1180px, calc(100% - 32px)); margin: 32px auto; }
|
||||
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: end; margin: 20px 0; }
|
||||
label { display: grid; gap: 5px; color: #d8cace; }
|
||||
input, select, button { font: inherit; border: 1px solid #665159; border-radius: 7px; padding: 9px; background: #251e20; color: inherit; }
|
||||
button { cursor: pointer; background: #d59b62; color: #211818; border-color: #d59b62; }
|
||||
.error { color: #ff9f9f; white-space: pre-wrap; }
|
||||
.table-wrap { overflow-x: auto; border: 1px solid #4a383d; border-radius: 10px; }
|
||||
table { width: 100%; border-collapse: collapse; min-width: 820px; }
|
||||
th, td { text-align: left; vertical-align: top; padding: 10px; border-bottom: 1px solid #4a383d; }
|
||||
th { color: #d59b62; }
|
||||
td pre { white-space: pre-wrap; margin: 0; max-width: 560px; }
|
||||
.muted { color: #b9aaad; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<h1>Беличья нора — админская</h1>
|
||||
<p class="muted">История подтверждённых расчётов из VK-бота и веб-калькулятора.</p>
|
||||
<div class="toolbar">
|
||||
<label>Пароль администратора<input id="password" type="password" autocomplete="current-password"></label>
|
||||
<label>Сортировать<select id="sort"><option value="kitten_id">ID котёнка</option><option value="kitten_name">Имя котёнка</option></select></label>
|
||||
<label>Порядок<select id="direction"><option value="asc">А–Я / по возрастанию</option><option value="desc" selected>Я–А / по убыванию</option></select></label>
|
||||
<button id="load">Загрузить</button>
|
||||
</div>
|
||||
<p class="error" id="error"></p>
|
||||
<div class="table-wrap"><table><thead><tr><th>ID записи</th><th>Автор</th><th>Режим</th><th>Котёнок</th><th>Дата</th><th>Сообщение</th></tr></thead><tbody id="rows"></tbody></table></div>
|
||||
</main>
|
||||
<script>
|
||||
const password = document.querySelector('#password');
|
||||
const sort = document.querySelector('#sort');
|
||||
const direction = document.querySelector('#direction');
|
||||
const rows = document.querySelector('#rows');
|
||||
const error = document.querySelector('#error');
|
||||
function cell(text) { const node = document.createElement('td'); node.textContent = text ?? '—'; return node; }
|
||||
async function load() {
|
||||
error.textContent = ''; rows.textContent = '';
|
||||
const query = new URLSearchParams({sort: sort.value, direction: direction.value});
|
||||
try {
|
||||
const response = await fetch(`/api/admin/calculations?${query}`, {headers: {'X-Admin-Password': password.value}});
|
||||
const data = await response.json();
|
||||
if (!response.ok) throw new Error(data.error || 'Не удалось загрузить историю');
|
||||
data.items.forEach(item => {
|
||||
const row = document.createElement('tr');
|
||||
row.append(cell(item.id)); row.append(cell(item.actor_id || '—')); row.append(cell(item.mode));
|
||||
row.append(cell(`${item.input.kitten_name || '—'} [${item.input.kitten_id || '—'}]`));
|
||||
row.append(cell(item.created_at));
|
||||
const message = document.createElement('td'); const pre = document.createElement('pre'); pre.textContent = item.message; message.append(pre); row.append(message);
|
||||
rows.append(row);
|
||||
});
|
||||
} catch (err) { error.textContent = err.message; }
|
||||
}
|
||||
document.querySelector('#load').addEventListener('click', load);
|
||||
if (password.value) load();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in new issue
Block a user