@7365admin1/layer-common 4.35.0 → 4.35.1-staging.371

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 (48) hide show
  1. package/CHANGELOG.md +4 -4
  2. package/assets/css/robot-hero.css +40 -3
  3. package/components/AccessCardAddForm.vue +5 -4
  4. package/components/AccessCardAssignToUnitForm.vue +3 -2
  5. package/components/AccessCardPreviewDialog.vue +4 -3
  6. package/components/Dialog/UpdateMoreAction.vue +11 -1
  7. package/components/DocumentForm.vue +407 -112
  8. package/components/DocumentManagement.vue +213 -12
  9. package/components/EntryPass/QrTemplatePreview.vue +21 -25
  10. package/components/EntryPassInformation.vue +119 -24
  11. package/components/Facility/BookingSetup.vue +63 -0
  12. package/components/HidAccessLogDashboard.vue +41 -8
  13. package/components/HidAccessPermissions.vue +424 -0
  14. package/components/HidIntercomManagement.vue +148 -14
  15. package/components/HidProfileQrCode.vue +332 -0
  16. package/components/HidQrCodeConfiguration.vue +17 -195
  17. package/components/HidReaderManagement.vue +306 -0
  18. package/components/HidReaderUserRoster.vue +44 -3
  19. package/components/HidUserEnrollment.vue +845 -155
  20. package/components/InvitationClientForm.vue +19 -1
  21. package/components/Robot/MapEditor.vue +313 -56
  22. package/components/VisitorForm.vue +12 -0
  23. package/components/VisitorManagement.vue +267 -5
  24. package/composables/useAccessManagement.ts +5 -0
  25. package/composables/useDocument.ts +7 -0
  26. package/composables/useFacility.ts +11 -0
  27. package/composables/useHidAmico.ts +134 -0
  28. package/composables/useHidNavigation.ts +25 -1
  29. package/composables/useHidReaderSelection.ts +50 -0
  30. package/composables/usePeople.ts +19 -0
  31. package/composables/usePropertyPermission.ts +17 -0
  32. package/composables/useSecurityPermission.ts +19 -0
  33. package/composables/useSiteCategory.ts +45 -0
  34. package/composables/useSiteEntryPassSettings.ts +26 -0
  35. package/composables/useWebUsb.ts +14 -11
  36. package/package.json +1 -1
  37. package/pages/[org]/[site]/access-mgmt/administrator/index.vue +1 -1
  38. package/pages/[org]/[site]/access-mgmt/hid-cards/index.vue +1 -1
  39. package/pages/[org]/[site]/access-mgmt/hid-qr-code/index.vue +23 -0
  40. package/pages/[org]/[site]/access-mgmt/hid-readers/index.vue +1 -1
  41. package/plugins/API.ts +11 -0
  42. package/types/document.d.ts +14 -0
  43. package/types/facility.d.ts +4 -0
  44. package/types/people.d.ts +28 -1
  45. package/utils/hid-permission-assignments.ts +190 -0
  46. package/utils/hid-reader-selection.ts +52 -0
  47. package/utils/occupancy-role.ts +109 -0
  48. package/utils/robot-building.ts +472 -36
@@ -21,33 +21,6 @@
21
21
  <div class="config-body">
22
22
  <div class="section-label config-body__title">HID Configuration</div>
23
23
 
24
- <div class="form-section identification-section">
25
- <div class="section-label">Enable/disable reader identification method</div>
26
- <p class="section-description">
27
- Toggles multi-factor access methods, allowing users to authenticate via biometric, physical card, or credential inputs.
28
- </p>
29
- <div class="methods-grid">
30
- <div
31
- v-for="method in identificationMethodOptions"
32
- :key="method.key"
33
- class="method-control"
34
- >
35
- <span>{{ method.label }}</span>
36
- <v-switch
37
- v-model="form.identificationMethods[method.key]"
38
- class="app-switch"
39
- hide-details
40
- density="compact"
41
- :loading="savingSection === `method-${method.key}`"
42
- :disabled="Boolean(savingSection) || !form.readerId"
43
- @update:model-value="saveIdentificationMethod(method.key)"
44
- />
45
- </div>
46
- </div>
47
- </div>
48
-
49
- <v-divider />
50
-
51
24
  <div class="form-section">
