feat(manager): Devices page — pair by code, app, name, sign-in mode, link, change app, remove
Platform-v2 step 2.6d: - /devices (core.devices.manage, sidebar): devices from /api/devices with status (online / last seen / waiting for the device / app turned off / removed), app, sign-in mode (own or venue default), linked device; usage per device app against the license limit (devices) - pair dialog: code as typed (normalized), app (only apps that are on, "all in use" when the limit is reached), name, sign-in mode for apps with a choice, optional linked device; license.limit_reached explained with the app's limit - edit (name, sign-in mode, link), change app (signs out whoever is on it), remove with confirm (the device goes back to pairing), show removed - manager_dashboard gets node --test (tests/platform.test.mjs: module states, dependents, device status/usage/room/links), added to run-all - e2e manager.mjs: 54 checks (+ wrong code, normalized code, pair, the device picks up its token, online, rename, change app, remove → device.revoked) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
// Pure helpers for the Devices page (plan step 2.6d). Unit-tested in manager_dashboard/tests.
|
||||
|
||||
/** Seen within this long = "Online" (the backend writes last_seen_at at most once a minute). */
|
||||
export const ONLINE_WITHIN_MS = 3 * 60 * 1000
|
||||
|
||||
/**
|
||||
* A device's status for the list:
|
||||
* removed revoked
|
||||
* waiting paired here, but the device hasn't picked up its token yet
|
||||
* app_off its app is turned off or not licensed (the device shows "app disabled")
|
||||
* online seen in the last 3 minutes
|
||||
* offline seen before that (or never since pairing)
|
||||
*/
|
||||
export function deviceStatus(d, { appOn = true, now = Date.now() } = {}) {
|
||||
if (d.revoked_at) return 'removed'
|
||||
if (!d.claimed) return 'waiting'
|
||||
if (!appOn) return 'app_off'
|
||||
const seen = d.last_seen_at ? Date.parse(d.last_seen_at) : NaN
|
||||
return Number.isFinite(seen) && now - seen <= ONLINE_WITHIN_MS ? 'online' : 'offline'
|
||||
}
|
||||
|
||||
/** Pairing codes are typed by people: upper-case, no spaces or dashes, at most 6 characters. */
|
||||
export function normalizeCode(input) {
|
||||
return String(input || '').toUpperCase().replace(/[^A-Z0-9]/g, '').slice(0, 6)
|
||||
}
|
||||
|
||||
/**
|
||||
* How many devices of each app are paired (not removed), and the license limit:
|
||||
* { kds: { used: 1, max: 2 }, signage: { used: 0, max: null } } (max null = unlimited)
|
||||
* `modules` = GET /api/platform/modules → modules.
|
||||
*/
|
||||
export function deviceUsage(devices, modules) {
|
||||
const out = {}
|
||||
for (const m of modules) {
|
||||
if (!m.device_app) continue
|
||||
const limit = m.limits.find(l => l.key === 'devices')
|
||||
out[m.key] = { used: 0, max: limit ? limit.value ?? null : null }
|
||||
}
|
||||
for (const d of devices) {
|
||||
if (!d.revoked_at && out[d.app_key]) out[d.app_key].used++
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
/** Is there room for one more device of this app? (when moving a device, it doesn't count against itself) */
|
||||
export function hasRoom(usage, appKey, { moving = false } = {}) {
|
||||
const u = usage[appKey]
|
||||
if (!u || u.max == null) return true
|
||||
return u.used - (moving ? 1 : 0) < u.max
|
||||
}
|
||||
|
||||
/** Devices another device may link to: not itself, not removed. */
|
||||
export function linkTargets(devices, selfId = null) {
|
||||
return devices.filter(d => !d.revoked_at && d.id !== selfId)
|
||||
}
|
||||
Reference in New Issue
Block a user