@7365admin1/layer-common 4.27.0 → 4.28.1-staging.356
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 +4 -10
- package/components/AccessCardAddForm.vue +5 -4
- package/components/AccessCardAssignToUnitForm.vue +3 -2
- package/components/AccessCardPreviewDialog.vue +4 -3
- package/components/Dialog/UpdateMoreAction.vue +11 -1
- package/components/DocumentForm.vue +407 -112
- package/components/DocumentManagement.vue +213 -12
- package/components/EntryPass/QrTemplatePreview.vue +21 -25
- package/components/EntryPassInformation.vue +119 -24
- package/components/Facility/BookingSetup.vue +63 -0
- package/components/HidAccessLogDashboard.vue +29 -5
- package/components/HidAccessPermissions.vue +424 -0
- package/components/HidIntercomManagement.vue +148 -14
- package/components/HidProfileQrCode.vue +323 -0
- package/components/HidReaderManagement.vue +26 -0
- package/components/HidReaderUserRoster.vue +32 -2
- package/components/HidUserEnrollment.vue +833 -152
- package/components/InvitationClientForm.vue +19 -1
- package/components/Robot/Map3D.vue +440 -45
- package/components/RolePermissionFormCreate.vue +163 -19
- package/components/RolePermissionFormPreviewUpdate.vue +230 -19
- package/components/RolePermissionMain.vue +19 -0
- package/components/VisitorManagement.vue +267 -5
- package/composables/useAccessManagement.ts +5 -0
- package/composables/useDocument.ts +7 -0
- package/composables/useFacility.ts +11 -0
- package/composables/useHidAmico.ts +117 -0
- package/composables/useHidNavigation.ts +25 -1
- package/composables/usePeople.ts +19 -0
- package/composables/useSiteCategory.ts +45 -0
- package/composables/useSiteEntryPassSettings.ts +26 -0
- package/composables/useWebUsb.ts +14 -11
- 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-qr-code/index.vue +23 -0
- package/pages/[org]/[site]/access-mgmt/hid-readers/index.vue +1 -1
- package/types/document.d.ts +14 -0
- package/types/facility.d.ts +4 -0
- package/types/people.d.ts +28 -1
- package/utils/building-map.ts +182 -5
- package/utils/hid-permission-assignments.ts +190 -0
- package/utils/occupancy-role.ts +109 -0
- package/utils/permission-labels.ts +30 -0
|
@@ -27,9 +27,35 @@ export default function useSiteEntryPassSettings() {
|
|
|
27
27
|
);
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
/**
|
|
31
|
+
* The encrypted ACM URL the access-card screens hand to API-core, which
|
|
32
|
+
* decrypts it and sends the ACM commands to that host.
|
|
33
|
+
*
|
|
34
|
+
* Resolves the site's own "Enter entrypass URL" setting first, the way
|
|
35
|
+
* `VisitorForm` does for contractor passes. The access-card forms used to
|
|
36
|
+
* call `/api/encrypt-acm-url` with no `url`, so every site's door/lift
|
|
37
|
+
* levels and access groups came from the route's hardcoded default host
|
|
38
|
+
* whatever the site had configured. A site with no URL set, or whose
|
|
39
|
+
* settings cannot be read, still gets that default.
|
|
40
|
+
*/
|
|
41
|
+
async function getEncryptedAcmUrl(siteId: string): Promise<string> {
|
|
42
|
+
let rawUrl = "";
|
|
43
|
+
try {
|
|
44
|
+
const settings: any = await getBySiteId(siteId);
|
|
45
|
+
rawUrl = String(settings?.data?.settings?.url ?? "").trim();
|
|
46
|
+
} catch {
|
|
47
|
+
// No entry pass settings for this site yet - the default host applies.
|
|
48
|
+
}
|
|
49
|
+
const { encrypted } = await $fetch<{ encrypted: string }>(
|
|
50
|
+
`/api/encrypt-acm-url${rawUrl ? `?url=${encodeURIComponent(rawUrl)}` : ""}`,
|
|
51
|
+
);
|
|
52
|
+
return encrypted;
|
|
53
|
+
}
|
|
54
|
+
|
|
30
55
|
return {
|
|
31
56
|
getBySiteId,
|
|
32
57
|
getById,
|
|
33
58
|
save,
|
|
59
|
+
getEncryptedAcmUrl,
|
|
34
60
|
};
|
|
35
61
|
}
|
package/composables/useWebUsb.ts
CHANGED
|
@@ -345,16 +345,19 @@ export default function useWebUsb() {
|
|
|
345
345
|
70,
|
|
346
346
|
);
|
|
347
347
|
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
348
|
+
// The pass used to print five copies of the same QR - four 140px ones at
|
|
349
|
+
// the corners around a 250px centre - so a strip could be cut apart. It now
|
|
350
|
+
// prints a single large QR filling that same band (y 90 to 440, above the
|
|
351
|
+
// company name at y 470), which scans far more reliably on a thermal print.
|
|
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
|
+
});
|
|
352
359
|
|
|
353
|
-
ctx.drawImage(qrCanvas,
|
|
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);
|
|
360
|
+
ctx.drawImage(qrCanvas, (canvas.width - qrSize) / 2, 90, qrSize, qrSize);
|
|
358
361
|
|
|
359
362
|
ctx.font = "25px Arial";
|
|
360
363
|
ctx.fillText(companyName || "", canvas.width / 2, 470);
|
|
@@ -401,8 +404,8 @@ export default function useWebUsb() {
|
|
|
401
404
|
/**
|
|
402
405
|
* The self-service onboarding QR: one large QR code, a "SCAN QR CODE"-style
|
|
403
406
|
* subtext, and a dark site-name banner along the bottom - a single-purpose
|
|
404
|
-
* gate sign, not the
|
|
405
|
-
*
|
|
407
|
+
* gate sign, not the visitor-pass receipt `createReceiptLayout` produces
|
|
408
|
+
* (that one pairs its QR with company, date, access and instruction lines).
|
|
406
409
|
*/
|
|
407
410
|
async function createOnboardingQrLayout(
|
|
408
411
|
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.28.1-staging.356",
|
|
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" card-management />
|
|
8
|
+
<HidUserEnrollment :site="siteId" :org="orgId" card-management />
|
|
9
9
|
</HidEnabledGate>
|
|
10
10
|
</v-container>
|
|
11
11
|
</template>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<v-container fluid>
|
|
3
|
+
<HidEnabledGate
|
|
4
|
+
:site="siteId"
|
|
5
|
+
:org="orgId"
|
|
6
|
+
message="Enable HID as a service for this site before generating a QR code."
|
|
7
|
+
>
|
|
8
|
+
<HidProfileQrCode :site="siteId" />
|
|
9
|
+
</HidEnabledGate>
|
|
10
|
+
</v-container>
|
|
11
|
+
</template>
|
|
12
|
+
|
|
13
|
+
<script setup lang="ts">
|
|
14
|
+
definePageMeta({
|
|
15
|
+
layout: "default",
|
|
16
|
+
middleware: ["01-auth", "02-org"],
|
|
17
|
+
memberOnly: true,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const route = useRoute();
|
|
21
|
+
const siteId = computed(() => String(route.params.site ?? ""));
|
|
22
|
+
const orgId = computed(() => String(route.params.org ?? ""));
|
|
23
|
+
</script>
|
package/types/document.d.ts
CHANGED
|
@@ -3,4 +3,18 @@ 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;
|
|
6
20
|
};
|
package/types/facility.d.ts
CHANGED
|
@@ -73,6 +73,10 @@ 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;
|
|
76
80
|
bookingAmount: number | null;
|
|
77
81
|
peakBookingFeeAmount?: number | null;
|
|
78
82
|
bookingFeeGuestAmount?: number | null;
|
package/types/people.d.ts
CHANGED
|
@@ -22,11 +22,38 @@ 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;
|
|
25
49
|
};
|
|
26
50
|
|
|
27
51
|
declare type TPlateNumber = { plateNumber: string, recNo?: string, _id?: string, status: TVehicleStatus, type: TVehicleType, anprCameras?: TVehicleAnprCamera[] };
|
|
28
52
|
|
|
29
53
|
|
|
30
|
-
|
|
54
|
+
// `""` is the FORM's "nothing picked yet" - it is stripped from the payload
|
|
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 | "" }
|
|
31
58
|
|
|
32
59
|
declare type TPeopleType = "guest" | "resident" | "tenant"
|
package/utils/building-map.ts
CHANGED
|
@@ -48,7 +48,7 @@ export type TWallSolid = {
|
|
|
48
48
|
heightM: number;
|
|
49
49
|
yaw: number;
|
|
50
50
|
/** What the box is, so the renderer can colour it. Absent = a wall. */
|
|
51
|
-
kind?: "wall" | "door" | "lift" | "car";
|
|
51
|
+
kind?: "wall" | "drawn" | "door" | "lift" | "car";
|
|
52
52
|
};
|
|
53
53
|
|
|
54
54
|
/* ------------------------------------------------- image to occupancy grid */
|
|
@@ -524,14 +524,191 @@ export function insideLift(p: TMapPointM, lift: TMapLift): boolean {
|
|
|
524
524
|
return Math.abs(p.x - lift.x) <= lift.widthM / 2 && Math.abs(p.y - lift.y) <= lift.depthM / 2;
|
|
525
525
|
}
|
|
526
526
|
|
|
527
|
-
/** The next free default name: Lift A, Lift B, ... / Door 1,
|
|
528
|
-
export function nextFeatureName(existing: string[], kind: "lift" | "door"): string {
|
|
527
|
+
/** The next free default name: Lift A, Lift B, ... / Door 1, ... / Zone 1, ... */
|
|
528
|
+
export function nextFeatureName(existing: string[], kind: "lift" | "door" | "zone"): string {
|
|
529
529
|
const taken = new Set(existing);
|
|
530
|
+
const word = kind === "lift" ? "Lift" : kind === "door" ? "Door" : "Zone";
|
|
530
531
|
for (let i = 0; i < 500; i++) {
|
|
531
532
|
const name = kind === "lift"
|
|
532
533
|
? `Lift ${i < 26 ? String.fromCharCode(65 + i) : i + 1}`
|
|
533
|
-
:
|
|
534
|
+
: `${word} ${i + 1}`;
|
|
534
535
|
if (!taken.has(name)) return name;
|
|
535
536
|
}
|
|
536
|
-
return `${
|
|
537
|
+
return `${word} ${existing.length + 1}`;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
/* ------------------------------------------- drawn walls and zones */
|
|
541
|
+
|
|
542
|
+
/**
|
|
543
|
+
* Walls and zones somebody drew, flattened with their floor so the editor can
|
|
544
|
+
* treat them like doors. Saved per level (`levels[].walls` / `levels[].zones`,
|
|
545
|
+
* the shapes core's `robot-building-map.model.ts` validates).
|
|
546
|
+
*/
|
|
547
|
+
export type TMapDrawnWall = { floorNo: number; start: TMapPointM; end: TMapPointM };
|
|
548
|
+
export type TMapZone = { floorNo: number; name: string; points: TMapPointM[] };
|
|
549
|
+
|
|
550
|
+
/** The API's limits, checked before a save so the message names the problem. */
|
|
551
|
+
export const MAX_WALLS_PER_LEVEL = 2000;
|
|
552
|
+
export const MAX_ZONES_PER_LEVEL = 200;
|
|
553
|
+
export const MAX_ZONE_POINTS = 200;
|
|
554
|
+
export const COORD_LIMIT_M = 1000;
|
|
555
|
+
/** Shorter than this, a click pair is a slip, not a wall. */
|
|
556
|
+
export const MIN_WALL_M = 0.1;
|
|
557
|
+
|
|
558
|
+
/** A drawn wall as a full-height box. Null for a zero-length wall. */
|
|
559
|
+
export function drawnWallSolid(wall: TMapDrawnWall, elevationM: number): TWallSolid | null {
|
|
560
|
+
const lengthM = Math.hypot(wall.end.x - wall.start.x, wall.end.y - wall.start.y);
|
|
561
|
+
if (!(lengthM > 0)) return null;
|
|
562
|
+
return {
|
|
563
|
+
kind: "drawn",
|
|
564
|
+
centre: {
|
|
565
|
+
x: (wall.start.x + wall.end.x) / 2,
|
|
566
|
+
y: (wall.start.y + wall.end.y) / 2,
|
|
567
|
+
z: elevationM + WALL_HEIGHT_M / 2,
|
|
568
|
+
},
|
|
569
|
+
lengthM,
|
|
570
|
+
thicknessM: WALL_THICKNESS_M * 1.5,
|
|
571
|
+
heightM: WALL_HEIGHT_M,
|
|
572
|
+
yaw: Math.atan2(wall.end.y - wall.start.y, wall.end.x - wall.start.x),
|
|
573
|
+
};
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
/** Even-odd ray cast. The editor's zone hit test. */
|
|
577
|
+
export function pointInPolygon(p: TMapPointM, points: TMapPointM[]): boolean {
|
|
578
|
+
let inside = false;
|
|
579
|
+
for (let i = 0, j = points.length - 1; i < points.length; j = i++) {
|
|
580
|
+
const a = points[i];
|
|
581
|
+
const b = points[j];
|
|
582
|
+
if (a.y > p.y !== b.y > p.y && p.x < ((b.x - a.x) * (p.y - a.y)) / (b.y - a.y) + a.x) {
|
|
583
|
+
inside = !inside;
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
return inside;
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
/** Shoelace area, square metres, always positive. */
|
|
590
|
+
export function polygonArea(points: TMapPointM[]): number {
|
|
591
|
+
let twice = 0;
|
|
592
|
+
for (let i = 0, j = points.length - 1; i < points.length; j = i++) {
|
|
593
|
+
twice += (points[j].x + points[i].x) * (points[j].y - points[i].y);
|
|
594
|
+
}
|
|
595
|
+
return Math.abs(twice) / 2;
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
/** Where a zone's name is written: the mean of its corners. */
|
|
599
|
+
export function polygonCentre(points: TMapPointM[]): TMapPointM {
|
|
600
|
+
const n = points.length || 1;
|
|
601
|
+
return {
|
|
602
|
+
x: points.reduce((t, p) => t + p.x, 0) / n,
|
|
603
|
+
y: points.reduce((t, p) => t + p.y, 0) / n,
|
|
604
|
+
};
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
/** Index of the nearest candidate within `tolerance` metres, or -1. */
|
|
608
|
+
export function nearestPoint(p: TMapPointM, candidates: TMapPointM[], tolerance: number): number {
|
|
609
|
+
let best = -1;
|
|
610
|
+
let bestD = tolerance;
|
|
611
|
+
candidates.forEach((c, i) => {
|
|
612
|
+
const d = Math.hypot(c.x - p.x, c.y - p.y);
|
|
613
|
+
if (d <= bestD) {
|
|
614
|
+
best = i;
|
|
615
|
+
bestD = d;
|
|
616
|
+
}
|
|
617
|
+
});
|
|
618
|
+
return best;
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
/** A saved map's levels to the editor's flat lists. Malformed entries are skipped. */
|
|
622
|
+
export function levelFeatures(
|
|
623
|
+
levels: Array<Record<string, any>> = [],
|
|
624
|
+
): { walls: TMapDrawnWall[]; zones: TMapZone[] } {
|
|
625
|
+
const ok = (p: any) => p && Number.isFinite(p.x) && Number.isFinite(p.y);
|
|
626
|
+
const walls: TMapDrawnWall[] = [];
|
|
627
|
+
const zones: TMapZone[] = [];
|
|
628
|
+
for (const level of levels ?? []) {
|
|
629
|
+
const floorNo = Number(level?.floorNo);
|
|
630
|
+
if (!Number.isFinite(floorNo)) continue;
|
|
631
|
+
for (const w of level.walls ?? []) {
|
|
632
|
+
if (ok(w?.start) && ok(w?.end)) {
|
|
633
|
+
walls.push({ floorNo, start: { x: w.start.x, y: w.start.y }, end: { x: w.end.x, y: w.end.y } });
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
for (const z of level.zones ?? []) {
|
|
637
|
+
const points = (z?.points ?? []).filter(ok).map((p: TMapPointM) => ({ x: p.x, y: p.y }));
|
|
638
|
+
if (points.length >= 3) zones.push({ floorNo, name: String(z.name ?? ""), points });
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
return { walls, zones };
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
type TSavedLevelFeatures = {
|
|
645
|
+
walls?: Array<{ start: TMapPointM; end: TMapPointM }>;
|
|
646
|
+
zones?: Array<{ name: string; points: TMapPointM[] }>;
|
|
647
|
+
};
|
|
648
|
+
|
|
649
|
+
/** One floor's drawn walls and zones in the saved shape; keys omitted when empty. */
|
|
650
|
+
export function featuresForLevel(
|
|
651
|
+
floorNo: number,
|
|
652
|
+
walls: TMapDrawnWall[],
|
|
653
|
+
zones: TMapZone[],
|
|
654
|
+
): TSavedLevelFeatures {
|
|
655
|
+
const out: TSavedLevelFeatures = {};
|
|
656
|
+
const w = walls.filter((x) => x.floorNo === floorNo).map(({ start, end }) => ({ start, end }));
|
|
657
|
+
const z = zones
|
|
658
|
+
.filter((x) => x.floorNo === floorNo)
|
|
659
|
+
.map(({ name, points }) => ({ name: name.trim() || "Zone", points }));
|
|
660
|
+
if (w.length) out.walls = w;
|
|
661
|
+
if (z.length) out.zones = z;
|
|
662
|
+
return out;
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
/**
|
|
666
|
+
* The first reason the API would refuse these walls and zones, in words, or
|
|
667
|
+
* null. Checked before a save so the person sees which shape is wrong instead
|
|
668
|
+
* of a validation error.
|
|
669
|
+
*/
|
|
670
|
+
export function layoutProblem(walls: TMapDrawnWall[], zones: TMapZone[]): string | null {
|
|
671
|
+
const far = (p: TMapPointM) => Math.abs(p.x) > COORD_LIMIT_M || Math.abs(p.y) > COORD_LIMIT_M;
|
|
672
|
+
const count = new Map<string, number>();
|
|
673
|
+
const bump = (k: string) => {
|
|
674
|
+
count.set(k, (count.get(k) ?? 0) + 1);
|
|
675
|
+
return count.get(k) as number;
|
|
676
|
+
};
|
|
677
|
+
for (const w of walls) {
|
|
678
|
+
if (far(w.start) || far(w.end)) return `A wall on floor ${w.floorNo} is too far from the map.`;
|
|
679
|
+
if (bump(`w${w.floorNo}`) > MAX_WALLS_PER_LEVEL) {
|
|
680
|
+
return `Floor ${w.floorNo} has more than ${MAX_WALLS_PER_LEVEL} drawn walls.`;
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
for (const z of zones) {
|
|
684
|
+
const name = z.name.trim() || "A zone";
|
|
685
|
+
if (name.length > 60) return `"${name.slice(0, 20)}…" is too long - a zone name can be 60 characters at most.`;
|
|
686
|
+
if (z.points.length < 3) return `${name} needs at least three corners.`;
|
|
687
|
+
if (z.points.length > MAX_ZONE_POINTS) return `${name} has more than ${MAX_ZONE_POINTS} corners.`;
|
|
688
|
+
if (z.points.some(far)) return `${name} is too far from the map.`;
|
|
689
|
+
if (polygonArea(z.points) < 0.01) return `${name} has no area - its corners are in a line.`;
|
|
690
|
+
if (bump(`z${z.floorNo}`) > MAX_ZONES_PER_LEVEL) {
|
|
691
|
+
return `Floor ${z.floorNo} has more than ${MAX_ZONES_PER_LEVEL} zones.`;
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
return null;
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
/**
|
|
698
|
+
* Undo history: whole-layout snapshots, newest last. A layout is a few KB, so
|
|
699
|
+
* a snapshot per edit is simpler and safer than inverse operations.
|
|
700
|
+
*
|
|
701
|
+
* ponytail: snapshots capped at `limit`. Diff-based history if layouts ever
|
|
702
|
+
* reach megabytes.
|
|
703
|
+
*/
|
|
704
|
+
export function pushUndo<T>(stack: string[], state: T, limit = 50): void {
|
|
705
|
+
const snap = JSON.stringify(state);
|
|
706
|
+
if (stack[stack.length - 1] === snap) return;
|
|
707
|
+
stack.push(snap);
|
|
708
|
+
if (stack.length > limit) stack.splice(0, stack.length - limit);
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
export function popUndo<T>(stack: string[]): T | null {
|
|
712
|
+
const snap = stack.pop();
|
|
713
|
+
return snap === undefined ? null : (JSON.parse(snap) as T);
|
|
537
714
|
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WHO IS ASSIGNED TO A HID READER — the editing model behind the permissions
|
|
3
|
+
* dialog.
|
|
4
|
+
*
|
|
5
|
+
* This is the step that actually grants access. Enrolling a person gives the
|
|
6
|
+
* reader a face, a card or a PIN it can RECOGNISE; it puts nobody in the group
|
|
7
|
+
* the access rule is attached to, so a recognised person is still refused at
|
|
8
|
+
* the door (access log event 6). `PUT /sites/:siteId/permissions` is the only
|
|
9
|
+
* call in the system that writes that group membership.
|
|
10
|
+
*
|
|
11
|
+
* Two contracts make this file necessary rather than inlining the logic in the
|
|
12
|
+
* component:
|
|
13
|
+
*
|
|
14
|
+
* 1. **The PUT REPLACES the whole assignment set for the reader.** The server
|
|
15
|
+
* keeps other readers' rows and overwrites this reader's with exactly what
|
|
16
|
+
* is sent. The candidate list, however, is fetched ONE CATEGORY AT A TIME.
|
|
17
|
+
* Saving from the tab in front of you while sending only that tab's people
|
|
18
|
+
* would silently revoke every resident if you were looking at the service
|
|
19
|
+
* providers tab. So the edit state is held for the whole reader and the
|
|
20
|
+
* payload is always built from all of it.
|
|
21
|
+
*
|
|
22
|
+
* 2. **The body schema accepts three keys and nothing else.**
|
|
23
|
+
* `hidPermissionAssignmentSchema` is `{ subjectId, category, intercom }`,
|
|
24
|
+
* and Joi rejects unknown keys rather than stripping them. The candidate
|
|
25
|
+
* rows carry `name`, `subtitle`, `location` and friends for display, so the
|
|
26
|
+
* payload has to be narrowed deliberately — passing a candidate straight
|
|
27
|
+
* through is a 400.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
/** The three real categories. `intercom` is a candidate FILTER, never a category. */
|
|
31
|
+
export const HID_PERMISSION_CATEGORIES: THidPermissionCategory[] = [
|
|
32
|
+
"resident",
|
|
33
|
+
"property_management",
|
|
34
|
+
"service_provider",
|
|
35
|
+
];
|
|
36
|
+
|
|
37
|
+
export type HidAssignmentState = Map<string, { category: THidPermissionCategory; intercom: boolean }>;
|
|
38
|
+
|
|
39
|
+
/** Body row for `updateSitePermissions` — exactly the keys Joi allows. */
|
|
40
|
+
export type HidAssignmentPayload = {
|
|
41
|
+
subjectId: string;
|
|
42
|
+
category: THidPermissionCategory;
|
|
43
|
+
intercom: boolean;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
function isRealCategory(value: unknown): value is THidPermissionCategory {
|
|
47
|
+
return HID_PERMISSION_CATEGORIES.includes(value as THidPermissionCategory);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The reader's CURRENT assignments, as the edit state.
|
|
52
|
+
*
|
|
53
|
+
* Seeded from `getSitePermissions`, which returns every category at once —
|
|
54
|
+
* that is what makes a whole-reader payload possible from a one-category view.
|
|
55
|
+
* Rows with an unrecognised category are dropped rather than carried: sending
|
|
56
|
+
* one back fails the enum check and takes the entire save with it.
|
|
57
|
+
*/
|
|
58
|
+
export function seedAssignments(
|
|
59
|
+
assignments: readonly THidPermissionAssignment[] | undefined | null,
|
|
60
|
+
): HidAssignmentState {
|
|
61
|
+
const state: HidAssignmentState = new Map();
|
|
62
|
+
if (!Array.isArray(assignments)) return state;
|
|
63
|
+
for (const assignment of assignments) {
|
|
64
|
+
const subjectId = String(assignment?.subjectId ?? "");
|
|
65
|
+
if (!subjectId || !isRealCategory(assignment?.category)) continue;
|
|
66
|
+
state.set(subjectId, {
|
|
67
|
+
category: assignment.category,
|
|
68
|
+
intercom: assignment.intercom === true,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
return state;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Add or remove one person.
|
|
76
|
+
*
|
|
77
|
+
* `saved` is the state the dialog opened with, and it is consulted for one
|
|
78
|
+
* reason: the `intercom` flag. Nothing here edits that flag, but
|
|
79
|
+
* `userHasSiteIntercomPermission` reads it off these same rows, so it must
|
|
80
|
+
* survive a round trip through the checkbox.
|
|
81
|
+
*
|
|
82
|
+
* - **Untick then save** drops it, which is right — an unassigned person
|
|
83
|
+
* holding a dangling intercom right would keep answering the door panel
|
|
84
|
+
* after losing the door.
|
|
85
|
+
* - **Untick then re-tick, without saving** must restore it. Removing from the
|
|
86
|
+
* draft forgets the flag, so re-adding recovers it from `saved`; otherwise a
|
|
87
|
+
* misclick corrected a second later would silently revoke intercom on the
|
|
88
|
+
* next save, with nothing on screen to show it had happened.
|
|
89
|
+
*/
|
|
90
|
+
export function setAssignment(
|
|
91
|
+
state: HidAssignmentState,
|
|
92
|
+
saved: HidAssignmentState,
|
|
93
|
+
subjectId: string,
|
|
94
|
+
category: THidPermissionCategory,
|
|
95
|
+
selected: boolean,
|
|
96
|
+
): HidAssignmentState {
|
|
97
|
+
const next: HidAssignmentState = new Map(state);
|
|
98
|
+
const id = String(subjectId ?? "");
|
|
99
|
+
if (!id || !isRealCategory(category)) return next;
|
|
100
|
+
if (!selected) {
|
|
101
|
+
next.delete(id);
|
|
102
|
+
return next;
|
|
103
|
+
}
|
|
104
|
+
const intercom = next.get(id)?.intercom ?? saved.get(id)?.intercom ?? false;
|
|
105
|
+
next.set(id, { category, intercom: intercom === true });
|
|
106
|
+
return next;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** The whole reader's assignments, narrowed to the three keys the API accepts. */
|
|
110
|
+
export function toAssignmentPayload(state: HidAssignmentState): HidAssignmentPayload[] {
|
|
111
|
+
return [...state.entries()].map(([subjectId, value]) => ({
|
|
112
|
+
subjectId,
|
|
113
|
+
category: value.category,
|
|
114
|
+
intercom: value.intercom === true,
|
|
115
|
+
}));
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* The server sends `selected` with each candidate, describing what is SAVED.
|
|
120
|
+
* Once the dialog is open the local edit state is the truth, so the flag is
|
|
121
|
+
* recomputed rather than trusted — otherwise paging or searching would redraw
|
|
122
|
+
* a row with the saved value and quietly discard an unsaved tick.
|
|
123
|
+
*/
|
|
124
|
+
export function applySelection(
|
|
125
|
+
candidates: readonly THidPermissionCandidate[] | undefined | null,
|
|
126
|
+
state: HidAssignmentState,
|
|
127
|
+
): THidPermissionCandidate[] {
|
|
128
|
+
if (!Array.isArray(candidates)) return [];
|
|
129
|
+
return candidates.map((candidate) => ({
|
|
130
|
+
...candidate,
|
|
131
|
+
selected: state.has(String(candidate?.subjectId ?? "")),
|
|
132
|
+
}));
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** Per-category totals for the dialog header, counted over the whole reader. */
|
|
136
|
+
export function countByCategory(state: HidAssignmentState): Record<THidPermissionCategory, number> {
|
|
137
|
+
const counts = { resident: 0, property_management: 0, service_provider: 0 } as Record<
|
|
138
|
+
THidPermissionCategory,
|
|
139
|
+
number
|
|
140
|
+
>;
|
|
141
|
+
for (const value of state.values()) counts[value.category] += 1;
|
|
142
|
+
return counts;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** Has anything changed since the dialog opened? Drives the Save button. */
|
|
146
|
+
export function hasChanges(saved: HidAssignmentState, draft: HidAssignmentState): boolean {
|
|
147
|
+
if (saved.size !== draft.size) return true;
|
|
148
|
+
for (const [subjectId, value] of draft) {
|
|
149
|
+
const before = saved.get(subjectId);
|
|
150
|
+
if (!before) return true;
|
|
151
|
+
if (before.category !== value.category) return true;
|
|
152
|
+
if (before.intercom !== value.intercom) return true;
|
|
153
|
+
}
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* What a listing response tells us: the rows, and how many pages exist.
|
|
159
|
+
*
|
|
160
|
+
* It deliberately does NOT return the current page, and the caller must keep
|
|
161
|
+
* owning that. `paginate` in `@7365admin1/node-server-utils` returns only
|
|
162
|
+
* `{ items, pages, pageRange }` — it never echoes the page it was asked for. A
|
|
163
|
+
* caller that read one back therefore got a default on every fetch and pinned
|
|
164
|
+
* itself to page one, so the pager moved and the rows never did.
|
|
165
|
+
*
|
|
166
|
+
* `items` sits at the root on some of these endpoints and under `data` on
|
|
167
|
+
* others, so both are read.
|
|
168
|
+
*/
|
|
169
|
+
export function readCandidatePage(response: unknown): {
|
|
170
|
+
items: THidPermissionCandidate[];
|
|
171
|
+
pages: number;
|
|
172
|
+
pageRange: string;
|
|
173
|
+
} {
|
|
174
|
+
const source = (response && typeof response === "object" ? response : {}) as Record<string, unknown>;
|
|
175
|
+
const nested = (source.data && typeof source.data === "object" ? source.data : {}) as Record<string, unknown>;
|
|
176
|
+
const items = Array.isArray(source.items)
|
|
177
|
+
? source.items
|
|
178
|
+
: Array.isArray(nested.items)
|
|
179
|
+
? nested.items
|
|
180
|
+
: [];
|
|
181
|
+
const pages = Number(source.pages ?? nested.pages ?? 1);
|
|
182
|
+
// `paginate` builds this ("1-10 of 37") and the table renders it verbatim.
|
|
183
|
+
// Without it the pager draws its placeholder, "-- - -- of --".
|
|
184
|
+
const pageRange = String(source.pageRange ?? nested.pageRange ?? "");
|
|
185
|
+
return {
|
|
186
|
+
items: items as THidPermissionCandidate[],
|
|
187
|
+
pages: Number.isFinite(pages) && pages > 0 ? pages : 1,
|
|
188
|
+
pageRange,
|
|
189
|
+
};
|
|
190
|
+
}
|