52
25
  <div class="section-label">Printer Setup</div>
53
26
  <div class="printer-grid">
@@ -224,14 +197,11 @@
224
197
 
225
198
 
226
199
  <script setup lang="ts">
227
- type HidIdentificationMethod = keyof NonNullable<THidQrCodePassConfig["identificationMethods"]>;
228
-
229
200
  type HidQrConfig = Omit<
230
201
  THidQrCodePassConfig,
231
202
  "identificationMethods" | "onlineMode" | "updatedAt" | "qrGatePermissions"
232
203
  > & {
233
204
  onlineMode: boolean;
234
- identificationMethods: Record<HidIdentificationMethod, boolean>;
235
205
  qrGatePermissions: {
236
206
  resident: string[];
237
207
  propertyManagement: string[];
@@ -265,11 +235,7 @@ const runtimeConfig = useRuntimeConfig();
265
235
  const isPermissionManager = computed(() => runtimeConfig.public.APP === "security_agency");
266
236
 
267
237
  const { getSiteById, updateSitebyId } = useSiteSettings();
268
- const {
269
- getReaders,
270
- getReaderConfiguration,
271
- setReaderConfiguration,
272
- } = useHidAmico();
238
+ const { getReaders } = useHidAmico();
273
239
  const {
274
240
  requestDevice: requestPrinterDevice,
275
241
  testConnection: testPrinterConnection,
@@ -284,14 +250,6 @@ const defaultConfig: HidQrConfig = {
284
250
  propertyManagement: [],
285
251
  },
286
252
  qrFormat: "0",
287
- identificationMethods: {
288
- facial: true,
289
- card: true,
290
- qrCode: false,
291
- idPassword: true,
292
- pin: false,
293
- bluetooth: false,
294
- },
295
253
  printer: {
296
254
  vendorId: "",
297
255
  productId: "",
@@ -321,16 +279,6 @@ const visitorQrGateOptions = computed(() => readers.value
321
279
  title: String(reader.name || reader.deviceId || reader._id) + " - " + String(reader.portalName || "Portal"),
322
280
  value: reader._id,
323
281
  })));
324
- const identificationMethodOptions: Array<{
325
- key: HidIdentificationMethod;
326
- label: string;
327
- }> = [
328
- { key: "facial", label: "Facial" },
329
- { key: "card", label: "Card" },
330
- { key: "qrCode", label: "QR Code" },
331
- { key: "idPassword", label: "ID Password" },
332
- { key: "pin", label: "PIN" },
333
- ];
334
282
  const siteName = computed(() => siteData.value?.name || "Site");
335
283
  const siteLabel = computed(() => siteData.value?.code || siteData.value?.block || props.site);
336
284
  const primaryQrGateReaderId = computed(() => (
@@ -371,7 +319,6 @@ async function loadConfig() {
371
319
  const readerList = readerResponse as HidReaderListResponse;
372
320
  readers.value = readerList.items ?? readerList.data?.items ?? readerList.data?.readers ?? [];
373
321
  const config = siteData.value?.metadata?.hidQrCodePass || {};
374
- const configuredMethods = config.identificationMethods;
375
322
  Object.assign(form, {
376
323
  enabled: Boolean(config.enabled),
377
324
  // Visitor QR is reader-local. Do not restore a legacy Online Mode value
@@ -392,14 +339,6 @@ async function loadConfig() {
392
339
  || "",
393
340
  ),
394
341
  qrFormat: "0",
395
- identificationMethods: {
396
- facial: configuredMethods?.facial ?? true,
397
- card: configuredMethods?.card ?? true,
398
- qrCode: configuredMethods?.qrCode ?? Boolean(config.enabled),
399
- idPassword: configuredMethods?.idPassword ?? true,
400
- pin: configuredMethods?.pin ?? false,
401
- bluetooth: false,
402
- },
403
342
  printer: {
404
343
  vendorId: String(config.printer?.vendorId || ""),
405
344
  productId: String(config.printer?.productId || ""),
@@ -410,57 +349,25 @@ async function loadConfig() {
410
349
  },
411
350
  validityMinutes: config.validityMinutes ? Number(config.validityMinutes) : null,
412
351
  });
413
-
414
- await loadReaderConfiguration();
415
- }
416
-
417
- function isUnknownRecord(value: unknown): value is Record<string, unknown> {
418
- return Boolean(value) && typeof value === "object" && !Array.isArray(value);
419
- }
420
-
421
- function getConfigurationData(response: unknown) {
422
- if (!isUnknownRecord(response)) return {};
423
- return isUnknownRecord(response.data) ? response.data : response;
424
- }
425
-
426
- function isEnabledConfiguration(value: unknown) {
427
- return value === true || value === 1 || value === "1";
428
- }
429
-
430
- async function loadReaderConfiguration() {
431
- if (!form.readerId) return;
432
-
433
- try {
434
- const response = await getReaderConfiguration(form.readerId, {
435
- identifier: [
436
- "card_identification_enabled",
437
- "pin_identification_enabled",
438
- "multi_factor_authentication",
439
- ],
440
- });
441
- const configuration = getConfigurationData(response);
442
- const identifier = isUnknownRecord(configuration.identifier) ? configuration.identifier : {};
443
-
444
- if (identifier.pin_identification_enabled !== undefined) {
445
- const pinEnabled = isEnabledConfiguration(identifier.pin_identification_enabled);
446
- form.identificationMethods.pin = pinEnabled;
447
- form.identificationMethods.idPassword = !pinEnabled;
448
- }
449
- if (identifier.card_identification_enabled !== undefined) {
450
- form.identificationMethods.card = isEnabledConfiguration(
451
- identifier.card_identification_enabled,
452
- );
453
- }
454
- } catch (error: unknown) {
455
- console.warn("Unable to load HID reader configuration:", errorConverter(error));
456
- }
457
352
  }
458
353
 
459
354
  function buildPayload() {
355
+ /*
356
+ * `enabled` and `identificationMethods` are passed through from what was
357
+ * loaded, never recomputed.
358
+ *
359
+ * Which credentials a reader accepts now lives on the READER record and is
360
+ * set from HID Readers > Identification Methods, because the device is what
361
+ * holds them. The toggles that used to derive these two values are gone from
362
+ * this screen, so deriving them again from a form that no longer has them
363
+ * would erase the stored copy and flip `enabled` every time somebody saved
364
+ * the printer settings.
365
+ */
366
+ const storedQrPass = siteData.value?.metadata?.hidQrCodePass || {};
460
367
  const metadata = {
461
368
  ...(siteData.value?.metadata || {}),
462
369
  hidQrCodePass: {
463
- enabled: form.identificationMethods.qrCode,
370
+ enabled: Boolean(storedQrPass.enabled),
464
371
  onlineMode: false,
465
372
  // Kept only for old background/mobile flows. Gate permissions, not this
466
373
  // compatibility value, decide where a new Visitor QR may be scanned.
@@ -471,7 +378,9 @@ function buildPayload() {
471
378
  },
472
379
  // Visitor QR passes always use Amico alphanumeric qrcodes.
473
380
  qrFormat: "0",
474
- identificationMethods: { ...form.identificationMethods },
381
+ ...(storedQrPass.identificationMethods
382
+ ? { identificationMethods: storedQrPass.identificationMethods }
383
+ : {}),
475
384
  printer: {
476
385
  vendorId: form.printer.vendorId.trim(),
477
386
  productId: form.printer.productId.trim(),
@@ -507,43 +416,6 @@ async function saveSection(section: string) {
507
416
  }
508
417
  }
509
418
 
510
- async function saveIdentificationMethod(method: HidIdentificationMethod) {
511
- if (!props.site) return;
512
-
513
- form.enabled = form.identificationMethods.qrCode;
514
-
515
- savingSection.value = `method-${method}`;
516
- try {
517
- if (method === "card") {
518
- await setReaderConfiguration(form.readerId, {
519
- identifier: {
520
- card_identification_enabled: form.identificationMethods.card ? "1" : "0",
521
- },
522
- });
523
- } else if (method === "pin" || method === "idPassword") {
524
- if (method === "pin" && form.identificationMethods.pin) {
525
- form.identificationMethods.idPassword = false;
526
- } else if (method === "idPassword" && form.identificationMethods.idPassword) {
527
- form.identificationMethods.pin = false;
528
- }
529
- await setReaderConfiguration(form.readerId, {
530
- identifier: {
531
- pin_identification_enabled: form.identificationMethods.pin ? "1" : "0",
532
- // Mode 1: PIN is an alternative credential, never a second factor.
533
- multi_factor_authentication: "0",
534
- },
535
- });
536
- }
537
- await updateSitebyId(props.site, buildPayload());
538
- showMessage(`${identificationMethodOptions.find((item) => item.key === method)?.label || "Identification method"} updated.`, "success");
539
- } catch (error: unknown) {
540
- await loadConfig();
541
- showMessage(errorConverter(error), "error");
542
- } finally {
543
- savingSection.value = "";
544
- }
545
- }
546
-
547
419
  async function scanPrinter() {
548
420
  if (!("usb" in navigator)) {
549
421
  showMessage("USB printer scan is not available in this browser.", "error");
@@ -651,51 +523,6 @@ function showMessage(text: string, color: string) {
651
523
  padding: 16px 0;
652
524
  }
653
525
 
654
- .identification-section {
655
- padding-bottom: 20px;
656
- }
657
-
658
- .methods-grid {
659
- display: grid;
660
- grid-template-columns: repeat(6, minmax(120px, 1fr));
661
- gap: 18px;
662
- margin-top: 16px;
663
- }
664
-
665
- .method-control {
666
- display: flex;
667
- align-items: center;
668
- justify-content: space-between;
669
- min-width: 0;
670
- min-height: 42px;
671
- padding: 0 10px 0 14px;
672
- border: 1px solid var(--border);
673
- border-radius: var(--r-inner);
674
- color: var(--text2);
675
- font-family: var(--font-sans);
676
- font-size: 12px;
677
- font-weight: 700;
678
- }
679
-
680
- .method-control span {
681
- overflow: hidden;
682
- text-overflow: ellipsis;
683
- white-space: nowrap;
684
- }
685
-
686
- .method-control--disabled {
687
- background-color: var(--hover);
688
- color: var(--muted);
689
- }
690
-
691
- .method-control :deep(.v-switch) {
692
- flex: 0 0 auto;
693
- }
694
-
695
- .method-control :deep(.v-selection-control) {
696
- min-height: 32px;
697
- }
698
-
699
526
  /* The three `.hid-config-switch` rules are gone: `.app-switch` in
700
527
  primitives.css is the handoff's toggle, and it is shared with the other two
701
528
  HID panels that have one. */
@@ -867,10 +694,6 @@ function showMessage(text: string, color: string) {
867
694
  }
868
695
 
869
696
  @media (max-width: 1100px) {
870
- .methods-grid {
871
- grid-template-columns: repeat(3, minmax(140px, 1fr));
872
- }
873
-
874
697
  .printer-grid,
875
698
  .reader-grid,
876
699
  .template-grid,
@@ -891,7 +714,6 @@ function showMessage(text: string, color: string) {
891
714
  .reader-grid,
892
715
  .template-grid,
893
716
  .validity-grid,
894
- .methods-grid,
895
717
  .permission-location,
896
718
  .permission-row,
897
719
  .permission-actions {
@@ -87,6 +87,8 @@
87
87
 
88
88
  <v-list density="compact" min-width="180">
89
89
  <v-list-item title="View" @click="openView(item)" />
90
+ <v-list-item title="Access Permissions" @click="openPermissions(item)" />
91
+ <v-list-item title="Identification Methods" @click="openIdentification(item)" />
90
92
  <v-list-item title="Sync HID Reader" @click="openSyncConfirm(item)" />
91
93
  <v-list-item title="Test Connection" @click="openTestConfirm(item)" />
92
94
  <v-list-item title="Edit" @click="openEdit(item)" />
@@ -144,6 +146,108 @@
144
146
  </v-card>
145
147
  </v-dialog>
146
148
 
149
+ <!--
150
+ IDENTIFICATION METHODS - what this reader accepts at the door.
151
+
152
+ Per reader, not per site: the device's own `identifier` module is the
153
+ authority, and a site-wide copy could only ever describe one of them.
154
+
155
+ There is deliberately no Bluetooth control. The HID API has no Bluetooth
156
+ identification field; the old site-level toggle of that name referred to
157
+ the phone-as-a-card feature in the mobile app, which is a different thing.
158
+ -->
159
+ <v-dialog v-model="identificationDialog" max-width="430" persistent>
160
+ <v-card rounded="lg">
161
+ <v-card-title class="screen-card-title">Identification Methods</v-card-title>
162
+
163
+ <v-card-text v-if="identificationStage === 'edit'">
164
+ <p class="identification-lead">
165
+ Credentials {{ selectedReader?.name || "this HID Reader" }} will accept at the door.
166
+ </p>
167
+
168
+ <div class="identification-grid">
169
+ <div
170
+ v-for="method in identificationMethodRows"
171
+ :key="method.key"
172
+ class="identification-row"
173
+ >
174
+ <div class="identification-copy">
175
+ <span>{{ method.label }}</span>
176
+ <small v-if="!method.supported">Not supported by this reader</small>
177
+ </div>
178
+ <v-switch
179
+ v-model="identificationForm[method.key]"
180
+ class="app-switch"
181
+ hide-details
182
+ density="compact"
183
+ :disabled="!method.supported || identificationSaving"
184
+ />
185
+ </div>
186
+ </div>
187
+
188
+ <!--
189
+ One reader setting with two modes, not two switches:
190
+ `pin_identification_enabled` is 1 for PIN and 0 for ID-and-password.
191
+ A reader without the PIN capability can be given neither.
192
+ -->
193
+ <div class="identification-credential">
194
+ <div class="identification-copy">
195
+ <span>Credential entry</span>
196
+ <small v-if="!credentialModeSupported">Not supported by this reader</small>
197
+ </div>
198
+ <v-radio-group
199
+ v-model="identificationForm.credentialMode"
200
+ hide-details
201
+ density="compact"
202
+ :disabled="!credentialModeSupported || identificationSaving"
203
+ >
204
+ <v-radio label="PIN" value="pin" />
205
+ <v-radio label="ID and password" value="idPassword" />
206
+ </v-radio-group>
207
+ </div>
208
+
209
+ <p class="identification-applied">
210
+ Confirmed on the reader:
211
+ <strong>{{ formatDate(selectedReader?.identificationMethodsAppliedAt) }}</strong>
212
+ </p>
213
+ </v-card-text>
214
+
215
+ <v-card-text v-else class="reader-action-content">
216
+ <v-icon icon="mdi-shield-key-outline" class="dialog-mark" size="48" />
217
+ <h3>Change what opens this door?</h3>
218
+ <p>
219
+ You are about to change the credentials {{ selectedReader?.name || "this HID Reader" }}
220
+ accepts.
221
+ </p>
222
+ <p v-if="identificationBeingDisabled.length" class="identification-warning">
223
+ Turning off: <strong>{{ identificationBeingDisabled.join(", ") }}</strong>.
224
+ Anyone relying on that credential will stop getting in at this reader.
225
+ </p>
226
+ </v-card-text>
227
+
228
+ <v-card-actions>
229
+ <v-spacer />
230
+ <AppButton
231
+ variant="ghost"
232
+ :disabled="identificationSaving"
233
+ @click="identificationStage === 'confirm' ? (identificationStage = 'edit') : (identificationDialog = false)"
234
+ >
235
+ {{ identificationStage === "confirm" ? "Back" : "Cancel" }}
236
+ </AppButton>
237
+ <AppButton
238
+ v-if="identificationStage === 'edit'"
239
+ :disabled="!identificationChanged"
240
+ @click="identificationStage = 'confirm'"
241
+ >
242
+ Save
243
+ </AppButton>
244
+ <AppButton v-else :disabled="identificationSaving" @click="saveIdentificationMethods">
245
+ {{ identificationSaving ? "Applying..." : "Apply to reader" }}
246
+ </AppButton>
247
+ </v-card-actions>
248
+ </v-card>
249
+ </v-dialog>
250
+
147
251
  <v-dialog v-model="confirmDialog" max-width="390" persistent>
148
252
  <v-card rounded="lg" class="reader-action-dialog">
149
253
  <v-card-title class="screen-card-title">{{ confirmTitle }}</v-card-title>
@@ -241,6 +345,18 @@
241
345
  </v-card-actions>
242
346
  </v-card>
243
347
  </v-dialog>
348
+
349
+ <!-- Who may actually pass this reader. Enrolment makes a person
350
+ RECOGNISABLE; this is what puts them in the group the access rule is
351
+ attached to, and without it a recognised person is refused at the
352
+ door. Reloads the list on save so the reader's own counts stay true. -->
353
+ <HidAccessPermissions
354
+ v-model="permissionsDialog"
355
+ :site="props.site"
356
+ :org="props.org"
357
+ :reader="selectedReader"
358
+ @saved="loadReaders"
359
+ />
244
360
  </section>
245
361
  </template>
246
362
 
@@ -284,6 +400,21 @@ type HidRecord = {
284
400
  cardReadingMode?: "unconfigured" | "pacs" | "csn" | "csn_for_mifare";
285
401
  csnByteOrder?: "msb" | "lsb";
286
402
  pacsFormat?: "raw" | "wiegand";
403
+ capabilities?: {
404
+ card?: boolean;
405
+ facial?: boolean;
406
+ qr?: boolean;
407
+ pin?: boolean;
408
+ intercom?: boolean;
409
+ };
410
+ identificationMethods?: {
411
+ facial?: boolean;
412
+ card?: boolean;
413
+ qrCode?: boolean;
414
+ credentialMode?: "pin" | "idPassword";
415
+ };
416
+ /** When the READER confirmed the methods, not when they were saved here. */
417
+ identificationMethodsAppliedAt?: string;
287
418
  };
288
419
 
289
420
  type HidReaderFormPayload = {
@@ -322,6 +453,13 @@ const props = defineProps({
322
453
  type: String,
323
454
  required: true,
324
455
  },
456
+ // The permission endpoints are org-scoped (`assertOrganizationSiteAccess`),
457
+ // and this component previously had no reason to know the org. Passed from
458
+ // the page, as `HidQrCodeConfiguration` already does.
459
+ org: {
460
+ type: String,
461
+ required: true,
462
+ },
325
463
  });
326
464
 
327
465
  const {
@@ -333,6 +471,7 @@ const {
333
471
  configureReaderIntegration,
334
472
  setReaderMonitor,
335
473
  setReaderOperatingMode,
474
+ setReaderIdentificationMethods,
336
475
  getReaderUsers,
337
476
  } = useHidAmico();
338
477
 
@@ -347,6 +486,19 @@ const viewDialog = ref(false);
347
486
  const confirmDialog = ref(false);
348
487
  const resultDialog = ref(false);
349
488
  const selectedReader = ref<HidRecord | null>(null);
489
+ const permissionsDialog = ref(false);
490
+ const identificationDialog = ref(false);
491
+ /* Two stages in one dialog, like the sync flow: the controls, then the
492
+ confirmation. Switching a credential off decides what stops opening a door,
493
+ so it is never one click away. */
494
+ const identificationStage = ref<"edit" | "confirm">("edit");
495
+ const identificationSaving = ref(false);
496
+ const identificationForm = ref<{
497
+ facial: boolean;
498
+ card: boolean;
499
+ qrCode: boolean;
500
+ credentialMode: "pin" | "idPassword";
501
+ }>({ facial: false, card: false, qrCode: false, credentialMode: "idPassword" });
350
502
  const pendingAction = ref<"test" | "sync" | "delete" | null>(null);
351
503
  const actionStage = ref<"confirm" | "review" | "loading">("confirm");
352
504
  const resultSuccess = ref(true);
@@ -484,6 +636,109 @@ function openView(reader: HidRecord) {
484
636
  viewDialog.value = true;
485
637
  }
486
638
 
639
+ function openPermissions(reader: HidRecord) {
640
+ selectedReader.value = reader;
641
+ permissionsDialog.value = true;
642
+ }
643
+
644
+ /*
645
+ * The reader record is the source of truth, including for what is already on.
646
+ * A missing `identificationMethods` means nothing has been applied through this
647
+ * screen yet; the switches start off rather than guessing at the device.
648
+ */
649
+ function openIdentification(reader: HidRecord) {
650
+ selectedReader.value = reader;
651
+ const current = reader.identificationMethods || {};
652
+ identificationForm.value = {
653
+ facial: current.facial === true,
654
+ card: current.card === true,
655
+ qrCode: current.qrCode === true,
656
+ credentialMode: current.credentialMode === "pin" ? "pin" : "idPassword",
657
+ };
658
+ identificationStage.value = "edit";
659
+ identificationDialog.value = true;
660
+ }
661
+
662
+ /*
663
+ * A reader saved before capabilities were recorded has none. Those are treated
664
+ * as capable rather than having every control disabled on an older record —
665
+ * the backend gate makes the same allowance, and it is the one that decides.
666
+ */
667
+ function readerSupports(key: "facial" | "card" | "qr" | "pin") {
668
+ const capabilities = selectedReader.value?.capabilities;
669
+ if (!capabilities) return true;
670
+ return capabilities[key] === true;
671
+ }
672
+
673
+ const identificationMethodRows = computed(() => [
674
+ { key: "facial" as const, label: "Facial", supported: readerSupports("facial") },
675
+ { key: "card" as const, label: "Card", supported: readerSupports("card") },
676
+ { key: "qrCode" as const, label: "QR code", supported: readerSupports("qr") },
677
+ ]);
678
+
679
+ /* Both modes ride the reader's single PIN switch, so the pair stands or falls
680
+ together on that one capability. */
681
+ const credentialModeSupported = computed(() => readerSupports("pin"));
682
+
683
+ const identificationChanged = computed(() => {
684
+ const current = selectedReader.value?.identificationMethods || {};
685
+ const form = identificationForm.value;
686
+ return (
687
+ form.facial !== (current.facial === true)
688
+ || form.card !== (current.card === true)
689
+ || form.qrCode !== (current.qrCode === true)
690
+ || form.credentialMode !== (current.credentialMode === "pin" ? "pin" : "idPassword")
691
+ );
692
+ });
693
+
694
+ /* Named in the confirmation, because switching a credential OFF is the change
695
+ that locks somebody out. */
696
+ const identificationBeingDisabled = computed(() => {
697
+ const current = selectedReader.value?.identificationMethods || {};
698
+ const form = identificationForm.value;
699
+ const disabled: string[] = [];
700
+ if (current.facial === true && !form.facial) disabled.push("Facial");
701
+ if (current.card === true && !form.card) disabled.push("Card");
702
+ if (current.qrCode === true && !form.qrCode) disabled.push("QR code");
703
+ if (current.credentialMode === "pin" && form.credentialMode !== "pin") disabled.push("PIN");
704
+ return disabled;
705
+ });
706
+
707
+ /*
708
+ * Reload after BOTH outcomes.
709
+ *
710
+ * The confirmed time and the stored methods must come from the server, which
711
+ * only writes them once the reader has echoed the values back. Assuming them
712
+ * here would let the screen claim a door accepts something it refused. On
713
+ * failure the reload matters just as much: the API names the credential the
714
+ * reader would not take, and the controls must go back to what the device
715
+ * actually holds rather than keeping the rejected choice on screen.
716
+ */
717
+ async function saveIdentificationMethods() {
718
+ const readerId = String(selectedReader.value?._id || "");
719
+ if (!readerId) return;
720
+
721
+ const readerName = String(selectedReader.value?.name || "HID Reader");
722
+ identificationSaving.value = true;
723
+ try {
724
+ await setReaderIdentificationMethods(readerId, { ...identificationForm.value });
725
+ identificationDialog.value = false;
726
+ await loadReaders();
727
+ selectedReader.value = readers.value.find((reader) => String(reader._id) === readerId) || null;
728
+ showResult(true, "Identification Methods Updated", `${readerName} now accepts the credentials you selected.`, {
729
+ readerName,
730
+ });
731
+ } catch (error: unknown) {
732
+ console.error("Unable to set HID identification methods:", error);
733
+ identificationDialog.value = false;
734
+ await loadReaders();
735
+ showResult(false, "Identification Methods Not Applied", getFriendlyHidError(error), { readerName });
736
+ } finally {
737
+ identificationSaving.value = false;
738
+ identificationStage.value = "edit";
739
+ }
740
+ }
741
+
487
742
  function openTestConfirm(reader?: HidRecord | null) {
488
743
  if (reader) selectedReader.value = reader;
489
744
  pendingAction.value = "test";
@@ -919,6 +1174,57 @@ function formatCallback(reader?: HidRecord | null) {
919
1174
  margin-top: 20px;
920
1175
  }
921
1176
 
1177
+ .identification-lead {
1178
+ margin: 0 0 14px;
1179
+ color: var(--muted);
1180
+ font-size: 13px;
1181
+ }
1182
+
1183
+ .identification-grid {
1184
+ display: grid;
1185
+ gap: 4px;
1186
+ }
1187
+
1188
+ .identification-row,
1189
+ .identification-credential {
1190
+ display: flex;
1191
+ align-items: center;
1192
+ justify-content: space-between;
1193
+ gap: 16px;
1194
+ }
1195
+
1196
+ .identification-credential {
1197
+ align-items: flex-start;
1198
+ margin-top: 12px;
1199
+ padding-top: 12px;
1200
+ border-top: 1px solid var(--border);
1201
+ }
1202
+
1203
+ .identification-copy {
1204
+ display: grid;
1205
+ gap: 2px;
1206
+ font-size: 13px;
1207
+ color: var(--text);
1208
+ }
1209
+
1210
+ /* The reason a control is dead, next to the control rather than in a tooltip
1211
+ nobody opens. */
1212
+ .identification-copy small {
1213
+ color: var(--muted);
1214
+ font-size: 11px;
1215
+ }
1216
+
1217
+ .identification-applied {
1218
+ margin: 16px 0 0;
1219
+ color: var(--muted);
1220
+ font-size: 12px;
1221
+ }
1222
+
1223
+ .identification-warning {
1224
+ color: var(--text);
1225
+ font-size: 13px;
1226
+ }
1227
+
922
1228
  .reader-action-dialog {
923
1229
  overflow: hidden;
924
1230
  }