feat(card): speedtest
This commit is contained in:
@@ -211,3 +211,4 @@ ul.plain li:last-child { border-bottom: none; }
|
||||
.sv-bar > i { display: block; height: 100%; border-radius: 3px; background: linear-gradient(90deg, var(--accent-dim), var(--accent)); transition: box-shadow .35s; }
|
||||
.sv-card:hover .sv-bar > i { box-shadow: 0 0 9px rgba(255,79,46,.55); }
|
||||
.sv-search-input{width:100%;background:#0d0d13;border:1px solid var(--border);border-radius:6px;padding:8px 10px;color:var(--text);font-family:var(--font-mono);font-size:12px}
|
||||
.sv-run{background:var(--accent-soft);border:1px solid var(--accent-dim);color:var(--accent);border-radius:5px;padding:3px 10px;font-family:var(--font-ui);font-size:11px;cursor:pointer}
|
||||
|
||||
27
public/views/cards/speedtest.js
Normal file
27
public/views/cards/speedtest.js
Normal file
@@ -0,0 +1,27 @@
|
||||
// public/views/cards/speedtest.js
|
||||
import { el, mount } from '../../dom.js';
|
||||
import { api } from '../../api.js';
|
||||
|
||||
let body;
|
||||
async function load() {
|
||||
if (!body) return;
|
||||
try {
|
||||
const hist = await api.get('/api/speedtest/history');
|
||||
const latest = hist[0];
|
||||
const max = Math.max(1, ...hist.map(h => Number(h.down_mbps)));
|
||||
const bars = el('div', { style: { display: 'flex', gap: '2px', alignItems: 'flex-end', height: '40px', marginTop: '8px' } },
|
||||
hist.slice(0, 30).reverse().map(h =>
|
||||
el('div', { style: { flex: '1', background: 'var(--accent-dim)',
|
||||
height: (Number(h.down_mbps) / max * 100) + '%' } })));
|
||||
mount(body,
|
||||
el('div', { class: 'sv-row', style: { fontSize: '20px' } },
|
||||
el('span', { style: { fontFamily: 'var(--font-mono)' } }, latest ? `${Number(latest.down_mbps).toFixed(0)}↓ ${Number(latest.up_mbps).toFixed(0)}↑` : '—'),
|
||||
el('button', { class: 'sv-run', onclick: runNow }, 'Run')),
|
||||
bars);
|
||||
} catch { mount(body, el('span', { class: 'muted' }, 'No speedtest data')); }
|
||||
}
|
||||
async function runNow() { try { await api.post('/api/speedtest/run', {}); } catch {} setTimeout(load, 3000); }
|
||||
export default {
|
||||
id: 'speedtest', title: 'Speedtest', size: 'm',
|
||||
mount(el_) { body = el_; load(); }, start() {}, stop() { body = null; }
|
||||
};
|
||||
@@ -9,8 +9,9 @@ import hostPerf from './cards/host_perf.js';
|
||||
import jobs from './cards/jobs.js';
|
||||
import inbox from './cards/inbox.js';
|
||||
import search from './cards/search.js';
|
||||
import speedtest from './cards/speedtest.js';
|
||||
|
||||
const CARD_MODULES = [clock, weather, hostPerf, jobs, inbox, search]; // grows in later tasks
|
||||
const CARD_MODULES = [clock, weather, hostPerf, jobs, inbox, search, speedtest]; // grows in later tasks
|
||||
let active = []; // mounted cards needing stop()
|
||||
|
||||
export async function render(main) {
|
||||
|
||||
Reference in New Issue
Block a user