@7365admin1/layer-common 4.28.1-staging.359 → 4.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -4
- package/assets/css/robot-hero.css +466 -0
- package/components/AccessCardAddForm.vue +4 -5
- package/components/AccessCardAssignToUnitForm.vue +2 -3
- package/components/AccessCardPreviewDialog.vue +3 -4
- package/components/Dialog/UpdateMoreAction.vue +1 -11
- package/components/DocumentForm.vue +112 -407
- package/components/DocumentManagement.vue +12 -213
- package/components/EntryPass/QrTemplatePreview.vue +25 -21
- package/components/EntryPassInformation.vue +24 -119
- package/components/Facility/BookingSetup.vue +0 -63
- package/components/HidAccessLogDashboard.vue +8 -41
- package/components/HidIntercomManagement.vue +14 -148
- package/components/HidReaderManagement.vue +0 -26
- package/components/HidReaderUserRoster.vue +3 -44
- package/components/HidUserEnrollment.vue +155 -845
- package/components/InvitationClientForm.vue +1 -19
- package/components/NotificationBell.vue +3 -39
- package/components/Robot/Battery.vue +18 -0
- package/components/Robot/CapabilityTag.vue +14 -0
- package/components/Robot/Card.vue +56 -0
- package/components/Robot/CommandBar.vue +47 -0
- package/components/Robot/CredentialField.vue +37 -0
- package/components/Robot/FaultBadge.vue +26 -0
- package/components/Robot/FloorLabel.vue +12 -0
- package/components/Robot/Hero.vue +32 -0
- package/components/Robot/LiftQueueRow.vue +28 -0
- package/components/Robot/MapToolbar.vue +53 -0
- package/components/Robot/NoMonitoring.vue +14 -0
- package/components/Robot/Reconnecting.vue +7 -0
- package/components/Robot/StatusChip.vue +15 -0
- package/components/Robot/SummaryCell.vue +64 -0
- package/components/Robot/SummaryStrip.vue +19 -0
- package/components/Robot/Table.vue +115 -0
- package/components/Robot/Toast.vue +27 -0
- package/components/Robot/ViewOnlyNotice.vue +3 -0
- package/components/RolePermissionFormCreate.vue +1 -78
- package/components/RolePermissionFormPreviewUpdate.vue +2 -83
- package/components/VehicleManagement.vue +10 -150
- package/components/VisitorManagement.vue +5 -267
- package/composables/useAccessManagement.ts +0 -5
- package/composables/useDocument.ts +0 -7
- package/composables/useFacility.ts +0 -11
- package/composables/useHidAmico.ts +0 -117
- package/composables/useHidNavigation.ts +1 -25
- package/composables/usePeople.ts +0 -19
- package/composables/useSiteEntryPassSettings.ts +0 -26
- package/composables/useWebUsb.ts +11 -14
- package/package.json +1 -1
- package/pages/[org]/[site]/access-mgmt/administrator/index.vue +1 -1
- package/pages/[org]/[site]/access-mgmt/hid-cards/index.vue +1 -1
- package/pages/[org]/[site]/access-mgmt/hid-readers/index.vue +1 -1
- package/plugins/API.ts +2 -7
- package/plugins/vuetify.ts +8 -1
- package/types/document.d.ts +0 -14
- package/types/facility.d.ts +0 -4
- package/types/people.d.ts +1 -28
- package/types/vehicle.d.ts +0 -11
- package/utils/robot-display.ts +304 -0
- package/utils/theme.ts +152 -0
- package/components/HidAccessPermissions.vue +0 -424
- package/components/HidProfileQrCode.vue +0 -332
- package/composables/useHidReaderSelection.ts +0 -50
- package/composables/useSiteCategory.ts +0 -45
- package/pages/[org]/[site]/access-mgmt/hid-qr-code/index.vue +0 -23
- package/utils/hid-permission-assignments.ts +0 -190
- package/utils/hid-reader-selection.ts +0 -52
- package/utils/notification-target.ts +0 -75
- package/utils/occupancy-role.ts +0 -109
- package/utils/permission-refusal.ts +0 -40
package/composables/useWebUsb.ts
CHANGED
|
@@ -345,19 +345,16 @@ export default function useWebUsb() {
|
|
|
345
345
|
70,
|
|
346
346
|
);
|
|
347
347
|
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
// Generated at the size it is drawn at: the old corner copies were
|
|
353
|
-
// downscaled from the 250px canvas, which softened their modules.
|
|
354
|
-
const qrSize = 350;
|
|
355
|
-
const qrCanvas = await QRCode.toCanvas(qrUrlImage, {
|
|
356
|
-
width: qrSize,
|
|
357
|
-
margin: 1,
|
|
358
|
-
});
|
|
348
|
+
const qrSmall = 140;
|
|
349
|
+
const qrCenter = 250;
|
|
350
|
+
const margin = 20;
|
|
351
|
+
const qrCanvas = await QRCode.toCanvas(qrUrlImage, { width: qrCenter });
|
|
359
352
|
|
|
360
|
-
ctx.drawImage(qrCanvas,
|
|
353
|
+
ctx.drawImage(qrCanvas, margin, 90, qrSmall, qrSmall);
|
|
354
|
+
ctx.drawImage(qrCanvas, canvas.width - qrSmall - margin, 90, qrSmall, qrSmall);
|
|
355
|
+
ctx.drawImage(qrCanvas, (canvas.width - qrCenter) / 2, 110, qrCenter, qrCenter);
|
|
356
|
+
ctx.drawImage(qrCanvas, margin, 300, qrSmall, qrSmall);
|
|
357
|
+
ctx.drawImage(qrCanvas, canvas.width - qrSmall - margin, 300, qrSmall, qrSmall);
|
|
361
358
|
|
|
362
359
|
ctx.font = "25px Arial";
|
|
363
360
|
ctx.fillText(companyName || "", canvas.width / 2, 470);
|
|
@@ -404,8 +401,8 @@ export default function useWebUsb() {
|
|
|
404
401
|
/**
|
|
405
402
|
* The self-service onboarding QR: one large QR code, a "SCAN QR CODE"-style
|
|
406
403
|
* subtext, and a dark site-name banner along the bottom - a single-purpose
|
|
407
|
-
* gate sign, not the visitor-pass receipt `createReceiptLayout`
|
|
408
|
-
* (that one
|
|
404
|
+
* gate sign, not the multi-copy visitor-pass receipt `createReceiptLayout`
|
|
405
|
+
* produces (that one prints several QRs to be cut apart and handed out).
|
|
409
406
|
*/
|
|
410
407
|
async function createOnboardingQrLayout(
|
|
411
408
|
qrUrlImage: string,
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@7365admin1/layer-common",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "4.
|
|
5
|
+
"version": "4.29.0",
|
|
6
6
|
"author": "7365admin1",
|
|
7
7
|
"main": "./nuxt.config.ts",
|
|
8
8
|
"//files": "What a consumer extending this layer actually loads. Without this npm ships the whole working tree - the changesets, the CI workflows, the render harness in tools/ and any scratch directory that happened to exist at publish time. Nuxt resolves a layer by directory, so every runtime directory below has to stay listed; adding a new top-level runtime directory means adding it here too.",
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
:org="orgId"
|
|
6
6
|
message="Enable HID as a service for this site before managing physical HID cards."
|
|
7
7
|
>
|
|
8
|
-
<HidUserEnrollment :site="siteId"
|
|
8
|
+
<HidUserEnrollment :site="siteId" card-management />
|
|
9
9
|
</HidEnabledGate>
|
|
10
10
|
</v-container>
|
|
11
11
|
</template>
|
package/plugins/API.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { isPermissionRefusal } from "../utils/permission-refusal";
|
|
2
|
-
|
|
3
1
|
export default defineNuxtPlugin((nuxtApp) => {
|
|
4
2
|
const { cookieConfig } = useRuntimeConfig().public;
|
|
5
3
|
|
|
@@ -16,12 +14,9 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|
|
16
14
|
// read it. Re-read it in the background (plugins/secure-member.client.ts)
|
|
17
15
|
// so the screen stops offering what the server refuses. The request itself
|
|
18
16
|
// still fails as before; nothing here retries it.
|
|
19
|
-
//
|
|
20
|
-
// Both refusal shapes count: API-core's 403 + PERMISSION_DENIED and core's
|
|
21
|
-
// 401 + "You do not have permission ..." (vehicle writes and every other
|
|
22
|
-
// `requireSiteReach` gate). See utils/permission-refusal.ts.
|
|
23
17
|
onResponseError({ response }) {
|
|
24
|
-
if (
|
|
18
|
+
if (response?.status !== 403) return;
|
|
19
|
+
if ((response as any)?._data?.code !== "PERMISSION_DENIED") return;
|
|
25
20
|
if (!import.meta.client) return;
|
|
26
21
|
const refresh = (nuxtApp as any).$refreshAppRole;
|
|
27
22
|
if (typeof refresh === "function") {
|
package/plugins/vuetify.ts
CHANGED
|
@@ -42,7 +42,7 @@ import {
|
|
|
42
42
|
} from "vuetify-pro-tiptap";
|
|
43
43
|
import "vuetify-pro-tiptap/style.css";
|
|
44
44
|
|
|
45
|
-
import { LIGHT_THEME, DARK_THEME } from "../utils/theme";
|
|
45
|
+
import { LIGHT_THEME, DARK_THEME, HERO_LIGHT_THEME, HERO_DARK_THEME } from "../utils/theme";
|
|
46
46
|
import { MDI_TO_SYMBOL } from "../utils/materialSymbols";
|
|
47
47
|
import { THEME_COOKIE } from "../composables/useThemePreference";
|
|
48
48
|
import type { CookieOptions } from "#app";
|
|
@@ -175,6 +175,13 @@ export default defineNuxtPlugin((app) => {
|
|
|
175
175
|
* theme rather than a blank one.
|
|
176
176
|
*/
|
|
177
177
|
iservice365: LIGHT_THEME,
|
|
178
|
+
/**
|
|
179
|
+
* The robot fleet's HERO look (owner decision 2026-09-23). Never a
|
|
180
|
+
* default: only `components/Robot/Hero.vue` asks for these, through a
|
|
181
|
+
* `v-theme-provider`, so every other screen keeps the themes above.
|
|
182
|
+
*/
|
|
183
|
+
"hero-light": HERO_LIGHT_THEME,
|
|
184
|
+
"hero-dark": HERO_DARK_THEME,
|
|
178
185
|
},
|
|
179
186
|
},
|
|
180
187
|
icons: {
|
package/types/document.d.ts
CHANGED
|
@@ -3,18 +3,4 @@ declare type TDocument = {
|
|
|
3
3
|
name: string;
|
|
4
4
|
attachment: string;
|
|
5
5
|
type: string;
|
|
6
|
-
/**
|
|
7
|
-
* Set at upload or renewal, absent when the document never expires.
|
|
8
|
-
*
|
|
9
|
-
* An ISO instant on the way out of the API and a `YYYY-MM-DD` string on the
|
|
10
|
-
* way back in, which is what `InputDatePicker` binds to - hence the loose
|
|
11
|
-
* type rather than `string`.
|
|
12
|
-
*/
|
|
13
|
-
expiryDate?: string | Date | null;
|
|
14
|
-
remarks?: string;
|
|
15
|
-
size?: number;
|
|
16
|
-
parentId?: string | null;
|
|
17
|
-
createdAt?: string | Date;
|
|
18
|
-
updatedAt?: string | Date;
|
|
19
|
-
status?: string;
|
|
20
6
|
};
|
package/types/facility.d.ts
CHANGED
|
@@ -73,10 +73,6 @@ declare type TFacility = {
|
|
|
73
73
|
hourInterval?: number;
|
|
74
74
|
isBookingFeeEnabled: boolean;
|
|
75
75
|
isGuestEnabled: boolean;
|
|
76
|
-
/** Residents may complete this facility's checklist themselves. */
|
|
77
|
-
isResidentChecklistEnabled?: boolean;
|
|
78
|
-
/** Security may complete it. Mutually exclusive with the above. */
|
|
79
|
-
isSecurityChecklistEnabled?: boolean;
|
|
80
76
|
bookingAmount: number | null;
|
|
81
77
|
peakBookingFeeAmount?: number | null;
|
|
82
78
|
bookingFeeGuestAmount?: number | null;
|
package/types/people.d.ts
CHANGED
|
@@ -22,38 +22,11 @@ declare type TPeople = {
|
|
|
22
22
|
email?: string;
|
|
23
23
|
files?: { name: string, id: string }[];
|
|
24
24
|
isOwner?: boolean;
|
|
25
|
-
/**
|
|
26
|
-
* Owner / occupant / person-in-charge, as the BUSINESS people form asks it.
|
|
27
|
-
* Absent on everyone else - `isOwner` is still the flag that decides unit
|
|
28
|
-
* ownership, and the server derives it from this when it is sent. See
|
|
29
|
-
* `OccupancyRoles` in core's `person.model.ts`.
|
|
30
|
-
*/
|
|
31
|
-
occupancyRole?: TOccupancyRole;
|
|
32
|
-
// Link to this person's `users` row. Empty for the person types that carry
|
|
33
|
-
// no login, and empty for a resident whose account was never written.
|
|
34
|
-
user?: string;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
declare type TOccupancyRole = "owner" | "occupant" | "person-in-charge";
|
|
38
|
-
|
|
39
|
-
/** One standing and everything the product says about it. See `utils/occupancy-role.ts`. */
|
|
40
|
-
declare type TOccupancyRoleOption = {
|
|
41
|
-
value: TOccupancyRole;
|
|
42
|
-
/** The label a stored role is printed with. */
|
|
43
|
-
title: string;
|
|
44
|
-
/** The row menu's wording. */
|
|
45
|
-
action: string;
|
|
46
|
-
/** The confirmation's heading and its sentence. */
|
|
47
|
-
prompt: string;
|
|
48
|
-
description: string;
|
|
49
25
|
};
|
|
50
26
|
|
|
51
27
|
declare type TPlateNumber = { plateNumber: string, recNo?: string, _id?: string, status: TVehicleStatus, type: TVehicleType, anprCameras?: TVehicleAnprCamera[] };
|
|
52
28
|
|
|
53
29
|
|
|
54
|
-
|
|
55
|
-
// before it is sent, because absence is what the server reads as "never
|
|
56
|
-
// asked". See `PeopleFormMgmt.vue`.
|
|
57
|
-
declare type TPeoplePayload = Pick<TGuest, "name" | "block" | "level" | "unit" | "unitName" | "contact" | "plateNumber" | "nric" | "contact" | "remarks" | "org" | "site" | "start" | "end" | "type" | "isOwner"> & { status?: string; user?: string; occupancyRole?: TOccupancyRole | "" }
|
|
30
|
+
declare type TPeoplePayload = Pick<TGuest, "name" | "block" | "level" | "unit" | "unitName" | "contact" | "plateNumber" | "nric" | "contact" | "remarks" | "org" | "site" | "start" | "end" | "type" | "isOwner"> & { status?: string }
|
|
58
31
|
|
|
59
32
|
declare type TPeopleType = "guest" | "resident" | "tenant"
|
package/types/vehicle.d.ts
CHANGED
|
@@ -85,17 +85,6 @@ declare type TVehicleHistoryEntry = {
|
|
|
85
85
|
updatedByName?: string;
|
|
86
86
|
updatedAt: string;
|
|
87
87
|
fields: string[];
|
|
88
|
-
/** What each field changed from and to. Absent on older entries. */
|
|
89
|
-
changes?: TVehicleFieldChange[];
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
declare type TVehicleFieldChange = {
|
|
93
|
-
field: string;
|
|
94
|
-
from: string | number | boolean | null;
|
|
95
|
-
to: string | number | boolean | null;
|
|
96
|
-
/** Block / level / unit: the name the server resolved for the id. */
|
|
97
|
-
fromName?: string;
|
|
98
|
-
toName?: string;
|
|
99
88
|
};
|
|
100
89
|
|
|
101
90
|
declare type TVehiclePayload = Pick<
|
package/utils/robot-display.ts
CHANGED
|
@@ -210,3 +210,307 @@ export function planSummary(plan: Record<string, any> | null | undefined) {
|
|
|
210
210
|
jobs,
|
|
211
211
|
};
|
|
212
212
|
}
|
|
213
|
+
|
|
214
|
+
/* ==========================================================================
|
|
215
|
+
* HERO robot fleet - the rules behind the shared components in
|
|
216
|
+
* `components/Robot/`. Every decision a HERO component makes is one of these
|
|
217
|
+
* functions; the components only call them and draw the answer.
|
|
218
|
+
*
|
|
219
|
+
* Colours are named as HERO theme colours (`utils/theme.ts`), never hexes.
|
|
220
|
+
* ======================================================================== */
|
|
221
|
+
|
|
222
|
+
export type TRobotType = "cleaning" | "security";
|
|
223
|
+
|
|
224
|
+
/** A HERO theme colour a status or state is drawn in. `ink` = text as a fill. */
|
|
225
|
+
export type THeroTone = "success" | "warning" | "info" | "error" | "ink" | "accent";
|
|
226
|
+
|
|
227
|
+
export type THeroStatus = {
|
|
228
|
+
label: string;
|
|
229
|
+
tone: THeroTone;
|
|
230
|
+
/** The chip's dot blinks while the robot is doing something. */
|
|
231
|
+
blink: boolean;
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
/** Modes during which the robot is moving or changing state on its own. */
|
|
235
|
+
const BLINKING: ReadonlySet<string> = new Set(["WORKING", "IN_TRANSIT", "CHARGING_CYCLE", "MANUAL"]);
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* The status chip: the exact label, its tone and whether its dot blinks.
|
|
239
|
+
*
|
|
240
|
+
* Built on `robotDisplay` so the words can never drift from the existing
|
|
241
|
+
* screens. One HERO rule on top: a SECURITY robot that is working is
|
|
242
|
+
* "Patrolling", not "Cleaning". The tone is `robotDisplay`'s colour with the
|
|
243
|
+
* handoff's one substitution - its "primary" (Cleaning/Patrolling) is ink.
|
|
244
|
+
*/
|
|
245
|
+
export function robotStatus(mode: unknown, type?: unknown): THeroStatus {
|
|
246
|
+
const d = robotDisplay(mode);
|
|
247
|
+
return {
|
|
248
|
+
label: mode === "WORKING" && type === "security" ? "Patrolling" : d.label,
|
|
249
|
+
tone: d.color === "primary" ? "ink" : (d.color as THeroTone),
|
|
250
|
+
blink: typeof mode === "string" && BLINKING.has(mode),
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* The battery reading, or null - and null means RENDER NOTHING.
|
|
256
|
+
*
|
|
257
|
+
* A brand that cannot measure its battery must not show "0%", which reads as
|
|
258
|
+
* flat. Only a finite number counts; it is clamped to 0-100 and rounded.
|
|
259
|
+
* Fill: >=45 success, 20-44 warning, <20 accent.
|
|
260
|
+
*/
|
|
261
|
+
export function batteryReading(value: unknown): { pct: number; tone: THeroTone; text: string } | null {
|
|
262
|
+
if (typeof value !== "number" || !Number.isFinite(value)) return null;
|
|
263
|
+
const pct = Math.round(Math.min(Math.max(value, 0), 100));
|
|
264
|
+
const tone: THeroTone = pct >= 45 ? "success" : pct >= 20 ? "warning" : "accent";
|
|
265
|
+
return { pct, tone, text: `${pct}%` };
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Every command the platform can send, and the brand capability it needs - a
|
|
270
|
+
* copy of core's `COMMAND_NEEDS` (`robot-adapter.util.ts`). The capability
|
|
271
|
+
* badge is measured against THIS list: it is about what a robot will DO when
|
|
272
|
+
* told, never about what it reports.
|
|
273
|
+
*/
|
|
274
|
+
const COMMAND_NEEDS: Readonly<Record<string, string>> = {
|
|
275
|
+
full: "startProcess",
|
|
276
|
+
area: "startProcess",
|
|
277
|
+
spot: "spotClean",
|
|
278
|
+
return: "sendToDock",
|
|
279
|
+
pause: "pauseProcess",
|
|
280
|
+
resume: "pauseProcess",
|
|
281
|
+
cancel: "pauseProcess",
|
|
282
|
+
navigate: "navigateToPoint",
|
|
283
|
+
relocalize: "relocalize",
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
/** Telemetry a brand may declare - reporting only, never a command. */
|
|
287
|
+
const TELEMETRY = ["readLocation", "battery", "floorReporting", "pathAndEta", "processCompletion"];
|
|
288
|
+
|
|
289
|
+
export type TCapabilityLevel = "Full control" | "Basic control" | "Read-only" | "No interface";
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* The capability badge (owner rule, 2026-09-23): COMMAND level, never telemetry.
|
|
293
|
+
*
|
|
294
|
+
* - Full control: accepts every command (Demo);
|
|
295
|
+
* - Basic control: accepts some commands but not all (Ounitech: clean all / area, dock);
|
|
296
|
+
* - Read-only: reports telemetry but accepts no command;
|
|
297
|
+
* - No interface: no connection at all - nothing declared (the security robot today).
|
|
298
|
+
*
|
|
299
|
+
* Derived from the brand's declared capabilities (`/robots/:id/state` or
|
|
300
|
+
* `/robots/brands`), NOT core's Open-RMF `robotTier`, which weighs telemetry.
|
|
301
|
+
* Missing / unknown capabilities claim the least.
|
|
302
|
+
*/
|
|
303
|
+
export function capabilityLabel(capabilities: Record<string, unknown> | null | undefined): TCapabilityLevel {
|
|
304
|
+
const caps = capabilities && typeof capabilities === "object" ? capabilities : {};
|
|
305
|
+
const kinds = Object.keys(COMMAND_NEEDS);
|
|
306
|
+
const accepted = kinds.filter((k) => caps[COMMAND_NEEDS[k]!] === true).length;
|
|
307
|
+
if (accepted === kinds.length) return "Full control";
|
|
308
|
+
if (accepted > 0) return "Basic control";
|
|
309
|
+
return TELEMETRY.some((t) => caps[t] === true) ? "Read-only" : "No interface";
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/** The badge: Full control is outlined accent; the rest neutral; No interface struck through. */
|
|
313
|
+
export function capabilityBadge(capabilities: Record<string, unknown> | null | undefined): {
|
|
314
|
+
label: TCapabilityLevel;
|
|
315
|
+
variant: "outline" | "neutral" | "struck";
|
|
316
|
+
} {
|
|
317
|
+
const label = capabilityLabel(capabilities);
|
|
318
|
+
const variant = label === "Full control" ? "outline" : label === "No interface" ? "struck" : "neutral";
|
|
319
|
+
return { label, variant };
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/** The facts a brand may or may not report, in the order the "Not reported" line lists them. */
|
|
323
|
+
const REPORTED_FACTS: ReadonlyArray<{ fact: "battery" | "floor" | "position"; needs: string }> = [
|
|
324
|
+
{ fact: "battery", needs: "battery" },
|
|
325
|
+
{ fact: "floor", needs: "floorReporting" },
|
|
326
|
+
{ fact: "position", needs: "readLocation" },
|
|
327
|
+
];
|
|
328
|
+
|
|
329
|
+
/** Which facts this brand reports - a fact cell it cannot fill says "Not reported". */
|
|
330
|
+
export function reportedFacts(capabilities: Record<string, unknown> | null | undefined) {
|
|
331
|
+
const caps = capabilities ?? {};
|
|
332
|
+
return Object.fromEntries(REPORTED_FACTS.map((f) => [f.fact, caps[f.needs] === true])) as Record<
|
|
333
|
+
"battery" | "floor" | "position",
|
|
334
|
+
boolean
|
|
335
|
+
>;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* "Not reported by Ounitech: battery, floor" - shown on robot detail so a
|
|
340
|
+
* missing fact reads as the brand's limit, not a fault. The brand's trailing
|
|
341
|
+
* model list ("Ounitech (Q3-G / Q3-W)") is dropped. Null when nothing is missing.
|
|
342
|
+
*/
|
|
343
|
+
export function notReportedLine(brand: unknown, capabilities: Record<string, unknown> | null | undefined): string | null {
|
|
344
|
+
const facts = reportedFacts(capabilities);
|
|
345
|
+
const missing = REPORTED_FACTS.filter((f) => !facts[f.fact]).map((f) => f.fact);
|
|
346
|
+
if (!missing.length) return null;
|
|
347
|
+
const name = (typeof brand === "string" ? brand : "").replace(/\s*\([^)]*\)\s*$/, "").trim() || "this brand";
|
|
348
|
+
return `Not reported by ${name}: ${missing.join(", ")}`;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
export type TRobotCommandKind =
|
|
352
|
+
| "full"
|
|
353
|
+
| "area"
|
|
354
|
+
| "return"
|
|
355
|
+
| "pause"
|
|
356
|
+
| "resume"
|
|
357
|
+
| "cancel"
|
|
358
|
+
| "navigate"
|
|
359
|
+
| "relocalize";
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* The command bar's buttons, in bar order; each needs `COMMAND_NEEDS[kind]`.
|
|
363
|
+
* `spot` is not here: spot clean is the plan's own control (`SpotClean.vue`).
|
|
364
|
+
*/
|
|
365
|
+
const COMMANDS: ReadonlyArray<{ kind: TRobotCommandKind; label: string }> = [
|
|
366
|
+
{ kind: "full", label: "Clean all" },
|
|
367
|
+
{ kind: "area", label: "Clean area" },
|
|
368
|
+
{ kind: "return", label: "Return to dock" },
|
|
369
|
+
{ kind: "pause", label: "Pause" },
|
|
370
|
+
{ kind: "resume", label: "Resume" },
|
|
371
|
+
{ kind: "cancel", label: "Cancel" },
|
|
372
|
+
{ kind: "navigate", label: "Go to point" },
|
|
373
|
+
{ kind: "relocalize", label: "Set position" },
|
|
374
|
+
];
|
|
375
|
+
|
|
376
|
+
export type TRobotCommand = { kind: TRobotCommandKind; label: string; primary: boolean };
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* The command bar's buttons - HIDDEN, never greyed, when any rule says no.
|
|
380
|
+
*
|
|
381
|
+
* - brand: only commands its declared capabilities support;
|
|
382
|
+
* - role: only a Manager (`canCommand`, i.e. the app's command permission);
|
|
383
|
+
* - online: only a robot confirmed online (`online === true`);
|
|
384
|
+
* - context: Pause only while working, Resume only while paused;
|
|
385
|
+
* - type: a security robot has no cleaning jobs, so no Clean all / Clean area.
|
|
386
|
+
*
|
|
387
|
+
* Returns [] whenever the bar should not render at all.
|
|
388
|
+
*/
|
|
389
|
+
export function visibleCommands(input: {
|
|
390
|
+
capabilities?: Record<string, unknown> | null;
|
|
391
|
+
canCommand?: unknown;
|
|
392
|
+
online?: unknown;
|
|
393
|
+
mode?: unknown;
|
|
394
|
+
type?: unknown;
|
|
395
|
+
} | null | undefined): TRobotCommand[] {
|
|
396
|
+
if (!input || input.canCommand !== true || input.online !== true) return [];
|
|
397
|
+
const caps = input.capabilities ?? {};
|
|
398
|
+
return COMMANDS.filter((c) => {
|
|
399
|
+
if (caps[COMMAND_NEEDS[c.kind]!] !== true) return false;
|
|
400
|
+
if (c.kind === "pause" && input.mode !== "WORKING") return false;
|
|
401
|
+
if (c.kind === "resume" && input.mode !== "PAUSED") return false;
|
|
402
|
+
if ((c.kind === "full" || c.kind === "area") && input.type === "security") return false;
|
|
403
|
+
return true;
|
|
404
|
+
}).map((c) => ({ kind: c.kind, label: c.label, primary: c.kind === "full" }));
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* One key per fault OCCURRENCE, so an alert fires once per occurrence.
|
|
409
|
+
*
|
|
410
|
+
* The same code clearing and coming back later is a new occurrence (a new
|
|
411
|
+
* `since`), so it alerts again; the same fault seen on every poll is not.
|
|
412
|
+
* With no `since`, the message stands in. No fault -> null (nothing to alert).
|
|
413
|
+
*/
|
|
414
|
+
export function faultKey(
|
|
415
|
+
robotId: unknown,
|
|
416
|
+
fault: { code?: unknown; message?: unknown; since?: unknown } | null | undefined,
|
|
417
|
+
): string | null {
|
|
418
|
+
if (!fault || (robotId !== 0 && !robotId)) return null;
|
|
419
|
+
const code = typeof fault.code === "string" ? fault.code.trim() : "";
|
|
420
|
+
const message = typeof fault.message === "string" ? fault.message.trim() : "";
|
|
421
|
+
if (!code && !message) return null;
|
|
422
|
+
const since = fault.since instanceof Date ? fault.since.toISOString() : fault.since;
|
|
423
|
+
const when = typeof since === "string" || typeof since === "number" ? String(since) : message;
|
|
424
|
+
return `${robotId}|${code}|${when}`;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
/** True the first time a fault occurrence is seen; records it in `seen`. */
|
|
428
|
+
export function shouldNotifyFault(key: string | null, seen: Set<string>): boolean {
|
|
429
|
+
if (!key || seen.has(key)) return false;
|
|
430
|
+
seen.add(key);
|
|
431
|
+
return true;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* The table footer. `page` is 1-based (Vuetify's); out-of-range pages clamp.
|
|
436
|
+
* "Showing 1–10 of 60 robots"; nothing to show reads "No robots".
|
|
437
|
+
*/
|
|
438
|
+
export function pageRange(page: unknown, perPage: unknown, total: unknown, noun = "robots") {
|
|
439
|
+
const size = typeof perPage === "number" && perPage > 0 ? Math.floor(perPage) : 10;
|
|
440
|
+
const count = typeof total === "number" && total > 0 ? Math.floor(total) : 0;
|
|
441
|
+
const pages = Math.max(1, Math.ceil(count / size));
|
|
442
|
+
const asked = typeof page === "number" && page >= 1 ? Math.floor(page) : 1;
|
|
443
|
+
const p = Math.min(asked, pages);
|
|
444
|
+
const from = count ? (p - 1) * size + 1 : 0;
|
|
445
|
+
const to = Math.min(p * size, count);
|
|
446
|
+
return {
|
|
447
|
+
page: p,
|
|
448
|
+
pages,
|
|
449
|
+
from,
|
|
450
|
+
to,
|
|
451
|
+
total: count,
|
|
452
|
+
hasPrev: p > 1,
|
|
453
|
+
hasNext: p < pages,
|
|
454
|
+
text: count ? `Showing ${from}–${to} of ${count} ${noun}` : `No ${noun}`,
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
/** How many of a summary cell's tick segments are filled: value/total of 20. */
|
|
459
|
+
export function summaryTicks(value: unknown, total: unknown, segments = 20): number {
|
|
460
|
+
const v = typeof value === "number" && value > 0 ? value : 0;
|
|
461
|
+
const t = typeof total === "number" && total > 0 ? total : 0;
|
|
462
|
+
if (!t) return 0;
|
|
463
|
+
return Math.round(Math.min(1, v / t) * segments);
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
/** Faults and Offline turn accent (and blink) when there are any; all else is ink. */
|
|
467
|
+
export function summaryAlert(kind: unknown, value: unknown): boolean {
|
|
468
|
+
return (kind === "faults" || kind === "offline") && typeof value === "number" && value > 0;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
/**
|
|
472
|
+
* The count-up: `target` after `elapsed` of `duration` ms, ease-out cubic.
|
|
473
|
+
* Whole numbers only - a robot count is never 12.4.
|
|
474
|
+
*/
|
|
475
|
+
export function countUpValue(target: number, elapsed: number, duration = 900): number {
|
|
476
|
+
if (!(duration > 0) || elapsed >= duration) return target;
|
|
477
|
+
const t = Math.max(0, elapsed) / duration;
|
|
478
|
+
return Math.round(target * (1 - Math.pow(1 - t, 3)));
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
export type TLiftState = "requested" | "riding" | "released" | "timed out";
|
|
482
|
+
|
|
483
|
+
/**
|
|
484
|
+
* A lift-queue row's chip tone and its bottom progress stripe:
|
|
485
|
+
* riding = fast moving stripe, requested = slow, timed out = solid accent,
|
|
486
|
+
* released = none.
|
|
487
|
+
*/
|
|
488
|
+
export function liftState(state: unknown): { label: string; tone: THeroTone; stripe: "fast" | "slow" | "solid" | "none" } {
|
|
489
|
+
switch (state) {
|
|
490
|
+
case "requested": return { label: "requested", tone: "info", stripe: "slow" };
|
|
491
|
+
case "riding": return { label: "riding", tone: "ink", stripe: "fast" };
|
|
492
|
+
case "released": return { label: "released", tone: "success", stripe: "none" };
|
|
493
|
+
case "timed out": return { label: "timed out", tone: "error", stripe: "solid" };
|
|
494
|
+
default: return { label: "unknown", tone: "error", stripe: "none" };
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
/** The map editor's tools, in toolbar order. */
|
|
499
|
+
export const MAP_TOOLS = [
|
|
500
|
+
{ id: "wall", label: "Wall" },
|
|
501
|
+
{ id: "zone", label: "Zone" },
|
|
502
|
+
{ id: "door", label: "Door" },
|
|
503
|
+
{ id: "lift", label: "Lift shaft" },
|
|
504
|
+
{ id: "move", label: "Move" },
|
|
505
|
+
{ id: "delete", label: "Delete" },
|
|
506
|
+
] as const;
|
|
507
|
+
|
|
508
|
+
/** A write-only credential's placeholder: once saved it is acknowledged, never shown. */
|
|
509
|
+
export function credentialPlaceholder(saved: unknown): string {
|
|
510
|
+
return saved === true ? "Saved · hidden. Enter to replace" : "Paste from the brand portal";
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
/** The HERO theme for the app's current light/dark setting. */
|
|
514
|
+
export function heroThemeName(appThemeIsDark: unknown): "hero-dark" | "hero-light" {
|
|
515
|
+
return appThemeIsDark === true ? "hero-dark" : "hero-light";
|
|
516
|
+
}
|