@7365admin1/layer-common 4.26.1-staging.355 → 4.28.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.
Files changed (42) hide show
  1. package/CHANGELOG.md +16 -4
  2. package/components/AccessCardAddForm.vue +4 -5
  3. package/components/AccessCardAssignToUnitForm.vue +2 -3
  4. package/components/AccessCardPreviewDialog.vue +3 -4
  5. package/components/Dialog/UpdateMoreAction.vue +1 -11
  6. package/components/DocumentForm.vue +112 -407
  7. package/components/DocumentManagement.vue +12 -213
  8. package/components/EntryPass/QrTemplatePreview.vue +25 -21
  9. package/components/EntryPassInformation.vue +24 -119
  10. package/components/Facility/BookingSetup.vue +0 -63
  11. package/components/HidAccessLogDashboard.vue +5 -29
  12. package/components/HidIntercomManagement.vue +14 -148
  13. package/components/HidReaderManagement.vue +0 -26
  14. package/components/HidReaderUserRoster.vue +2 -32
  15. package/components/HidUserEnrollment.vue +152 -833
  16. package/components/InvitationClientForm.vue +1 -19
  17. package/components/RolePermissionFormCreate.vue +19 -163
  18. package/components/RolePermissionFormPreviewUpdate.vue +19 -230
  19. package/components/RolePermissionMain.vue +0 -19
  20. package/components/VisitorManagement.vue +5 -267
  21. package/composables/useAccessManagement.ts +0 -5
  22. package/composables/useDocument.ts +0 -7
  23. package/composables/useFacility.ts +0 -11
  24. package/composables/useHidAmico.ts +0 -117
  25. package/composables/useHidNavigation.ts +1 -25
  26. package/composables/usePeople.ts +0 -19
  27. package/composables/useSiteEntryPassSettings.ts +0 -26
  28. package/composables/useWebUsb.ts +11 -14
  29. package/package.json +1 -1
  30. package/pages/[org]/[site]/access-mgmt/administrator/index.vue +1 -1
  31. package/pages/[org]/[site]/access-mgmt/hid-cards/index.vue +1 -1
  32. package/pages/[org]/[site]/access-mgmt/hid-readers/index.vue +1 -1
  33. package/types/document.d.ts +0 -14
  34. package/types/facility.d.ts +0 -4
  35. package/types/people.d.ts +1 -28
  36. package/utils/permission-labels.ts +0 -30
  37. package/components/HidAccessPermissions.vue +0 -424
  38. package/components/HidProfileQrCode.vue +0 -323
  39. package/composables/useSiteCategory.ts +0 -45
  40. package/pages/[org]/[site]/access-mgmt/hid-qr-code/index.vue +0 -23
  41. package/utils/hid-permission-assignments.ts +0 -190
  42. package/utils/occupancy-role.ts +0 -109
@@ -27,35 +27,9 @@ 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
-
55
30
  return {
56
31
  getBySiteId,
57
32
  getById,
58
33
  save,
59
- getEncryptedAcmUrl,
60
34
  };
61
35
  }
@@ -345,19 +345,16 @@ export default function useWebUsb() {
345
345
  70,
346
346
  );
