@7365admin1/layer-common 4.16.0 → 4.17.1-staging.330

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 (43) hide show
  1. package/CHANGELOG.md +25 -4
  2. package/components/CameraWallTile.vue +13 -4
  3. package/components/DocumentForm.vue +407 -112
  4. package/components/DocumentManagement.vue +213 -12
  5. package/components/EntryPass/QrTemplatePreview.vue +21 -25
  6. package/components/EntryPassInformation.vue +119 -24
  7. package/components/Facility/BookingSetup.vue +63 -0
  8. package/components/HidAccessPermissions.vue +424 -0
  9. package/components/HidIntercomManagement.vue +193 -43
  10. package/components/HidProfileQrCode.vue +323 -0
  11. package/components/HidReaderManagement.vue +26 -0
  12. package/components/HidReaderUserRoster.vue +32 -2
  13. package/components/HidUserEnrollment.vue +779 -213
  14. package/components/InvitationClientForm.vue +19 -1
  15. package/components/Layout/Header.vue +26 -0
  16. package/components/NotificationBell.vue +321 -0
  17. package/components/VehicleAddSelection.vue +7 -2
  18. package/components/VehicleBulkAddForm.vue +1417 -0
  19. package/components/VehicleManagement.vue +31 -3
  20. package/components/VisitorManagement.vue +267 -5
  21. package/composables/useAccessManagement.ts +5 -0
  22. package/composables/useDocument.ts +7 -0
  23. package/composables/useFacility.ts +11 -0
  24. package/composables/useHidAmico.ts +97 -0
  25. package/composables/useHidNavigation.ts +25 -1
  26. package/composables/useNotification.ts +78 -0
  27. package/composables/usePeople.ts +19 -0
  28. package/composables/useSecurityPermission.ts +8 -7
  29. package/composables/useVehicle.ts +35 -0
  30. package/composables/useWebUsb.ts +14 -11
  31. package/package.json +1 -1
  32. package/pages/[org]/[site]/access-mgmt/administrator/index.vue +1 -1
  33. package/pages/[org]/[site]/access-mgmt/hid-cards/index.vue +1 -1
  34. package/pages/[org]/[site]/access-mgmt/hid-qr-code/index.vue +23 -0
  35. package/pages/[org]/[site]/access-mgmt/hid-readers/index.vue +1 -1
  36. package/types/document.d.ts +14 -0
  37. package/types/facility.d.ts +4 -0
  38. package/types/people.d.ts +4 -1
  39. package/utils/camera-wall.ts +30 -0
  40. package/utils/hid-permission-assignments.ts +190 -0
  41. package/utils/materialSymbols.ts +3 -0
  42. package/utils/vehicle-bulk-rows.ts +584 -0
  43. package/utils/vehicle-bulk-sheet.ts +387 -0
@@ -57,7 +57,24 @@
57
57
  </div>
58
58
  </v-col>
59
59
 
60
- <v-col cols="12" class="mb-2" v-if="isInsideFolder">
60
+ <v-col cols="12">
61
+ <v-tabs
62
+ v-model="activeTab"
63
+ class="doc-tabs"
64
+ density="compact"
65
+ :hide-slider="false"
66
+ >
67
+ <v-tab value="active" class="text-none">Documents</v-tab>
68
+ <v-tab value="expired" class="text-none">Document (Expired)</v-tab>
69
+ </v-tabs>
70
+ </v-col>
71
+
72
+ <!--
73
+ Hidden on the Expired tab: that tab is a site-wide worklist rather than a
74
+ place in the folder tree, so a breadcrumb there would name a folder whose
75
+ contents are not what is on screen.
76
+ -->
77
+ <v-col cols="12" class="mb-2" v-if="isInsideFolder && !isExpiredTab">
61
78
  <div class="folder-path-bar d-flex align-center ga-2 px-3 py-2">
62
79
  <v-btn
63
80
  icon="mdi-arrow-left"
@@ -149,19 +166,79 @@
149
166
  <span>{{ item.date_modified || "N/A" }}</span>
