@7365admin1/layer-common 4.25.0 → 4.26.1-staging.354

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.
Files changed (50) hide show
  1. package/CHANGELOG.md +18 -4
  2. package/components/AccessCardAddForm.vue +5 -4
  3. package/components/AccessCardAssignToUnitForm.vue +3 -2
  4. package/components/AccessCardPreviewDialog.vue +4 -3
  5. package/components/Dialog/UpdateMoreAction.vue +11 -1
  6. package/components/DocumentForm.vue +407 -112
  7. package/components/DocumentManagement.vue +213 -12
  8. package/components/EntryPass/QrTemplatePreview.vue +21 -25
  9. package/components/EntryPassInformation.vue +119 -24
  10. package/components/Facility/BookingSetup.vue +63 -0
  11. package/components/HidAccessLogDashboard.vue +29 -5
  12. package/components/HidAccessPermissions.vue +424 -0
  13. package/components/HidIntercomManagement.vue +148 -14
  14. package/components/HidProfileQrCode.vue +323 -0
  15. package/components/HidReaderManagement.vue +26 -0
  16. package/components/HidReaderUserRoster.vue +32 -2
  17. package/components/HidUserEnrollment.vue +833 -152
  18. package/components/InvitationClientForm.vue +19 -1
  19. package/components/Robot/Fleet.vue +182 -2
  20. package/components/Robot/Form.vue +37 -12
  21. package/components/Robot/Map3D.vue +803 -40
  22. package/components/Robot/Plans.vue +63 -0
  23. package/components/Robot/SpotClean.vue +174 -0
  24. package/components/RolePermissionFormCreate.vue +163 -19
  25. package/components/RolePermissionFormPreviewUpdate.vue +230 -19
  26. package/components/RolePermissionMain.vue +19 -0
  27. package/components/VisitorManagement.vue +267 -5
  28. package/composables/useAccessManagement.ts +5 -0
  29. package/composables/useDocument.ts +7 -0
  30. package/composables/useFacility.ts +11 -0
  31. package/composables/useHidAmico.ts +117 -0
  32. package/composables/useHidNavigation.ts +25 -1
  33. package/composables/usePeople.ts +19 -0
  34. package/composables/useRobots.ts +111 -0
  35. package/composables/useSiteCategory.ts +45 -0
  36. package/composables/useSiteEntryPassSettings.ts +26 -0
  37. package/composables/useWebUsb.ts +14 -11
  38. package/package.json +1 -1
  39. package/pages/[org]/[site]/access-mgmt/administrator/index.vue +1 -1
  40. package/pages/[org]/[site]/access-mgmt/hid-cards/index.vue +1 -1
  41. package/pages/[org]/[site]/access-mgmt/hid-qr-code/index.vue +23 -0
  42. package/pages/[org]/[site]/access-mgmt/hid-readers/index.vue +1 -1
  43. package/types/document.d.ts +14 -0
  44. package/types/facility.d.ts +4 -0
  45. package/types/people.d.ts +28 -1
  46. package/utils/building-map.ts +179 -8
  47. package/utils/hid-permission-assignments.ts +190 -0
  48. package/utils/occupancy-role.ts +109 -0
  49. package/utils/permission-labels.ts +30 -0
  50. package/utils/robot-display.ts +89 -0
