56 lines
2.5 KiB
JavaScript
56 lines
2.5 KiB
JavaScript
import { h } from '/static/admin2/vendor/preact.module.js';
|
|
import { useEffect, useState } from '/static/admin2/vendor/hooks.module.js';
|
|
import htm from '/static/admin2/vendor/htm.module.js';
|
|
import { api } from '/static/admin2/api.js';
|
|
import { Card } from '/static/admin2/ui/card.js';
|
|
import { Table } from '/static/admin2/ui/table.js';
|
|
|
|
const html = htm.bind(h);
|
|
const when = (ts) => new Date(ts * 1000).toLocaleString('ru-RU');
|
|
|
|
export function SystemPage() {
|
|
const [data, setData] = useState(null);
|
|
const [error, setError] = useState('');
|
|
|
|
useEffect(() => {
|
|
let alive = true;
|
|
const load = () => api('/api/admin/v2/system').then((d) => {
|
|
if (alive) { setData(d); setError(''); }
|
|
}).catch((e) => { if (alive) setError(e.message || 'Система не отвечает'); });
|
|
load();
|
|
const t = setInterval(load, 60000);
|
|
return () => { alive = false; clearInterval(t); };
|
|
}, []);
|
|
|
|
if (error) return html`<div class="card error" role="alert">${error}</div>`;
|
|
if (!data) return html`<div class="card">Загрузка…</div>`;
|
|
const bad = data.channels.filter((c) => !c.ok);
|
|
return html`
|
|
<div class="grid">
|
|
<${Card} title="Каналы" value=${bad.length ? bad.length + ' сбоя' : 'все живы'}
|
|
note=${'проверено ' + when(data.generated_at)} />
|
|
<${Card} title="Настройки" value=${data.settings.length} note="только чтение" />
|
|
<${Card} title="События" value=${data.history.length} note="последние 50" />
|
|
</div>
|
|
<section class="card">
|
|
<h2>Каналы</h2>
|
|
${data.channels.map((c) => html`<div class="kv" key=${c.name}>
|
|
<div><span>${c.name}</span><b class=${c.ok ? 'ok' : 'bad'}>${c.ok ? 'ок' : 'сбой'}</b></div>
|
|
<div><span>${c.detail || ''}</span></div></div>`)}
|
|
</section>
|
|
<section class="card">
|
|
<h2>Настройки</h2>
|
|
<${Table} columns=${[
|
|
{key: 'key', label: 'Ключ'}, {key: 'value', label: 'Значение'},
|
|
]} rows=${data.settings.map((r) => ({...r, key: r.key}))} empty="Настроек нет" />
|
|
</section>
|
|
<section class="card">
|
|
<h2>История</h2>
|
|
<${Table} columns=${[
|
|
{key: 'timestamp', label: 'Когда', render: (r) => when(r.timestamp)},
|
|
{key: 'label', label: 'Событие'}, {key: 'username', label: 'Кто'},
|
|
{key: 'detail', label: 'Было → стало'},
|
|
]} rows=${data.history.map((r, i) => ({...r, key: r.id || i}))} empty="Событий нет" />
|
|
</section>`;
|
|
}
|