150
167
  </template>
151
168
 
169
+ <template #item.expiry_date="{ item }">
170
+ <span>{{ item.expiry_date || "N/A" }}</span>
171
+ </template>
172
+
152
173
  <template #item.remarks="{ item }">
153
174
  <span>{{ item.remarks || "N/A" }}</span>
154
175
  </template>
155
176
 
156
177
  <template #item.action="{ item }">
157
- <v-btn
158
- v-if="!isFolderItem(item._raw)"
159
- variant="flat"
160
- class="table-download-btn text-none"
161
- @click.stop="downloadDocument(item._raw)"
162
- >
163
- Download
164
- </v-btn>
178
+ <!--
179
+ A document carries its primary action and a kebab beside it. Which
180
+ primary action depends on the tab: an expired document cannot be
181
+ usefully downloaded, it needs replacing, so Download gives way to
182
+ Update there.
183
+ -->
184
+ <template v-if="!isFolderItem(item._raw)">
185
+ <v-btn
186
+ v-if="isExpiredTab"
187
+ variant="flat"
188
+ class="table-download-btn text-none"
189
+ :disabled="!canUpdateDocument"
190
+ @click.stop="openUpdateDialog(item._raw)"
191
+ >
192
+ Update
193
+ </v-btn>
194
+
195
+ <v-btn
196
+ v-else
197
+ variant="flat"
198
+ class="table-download-btn text-none"
199
+ @click.stop="downloadDocument(item._raw)"
200
+ >
201
+ Download
202
+ </v-btn>
203
+
204
+ <v-menu
205
+ v-if="canUpdateDocument || canDeleteDocument"
206
+ v-model="documentActionMenu[item._raw._id]"
207
+ location="bottom end"
208
+ offset="6"
209
+ >
210
+ <template #activator="{ props }">
211
+ <v-btn
212
+ v-bind="props"
213
+ icon="mdi-dots-vertical"
214
+ variant="text"
215
+ size="small"
216
+ density="comfortable"
217
+ class="folder-action-btn"
218
+ @click.stop
219
+ />
220
+ </template>
221
+
222
+ <v-list class="folder-action-list pa-0">
223
+ <v-list-item
224
+ v-if="canUpdateDocument"
225
+ class="folder-action-item"
226
+ @click.stop="openDocumentEdit(item._raw)"
227
+ >
228
+ <v-list-item-title class="text-body-2">Edit</v-list-item-title>
229
+ </v-list-item>
230
+ <v-list-item
231
+ v-if="canDeleteDocument"
232
+ class="folder-action-item"
233
+ @click.stop="openDocumentDelete(item._raw)"
234
+ >
235
+ <v-list-item-title class="text-body-2">
236
+ Delete
237
+ </v-list-item-title>
238
+ </v-list-item>
239
+ </v-list>
240
+ </v-menu>
241
+ </template>
165
242
 
166
243
  <v-menu
167
244
  v-else
@@ -200,8 +277,11 @@
200
277
  </TableV3>
201
278
  </v-col>
202
279
 
203
- <!-- Create Dialog -->
204
- <v-dialog v-model="createDialog" width="450" persistent>
280
+ <!--
281
+ Wider than the other dialogs because Add Document holds a five-column
282
+ table, one row per file, rather than a stacked pair of fields.
283
+ -->
284
+ <v-dialog v-model="createDialog" max-width="1100" persistent>
205
285
  <DocumentForm
206
286
  v-if="createDialog"
207
287
  :parent-id="activeParentId"
@@ -210,6 +290,17 @@
210
290
  />
211
291
  </v-dialog>
212
292
 
293
+ <!-- Update Dialog: renew an expired document by replacing its file. -->
294
+ <v-dialog v-model="updateDialog" max-width="1100" persistent>
295
+ <DocumentForm
296
+ v-if="updateDialog"
297
+ mode="update"
298
+ :document="selectedDocument"
299
+ @cancel="updateDialog = false"
300
+ @success="successRenew()"
301
+ />
302
+ </v-dialog>
303
+
213
304
  <!-- Create Folder Dialog -->