@@ -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
+ }
@@ -0,0 +1,109 @@
1
+ /**
2
+ * OWNER / OCCUPANT / PERSON IN CHARGE - the three standings a business
3
+ * tenancy has, and everything the product says about them.
4
+ *
5
+ * One list, because three screens read it: the form that asks the question
6
+ * (`PeopleFormMgmt`), the list and preview that print the answer back, and
7
+ * the row menu that reassigns it (`people-mgmt`). The values are the ones the
8
+ * server stores and validates - `OccupancyRoles` in core's `person.model.ts`
9
+ * - so a value added on one side has to be added on the other.
10
+ */
11
+ export const OCCUPANCY_ROLE_OPTIONS: TOccupancyRoleOption[] = [
12
+ {
13
+ value: "owner",
14
+ title: "Owner",
15
+ action: "Assign Owner",
16
+ prompt: "Assign Owner",
17
+ description:
18
+ "The legal titleholder or primary deed owner of the property.",
19
+ },
20
+ {
21
+ value: "occupant",
22
+ title: "Occupant",
23
+ action: "Assign Occupant",
24
+ prompt: "Assign Occupant",
25
+ description:
26
+ "The person currently living in, renting, or utilizing the physical unit.",
27
+ },
28
+ {
29
+ value: "person-in-charge",
30
+ title: "Person in Charge",
31
+ action: "Assign Person in Charge",
32
+ prompt: "Assign Person in Charge (PIC)",
33
+ description:
34
+ "The designated manager responsible for maintenance, emergencies, and daily operations.",
35
+ },
36
+ ];
37
+
38
+ /**
39
+ * The same three, in the order the ROW MENU draws them, which is not the
40
+ * order the form's radio does. Derived rather than re-typed so the wording
41
+ * cannot drift between the two.
42
+ */
43
+ export const OCCUPANCY_ROLE_ACTIONS: TOccupancyRoleOption[] = (
44
+ ["person-in-charge", "owner", "occupant"] as TOccupancyRole[]
45
+ ).map(
46
+ (value) =>
47
+ OCCUPANCY_ROLE_OPTIONS.find(
48
+ (option) => option.value === value,
49
+ ) as TOccupancyRoleOption,
50
+ );
51
+
52
+ /**
53
+ * The label for a stored role, or "" for a person who was never asked - which
54
+ * is everyone on a residential site and everyone saved before the question
55
+ * existed. Callers decide what to print instead; nobody should print a raw
56
+ * `person-in-charge` at a user.
57
+ */
58
+ export function occupancyRoleLabel(role?: string | null): string {
59
+ return (
60
+ OCCUPANCY_ROLE_OPTIONS.find((option) => option.value === role)?.title ?? ""
61
+ );
62
+ }
63
+
64
+ /**
65
+ * Does this person hold OWNER at their unit?
66
+ *
67
+ * The role when there is one, `isOwner` when there is not - the same test the
68
+ * server applies (`holdsUnitOwner` in core's `unit-owner.util.ts`). A person
69
+ * recorded before the role existed carries only the flag, and the people list
70
+ * already prints them as "Owner".
71
+ */
72
+ export function holdsUnitOwner(person?: {
73
+ occupancyRole?: string | null;
74
+ isOwner?: boolean;
75
+ }): boolean {
76
+ if (!person) return false;
77
+
78
+ if (person.occupancyRole) return person.occupancyRole === "owner";
79
+
80
+ return person.isOwner === true;
81
+ }
82
+
83
+ /**
84
+ * MUST THIS PERSON HAND THE UNIT OVER BEFORE THEY CAN BE DEACTIVATED?
85
+ *
86
+ * The owner of a unit does not leave while they still own it - the standing
87
+ * moves to another tenant at the same block, level and unit first.
88
+ *
89
+ * Keyed to the ROLE and never to `isOwner`, exactly as the server keys it
90
+ * (`mustHandOverBeforeDeactivating` in core): the flag is on every resident in
91
+ * the estate, and no residential screen can change it, so a rule keyed to it
92
+ * would trap records that can never satisfy it.
93
+ */
94
+ export function mustHandOverBeforeDeactivating(person?: {
95
+ occupancyRole?: string | null;
96
+ }): boolean {
97
+ return person?.occupancyRole === "owner";
98
+ }
99
+
100
+ /**
101
+ * Why a deactivation was held back. The SERVER carries the enforcing copy of
102
+ * this rule and of these words (core `unit-owner.util.ts`); this one exists so
103
+ * the console can say it before the round trip rather than after.
104
+ */
105
+ export function ownerHandoverRequiredMessage(name?: string): string {
106
+ const who = name?.trim() ? `"${name.trim()}"` : "This person";
107
+
108
+ return `${who} is the owner of this unit. Assign the owner role to another tenant at the same block, level and unit before deactivating them.`;
109
+ }
@@ -98,3 +98,33 @@ export function formatActionLabel(action: string): string {
98
98
  .map((word) => ACRONYMS[word.toLowerCase()] ?? word.toLowerCase())
99
99
  .join(" ");
100
100
  }
101
+
102
+
103
+ /**
104
+ * A permission tree with its modules in the order a person reads them: A-Z by
105
+ * the LABEL on screen, not by the raw key.
106
+ *
107
+ * Sorting the keys would order by `daily-occurrence-books` and `SOA-mgmt`,
108
+ * which is not the order the eye scans -- "Daily Occurrence Book" and
109
+ * "Statements" are what is actually printed. `localeCompare` with `numeric` so
110
+ * a "Level 2" sorts after "Level 10" the way a person expects, and case is
111
+ * ignored so a capitalised label does not sort ahead of the alphabet.
112
+ *
113
+ * Returns a NEW object; string keys keep insertion order, which is what the
114
+ * `v-for` walks. Display only -- no permission is added, removed or renamed.
115
+ */
116
+ export function sortResourcesByLabel<T>(
117
+ tree: Record<string, T> | null | undefined,
118
+ ): Record<string, T> {
119
+ if (!tree || typeof tree !== "object") return {};
120
+ const sorted: Record<string, T> = {};
121
+ for (const key of Object.keys(tree).sort((a, b) =>
122
+ formatResourceLabel(a).localeCompare(formatResourceLabel(b), undefined, {
123
+ sensitivity: "base",
124
+ numeric: true,
125
+ }),
126
+ )) {
127
+ sorted[key] = tree[key];
128
+ }
129
+ return sorted;
130
+ }
@@ -121,3 +121,92 @@ export function robotErrorMessage(error: unknown, fallback = "Could not reach th
121
121
  if (typeof e?.message === "string" && e.message.trim()) return e.message.trim();
122
122
  return fallback;
123
123
  }
