added new static pages
This commit is contained in:
parent
49860df5a0
commit
e38ecfc037
|
|
@ -1,379 +1,379 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Force Monitor — Alarms</title>
|
||||
<style>
|
||||
:root {
|
||||
--bg1:#050816; --bg2:#0b1224; --panel:rgba(255,255,255,0.055); --border:rgba(255,255,255,0.10);
|
||||
--text:#f4f4f5; --muted:#a1a1aa; --muted2:#71717a; --btnbg:rgba(255,255,255,0.05); --shadow:0 16px 36px rgba(0,0,0,0.18);
|
||||
--tableHover:rgba(255,255,255,0.04);
|
||||
}
|
||||
body[data-theme="light"] {
|
||||
--bg1:#eef4ff; --bg2:#f8fafc; --panel:rgba(255,255,255,0.84); --border:rgba(15,23,42,0.10);
|
||||
--text:#0f172a; --muted:#475569; --muted2:#64748b; --btnbg:rgba(255,255,255,0.88); --shadow:0 16px 36px rgba(15,23,42,0.08);
|
||||
--tableHover:rgba(15,23,42,0.04);
|
||||
}
|
||||
* { box-sizing:border-box; }
|
||||
body {
|
||||
margin:0; min-height:100vh; color:var(--text); font-family:'Segoe UI',system-ui,-apple-system,sans-serif;
|
||||
background:
|
||||
radial-gradient(circle at 10% 10%, rgba(34,211,238,0.12), transparent 18%),
|
||||
radial-gradient(circle at 90% 10%, rgba(168,85,247,0.14), transparent 18%),
|
||||
linear-gradient(180deg, var(--bg1) 0%, var(--bg2) 100%);
|
||||
}
|
||||
body[data-theme="light"] {
|
||||
background:
|
||||
radial-gradient(circle at 10% 10%, rgba(14,165,233,0.10), transparent 20%),
|
||||
radial-gradient(circle at 90% 10%, rgba(168,85,247,0.10), transparent 18%),
|
||||
linear-gradient(180deg, var(--bg1) 0%, var(--bg2) 100%);
|
||||
}
|
||||
.wrap { width:min(94vw, 1680px); margin:0 auto; padding:24px; }
|
||||
.glass { background:var(--panel); border:1px solid var(--border); border-radius:24px; backdrop-filter:blur(14px); -webkit-backdrop-filter:blur(14px); box-shadow:var(--shadow); }
|
||||
.nav, .toolbar { display:flex; flex-wrap:wrap; gap:12px; align-items:center; }
|
||||
.nav { margin-bottom:18px; }
|
||||
.btn, .input, select {
|
||||
min-height:42px; border-radius:14px; border:1px solid var(--border); background:var(--btnbg); color:var(--text);
|
||||
padding:10px 14px; font:inherit;
|
||||
}
|
||||
.btn { cursor:pointer; font-weight:600; text-decoration:none; display:inline-flex; align-items:center; justify-content:center; }
|
||||
.btn:hover { transform:translateY(-1px); }
|
||||
.btn.primary { background:rgba(14,165,233,0.14); border-color:rgba(14,165,233,0.35); }
|
||||
.btn.good { background:rgba(16,185,129,0.14); border-color:rgba(16,185,129,0.35); }
|
||||
.btn.warn { background:rgba(245,158,11,0.14); border-color:rgba(245,158,11,0.35); }
|
||||
.input { width:100%; }
|
||||
.grid { display:grid; gap:16px; }
|
||||
.cards { grid-template-columns:repeat(auto-fit,minmax(220px,1fr)); margin-bottom:18px; }
|
||||
.card { padding:18px 20px; }
|
||||
.kicker { font-size:11px; letter-spacing:.22em; color:var(--muted2); text-transform:uppercase; }
|
||||
.value { font-size:34px; font-weight:800; margin-top:8px; }
|
||||
.sub { color:var(--muted); margin-top:8px; font-size:14px; }
|
||||
.pill {
|
||||
display:inline-flex; align-items:center; justify-content:center; min-width:86px; padding:4px 10px; border-radius:999px;
|
||||
font-size:12px; font-weight:700; letter-spacing:.04em; border:1px solid transparent;
|
||||
}
|
||||
.pill.info { background:rgba(59,130,246,0.12); color:#93c5fd; border-color:rgba(59,130,246,0.24); }
|
||||
.pill.warning { background:rgba(245,158,11,0.12); color:#fde68a; border-color:rgba(245,158,11,0.24); }
|
||||
.pill.critical { background:rgba(239,68,68,0.12); color:#fca5a5; border-color:rgba(239,68,68,0.24); }
|
||||
.pill.clear { background:rgba(113,113,122,0.12); color:#d4d4d8; border-color:rgba(113,113,122,0.24); }
|
||||
body[data-theme="light"] .pill.info { color:#1d4ed8; }
|
||||
body[data-theme="light"] .pill.warning { color:#b45309; }
|
||||
body[data-theme="light"] .pill.critical { color:#dc2626; }
|
||||
body[data-theme="light"] .pill.clear { color:#52525b; }
|
||||
.status-line { display:flex; flex-wrap:wrap; gap:12px; color:var(--muted); font-size:14px; margin-top:8px; }
|
||||
table { width:100%; border-collapse:collapse; }
|
||||
th, td { padding:12px 10px; text-align:left; border-bottom:1px solid var(--border); vertical-align:top; }
|
||||
th { color:var(--muted2); font-size:12px; text-transform:uppercase; letter-spacing:.16em; }
|
||||
tbody tr:hover { background:var(--tableHover); }
|
||||
.mono { font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace; }
|
||||
.right { text-align:right; }
|
||||
.toolbar-wrap { padding:18px 20px; margin-bottom:18px; }
|
||||
.table-wrap { padding:0 0 6px 0; overflow:auto; }
|
||||
.error, .empty, .hint { color:var(--muted); }
|
||||
.banner {
|
||||
display:none; margin-bottom:16px; padding:14px 18px; border-radius:18px;
|
||||
background:rgba(239,68,68,0.14); border:1px solid rgba(239,68,68,0.28); color:#fecaca;
|
||||
}
|
||||
.banner.show { display:block; }
|
||||
.row { display:flex; flex-wrap:wrap; gap:12px; align-items:center; }
|
||||
.spacer { flex:1 1 auto; }
|
||||
@media (max-width: 900px) {
|
||||
.wrap { width:min(96vw, 1680px); padding:16px; }
|
||||
.value { font-size:28px; }
|
||||
th:nth-child(5), td:nth-child(5), th:nth-child(6), td:nth-child(6) { display:none; }
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body data-theme="dark">
|
||||
<div class="wrap">
|
||||
<div class="nav">
|
||||
<a class="btn" href="/">Dashboard</a>
|
||||
<a class="btn" href="/history">History</a>
|
||||
<a class="btn primary" href="/alarms">Alarms</a>
|
||||
<a class="btn" href="/kiosk">Kiosk</a>
|
||||
<a class="btn" href="/process-capability">Process capability</a>
|
||||
<a class="btn" href="/reports">Reports</a>
|
||||
<a class="btn" href="/license">License</a>
|
||||
<div class="spacer"></div>
|
||||
<button id="theme-toggle" class="btn" type="button">Light theme</button>
|
||||
<button id="fullscreen-toggle" class="btn" type="button">Enter fullscreen</button>
|
||||
</div>
|
||||
|
||||
<div class="glass card" style="margin-bottom:18px;">
|
||||
<div class="row">
|
||||
<div>
|
||||
<div class="kicker">Force Monitor</div>
|
||||
<h1 style="margin:8px 0 0 0; font-size:40px; line-height:1;">Alarm Timeline</h1>
|
||||
<div class="sub">Advanced event view with filters, summary cards, active-only mode, CSV export, and auto-refresh.</div>
|
||||
</div>
|
||||
<div class="spacer"></div>
|
||||
<div class="status-line">
|
||||
<span id="fetch-status">Status: idle</span>
|
||||
<span id="last-refresh">Last refresh: --</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="license-warning" class="banner"></div>
|
||||
|
||||
<div class="grid cards">
|
||||
<div class="glass card"><div class="kicker">Loaded events</div><div id="metric-total" class="value mono">0</div><div id="metric-total-sub" class="sub">Current filtered set</div></div>
|
||||
<div class="glass card"><div class="kicker">Active alarms</div><div id="metric-active" class="value mono">0</div><div class="sub">State = active</div></div>
|
||||
<div class="glass card"><div class="kicker">Critical</div><div id="metric-critical" class="value mono">0</div><div class="sub">Severity critical</div></div>
|
||||
<div class="glass card"><div class="kicker">Warning</div><div id="metric-warning" class="value mono">0</div><div class="sub">Severity warning</div></div>
|
||||
</div>
|
||||
|
||||
<div class="glass toolbar-wrap">
|
||||
<div class="toolbar">
|
||||
<select id="limit-select" title="Fetch limit">
|
||||
<option value="20">20 rows</option>
|
||||
<option value="50" selected>50 rows</option>
|
||||
<option value="100">100 rows</option>
|
||||
</select>
|
||||
<select id="severity-filter" title="Severity filter">
|
||||
<option value="all">All severities</option>
|
||||
<option value="critical">Critical</option>
|
||||
<option value="warning">Warning</option>
|
||||
<option value="info">Info</option>
|
||||
</select>
|
||||
<select id="source-filter" title="Source filter">
|
||||
<option value="all">All sources</option>
|
||||
<option value="plc">PLC</option>
|
||||
<option value="force_left">Left force</option>
|
||||
<option value="force_right">Right force</option>
|
||||
<option value="imbalance">Imbalance</option>
|
||||
</select>
|
||||
<select id="state-filter" title="State filter">
|
||||
<option value="all">All states</option>
|
||||
<option value="active">Active only</option>
|
||||
<option value="clear">Clear only</option>
|
||||
<option value="info">Info only</option>
|
||||
</select>
|
||||
<input id="search-input" class="input" style="max-width:320px;" type="text" placeholder="Search source, message, time...">
|
||||
<label class="btn warn" style="gap:8px;"><input id="auto-refresh" type="checkbox" checked> Auto refresh</label>
|
||||
<button id="refresh-btn" class="btn primary" type="button">Refresh now</button>
|
||||
<button id="export-btn" class="btn good" type="button">Export CSV</button>
|
||||
</div>
|
||||
<div class="status-line" style="margin-top:12px;">
|
||||
<span>Tip: “active only” helps operators see what still matters right now.</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="glass table-wrap">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Time</th>
|
||||
<th>Severity</th>
|
||||
<th>Source</th>
|
||||
<th>State</th>
|
||||
<th>Event</th>
|
||||
<th class="right">Value</th>
|
||||
<th class="right">Limit</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="alarm-body">
|
||||
<tr><td colspan="7" class="empty" style="padding:24px 10px; text-align:center;">Loading alarms...</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="/static/app-common.js"></script>
|
||||
<script>
|
||||
let allEvents = [];
|
||||
let refreshTimer = null;
|
||||
|
||||
function escapeHtml(value) {
|
||||
return String(value === undefined || value === null ? '' : value)
|
||||
.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>')
|
||||
.replace(/"/g, '"').replace(/'/g, ''');
|
||||
}
|
||||
|
||||
function setTheme(theme) {
|
||||
const t = theme === 'light' ? 'light' : 'dark';
|
||||
document.body.setAttribute('data-theme', t);
|
||||
try { localStorage.setItem('force-monitor-theme', t); } catch (e) {}
|
||||
const btn = document.getElementById('theme-toggle');
|
||||
if (btn) btn.textContent = t === 'light' ? 'Dark theme' : 'Light theme';
|
||||
}
|
||||
|
||||
function initTheme() {
|
||||
let theme = 'dark';
|
||||
try {
|
||||
const stored = localStorage.getItem('force-monitor-theme');
|
||||
if (stored === 'light' || stored === 'dark') theme = stored;
|
||||
} catch (e) {}
|
||||
setTheme(theme);
|
||||
}
|
||||
|
||||
function formatPct(value) {
|
||||
const n = Number(value);
|
||||
return Number.isFinite(n) ? n.toFixed(1) + '%' : '--';
|
||||
}
|
||||
|
||||
function formatSource(source) {
|
||||
return ({ force_left:'LEFT', force_right:'RIGHT', imbalance:'IMBALANCE', plc:'PLC' })[source] || String(source || '').toUpperCase();
|
||||
}
|
||||
|
||||
function severityPill(severity, state) {
|
||||
const sev = String(severity || 'info').toLowerCase();
|
||||
const klass = state === 'clear' ? 'clear' : sev;
|
||||
const label = state === 'clear' ? 'CLEAR' : sev.toUpperCase();
|
||||
return '<span class="pill ' + escapeHtml(klass) + '">' + escapeHtml(label) + '</span>';
|
||||
}
|
||||
|
||||
function setMetrics(events) {
|
||||
const active = events.filter(e => String(e.state || '').toLowerCase() === 'active').length;
|
||||
const critical = events.filter(e => String(e.severity || '').toLowerCase() === 'critical').length;
|
||||
const warning = events.filter(e => String(e.severity || '').toLowerCase() === 'warning').length;
|
||||
document.getElementById('metric-total').textContent = String(events.length);
|
||||
document.getElementById('metric-active').textContent = String(active);
|
||||
document.getElementById('metric-critical').textContent = String(critical);
|
||||
document.getElementById('metric-warning').textContent = String(warning);
|
||||
document.getElementById('metric-total-sub').textContent = events.length === allEvents.length ? 'Current fetched set' : 'Filtered view';
|
||||
}
|
||||
|
||||
function renderTable(events) {
|
||||
const body = document.getElementById('alarm-body');
|
||||
if (!body) return;
|
||||
if (!events.length) {
|
||||
body.innerHTML = '<tr><td colspan="7" class="empty" style="padding:24px 10px; text-align:center;">No events match the current filters</td></tr>';
|
||||
setMetrics(events);
|
||||
return;
|
||||
}
|
||||
let html = '';
|
||||
for (const ev of events) {
|
||||
const state = String(ev.state || '').toLowerCase();
|
||||
const value = ev.source === 'plc' ? '--' : formatPct(ev.value);
|
||||
const limit = Number(ev.limit) > 0 ? formatPct(ev.limit) : '--';
|
||||
html += '<tr>' +
|
||||
'<td class="mono">' + escapeHtml(ev.time || '--') + '</td>' +
|
||||
'<td>' + severityPill(ev.severity, state) + '</td>' +
|
||||
'<td style="font-weight:700;">' + escapeHtml(formatSource(ev.source)) + '</td>' +
|
||||
'<td class="mono">' + escapeHtml(state || '--') + '</td>' +
|
||||
'<td>' + escapeHtml(ev.message || '--') + '</td>' +
|
||||
'<td class="right mono">' + escapeHtml(value) + '</td>' +
|
||||
'<td class="right mono">' + escapeHtml(limit) + '</td>' +
|
||||
'</tr>';
|
||||
}
|
||||
body.innerHTML = html;
|
||||
setMetrics(events);
|
||||
}
|
||||
|
||||
function getFilters() {
|
||||
return {
|
||||
severity: document.getElementById('severity-filter').value,
|
||||
source: document.getElementById('source-filter').value,
|
||||
state: document.getElementById('state-filter').value,
|
||||
search: document.getElementById('search-input').value.trim().toLowerCase()
|
||||
};
|
||||
}
|
||||
|
||||
function applyFilters() {
|
||||
const f = getFilters();
|
||||
const out = allEvents.filter(ev => {
|
||||
const sev = String(ev.severity || '').toLowerCase();
|
||||
const src = String(ev.source || '').toLowerCase();
|
||||
const state = String(ev.state || '').toLowerCase();
|
||||
const hay = [ev.time, ev.source, ev.state, ev.message, ev.severity].join(' ').toLowerCase();
|
||||
if (f.severity !== 'all' && sev !== f.severity) return false;
|
||||
if (f.source !== 'all' && src !== f.source) return false;
|
||||
if (f.state !== 'all' && state !== f.state) return false;
|
||||
if (f.search && !hay.includes(f.search)) return false;
|
||||
return true;
|
||||
});
|
||||
renderTable(out);
|
||||
}
|
||||
|
||||
function updateBanner(msg, show) {
|
||||
const el = document.getElementById('license-warning');
|
||||
if (!el) return;
|
||||
el.textContent = msg || '';
|
||||
el.classList.toggle('show', !!show);
|
||||
}
|
||||
|
||||
async function fetchAlarms() {
|
||||
const limit = document.getElementById('limit-select').value || '50';
|
||||
document.getElementById('fetch-status').textContent = 'Status: loading...';
|
||||
try {
|
||||
const res = await fetch('/api/alarms?limit=' + encodeURIComponent(limit), { cache: 'no-store' });
|
||||
if (res.status === 403) {
|
||||
const data = await res.json().catch(() => ({}));
|
||||
const message = data && data.error ? data.error : 'license required';
|
||||
allEvents = [];
|
||||
applyFilters();
|
||||
updateBanner('Alarm API is locked: ' + message + '. Open /license to activate the app.', true);
|
||||
document.getElementById('fetch-status').textContent = 'Status: license locked';
|
||||
return;
|
||||
}
|
||||
if (!res.ok) throw new Error('HTTP ' + res.status);
|
||||
const data = await res.json();
|
||||
allEvents = Array.isArray(data.events) ? data.events : [];
|
||||
applyFilters();
|
||||
updateBanner('', false);
|
||||
document.getElementById('fetch-status').textContent = 'Status: OK';
|
||||
document.getElementById('last-refresh').textContent = 'Last refresh: ' + new Date().toLocaleTimeString();
|
||||
} catch (err) {
|
||||
console.warn('Alarm fetch error:', err);
|
||||
allEvents = [];
|
||||
applyFilters();
|
||||
updateBanner('Could not load alarms. Check app connectivity and browser console.', true);
|
||||
document.getElementById('fetch-status').textContent = 'Status: error';
|
||||
}
|
||||
}
|
||||
|
||||
function exportCSV() {
|
||||
const rows = [['time','severity','source','state','message','value','limit']];
|
||||
const events = allEvents.filter(ev => {
|
||||
const f = getFilters();
|
||||
const sev = String(ev.severity || '').toLowerCase();
|
||||
const src = String(ev.source || '').toLowerCase();
|
||||
const state = String(ev.state || '').toLowerCase();
|
||||
const hay = [ev.time, ev.source, ev.state, ev.message, ev.severity].join(' ').toLowerCase();
|
||||
if (f.severity !== 'all' && sev !== f.severity) return false;
|
||||
if (f.source !== 'all' && src !== f.source) return false;
|
||||
if (f.state !== 'all' && state !== f.state) return false;
|
||||
if (f.search && !hay.includes(f.search)) return false;
|
||||
return true;
|
||||
});
|
||||
for (const ev of events) {
|
||||
rows.push([ev.time || '', ev.severity || '', ev.source || '', ev.state || '', ev.message || '', ev.value ?? '', ev.limit ?? '']);
|
||||
}
|
||||
const csv = rows.map(r => r.map(v => '"' + String(v).replace(/"/g, '""') + '"').join(',')).join('\r\n');
|
||||
const blob = new Blob([csv], { type: 'text/csv;charset=utf-8' });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = 'force-monitor-alarms-' + new Date().toISOString().replace(/[:.]/g, '-') + '.csv';
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
a.remove();
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
|
||||
function syncAutoRefresh() {
|
||||
const enabled = document.getElementById('auto-refresh').checked;
|
||||
if (refreshTimer) clearInterval(refreshTimer);
|
||||
refreshTimer = null;
|
||||
if (enabled) refreshTimer = setInterval(fetchAlarms, 3000);
|
||||
}
|
||||
|
||||
window.addEventListener('DOMContentLoaded', () => {
|
||||
AppUI.initTheme();
|
||||
AppUI.initFullscreen({ buttonId:'fullscreen-toggle' });
|
||||
document.getElementById('refresh-btn').addEventListener('click', fetchAlarms);
|
||||
document.getElementById('export-btn').addEventListener('click', exportCSV);
|
||||
document.getElementById('auto-refresh').addEventListener('change', syncAutoRefresh);
|
||||
['severity-filter','source-filter','state-filter','search-input','limit-select'].forEach(id => {
|
||||
document.getElementById(id).addEventListener(id === 'search-input' ? 'input' : 'change', () => {
|
||||
if (id === 'limit-select') fetchAlarms(); else applyFilters();
|
||||
});
|
||||
});
|
||||
fetchAlarms();
|
||||
syncAutoRefresh();
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Force Monitor — Alarms</title>
|
||||
<style>
|
||||
:root {
|
||||
--bg1:#050816; --bg2:#0b1224; --panel:rgba(255,255,255,0.055); --border:rgba(255,255,255,0.10);
|
||||
--text:#f4f4f5; --muted:#a1a1aa; --muted2:#71717a; --btnbg:rgba(255,255,255,0.05); --shadow:0 16px 36px rgba(0,0,0,0.18);
|
||||
--tableHover:rgba(255,255,255,0.04);
|
||||
}
|
||||
body[data-theme="light"] {
|
||||
--bg1:#eef4ff; --bg2:#f8fafc; --panel:rgba(255,255,255,0.84); --border:rgba(15,23,42,0.10);
|
||||
--text:#0f172a; --muted:#475569; --muted2:#64748b; --btnbg:rgba(255,255,255,0.88); --shadow:0 16px 36px rgba(15,23,42,0.08);
|
||||
--tableHover:rgba(15,23,42,0.04);
|
||||
}
|
||||
* { box-sizing:border-box; }
|
||||
body {
|
||||
margin:0; min-height:100vh; color:var(--text); font-family:'Segoe UI',system-ui,-apple-system,sans-serif;
|
||||
background:
|
||||
radial-gradient(circle at 10% 10%, rgba(34,211,238,0.12), transparent 18%),
|
||||
radial-gradient(circle at 90% 10%, rgba(168,85,247,0.14), transparent 18%),
|
||||
linear-gradient(180deg, var(--bg1) 0%, var(--bg2) 100%);
|
||||
}
|
||||
body[data-theme="light"] {
|
||||
background:
|
||||
radial-gradient(circle at 10% 10%, rgba(14,165,233,0.10), transparent 20%),
|
||||
radial-gradient(circle at 90% 10%, rgba(168,85,247,0.10), transparent 18%),
|
||||
linear-gradient(180deg, var(--bg1) 0%, var(--bg2) 100%);
|
||||
}
|
||||
.wrap { width:min(94vw, 1680px); margin:0 auto; padding:24px; }
|
||||
.glass { background:var(--panel); border:1px solid var(--border); border-radius:24px; backdrop-filter:blur(14px); -webkit-backdrop-filter:blur(14px); box-shadow:var(--shadow); }
|
||||
.nav, .toolbar { display:flex; flex-wrap:wrap; gap:12px; align-items:center; }
|
||||
.nav { margin-bottom:18px; }
|
||||
.btn, .input, select {
|
||||
min-height:42px; border-radius:14px; border:1px solid var(--border); background:var(--btnbg); color:var(--text);
|
||||
padding:10px 14px; font:inherit;
|
||||
}
|
||||
.btn { cursor:pointer; font-weight:600; text-decoration:none; display:inline-flex; align-items:center; justify-content:center; }
|
||||
.btn:hover { transform:translateY(-1px); }
|
||||
.btn.primary { background:rgba(14,165,233,0.14); border-color:rgba(14,165,233,0.35); }
|
||||
.btn.good { background:rgba(16,185,129,0.14); border-color:rgba(16,185,129,0.35); }
|
||||
.btn.warn { background:rgba(245,158,11,0.14); border-color:rgba(245,158,11,0.35); }
|
||||
.input { width:100%; }
|
||||
.grid { display:grid; gap:16px; }
|
||||
.cards { grid-template-columns:repeat(auto-fit,minmax(220px,1fr)); margin-bottom:18px; }
|
||||
.card { padding:18px 20px; }
|
||||
.kicker { font-size:11px; letter-spacing:.22em; color:var(--muted2); text-transform:uppercase; }
|
||||
.value { font-size:34px; font-weight:800; margin-top:8px; }
|
||||
.sub { color:var(--muted); margin-top:8px; font-size:14px; }
|
||||
.pill {
|
||||
display:inline-flex; align-items:center; justify-content:center; min-width:86px; padding:4px 10px; border-radius:999px;
|
||||
font-size:12px; font-weight:700; letter-spacing:.04em; border:1px solid transparent;
|
||||
}
|
||||
.pill.info { background:rgba(59,130,246,0.12); color:#93c5fd; border-color:rgba(59,130,246,0.24); }
|
||||
.pill.warning { background:rgba(245,158,11,0.12); color:#fde68a; border-color:rgba(245,158,11,0.24); }
|
||||
.pill.critical { background:rgba(239,68,68,0.12); color:#fca5a5; border-color:rgba(239,68,68,0.24); }
|
||||
.pill.clear { background:rgba(113,113,122,0.12); color:#d4d4d8; border-color:rgba(113,113,122,0.24); }
|
||||
body[data-theme="light"] .pill.info { color:#1d4ed8; }
|
||||
body[data-theme="light"] .pill.warning { color:#b45309; }
|
||||
body[data-theme="light"] .pill.critical { color:#dc2626; }
|
||||
body[data-theme="light"] .pill.clear { color:#52525b; }
|
||||
.status-line { display:flex; flex-wrap:wrap; gap:12px; color:var(--muted); font-size:14px; margin-top:8px; }
|
||||
table { width:100%; border-collapse:collapse; }
|
||||
th, td { padding:12px 10px; text-align:left; border-bottom:1px solid var(--border); vertical-align:top; }
|
||||
th { color:var(--muted2); font-size:12px; text-transform:uppercase; letter-spacing:.16em; }
|
||||
tbody tr:hover { background:var(--tableHover); }
|
||||
.mono { font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace; }
|
||||
.right { text-align:right; }
|
||||
.toolbar-wrap { padding:18px 20px; margin-bottom:18px; }
|
||||
.table-wrap { padding:0 0 6px 0; overflow:auto; }
|
||||
.error, .empty, .hint { color:var(--muted); }
|
||||
.banner {
|
||||
display:none; margin-bottom:16px; padding:14px 18px; border-radius:18px;
|
||||
background:rgba(239,68,68,0.14); border:1px solid rgba(239,68,68,0.28); color:#fecaca;
|
||||
}
|
||||
.banner.show { display:block; }
|
||||
.row { display:flex; flex-wrap:wrap; gap:12px; align-items:center; }
|
||||
.spacer { flex:1 1 auto; }
|
||||
@media (max-width: 900px) {
|
||||
.wrap { width:min(96vw, 1680px); padding:16px; }
|
||||
.value { font-size:28px; }
|
||||
th:nth-child(5), td:nth-child(5), th:nth-child(6), td:nth-child(6) { display:none; }
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body data-theme="dark">
|
||||
<div class="wrap">
|
||||
<div class="nav">
|
||||
<a class="btn" href="/">Dashboard</a>
|
||||
<a class="btn" href="/history">History</a>
|
||||
<a class="btn primary" href="/alarms">Alarms</a>
|
||||
<a class="btn" href="/kiosk">Kiosk</a>
|
||||
<a class="btn" href="/process-capability">Process capability</a>
|
||||
<a class="btn" href="/reports">Reports</a>
|
||||
<a class="btn" href="/license">License</a>
|
||||
<div class="spacer"></div>
|
||||
<button id="theme-toggle" class="btn" type="button">Light theme</button>
|
||||
<button id="fullscreen-toggle" class="btn" type="button">Enter fullscreen</button>
|
||||
</div>
|
||||
|
||||
<div class="glass card" style="margin-bottom:18px;">
|
||||
<div class="row">
|
||||
<div>
|
||||
<div class="kicker">Force Monitor</div>
|
||||
<h1 style="margin:8px 0 0 0; font-size:40px; line-height:1;">Alarm Timeline</h1>
|
||||
<div class="sub">Advanced event view with filters, summary cards, active-only mode, CSV export, and auto-refresh.</div>
|
||||
</div>
|
||||
<div class="spacer"></div>
|
||||
<div class="status-line">
|
||||
<span id="fetch-status">Status: idle</span>
|
||||
<span id="last-refresh">Last refresh: --</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="license-warning" class="banner"></div>
|
||||
|
||||
<div class="grid cards">
|
||||
<div class="glass card"><div class="kicker">Loaded events</div><div id="metric-total" class="value mono">0</div><div id="metric-total-sub" class="sub">Current filtered set</div></div>
|
||||
<div class="glass card"><div class="kicker">Active alarms</div><div id="metric-active" class="value mono">0</div><div class="sub">State = active</div></div>
|
||||
<div class="glass card"><div class="kicker">Critical</div><div id="metric-critical" class="value mono">0</div><div class="sub">Severity critical</div></div>
|
||||
<div class="glass card"><div class="kicker">Warning</div><div id="metric-warning" class="value mono">0</div><div class="sub">Severity warning</div></div>
|
||||
</div>
|
||||
|
||||
<div class="glass toolbar-wrap">
|
||||
<div class="toolbar">
|
||||
<select id="limit-select" title="Fetch limit">
|
||||
<option value="20">20 rows</option>
|
||||
<option value="50" selected>50 rows</option>
|
||||
<option value="100">100 rows</option>
|
||||
</select>
|
||||
<select id="severity-filter" title="Severity filter">
|
||||
<option value="all">All severities</option>
|
||||
<option value="critical">Critical</option>
|
||||
<option value="warning">Warning</option>
|
||||
<option value="info">Info</option>
|
||||
</select>
|
||||
<select id="source-filter" title="Source filter">
|
||||
<option value="all">All sources</option>
|
||||
<option value="plc">PLC</option>
|
||||
<option value="force_left">Left force</option>
|
||||
<option value="force_right">Right force</option>
|
||||
<option value="imbalance">Imbalance</option>
|
||||
</select>
|
||||
<select id="state-filter" title="State filter">
|
||||
<option value="all">All states</option>
|
||||
<option value="active">Active only</option>
|
||||
<option value="clear">Clear only</option>
|
||||
<option value="info">Info only</option>
|
||||
</select>
|
||||
<input id="search-input" class="input" style="max-width:320px;" type="text" placeholder="Search source, message, time...">
|
||||
<label class="btn warn" style="gap:8px;"><input id="auto-refresh" type="checkbox" checked> Auto refresh</label>
|
||||
<button id="refresh-btn" class="btn primary" type="button">Refresh now</button>
|
||||
<button id="export-btn" class="btn good" type="button">Export CSV</button>
|
||||
</div>
|
||||
<div class="status-line" style="margin-top:12px;">
|
||||
<span>Tip: “active only” helps operators see what still matters right now.</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="glass table-wrap">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Time</th>
|
||||
<th>Severity</th>
|
||||
<th>Source</th>
|
||||
<th>State</th>
|
||||
<th>Event</th>
|
||||
<th class="right">Value</th>
|
||||
<th class="right">Limit</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="alarm-body">
|
||||
<tr><td colspan="7" class="empty" style="padding:24px 10px; text-align:center;">Loading alarms...</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="/static/app-common.js"></script>
|
||||
<script>
|
||||
let allEvents = [];
|
||||
let refreshTimer = null;
|
||||
|
||||
function escapeHtml(value) {
|
||||
return String(value === undefined || value === null ? '' : value)
|
||||
.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>')
|
||||
.replace(/"/g, '"').replace(/'/g, ''');
|
||||
}
|
||||
|
||||
function setTheme(theme) {
|
||||
const t = theme === 'light' ? 'light' : 'dark';
|
||||
document.body.setAttribute('data-theme', t);
|
||||
try { localStorage.setItem('force-monitor-theme', t); } catch (e) {}
|
||||
const btn = document.getElementById('theme-toggle');
|
||||
if (btn) btn.textContent = t === 'light' ? 'Dark theme' : 'Light theme';
|
||||
}
|
||||
|
||||
function initTheme() {
|
||||
let theme = 'dark';
|
||||
try {
|
||||
const stored = localStorage.getItem('force-monitor-theme');
|
||||
if (stored === 'light' || stored === 'dark') theme = stored;
|
||||
} catch (e) {}
|
||||
setTheme(theme);
|
||||
}
|
||||
|
||||
function formatPct(value) {
|
||||
const n = Number(value);
|
||||
return Number.isFinite(n) ? n.toFixed(1) + '%' : '--';
|
||||
}
|
||||
|
||||
function formatSource(source) {
|
||||
return ({ force_left:'LEFT', force_right:'RIGHT', imbalance:'IMBALANCE', plc:'PLC' })[source] || String(source || '').toUpperCase();
|
||||
}
|
||||
|
||||
function severityPill(severity, state) {
|
||||
const sev = String(severity || 'info').toLowerCase();
|
||||
const klass = state === 'clear' ? 'clear' : sev;
|
||||
const label = state === 'clear' ? 'CLEAR' : sev.toUpperCase();
|
||||
return '<span class="pill ' + escapeHtml(klass) + '">' + escapeHtml(label) + '</span>';
|
||||
}
|
||||
|
||||
function setMetrics(events) {
|
||||
const active = events.filter(e => String(e.state || '').toLowerCase() === 'active').length;
|
||||
const critical = events.filter(e => String(e.severity || '').toLowerCase() === 'critical').length;
|
||||
const warning = events.filter(e => String(e.severity || '').toLowerCase() === 'warning').length;
|
||||
document.getElementById('metric-total').textContent = String(events.length);
|
||||
document.getElementById('metric-active').textContent = String(active);
|
||||
document.getElementById('metric-critical').textContent = String(critical);
|
||||
document.getElementById('metric-warning').textContent = String(warning);
|
||||
document.getElementById('metric-total-sub').textContent = events.length === allEvents.length ? 'Current fetched set' : 'Filtered view';
|
||||
}
|
||||
|
||||
function renderTable(events) {
|
||||
const body = document.getElementById('alarm-body');
|
||||
if (!body) return;
|
||||
if (!events.length) {
|
||||
body.innerHTML = '<tr><td colspan="7" class="empty" style="padding:24px 10px; text-align:center;">No events match the current filters</td></tr>';
|
||||
setMetrics(events);
|
||||
return;
|
||||
}
|
||||
let html = '';
|
||||
for (const ev of events) {
|
||||
const state = String(ev.state || '').toLowerCase();
|
||||
const value = ev.source === 'plc' ? '--' : formatPct(ev.value);
|
||||
const limit = Number(ev.limit) > 0 ? formatPct(ev.limit) : '--';
|
||||
html += '<tr>' +
|
||||
'<td class="mono">' + escapeHtml(ev.time || '--') + '</td>' +
|
||||
'<td>' + severityPill(ev.severity, state) + '</td>' +
|
||||
'<td style="font-weight:700;">' + escapeHtml(formatSource(ev.source)) + '</td>' +
|
||||
'<td class="mono">' + escapeHtml(state || '--') + '</td>' +
|
||||
'<td>' + escapeHtml(ev.message || '--') + '</td>' +
|
||||
'<td class="right mono">' + escapeHtml(value) + '</td>' +
|
||||
'<td class="right mono">' + escapeHtml(limit) + '</td>' +
|
||||
'</tr>';
|
||||
}
|
||||
body.innerHTML = html;
|
||||
setMetrics(events);
|
||||
}
|
||||
|
||||
function getFilters() {
|
||||
return {
|
||||
severity: document.getElementById('severity-filter').value,
|
||||
source: document.getElementById('source-filter').value,
|
||||
state: document.getElementById('state-filter').value,
|
||||
search: document.getElementById('search-input').value.trim().toLowerCase()
|
||||
};
|
||||
}
|
||||
|
||||
function applyFilters() {
|
||||
const f = getFilters();
|
||||
const out = allEvents.filter(ev => {
|
||||
const sev = String(ev.severity || '').toLowerCase();
|
||||
const src = String(ev.source || '').toLowerCase();
|
||||
const state = String(ev.state || '').toLowerCase();
|
||||
const hay = [ev.time, ev.source, ev.state, ev.message, ev.severity].join(' ').toLowerCase();
|
||||
if (f.severity !== 'all' && sev !== f.severity) return false;
|
||||
if (f.source !== 'all' && src !== f.source) return false;
|
||||
if (f.state !== 'all' && state !== f.state) return false;
|
||||
if (f.search && !hay.includes(f.search)) return false;
|
||||
return true;
|
||||
});
|
||||
renderTable(out);
|
||||
}
|
||||
|
||||
function updateBanner(msg, show) {
|
||||
const el = document.getElementById('license-warning');
|
||||
if (!el) return;
|
||||
el.textContent = msg || '';
|
||||
el.classList.toggle('show', !!show);
|
||||
}
|
||||
|
||||
async function fetchAlarms() {
|
||||
const limit = document.getElementById('limit-select').value || '50';
|
||||
document.getElementById('fetch-status').textContent = 'Status: loading...';
|
||||
try {
|
||||
const res = await fetch('/api/alarms?limit=' + encodeURIComponent(limit), { cache: 'no-store' });
|
||||
if (res.status === 403) {
|
||||
const data = await res.json().catch(() => ({}));
|
||||
const message = data && data.error ? data.error : 'license required';
|
||||
allEvents = [];
|
||||
applyFilters();
|
||||
updateBanner('Alarm API is locked: ' + message + '. Open /license to activate the app.', true);
|
||||
document.getElementById('fetch-status').textContent = 'Status: license locked';
|
||||
return;
|
||||
}
|
||||
if (!res.ok) throw new Error('HTTP ' + res.status);
|
||||
const data = await res.json();
|
||||
allEvents = Array.isArray(data.events) ? data.events : [];
|
||||
applyFilters();
|
||||
updateBanner('', false);
|
||||
document.getElementById('fetch-status').textContent = 'Status: OK';
|
||||
document.getElementById('last-refresh').textContent = 'Last refresh: ' + new Date().toLocaleTimeString();
|
||||
} catch (err) {
|
||||
console.warn('Alarm fetch error:', err);
|
||||
allEvents = [];
|
||||
applyFilters();
|
||||
updateBanner('Could not load alarms. Check app connectivity and browser console.', true);
|
||||
document.getElementById('fetch-status').textContent = 'Status: error';
|
||||
}
|
||||
}
|
||||
|
||||
function exportCSV() {
|
||||
const rows = [['time','severity','source','state','message','value','limit']];
|
||||
const events = allEvents.filter(ev => {
|
||||
const f = getFilters();
|
||||
const sev = String(ev.severity || '').toLowerCase();
|
||||
const src = String(ev.source || '').toLowerCase();
|
||||
const state = String(ev.state || '').toLowerCase();
|
||||
const hay = [ev.time, ev.source, ev.state, ev.message, ev.severity].join(' ').toLowerCase();
|
||||
if (f.severity !== 'all' && sev !== f.severity) return false;
|
||||
if (f.source !== 'all' && src !== f.source) return false;
|
||||
if (f.state !== 'all' && state !== f.state) return false;
|
||||
if (f.search && !hay.includes(f.search)) return false;
|
||||
return true;
|
||||
});
|
||||
for (const ev of events) {
|
||||
rows.push([ev.time || '', ev.severity || '', ev.source || '', ev.state || '', ev.message || '', ev.value ?? '', ev.limit ?? '']);
|
||||
}
|
||||
const csv = rows.map(r => r.map(v => '"' + String(v).replace(/"/g, '""') + '"').join(',')).join('\r\n');
|
||||
const blob = new Blob([csv], { type: 'text/csv;charset=utf-8' });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = 'force-monitor-alarms-' + new Date().toISOString().replace(/[:.]/g, '-') + '.csv';
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
a.remove();
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
|
||||
function syncAutoRefresh() {
|
||||
const enabled = document.getElementById('auto-refresh').checked;
|
||||
if (refreshTimer) clearInterval(refreshTimer);
|
||||
refreshTimer = null;
|
||||
if (enabled) refreshTimer = setInterval(fetchAlarms, 3000);
|
||||
}
|
||||
|
||||
window.addEventListener('DOMContentLoaded', () => {
|
||||
AppUI.initTheme();
|
||||
AppUI.initFullscreen({ buttonId:'fullscreen-toggle' });
|
||||
document.getElementById('refresh-btn').addEventListener('click', fetchAlarms);
|
||||
document.getElementById('export-btn').addEventListener('click', exportCSV);
|
||||
document.getElementById('auto-refresh').addEventListener('change', syncAutoRefresh);
|
||||
['severity-filter','source-filter','state-filter','search-input','limit-select'].forEach(id => {
|
||||
document.getElementById(id).addEventListener(id === 'search-input' ? 'input' : 'change', () => {
|
||||
if (id === 'limit-select') fetchAlarms(); else applyFilters();
|
||||
});
|
||||
});
|
||||
fetchAlarms();
|
||||
syncAutoRefresh();
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -1,176 +1,176 @@
|
|||
(function(){
|
||||
const THEME_KEY = 'force-monitor-theme';
|
||||
const FULLSCREEN_INTENT_KEY = 'force-monitor-fullscreen-intent';
|
||||
|
||||
function byId(id){ return id ? document.getElementById(id) : null; }
|
||||
|
||||
function getFullscreenIntent(){
|
||||
try { return sessionStorage.getItem(FULLSCREEN_INTENT_KEY) === '1'; } catch (_) { return false; }
|
||||
}
|
||||
|
||||
function setFullscreenIntent(enabled){
|
||||
try { sessionStorage.setItem(FULLSCREEN_INTENT_KEY, enabled ? '1' : '0'); } catch (_) {}
|
||||
}
|
||||
|
||||
function setTheme(theme, opts){
|
||||
opts = opts || {};
|
||||
const t = theme === 'light' ? 'light' : 'dark';
|
||||
document.body.setAttribute('data-theme', t);
|
||||
try { localStorage.setItem(THEME_KEY, t); } catch (_) {}
|
||||
const btn = byId(opts.buttonId || 'theme-toggle');
|
||||
if (btn) btn.textContent = t === 'light' ? 'Dark theme' : 'Light theme';
|
||||
if (typeof opts.onChange === 'function') opts.onChange(t);
|
||||
return t;
|
||||
}
|
||||
|
||||
function initTheme(opts){
|
||||
opts = opts || {};
|
||||
let theme = 'dark';
|
||||
try {
|
||||
const stored = localStorage.getItem(THEME_KEY);
|
||||
if (stored === 'light' || stored === 'dark') theme = stored;
|
||||
else if (window.matchMedia && window.matchMedia('(prefers-color-scheme: light)').matches) theme = 'light';
|
||||
} catch (_) {}
|
||||
setTheme(theme, opts);
|
||||
const btn = byId(opts.buttonId || 'theme-toggle');
|
||||
if (btn && !btn.dataset.themeBound) {
|
||||
btn.dataset.themeBound = '1';
|
||||
btn.addEventListener('click', function(){
|
||||
setTheme(document.body.getAttribute('data-theme') === 'light' ? 'dark' : 'light', opts);
|
||||
});
|
||||
}
|
||||
return theme;
|
||||
}
|
||||
|
||||
function updateFullscreenButton(buttonId){
|
||||
const btn = byId(buttonId || 'fullscreen-toggle');
|
||||
if (!btn) return;
|
||||
if (document.fullscreenElement) {
|
||||
btn.textContent = 'Exit fullscreen';
|
||||
return;
|
||||
}
|
||||
btn.textContent = getFullscreenIntent() ? 'Restore fullscreen' : 'Enter fullscreen';
|
||||
}
|
||||
|
||||
async function requestFullscreenSafe(){
|
||||
if (document.fullscreenElement) return true;
|
||||
if (!document.fullscreenEnabled) return false;
|
||||
try {
|
||||
await document.documentElement.requestFullscreen();
|
||||
setFullscreenIntent(true);
|
||||
return true;
|
||||
} catch (err) {
|
||||
console.warn('Fullscreen restore/request blocked:', err);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async function toggleFullscreen(buttonId){
|
||||
try {
|
||||
if (!document.fullscreenElement) {
|
||||
await requestFullscreenSafe();
|
||||
} else {
|
||||
setFullscreenIntent(false);
|
||||
await document.exitFullscreen();
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn('Fullscreen error:', err);
|
||||
} finally {
|
||||
updateFullscreenButton(buttonId || 'fullscreen-toggle');
|
||||
}
|
||||
}
|
||||
|
||||
function bindFullscreenNavPersistence(){
|
||||
if (document.documentElement.dataset.fsNavBound) return;
|
||||
document.documentElement.dataset.fsNavBound = '1';
|
||||
|
||||
document.addEventListener('click', function(ev){
|
||||
const link = ev.target && ev.target.closest ? ev.target.closest('a[href]') : null;
|
||||
if (!link) return;
|
||||
const href = link.getAttribute('href') || '';
|
||||
const target = link.getAttribute('target') || '';
|
||||
if (!href || href.startsWith('#') || target === '_blank' || link.hasAttribute('download')) return;
|
||||
try {
|
||||
const url = new URL(link.href, window.location.href);
|
||||
if (url.origin !== window.location.origin) return;
|
||||
} catch (_) {
|
||||
return;
|
||||
}
|
||||
if (document.fullscreenElement || getFullscreenIntent()) {
|
||||
setFullscreenIntent(true);
|
||||
}
|
||||
}, true);
|
||||
|
||||
window.addEventListener('pageshow', function(){
|
||||
document.querySelectorAll('#fullscreen-toggle, #fullscreen-btn').forEach(function(el){
|
||||
updateFullscreenButton(el.id);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function initFullscreen(opts){
|
||||
opts = opts || {};
|
||||
const buttonId = opts.buttonId || 'fullscreen-toggle';
|
||||
const btn = byId(buttonId);
|
||||
if (btn && !btn.dataset.fsBound) {
|
||||
btn.dataset.fsBound = '1';
|
||||
btn.addEventListener('click', function(){ toggleFullscreen(buttonId); });
|
||||
}
|
||||
if (!document.documentElement.dataset.fsListenerBound) {
|
||||
document.documentElement.dataset.fsListenerBound = '1';
|
||||
document.addEventListener('fullscreenchange', function(){
|
||||
setFullscreenIntent(!!document.fullscreenElement);
|
||||
document.querySelectorAll('#fullscreen-toggle, #fullscreen-btn').forEach(function(el){
|
||||
updateFullscreenButton(el.id);
|
||||
});
|
||||
});
|
||||
}
|
||||
bindFullscreenNavPersistence();
|
||||
updateFullscreenButton(buttonId);
|
||||
|
||||
if (getFullscreenIntent() && !document.fullscreenElement) {
|
||||
// Best effort only: some browsers require a fresh user gesture after navigation.
|
||||
requestAnimationFrame(function(){
|
||||
requestFullscreenSafe().finally(function(){ updateFullscreenButton(buttonId); });
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchJson(url, opts){
|
||||
opts = opts || {};
|
||||
const controller = new AbortController();
|
||||
const timeoutMs = opts.timeoutMs || 8000;
|
||||
const timer = setTimeout(function(){ controller.abort(); }, timeoutMs);
|
||||
try {
|
||||
const res = await fetch(url, {
|
||||
method: opts.method || 'GET',
|
||||
headers: opts.headers || undefined,
|
||||
body: opts.body,
|
||||
cache: 'no-store',
|
||||
signal: controller.signal
|
||||
});
|
||||
let data = null;
|
||||
try { data = await res.json(); } catch (_) { data = null; }
|
||||
if (!res.ok) {
|
||||
const err = new Error(data && data.error ? data.error : ('HTTP ' + res.status));
|
||||
err.response = res;
|
||||
err.data = data;
|
||||
throw err;
|
||||
}
|
||||
return data;
|
||||
} finally {
|
||||
clearTimeout(timer);
|
||||
}
|
||||
}
|
||||
|
||||
window.AppUI = {
|
||||
setTheme,
|
||||
initTheme,
|
||||
updateFullscreenButton,
|
||||
toggleFullscreen,
|
||||
initFullscreen,
|
||||
fetchJson,
|
||||
getFullscreenIntent,
|
||||
setFullscreenIntent
|
||||
};
|
||||
})();
|
||||
(function(){
|
||||
const THEME_KEY = 'force-monitor-theme';
|
||||
const FULLSCREEN_INTENT_KEY = 'force-monitor-fullscreen-intent';
|
||||
|
||||
function byId(id){ return id ? document.getElementById(id) : null; }
|
||||
|
||||
function getFullscreenIntent(){
|
||||
try { return sessionStorage.getItem(FULLSCREEN_INTENT_KEY) === '1'; } catch (_) { return false; }
|
||||
}
|
||||
|
||||
function setFullscreenIntent(enabled){
|
||||
try { sessionStorage.setItem(FULLSCREEN_INTENT_KEY, enabled ? '1' : '0'); } catch (_) {}
|
||||
}
|
||||
|
||||
function setTheme(theme, opts){
|
||||
opts = opts || {};
|
||||
const t = theme === 'light' ? 'light' : 'dark';
|
||||
document.body.setAttribute('data-theme', t);
|
||||
try { localStorage.setItem(THEME_KEY, t); } catch (_) {}
|
||||
const btn = byId(opts.buttonId || 'theme-toggle');
|
||||
if (btn) btn.textContent = t === 'light' ? 'Dark theme' : 'Light theme';
|
||||
if (typeof opts.onChange === 'function') opts.onChange(t);
|
||||
return t;
|
||||
}
|
||||
|
||||
function initTheme(opts){
|
||||
opts = opts || {};
|
||||
let theme = 'dark';
|
||||
try {
|
||||
const stored = localStorage.getItem(THEME_KEY);
|
||||
if (stored === 'light' || stored === 'dark') theme = stored;
|
||||
else if (window.matchMedia && window.matchMedia('(prefers-color-scheme: light)').matches) theme = 'light';
|
||||
} catch (_) {}
|
||||
setTheme(theme, opts);
|
||||
const btn = byId(opts.buttonId || 'theme-toggle');
|
||||
if (btn && !btn.dataset.themeBound) {
|
||||
btn.dataset.themeBound = '1';
|
||||
btn.addEventListener('click', function(){
|
||||
setTheme(document.body.getAttribute('data-theme') === 'light' ? 'dark' : 'light', opts);
|
||||
});
|
||||
}
|
||||
return theme;
|
||||
}
|
||||
|
||||
function updateFullscreenButton(buttonId){
|
||||
const btn = byId(buttonId || 'fullscreen-toggle');
|
||||
if (!btn) return;
|
||||
if (document.fullscreenElement) {
|
||||
btn.textContent = 'Exit fullscreen';
|
||||
return;
|
||||
}
|
||||
btn.textContent = getFullscreenIntent() ? 'Restore fullscreen' : 'Enter fullscreen';
|
||||
}
|
||||
|
||||
async function requestFullscreenSafe(){
|
||||
if (document.fullscreenElement) return true;
|
||||
if (!document.fullscreenEnabled) return false;
|
||||
try {
|
||||
await document.documentElement.requestFullscreen();
|
||||
setFullscreenIntent(true);
|
||||
return true;
|
||||
} catch (err) {
|
||||
console.warn('Fullscreen restore/request blocked:', err);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async function toggleFullscreen(buttonId){
|
||||
try {
|
||||
if (!document.fullscreenElement) {
|
||||
await requestFullscreenSafe();
|
||||
} else {
|
||||
setFullscreenIntent(false);
|
||||
await document.exitFullscreen();
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn('Fullscreen error:', err);
|
||||
} finally {
|
||||
updateFullscreenButton(buttonId || 'fullscreen-toggle');
|
||||
}
|
||||
}
|
||||
|
||||
function bindFullscreenNavPersistence(){
|
||||
if (document.documentElement.dataset.fsNavBound) return;
|
||||
document.documentElement.dataset.fsNavBound = '1';
|
||||
|
||||
document.addEventListener('click', function(ev){
|
||||
const link = ev.target && ev.target.closest ? ev.target.closest('a[href]') : null;
|
||||
if (!link) return;
|
||||
const href = link.getAttribute('href') || '';
|
||||
const target = link.getAttribute('target') || '';
|
||||
if (!href || href.startsWith('#') || target === '_blank' || link.hasAttribute('download')) return;
|
||||
try {
|
||||
const url = new URL(link.href, window.location.href);
|
||||
if (url.origin !== window.location.origin) return;
|
||||
} catch (_) {
|
||||
return;
|
||||
}
|
||||
if (document.fullscreenElement || getFullscreenIntent()) {
|
||||
setFullscreenIntent(true);
|
||||
}
|
||||
}, true);
|
||||
|
||||
window.addEventListener('pageshow', function(){
|
||||
document.querySelectorAll('#fullscreen-toggle, #fullscreen-btn').forEach(function(el){
|
||||
updateFullscreenButton(el.id);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function initFullscreen(opts){
|
||||
opts = opts || {};
|
||||
const buttonId = opts.buttonId || 'fullscreen-toggle';
|
||||
const btn = byId(buttonId);
|
||||
if (btn && !btn.dataset.fsBound) {
|
||||
btn.dataset.fsBound = '1';
|
||||
btn.addEventListener('click', function(){ toggleFullscreen(buttonId); });
|
||||
}
|
||||
if (!document.documentElement.dataset.fsListenerBound) {
|
||||
document.documentElement.dataset.fsListenerBound = '1';
|
||||
document.addEventListener('fullscreenchange', function(){
|
||||
setFullscreenIntent(!!document.fullscreenElement);
|
||||
document.querySelectorAll('#fullscreen-toggle, #fullscreen-btn').forEach(function(el){
|
||||
updateFullscreenButton(el.id);
|
||||
});
|
||||
});
|
||||
}
|
||||
bindFullscreenNavPersistence();
|
||||
updateFullscreenButton(buttonId);
|
||||
|
||||
if (getFullscreenIntent() && !document.fullscreenElement) {
|
||||
// Best effort only: some browsers require a fresh user gesture after navigation.
|
||||
requestAnimationFrame(function(){
|
||||
requestFullscreenSafe().finally(function(){ updateFullscreenButton(buttonId); });
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchJson(url, opts){
|
||||
opts = opts || {};
|
||||
const controller = new AbortController();
|
||||
const timeoutMs = opts.timeoutMs || 8000;
|
||||
const timer = setTimeout(function(){ controller.abort(); }, timeoutMs);
|
||||
try {
|
||||
const res = await fetch(url, {
|
||||
method: opts.method || 'GET',
|
||||
headers: opts.headers || undefined,
|
||||
body: opts.body,
|
||||
cache: 'no-store',
|
||||
signal: controller.signal
|
||||
});
|
||||
let data = null;
|
||||
try { data = await res.json(); } catch (_) { data = null; }
|
||||
if (!res.ok) {
|
||||
const err = new Error(data && data.error ? data.error : ('HTTP ' + res.status));
|
||||
err.response = res;
|
||||
err.data = data;
|
||||
throw err;
|
||||
}
|
||||
return data;
|
||||
} finally {
|
||||
clearTimeout(timer);
|
||||
}
|
||||
}
|
||||
|
||||
window.AppUI = {
|
||||
setTheme,
|
||||
initTheme,
|
||||
updateFullscreenButton,
|
||||
toggleFullscreen,
|
||||
initFullscreen,
|
||||
fetchJson,
|
||||
getFullscreenIntent,
|
||||
setFullscreenIntent
|
||||
};
|
||||
})();
|
||||
|
|
|
|||
1090
static/history.html
1090
static/history.html
File diff suppressed because it is too large
Load diff
2834
static/index.html
2834
static/index.html
File diff suppressed because it is too large
Load diff
|
|
@ -1,104 +1,104 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Force Monitor — Kiosk</title>
|
||||
<style>
|
||||
.btn.primary { background:rgba(14,165,233,0.14); border-color:rgba(14,165,233,0.35); }
|
||||
:root{--bg1:#030712;--bg2:#0f172a;--panel:rgba(255,255,255,.06);--border:rgba(255,255,255,.1);--text:#f8fafc;--muted:#94a3b8;--ok:#34d399;--warn:#facc15;--bad:#f87171;}
|
||||
body[data-theme="light"]{--bg1:#eef4ff;--bg2:#f8fafc;--panel:rgba(255,255,255,.84);--border:rgba(15,23,42,.10);--text:#0f172a;--muted:#475569;--ok:#059669;--warn:#b45309;--bad:#dc2626;}
|
||||
*{box-sizing:border-box} body{margin:0;min-height:100vh;color:var(--text);font-family:'Segoe UI',system-ui,sans-serif;background:radial-gradient(circle at 20% 10%, rgba(56,189,248,.14), transparent 20%),radial-gradient(circle at 80% 10%, rgba(168,85,247,.14), transparent 18%),linear-gradient(180deg,var(--bg1),var(--bg2));}
|
||||
body[data-theme="light"]{background:radial-gradient(circle at 20% 10%, rgba(14,165,233,.10), transparent 20%),radial-gradient(circle at 80% 10%, rgba(168,85,247,.10), transparent 18%),linear-gradient(180deg,var(--bg1),var(--bg2));}
|
||||
.wrap{width:min(96vw,1800px);margin:0 auto;padding:18px 22px 28px;} .row,.nav{display:flex;gap:12px;flex-wrap:wrap;align-items:center}.spacer{flex:1 1 auto}
|
||||
.btn{display:inline-flex;align-items:center;justify-content:center;min-height:42px;padding:10px 14px;border-radius:14px;border:1px solid var(--border);background:rgba(255,255,255,.05);color:var(--text);text-decoration:none;font-weight:600;cursor:pointer}
|
||||
body[data-theme="light"] .btn{background:rgba(255,255,255,.88);}
|
||||
.glass{background:var(--panel);border:1px solid var(--border);border-radius:24px;backdrop-filter:blur(14px);-webkit-backdrop-filter:blur(14px)}
|
||||
.hero{padding:18px 24px;margin-bottom:18px}.status{font-size:64px;font-weight:900;line-height:1;margin-top:12px}.sub{color:var(--muted)} .mono{font-family:ui-monospace,SFMono-Regular,Consolas,monospace}
|
||||
.grid{display:grid;gap:16px}.cards{grid-template-columns:repeat(4,minmax(0,1fr));margin-bottom:18px}.card{padding:22px 24px}.label{font-size:12px;letter-spacing:.22em;text-transform:uppercase;color:var(--muted)} .value{font-size:54px;font-weight:900;line-height:1;margin-top:12px}
|
||||
.small{font-size:18px;color:var(--muted);margin-top:10px}.banner{padding:16px 18px;border-radius:18px;border:1px solid rgba(239,68,68,.35);background:rgba(239,68,68,.14);display:none;margin-bottom:16px}.banner.show{display:block}
|
||||
.ok{color:var(--ok)} .warning{color:var(--warn)} .critical{color:var(--bad)} .neutral{color:var(--muted)}
|
||||
.split{display:grid;grid-template-columns:1.35fr .85fr;gap:16px}.panel{padding:18px 22px} ul{margin:12px 0 0;padding-left:18px} li{margin:8px 0;color:var(--muted)}
|
||||
@media (max-width:1200px){.cards{grid-template-columns:repeat(2,minmax(0,1fr))}.split{grid-template-columns:1fr}.value{font-size:42px}.status{font-size:48px}}
|
||||
@media (max-width:760px){.cards{grid-template-columns:1fr}.wrap{padding:14px}.value{font-size:36px}.status{font-size:38px}}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="wrap">
|
||||
<div class="nav" style="margin-bottom:14px">
|
||||
<a class="btn" href="/">Dashboard</a><a class="btn" href="/history">History</a><a class="btn" href="/alarms">Alarms</a><a class="btn primary" href="/kiosk">Kiosk</a><a class="btn" href="/process-capability">Process capability</a><a class="btn" href="/reports">Reports</a><a class="btn" href="/license">License</a>
|
||||
<div class="spacer"></div><button id="theme-toggle" class="btn" type="button">Light theme</button><button id="fullscreen-btn" class="btn" type="button">Enter fullscreen</button>
|
||||
</div>
|
||||
<div id="alarm-banner" class="banner"></div>
|
||||
<div class="glass hero">
|
||||
<div class="row"><div><div class="label" id="title-kicker">Force Monitor</div><div class="status" id="status-text">LOADING</div><div class="sub" id="status-reason">Preparing kiosk view…</div></div><div class="spacer"></div><div class="mono sub" id="clock">--</div></div>
|
||||
</div>
|
||||
<div class="grid cards">
|
||||
<div class="glass card"><div class="label">Total peak</div><div id="total-value" class="value mono">--</div><div id="total-sub" class="small">kN / %</div></div>
|
||||
<div class="glass card"><div class="label">Left</div><div id="left-value" class="value mono">--</div><div id="left-sub" class="small">kN / %</div></div>
|
||||
<div class="glass card"><div class="label">Right</div><div id="right-value" class="value mono">--</div><div id="right-sub" class="small">kN / %</div></div>
|
||||
<div class="glass card"><div class="label">Imbalance</div><div id="imb-value" class="value mono">--</div><div id="imb-sub" class="small">bias / trend</div></div>
|
||||
</div>
|
||||
<div class="split">
|
||||
<div class="glass panel">
|
||||
<div class="row"><h2 style="margin:0;font-size:30px">Live production verdict</h2><div class="spacer"></div><span id="stale-pill" class="mono sub">Data freshness: --</span></div>
|
||||
<div id="verdict-summary" class="status neutral" style="font-size:56px;margin-top:14px">WAITING</div>
|
||||
<div id="verdict-detail" class="sub" style="font-size:22px;margin-top:12px">No PLC data yet.</div>
|
||||
<div class="row" style="margin-top:22px">
|
||||
<div class="glass" style="padding:14px 16px;min-width:220px"><div class="label">Trend direction</div><div id="trend-force" class="value mono" style="font-size:32px">--</div><div id="trend-force-sub" class="small">force drift</div></div>
|
||||
<div class="glass" style="padding:14px 16px;min-width:220px"><div class="label">Process stability</div><div id="trend-stability" class="value mono" style="font-size:32px">--</div><div id="trend-stability-sub" class="small">stability</div></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="glass panel">
|
||||
<div class="row"><h2 style="margin:0;font-size:28px">Active attention items</h2><div class="spacer"></div><span class="sub mono" id="last-refresh">Last refresh: --</span></div>
|
||||
<ul id="attention-list"><li>Loading live status…</li></ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="/static/app-common.js"></script>
|
||||
<script>
|
||||
let cfg={ui:{title:'Force Monitor',unit_force:'kN',unit_percent:'%'},thresholds:{warning_percent:80,critical_percent:95,imbalance_warning_percent:10,imbalance_critical_percent:20}};
|
||||
const fmt=(n,d=1)=>Number(n||0).toFixed(d); const cls=(z)=>z==='critical'?'critical':z==='warning'?'warning':'ok';
|
||||
function zone(v,w,c){return v>=c?'critical':v>=w?'warning':'ok'}
|
||||
function setThemeTitle(){document.getElementById('title-kicker').textContent=cfg.ui.title+' • kiosk'}
|
||||
async function loadCfg(){try{const r=await fetch('/api/config/public',{cache:'no-store'}); if(r.ok){cfg=await r.json(); setThemeTitle();}}catch(e){}}
|
||||
async function refreshAll(){
|
||||
try{
|
||||
const [dataRes, trendRes, alarmsRes]=await Promise.all([
|
||||
fetch('/api/data',{cache:'no-store'}), fetch('/api/trend?window=15m',{cache:'no-store'}), fetch('/api/alarms?limit=8',{cache:'no-store'})
|
||||
]);
|
||||
if(dataRes.status===403){document.getElementById('status-text').textContent='LICENSE REQUIRED';document.getElementById('status-text').className='status critical';document.getElementById('status-reason').textContent='Open /license to activate the application.';return;}
|
||||
const d=await dataRes.json(); const t=trendRes.ok?await trendRes.json():{}; const a=alarmsRes.ok?await alarmsRes.json():{events:[]};
|
||||
const connected=!!d.connected, stale=!!d.stale; const lp=Number(d.sila_l)||0, rp=Number(d.sila_r)||0, tp=Number(d.sum_percent)||0, tkn=Number(d.sum_kn)||0, imb=Number(d.imbalance_percent)||0, bias=Number(d.bias_percent)||0;
|
||||
const lkn=Number(d.sila_l_kn)||0, rkn=Number(d.sila_r_kn)||0;
|
||||
document.getElementById('clock').textContent=new Date().toLocaleString(); document.getElementById('last-refresh').textContent='Last refresh: '+new Date().toLocaleTimeString();
|
||||
document.getElementById('total-value').textContent=fmt(tkn,1)+' '+(cfg.ui.unit_force||'kN'); document.getElementById('total-sub').textContent=fmt(tp,1)+(cfg.ui.unit_percent||'%')+' total load';
|
||||
document.getElementById('left-value').textContent=fmt(lp,1)+(cfg.ui.unit_percent||'%'); document.getElementById('left-sub').textContent=fmt(lkn,1)+' '+(cfg.ui.unit_force||'kN');
|
||||
document.getElementById('right-value').textContent=fmt(rp,1)+(cfg.ui.unit_percent||'%'); document.getElementById('right-sub').textContent=fmt(rkn,1)+' '+(cfg.ui.unit_force||'kN');
|
||||
document.getElementById('imb-value').textContent=fmt(imb,1)+(cfg.ui.unit_percent||'%'); document.getElementById('imb-sub').textContent='Bias '+fmt(bias,1)+(cfg.ui.unit_percent||'%');
|
||||
const zForce=zone(Math.max(lp,rp),cfg.thresholds.warning_percent,cfg.thresholds.critical_percent); const zImb=zone(imb,cfg.thresholds.imbalance_warning_percent,cfg.thresholds.imbalance_critical_percent);
|
||||
const statusEl=document.getElementById('status-text'); const reasonEl=document.getElementById('status-reason'); const verdict=document.getElementById('verdict-summary'); const detail=document.getElementById('verdict-detail');
|
||||
let verdictText='OK', reason='Production looks stable.'; let level='ok';
|
||||
if(!connected){ verdictText='PLC OFFLINE'; reason='No PLC communication.'; level='critical'; }
|
||||
else if(stale){ verdictText='STALE DATA'; reason='PLC connected, but no fresh values are arriving.'; level='warning'; }
|
||||
else if(zForce==='critical' || zImb==='critical'){ verdictText='CRITICAL'; reason='Force or imbalance reached critical region.'; level='critical'; }
|
||||
else if(zForce==='warning' || zImb==='warning'){ verdictText='WARNING'; reason='Process is above warning thresholds.'; level='warning'; }
|
||||
statusEl.textContent=verdictText; statusEl.className='status '+level; reasonEl.textContent=reason; verdict.textContent=verdictText; verdict.className='status '+level; detail.textContent=reason;
|
||||
document.getElementById('stale-pill').textContent='Data freshness: '+(stale?'stale':connected?'fresh':'offline');
|
||||
document.getElementById('trend-force').textContent=((Number(t.force_delta_pct)||0)>=0?'+':'')+fmt(t.force_delta_pct,1)+(cfg.ui.unit_percent||'%');
|
||||
document.getElementById('trend-force').className='value mono '+(((Number(t.force_delta_pct)||0)>=3)?'warning':'ok');
|
||||
document.getElementById('trend-force-sub').textContent=(t.force_direction||'--')+' over 15m';
|
||||
document.getElementById('trend-stability').textContent=String(t.process_stability||'--').toUpperCase();
|
||||
document.getElementById('trend-stability').className='value mono '+(t.process_stability==='unstable'?'critical':t.process_stability==='caution'?'warning':'ok');
|
||||
document.getElementById('trend-stability-sub').textContent=t.stability_reason||'No trend reason';
|
||||
const attention=[]; if(!connected) attention.push('Restore PLC communication to recover live monitoring.'); if(stale) attention.push('Investigate stale data path between PLC and the app.'); if(zForce!=='ok') attention.push('Force level is '+zForce+'; review current load and top-force causes.'); if(zImb!=='ok') attention.push('Imbalance is '+zImb+'; check centering, alignment, and tooling.');
|
||||
(a.events||[]).slice(0,4).forEach(ev=>{if(ev.severity!=='info') attention.push((ev.time||'')+' • '+(ev.message||''));});
|
||||
const ul=document.getElementById('attention-list'); ul.innerHTML=''; (attention.length?attention:['No active attention items.']).forEach(item=>{const li=document.createElement('li'); li.textContent=item; ul.appendChild(li);});
|
||||
const banner=document.getElementById('alarm-banner'); if(level==='critical'){banner.textContent='Critical attention required — review force, imbalance, or PLC connectivity.'; banner.classList.add('show');} else if(level==='warning'){banner.textContent='Warning condition active — process should be reviewed.'; banner.classList.add('show');} else {banner.classList.remove('show');}
|
||||
}catch(err){console.warn(err)}
|
||||
}
|
||||
AppUI.initTheme(); AppUI.initFullscreen({ buttonId:'fullscreen-btn' });
|
||||
loadCfg().then(refreshAll); setInterval(refreshAll, 1500);
|
||||
</script>
|
||||
</body>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Force Monitor — Kiosk</title>
|
||||
<style>
|
||||
.btn.primary { background:rgba(14,165,233,0.14); border-color:rgba(14,165,233,0.35); }
|
||||
:root{--bg1:#030712;--bg2:#0f172a;--panel:rgba(255,255,255,.06);--border:rgba(255,255,255,.1);--text:#f8fafc;--muted:#94a3b8;--ok:#34d399;--warn:#facc15;--bad:#f87171;}
|
||||
body[data-theme="light"]{--bg1:#eef4ff;--bg2:#f8fafc;--panel:rgba(255,255,255,.84);--border:rgba(15,23,42,.10);--text:#0f172a;--muted:#475569;--ok:#059669;--warn:#b45309;--bad:#dc2626;}
|
||||
*{box-sizing:border-box} body{margin:0;min-height:100vh;color:var(--text);font-family:'Segoe UI',system-ui,sans-serif;background:radial-gradient(circle at 20% 10%, rgba(56,189,248,.14), transparent 20%),radial-gradient(circle at 80% 10%, rgba(168,85,247,.14), transparent 18%),linear-gradient(180deg,var(--bg1),var(--bg2));}
|
||||
body[data-theme="light"]{background:radial-gradient(circle at 20% 10%, rgba(14,165,233,.10), transparent 20%),radial-gradient(circle at 80% 10%, rgba(168,85,247,.10), transparent 18%),linear-gradient(180deg,var(--bg1),var(--bg2));}
|
||||
.wrap{width:min(96vw,1800px);margin:0 auto;padding:18px 22px 28px;} .row,.nav{display:flex;gap:12px;flex-wrap:wrap;align-items:center}.spacer{flex:1 1 auto}
|
||||
.btn{display:inline-flex;align-items:center;justify-content:center;min-height:42px;padding:10px 14px;border-radius:14px;border:1px solid var(--border);background:rgba(255,255,255,.05);color:var(--text);text-decoration:none;font-weight:600;cursor:pointer}
|
||||
body[data-theme="light"] .btn{background:rgba(255,255,255,.88);}
|
||||
.glass{background:var(--panel);border:1px solid var(--border);border-radius:24px;backdrop-filter:blur(14px);-webkit-backdrop-filter:blur(14px)}
|
||||
.hero{padding:18px 24px;margin-bottom:18px}.status{font-size:64px;font-weight:900;line-height:1;margin-top:12px}.sub{color:var(--muted)} .mono{font-family:ui-monospace,SFMono-Regular,Consolas,monospace}
|
||||
.grid{display:grid;gap:16px}.cards{grid-template-columns:repeat(4,minmax(0,1fr));margin-bottom:18px}.card{padding:22px 24px}.label{font-size:12px;letter-spacing:.22em;text-transform:uppercase;color:var(--muted)} .value{font-size:54px;font-weight:900;line-height:1;margin-top:12px}
|
||||
.small{font-size:18px;color:var(--muted);margin-top:10px}.banner{padding:16px 18px;border-radius:18px;border:1px solid rgba(239,68,68,.35);background:rgba(239,68,68,.14);display:none;margin-bottom:16px}.banner.show{display:block}
|
||||
.ok{color:var(--ok)} .warning{color:var(--warn)} .critical{color:var(--bad)} .neutral{color:var(--muted)}
|
||||
.split{display:grid;grid-template-columns:1.35fr .85fr;gap:16px}.panel{padding:18px 22px} ul{margin:12px 0 0;padding-left:18px} li{margin:8px 0;color:var(--muted)}
|
||||
@media (max-width:1200px){.cards{grid-template-columns:repeat(2,minmax(0,1fr))}.split{grid-template-columns:1fr}.value{font-size:42px}.status{font-size:48px}}
|
||||
@media (max-width:760px){.cards{grid-template-columns:1fr}.wrap{padding:14px}.value{font-size:36px}.status{font-size:38px}}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="wrap">
|
||||
<div class="nav" style="margin-bottom:14px">
|
||||
<a class="btn" href="/">Dashboard</a><a class="btn" href="/history">History</a><a class="btn" href="/alarms">Alarms</a><a class="btn primary" href="/kiosk">Kiosk</a><a class="btn" href="/process-capability">Process capability</a><a class="btn" href="/reports">Reports</a><a class="btn" href="/license">License</a>
|
||||
<div class="spacer"></div><button id="theme-toggle" class="btn" type="button">Light theme</button><button id="fullscreen-btn" class="btn" type="button">Enter fullscreen</button>
|
||||
</div>
|
||||
<div id="alarm-banner" class="banner"></div>
|
||||
<div class="glass hero">
|
||||
<div class="row"><div><div class="label" id="title-kicker">Force Monitor</div><div class="status" id="status-text">LOADING</div><div class="sub" id="status-reason">Preparing kiosk view…</div></div><div class="spacer"></div><div class="mono sub" id="clock">--</div></div>
|
||||
</div>
|
||||
<div class="grid cards">
|
||||
<div class="glass card"><div class="label">Total peak</div><div id="total-value" class="value mono">--</div><div id="total-sub" class="small">kN / %</div></div>
|
||||
<div class="glass card"><div class="label">Left</div><div id="left-value" class="value mono">--</div><div id="left-sub" class="small">kN / %</div></div>
|
||||
<div class="glass card"><div class="label">Right</div><div id="right-value" class="value mono">--</div><div id="right-sub" class="small">kN / %</div></div>
|
||||
<div class="glass card"><div class="label">Imbalance</div><div id="imb-value" class="value mono">--</div><div id="imb-sub" class="small">bias / trend</div></div>
|
||||
</div>
|
||||
<div class="split">
|
||||
<div class="glass panel">
|
||||
<div class="row"><h2 style="margin:0;font-size:30px">Live production verdict</h2><div class="spacer"></div><span id="stale-pill" class="mono sub">Data freshness: --</span></div>
|
||||
<div id="verdict-summary" class="status neutral" style="font-size:56px;margin-top:14px">WAITING</div>
|
||||
<div id="verdict-detail" class="sub" style="font-size:22px;margin-top:12px">No PLC data yet.</div>
|
||||
<div class="row" style="margin-top:22px">
|
||||
<div class="glass" style="padding:14px 16px;min-width:220px"><div class="label">Trend direction</div><div id="trend-force" class="value mono" style="font-size:32px">--</div><div id="trend-force-sub" class="small">force drift</div></div>
|
||||
<div class="glass" style="padding:14px 16px;min-width:220px"><div class="label">Process stability</div><div id="trend-stability" class="value mono" style="font-size:32px">--</div><div id="trend-stability-sub" class="small">stability</div></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="glass panel">
|
||||
<div class="row"><h2 style="margin:0;font-size:28px">Active attention items</h2><div class="spacer"></div><span class="sub mono" id="last-refresh">Last refresh: --</span></div>
|
||||
<ul id="attention-list"><li>Loading live status…</li></ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="/static/app-common.js"></script>
|
||||
<script>
|
||||
let cfg={ui:{title:'Force Monitor',unit_force:'kN',unit_percent:'%'},thresholds:{warning_percent:80,critical_percent:95,imbalance_warning_percent:10,imbalance_critical_percent:20}};
|
||||
const fmt=(n,d=1)=>Number(n||0).toFixed(d); const cls=(z)=>z==='critical'?'critical':z==='warning'?'warning':'ok';
|
||||
function zone(v,w,c){return v>=c?'critical':v>=w?'warning':'ok'}
|
||||
function setThemeTitle(){document.getElementById('title-kicker').textContent=cfg.ui.title+' • kiosk'}
|
||||
async function loadCfg(){try{const r=await fetch('/api/config/public',{cache:'no-store'}); if(r.ok){cfg=await r.json(); setThemeTitle();}}catch(e){}}
|
||||
async function refreshAll(){
|
||||
try{
|
||||
const [dataRes, trendRes, alarmsRes]=await Promise.all([
|
||||
fetch('/api/data',{cache:'no-store'}), fetch('/api/trend?window=15m',{cache:'no-store'}), fetch('/api/alarms?limit=8',{cache:'no-store'})
|
||||
]);
|
||||
if(dataRes.status===403){document.getElementById('status-text').textContent='LICENSE REQUIRED';document.getElementById('status-text').className='status critical';document.getElementById('status-reason').textContent='Open /license to activate the application.';return;}
|
||||
const d=await dataRes.json(); const t=trendRes.ok?await trendRes.json():{}; const a=alarmsRes.ok?await alarmsRes.json():{events:[]};
|
||||
const connected=!!d.connected, stale=!!d.stale; const lp=Number(d.sila_l)||0, rp=Number(d.sila_r)||0, tp=Number(d.sum_percent)||0, tkn=Number(d.sum_kn)||0, imb=Number(d.imbalance_percent)||0, bias=Number(d.bias_percent)||0;
|
||||
const lkn=Number(d.sila_l_kn)||0, rkn=Number(d.sila_r_kn)||0;
|
||||
document.getElementById('clock').textContent=new Date().toLocaleString(); document.getElementById('last-refresh').textContent='Last refresh: '+new Date().toLocaleTimeString();
|
||||
document.getElementById('total-value').textContent=fmt(tkn,1)+' '+(cfg.ui.unit_force||'kN'); document.getElementById('total-sub').textContent=fmt(tp,1)+(cfg.ui.unit_percent||'%')+' total load';
|
||||
document.getElementById('left-value').textContent=fmt(lp,1)+(cfg.ui.unit_percent||'%'); document.getElementById('left-sub').textContent=fmt(lkn,1)+' '+(cfg.ui.unit_force||'kN');
|
||||
document.getElementById('right-value').textContent=fmt(rp,1)+(cfg.ui.unit_percent||'%'); document.getElementById('right-sub').textContent=fmt(rkn,1)+' '+(cfg.ui.unit_force||'kN');
|
||||
document.getElementById('imb-value').textContent=fmt(imb,1)+(cfg.ui.unit_percent||'%'); document.getElementById('imb-sub').textContent='Bias '+fmt(bias,1)+(cfg.ui.unit_percent||'%');
|
||||
const zForce=zone(Math.max(lp,rp),cfg.thresholds.warning_percent,cfg.thresholds.critical_percent); const zImb=zone(imb,cfg.thresholds.imbalance_warning_percent,cfg.thresholds.imbalance_critical_percent);
|
||||
const statusEl=document.getElementById('status-text'); const reasonEl=document.getElementById('status-reason'); const verdict=document.getElementById('verdict-summary'); const detail=document.getElementById('verdict-detail');
|
||||
let verdictText='OK', reason='Production looks stable.'; let level='ok';
|
||||
if(!connected){ verdictText='PLC OFFLINE'; reason='No PLC communication.'; level='critical'; }
|
||||
else if(stale){ verdictText='STALE DATA'; reason='PLC connected, but no fresh values are arriving.'; level='warning'; }
|
||||
else if(zForce==='critical' || zImb==='critical'){ verdictText='CRITICAL'; reason='Force or imbalance reached critical region.'; level='critical'; }
|
||||
else if(zForce==='warning' || zImb==='warning'){ verdictText='WARNING'; reason='Process is above warning thresholds.'; level='warning'; }
|
||||
statusEl.textContent=verdictText; statusEl.className='status '+level; reasonEl.textContent=reason; verdict.textContent=verdictText; verdict.className='status '+level; detail.textContent=reason;
|
||||
document.getElementById('stale-pill').textContent='Data freshness: '+(stale?'stale':connected?'fresh':'offline');
|
||||
document.getElementById('trend-force').textContent=((Number(t.force_delta_pct)||0)>=0?'+':'')+fmt(t.force_delta_pct,1)+(cfg.ui.unit_percent||'%');
|
||||
document.getElementById('trend-force').className='value mono '+(((Number(t.force_delta_pct)||0)>=3)?'warning':'ok');
|
||||
document.getElementById('trend-force-sub').textContent=(t.force_direction||'--')+' over 15m';
|
||||
document.getElementById('trend-stability').textContent=String(t.process_stability||'--').toUpperCase();
|
||||
document.getElementById('trend-stability').className='value mono '+(t.process_stability==='unstable'?'critical':t.process_stability==='caution'?'warning':'ok');
|
||||
document.getElementById('trend-stability-sub').textContent=t.stability_reason||'No trend reason';
|
||||
const attention=[]; if(!connected) attention.push('Restore PLC communication to recover live monitoring.'); if(stale) attention.push('Investigate stale data path between PLC and the app.'); if(zForce!=='ok') attention.push('Force level is '+zForce+'; review current load and top-force causes.'); if(zImb!=='ok') attention.push('Imbalance is '+zImb+'; check centering, alignment, and tooling.');
|
||||
(a.events||[]).slice(0,4).forEach(ev=>{if(ev.severity!=='info') attention.push((ev.time||'')+' • '+(ev.message||''));});
|
||||
const ul=document.getElementById('attention-list'); ul.innerHTML=''; (attention.length?attention:['No active attention items.']).forEach(item=>{const li=document.createElement('li'); li.textContent=item; ul.appendChild(li);});
|
||||
const banner=document.getElementById('alarm-banner'); if(level==='critical'){banner.textContent='Critical attention required — review force, imbalance, or PLC connectivity.'; banner.classList.add('show');} else if(level==='warning'){banner.textContent='Warning condition active — process should be reviewed.'; banner.classList.add('show');} else {banner.classList.remove('show');}
|
||||
}catch(err){console.warn(err)}
|
||||
}
|
||||
AppUI.initTheme(); AppUI.initFullscreen({ buttonId:'fullscreen-btn' });
|
||||
loadCfg().then(refreshAll); setInterval(refreshAll, 1500);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -1,336 +1,336 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Force Monitor — License</title>
|
||||
<style>
|
||||
:root {
|
||||
--bg1:#050816; --bg2:#0b1224; --panel:rgba(255,255,255,0.055); --border:rgba(255,255,255,0.10);
|
||||
--text:#f4f4f5; --muted:#a1a1aa; --muted2:#71717a; --btnbg:rgba(255,255,255,0.05); --shadow:0 16px 36px rgba(0,0,0,0.18);
|
||||
--ok:#34d399; --warn:#facc15; --bad:#f87171; --info:#93c5fd;
|
||||
}
|
||||
body[data-theme="light"] {
|
||||
--bg1:#eef4ff; --bg2:#f8fafc; --panel:rgba(255,255,255,0.84); --border:rgba(15,23,42,0.10);
|
||||
--text:#0f172a; --muted:#475569; --muted2:#64748b; --btnbg:rgba(255,255,255,0.88); --shadow:0 16px 36px rgba(15,23,42,0.08);
|
||||
--ok:#059669; --warn:#b45309; --bad:#dc2626; --info:#1d4ed8;
|
||||
}
|
||||
* { box-sizing:border-box; }
|
||||
body {
|
||||
margin:0; min-height:100vh; color:var(--text); font-family:'Segoe UI',system-ui,-apple-system,sans-serif;
|
||||
background:
|
||||
radial-gradient(circle at 10% 10%, rgba(34,211,238,0.12), transparent 18%),
|
||||
radial-gradient(circle at 90% 10%, rgba(168,85,247,0.14), transparent 18%),
|
||||
linear-gradient(180deg, var(--bg1) 0%, var(--bg2) 100%);
|
||||
}
|
||||
body[data-theme="light"] {
|
||||
background:
|
||||
radial-gradient(circle at 10% 10%, rgba(14,165,233,0.10), transparent 20%),
|
||||
radial-gradient(circle at 90% 10%, rgba(168,85,247,0.10), transparent 18%),
|
||||
linear-gradient(180deg, var(--bg1) 0%, var(--bg2) 100%);
|
||||
}
|
||||
.wrap { width:min(94vw, 1560px); margin:0 auto; padding:24px; }
|
||||
.glass { background:var(--panel); border:1px solid var(--border); border-radius:24px; backdrop-filter:blur(14px); -webkit-backdrop-filter:blur(14px); box-shadow:var(--shadow); }
|
||||
.nav, .row, .toolbar { display:flex; flex-wrap:wrap; gap:12px; align-items:center; }
|
||||
.nav { margin-bottom:18px; }
|
||||
.btn, .input, textarea {
|
||||
min-height:42px; border-radius:14px; border:1px solid var(--border); background:var(--btnbg); color:var(--text);
|
||||
padding:10px 14px; font:inherit;
|
||||
}
|
||||
.btn { cursor:pointer; font-weight:600; text-decoration:none; display:inline-flex; align-items:center; justify-content:center; }
|
||||
.btn.primary { background:rgba(14,165,233,0.14); border-color:rgba(14,165,233,0.35); }
|
||||
.btn.good { background:rgba(16,185,129,0.14); border-color:rgba(16,185,129,0.35); }
|
||||
.btn.warn { background:rgba(245,158,11,0.14); border-color:rgba(245,158,11,0.35); }
|
||||
.grid { display:grid; gap:16px; }
|
||||
.cards { grid-template-columns:repeat(auto-fit,minmax(220px,1fr)); margin-bottom:18px; }
|
||||
.card { padding:18px 20px; }
|
||||
.kicker { font-size:11px; letter-spacing:.22em; color:var(--muted2); text-transform:uppercase; }
|
||||
.value { font-size:30px; font-weight:800; margin-top:8px; }
|
||||
.sub { color:var(--muted); margin-top:8px; font-size:14px; }
|
||||
.mono { font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace; }
|
||||
textarea { width:100%; min-height:210px; resize:vertical; }
|
||||
.two { grid-template-columns:1.1fr .9fr; }
|
||||
pre {
|
||||
margin:0; padding:16px; border-radius:18px; border:1px solid var(--border); background:rgba(2,6,23,0.35);
|
||||
color:var(--text); white-space:pre-wrap; word-break:break-word; min-height:210px; overflow:auto;
|
||||
}
|
||||
body[data-theme="light"] pre { background:rgba(248,250,252,0.96); }
|
||||
.badge { display:inline-flex; align-items:center; gap:8px; border-radius:999px; padding:6px 12px; font-weight:700; border:1px solid var(--border); }
|
||||
.ok { color:var(--ok); }
|
||||
.warnc { color:var(--warn); }
|
||||
.bad { color:var(--bad); }
|
||||
.info { color:var(--info); }
|
||||
.field { margin-top:12px; }
|
||||
.label { color:var(--muted2); font-size:12px; letter-spacing:.14em; text-transform:uppercase; margin-bottom:6px; }
|
||||
.details { display:grid; grid-template-columns:repeat(auto-fit,minmax(240px,1fr)); gap:12px; }
|
||||
.detail-box { padding:14px 16px; border-radius:18px; border:1px solid var(--border); background:rgba(255,255,255,0.03); }
|
||||
body[data-theme="light"] .detail-box { background:rgba(255,255,255,0.68); }
|
||||
.message { margin-top:12px; padding:14px 16px; border-radius:16px; display:none; }
|
||||
.message.show { display:block; }
|
||||
.message.good { background:rgba(16,185,129,0.12); border:1px solid rgba(16,185,129,0.24); color:#bbf7d0; }
|
||||
.message.bad { background:rgba(239,68,68,0.12); border:1px solid rgba(239,68,68,0.24); color:#fecaca; }
|
||||
body[data-theme="light"] .message.good { color:#166534; }
|
||||
body[data-theme="light"] .message.bad { color:#991b1b; }
|
||||
.spacer { flex:1 1 auto; }
|
||||
@media (max-width: 980px) { .two { grid-template-columns:1fr; } .wrap { width:min(96vw, 1560px); padding:16px; } }
|
||||
</style>
|
||||
</head>
|
||||
<body data-theme="dark">
|
||||
<div class="wrap">
|
||||
<div class="nav">
|
||||
<a class="btn" href="/">Dashboard</a>
|
||||
<a class="btn" href="/history">History</a>
|
||||
<a class="btn" href="/alarms">Alarms</a>
|
||||
<a class="btn" href="/kiosk">Kiosk</a>
|
||||
<a class="btn" href="/process-capability">Process capability</a>
|
||||
<a class="btn" href="/reports">Reports</a>
|
||||
<a class="btn primary" href="/license">License</a>
|
||||
<div class="spacer"></div>
|
||||
<button id="theme-toggle" class="btn" type="button">Light theme</button>
|
||||
<button id="fullscreen-toggle" class="btn" type="button">Enter fullscreen</button>
|
||||
<button id="refresh-btn" class="btn warn" type="button">Refresh</button>
|
||||
</div>
|
||||
|
||||
<div class="glass card" style="margin-bottom:18px;">
|
||||
<div class="row">
|
||||
<div>
|
||||
<div class="kicker">Force Monitor</div>
|
||||
<h1 style="margin:8px 0 0 0; font-size:40px; line-height:1;">License Center</h1>
|
||||
<div class="sub">Status, fingerprint, activation request, local license import, and signed license activation.</div>
|
||||
</div>
|
||||
<div class="spacer"></div>
|
||||
<div class="row">
|
||||
<span id="mode-badge" class="badge info">mode: loading</span>
|
||||
<span id="lock-badge" class="badge">locked: --</span>
|
||||
<span id="tamper-badge" class="badge">tamper: --</span>
|
||||
</div>
|
||||
</div>
|
||||
<div id="action-message" class="message"></div>
|
||||
</div>
|
||||
|
||||
<div class="grid cards">
|
||||
<div class="glass card"><div class="kicker">Current mode</div><div id="metric-mode" class="value">--</div><div id="metric-mode-sub" class="sub">Loading...</div></div>
|
||||
<div class="glass card"><div class="kicker">Days remaining</div><div id="metric-days" class="value mono">--</div><div class="sub">Trial or expiry information</div></div>
|
||||
<div class="glass card"><div class="kicker">Activation configured</div><div id="metric-configured" class="value mono">--</div><div class="sub">Public key present or not</div></div>
|
||||
<div class="glass card"><div class="kicker">Fingerprint</div><div id="metric-fingerprint" class="value mono" style="font-size:24px;">--</div><div class="sub">Short fingerprint</div></div>
|
||||
</div>
|
||||
|
||||
<div class="grid two">
|
||||
<div class="glass card">
|
||||
<div class="row" style="justify-content:space-between; margin-bottom:10px;">
|
||||
<div>
|
||||
<div class="kicker">Activation request</div>
|
||||
<div class="sub">Send this JSON to your private signing tool or license issuer.</div>
|
||||
</div>
|
||||
<div class="toolbar">
|
||||
<button id="copy-request-btn" class="btn" type="button">Copy</button>
|
||||
<button id="download-request-btn" class="btn good" type="button">Download</button>
|
||||
</div>
|
||||
</div>
|
||||
<pre id="request-json">Loading activation request...</pre>
|
||||
</div>
|
||||
|
||||
<div class="glass card">
|
||||
<div class="row" style="justify-content:space-between; margin-bottom:10px;">
|
||||
<div>
|
||||
<div class="kicker">Activate signed license</div>
|
||||
<div class="sub">Paste the signed license JSON or load it from a local file.</div>
|
||||
</div>
|
||||
<div class="toolbar">
|
||||
<input id="license-file" type="file" accept="application/json,.json" class="btn" style="padding:8px 12px;">
|
||||
<button id="activate-btn" class="btn primary" type="button">Activate</button>
|
||||
</div>
|
||||
</div>
|
||||
<textarea id="license-text" class="mono" placeholder='{"app":"force_monitor",...}'></textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="glass card" style="margin-top:18px;">
|
||||
<div class="kicker">Status details</div>
|
||||
<div class="details" style="margin-top:14px;">
|
||||
<div class="detail-box"><div class="label">Message</div><div id="detail-message">--</div></div>
|
||||
<div class="detail-box"><div class="label">Customer</div><div id="detail-customer">--</div></div>
|
||||
<div class="detail-box"><div class="label">License ID</div><div id="detail-license-id" class="mono">--</div></div>
|
||||
<div class="detail-box"><div class="label">Hostname</div><div id="detail-hostname" class="mono">--</div></div>
|
||||
<div class="detail-box"><div class="label">Fingerprint</div><div id="detail-fingerprint" class="mono">--</div></div>
|
||||
<div class="detail-box"><div class="label">Trial window</div><div id="detail-trial-window">--</div></div>
|
||||
<div class="detail-box"><div class="label">Expires at</div><div id="detail-expires">--</div></div>
|
||||
<div class="detail-box"><div class="label">Features</div><div id="detail-features">--</div></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="/static/app-common.js"></script>
|
||||
<script>
|
||||
let activationRequestText = '';
|
||||
|
||||
function escapeHtml(value) {
|
||||
return String(value === undefined || value === null ? '' : value)
|
||||
.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>')
|
||||
.replace(/"/g, '"').replace(/'/g, ''');
|
||||
}
|
||||
|
||||
function setTheme(theme) {
|
||||
const t = theme === 'light' ? 'light' : 'dark';
|
||||
document.body.setAttribute('data-theme', t);
|
||||
try { localStorage.setItem('force-monitor-theme', t); } catch (e) {}
|
||||
const btn = document.getElementById('theme-toggle');
|
||||
if (btn) btn.textContent = t === 'light' ? 'Dark theme' : 'Light theme';
|
||||
}
|
||||
|
||||
function initTheme() {
|
||||
let theme = 'dark';
|
||||
try {
|
||||
const stored = localStorage.getItem('force-monitor-theme');
|
||||
if (stored === 'light' || stored === 'dark') theme = stored;
|
||||
} catch (e) {}
|
||||
setTheme(theme);
|
||||
}
|
||||
|
||||
function setMessage(text, good) {
|
||||
const box = document.getElementById('action-message');
|
||||
if (!box) return;
|
||||
box.textContent = text || '';
|
||||
box.className = 'message' + (text ? ' show ' + (good ? 'good' : 'bad') : '');
|
||||
}
|
||||
|
||||
function setDetail(id, value) {
|
||||
const el = document.getElementById(id);
|
||||
if (el) el.textContent = value || '--';
|
||||
}
|
||||
|
||||
function setBadge(id, text, klass) {
|
||||
const el = document.getElementById(id);
|
||||
if (!el) return;
|
||||
el.className = 'badge ' + (klass || '');
|
||||
el.textContent = text;
|
||||
}
|
||||
|
||||
function renderStatus(status) {
|
||||
const mode = String(status.mode || '--');
|
||||
const locked = !!status.locked;
|
||||
const tampered = !!status.tampered;
|
||||
const activationConfigured = !!status.activation_configured;
|
||||
const daysRemaining = Number.isFinite(Number(status.days_remaining)) ? String(status.days_remaining) : '--';
|
||||
document.getElementById('metric-mode').textContent = mode.toUpperCase();
|
||||
document.getElementById('metric-mode-sub').textContent = status.message || '--';
|
||||
document.getElementById('metric-days').textContent = daysRemaining;
|
||||
document.getElementById('metric-configured').textContent = activationConfigured ? 'YES' : 'NO';
|
||||
document.getElementById('metric-fingerprint').textContent = status.fingerprint_short || '--';
|
||||
|
||||
setBadge('mode-badge', 'mode: ' + mode, locked ? 'bad' : (mode === 'licensed' ? 'ok' : 'info'));
|
||||
setBadge('lock-badge', 'locked: ' + (locked ? 'yes' : 'no'), locked ? 'bad' : 'ok');
|
||||
setBadge('tamper-badge', 'tamper: ' + (tampered ? 'yes' : 'no'), tampered ? 'bad' : 'ok');
|
||||
|
||||
setDetail('detail-message', status.message || '--');
|
||||
setDetail('detail-customer', status.customer || '--');
|
||||
setDetail('detail-license-id', status.license_id || '--');
|
||||
setDetail('detail-hostname', status.hostname || '--');
|
||||
setDetail('detail-fingerprint', status.fingerprint || '--');
|
||||
const trialWindow = (status.trial_started_at || '--') + ' → ' + (status.trial_expires_at || '--');
|
||||
setDetail('detail-trial-window', trialWindow);
|
||||
setDetail('detail-expires', status.expires_at || '--');
|
||||
setDetail('detail-features', Array.isArray(status.features) && status.features.length ? status.features.join(', ') : '--');
|
||||
}
|
||||
|
||||
async function refreshStatus() {
|
||||
try {
|
||||
const status = await AppUI.fetchJson('/api/license/status', { timeoutMs:8000 });
|
||||
renderStatus(status);
|
||||
} catch (err) {
|
||||
console.warn('License status error:', err);
|
||||
setMessage('Could not load license status.', false);
|
||||
document.getElementById('metric-mode').textContent = 'ERROR';
|
||||
document.getElementById('metric-mode-sub').textContent = err && err.message ? err.message : 'Could not load license status.';
|
||||
}
|
||||
}
|
||||
|
||||
async function refreshRequest() {
|
||||
try {
|
||||
const data = await AppUI.fetchJson('/api/license/request', { timeoutMs:8000 });
|
||||
activationRequestText = JSON.stringify(data, null, 2);
|
||||
document.getElementById('request-json').textContent = activationRequestText;
|
||||
} catch (err) {
|
||||
console.warn('License request error:', err);
|
||||
activationRequestText = '';
|
||||
document.getElementById('request-json').textContent = 'Could not load activation request: ' + (err && err.message ? err.message : 'unknown error');
|
||||
}
|
||||
}
|
||||
|
||||
async function activateLicense() {
|
||||
const text = document.getElementById('license-text').value.trim();
|
||||
if (!text) {
|
||||
setMessage('Paste a signed license JSON first.', false);
|
||||
return;
|
||||
}
|
||||
setMessage('Activating license...', true);
|
||||
try {
|
||||
const res = await fetch('/api/license/activate', {
|
||||
method:'POST',
|
||||
headers:{ 'Content-Type':'application/json' },
|
||||
body: JSON.stringify({ license_text:text })
|
||||
});
|
||||
const data = await res.json().catch(() => ({}));
|
||||
if (!res.ok) {
|
||||
const errMsg = data && data.error ? data.error : ('HTTP ' + res.status);
|
||||
setMessage('Activation failed: ' + errMsg, false);
|
||||
if (data && data.license) renderStatus(data.license);
|
||||
return;
|
||||
}
|
||||
setMessage('License activated successfully.', true);
|
||||
if (data && data.license) renderStatus(data.license);
|
||||
await refreshStatus();
|
||||
} catch (err) {
|
||||
console.warn('License activate error:', err);
|
||||
setMessage('Activation request failed.', false);
|
||||
}
|
||||
}
|
||||
|
||||
async function copyRequest() {
|
||||
if (!activationRequestText) return;
|
||||
try {
|
||||
await navigator.clipboard.writeText(activationRequestText);
|
||||
setMessage('Activation request copied to clipboard.', true);
|
||||
} catch (err) {
|
||||
setMessage('Clipboard copy failed.', false);
|
||||
}
|
||||
}
|
||||
|
||||
function downloadRequest() {
|
||||
if (!activationRequestText) return;
|
||||
const blob = new Blob([activationRequestText], { type:'application/json;charset=utf-8' });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = 'force-monitor-activation-request.json';
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
a.remove();
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
|
||||
function attachFileReader() {
|
||||
const input = document.getElementById('license-file');
|
||||
if (!input) return;
|
||||
input.addEventListener('change', async () => {
|
||||
const file = input.files && input.files[0];
|
||||
if (!file) return;
|
||||
const text = await file.text();
|
||||
document.getElementById('license-text').value = text;
|
||||
setMessage('Loaded license file into the text box.', true);
|
||||
});
|
||||
}
|
||||
|
||||
window.addEventListener('DOMContentLoaded', async () => {
|
||||
AppUI.initTheme();
|
||||
AppUI.initFullscreen({ buttonId:'fullscreen-toggle' });
|
||||
document.getElementById('refresh-btn').addEventListener('click', async () => { setMessage('', true); await Promise.all([refreshStatus(), refreshRequest()]); });
|
||||
document.getElementById('activate-btn').addEventListener('click', activateLicense);
|
||||
document.getElementById('copy-request-btn').addEventListener('click', copyRequest);
|
||||
document.getElementById('download-request-btn').addEventListener('click', downloadRequest);
|
||||
attachFileReader();
|
||||
await Promise.all([refreshStatus(), refreshRequest()]);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Force Monitor — License</title>
|
||||
<style>
|
||||
:root {
|
||||
--bg1:#050816; --bg2:#0b1224; --panel:rgba(255,255,255,0.055); --border:rgba(255,255,255,0.10);
|
||||
--text:#f4f4f5; --muted:#a1a1aa; --muted2:#71717a; --btnbg:rgba(255,255,255,0.05); --shadow:0 16px 36px rgba(0,0,0,0.18);
|
||||
--ok:#34d399; --warn:#facc15; --bad:#f87171; --info:#93c5fd;
|
||||
}
|
||||
body[data-theme="light"] {
|
||||
--bg1:#eef4ff; --bg2:#f8fafc; --panel:rgba(255,255,255,0.84); --border:rgba(15,23,42,0.10);
|
||||
--text:#0f172a; --muted:#475569; --muted2:#64748b; --btnbg:rgba(255,255,255,0.88); --shadow:0 16px 36px rgba(15,23,42,0.08);
|
||||
--ok:#059669; --warn:#b45309; --bad:#dc2626; --info:#1d4ed8;
|
||||
}
|
||||
* { box-sizing:border-box; }
|
||||
body {
|
||||
margin:0; min-height:100vh; color:var(--text); font-family:'Segoe UI',system-ui,-apple-system,sans-serif;
|
||||
background:
|
||||
radial-gradient(circle at 10% 10%, rgba(34,211,238,0.12), transparent 18%),
|
||||
radial-gradient(circle at 90% 10%, rgba(168,85,247,0.14), transparent 18%),
|
||||
linear-gradient(180deg, var(--bg1) 0%, var(--bg2) 100%);
|
||||
}
|
||||
body[data-theme="light"] {
|
||||
background:
|
||||
radial-gradient(circle at 10% 10%, rgba(14,165,233,0.10), transparent 20%),
|
||||
radial-gradient(circle at 90% 10%, rgba(168,85,247,0.10), transparent 18%),
|
||||
linear-gradient(180deg, var(--bg1) 0%, var(--bg2) 100%);
|
||||
}
|
||||
.wrap { width:min(94vw, 1560px); margin:0 auto; padding:24px; }
|
||||
.glass { background:var(--panel); border:1px solid var(--border); border-radius:24px; backdrop-filter:blur(14px); -webkit-backdrop-filter:blur(14px); box-shadow:var(--shadow); }
|
||||
.nav, .row, .toolbar { display:flex; flex-wrap:wrap; gap:12px; align-items:center; }
|
||||
.nav { margin-bottom:18px; }
|
||||
.btn, .input, textarea {
|
||||
min-height:42px; border-radius:14px; border:1px solid var(--border); background:var(--btnbg); color:var(--text);
|
||||
padding:10px 14px; font:inherit;
|
||||
}
|
||||
.btn { cursor:pointer; font-weight:600; text-decoration:none; display:inline-flex; align-items:center; justify-content:center; }
|
||||
.btn.primary { background:rgba(14,165,233,0.14); border-color:rgba(14,165,233,0.35); }
|
||||
.btn.good { background:rgba(16,185,129,0.14); border-color:rgba(16,185,129,0.35); }
|
||||
.btn.warn { background:rgba(245,158,11,0.14); border-color:rgba(245,158,11,0.35); }
|
||||
.grid { display:grid; gap:16px; }
|
||||
.cards { grid-template-columns:repeat(auto-fit,minmax(220px,1fr)); margin-bottom:18px; }
|
||||
.card { padding:18px 20px; }
|
||||
.kicker { font-size:11px; letter-spacing:.22em; color:var(--muted2); text-transform:uppercase; }
|
||||
.value { font-size:30px; font-weight:800; margin-top:8px; }
|
||||
.sub { color:var(--muted); margin-top:8px; font-size:14px; }
|
||||
.mono { font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace; }
|
||||
textarea { width:100%; min-height:210px; resize:vertical; }
|
||||
.two { grid-template-columns:1.1fr .9fr; }
|
||||
pre {
|
||||
margin:0; padding:16px; border-radius:18px; border:1px solid var(--border); background:rgba(2,6,23,0.35);
|
||||
color:var(--text); white-space:pre-wrap; word-break:break-word; min-height:210px; overflow:auto;
|
||||
}
|
||||
body[data-theme="light"] pre { background:rgba(248,250,252,0.96); }
|
||||
.badge { display:inline-flex; align-items:center; gap:8px; border-radius:999px; padding:6px 12px; font-weight:700; border:1px solid var(--border); }
|
||||
.ok { color:var(--ok); }
|
||||
.warnc { color:var(--warn); }
|
||||
.bad { color:var(--bad); }
|
||||
.info { color:var(--info); }
|
||||
.field { margin-top:12px; }
|
||||
.label { color:var(--muted2); font-size:12px; letter-spacing:.14em; text-transform:uppercase; margin-bottom:6px; }
|
||||
.details { display:grid; grid-template-columns:repeat(auto-fit,minmax(240px,1fr)); gap:12px; }
|
||||
.detail-box { padding:14px 16px; border-radius:18px; border:1px solid var(--border); background:rgba(255,255,255,0.03); }
|
||||
body[data-theme="light"] .detail-box { background:rgba(255,255,255,0.68); }
|
||||
.message { margin-top:12px; padding:14px 16px; border-radius:16px; display:none; }
|
||||
.message.show { display:block; }
|
||||
.message.good { background:rgba(16,185,129,0.12); border:1px solid rgba(16,185,129,0.24); color:#bbf7d0; }
|
||||
.message.bad { background:rgba(239,68,68,0.12); border:1px solid rgba(239,68,68,0.24); color:#fecaca; }
|
||||
body[data-theme="light"] .message.good { color:#166534; }
|
||||
body[data-theme="light"] .message.bad { color:#991b1b; }
|
||||
.spacer { flex:1 1 auto; }
|
||||
@media (max-width: 980px) { .two { grid-template-columns:1fr; } .wrap { width:min(96vw, 1560px); padding:16px; } }
|
||||
</style>
|
||||
</head>
|
||||
<body data-theme="dark">
|
||||
<div class="wrap">
|
||||
<div class="nav">
|
||||
<a class="btn" href="/">Dashboard</a>
|
||||
<a class="btn" href="/history">History</a>
|
||||
<a class="btn" href="/alarms">Alarms</a>
|
||||
<a class="btn" href="/kiosk">Kiosk</a>
|
||||
<a class="btn" href="/process-capability">Process capability</a>
|
||||
<a class="btn" href="/reports">Reports</a>
|
||||
<a class="btn primary" href="/license">License</a>
|
||||
<div class="spacer"></div>
|
||||
<button id="theme-toggle" class="btn" type="button">Light theme</button>
|
||||
<button id="fullscreen-toggle" class="btn" type="button">Enter fullscreen</button>
|
||||
<button id="refresh-btn" class="btn warn" type="button">Refresh</button>
|
||||
</div>
|
||||
|
||||
<div class="glass card" style="margin-bottom:18px;">
|
||||
<div class="row">
|
||||
<div>
|
||||
<div class="kicker">Force Monitor</div>
|
||||
<h1 style="margin:8px 0 0 0; font-size:40px; line-height:1;">License Center</h1>
|
||||
<div class="sub">Status, fingerprint, activation request, local license import, and signed license activation.</div>
|
||||
</div>
|
||||
<div class="spacer"></div>
|
||||
<div class="row">
|
||||
<span id="mode-badge" class="badge info">mode: loading</span>
|
||||
<span id="lock-badge" class="badge">locked: --</span>
|
||||
<span id="tamper-badge" class="badge">tamper: --</span>
|
||||
</div>
|
||||
</div>
|
||||
<div id="action-message" class="message"></div>
|
||||
</div>
|
||||
|
||||
<div class="grid cards">
|
||||
<div class="glass card"><div class="kicker">Current mode</div><div id="metric-mode" class="value">--</div><div id="metric-mode-sub" class="sub">Loading...</div></div>
|
||||
<div class="glass card"><div class="kicker">Days remaining</div><div id="metric-days" class="value mono">--</div><div class="sub">Trial or expiry information</div></div>
|
||||
<div class="glass card"><div class="kicker">Activation configured</div><div id="metric-configured" class="value mono">--</div><div class="sub">Public key present or not</div></div>
|
||||
<div class="glass card"><div class="kicker">Fingerprint</div><div id="metric-fingerprint" class="value mono" style="font-size:24px;">--</div><div class="sub">Short fingerprint</div></div>
|
||||
</div>
|
||||
|
||||
<div class="grid two">
|
||||
<div class="glass card">
|
||||
<div class="row" style="justify-content:space-between; margin-bottom:10px;">
|
||||
<div>
|
||||
<div class="kicker">Activation request</div>
|
||||
<div class="sub">Send this JSON to your private signing tool or license issuer.</div>
|
||||
</div>
|
||||
<div class="toolbar">
|
||||
<button id="copy-request-btn" class="btn" type="button">Copy</button>
|
||||
<button id="download-request-btn" class="btn good" type="button">Download</button>
|
||||
</div>
|
||||
</div>
|
||||
<pre id="request-json">Loading activation request...</pre>
|
||||
</div>
|
||||
|
||||
<div class="glass card">
|
||||
<div class="row" style="justify-content:space-between; margin-bottom:10px;">
|
||||
<div>
|
||||
<div class="kicker">Activate signed license</div>
|
||||
<div class="sub">Paste the signed license JSON or load it from a local file.</div>
|
||||
</div>
|
||||
<div class="toolbar">
|
||||
<input id="license-file" type="file" accept="application/json,.json" class="btn" style="padding:8px 12px;">
|
||||
<button id="activate-btn" class="btn primary" type="button">Activate</button>
|
||||
</div>
|
||||
</div>
|
||||
<textarea id="license-text" class="mono" placeholder='{"app":"force_monitor",...}'></textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="glass card" style="margin-top:18px;">
|
||||
<div class="kicker">Status details</div>
|
||||
<div class="details" style="margin-top:14px;">
|
||||
<div class="detail-box"><div class="label">Message</div><div id="detail-message">--</div></div>
|
||||
<div class="detail-box"><div class="label">Customer</div><div id="detail-customer">--</div></div>
|
||||
<div class="detail-box"><div class="label">License ID</div><div id="detail-license-id" class="mono">--</div></div>
|
||||
<div class="detail-box"><div class="label">Hostname</div><div id="detail-hostname" class="mono">--</div></div>
|
||||
<div class="detail-box"><div class="label">Fingerprint</div><div id="detail-fingerprint" class="mono">--</div></div>
|
||||
<div class="detail-box"><div class="label">Trial window</div><div id="detail-trial-window">--</div></div>
|
||||
<div class="detail-box"><div class="label">Expires at</div><div id="detail-expires">--</div></div>
|
||||
<div class="detail-box"><div class="label">Features</div><div id="detail-features">--</div></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="/static/app-common.js"></script>
|
||||
<script>
|
||||
let activationRequestText = '';
|
||||
|
||||
function escapeHtml(value) {
|
||||
return String(value === undefined || value === null ? '' : value)
|
||||
.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>')
|
||||
.replace(/"/g, '"').replace(/'/g, ''');
|
||||
}
|
||||
|
||||
function setTheme(theme) {
|
||||
const t = theme === 'light' ? 'light' : 'dark';
|
||||
document.body.setAttribute('data-theme', t);
|
||||
try { localStorage.setItem('force-monitor-theme', t); } catch (e) {}
|
||||
const btn = document.getElementById('theme-toggle');
|
||||
if (btn) btn.textContent = t === 'light' ? 'Dark theme' : 'Light theme';
|
||||
}
|
||||
|
||||
function initTheme() {
|
||||
let theme = 'dark';
|
||||
try {
|
||||
const stored = localStorage.getItem('force-monitor-theme');
|
||||
if (stored === 'light' || stored === 'dark') theme = stored;
|
||||
} catch (e) {}
|
||||
setTheme(theme);
|
||||
}
|
||||
|
||||
function setMessage(text, good) {
|
||||
const box = document.getElementById('action-message');
|
||||
if (!box) return;
|
||||
box.textContent = text || '';
|
||||
box.className = 'message' + (text ? ' show ' + (good ? 'good' : 'bad') : '');
|
||||
}
|
||||
|
||||
function setDetail(id, value) {
|
||||
const el = document.getElementById(id);
|
||||
if (el) el.textContent = value || '--';
|
||||
}
|
||||
|
||||
function setBadge(id, text, klass) {
|
||||
const el = document.getElementById(id);
|
||||
if (!el) return;
|
||||
el.className = 'badge ' + (klass || '');
|
||||
el.textContent = text;
|
||||
}
|
||||
|
||||
function renderStatus(status) {
|
||||
const mode = String(status.mode || '--');
|
||||
const locked = !!status.locked;
|
||||
const tampered = !!status.tampered;
|
||||
const activationConfigured = !!status.activation_configured;
|
||||
const daysRemaining = Number.isFinite(Number(status.days_remaining)) ? String(status.days_remaining) : '--';
|
||||
document.getElementById('metric-mode').textContent = mode.toUpperCase();
|
||||
document.getElementById('metric-mode-sub').textContent = status.message || '--';
|
||||
document.getElementById('metric-days').textContent = daysRemaining;
|
||||
document.getElementById('metric-configured').textContent = activationConfigured ? 'YES' : 'NO';
|
||||
document.getElementById('metric-fingerprint').textContent = status.fingerprint_short || '--';
|
||||
|
||||
setBadge('mode-badge', 'mode: ' + mode, locked ? 'bad' : (mode === 'licensed' ? 'ok' : 'info'));
|
||||
setBadge('lock-badge', 'locked: ' + (locked ? 'yes' : 'no'), locked ? 'bad' : 'ok');
|
||||
setBadge('tamper-badge', 'tamper: ' + (tampered ? 'yes' : 'no'), tampered ? 'bad' : 'ok');
|
||||
|
||||
setDetail('detail-message', status.message || '--');
|
||||
setDetail('detail-customer', status.customer || '--');
|
||||
setDetail('detail-license-id', status.license_id || '--');
|
||||
setDetail('detail-hostname', status.hostname || '--');
|
||||
setDetail('detail-fingerprint', status.fingerprint || '--');
|
||||
const trialWindow = (status.trial_started_at || '--') + ' → ' + (status.trial_expires_at || '--');
|
||||
setDetail('detail-trial-window', trialWindow);
|
||||
setDetail('detail-expires', status.expires_at || '--');
|
||||
setDetail('detail-features', Array.isArray(status.features) && status.features.length ? status.features.join(', ') : '--');
|
||||
}
|
||||
|
||||
async function refreshStatus() {
|
||||
try {
|
||||
const status = await AppUI.fetchJson('/api/license/status', { timeoutMs:8000 });
|
||||
renderStatus(status);
|
||||
} catch (err) {
|
||||
console.warn('License status error:', err);
|
||||
setMessage('Could not load license status.', false);
|
||||
document.getElementById('metric-mode').textContent = 'ERROR';
|
||||
document.getElementById('metric-mode-sub').textContent = err && err.message ? err.message : 'Could not load license status.';
|
||||
}
|
||||
}
|
||||
|
||||
async function refreshRequest() {
|
||||
try {
|
||||
const data = await AppUI.fetchJson('/api/license/request', { timeoutMs:8000 });
|
||||
activationRequestText = JSON.stringify(data, null, 2);
|
||||
document.getElementById('request-json').textContent = activationRequestText;
|
||||
} catch (err) {
|
||||
console.warn('License request error:', err);
|
||||
activationRequestText = '';
|
||||
document.getElementById('request-json').textContent = 'Could not load activation request: ' + (err && err.message ? err.message : 'unknown error');
|
||||
}
|
||||
}
|
||||
|
||||
async function activateLicense() {
|
||||
const text = document.getElementById('license-text').value.trim();
|
||||
if (!text) {
|
||||
setMessage('Paste a signed license JSON first.', false);
|
||||
return;
|
||||
}
|
||||
setMessage('Activating license...', true);
|
||||
try {
|
||||
const res = await fetch('/api/license/activate', {
|
||||
method:'POST',
|
||||
headers:{ 'Content-Type':'application/json' },
|
||||
body: JSON.stringify({ license_text:text })
|
||||
});
|
||||
const data = await res.json().catch(() => ({}));
|
||||
if (!res.ok) {
|
||||
const errMsg = data && data.error ? data.error : ('HTTP ' + res.status);
|
||||
setMessage('Activation failed: ' + errMsg, false);
|
||||
if (data && data.license) renderStatus(data.license);
|
||||
return;
|
||||
}
|
||||
setMessage('License activated successfully.', true);
|
||||
if (data && data.license) renderStatus(data.license);
|
||||
await refreshStatus();
|
||||
} catch (err) {
|
||||
console.warn('License activate error:', err);
|
||||
setMessage('Activation request failed.', false);
|
||||
}
|
||||
}
|
||||
|
||||
async function copyRequest() {
|
||||
if (!activationRequestText) return;
|
||||
try {
|
||||
await navigator.clipboard.writeText(activationRequestText);
|
||||
setMessage('Activation request copied to clipboard.', true);
|
||||
} catch (err) {
|
||||
setMessage('Clipboard copy failed.', false);
|
||||
}
|
||||
}
|
||||
|
||||
function downloadRequest() {
|
||||
if (!activationRequestText) return;
|
||||
const blob = new Blob([activationRequestText], { type:'application/json;charset=utf-8' });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = 'force-monitor-activation-request.json';
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
a.remove();
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
|
||||
function attachFileReader() {
|
||||
const input = document.getElementById('license-file');
|
||||
if (!input) return;
|
||||
input.addEventListener('change', async () => {
|
||||
const file = input.files && input.files[0];
|
||||
if (!file) return;
|
||||
const text = await file.text();
|
||||
document.getElementById('license-text').value = text;
|
||||
setMessage('Loaded license file into the text box.', true);
|
||||
});
|
||||
}
|
||||
|
||||
window.addEventListener('DOMContentLoaded', async () => {
|
||||
AppUI.initTheme();
|
||||
AppUI.initFullscreen({ buttonId:'fullscreen-toggle' });
|
||||
document.getElementById('refresh-btn').addEventListener('click', async () => { setMessage('', true); await Promise.all([refreshStatus(), refreshRequest()]); });
|
||||
document.getElementById('activate-btn').addEventListener('click', activateLicense);
|
||||
document.getElementById('copy-request-btn').addEventListener('click', copyRequest);
|
||||
document.getElementById('download-request-btn').addEventListener('click', downloadRequest);
|
||||
attachFileReader();
|
||||
await Promise.all([refreshStatus(), refreshRequest()]);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -1,28 +1,28 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Force Monitor — Process Capability</title>
|
||||
<script src="/static/chart.umd.min.js"></script>
|
||||
<style>
|
||||
:root{--bg1:#050816;--bg2:#0b1224;--panel:rgba(255,255,255,.055);--border:rgba(255,255,255,.1);--text:#f4f4f5;--muted:#a1a1aa;--muted2:#71717a;--btnbg:rgba(255,255,255,.05);--good:#34d399;--warn:#facc15;--bad:#f87171;--info:#93c5fd;}body[data-theme="light"]{--bg1:#eef4ff;--bg2:#f8fafc;--panel:rgba(255,255,255,.84);--border:rgba(15,23,42,.1);--text:#0f172a;--muted:#475569;--muted2:#64748b;--btnbg:rgba(255,255,255,.88);--good:#059669;--warn:#b45309;--bad:#dc2626;--info:#1d4ed8;}*{box-sizing:border-box}body{margin:0;min-height:100vh;color:var(--text);font-family:'Segoe UI',system-ui,sans-serif;background:radial-gradient(circle at 10% 10%, rgba(34,211,238,.12), transparent 18%),radial-gradient(circle at 90% 10%, rgba(168,85,247,.14), transparent 18%),linear-gradient(180deg,var(--bg1),var(--bg2));}.wrap{width:min(95vw,1720px);margin:0 auto;padding:24px}.glass{background:var(--panel);border:1px solid var(--border);border-radius:24px;backdrop-filter:blur(14px);-webkit-backdrop-filter:blur(14px)}.nav,.row,.toolbar{display:flex;gap:12px;flex-wrap:wrap;align-items:center}.spacer{flex:1 1 auto}.btn,.input{min-height:42px;border-radius:14px;border:1px solid var(--border);background:var(--btnbg);color:var(--text);padding:10px 14px;font:inherit}.btn{text-decoration:none;font-weight:600;display:inline-flex;align-items:center;justify-content:center;cursor:pointer}.btn.primary{background:rgba(14,165,233,.14);border-color:rgba(14,165,233,.35)}.page{padding:20px 22px;margin-bottom:18px}.kicker{font-size:11px;letter-spacing:.22em;text-transform:uppercase;color:var(--muted2)}.sub{color:var(--muted);margin-top:8px}.grid{display:grid;gap:16px}.cards{grid-template-columns:repeat(auto-fit,minmax(220px,1fr));margin-bottom:18px}.card{padding:18px 20px}.value{font-size:34px;font-weight:800;margin-top:8px}.mono{font-family:ui-monospace,SFMono-Regular,Consolas,monospace}.chart-grid{display:grid;grid-template-columns:1fr 1fr;gap:16px}.chart-box{height:360px}.table-wrap{overflow:auto}table{width:100%;border-collapse:collapse}th,td{padding:12px 10px;border-bottom:1px solid var(--border);text-align:left}th{font-size:12px;color:var(--muted2);text-transform:uppercase;letter-spacing:.16em}.pill{display:inline-flex;align-items:center;justify-content:center;min-width:88px;padding:4px 10px;border-radius:999px;font-size:12px;font-weight:700;border:1px solid var(--border)}.good{color:var(--good)}.warning{color:var(--warn)}.critical{color:var(--bad)}@media(max-width:1080px){.chart-grid{grid-template-columns:1fr}.wrap{padding:16px}}</style></head>
|
||||
<body data-theme="dark"><div class="wrap">
|
||||
<div class="nav" style="margin-bottom:18px"><a class="btn" href="/">Dashboard</a><a class="btn" href="/history">History</a><a class="btn" href="/alarms">Alarms</a><a class="btn" href="/kiosk">Kiosk</a><a class="btn primary" href="/process-capability">Process capability</a><a class="btn" href="/reports">Reports</a><a class="btn" href="/license">License</a><div class="spacer"></div><button id="theme-toggle" class="btn" type="button">Light theme</button><button id="fullscreen-toggle" class="btn" type="button">Enter fullscreen</button></div>
|
||||
<div class="glass page"><div class="row"><div><div class="kicker">Engineering capability</div><h1 style="margin:8px 0 0;font-size:42px;line-height:1.04">Process Capability & Distribution</h1><div class="sub">Histogram-based force and imbalance capability, one-sided CPU/CPK-style indicators against your configured thresholds, correlation between left and right columns, and suggested engineering action.</div></div><div class="spacer"></div><div class="mono sub" id="window-label">Window: --</div></div></div>
|
||||
<div class="glass page"><div class="toolbar"><button class="btn primary window-btn" data-window="1h">1h</button><button class="btn window-btn" data-window="8h">8h</button><button class="btn window-btn" data-window="24h">24h</button><button class="btn window-btn" data-window="7d">7d</button><input id="custom-window" class="input" style="width:140px" placeholder="e.g. 3h or 2d"><button id="apply-window" class="btn" type="button">Apply</button><div class="spacer"></div><button id="refresh-btn" class="btn" type="button">Refresh</button></div></div>
|
||||
<div class="grid cards"><div class="glass card"><div class="kicker">Total Cpk @ critical</div><div id="total-cpk-critical" class="value mono">--</div><div id="total-cpk-sub" class="sub">Capability versus critical load limit</div></div><div class="glass card"><div class="kicker">Imbalance Cpk @ critical</div><div id="imb-cpk-critical" class="value mono">--</div><div id="imb-cpk-sub" class="sub">Capability versus critical imbalance limit</div></div><div class="glass card"><div class="kicker">Left ↔ right correlation</div><div id="corr-value" class="value mono">--</div><div class="sub">Closer to 1.00 means both sides move together</div></div><div class="glass card"><div class="kicker">Suggested action</div><div id="action-pill" class="value" style="font-size:28px">--</div><div id="action-text" class="sub">Loading capability guidance…</div></div></div>
|
||||
<div class="chart-grid"><div class="glass page"><div class="row"><h2 style="margin:0;font-size:28px">Total force distribution</h2><div class="spacer"></div><span class="pill good">histogram</span></div><div class="sub">Distribution of total peak force against configured warning and critical boundaries.</div><div class="chart-box"><canvas id="totalHist"></canvas></div></div><div class="glass page"><div class="row"><h2 style="margin:0;font-size:28px">Imbalance distribution</h2><div class="spacer"></div><span class="pill warning">histogram</span></div><div class="sub">Distribution of imbalance magnitude. A tight distribution below warning is usually what engineering wants.</div><div class="chart-box"><canvas id="imbHist"></canvas></div></div></div>
|
||||
<div class="grid cards"><div class="glass card"><div class="kicker">Mean / σ total</div><div id="mean-total" class="value mono">--</div><div id="mean-total-sub" class="sub">P95 / P99 and warning occupancy</div></div><div class="glass card"><div class="kicker">Mean / σ imbalance</div><div id="mean-imb" class="value mono">--</div><div id="mean-imb-sub" class="sub">P95 and critical occupancy</div></div><div class="glass card"><div class="kicker">CPU warning / critical</div><div id="cpu-total" class="value mono">--</div><div class="sub">One-sided capability against upper limits</div></div><div class="glass card"><div class="kicker">Stability</div><div id="stability" class="value mono">--</div><div id="stability-sub" class="sub">Loading…</div></div></div>
|
||||
<div class="glass page"><div class="row"><h2 style="margin:0;font-size:28px">Top outliers</h2><div class="spacer"></div><span class="pill critical">review points</span></div><div class="sub">Combined overload and imbalance stress points worth engineering review.</div><div class="table-wrap" style="margin-top:12px"><table><thead><tr><th>Time</th><th>Total %</th><th>Total kN</th><th>L %</th><th>R %</th><th>Imb %</th></tr></thead><tbody id="outlier-body"><tr><td colspan="6">No data</td></tr></tbody></table></div></div>
|
||||
</div>
|
||||
<script src="/static/app-common.js"></script>
|
||||
<script>
|
||||
let currentWindow='1h', cfg={ui:{title:'Force Monitor',unit_force:'kN',unit_percent:'%'},thresholds:{warning_percent:80,critical_percent:95,imbalance_warning_percent:10,imbalance_critical_percent:20}}, totalChart=null, imbChart=null;
|
||||
function fmt(n,d=2){return Number(n||0).toFixed(d)}
|
||||
function updateChartTheme(){const light=document.body.dataset.theme==='light'; [totalChart,imbChart].forEach(ch=>{ if(!ch) return; ch.options.scales.x.ticks.color=light?'#334155':'#a1a1aa'; ch.options.scales.y.ticks.color=light?'#334155':'#a1a1aa'; ch.options.scales.x.grid.color=light?'rgba(15,23,42,.10)':'rgba(255,255,255,.06)'; ch.options.scales.y.grid.color=light?'rgba(15,23,42,.10)':'rgba(255,255,255,.06)'; ch.update('none');});}
|
||||
function makeHistChart(id,label,color){return new Chart(document.getElementById(id),{type:'bar',data:{labels:[],datasets:[{label:label,borderColor:color,backgroundColor:color+'55',data:[]}]},options:{responsive:true,maintainAspectRatio:false,animation:false,plugins:{legend:{labels:{color:'#f4f4f5'}}},scales:{x:{grid:{color:'rgba(255,255,255,.06)'},ticks:{color:'#a1a1aa'}},y:{grid:{color:'rgba(255,255,255,.06)'},ticks:{color:'#a1a1aa'}}}}});}
|
||||
async function loadCfg(){try{cfg=await AppUI.fetchJson('/api/config/public',{timeoutMs:8000});}catch(e){console.warn('Config load error:',e)}}
|
||||
async function refresh(){const r=await fetch('/api/process-capability?window='+encodeURIComponent(currentWindow),{cache:'no-store'}); if(!r.ok) throw new Error('HTTP '+r.status); const d=await r.json(); document.getElementById('window-label').textContent='Window: '+d.window+' • '+d.from+' → '+d.to; document.getElementById('total-cpk-critical').textContent=fmt(d.total_cpk_critical); document.getElementById('total-cpk-sub').textContent='Warning Cpk '+fmt(d.total_cpk_warning)+' • critical occupancy '+fmt(d.total_above_critical_pct,1)+'%'; document.getElementById('imb-cpk-critical').textContent=fmt(d.imbalance_cpk_critical); document.getElementById('imb-cpk-sub').textContent='Warning Cpk '+fmt(d.imbalance_cpk_warning)+' • critical occupancy '+fmt(d.imbalance_above_critical_pct,1)+'%'; document.getElementById('corr-value').textContent=fmt(d.left_right_correlation,3); document.getElementById('action-pill').textContent=(d.total_cpk_critical<1 || d.imbalance_cpk_critical<1)?'ACT':'OK'; document.getElementById('action-pill').className='value '+((d.total_cpk_critical<1 || d.imbalance_cpk_critical<1)?'critical':'good'); document.getElementById('action-text').textContent=d.suggested_action||'--'; document.getElementById('mean-total').textContent=fmt(d.total_mean_pct,1)+(cfg.ui.unit_percent||'%')+' / '+fmt(d.total_std_pct,2); document.getElementById('mean-total-sub').textContent='P95 '+fmt(d.total_p95_pct,1)+' • P99 '+fmt(d.total_p99_pct,1)+' • above warn '+fmt(d.total_above_warning_pct,1)+'%'; document.getElementById('mean-imb').textContent=fmt(d.imbalance_mean_pct,1)+(cfg.ui.unit_percent||'%')+' / '+fmt(d.imbalance_std_pct,2); document.getElementById('mean-imb-sub').textContent='P95 '+fmt(d.imbalance_p95_pct,1)+' • above warn '+fmt(d.imbalance_above_warning_pct,1)+'%'; document.getElementById('cpu-total').textContent=fmt(d.total_cpu_warning)+' / '+fmt(d.total_cpu_critical); document.getElementById('stability').textContent=String(d.stability||'--').toUpperCase(); document.getElementById('stability').className='value mono '+(d.stability==='unstable'?'critical':d.stability==='caution'?'warning':'good'); document.getElementById('stability-sub').textContent=d.stability_reason||'--';
|
||||
if(!totalChart){ totalChart=makeHistChart('totalHist','Total %','#22d3ee'); imbChart=makeHistChart('imbHist','Imbalance %','#f59e0b'); updateChartTheme();}
|
||||
totalChart.data.labels=(d.total_histogram||[]).map(b=>fmt(b.start,0)+'-'+fmt(b.end,0)); totalChart.data.datasets[0].data=(d.total_histogram||[]).map(b=>b.count); totalChart.update('none'); imbChart.data.labels=(d.imbalance_histogram||[]).map(b=>fmt(b.start,0)+'-'+fmt(b.end,0)); imbChart.data.datasets[0].data=(d.imbalance_histogram||[]).map(b=>b.count); imbChart.update('none');
|
||||
const body=document.getElementById('outlier-body'); const rows=(d.top_outliers||[]).map(p=>'<tr><td>'+p.time+'</td><td>'+fmt(p.total_percent,1)+'</td><td>'+fmt(p.total_kn,1)+'</td><td>'+fmt(p.left_percent,1)+'</td><td>'+fmt(p.right_percent,1)+'</td><td>'+fmt(p.imbalance_percent,1)+'</td></tr>').join(''); body.innerHTML=rows||'<tr><td colspan="6">No data</td></tr>';}
|
||||
function useWindow(v){currentWindow=v; document.querySelectorAll('.window-btn').forEach(btn=>btn.classList.toggle('primary',btn.dataset.window===v)); refresh().catch(console.warn)}
|
||||
AppUI.initTheme({ onChange: ()=>{ if(totalChart||imbChart) updateChartTheme(); } }); AppUI.initFullscreen({ buttonId:'fullscreen-toggle' }); document.getElementById('refresh-btn').addEventListener('click',()=>refresh().catch(console.warn)); document.getElementById('apply-window').addEventListener('click',()=>{const v=document.getElementById('custom-window').value.trim(); if(v) useWindow(v)}); document.querySelectorAll('.window-btn').forEach(btn=>btn.addEventListener('click',()=>useWindow(btn.dataset.window))); loadCfg().then(()=>refresh().catch(console.warn));
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Force Monitor — Process Capability</title>
|
||||
<script src="/static/chart.umd.min.js"></script>
|
||||
<style>
|
||||
:root{--bg1:#050816;--bg2:#0b1224;--panel:rgba(255,255,255,.055);--border:rgba(255,255,255,.1);--text:#f4f4f5;--muted:#a1a1aa;--muted2:#71717a;--btnbg:rgba(255,255,255,.05);--good:#34d399;--warn:#facc15;--bad:#f87171;--info:#93c5fd;}body[data-theme="light"]{--bg1:#eef4ff;--bg2:#f8fafc;--panel:rgba(255,255,255,.84);--border:rgba(15,23,42,.1);--text:#0f172a;--muted:#475569;--muted2:#64748b;--btnbg:rgba(255,255,255,.88);--good:#059669;--warn:#b45309;--bad:#dc2626;--info:#1d4ed8;}*{box-sizing:border-box}body{margin:0;min-height:100vh;color:var(--text);font-family:'Segoe UI',system-ui,sans-serif;background:radial-gradient(circle at 10% 10%, rgba(34,211,238,.12), transparent 18%),radial-gradient(circle at 90% 10%, rgba(168,85,247,.14), transparent 18%),linear-gradient(180deg,var(--bg1),var(--bg2));}.wrap{width:min(95vw,1720px);margin:0 auto;padding:24px}.glass{background:var(--panel);border:1px solid var(--border);border-radius:24px;backdrop-filter:blur(14px);-webkit-backdrop-filter:blur(14px)}.nav,.row,.toolbar{display:flex;gap:12px;flex-wrap:wrap;align-items:center}.spacer{flex:1 1 auto}.btn,.input{min-height:42px;border-radius:14px;border:1px solid var(--border);background:var(--btnbg);color:var(--text);padding:10px 14px;font:inherit}.btn{text-decoration:none;font-weight:600;display:inline-flex;align-items:center;justify-content:center;cursor:pointer}.btn.primary{background:rgba(14,165,233,.14);border-color:rgba(14,165,233,.35)}.page{padding:20px 22px;margin-bottom:18px}.kicker{font-size:11px;letter-spacing:.22em;text-transform:uppercase;color:var(--muted2)}.sub{color:var(--muted);margin-top:8px}.grid{display:grid;gap:16px}.cards{grid-template-columns:repeat(auto-fit,minmax(220px,1fr));margin-bottom:18px}.card{padding:18px 20px}.value{font-size:34px;font-weight:800;margin-top:8px}.mono{font-family:ui-monospace,SFMono-Regular,Consolas,monospace}.chart-grid{display:grid;grid-template-columns:1fr 1fr;gap:16px}.chart-box{height:360px}.table-wrap{overflow:auto}table{width:100%;border-collapse:collapse}th,td{padding:12px 10px;border-bottom:1px solid var(--border);text-align:left}th{font-size:12px;color:var(--muted2);text-transform:uppercase;letter-spacing:.16em}.pill{display:inline-flex;align-items:center;justify-content:center;min-width:88px;padding:4px 10px;border-radius:999px;font-size:12px;font-weight:700;border:1px solid var(--border)}.good{color:var(--good)}.warning{color:var(--warn)}.critical{color:var(--bad)}@media(max-width:1080px){.chart-grid{grid-template-columns:1fr}.wrap{padding:16px}}</style></head>
|
||||
<body data-theme="dark"><div class="wrap">
|
||||
<div class="nav" style="margin-bottom:18px"><a class="btn" href="/">Dashboard</a><a class="btn" href="/history">History</a><a class="btn" href="/alarms">Alarms</a><a class="btn" href="/kiosk">Kiosk</a><a class="btn primary" href="/process-capability">Process capability</a><a class="btn" href="/reports">Reports</a><a class="btn" href="/license">License</a><div class="spacer"></div><button id="theme-toggle" class="btn" type="button">Light theme</button><button id="fullscreen-toggle" class="btn" type="button">Enter fullscreen</button></div>
|
||||
<div class="glass page"><div class="row"><div><div class="kicker">Engineering capability</div><h1 style="margin:8px 0 0;font-size:42px;line-height:1.04">Process Capability & Distribution</h1><div class="sub">Histogram-based force and imbalance capability, one-sided CPU/CPK-style indicators against your configured thresholds, correlation between left and right columns, and suggested engineering action.</div></div><div class="spacer"></div><div class="mono sub" id="window-label">Window: --</div></div></div>
|
||||
<div class="glass page"><div class="toolbar"><button class="btn primary window-btn" data-window="1h">1h</button><button class="btn window-btn" data-window="8h">8h</button><button class="btn window-btn" data-window="24h">24h</button><button class="btn window-btn" data-window="7d">7d</button><input id="custom-window" class="input" style="width:140px" placeholder="e.g. 3h or 2d"><button id="apply-window" class="btn" type="button">Apply</button><div class="spacer"></div><button id="refresh-btn" class="btn" type="button">Refresh</button></div></div>
|
||||
<div class="grid cards"><div class="glass card"><div class="kicker">Total Cpk @ critical</div><div id="total-cpk-critical" class="value mono">--</div><div id="total-cpk-sub" class="sub">Capability versus critical load limit</div></div><div class="glass card"><div class="kicker">Imbalance Cpk @ critical</div><div id="imb-cpk-critical" class="value mono">--</div><div id="imb-cpk-sub" class="sub">Capability versus critical imbalance limit</div></div><div class="glass card"><div class="kicker">Left ↔ right correlation</div><div id="corr-value" class="value mono">--</div><div class="sub">Closer to 1.00 means both sides move together</div></div><div class="glass card"><div class="kicker">Suggested action</div><div id="action-pill" class="value" style="font-size:28px">--</div><div id="action-text" class="sub">Loading capability guidance…</div></div></div>
|
||||
<div class="chart-grid"><div class="glass page"><div class="row"><h2 style="margin:0;font-size:28px">Total force distribution</h2><div class="spacer"></div><span class="pill good">histogram</span></div><div class="sub">Distribution of total peak force against configured warning and critical boundaries.</div><div class="chart-box"><canvas id="totalHist"></canvas></div></div><div class="glass page"><div class="row"><h2 style="margin:0;font-size:28px">Imbalance distribution</h2><div class="spacer"></div><span class="pill warning">histogram</span></div><div class="sub">Distribution of imbalance magnitude. A tight distribution below warning is usually what engineering wants.</div><div class="chart-box"><canvas id="imbHist"></canvas></div></div></div>
|
||||
<div class="grid cards"><div class="glass card"><div class="kicker">Mean / σ total</div><div id="mean-total" class="value mono">--</div><div id="mean-total-sub" class="sub">P95 / P99 and warning occupancy</div></div><div class="glass card"><div class="kicker">Mean / σ imbalance</div><div id="mean-imb" class="value mono">--</div><div id="mean-imb-sub" class="sub">P95 and critical occupancy</div></div><div class="glass card"><div class="kicker">CPU warning / critical</div><div id="cpu-total" class="value mono">--</div><div class="sub">One-sided capability against upper limits</div></div><div class="glass card"><div class="kicker">Stability</div><div id="stability" class="value mono">--</div><div id="stability-sub" class="sub">Loading…</div></div></div>
|
||||
<div class="glass page"><div class="row"><h2 style="margin:0;font-size:28px">Top outliers</h2><div class="spacer"></div><span class="pill critical">review points</span></div><div class="sub">Combined overload and imbalance stress points worth engineering review.</div><div class="table-wrap" style="margin-top:12px"><table><thead><tr><th>Time</th><th>Total %</th><th>Total kN</th><th>L %</th><th>R %</th><th>Imb %</th></tr></thead><tbody id="outlier-body"><tr><td colspan="6">No data</td></tr></tbody></table></div></div>
|
||||
</div>
|
||||
<script src="/static/app-common.js"></script>
|
||||
<script>
|
||||
let currentWindow='1h', cfg={ui:{title:'Force Monitor',unit_force:'kN',unit_percent:'%'},thresholds:{warning_percent:80,critical_percent:95,imbalance_warning_percent:10,imbalance_critical_percent:20}}, totalChart=null, imbChart=null;
|
||||
function fmt(n,d=2){return Number(n||0).toFixed(d)}
|
||||
function updateChartTheme(){const light=document.body.dataset.theme==='light'; [totalChart,imbChart].forEach(ch=>{ if(!ch) return; ch.options.scales.x.ticks.color=light?'#334155':'#a1a1aa'; ch.options.scales.y.ticks.color=light?'#334155':'#a1a1aa'; ch.options.scales.x.grid.color=light?'rgba(15,23,42,.10)':'rgba(255,255,255,.06)'; ch.options.scales.y.grid.color=light?'rgba(15,23,42,.10)':'rgba(255,255,255,.06)'; ch.update('none');});}
|
||||
function makeHistChart(id,label,color){return new Chart(document.getElementById(id),{type:'bar',data:{labels:[],datasets:[{label:label,borderColor:color,backgroundColor:color+'55',data:[]}]},options:{responsive:true,maintainAspectRatio:false,animation:false,plugins:{legend:{labels:{color:'#f4f4f5'}}},scales:{x:{grid:{color:'rgba(255,255,255,.06)'},ticks:{color:'#a1a1aa'}},y:{grid:{color:'rgba(255,255,255,.06)'},ticks:{color:'#a1a1aa'}}}}});}
|
||||
async function loadCfg(){try{cfg=await AppUI.fetchJson('/api/config/public',{timeoutMs:8000});}catch(e){console.warn('Config load error:',e)}}
|
||||
async function refresh(){const r=await fetch('/api/process-capability?window='+encodeURIComponent(currentWindow),{cache:'no-store'}); if(!r.ok) throw new Error('HTTP '+r.status); const d=await r.json(); document.getElementById('window-label').textContent='Window: '+d.window+' • '+d.from+' → '+d.to; document.getElementById('total-cpk-critical').textContent=fmt(d.total_cpk_critical); document.getElementById('total-cpk-sub').textContent='Warning Cpk '+fmt(d.total_cpk_warning)+' • critical occupancy '+fmt(d.total_above_critical_pct,1)+'%'; document.getElementById('imb-cpk-critical').textContent=fmt(d.imbalance_cpk_critical); document.getElementById('imb-cpk-sub').textContent='Warning Cpk '+fmt(d.imbalance_cpk_warning)+' • critical occupancy '+fmt(d.imbalance_above_critical_pct,1)+'%'; document.getElementById('corr-value').textContent=fmt(d.left_right_correlation,3); document.getElementById('action-pill').textContent=(d.total_cpk_critical<1 || d.imbalance_cpk_critical<1)?'ACT':'OK'; document.getElementById('action-pill').className='value '+((d.total_cpk_critical<1 || d.imbalance_cpk_critical<1)?'critical':'good'); document.getElementById('action-text').textContent=d.suggested_action||'--'; document.getElementById('mean-total').textContent=fmt(d.total_mean_pct,1)+(cfg.ui.unit_percent||'%')+' / '+fmt(d.total_std_pct,2); document.getElementById('mean-total-sub').textContent='P95 '+fmt(d.total_p95_pct,1)+' • P99 '+fmt(d.total_p99_pct,1)+' • above warn '+fmt(d.total_above_warning_pct,1)+'%'; document.getElementById('mean-imb').textContent=fmt(d.imbalance_mean_pct,1)+(cfg.ui.unit_percent||'%')+' / '+fmt(d.imbalance_std_pct,2); document.getElementById('mean-imb-sub').textContent='P95 '+fmt(d.imbalance_p95_pct,1)+' • above warn '+fmt(d.imbalance_above_warning_pct,1)+'%'; document.getElementById('cpu-total').textContent=fmt(d.total_cpu_warning)+' / '+fmt(d.total_cpu_critical); document.getElementById('stability').textContent=String(d.stability||'--').toUpperCase(); document.getElementById('stability').className='value mono '+(d.stability==='unstable'?'critical':d.stability==='caution'?'warning':'good'); document.getElementById('stability-sub').textContent=d.stability_reason||'--';
|
||||
if(!totalChart){ totalChart=makeHistChart('totalHist','Total %','#22d3ee'); imbChart=makeHistChart('imbHist','Imbalance %','#f59e0b'); updateChartTheme();}
|
||||
totalChart.data.labels=(d.total_histogram||[]).map(b=>fmt(b.start,0)+'-'+fmt(b.end,0)); totalChart.data.datasets[0].data=(d.total_histogram||[]).map(b=>b.count); totalChart.update('none'); imbChart.data.labels=(d.imbalance_histogram||[]).map(b=>fmt(b.start,0)+'-'+fmt(b.end,0)); imbChart.data.datasets[0].data=(d.imbalance_histogram||[]).map(b=>b.count); imbChart.update('none');
|
||||
const body=document.getElementById('outlier-body'); const rows=(d.top_outliers||[]).map(p=>'<tr><td>'+p.time+'</td><td>'+fmt(p.total_percent,1)+'</td><td>'+fmt(p.total_kn,1)+'</td><td>'+fmt(p.left_percent,1)+'</td><td>'+fmt(p.right_percent,1)+'</td><td>'+fmt(p.imbalance_percent,1)+'</td></tr>').join(''); body.innerHTML=rows||'<tr><td colspan="6">No data</td></tr>';}
|
||||
function useWindow(v){currentWindow=v; document.querySelectorAll('.window-btn').forEach(btn=>btn.classList.toggle('primary',btn.dataset.window===v)); refresh().catch(console.warn)}
|
||||
AppUI.initTheme({ onChange: ()=>{ if(totalChart||imbChart) updateChartTheme(); } }); AppUI.initFullscreen({ buttonId:'fullscreen-toggle' }); document.getElementById('refresh-btn').addEventListener('click',()=>refresh().catch(console.warn)); document.getElementById('apply-window').addEventListener('click',()=>{const v=document.getElementById('custom-window').value.trim(); if(v) useWindow(v)}); document.querySelectorAll('.window-btn').forEach(btn=>btn.addEventListener('click',()=>useWindow(btn.dataset.window))); loadCfg().then(()=>refresh().catch(console.warn));
|
||||
</script></body></html>
|
||||
|
|
@ -1,25 +1,25 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Force Monitor — Reports</title>
|
||||
<script src="/static/chart.umd.min.js"></script>
|
||||
<style>
|
||||
:root{--bg1:#050816;--bg2:#0b1224;--panel:rgba(255,255,255,.055);--border:rgba(255,255,255,.1);--text:#f4f4f5;--muted:#a1a1aa;--muted2:#71717a;--btnbg:rgba(255,255,255,.05);--good:#34d399;--warn:#facc15;--bad:#f87171;--info:#93c5fd;}body[data-theme="light"]{--bg1:#eef4ff;--bg2:#f8fafc;--panel:rgba(255,255,255,.84);--border:rgba(15,23,42,.1);--text:#0f172a;--muted:#475569;--muted2:#64748b;--btnbg:rgba(255,255,255,.88);--good:#059669;--warn:#b45309;--bad:#dc2626;--info:#1d4ed8;}*{box-sizing:border-box}body{margin:0;min-height:100vh;color:var(--text);font-family:'Segoe UI',system-ui,sans-serif;background:radial-gradient(circle at 10% 10%, rgba(34,211,238,.12), transparent 18%),radial-gradient(circle at 90% 10%, rgba(168,85,247,.14), transparent 18%),linear-gradient(180deg,var(--bg1),var(--bg2));}.wrap{width:min(95vw,1760px);margin:0 auto;padding:24px}.glass{background:var(--panel);border:1px solid var(--border);border-radius:24px;backdrop-filter:blur(14px);-webkit-backdrop-filter:blur(14px)}.nav,.row,.toolbar{display:flex;gap:12px;flex-wrap:wrap;align-items:center}.spacer{flex:1 1 auto}.btn,.input{min-height:42px;border-radius:14px;border:1px solid var(--border);background:var(--btnbg);color:var(--text);padding:10px 14px;font:inherit}.btn{text-decoration:none;font-weight:600;display:inline-flex;align-items:center;justify-content:center;cursor:pointer}.btn.primary{background:rgba(14,165,233,.14);border-color:rgba(14,165,233,.35)}.page{padding:20px 22px;margin-bottom:18px}.kicker{font-size:11px;letter-spacing:.22em;color:var(--muted2);text-transform:uppercase}.sub{color:var(--muted);margin-top:8px}.grid{display:grid;gap:16px}.cards{grid-template-columns:repeat(auto-fit,minmax(220px,1fr));margin-bottom:18px}.card{padding:18px 20px}.value{font-size:34px;font-weight:800;margin-top:8px}.mono{font-family:ui-monospace,SFMono-Regular,Consolas,monospace}.chart-box{height:420px}.list{margin:10px 0 0;padding-left:18px}.list li{margin:8px 0;color:var(--muted)}.pill{display:inline-flex;align-items:center;justify-content:center;min-width:88px;padding:4px 10px;border-radius:999px;font-size:12px;font-weight:700;border:1px solid var(--border)}.good{color:var(--good)}.warning{color:var(--warn)}.critical{color:var(--bad)}.table-wrap{overflow:auto}table{width:100%;border-collapse:collapse}th,td{padding:12px 10px;border-bottom:1px solid var(--border);text-align:left}th{font-size:12px;color:var(--muted2);text-transform:uppercase;letter-spacing:.16em}@media(max-width:1080px){.wrap{padding:16px}}</style></head>
|
||||
<body data-theme="dark"><div class="wrap">
|
||||
<div class="nav" style="margin-bottom:18px"><a class="btn" href="/">Dashboard</a><a class="btn" href="/history">History</a><a class="btn" href="/alarms">Alarms</a><a class="btn" href="/kiosk">Kiosk</a><a class="btn" href="/process-capability">Process capability</a><a class="btn primary" href="/reports">Reports</a><a class="btn" href="/license">License</a><div class="spacer"></div><button id="theme-toggle" class="btn" type="button">Light theme</button><button id="fullscreen-toggle" class="btn" type="button">Enter fullscreen</button></div>
|
||||
<div class="glass page"><div class="row"><div><div class="kicker">Management & engineering report</div><h1 style="margin:8px 0 0;font-size:42px;line-height:1.04">Shift, Day & Week Reports</h1><div class="sub">A report-friendly view for engineering and boss departments with health score, availability estimate, event counts, peak summaries, trend deltas, and a bucket chart for the selected period.</div></div><div class="spacer"></div><div class="mono sub" id="report-range">Window: --</div></div></div>
|
||||
<div class="glass page"><div class="toolbar"><button class="btn primary window-btn" data-window="8h">Shift (8h)</button><button class="btn window-btn" data-window="24h">Day</button><button class="btn window-btn" data-window="7d">Week</button><button class="btn window-btn" data-window="30d">Month</button><input id="custom-window" class="input" style="width:160px" placeholder="e.g. 48h or 14d"><button id="apply-window" class="btn" type="button">Apply</button><div class="spacer"></div><button id="refresh-btn" class="btn" type="button">Refresh</button><button id="download-json" class="btn" type="button">Download JSON</button></div></div>
|
||||
<div class="grid cards"><div class="glass card"><div class="kicker">Health score</div><div id="health" class="value mono">--</div><div id="health-sub" class="sub">Availability and event pressure</div></div><div class="glass card"><div class="kicker">Avg / peak total</div><div id="avg-peak" class="value mono">--</div><div id="avg-peak-sub" class="sub">Total force summary</div></div><div class="glass card"><div class="kicker">Avg / peak imbalance</div><div id="avg-imb" class="value mono">--</div><div id="avg-imb-sub" class="sub">Centering summary</div></div><div class="glass card"><div class="kicker">Events</div><div id="events" class="value mono">--</div><div id="events-sub" class="sub">Warnings, criticals, PLC disconnects</div></div></div>
|
||||
<div class="glass page"><div class="row"><h2 style="margin:0;font-size:28px">Executive summary</h2><div class="spacer"></div><span id="summary-pill" class="pill good">loading</span></div><div id="executive-summary" class="sub" style="font-size:18px;margin-top:14px">Loading report…</div><ul id="findings" class="list"><li>Loading findings…</li></ul></div>
|
||||
<div class="glass page"><div class="row"><h2 style="margin:0;font-size:28px">Bucket trend</h2><div class="spacer"></div><span class="pill">selected period</span></div><div class="sub">Each bucket summarizes average total force, maximum force, and event density inside the selected report window.</div><div class="chart-box"><canvas id="reportChart"></canvas></div></div>
|
||||
<div class="glass page"><div class="row"><h2 style="margin:0;font-size:28px">Top peaks in report window</h2><div class="spacer"></div><span class="pill critical">top load moments</span></div><div class="table-wrap" style="margin-top:12px"><table><thead><tr><th>Time</th><th>Total %</th><th>Total kN</th><th>Imb %</th><th>L %</th><th>R %</th></tr></thead><tbody id="top-peaks-body"><tr><td colspan="6">No data</td></tr></tbody></table></div></div>
|
||||
</div>
|
||||
<script src="/static/app-common.js"></script>
|
||||
<script>
|
||||
let currentWindow='8h', reportCache=null, cfg={ui:{unit_force:'kN',unit_percent:'%'}}, chart=null;
|
||||
function fmt(n,d=1){return Number(n||0).toFixed(d)} function setTheme(theme){if(chart){const light=theme==='light'; chart.options.scales.x.ticks.color=light?'#334155':'#a1a1aa'; chart.options.scales.y.ticks.color=light?'#334155':'#a1a1aa'; chart.options.scales.y1.ticks.color=light?'#334155':'#a1a1aa'; chart.options.scales.x.grid.color=light?'rgba(15,23,42,.10)':'rgba(255,255,255,.06)'; chart.options.scales.y.grid.color=light?'rgba(15,23,42,.10)':'rgba(255,255,255,.06)'; chart.options.scales.y1.grid.color='transparent'; chart.update('none');}}
|
||||
|
||||
async function loadCfg(){try{cfg=await AppUI.fetchJson('/api/config/public',{timeoutMs:8000});}catch(e){console.warn('Config load error:',e)}}
|
||||
function makeChart(){chart=new Chart(document.getElementById('reportChart'),{type:'bar',data:{labels:[],datasets:[{type:'bar',label:'Avg total %',backgroundColor:'rgba(34,211,238,.55)',borderColor:'#22d3ee',data:[]},{type:'line',label:'Max total %',borderColor:'#f87171',backgroundColor:'rgba(248,113,113,.12)',tension:.18,borderWidth:3,data:[],yAxisID:'y'},{type:'line',label:'Warning+Critical events',borderColor:'#facc15',backgroundColor:'rgba(250,204,21,.10)',tension:.18,borderWidth:3,data:[],yAxisID:'y1'}]},options:{responsive:true,maintainAspectRatio:false,animation:false,plugins:{legend:{labels:{color:'#f4f4f5'}}},scales:{x:{grid:{color:'rgba(255,255,255,.06)'},ticks:{color:'#a1a1aa'}},y:{grid:{color:'rgba(255,255,255,.06)'},ticks:{color:'#a1a1aa'}},y1:{position:'right',grid:{color:'transparent'},ticks:{color:'#a1a1aa'}}}}}); setTheme(document.body.dataset.theme||'dark');}
|
||||
async function refresh(){const r=await fetch('/api/reports/summary?window='+encodeURIComponent(currentWindow),{cache:'no-store'}); if(!r.ok) throw new Error('HTTP '+r.status); const d=await r.json(); reportCache=d; document.getElementById('report-range').textContent='Window: '+d.window+' • '+d.from+' → '+d.to; document.getElementById('health').textContent=d.health_score+'/100'; document.getElementById('health').className='value mono '+(d.health_score<70?'critical':d.health_score<85?'warning':'good'); document.getElementById('health-sub').textContent='Availability '+fmt(d.availability_pct,1)+'% • stability '+String(d.stability||'--').toUpperCase(); document.getElementById('avg-peak').textContent=fmt(d.average_total_pct,1)+' / '+fmt(d.peak_total_pct,1)+(cfg.ui.unit_percent||'%'); document.getElementById('avg-peak-sub').textContent='Avg '+fmt(d.average_total_kn,1)+' '+(cfg.ui.unit_force||'kN')+' • peak '+fmt(d.peak_total_kn,1)+' '+(cfg.ui.unit_force||'kN'); document.getElementById('avg-imb').textContent=fmt(d.average_imbalance_pct,1)+' / '+fmt(d.peak_imbalance_pct,1)+(cfg.ui.unit_percent||'%'); document.getElementById('avg-imb-sub').textContent='Δ force '+((d.force_delta_pct>=0)?'+':'')+fmt(d.force_delta_pct,1)+' • Δ imb '+((d.imbalance_delta_pct>=0)?'+':'')+fmt(d.imbalance_delta_pct,1); document.getElementById('events').textContent=d.warning_events+' / '+d.critical_events; document.getElementById('events-sub').textContent='Warnings / criticals • PLC disconnects '+d.plc_disconnects; document.getElementById('executive-summary').textContent=d.executive_summary||'--'; document.getElementById('summary-pill').textContent=String(d.stability||'stable').toUpperCase(); document.getElementById('summary-pill').className='pill '+(d.stability==='unstable'?'critical':d.stability==='caution'?'warning':'good'); const findings=document.getElementById('findings'); findings.innerHTML=''; (d.findings||[]).forEach(item=>{const li=document.createElement('li'); li.textContent=item; findings.appendChild(li);}); if(!chart) makeChart(); chart.data.labels=(d.buckets||[]).map(b=>b.label); chart.data.datasets[0].data=(d.buckets||[]).map(b=>b.avg_total_pct); chart.data.datasets[1].data=(d.buckets||[]).map(b=>b.max_total_pct); chart.data.datasets[2].data=(d.buckets||[]).map(b=>(b.warning_events||0)+(b.critical_events||0)); chart.update('none'); const rows=(d.top_peaks||[]).map(p=>'<tr><td>'+p.time+'</td><td>'+fmt(p.total_percent,1)+'</td><td>'+fmt(p.total_kn,1)+'</td><td>'+fmt(p.imbalance_percent,1)+'</td><td>'+fmt(p.left_percent,1)+'</td><td>'+fmt(p.right_percent,1)+'</td></tr>').join(''); document.getElementById('top-peaks-body').innerHTML=rows||'<tr><td colspan="6">No data</td></tr>';}
|
||||
function useWindow(v){currentWindow=v; document.querySelectorAll('.window-btn').forEach(btn=>btn.classList.toggle('primary',btn.dataset.window===v)); refresh().catch(console.warn)}
|
||||
AppUI.initTheme({ onChange: ()=>{ if(chart) setTheme(document.body.dataset.theme || 'dark'); } }); AppUI.initFullscreen({ buttonId:'fullscreen-toggle' }); document.getElementById('refresh-btn').addEventListener('click',()=>refresh().catch(console.warn)); document.getElementById('apply-window').addEventListener('click',()=>{const v=document.getElementById('custom-window').value.trim(); if(v) useWindow(v)}); document.querySelectorAll('.window-btn').forEach(btn=>btn.addEventListener('click',()=>useWindow(btn.dataset.window))); document.getElementById('download-json').addEventListener('click',()=>{ if(!reportCache) return; const blob=new Blob([JSON.stringify(reportCache,null,2)],{type:'application/json'}); const a=document.createElement('a'); a.href=URL.createObjectURL(blob); a.download='force-monitor-report-'+currentWindow+'.json'; a.click(); URL.revokeObjectURL(a.href);}); loadCfg().then(()=>refresh().catch(console.warn));
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Force Monitor — Reports</title>
|
||||
<script src="/static/chart.umd.min.js"></script>
|
||||
<style>
|
||||
:root{--bg1:#050816;--bg2:#0b1224;--panel:rgba(255,255,255,.055);--border:rgba(255,255,255,.1);--text:#f4f4f5;--muted:#a1a1aa;--muted2:#71717a;--btnbg:rgba(255,255,255,.05);--good:#34d399;--warn:#facc15;--bad:#f87171;--info:#93c5fd;}body[data-theme="light"]{--bg1:#eef4ff;--bg2:#f8fafc;--panel:rgba(255,255,255,.84);--border:rgba(15,23,42,.1);--text:#0f172a;--muted:#475569;--muted2:#64748b;--btnbg:rgba(255,255,255,.88);--good:#059669;--warn:#b45309;--bad:#dc2626;--info:#1d4ed8;}*{box-sizing:border-box}body{margin:0;min-height:100vh;color:var(--text);font-family:'Segoe UI',system-ui,sans-serif;background:radial-gradient(circle at 10% 10%, rgba(34,211,238,.12), transparent 18%),radial-gradient(circle at 90% 10%, rgba(168,85,247,.14), transparent 18%),linear-gradient(180deg,var(--bg1),var(--bg2));}.wrap{width:min(95vw,1760px);margin:0 auto;padding:24px}.glass{background:var(--panel);border:1px solid var(--border);border-radius:24px;backdrop-filter:blur(14px);-webkit-backdrop-filter:blur(14px)}.nav,.row,.toolbar{display:flex;gap:12px;flex-wrap:wrap;align-items:center}.spacer{flex:1 1 auto}.btn,.input{min-height:42px;border-radius:14px;border:1px solid var(--border);background:var(--btnbg);color:var(--text);padding:10px 14px;font:inherit}.btn{text-decoration:none;font-weight:600;display:inline-flex;align-items:center;justify-content:center;cursor:pointer}.btn.primary{background:rgba(14,165,233,.14);border-color:rgba(14,165,233,.35)}.page{padding:20px 22px;margin-bottom:18px}.kicker{font-size:11px;letter-spacing:.22em;color:var(--muted2);text-transform:uppercase}.sub{color:var(--muted);margin-top:8px}.grid{display:grid;gap:16px}.cards{grid-template-columns:repeat(auto-fit,minmax(220px,1fr));margin-bottom:18px}.card{padding:18px 20px}.value{font-size:34px;font-weight:800;margin-top:8px}.mono{font-family:ui-monospace,SFMono-Regular,Consolas,monospace}.chart-box{height:420px}.list{margin:10px 0 0;padding-left:18px}.list li{margin:8px 0;color:var(--muted)}.pill{display:inline-flex;align-items:center;justify-content:center;min-width:88px;padding:4px 10px;border-radius:999px;font-size:12px;font-weight:700;border:1px solid var(--border)}.good{color:var(--good)}.warning{color:var(--warn)}.critical{color:var(--bad)}.table-wrap{overflow:auto}table{width:100%;border-collapse:collapse}th,td{padding:12px 10px;border-bottom:1px solid var(--border);text-align:left}th{font-size:12px;color:var(--muted2);text-transform:uppercase;letter-spacing:.16em}@media(max-width:1080px){.wrap{padding:16px}}</style></head>
|
||||
<body data-theme="dark"><div class="wrap">
|
||||
<div class="nav" style="margin-bottom:18px"><a class="btn" href="/">Dashboard</a><a class="btn" href="/history">History</a><a class="btn" href="/alarms">Alarms</a><a class="btn" href="/kiosk">Kiosk</a><a class="btn" href="/process-capability">Process capability</a><a class="btn primary" href="/reports">Reports</a><a class="btn" href="/license">License</a><div class="spacer"></div><button id="theme-toggle" class="btn" type="button">Light theme</button><button id="fullscreen-toggle" class="btn" type="button">Enter fullscreen</button></div>
|
||||
<div class="glass page"><div class="row"><div><div class="kicker">Management & engineering report</div><h1 style="margin:8px 0 0;font-size:42px;line-height:1.04">Shift, Day & Week Reports</h1><div class="sub">A report-friendly view for engineering and boss departments with health score, availability estimate, event counts, peak summaries, trend deltas, and a bucket chart for the selected period.</div></div><div class="spacer"></div><div class="mono sub" id="report-range">Window: --</div></div></div>
|
||||
<div class="glass page"><div class="toolbar"><button class="btn primary window-btn" data-window="8h">Shift (8h)</button><button class="btn window-btn" data-window="24h">Day</button><button class="btn window-btn" data-window="7d">Week</button><button class="btn window-btn" data-window="30d">Month</button><input id="custom-window" class="input" style="width:160px" placeholder="e.g. 48h or 14d"><button id="apply-window" class="btn" type="button">Apply</button><div class="spacer"></div><button id="refresh-btn" class="btn" type="button">Refresh</button><button id="download-json" class="btn" type="button">Download JSON</button></div></div>
|
||||
<div class="grid cards"><div class="glass card"><div class="kicker">Health score</div><div id="health" class="value mono">--</div><div id="health-sub" class="sub">Availability and event pressure</div></div><div class="glass card"><div class="kicker">Avg / peak total</div><div id="avg-peak" class="value mono">--</div><div id="avg-peak-sub" class="sub">Total force summary</div></div><div class="glass card"><div class="kicker">Avg / peak imbalance</div><div id="avg-imb" class="value mono">--</div><div id="avg-imb-sub" class="sub">Centering summary</div></div><div class="glass card"><div class="kicker">Events</div><div id="events" class="value mono">--</div><div id="events-sub" class="sub">Warnings, criticals, PLC disconnects</div></div></div>
|
||||
<div class="glass page"><div class="row"><h2 style="margin:0;font-size:28px">Executive summary</h2><div class="spacer"></div><span id="summary-pill" class="pill good">loading</span></div><div id="executive-summary" class="sub" style="font-size:18px;margin-top:14px">Loading report…</div><ul id="findings" class="list"><li>Loading findings…</li></ul></div>
|
||||
<div class="glass page"><div class="row"><h2 style="margin:0;font-size:28px">Bucket trend</h2><div class="spacer"></div><span class="pill">selected period</span></div><div class="sub">Each bucket summarizes average total force, maximum force, and event density inside the selected report window.</div><div class="chart-box"><canvas id="reportChart"></canvas></div></div>
|
||||
<div class="glass page"><div class="row"><h2 style="margin:0;font-size:28px">Top peaks in report window</h2><div class="spacer"></div><span class="pill critical">top load moments</span></div><div class="table-wrap" style="margin-top:12px"><table><thead><tr><th>Time</th><th>Total %</th><th>Total kN</th><th>Imb %</th><th>L %</th><th>R %</th></tr></thead><tbody id="top-peaks-body"><tr><td colspan="6">No data</td></tr></tbody></table></div></div>
|
||||
</div>
|
||||
<script src="/static/app-common.js"></script>
|
||||
<script>
|
||||
let currentWindow='8h', reportCache=null, cfg={ui:{unit_force:'kN',unit_percent:'%'}}, chart=null;
|
||||
function fmt(n,d=1){return Number(n||0).toFixed(d)} function setTheme(theme){if(chart){const light=theme==='light'; chart.options.scales.x.ticks.color=light?'#334155':'#a1a1aa'; chart.options.scales.y.ticks.color=light?'#334155':'#a1a1aa'; chart.options.scales.y1.ticks.color=light?'#334155':'#a1a1aa'; chart.options.scales.x.grid.color=light?'rgba(15,23,42,.10)':'rgba(255,255,255,.06)'; chart.options.scales.y.grid.color=light?'rgba(15,23,42,.10)':'rgba(255,255,255,.06)'; chart.options.scales.y1.grid.color='transparent'; chart.update('none');}}
|
||||
|
||||
async function loadCfg(){try{cfg=await AppUI.fetchJson('/api/config/public',{timeoutMs:8000});}catch(e){console.warn('Config load error:',e)}}
|
||||
function makeChart(){chart=new Chart(document.getElementById('reportChart'),{type:'bar',data:{labels:[],datasets:[{type:'bar',label:'Avg total %',backgroundColor:'rgba(34,211,238,.55)',borderColor:'#22d3ee',data:[]},{type:'line',label:'Max total %',borderColor:'#f87171',backgroundColor:'rgba(248,113,113,.12)',tension:.18,borderWidth:3,data:[],yAxisID:'y'},{type:'line',label:'Warning+Critical events',borderColor:'#facc15',backgroundColor:'rgba(250,204,21,.10)',tension:.18,borderWidth:3,data:[],yAxisID:'y1'}]},options:{responsive:true,maintainAspectRatio:false,animation:false,plugins:{legend:{labels:{color:'#f4f4f5'}}},scales:{x:{grid:{color:'rgba(255,255,255,.06)'},ticks:{color:'#a1a1aa'}},y:{grid:{color:'rgba(255,255,255,.06)'},ticks:{color:'#a1a1aa'}},y1:{position:'right',grid:{color:'transparent'},ticks:{color:'#a1a1aa'}}}}}); setTheme(document.body.dataset.theme||'dark');}
|
||||
async function refresh(){const r=await fetch('/api/reports/summary?window='+encodeURIComponent(currentWindow),{cache:'no-store'}); if(!r.ok) throw new Error('HTTP '+r.status); const d=await r.json(); reportCache=d; document.getElementById('report-range').textContent='Window: '+d.window+' • '+d.from+' → '+d.to; document.getElementById('health').textContent=d.health_score+'/100'; document.getElementById('health').className='value mono '+(d.health_score<70?'critical':d.health_score<85?'warning':'good'); document.getElementById('health-sub').textContent='Availability '+fmt(d.availability_pct,1)+'% • stability '+String(d.stability||'--').toUpperCase(); document.getElementById('avg-peak').textContent=fmt(d.average_total_pct,1)+' / '+fmt(d.peak_total_pct,1)+(cfg.ui.unit_percent||'%'); document.getElementById('avg-peak-sub').textContent='Avg '+fmt(d.average_total_kn,1)+' '+(cfg.ui.unit_force||'kN')+' • peak '+fmt(d.peak_total_kn,1)+' '+(cfg.ui.unit_force||'kN'); document.getElementById('avg-imb').textContent=fmt(d.average_imbalance_pct,1)+' / '+fmt(d.peak_imbalance_pct,1)+(cfg.ui.unit_percent||'%'); document.getElementById('avg-imb-sub').textContent='Δ force '+((d.force_delta_pct>=0)?'+':'')+fmt(d.force_delta_pct,1)+' • Δ imb '+((d.imbalance_delta_pct>=0)?'+':'')+fmt(d.imbalance_delta_pct,1); document.getElementById('events').textContent=d.warning_events+' / '+d.critical_events; document.getElementById('events-sub').textContent='Warnings / criticals • PLC disconnects '+d.plc_disconnects; document.getElementById('executive-summary').textContent=d.executive_summary||'--'; document.getElementById('summary-pill').textContent=String(d.stability||'stable').toUpperCase(); document.getElementById('summary-pill').className='pill '+(d.stability==='unstable'?'critical':d.stability==='caution'?'warning':'good'); const findings=document.getElementById('findings'); findings.innerHTML=''; (d.findings||[]).forEach(item=>{const li=document.createElement('li'); li.textContent=item; findings.appendChild(li);}); if(!chart) makeChart(); chart.data.labels=(d.buckets||[]).map(b=>b.label); chart.data.datasets[0].data=(d.buckets||[]).map(b=>b.avg_total_pct); chart.data.datasets[1].data=(d.buckets||[]).map(b=>b.max_total_pct); chart.data.datasets[2].data=(d.buckets||[]).map(b=>(b.warning_events||0)+(b.critical_events||0)); chart.update('none'); const rows=(d.top_peaks||[]).map(p=>'<tr><td>'+p.time+'</td><td>'+fmt(p.total_percent,1)+'</td><td>'+fmt(p.total_kn,1)+'</td><td>'+fmt(p.imbalance_percent,1)+'</td><td>'+fmt(p.left_percent,1)+'</td><td>'+fmt(p.right_percent,1)+'</td></tr>').join(''); document.getElementById('top-peaks-body').innerHTML=rows||'<tr><td colspan="6">No data</td></tr>';}
|
||||
function useWindow(v){currentWindow=v; document.querySelectorAll('.window-btn').forEach(btn=>btn.classList.toggle('primary',btn.dataset.window===v)); refresh().catch(console.warn)}
|
||||
AppUI.initTheme({ onChange: ()=>{ if(chart) setTheme(document.body.dataset.theme || 'dark'); } }); AppUI.initFullscreen({ buttonId:'fullscreen-toggle' }); document.getElementById('refresh-btn').addEventListener('click',()=>refresh().catch(console.warn)); document.getElementById('apply-window').addEventListener('click',()=>{const v=document.getElementById('custom-window').value.trim(); if(v) useWindow(v)}); document.querySelectorAll('.window-btn').forEach(btn=>btn.addEventListener('click',()=>useWindow(btn.dataset.window))); document.getElementById('download-json').addEventListener('click',()=>{ if(!reportCache) return; const blob=new Blob([JSON.stringify(reportCache,null,2)],{type:'application/json'}); const a=document.createElement('a'); a.href=URL.createObjectURL(blob); a.download='force-monitor-report-'+currentWindow+'.json'; a.click(); URL.revokeObjectURL(a.href);}); loadCfg().then(()=>refresh().catch(console.warn));
|
||||
</script></body></html>
|
||||
Loading…
Reference in a new issue