214
305
  <v-dialog v-model="createFolderDialog" width="450" persistent>
215
306
  <v-card width="100%">
@@ -484,6 +575,15 @@
484
575
  </v-row>
485
576
  </v-col>
486
577
 
578
+ <v-col cols="12" class="mb-2">
579
+ <v-row no-gutters>
580
+ <v-col cols="6" class="text-body-1">Expiry Date</v-col>
581
+ <v-col cols="6" class="text-right text-body-1">{{
582
+ previewDetails.expiryDate
583
+ }}</v-col>
584
+ </v-row>
585
+ </v-col>
586
+
487
587
  <v-col cols="12">
488
588
  <v-row no-gutters>
489
589
  <v-col cols="6" class="text-body-1">Remarks</v-col>
@@ -634,6 +734,10 @@ const props = defineProps({
634
734
  title: "Date Modified",
635
735
  value: "date_modified",
636
736
  },
737
+ {
738
+ title: "Expiry Date",
739
+ value: "expiry_date",
740
+ },
637
741
  {
638
742
  title: "Remarks",
639
743
  value: "remarks",
@@ -733,6 +837,13 @@ const currentFolderPath = computed(() => {
733
837
  const fileTypes = ref(["all", "pdf", "csv", "doc"]);
734
838
  const selectedFileType = ref("all");
735
839
 
840
+ /**
841
+ * Which half of the list is on screen. The value is sent straight to the API as
842
+ * its `expiry` filter, so the tab and the query cannot drift apart.
843
+ */
844
+ const activeTab = ref<"active" | "expired">("active");
845
+ const isExpiredTab = computed(() => activeTab.value === "expired");
846
+
736
847
  const {
737
848
  data: getDocumentReq,
738
849
  refresh: getDocuments,
@@ -748,12 +859,20 @@ const {
748
859
  parentId: activeParentId.value,
749
860
  type:
750
861
  selectedFileType.value === "all" ? undefined : selectedFileType.value,
862
+ expiry: activeTab.value,
751
863
  }),
752
864
  {
753
- watch: [page, headerSearch, activeParentId, selectedFileType],
865
+ watch: [page, headerSearch, activeParentId, selectedFileType, activeTab],
754
866
  }
755
867
  );
756
868
 
869
+ // Page 3 of the Documents tab is rarely page 3 of a much shorter Expired list,
870
+ // so a tab change that kept the page number would land on an empty table that
871
+ // looks like "nothing has expired".
872
+ watch(activeTab, () => {
873
+ page.value = 1;
874
+ });
875
+
757
876
  const loading = computed(() => getAllReqStatus.value === "pending");
758
877
 
759
878
  // The page totals are the server's count of the WHOLE list, read through the
@@ -788,6 +907,28 @@ function formatDate(value?: string | null) {
788
907
  });
789
908
  }
790
909
 
910
+ /**
911
+ * Expiry is a day, not a moment: the picker collects `YYYY-MM-DD` and the
912
+ * design renders `13/12/2026`. Reusing `formatDate` would append a meaningless
913
+ * 00:00 to every row.
914
+ */
915
+ function formatDateOnly(value?: string | null) {
916
+ if (!value) {
917
+ return "N/A";
918
+ }
919
+
920
+ const dateValue = new Date(value);
921
+ if (Number.isNaN(dateValue.getTime())) {
922
+ return "N/A";
923
+ }
924
+
925
+ return dateValue.toLocaleDateString("en-SG", {
926
+ year: "numeric",
927
+ month: "2-digit",
928
+ day: "2-digit",
929
+ });
930
+ }
931
+
791
932
  function formatBytes(bytes = 0) {
792
933
  const b = Number(bytes) || 0;
793
934
  if (b === 0) return "0 B";
@@ -823,13 +964,20 @@ const tableItems = computed(() => {
823
964
  : formatBytes(Number(doc.file_size ?? doc.size ?? 0)),
824
965
  date_created: formatDate(doc.created_at || doc.createdAt),
825
966
  date_modified: formatDate(doc.updated_at || doc.updatedAt),
967
+ // Folders never expire, so they read N/A rather than borrowing a date.
968
+ expiry_date:
969
+ doc.type === "folder"
970
+ ? "N/A"
971
+ : formatDateOnly(doc.expiry_date || doc.expiryDate),
826
972
  remarks: doc.remarks || "N/A",
827
973
  }));
828
974
  });