124
+
125
+ /**
126
+ * May the "Spot clean" control be offered?
127
+ *
128
+ * Only when the robot could take a job now AND its brand says it can take a
129
+ * click on the plan (`spotClean`). A brand without it - Ounitech, until its
130
+ * pixel frame is verified - gets no control rather than one the server refuses.
131
+ */
132
+ export function canSpotClean(state: {
133
+ online?: unknown;
134
+ dispatchable?: unknown;
135
+ capabilities?: Record<string, unknown> | null;
136
+ } | null | undefined): boolean {
137
+ return canDispatch(state) && state?.capabilities?.spotClean === true;
138
+ }
139
+
140
+ /** Whether the brand can take a spot at all, busy or not - decides if the control exists. */
141
+ export function brandSpotCleans(state: { capabilities?: Record<string, unknown> | null } | null | undefined) {
142
+ return state?.capabilities?.spotClean === true;
143
+ }
144
+
145
+ /** The fault the robot is reporting, in its own words, or null. */
146
+ export function robotFaultText(state: { fault?: { message?: unknown; code?: unknown } | null } | null | undefined): string | null {
147
+ const fault = state?.fault;
148
+ if (!fault) return null;
149
+ const text = typeof fault.message === "string" && fault.message.trim()
150
+ ? fault.message.trim()
151
+ : typeof fault.code === "string" ? fault.code : "";
152
+ return text ? `Fault: ${text}` : null;
153
+ }
154
+
155
+ /**
156
+ * A small square around a clicked pixel, as the polygon a spot command takes.
157
+ *
158
+ * A spot command needs at least three points (a single point encloses
159
+ * nothing). Clamped to the image so a click on the edge stays on the plan.
160
+ */
161
+ export function spotPolygon(
162
+ x: number,
163
+ y: number,
164
+ size: { width: number; height: number },
165
+ half = 10,
166
+ ): Array<{ x: number; y: number }> {
167
+ const cx = (v: number) => Math.round(Math.min(Math.max(v, 0), Math.max(size.width - 1, 0)));
168
+ const cy = (v: number) => Math.round(Math.min(Math.max(v, 0), Math.max(size.height - 1, 0)));
169
+ return [
170
+ { x: cx(x - half), y: cy(y - half) },
171
+ { x: cx(x + half), y: cy(y - half) },
172
+ { x: cx(x + half), y: cy(y + half) },
173
+ { x: cx(x - half), y: cy(y + half) },
174
+ ];
175
+ }
176
+
177
+ const DAY_NAMES = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
178
+
179
+ /**
180
+ * A cleaning schedule, as a person reads it.
181
+ *
182
+ * The vendor's `dateList` is 1-7, Monday first. An unknown day number is
183
+ * dropped rather than shown as a blank - but a plan with NO valid days says so,
184
+ * instead of reading like "every day".
185
+ */
186
+ export function planSummary(plan: Record<string, any> | null | undefined) {
187
+ const days = [...new Set((Array.isArray(plan?.dateList) ? plan!.dateList : [])
188
+ .filter((d: unknown) => Number.isInteger(d) && (d as number) >= 1 && (d as number) <= 7))]
189
+ .sort((a: any, b: any) => a - b) as number[];
190
+
191
+ const dayText =
192
+ days.length === 7 ? "Every day"
193
+ : days.length ? days.map((d) => DAY_NAMES[d - 1]).join(", ")
194
+ : "No days set";
195
+
196
+ const start = typeof plan?.startTime === "string" ? plan.startTime : "";
197
+ const end = typeof plan?.endTime === "string" ? plan.endTime : "";
198
+ const time = start && end ? `${start}–${end}` : start || end || "No time set";
199
+
200
+ const jobs = (Array.isArray(plan?.jobList) ? plan!.jobList : []).map((job: any) => {
201
+ const floor = typeof job?.floorNo === "number" ? `Floor ${job.floorNo}` : "Floor unknown";
202
+ const passes = typeof job?.cleanTimes === "number" ? `${job.cleanTimes} pass${job.cleanTimes === 1 ? "" : "es"}` : "";
203
+ return [floor, passes].filter(Boolean).join(" · ");
204
+ });
205
+
206
+ return {
207
+ days: dayText,
208
+ time,
209
+ enabled: plan?.enableFlag === true || plan?.enableFlag === 1,
210
+ jobs,
211
+ };
212
+ }