Files
Qris-Soundbox/ui/device-registry-monitoring/index.html

921 lines
46 KiB
HTML

<!DOCTYPE html>
<html class="light" lang="en"><head>
<meta charset="utf-8"/>
<meta content="width=device-width, initial-scale=1.0" name="viewport"/>
<title>Device Registry | Soundbox Ops</title>
<script src="https://cdn.tailwindcss.com?plugins=forms,container-queries"></script>
<link href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&amp;family=Inter:wght@400;500;600&amp;family=JetBrains+Mono&amp;display=swap" rel="stylesheet"/>
<link href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:wght,FILL@100..700,0..1&amp;display=swap" rel="stylesheet"/>
<link href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:wght,FILL@100..700,0..1&amp;display=swap" rel="stylesheet"/>
<style>
.material-symbols-outlined {
font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
vertical-align: middle;
}
[data-weight="fill"] .material-symbols-outlined {
font-variation-settings: 'FILL' 1;
}
::-webkit-scrollbar {
width: 6px;
height: 6px;
}
::-webkit-scrollbar-track {
background: transparent;
}
::-webkit-scrollbar-thumb {
background: #E2E8F0;
border-radius: 10px;
}
.data-table-container {
scrollbar-gutter: stable;
}
</style>
<script id="tailwind-config">
tailwind.config = {
darkMode: "class",
theme: {
extend: {
"colors": {
"surface-container-lowest": "#ffffff",
"on-tertiary": "#ffffff",
"secondary-fixed-dim": "#b7c8e1",
"warning": "#F59E0B",
"on-primary-fixed-variant": "#003ea8",
"inverse-surface": "#2e3039",
"surface": "#faf8ff",
"surface-container-low": "#f3f3fe",
"outline": "#737686",
"on-primary": "#ffffff",
"tertiary-fixed": "#ffdbcd",
"primary": "#004ac6",
"on-error-container": "#93000a",
"surface-tint": "#0053db",
"tertiary-container": "#bc4800",
"surface-variant": "#e1e2ed",
"on-tertiary-fixed": "#360f00",
"surface-container-high": "#e7e7f3",
"info": "#0EA5E9",
"slate-500": "#64748B",
"tertiary-fixed-dim": "#ffb596",
"on-surface": "#191b23",
"outline-variant": "#c3c6d7",
"error": "#ba1a1a",
"inverse-on-surface": "#f0f0fb",
"on-primary-fixed": "#00174b",
"surface-bright": "#faf8ff",
"surface-container": "#ededf9",
"error-container": "#ffdad6",
"slate-900": "#0F172A",
"inverse-primary": "#b4c5ff",
"on-tertiary-fixed-variant": "#7d2d00",
"slate-700": "#334155",
"slate-200": "#E2E8F0",
"on-background": "#191b23",
"on-error": "#ffffff",
"on-secondary": "#ffffff",
"secondary": "#505f76",
"on-secondary-fixed": "#0b1c30",
"on-secondary-fixed-variant": "#38485d",
"danger": "#DC2626",
"on-primary-container": "#eeefff",
"success": "#16A34A",
"on-tertiary-container": "#ffede6",
"surface-container-highest": "#e1e2ed",
"primary-fixed": "#dbe1ff",
"on-surface-variant": "#434655",
"secondary-container": "#d0e1fb",
"primary-container": "#2563eb",
"background": "#F8FAFC",
"primary-fixed-dim": "#b4c5ff",
"tertiary": "#943700",
"secondary-fixed": "#d3e4fe",
"surface-dim": "#d9d9e5",
"on-secondary-container": "#54647a",
"slate-100": "#F1F5F9"
},
"borderRadius": {
"DEFAULT": "0.125rem",
"lg": "0.25rem",
"xl": "0.5rem",
"full": "0.75rem"
},
"spacing": {
"page-padding": "24px",
"gutter": "24px",
"topbar-height": "72px",
"card-padding": "20px",
"row-height": "52px"
},
"fontFamily": {
"display-lg": ["Plus Jakarta Sans"],
"label-md": ["Inter"],
"headline-md": ["Plus Jakarta Sans"],
"body-md": ["Inter"],
"headline-lg": ["Plus Jakarta Sans"],
"body-lg": ["Inter"],
"metric-lg": ["Inter"],
"metric-sm": ["Inter"]
},
"fontSize": {
"display-lg": ["36px", { "lineHeight": "44px", "letterSpacing": "-0.02em", "fontWeight": "600" }],
"label-md": ["12px", { "lineHeight": "16px", "letterSpacing": "0.01em", "fontWeight": "500" }],
"headline-md": ["20px", { "lineHeight": "28px", "fontWeight": "600" }],
"body-md": ["14px", { "lineHeight": "20px", "fontWeight": "400" }],
"headline-lg": ["28px", { "lineHeight": "36px", "fontWeight": "600" }],
"body-lg": ["16px", { "lineHeight": "24px", "fontWeight": "400" }],
"metric-lg": ["32px", { "lineHeight": "40px", "fontWeight": "600" }],
"metric-sm": ["14px", { "lineHeight": "20px", "fontWeight": "600" }]
}
},
},
}
</script>
</head>
<body class="bg-background font-body-md text-on-background min-h-screen">
<!-- Sidebar Navigation -->
<aside class="w-64 h-full fixed left-0 top-0 bg-surface-container-lowest border-r border-slate-200 flex flex-col py-6 px-4 gap-2 z-50">
<div class="mb-8 px-2">
<h1 class="font-headline-md text-headline-md font-bold text-primary">Soundbox Ops</h1>
<p class="text-label-md font-label-md text-slate-500">Admin Console</p>
</div>
<nav class="flex flex-col gap-1 flex-1">
<a class="flex items-center gap-3 px-3 py-2 text-on-surface-variant hover:bg-slate-100 transition-colors rounded-lg" href="#">
<span class="material-symbols-outlined" data-icon="dashboard">dashboard</span>
<span class="font-body-md text-body-md">Overview</span>
</a>
<a class="flex items-center gap-3 px-3 py-2 text-on-surface-variant hover:bg-slate-100 transition-colors rounded-lg" href="#">
<span class="material-symbols-outlined" data-icon="storefront">storefront</span>
<span class="font-body-md text-body-md">Merchant Management</span>
</a>
<!-- Active State: Device Registry -->
<a class="flex items-center gap-3 px-3 py-2 bg-secondary-container text-on-secondary-container font-bold rounded-lg" href="#">
<span class="material-symbols-outlined" data-icon="speaker_group" data-weight="fill" style="font-variation-settings: 'FILL' 1;">speaker_group</span>
<span class="font-body-md text-body-md">Device Registry</span>
</a>
<a class="flex items-center gap-3 px-3 py-2 text-on-surface-variant hover:bg-slate-100 transition-colors rounded-lg" href="#">
<span class="material-symbols-outlined" data-icon="receipt_long">receipt_long</span>
<span class="font-body-md text-body-md">Transactions</span>
</a>
<a class="flex items-center gap-3 px-3 py-2 text-on-surface-variant hover:bg-slate-100 transition-colors rounded-lg" href="#">
<span class="material-symbols-outlined" data-icon="account_balance">account_balance</span>
<span class="font-body-md text-body-md">Ledger &amp; Settlement</span>
</a>
<a class="flex items-center gap-3 px-3 py-2 text-on-surface-variant hover:bg-slate-100 transition-colors rounded-lg" href="#">
<span class="material-symbols-outlined" data-icon="history_edu">history_edu</span>
<span class="font-body-md text-body-md">Audit Control</span>
</a>
</nav>
<div class="mt-auto flex flex-col gap-1 pt-4 border-t border-slate-100">
<a class="flex items-center gap-3 px-3 py-2 text-on-surface-variant hover:bg-slate-100 transition-colors rounded-lg" href="#">
<span class="material-symbols-outlined" data-icon="settings">settings</span>
<span class="font-body-md text-body-md">Settings</span>
</a>
<a class="flex items-center gap-3 px-3 py-2 text-on-surface-variant hover:bg-slate-100 transition-colors rounded-lg" href="#">
<span class="material-symbols-outlined" data-icon="help">help</span>
<span class="font-body-md text-body-md">Support</span>
</a>
</div>
</aside>
<!-- Top Navigation Bar -->
<header class="fixed top-0 right-0 h-[72px] flex justify-between items-center w-[calc(100%-256px)] ml-64 px-page-padding bg-surface-container-lowest z-40">
<div class="flex items-center gap-8">
<div class="relative w-96">
<span class="material-symbols-outlined absolute left-3 top-1/2 -translate-y-1/2 text-slate-400">search</span>
<input id="device-search-input" class="w-full bg-slate-50 border-none rounded-full pl-10 pr-4 py-2 text-body-md focus:ring-2 focus:ring-primary/20" placeholder="Search devices, merchants..." type="text"/>
</div>
<nav class="hidden md:flex gap-6">
<a class="text-primary font-bold border-b-2 border-primary h-[72px] flex items-center" href="#">Dashboard</a>
<a class="text-on-surface-variant hover:text-primary transition-colors h-[72px] flex items-center" href="#">System Health</a>
</nav>
</div>
<div class="flex items-center gap-4">
<button class="w-10 h-10 flex items-center justify-center rounded-full hover:bg-slate-100 text-on-surface-variant relative">
<span class="material-symbols-outlined" data-icon="notifications">notifications</span>
<span class="absolute top-2 right-2 w-2 h-2 bg-danger rounded-full border-2 border-white"></span>
</button>
<button class="w-10 h-10 flex items-center justify-center rounded-full hover:bg-slate-100 text-on-surface-variant">
<span class="material-symbols-outlined" data-icon="calendar_today">calendar_today</span>
</button>
<div class="h-8 w-[1px] bg-slate-200 mx-2"></div>
<img alt="Administrator Profile" class="w-8 h-8 rounded-full border border-slate-200" src="https://lh3.googleusercontent.com/aida-public/AB6AXuAUwYwdc49M8Tip_Q5HmjRqGoXJNad0776g4k4xB27qMd7FLleWQSH8N1gke6Z6TiIPEBkLv5roSTK4A6M7VQVJn70_OxUWPXBdbShZifG7LpCjVfBESpHZfmsCtWATl6JUy9Cb8LbwBsahotAx-TO6rXW0uyxuskJecoWJnTymG38_sBZTSACEQveLAkKoJEZPJw6e53HokMROjScOdO-c3-2BwWuW7f05y-2ZPXthdv6ZcmR3ViwtYPiPbARRzL_nY5udIyoXvZA"/>
</div>
</header>
<!-- Main Content Area -->
<main class="ml-64 pt-[72px] p-page-padding">
<!-- Page Header -->
<div class="flex justify-between items-end mb-8">
<div>
<h2 class="font-headline-lg text-headline-lg text-on-surface mb-1">Device Registry</h2>
<p class="text-body-md text-on-surface-variant">Manage and monitor all IoT soundbox units across the network.</p>
</div>
<button class="bg-primary hover:bg-primary-container text-on-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 transition-all active:scale-95">
<span class="material-symbols-outlined text-[20px]" data-icon="add">add</span>
Register New Device
</button>
</div>
<!-- Summary KPI Grid -->
<div class="grid grid-cols-1 md:grid-cols-3 gap-gutter mb-8">
<div class="bg-surface-container-lowest border border-slate-200 p-card-padding rounded-xl shadow-sm">
<div class="flex justify-between items-start mb-4">
<div class="w-10 h-10 bg-primary/10 text-primary rounded-lg flex items-center justify-center">
<span class="material-symbols-outlined" data-icon="devices">devices</span>
</div>
<span class="text-success text-metric-sm font-metric-sm flex items-center gap-1">
<span class="material-symbols-outlined text-[16px]">trending_up</span>
+24
</span>
</div>
<h3 class="text-label-md font-label-md text-slate-500 uppercase tracking-wider">Total Registered</h3>
<p id="device-kpi-total-registered" class="text-metric-lg font-metric-lg text-on-surface">1,200</p>
<div class="mt-4 w-full bg-slate-100 h-1.5 rounded-full overflow-hidden">
<div class="bg-primary h-full w-full"></div>
</div>
</div>
<div class="bg-surface-container-lowest border border-slate-200 p-card-padding rounded-xl shadow-sm">
<div class="flex justify-between items-start mb-4">
<div class="w-10 h-10 bg-success/10 text-success rounded-lg flex items-center justify-center">
<span class="material-symbols-outlined" data-icon="router">router</span>
</div>
<span class="text-success text-metric-sm font-metric-sm flex items-center gap-1">
<span class="material-symbols-outlined text-[16px]">check_circle</span>
75% Rate
</span>
</div>
<h3 class="text-label-md font-label-md text-slate-500 uppercase tracking-wider">Active Units</h3>
<p id="device-kpi-active-units" class="text-metric-lg font-metric-lg text-on-surface">900</p>
<div class="mt-4 w-full bg-slate-100 h-1.5 rounded-full overflow-hidden">
<div class="bg-success h-full w-3/4"></div>
</div>
</div>
<div class="bg-surface-container-lowest border border-slate-200 p-card-padding rounded-xl shadow-sm">
<div class="flex justify-between items-start mb-4">
<div class="w-10 h-10 bg-warning/10 text-warning rounded-lg flex items-center justify-center">
<span class="material-symbols-outlined" data-icon="inventory_2">inventory_2</span>
</div>
<span class="text-slate-500 text-metric-sm font-metric-sm">Unassigned</span>
</div>
<h3 class="text-label-md font-label-md text-slate-500 uppercase tracking-wider">Stock Available</h3>
<p id="device-kpi-unassigned" class="text-metric-lg font-metric-lg text-on-surface">300</p>
<div class="mt-4 w-full bg-slate-100 h-1.5 rounded-full overflow-hidden">
<div class="bg-warning h-full w-1/4"></div>
</div>
</div>
</div>
<!-- Filter Bar & Data Table -->
<div class="bg-surface-container-lowest border border-slate-200 rounded-xl shadow-sm overflow-hidden">
<!-- Filters -->
<div class="p-4 border-b border-slate-200 flex flex-wrap items-center gap-4 bg-slate-50/50">
<div class="flex items-center gap-2">
<span class="material-symbols-outlined text-slate-400" data-icon="filter_list">filter_list</span>
<span class="font-bold text-body-md">Filters</span>
</div>
<div class="h-6 w-[1px] bg-slate-300 mx-2"></div>
<select id="device-model-filter" class="bg-white border-slate-200 rounded-lg text-body-md py-1.5 px-3 focus:ring-primary focus:border-primary">
<option value="">All Models</option>
</select>
<select id="device-merchant-filter" class="bg-white border-slate-200 rounded-lg text-body-md py-1.5 px-3 focus:ring-primary focus:border-primary">
<option value="">All Merchants</option>
</select>
<select id="device-connection-filter" class="bg-white border-slate-200 rounded-lg text-body-md py-1.5 px-3 focus:ring-primary focus:border-primary">
<option value="">All Connections</option>
<option value="static">Static</option>
<option value="mqtt">MQTT</option>
<option value="api">API</option>
</select>
<div class="ml-auto flex items-center gap-2">
<button id="device-clear-filter" class="text-primary font-bold text-body-md hover:underline">Clear All</button>
<button class="bg-white border border-slate-200 px-3 py-1.5 rounded-lg text-body-md flex items-center gap-2 hover:bg-slate-50">
<span class="material-symbols-outlined text-[18px]" data-icon="download">download</span>
Export List
</button>
</div>
</div>
<!-- Table Container -->
<div class="overflow-x-auto data-table-container">
<table class="w-full text-left border-collapse">
<thead>
<tr class="bg-slate-50 border-b border-slate-200">
<th class="px-6 py-4 font-bold text-label-md text-slate-500 uppercase tracking-wider">Device ID</th>
<th class="px-6 py-4 font-bold text-label-md text-slate-500 uppercase tracking-wider">Model</th>
<th class="px-6 py-4 font-bold text-label-md text-slate-500 uppercase tracking-wider">Merchant Binding</th>
<th class="px-6 py-4 font-bold text-label-md text-slate-500 uppercase tracking-wider">Connection</th>
<th class="px-6 py-4 font-bold text-label-md text-slate-500 uppercase tracking-wider">Status</th>
<th class="px-6 py-4 font-bold text-label-md text-slate-500 uppercase tracking-wider">Health</th>
<th class="px-6 py-4 font-bold text-label-md text-slate-500 uppercase tracking-wider text-right">Last Seen</th>
<th class="px-6 py-4"></th>
</tr>
</thead>
<tbody id="device-table-body" class="divide-y divide-slate-100">
<tr>
<td id="device-table-empty" colspan="8" class="px-6 py-10 text-center text-slate-500">Loading device registry...</td>
</tr>
</tbody>
</table>
</div>
<!-- Pagination -->
<div class="p-4 border-t border-slate-200 flex items-center justify-between bg-white">
<span id="device-pagination-label" class="text-body-md text-slate-500">Showing <span class="font-bold text-on-surface">1-4</span> of <span class="font-bold text-on-surface">1,200</span> devices</span>
<div class="flex items-center gap-1">
<button class="p-2 border border-slate-200 rounded-lg hover:bg-slate-50 disabled:opacity-50" disabled="">
<span class="material-symbols-outlined">chevron_left</span>
</button>
<button class="w-10 h-10 flex items-center justify-center rounded-lg bg-primary text-on-primary font-bold">1</button>
<button class="w-10 h-10 flex items-center justify-center rounded-lg hover:bg-slate-50 text-on-surface">2</button>
<button class="w-10 h-10 flex items-center justify-center rounded-lg hover:bg-slate-50 text-on-surface">3</button>
<span class="px-2">...</span>
<button class="w-10 h-10 flex items-center justify-center rounded-lg hover:bg-slate-50 text-on-surface">300</button>
<button class="p-2 border border-slate-200 rounded-lg hover:bg-slate-50">
<span class="material-symbols-outlined">chevron_right</span>
</button>
</div>
</div>
</div>
<!-- System Maintenance Warning (Low-depth atmospheric card) -->
<div class="mt-8 p-4 bg-tertiary-container/5 border border-tertiary-container/20 rounded-xl flex items-center gap-4">
<div class="w-12 h-12 rounded-full bg-tertiary-container/10 flex items-center justify-center text-tertiary">
<span class="material-symbols-outlined">build</span>
</div>
<div>
<h4 class="font-bold text-on-tertiary-fixed-variant">Scheduled Maintenance</h4>
<p class="text-body-md text-on-tertiary-fixed-variant opacity-80">Device Heartbeat service will be offline for 15 minutes today at 02:00 UTC for firmware indexing updates.</p>
</div>
<button class="ml-auto text-on-tertiary-fixed-variant font-bold hover:underline">Dismiss</button>
</div>
</main>
<!-- Side Inspection Drawer (Initially hidden, triggered by row interaction) -->
<div class="fixed inset-0 bg-slate-900/40 backdrop-blur-sm z-[60] opacity-0 pointer-events-none transition-opacity duration-300" id="device-detail-overlay"></div>
<div class="fixed inset-y-0 right-0 w-[450px] bg-white shadow-2xl z-[60] transform translate-x-full transition-transform duration-300 ease-in-out border-l border-slate-200" id="device-detail-drawer">
<div class="h-full flex flex-col">
<div class="p-6 border-b border-slate-200 flex justify-between items-center">
<h3 class="font-headline-md text-headline-md">Device Detail</h3>
<button class="p-2 hover:bg-slate-100 rounded-full" id="device-detail-close">
<span class="material-symbols-outlined">close</span>
</button>
</div>
<div class="p-6 overflow-y-auto flex-1">
<div class="flex items-center gap-4 mb-8">
<img alt="Soundbox V2 Product" class="w-20 h-20 rounded-xl bg-slate-100" data-alt="A clean professional studio product shot of a minimalist electronic soundbox speaker device with a small LCD screen and premium matte plastic finish. The lighting is soft and corporate with subtle blue reflections on the surface consistent with a high-end fintech hardware brand. The background is a clean neutral white studio setting." src="https://lh3.googleusercontent.com/aida-public/AB6AXuC-CSPTCnxQuDTN1XM0atRPM9hIcVzf3zpbuxEUGTIlC-c1BivDqPa9osmBscvoiUcJeMBwUaXbZ6Ut5FuG2a91sVtZjzWRTgLck34kJJJy3N2E9O3uVtZw6InOpX9Gkph2OJxu_Z-PkR_t3F56EVZY3u8o2iZO3iH8hj9_ajrku7g1r_l54uobcRoN3dRH3k_at6GTuGbMtSSD4ew24sX8nePUsVvILKJauQLcMKD14J6mtAGm0x5PfViQQKdJzf_pYMqKswr3Yz4"/>
<div>
<h4 class="font-bold text-headline-md mb-1" id="device-detail-title">-</h4>
<span class="inline-flex items-center px-2 py-0.5 rounded-full text-xs font-bold bg-slate-100 text-slate-600" id="device-detail-model">Device</span>
</div>
</div>
<div class="space-y-6" id="device-detail-content"></div>
</div>
<div class="p-6 border-t border-slate-200 grid grid-cols-2 gap-4">
<button class="w-full py-2.5 border border-slate-200 rounded-xl font-bold hover:bg-slate-50 transition-colors">Reboot Device</button>
<button class="w-full py-2.5 bg-danger/10 text-danger rounded-xl font-bold hover:bg-danger/20 transition-colors">Unbind Merchant</button>
</div>
</div>
</div>
<script src="/ui/shared/admin-api.js"></script>
<script>
(function () {
const api = window.AdminUIAPI;
if (!api) {
return;
}
const tableBody = document.getElementById("device-table-body");
const searchInput = document.getElementById("device-search-input");
const modelFilter = document.getElementById("device-model-filter");
const merchantFilter = document.getElementById("device-merchant-filter");
const connectionFilter = document.getElementById("device-connection-filter");
const clearFilter = document.getElementById("device-clear-filter");
const kpiTotal = document.getElementById("device-kpi-total-registered");
const kpiActive = document.getElementById("device-kpi-active-units");
const kpiUnassigned = document.getElementById("device-kpi-unassigned");
const paginationLabel = document.getElementById("device-pagination-label");
const detailOverlay = document.getElementById("device-detail-overlay");
const detailDrawer = document.getElementById("device-detail-drawer");
const detailCloseButton = document.getElementById("device-detail-close");
const detailTitle = document.getElementById("device-detail-title");
const detailModel = document.getElementById("device-detail-model");
const detailContent = document.getElementById("device-detail-content");
const normalizeText = (value) => String(value || "").toLowerCase().trim();
const formatLastSeen = (value) => {
if (!value) {
return "No heartbeat";
}
const now = new Date();
const then = new Date(value);
if (Number.isNaN(then.getTime())) {
return value;
}
const diffMinutes = Math.floor((now.getTime() - then.getTime()) / (1000 * 60));
if (diffMinutes < 1) {
return "Just now";
}
if (diffMinutes < 60) {
return `${diffMinutes} min ago`;
}
if (diffMinutes < 60 * 24) {
const hours = Math.floor(diffMinutes / 60);
return `${hours} hour${hours === 1 ? "" : "s"} ago`;
}
const days = Math.floor(diffMinutes / (60 * 24));
return `${days} day${days === 1 ? "" : "s"} ago`;
};
const healthMeta = (value, summary) => {
if (summary && typeof summary.score === "number") {
if (summary.score >= 90) {
return { value: `${summary.score}%`, className: "text-success", icon: "favorite" };
}
if (summary.score >= 65) {
return { value: `${summary.score}%`, className: "text-success", icon: "favorite" };
}
if (summary.score >= 35) {
return { value: `${summary.score}%`, className: "text-warning", icon: "heart_minus" };
}
return { value: `${summary.score}%`, className: "text-danger", icon: "heart_broken" };
}
if (!value) {
return { value: "N/A", className: "text-slate-500", icon: "heart_broken" };
}
const then = new Date(value);
if (Number.isNaN(then.getTime())) {
return { value: "N/A", className: "text-slate-500", icon: "heart_broken" };
}
const diffMinutes = Math.floor((Date.now() - then.getTime()) / (1000 * 60));
if (diffMinutes <= 10) {
return { value: "Excellent", className: "text-success", icon: "favorite" };
}
if (diffMinutes <= 60) {
return { value: "Good", className: "text-success", icon: "favorite" };
}
if (diffMinutes <= 180) {
return { value: "Fair", className: "text-warning", icon: "heart_minus" };
}
return { value: "Poor", className: "text-danger", icon: "heart_broken" };
};
const reasonLabels = {
no_heartbeat: "No heartbeat",
offline_threshold_exceeded: "Offline threshold",
stale_threshold_exceeded: "Stale heartbeat",
low_signal: "Low signal",
low_battery: "Low battery"
};
const configStatusMeta = (status) => {
const value = normalizeText(status);
if (value === "applied") {
return { label: "Applied", className: "bg-success/10 text-success border-success/20", icon: "check_circle" };
}
if (value === "pending_ack") {
return { label: "Pending ACK", className: "bg-warning/10 text-warning border-warning/20", icon: "pending" };
}
if (value === "failed_ack") {
return { label: "Failed ACK", className: "bg-danger/10 text-danger border-danger/20", icon: "error" };
}
if (value === "stale_ack") {
return { label: "Stale ACK", className: "bg-warning/10 text-warning border-warning/20", icon: "sync_problem" };
}
return { label: "Never pushed", className: "bg-slate-100 text-slate-600 border-slate-200", icon: "cloud_off" };
};
const statusMeta = (status) => {
const value = normalizeText(status);
if (value === "online") {
return {
label: "Online",
className: "bg-success/10 text-success border border-success/20",
dot: "bg-success"
};
}
if (value === "degraded") {
return {
label: "Degraded",
className: "bg-warning/10 text-warning border border-warning/20",
dot: "bg-warning"
};
}
if (value === "stale") {
return {
label: "Stale",
className: "bg-warning/10 text-warning border border-warning/20",
dot: "bg-warning"
};
}
return {
label: "Offline",
className: "bg-slate-100 text-slate-500 border border-slate-200",
dot: "bg-slate-400"
};
};
const connectionMeta = (mode) => {
const value = normalizeText(mode);
if (value === "static") {
return { label: "Static", icon: "settings_ethernet" };
}
if (value === "mqtt") {
return { label: "MQTT", icon: "cell_tower" };
}
if (value === "api") {
return { label: "API", icon: "hub" };
}
return { label: value || "Unknown", icon: "device_hub" };
};
let rows = [];
const merchantMap = new Map();
let timeoutId;
const renderRows = (items) => {
if (!tableBody) {
return;
}
if (!items.length) {
tableBody.innerHTML = '<tr><td colspan="8" class="px-6 py-10 text-center text-slate-500">No devices found.</td></tr>';
return;
}
tableBody.innerHTML = items
.map((device) => {
const id = device.device_code || device.id || "";
const model = device.model || "Unknown";
const binding = device.binding_summary || {};
const merchantName = merchantMap.get(binding.merchant_id) || "Unassigned";
const status = statusMeta(device.derived_status);
const connection = connectionMeta(device.communication_mode);
const health = healthMeta(device.latest_heartbeat, device.health_summary);
return `
<tr class="hover:bg-slate-50 transition-colors group">
<td class="px-6 py-row-height">
<span class="font-mono text-primary font-bold">${id || "-"}</span>
</td>
<td class="px-6 py-row-height">${model}</td>
<td class="px-6 py-row-height">
<div class="flex items-center gap-2">
<div class="w-6 h-6 rounded bg-slate-100 flex items-center justify-center">
<span class="material-symbols-outlined text-[16px]">${merchantName === "Unassigned" ? "block" : "store"}</span>
</div>
<span>${merchantName}</span>
</div>
</td>
<td class="px-6 py-row-height">
<span class="flex items-center gap-1.5 text-slate-600">
<span class="material-symbols-outlined text-[18px]">${connection.icon}</span>
${connection.label}
</span>
</td>
<td class="px-6 py-row-height">
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-bold ${status.className}">
<span class="w-1.5 h-1.5 rounded-full ${status.dot} mr-1.5"></span>
${status.label}
</span>
</td>
<td class="px-6 py-row-height">
<span class="flex items-center gap-1 ${health.className}">
<span class="material-symbols-outlined text-[18px]">${health.icon}</span>
${health.value}
</span>
</td>
<td class="px-6 py-row-height text-right font-mono text-slate-500">${formatLastSeen(device.latest_heartbeat)}</td>
<td class="px-6 py-row-height text-right">
<button class="opacity-0 group-hover:opacity-100 transition-opacity p-2 hover:bg-slate-200 rounded-lg" data-action="open-detail" data-id="${id}">
<span class="material-symbols-outlined">more_vert</span>
</button>
</td>
</tr>
`;
})
.join("");
tableBody.querySelectorAll("button[data-action='open-detail']").forEach((button) => {
button.addEventListener("click", (event) => {
const rowId = event.currentTarget.getAttribute("data-id");
const item = rows.find((row) => (row.device_code || row.id) === rowId);
if (item) {
openDrawer(item);
}
});
});
};
const applyFilters = () => {
const q = normalizeText(searchInput?.value);
const model = normalizeText(modelFilter?.value);
const merchant = merchantFilter?.value || "";
const connection = normalizeText(connectionFilter?.value);
const filtered = rows.filter((device) => {
const currentModel = normalizeText(device.model);
const merchantId = device.binding_summary?.merchant_id || "";
const merchantName = normalizeText(merchantMap.get(merchantId) || "");
const deviceId = normalizeText(device.device_code || device.id);
const matchesQ =
!q ||
deviceId.includes(q) ||
normalizeText(device.serial_number).includes(q) ||
currentModel.includes(q) ||
merchantName.includes(q);
const matchesModel = !model || normalizeText(device.model) === model;
const matchesMerchant = !merchant || merchantId === merchant;
const matchesConnection = !connection || normalizeText(device.communication_mode) === connection;
return matchesQ && matchesModel && matchesMerchant && matchesConnection;
});
const activeCount = filtered.filter((item) => normalizeText(item.derived_status) === "online").length;
const unassignedCount = filtered.filter((item) => !(item.binding_summary && item.binding_summary.merchant_id)).length;
if (kpiTotal) {
kpiTotal.textContent = String(filtered.length);
}
if (kpiActive) {
kpiActive.textContent = String(activeCount);
}
if (kpiUnassigned) {
kpiUnassigned.textContent = String(unassignedCount);
}
renderRows(filtered);
if (paginationLabel) {
paginationLabel.innerHTML = `Showing <span class="font-bold text-on-surface">1 - ${Math.min(filtered.length, 10)}</span> of <span class="font-bold text-on-surface">${filtered.length}</span> devices`;
}
};
const renderMerchantFilter = () => {
if (!merchantFilter) {
return;
}
const options = Array.from(merchantMap.entries())
.map(([id, name]) => ({ id, name }))
.filter((item) => item.id)
.sort((a, b) => normalizeText(a.name).localeCompare(normalizeText(b.name)));
merchantFilter.innerHTML = '<option value="">All Merchants</option>';
options.forEach((item) => {
const option = document.createElement("option");
option.value = item.id;
option.textContent = item.name;
merchantFilter.appendChild(option);
});
};
const renderModelFilter = () => {
if (!modelFilter) {
return;
}
const models = new Set(
rows
.map((item) => item.model)
.filter(Boolean)
);
modelFilter.innerHTML = '<option value="">All Models</option>';
Array.from(models)
.sort((a, b) => normalizeText(a).localeCompare(normalizeText(b)))
.forEach((model) => {
const option = document.createElement("option");
option.value = model;
option.textContent = model;
modelFilter.appendChild(option);
});
};
const openDrawer = (device) => {
if (!detailDrawer || !detailOverlay || !detailTitle || !detailModel || !detailContent) {
return;
}
const binding = device.binding_summary || {};
const connection = connectionMeta(device.communication_mode);
const status = statusMeta(device.derived_status);
const health = healthMeta(device.latest_heartbeat, device.health_summary);
const summary = device.health_summary || {};
const reasons = Array.isArray(summary.reasons) && summary.reasons.length
? summary.reasons.map((item) => reasonLabels[item] || item).join(", ")
: "No active warning";
const id = device.device_code || device.id || "-";
detailTitle.textContent = id;
detailModel.textContent = device.model || "Unknown";
detailModel.className = `inline-flex items-center px-2 py-0.5 rounded-full text-xs font-bold ${status.className}`;
detailContent.innerHTML = `
<section>
<h5 class="text-label-md font-label-md text-slate-500 uppercase mb-3">Device Detail</h5>
<div class="bg-slate-50 p-4 rounded-xl border border-slate-100">
<div class="flex justify-between mb-2">
<span class="text-on-surface-variant">Model</span>
<span class="font-bold">${device.model || "Unknown"}</span>
</div>
<div class="flex justify-between mb-2">
<span class="text-on-surface-variant">Connection</span>
<span class="font-bold">${connection.label}</span>
</div>
<div class="flex justify-between mb-2">
<span class="text-on-surface-variant">Status</span>
<span class="inline-flex items-center gap-1.5 ${status.className}">
<span class="w-1.5 h-1.5 rounded-full bg-current"></span>
${status.label}
</span>
</div>
<div class="flex justify-between mb-2">
<span class="text-on-surface-variant">Last Seen</span>
<span class="font-bold">${formatLastSeen(device.latest_heartbeat)}</span>
</div>
<div class="flex justify-between">
<span class="text-on-surface-variant">Health</span>
<span class="${health.className}">${health.value}</span>
</div>
<div class="mt-3 pt-3 border-t border-slate-200">
<div class="flex justify-between mb-2">
<span class="text-on-surface-variant">Heartbeat Age</span>
<span class="font-bold">${typeof summary.age_seconds === "number" ? `${summary.age_seconds}s` : "-"}</span>
</div>
<div class="flex justify-between gap-4">
<span class="text-on-surface-variant">Reason</span>
<span class="text-right font-bold">${reasons}</span>
</div>
</div>
</div>
</section>
<section id="device-config-section">
<h5 class="text-label-md font-label-md text-slate-500 uppercase mb-3">Config Delivery</h5>
<div class="bg-slate-50 p-4 rounded-xl border border-slate-100" id="device-config-status-box">
<p class="text-slate-500">Loading config status...</p>
</div>
</section>
<section>
<h5 class="text-label-md font-label-md text-slate-500 uppercase mb-3">Binding Info</h5>
<div class="bg-slate-50 p-4 rounded-xl border border-slate-100">
<div class="flex justify-between mb-2">
<span class="text-on-surface-variant">Merchant</span>
<span class="font-bold">${merchantMap.get(binding.merchant_id) || "Unassigned"}</span>
</div>
<div class="flex justify-between mb-2">
<span class="text-on-surface-variant">Outlet</span>
<span class="font-mono">${binding.outlet_id || "-"}</span>
</div>
<div class="flex justify-between">
<span class="text-on-surface-variant">Terminal</span>
<span class="font-mono">${binding.terminal_id || "-"}</span>
</div>
</div>
</section>
<section>
<h5 class="text-label-md font-label-md text-slate-500 uppercase mb-3">Live Payload (Audit Control)</h5>
<div class="bg-slate-900 text-slate-300 p-4 rounded-xl font-mono text-[12px]">
<pre>${JSON.stringify(device, null, 2)}</pre>
</div>
</section>
`;
detailOverlay.classList.remove("pointer-events-none", "opacity-0");
detailOverlay.classList.add("opacity-100");
detailDrawer.classList.remove("translate-x-full");
loadDrawerConfig(device.id);
};
const loadDrawerConfig = async (deviceId) => {
const box = document.getElementById("device-config-status-box");
if (!box || !deviceId) {
return;
}
try {
const configStatus = await api.getDeviceConfigStatus(deviceId);
const meta = configStatusMeta(configStatus.drift_status);
const latestPush = configStatus.latest_push;
const latestAck = configStatus.latest_ack;
const canRetry = configStatus.retry_recommended;
box.innerHTML = `
<div class="flex items-center justify-between gap-3 mb-3">
<span class="inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-bold border ${meta.className}">
<span class="material-symbols-outlined text-[16px]">${meta.icon}</span>
${meta.label}
</span>
<span class="font-mono text-slate-500">v${configStatus.desired_config_version || "-"}</span>
</div>
<div class="grid grid-cols-2 gap-3 text-sm mb-4">
<div>
<p class="text-slate-500">Latest Push</p>
<p class="font-bold">${latestPush ? formatLastSeen(latestPush.created_at) : "-"}</p>
</div>
<div>
<p class="text-slate-500">Latest ACK</p>
<p class="font-bold">${latestAck ? latestAck.status : "-"}</p>
</div>
</div>
<button id="device-config-retry" class="w-full px-3 py-2 rounded-lg text-sm font-bold border ${canRetry ? "bg-primary text-white border-primary" : "bg-white text-slate-500 border-slate-200"}">
${canRetry ? "Retry Config Push" : "Config Applied"}
</button>
`;
const retryButton = document.getElementById("device-config-retry");
retryButton?.addEventListener("click", async () => {
retryButton.disabled = true;
retryButton.textContent = "Retrying...";
try {
await api.retryDeviceConfigPush(deviceId, canRetry ? {} : { force: true });
await loadDrawerConfig(deviceId);
} catch (error) {
retryButton.disabled = false;
retryButton.textContent = "Retry Failed";
}
});
} catch (error) {
box.innerHTML = '<p class="text-danger">Unable to load config status.</p>';
}
};
const closeDrawer = () => {
if (!detailDrawer || !detailOverlay) {
return;
}
detailDrawer.classList.add("translate-x-full");
detailOverlay.classList.remove("opacity-100");
detailOverlay.classList.add("opacity-0", "pointer-events-none");
};
const onSearch = () => {
if (timeoutId) {
clearTimeout(timeoutId);
}
timeoutId = setTimeout(applyFilters, 180);
};
const refresh = async () => {
try {
api.requireToken();
const [deviceRows, merchantRows] = await Promise.all([
api.listDevices(),
api.listMerchants()
]);
rows = Array.isArray(deviceRows) ? deviceRows : [];
merchantMap.clear();
(Array.isArray(merchantRows) ? merchantRows : []).forEach((merchant) => {
const id = merchant.id || merchant.merchant_id || merchant.merchant_code;
const name = merchant.legal_name || merchant.brand_name || merchant.company_name || merchant.name || id || "Unknown";
if (id) {
merchantMap.set(id, name);
}
});
renderMerchantFilter();
renderModelFilter();
applyFilters();
} catch (error) {
console.error("[device-registry] failed loading", error);
if (tableBody) {
tableBody.innerHTML = '<tr><td colspan="8" class="px-6 py-6 text-center text-danger">Unable to load device data</td></tr>';
}
}
};
clearFilter?.addEventListener("click", () => {
if (searchInput) {
searchInput.value = "";
}
if (modelFilter) {
modelFilter.value = "";
}
if (merchantFilter) {
merchantFilter.value = "";
}
if (connectionFilter) {
connectionFilter.value = "";
}
applyFilters();
});
searchInput?.addEventListener("input", onSearch);
modelFilter?.addEventListener("change", applyFilters);
merchantFilter?.addEventListener("change", applyFilters);
connectionFilter?.addEventListener("change", applyFilters);
detailOverlay?.addEventListener("click", closeDrawer);
detailCloseButton?.addEventListener("click", closeDrawer);
document.addEventListener("keydown", (event) => {
if (event.key === "Escape") {
closeDrawer();
}
});
refresh();
})();
</script>
<!-- ui-nav -->
<div id="__sb_nav" style="position:fixed;left:16px;bottom:16px;z-index:9999;background:#fff;border:1px solid #e2e8f0;padding:8px 10px;border-radius:8px;box-shadow:0 6px 24px rgba(15,23,42,0.12);font-family:Inter,Arial,sans-serif;font-size:12px;line-height:1.4">
<a href="/ui" style="margin-right:8px;color:#2563eb;text-decoration:none;font-weight:600">UI Catalog</a>
<a href="/ui/hub" style="margin-right:8px;color:#2563eb;text-decoration:none;font-weight:600">Hub</a>
<a href="/ui/admin-login" style="margin-right:8px;color:#2563eb;text-decoration:none;font-weight:600">Admin Login</a>
<a href="/ui/merchant-login" style="margin-right:8px;color:#2563eb;text-decoration:none;font-weight:600">Merchant Login</a>
<a href="/ui/admin-dashboard-overview" style="margin-right:0;color:#2563eb;text-decoration:none;font-weight:600">Dashboard</a>
</div>
</body></html>