829
975
 
830
976
  const createDialog = ref(false);
831
977
  const editDialog = ref(false);
978
+ const updateDialog = ref(false);
832
979
  const previewDialog = ref(false);
980
+ const documentActionMenu = ref<Record<string, boolean>>({});
833
981
 
834
982
  // Create folder dialog state
835
983
  const createFolderDialog = ref(false);
@@ -880,6 +1028,10 @@ const previewDetails = computed(() => {
880
1028
  fileSize,
881
1029
  dateCreated: formatDate(document?.created_at || document?.createdAt),
882
1030
  dateModified: formatDate(document?.updated_at || document?.updatedAt),
1031
+ expiryDate:
1032
+ document?.type === "folder"
1033
+ ? "N/A"
1034
+ : formatDateOnly(document?.expiry_date || document?.expiryDate),
883
1035
  remarks: document?.remarks || "N/A",
884
1036
  };
885
1037
  });
@@ -1151,6 +1303,29 @@ function openDeleteDialog() {
1151
1303
  message.value = "";
1152
1304
  }
1153
1305
 
1306
+ /*
1307
+ * The three row-kebab entry points. Each names its document first: the dialogs
1308
+ * below all read `selectedDocument`, which until now was only ever set by
1309
+ * opening the detail modal, so firing one straight from a row without setting
1310
+ * it would have acted on whichever document was inspected last.
1311
+ */
1312
+ function openDocumentEdit(document: TDocument) {
1313
+ selectedDocument.value = document;
1314
+ documentActionMenu.value = {};
1315
+ editDialog.value = true;
1316
+ }
1317
+
1318
+ function openDocumentDelete(document: TDocument) {
1319
+ selectedDocument.value = document;
1320
+ documentActionMenu.value = {};
1321
+ openDeleteDialog();
1322
+ }
1323
+
1324
+ function openUpdateDialog(document: TDocument) {
1325
+ selectedDocument.value = document;
1326
+ updateDialog.value = true;
1327
+ }
1328
+
1154
1329
  function openEditDialog() {
1155
1330
  editDialog.value = true;
1156
1331
  }
@@ -1179,6 +1354,19 @@ function successUpdate() {
1179
1354
  showMessage("Document updated successfully!", "success");
1180
1355
  }
1181
1356
 
