feat(админка): система — каналы и история
This commit is contained in:
@@ -5,6 +5,7 @@ import { DayPage } from '/static/admin2/pages/day.js';
|
||||
import { CustomersPage } from '/static/admin2/pages/customers.js';
|
||||
import { MoneyPage } from '/static/admin2/pages/money.js';
|
||||
import { WorkPage } from '/static/admin2/pages/work.js';
|
||||
import { SystemPage } from '/static/admin2/pages/system.js';
|
||||
|
||||
const html = htm.bind(h);
|
||||
const TITLES = {
|
||||
@@ -31,7 +32,8 @@ const App = () => html`
|
||||
${section === 'today' ? html`<${DayPage} />`
|
||||
: section === 'customers' ? html`<${CustomersPage} />`
|
||||
: section === 'money' ? html`<${MoneyPage} />`
|
||||
: section === 'work' ? html`<${WorkPage} />` : html`
|
||||
: section === 'work' ? html`<${WorkPage} />`
|
||||
: section === 'system' ? html`<${SystemPage} />` : html`
|
||||
<section class="card" aria-labelledby="placeholder">
|
||||
<h2 id="placeholder">Раздел готовится</h2>
|
||||
<p>Данные и действия подключит следующий этап.</p>
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
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>`;
|
||||
}
|
||||
@@ -82,3 +82,5 @@ tr.clickable{cursor:pointer} tr.clickable:hover td{background:#f3f6ff}
|
||||
|
||||
.s-new{background:#fff4e5;color:#b54708}.s-resolved{background:#e7f6ec;color:#067647}
|
||||
.s-deferred,.s-ignored{background:#f2f4f7;color:#667085}
|
||||
|
||||
.badge.ok,.ok{color:#067647}.bad,.badge.bad{color:#b42318}
|
||||
|
||||
Reference in New Issue
Block a user