347
347
 
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
- });
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, (canvas.width - qrSize) / 2, 90, qrSize, qrSize);
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` produces
408
- * (that one pairs its QR with company, date, access and instruction lines).
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.26.1-staging.355",
5
+ "version": "4.28.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 HID users."
7
7
  >
8
- <HidUserEnrollment :site="siteId" :org="orgId" />
8
+ <HidUserEnrollment :site="siteId" />
9
9
  </HidEnabledGate>
10
10
  </v-container>
11
11
  </template>
@@ -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" :org="orgId" card-management />
8
+ <HidUserEnrollment :site="siteId" card-management />
9
9
  </HidEnabledGate>
10
10
  </v-container>
11
11
  </template>
@@ -5,7 +5,7 @@
5
5
  :org="orgId"
6
6
  message="Enable HID as a service for this site before managing HID readers."
7
7
  >
8
- <HidReaderManagement :site="siteId" :org="orgId" />
8
+ <HidReaderManagement :site="siteId" />
9
9
  </HidEnabledGate>
10
10
  </v-container>
11
11
  </template>
@@ -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
  };
@@ -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
- // `""` 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 | "" }
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"
@@ -98,33 +98,3 @@ 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
- }
@@ -1,424 +0,0 @@
1
- <template>
2
- <v-dialog v-model="open" max-width="760" scrollable>
3
- <v-card class="hid-access-permissions">
4
- <v-card-title class="hid-access-permissions__title">
5
- <div>
6
- <div class="text-h6">Access Permissions</div>
7
- <div class="text-caption text-medium-emphasis">{{ readerLabel }}</div>
8
- </div>
9
- </v-card-title>
10
-
11
- <v-divider />
12
-
13
- <!-- The one precondition the server enforces before it will talk about
14
- permissions at all. Saying it here beats letting the first request
15
- fail with the same sentence in a snackbar. -->
16
- <v-alert
17
- v-if="!readerLocation"
18
- type="warning"
19
- variant="tonal"
20
- density="compact"
21
- class="ma-4"
22
- >
23
- Set a location on this HID Face Reader before managing permissions.
24
- </v-alert>
25
-
26
- <template v-else>
27
- <div class="hid-access-permissions__intro">
28
- <p class="text-body-2 text-medium-emphasis mb-0">
29
- Residents enrolled on this reader. Enrolling already grants access — switch
30
- somebody off to close the door to them without removing their face, card
31
- or PIN.
32
- </p>
33
- </div>
34
-
35
- <v-card-text class="hid-access-permissions__body">
36
- <TableMain
37
- :headers="headers"
38
- :items="rows"
39
- :loading="loading"
40
- :items-per-page="-1"
41
- :page="page"
42
- :pages="pages"
43
- :page-range="pageRange"
44
- item-value="rowKey"
45
- @refresh="loadEnrolled"
46
- @update:page="goToPage"
47
- >
48
- <template #extension>
49
- <div class="app-filter-row">
50
- <AppField
51
- v-model="search"
52
- search
53
- placeholder="Search name, unit or registration"
54
- @keyup.enter="searchFromFirstPage"
55
- />
56
- </div>
57
- </template>
58
-
59
- <template #[`item.name`]="{ item }">
60
- <div class="hid-access-permissions__person">
61
- <div>{{ item.name || "—" }}</div>
62
- <div class="text-caption text-medium-emphasis">{{ item.subtitle || "—" }}</div>
63
- </div>
64
- </template>
65
-
66
- <template #[`item.selected`]="{ item }">
67
- <div v-if="!item.assignable" class="hid-access-permissions__toggle">
68
- <span class="text-caption text-medium-emphasis">{{ item.reason }}</span>
69
- </div>
70
- <div v-else class="hid-access-permissions__toggle">
71
- <v-switch
72
- :model-value="item.selected"
73
- :disabled="saving"
74
- color="primary"
75
- density="compact"
76
- hide-details
77
- :aria-label="`Door access for ${item.name}`"
78
- @update:model-value="(value) => toggle(item, value === true)"
79
- />
80
- <span
81
- class="text-caption"
82
- :class="item.selected ? 'text-success' : 'text-medium-emphasis'"
83
- >
84
- {{ item.selected ? "Has access" : "No access" }}
85
- </span>
86
- </div>
87
- </template>
88
- </TableMain>
89
- </v-card-text>
90
- </template>
91
-
92
- <v-divider />
93
-
94
- <v-card-actions class="hid-access-permissions__actions">
95
- <span v-if="readerLocation" class="text-caption text-medium-emphasis">
96
- {{ assignedTotal }} with access on this reader
97
- </span>
98
- <v-spacer />
99
- <AppButton variant="ghost" :disabled="saving" @click="open = false">Cancel</AppButton>
100
- <AppButton
101
- icon="mdi-content-save-outline"
102
- :loading="saving"
103
- :disabled="!readerLocation || !dirty || saving"
104
- @click="save"
105
- >
106
- Save Permissions
107
- </AppButton>
108
- </v-card-actions>
109
- </v-card>
110
-
111
- <v-snackbar v-model="snackbar.show" :color="snackbar.color" timeout="3500">
112
- {{ snackbar.message }}
113
- </v-snackbar>
114
- </v-dialog>
115
- </template>
116
-
117
- <script setup lang="ts">
118
- import {
119
- applySelection,
120
- hasChanges,
121
- readCandidatePage,
122
- seedAssignments,
123
- setAssignment,
124
- toAssignmentPayload,
125
- type HidAssignmentState,
126
- } from "../utils/hid-permission-assignments";
127
-
128
- /**
129
- * WHO MAY PASS THIS READER — a review and revoke screen, not a picker.
130
- *
131
- * Enrolling somebody now grants them access: `createIdentity` writes the
132
- * assignment, and the reconcile puts them in the reader's group in the same
133
- * pass. A property manager therefore has ONE thing to do, and this screen
134
- * exists for the other direction — taking access away again.
135
- *
136
- * So it lists the people ENROLLED on this reader rather than everybody at the
137
- * site. Switching somebody off removes their assignment, and the reconcile then
138
- * deletes their `user_groups` row; their identity, face, card and PIN are left
139
- * alone, so they stay recognisable at the door and are simply refused.
140
- *
141
- * The editing model lives in `utils/hid-permission-assignments.ts`, because the
142
- * save is whole-reader while the list is one page at a time — and getting that
143
- * wrong silently revokes everybody who is not on screen. See the tests there.
144
- */
145
- const props = defineProps<{
146
- modelValue: boolean;
147
- site: string;
148
- org: string;
149
- reader: Record<string, unknown> | null;
150
- }>();
151
-
152
- const emit = defineEmits<{
153
- (event: "update:modelValue", value: boolean): void;
154
- (event: "saved"): void;
155
- }>();
156
-
157
- const { getSitePermissions, getIdentities, updateSitePermissions } = useHidAmico();
158
-
159
- /* Name over unit in one cell rather than a "Unit" column — see `subtitleOf`. */
160
- const headers = [
161
- { title: "Resident", value: "name", sortable: false },
162
- { title: "Door access", value: "selected", sortable: false, width: 190 },
163
- ];
164
-
165
- const search = ref("");
166
- const page = ref(1);
167
- const pages = ref(1);
168
- const pageRange = ref("");
169
- const loading = ref(false);
170
- const saving = ref(false);
171
- const enrolled = ref<THidPermissionCandidate[]>([]);
172
- const snackbar = reactive({ show: false, color: "success", message: "" });
173
-
174
- /** What the server holds, and the working copy. The pair drives `dirty`. */
175
- const savedState = ref<HidAssignmentState>(new Map());
176
- const draft = ref<HidAssignmentState>(new Map());
177
-
178
- const open = computed({
179
- get: () => props.modelValue,
180
- set: (value: boolean) => emit("update:modelValue", value),
181
- });
182
-
183
- const readerId = computed(() => String(props.reader?._id ?? ""));
184
- const readerLocation = computed(() => String(props.reader?.location ?? "").trim());
185
- const readerLabel = computed(() => {
186
- const name = String(props.reader?.name ?? "").trim() || "HID Face Reader";
187
- return readerLocation.value ? `${name} · ${readerLocation.value}` : name;
188
- });
189
-
190
- const assignedTotal = computed(() => draft.value.size);
191
- const dirty = computed(() => hasChanges(savedState.value, draft.value));
192
- /* The draft is the truth once the dialog is open, so `selected` is recomputed
193
- on every render rather than trusted from the row. */
194
- const rows = computed(() => applySelection(enrolled.value, draft.value));
195
-
196
- watch(
197
- () => [props.modelValue, readerId.value] as const,
198
- ([isOpen]) => {
199
- if (!isOpen || !readerId.value) return;
200
- search.value = "";
201
- page.value = 1;
202
- void loadAll();
203
- },
204
- { immediate: true },
205
- );
206
-
207
- async function loadAll() {
208
- if (!readerLocation.value) return;
209
- await loadAssignments();
210
- await loadEnrolled();
211
- }
212
-
213
- /**
214
- * `getSitePermissions` returns the reader's assignments across ALL categories.
215
- * That is what makes a whole-reader payload possible from a paged view, so it
216
- * is loaded once per opening rather than once per page.
217
- */
218
- async function loadAssignments() {
219
- try {
220
- const response = await getSitePermissions(props.site, props.org, readerId.value);
221
- const assignments = response?.data?.assignments ?? [];
222
- savedState.value = seedAssignments(assignments);
223
- draft.value = seedAssignments(assignments);
224
- } catch (error) {
225
- showToast(getErrorMessage(error, "Unable to load this reader's permissions."), "error");
226
- }
227
- }
228
-
229
- function toRecord(value: unknown): Record<string, unknown> {
230
- return value && typeof value === "object" ? (value as Record<string, unknown>) : {};
231
- }
232
-
233
- /**
234
- * The subject an identity names, in the order `createIdentity` validates them.
235
- *
236
- * A visitor returns null and is left out of the list: visitor access comes from
237
- * `user_access_rules`, not from a group, so there is nothing here to switch
238
- * off. An identity linked to nobody — a device user the reader holds that was
239
- * never tied to a person — is dropped for the same reason.
240
- */
241
- function subjectOf(identity: Record<string, unknown>) {
242
- if (identity.person) {
243
- return { subjectId: String(identity.person), category: "resident" as const };
244
- }
245
- if (identity.member) {
246
- return { subjectId: String(identity.member), category: "property_management" as const };
247
- }
248
- if (identity.serviceProvider) {
249
- return { subjectId: String(identity.serviceProvider), category: "service_provider" as const };
250
- }
251
- return null;
252
- }
253
-
254
- /**
255
- * Why a row cannot be switched, in words the reader of the screen can act on.
256
- *
257
- * The row is still DRAWN. Dropping one silently is what made the pager say
258
- * "1-9 of 9" over seven rows: the count comes from the server and the rows came
259
- * from a filtered list, so people vanished with nothing to say they had.
260
- *
261
- * What lands here is a resident identity holding only an account link - no
262
- * person, member or service-provider record - which leaves no subject to
263
- * assign. Visitors never reach it: they are excluded by the query above,
264
- * because their access comes from `user_access_rules` rather than a group and
265
- * there would be nothing here to switch.
266
- */
267
- function unassignableReason() {
268
- return "Not linked to a person";
269
- }
270
-
271
- /**
272
- * The unit, when the enrolment captured one.
273
- *
274
- * `unitLabel` and NOT `block`/`level`/`unit`: those three hold ObjectIds, and
275
- * the enrolment form resolves them through the occupancy tree before storing
276
- * the readable label beside them. `buildUnitLabel` carries the warning this
277
- * ignored once already — joining the raw values stamps
278
- * "665f.../665f.../665f..." into the column.
279
- *
280
- * Falls back to the registration number, which is what the rows created by an
281
- * assignment rather than an enrolment carry instead of a unit.
282
- */
283
- function subtitleOf(identity: Record<string, unknown>) {
284
- const metadata = toRecord(identity.metadata);
285
- return String(metadata.unitLabel ?? "").trim()
286
- || String(identity.registration ?? "").trim();
287
- }
288
-
289
- async function loadEnrolled() {
290
- if (!readerId.value || !readerLocation.value) return;
291
- loading.value = true;
292
- try {
293
- const response = await getIdentities(readerId.value, {
294
- page: page.value,
295
- limit: 10,
296
- search: search.value.trim(),
297
- // Residents only, and filtered by the SERVER rather than here. The pager's
298
- // count comes back from the same query, so narrowing the list on this side
299
- // would print a total that never matched the rows under it.
300
- type: "resident",
301
- });
302
- const result = readCandidatePage(response);
303
- /*
304
- * EVERY row the server returned, including the ones this screen cannot act
305
- * on. A visitor's access comes from `user_access_rules` rather than a group,
306
- * and an identity linked to nobody has no subject to assign - but both are
307
- * still enrolled on this reader, and the count in the pager counts them. They
308
- * are drawn with the switch disabled and a reason, instead of disappearing.
309
- */
310
- enrolled.value = result.items.map((row) => {
311
- const identity = toRecord(row);
312
- const subject = subjectOf(identity);
313
- const metadata = toRecord(identity.metadata);
314
- return {
315
- subjectId: subject?.subjectId ?? "",
316
- category: subject?.category ?? "resident",
317
- // The row's own key. `subjectId` is empty for the rows below, and two
318
- // empty keys would collapse into one row in the table.
319
- rowKey: String(identity._id ?? identity.hidUserId ?? Math.random()),
320
- assignable: Boolean(subject),
321
- reason: subject ? "" : unassignableReason(),
322
- name: String(metadata.name ?? "").trim()
323
- || String(identity.registration ?? "").trim()
324
- || "—",
325
- subtitle: subtitleOf(identity),
326
- intercom: false,
327
- selected: false,
328
- } as THidPermissionCandidate;
329
- });
330
- // `pages` only. The page number stays whatever the pager set — this
331
- // endpoint's `paginate` never echoes it back, so reading one here pinned
332
- // the screen to page one on every fetch.
333
- pages.value = result.pages;
334
- pageRange.value = result.pageRange;
335
- } catch (error) {
336
- enrolled.value = [];
337
- pages.value = 1;
338
- pageRange.value = "";
339
- showToast(getErrorMessage(error, "Unable to load the people enrolled on this reader."), "error");
340
- } finally {
341
- loading.value = false;
342
- }
343
- }
344
-
345
- function goToPage(value: number) {
346
- page.value = Number(value) || 1;
347
- void loadEnrolled();
348
- }
349
-
350
- function searchFromFirstPage() {
351
- page.value = 1;
352
- void loadEnrolled();
353
- }
354
-
355
- function toggle(item: THidPermissionCandidate, selected: boolean) {
356
- if (!String(item.subjectId ?? "")) return;
357
- draft.value = setAssignment(
358
- draft.value,
359
- savedState.value,
360
- String(item.subjectId ?? ""),
361
- item.category,
362
- selected,
363
- );
364
- }
365
-
366
- async function save() {
367
- if (!dirty.value || saving.value) return;
368
- saving.value = true;
369
- try {
370
- await updateSitePermissions(
371
- props.site,
372
- props.org,
373
- readerId.value,
374
- toAssignmentPayload(draft.value),
375
- );
376
- // The server reconciles the device inside this call: anybody switched off
377
- // loses their `user_groups` row before it returns, so a success here means
378
- // the door has already been updated.
379
- savedState.value = new Map(draft.value);
380
- showToast("HID permissions updated.");
381
- emit("saved");
382
- open.value = false;
383
- } catch (error) {
384
- showToast(getErrorMessage(error, "Unable to update HID permissions."), "error");
385
- } finally {
386
- saving.value = false;
387
- }
388
- }
389
-
390
- function showToast(message: string, color = "success") {
391
- snackbar.message = message;
392
- snackbar.color = color;
393
- snackbar.show = true;
394
- }
395
-
396
- function getErrorMessage(error: unknown, fallback: string) {
397
- const record = toRecord(error);
398
- const data = toRecord(record.data);
399
- return String(data.message ?? "") || String(record.message ?? "") || fallback;
400
- }
401
- </script>
402
-
403
- <style scoped lang="scss">
404
- .hid-access-permissions {
405
- &__title { padding-block: 16px; }
406
-
407
- &__intro { padding: 12px 16px 0; }
408
-
409
- &__body {
410
- padding-top: 8px;
411
- min-height: 320px;
412
- }
413
-
414
- &__actions { padding: 12px 16px; }
415
-
416
- &__person > div:first-child { font-weight: 500; }
417
-
418
- &__toggle {
419
- display: flex;
420
- align-items: center;
421
- gap: 8px;
422
- }
423
- }
424
- </style>