1357
+ /**
1358
+ * A renewal usually moves the document off the tab it was renewed from, so the
1359
+ * refresh is what makes it disappear from the Expired list. A renewal that did
1360
+ * not move the expiry date forward stays put, which is the intended behaviour
1361
+ * rather than a failed save - hence the neutral wording.
1362
+ */
1363
+ function successRenew() {
1364
+ updateDialog.value = false;
1365
+ previewDialog.value = false;
1366
+ getDocuments();
1367
+ showMessage("Document updated successfully!", "success");
1368
+ }
1369
+
1182
1370
  function selectFileType(type: string) {
1183
1371
  selectedFileType.value = type;
1184
1372
  filterMenu.value = false;
@@ -1203,6 +1391,19 @@ function selectFileType(type: string) {
1203
1391
  color: var(--text);
1204
1392
  }
1205
1393
 
1394
+ /* The tab strip sits on the table card, so it takes the card's rule rather
1395
+ than Vuetify's default underline, and the cell type rather than the button
1396
+ scale - the same treatment the toolbar above it already gets. */
1397
+ .doc-tabs {
1398
+ border-bottom: 1px solid var(--border);
1399
+ }
1400
+
1401
+ .doc-tabs :deep(.v-tab) {
1402
+ font-size: var(--fs-cell);
1403
+ letter-spacing: normal;
1404
+ min-width: 0;
1405
+ }
1406
+
1206
1407
  .table-download-btn {
1207
1408
  min-width: 106px;
1208
1409
  height: 30px;
@@ -32,28 +32,18 @@
32
32
  </v-col>
33
33
 
34
34
  <v-col cols="12" class="mt-5">
35
- <!-- UPPER QR -->
36
- <v-row no-gutters>
37
- <v-col cols="6">
38
- <img v-if="qrSmall" :src="qrSmall" width="80" height="80" />
39
- </v-col>
40
- <v-col cols="6">
41
- <img v-if="qrSmall" :src="qrSmall" width="80" height="80" />
42
- </v-col>
43
- </v-row>
44
-
45
- <!-- CENTER QR -->
46
- <img v-if="qrLarge" :src="qrLarge" width="130" height="130" class="my-2" />
47
-
48
- <!-- LOWER QR -->
49
- <v-row no-gutters>
50
- <v-col cols="6">
51
- <img v-if="qrSmall" :src="qrSmall" width="80" height="80" />
52
- </v-col>
53
- <v-col cols="6">
54
- <img v-if="qrSmall" :src="qrSmall" width="80" height="80" />
55
- </v-col>
56
- </v-row>
35
+ <!-- The pass used to print five QRs - four 80px copies at the
36
+ corners around a 130px centre one - so a strip could be cut
37
+ apart. It now carries a single large QR, matching what
38
+ `createReceiptLayout` sends to the thermal printer. -->
39
+ <img
40
+ v-if="qrLarge"
41
+ :src="qrLarge"
42
+ width="260"
43
+ height="260"
44
+ class="qr-preview__code my-2"
45
+ alt="Entry pass QR code"
46
+ />
57
47
  </v-col>
58
48
 
59
49
  <v-col cols="12" class="mt-5">
@@ -90,12 +80,11 @@ defineProps({
90
80
 
91
81
  const emit = defineEmits(["update:modelValue"]);
92
82
 
93
- const qrSmall = ref<string>("");
94
83
  const qrLarge = ref<string>("");
95
84
 
96
85
  onMounted(async () => {
97
- qrSmall.value = await QRCode.toDataURL("123123", { width: 80, margin: 1 });
98
- qrLarge.value = await QRCode.toDataURL("123123", { width: 130, margin: 1 });
86
+ // Rendered at the size it is displayed at, so the modules stay crisp.
87
+ qrLarge.value = await QRCode.toDataURL("123123", { width: 260, margin: 1 });
99
88
  });
100
89
 
101
90
  const now = new Date();
@@ -112,4 +101,11 @@ const timeStr = now.toLocaleTimeString();
112
101
  font-weight: var(--fw-card-title);
113
102
  color: var(--text);
114
103
  }
104
+
105
+ /* The dialog is 550px wide but narrows on small screens, so the QR is capped
106
+ at its own width rather than a fixed 260px that would overflow the card. */
107
+ .qr-preview__code {
108
+ max-width: 100%;
109
+ height: auto;
110
+ }
115
111
  </style>
@@ -99,10 +99,18 @@
99
99
  <template v-if="passType === 'NFC'">
100
100
  <div class="mt-3">
101
101
  <InputLabel title="Select Cards" />
102
- <v-select
102
+ <!-- Was a `v-select` over the first 100 cards, which only lets the
103
+ operator scroll. Typing now goes to the endpoint as `search`
104
+ (debounced, page 1), and reaching the end of the list fetches
105
+ the next page. Vuetify's own client-side match on `cardNo` is
106
+ left on as well: API-core does not read `search` yet, so until
107
+ it does that is what makes typing narrow the list. -->
108
+ <v-autocomplete
103
109
  v-model="selectedCards"
110
+ v-model:search="cardSearch"
104
111
  :items="filteredCardItems"
105
112
  :loading="cardsLoading"
113
+ :hide-no-data="false"
106
114
  item-title="cardNo"
107
115
  item-value="_id"
108
116
  density="comfortable"
@@ -110,10 +118,30 @@
110
118
  chips
111
119
  closable-chips
112
120
  hide-details
113
- placeholder="Select cards..."
121
+ placeholder="Search or select cards..."
114
122
  return-object
123
+ @update:model-value="cardSearch = ''"
115
124
  >
116
- </v-select>
125
+ <template #append-item>
126
+ <!-- Sentinel for infinite scroll. Keyed on the page so it
127
+ re-mounts after each append: an IntersectionObserver only
128
+ reports changes, so a sentinel that stays in view after a
129
+ short page would otherwise never fire again. -->
130
+ <div
131
+ v-if="cardHasMore"
132
+ :key="cardPage"
133
+ v-intersect="onCardListEndReached"
134
+ class="d-flex justify-center py-2"
135
+ >
136
+ <v-progress-circular
137
+ v-if="cardsLoadingMore"
138
+ indeterminate
139
+ size="20"
140
+ width="2"
141
+ />
142
+ </div>
143
+ </template>
144
+ </v-autocomplete>
117
145
  </div>
118
146
 
119
147
  <div class="mt-3">
@@ -322,6 +350,7 @@ const props = defineProps({
322
350
  const emit = defineEmits(["update:modelValue", "update:quantity", "update:cards", "update:availableQrCount"]);
323
351
 
324
352
  const { getAvailableContractorCards, generateQrVms } = useAccessManagement();
353
+ const { debounce } = useUtils();
325
354
 
326
355
  const nfcEnabled = computed(() => props.settings?.data?.settings?.nfcPass ?? false);
327
356
  const hidQrCodeEnabled = computed(() => {
@@ -367,21 +396,53 @@ const filteredCardItems = computed(() =>
367
396
  : cardItems.value
368
397
  );
369
398
  const cardsLoading = ref(false);
399
+ const cardsLoadingMore = ref(false);
400
+ // Typed text in the card picker. Reset after each pick so the next search
401
+ // starts from the full list instead of staying narrowed to the last term.
402
+ const cardSearch = ref("");
403
+ const CARD_PAGE_SIZE = 100;
404
+ const cardPage = ref(1);
405
+ const cardHasMore = ref(false);
406
+ // Bumped on every request. A response whose number is no longer current is
407
+ // dropped, so a slow page-1 search cannot overwrite a newer one and a
408
+ // load-more cannot append onto a list that has since been replaced.
409
+ let cardRequestSeq = 0;
370
410
  const generating = ref(false);
371
411
  const availableCount = ref<number | null>(null);
372
412
 
373
- async function fetchCards(type: "NFC" | "QRCODE" = "NFC") {
413
+ // The picker is NFC-only (see the template's `v-if`), so only NFC fetches
414
+ // carry the search term and only NFC reacts to typing. The QR path keeps
415
+ // its page-1, no-search fetch and its top-up generation untouched.
416
+ const cardFetchType = computed<"NFC" | "QRCODE" | null>(() =>
417
+ passType.value === "NFC" ? "NFC" : passType.value === "QR" ? "QRCODE" : null,
418
+ );
419
+
420
+ async function fetchCards(
421
+ type: "NFC" | "QRCODE" = "NFC",
422
+ opts: { page?: number; append?: boolean } = {},
423
+ ) {
374
424
  if (!props.siteId || !props.unitId) return;
375
- cardsLoading.value = true;
425
+ const page = opts.page ?? 1;
426
+ const append = opts.append === true;
427
+ const seq = ++cardRequestSeq;
428
+ const query = {
429
+ type,
430
+ siteId: props.siteId,
431
+ unitId: props.unitId,
432
+ page,
433
+ limit: CARD_PAGE_SIZE,
434
+ // Vuetify writes null into the search model when it clears the field.
435
+ search: type === "NFC" ? cardSearch.value ?? "" : undefined,
436
+ };
437
+
438
+ if (append) cardsLoadingMore.value = true;
439
+ else cardsLoading.value = true;
376
440
  if (type === "QRCODE") emit("update:availableQrCount", null);
377
441
  try {
378
- const res = await getAvailableContractorCards({
379
- type,
380
- siteId: props.siteId,
381
- unitId: props.unitId,
382
- });
383
- cardItems.value = res?.data?.[0]?.items ?? [];
384
- availableCount.value = (res?.data?.[2] as any)?.count ?? cardItems.value.length;
442
+ const res = await getAvailableContractorCards(query);
443
+ if (seq !== cardRequestSeq) return;
444
+ let items: any[] = res?.data?.[0]?.items ?? [];
445
+ availableCount.value = (res?.data?.[2] as any)?.count ?? items.length;
385
446
 
386
447
  if (type === "QRCODE" && props.settings?.data?._id && availableCount.value !== null && availableCount.value > 0 && availableCount.value < 50) {
387
448
  cardsLoading.value = false;
@@ -392,30 +453,64 @@ async function fetchCards(type: "NFC" | "QRCODE" = "NFC") {
392
453
  quantity: 50,
393
454
  });
394
455
  // Re-fetch to get the updated count after generation
395
- const refreshed = await getAvailableContractorCards({
396
- type,
397
- siteId: props.siteId,
398
- unitId: props.unitId,
399
- });
400
- cardItems.value = refreshed?.data?.[0]?.items ?? [];
401
- availableCount.value = (refreshed?.data?.[2] as any)?.count ?? cardItems.value.length;
456
+ const refreshed = await getAvailableContractorCards(query);
457
+ if (seq !== cardRequestSeq) return;
458
+ items = refreshed?.data?.[0]?.items ?? [];
459
+ availableCount.value = (refreshed?.data?.[2] as any)?.count ?? items.length;
402
460
  generating.value = false;
403
461
  }
404
462
 
463
+ cardItems.value = append ? [...cardItems.value, ...items] : items;
464
+ cardPage.value = page;
465
+ // A short page is the last one. An exact multiple of the page size costs
466
+ // one extra, empty fetch, which then turns this off.
467
+ cardHasMore.value = items.length === CARD_PAGE_SIZE;
468
+
405
469
  if (type === "QRCODE") emit("update:availableQrCount", availableCount.value);
406
470
  } catch (err: any) {
471
+ if (seq !== cardRequestSeq) return;
407
472
  const msg = err?.data?.message ?? err?.message ?? String(err);
408
473
  showSnackbar(`Entry pass service error: ${msg}`);
409
- availableCount.value = null;
410
- cardItems.value = [];
411
474
  generating.value = false;
412
- if (type === "QRCODE") emit("update:availableQrCount", null);
475
+ // A failed load-more keeps what is already listed; a failed first page
476
+ // clears the list as before.
477
+ if (!append) {
478
+ availableCount.value = null;
479
+ cardItems.value = [];
480
+ cardHasMore.value = false;
481
+ if (type === "QRCODE") emit("update:availableQrCount", null);
482
+ }
413
483
  } finally {
414
- cardsLoading.value = false;
415
- generating.value = false;
484
+ // Only the request that is still current may clear the flags; a stale
485
+ // one finishing late must not switch off a newer request's spinner.
486
+ if (seq === cardRequestSeq) {
487
+ cardsLoading.value = false;
488
+ cardsLoadingMore.value = false;
489
+ generating.value = false;
490
+ }
416
491
  }
417
492
  }
418
493
 
494
+ function onCardListEndReached(isIntersecting: boolean) {
495
+ if (!isIntersecting || !cardHasMore.value) return;
496
+ if (cardsLoading.value || cardsLoadingMore.value) return;
497
+ const type = cardFetchType.value;
498
+ if (!type) return;
499
+ fetchCards(type, { page: cardPage.value + 1, append: true });
500
+ }
501
+
502
+ const searchCards = debounce(() => {
503
+ if (cardFetchType.value !== "NFC") return;
504
+ fetchCards("NFC");
505
+ }, 500);
506
+
507
+ // Vuetify hands back null when it clears the field, and re-sets "" on blur;
508
+ // only a real change of the trimmed term should cost a request.
509
+ watch(cardSearch, (val, old) => {
510
+ if ((val ?? "").trim() === (old ?? "").trim()) return;
511
+ searchCards();
512
+ });
513
+
419
514
  function addCard(card: any) {
420
515
  const already = selectedCards.value.some((c) => c._id === card._id);
421
516
  if (!already) selectedCards.value = [...selectedCards.value, card];
@@ -482,6 +482,55 @@
482
482
  </draggable>
483
483
  </section>
484
484
 
485
+ <!-- RESIDENT CHECKLISTS -->
486
+ <v-col cols="12" class="mt-4 border-t">
487
+ <v-row align="center" no-gutters class="pt-5">
488
+ <v-col cols="9" class="d-flex align-center text-body-2">
489
+ <v-row no-gutters>
490
+ <v-col cols="12" class="header-style">
491
+ Resident Checklists
492
+ </v-col>
493
+ <v-col cols="12" class="text-body-2 text-medium-emphasis">
494
+ Allow residents to view and complete assigned checklists. Each
495
+ checklist requires a photo upload before submission.
496
+ </v-col>
497
+ </v-row>
498
+ </v-col>
499
+ <v-col cols="3" class="d-flex align-center justify-end">
500
+ <v-switch
501
+ v-model="facility.isResidentChecklistEnabled"
502
+ class="d-flex align-center"
503
+ color="accent"
504
+ hide-details
505
+ @update:model-value="onToggleResidentChecklist"
506
+ />
507
+ </v-col>
508
+ </v-row>
509
+
510
+ <!-- SECURITY CHECKLISTS -->
511
+ <v-row align="center" no-gutters class="border-t pt-5 mt-5">
512
+ <v-col cols="9" class="d-flex align-center text-body-2">
513
+ <v-row no-gutters>
514
+ <v-col cols="12" class="header-style">
515
+ Security Checklists
516
+ </v-col>
517
+ <v-col cols="12" class="text-body-2 text-medium-emphasis">
518
+ Allow Security to view and complete assigned checklists
519
+ </v-col>
520
+ </v-row>
521
+ </v-col>
522
+ <v-col cols="3" class="d-flex align-center justify-end">
523
+ <v-switch
524
+ v-model="facility.isSecurityChecklistEnabled"
525
+ class="d-flex align-center"
526
+ color="accent"
527
+ hide-details
528
+ @update:model-value="onToggleSecurityChecklist"
529
+ />
530
+ </v-col>
531
+ </v-row>
532
+ </v-col>
533
+
485
534
  <v-col cols="12" class="mt-10">
486
535
  <p class="header-style font-weight-bold mb-5 mt-md-0 ml-md-4">
487
536
  Other Settings
@@ -1020,6 +1069,20 @@ watchEffect(() => {
1020
1069
  }
1021
1070
  });
1022
1071
 
1072
+ /**
1073
+ * One checklist, one owner, and always one. A facility is completed either by
1074
+ * its residents or by Security, so the two switches are each other's inverse:
1075
+ * turning either off turns the other on. There is no state where a facility
1076
+ * has no checklist owner.
1077
+ */
1078
+ function onToggleResidentChecklist(enabled: boolean | null) {
1079
+ facility.value.isSecurityChecklistEnabled = !enabled;
1080
+ }
1081
+
1082
+ function onToggleSecurityChecklist(enabled: boolean | null) {
1083
+ facility.value.isResidentChecklistEnabled = !enabled;
1084
+ }
1085
+
1023
1086
  function onToggleBookingUnitLimit(val: any) {
1024
1087
  if (val) {
1025
1088
  isBookingUnitLimitEnabled.value = true;