@7365admin1/layer-common 4.31.0 → 4.32.1-staging.364

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 (63) hide show
  1. package/CHANGELOG.md +10 -4
  2. package/assets/css/robot-hero.css +227 -1
  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/DeleteConfirmation.vue +17 -2
  7. package/components/Dialog/ReusablePrompt.vue +26 -3
  8. package/components/Dialog/UpdateMoreAction.vue +11 -1
  9. package/components/DocumentForm.vue +407 -112
  10. package/components/DocumentManagement.vue +213 -12
  11. package/components/EntryPass/QrTemplatePreview.vue +21 -25
  12. package/components/EntryPassInformation.vue +119 -24
  13. package/components/Facility/BookingSetup.vue +63 -0
  14. package/components/HidAccessLogDashboard.vue +41 -8
  15. package/components/HidAccessPermissions.vue +424 -0
  16. package/components/HidIntercomManagement.vue +148 -14
  17. package/components/HidProfileQrCode.vue +332 -0
  18. package/components/HidReaderManagement.vue +26 -0
  19. package/components/HidReaderUserRoster.vue +44 -3
  20. package/components/HidUserEnrollment.vue +845 -155
  21. package/components/InvitationClientForm.vue +19 -1
  22. package/components/NotificationBell.vue +39 -3
  23. package/components/Robot/BuildingMap.vue +403 -0
  24. package/components/Robot/LiftQueue.vue +247 -0
  25. package/components/Robot/MapEditor.vue +233 -0
  26. package/components/Robot/PatrolRoutes.vue +3 -3
  27. package/components/Robot/SiteScreen.vue +36 -1
  28. package/components/VehicleForm.vue +45 -2
  29. package/components/VehicleManagement.vue +95 -10
  30. package/components/VisitorManagement.vue +267 -5
  31. package/composables/useAccessManagement.ts +5 -0
  32. package/composables/useCleaningPermission.ts +4 -4
  33. package/composables/useCommonPermission.ts +16 -0
  34. package/composables/useDocument.ts +7 -0
  35. package/composables/useFacility.ts +11 -0
  36. package/composables/useHidAmico.ts +117 -0
  37. package/composables/useHidNavigation.ts +25 -1
  38. package/composables/useHidReaderSelection.ts +50 -0
  39. package/composables/useLandscapingPermission.ts +4 -4
  40. package/composables/useMechanicalElectricalPermission.ts +4 -4
  41. package/composables/usePeople.ts +19 -0
  42. package/composables/usePestControlPermission.ts +4 -4
  43. package/composables/usePoolMaintenancePermission.ts +4 -4
  44. package/composables/useRobotBuilding.ts +66 -0
  45. package/composables/useSecurityPermission.ts +4 -10
  46. package/composables/useSiteCategory.ts +45 -0
  47. package/composables/useSiteEntryPassSettings.ts +26 -0
  48. package/composables/useWebUsb.ts +14 -11
  49. package/package.json +2 -2
  50. package/pages/[org]/[site]/access-mgmt/administrator/index.vue +1 -1
  51. package/pages/[org]/[site]/access-mgmt/hid-cards/index.vue +1 -1
  52. package/pages/[org]/[site]/access-mgmt/hid-qr-code/index.vue +23 -0
  53. package/pages/[org]/[site]/access-mgmt/hid-readers/index.vue +1 -1
  54. package/types/document.d.ts +14 -0
  55. package/types/facility.d.ts +4 -0
  56. package/types/people.d.ts +28 -1
  57. package/utils/hid-permission-assignments.ts +190 -0
  58. package/utils/hid-reader-selection.ts +52 -0
  59. package/utils/notification-target.ts +75 -0
  60. package/utils/occupancy-role.ts +109 -0
  61. package/utils/robot-building.ts +521 -0
  62. package/utils/robot-display.ts +29 -6
  63. package/utils/vehicle-actions.ts +12 -4
@@ -162,11 +162,8 @@
162
162
  />
163
163
  <v-list-item class="screen-menu__item" title="Call Settings" prepend-icon="mdi-cog" @click="openCallDialog(item)" />
164
164
  <v-list-item class="screen-menu__item" title="Dial Code" prepend-icon="mdi-dialpad" @click="openDialCodeDialog(item)" />
165
- <v-list-item class="screen-menu__item" title="Make a call" prepend-icon="mdi-phone" @click="openMakeCallDialog(item)" />
166
- <v-list-item class="screen-menu__item" title="Web call" prepend-icon="mdi-headset" @click="openWebPhoneDialog(item)" />
167
165
  </v-list>
168
166
  <v-list v-else density="compact" class="screen-menu">
169
- <v-list-item class="screen-menu__item" title="Call" prepend-icon="mdi-phone" @click="openContactCall(item)" />
170
167
  <v-list-item class="screen-menu__item" title="Check reader SIP status" prepend-icon="mdi-lan-check" @click="testContactSipStatus(item)" />
171
168
  <v-list-item class="screen-menu__item" title="View" prepend-icon="mdi-eye" @click="openContactView(item)" />
172
169
  <v-list-item class="screen-menu__item" title="Edit" prepend-icon="mdi-pencil" @click="openContactDialog(item)" />
@@ -589,9 +586,31 @@
589
586
  :disabled="Boolean(contactForm.id)"
590
587
  />
591
588
  <FieldLabel text="Name" required />
592
- <AppField v-model="contactForm.name" placeholder="Name shown on calls" class="my-3" />
589
+ <!-- The name is picked from the site's SIP accounts (`hid-sip-accounts`)
590
+ rather than typed, so a contact always names a person who holds an
591
+ extension. The model stays the plain name string the reader stores,
592
+ so `saveContact` is unchanged; an existing contact whose name is not
593
+ in the list still displays it (AppSelect falls back to the raw value). -->
594
+ <AppSelect
595
+ v-model="contactForm.name"
596
+ :items="sipAccountOptions"
597
+ :disabled="sipAccountsLoading"
598
+ :placeholder="sipAccountsLoading ? 'Loading SIP accounts…' : 'Name shown on calls'"
599
+ class="my-3"
600
+ @update:model-value="applySipAccountToContact"
601
+ />
602
+ <p v-if="sipAccountsError" class="field-hint field-hint--error">{{ sipAccountsError }}</p>
603
+ <p v-else-if="!sipAccountsLoading && !sipAccounts.length" class="field-hint">
604
+ No SIP accounts on this site yet. An account is created the first time a user opens Web Call.
605
+ </p>
593
606
  <FieldLabel text="Address" required />
594
- <AppField v-model="contactForm.serverAddress" :placeholder="contactAddressPlaceholder" />
607
+ <!-- Always read-only: it shows the extension of the chosen SIP account
608
+ and is never typed into. -->
609
+ <AppField
610
+ v-model="contactForm.serverAddress"
611
+ :placeholder="contactAddressPlaceholder"
612
+ disabled
613
+ />
595
614
  <p class="field-hint">{{ contactAddressHint }}</p>
596
615
  </v-card-text>
597
616
  <v-card-actions class="dialog-actions pa-0">
@@ -636,6 +655,8 @@
636
655
  </template>
637
656
 
638
657
  <script setup lang="ts">
658
+ import type { HidSipAccountListItem } from "../composables/useHidAmico";
659
+
639
660
  const props = defineProps({
640
661
  org: {
641
662
  type: String,
@@ -732,6 +753,8 @@ const {
732
753
  makeIntercomCall,
733
754
  finalizeIntercomCall,
734
755
  ensureSipAccount,
756
+ getSipAccounts,
757
+ notifyIntercomCall,
735
758
  } = useHidAmico();
736
759
 
737
760
  const activeTab = ref<IntercomTab>("intercom");
@@ -760,6 +783,11 @@ const webPhoneActionLoading = ref(false);
760
783
  const sipAccount = ref<SipAccount | null>(null);
761
784
  const sipAccountLoading = ref(false);
762
785
  const sipAccountError = ref("");
786
+ // The site's SIP account list for the contact dialog's name picker. Distinct
787
+ // from `sipAccount` above, which is the CALLER's own account for the web phone.
788
+ const sipAccounts = ref<HidSipAccountListItem[]>([]);
789
+ const sipAccountsLoading = ref(false);
790
+ const sipAccountsError = ref("");
763
791
  const remoteVideoEl = ref<HTMLVideoElement | null>(null);
764
792
  const remoteAudioEl = ref<HTMLAudioElement | null>(null);
765
793
  const webPhone = useSipWebPhone();
@@ -864,6 +892,31 @@ const readerOptions = computed(() => readers.value.map((reader) => ({
864
892
  value: reader._id,
865
893
  })));
866
894
 
895
+ /**
896
+ * The contact name picker. `value` is the bare name because that is what the
897
+ * reader stores and what `saveContact` sends; the extension goes into the
898
+ * Address field, not the label. A name that already sits on the contact being
899
+ * edited but is no longer in the SIP list is kept as an option so the picker
900
+ * does not silently drop it.
901
+ */
902
+ const sipAccountOptions = computed(() => {
903
+ const options: Array<{ title: string; value: string }> = sipAccounts.value
904
+ .filter((account: HidSipAccountListItem) => account.name)
905
+ .map((account: HidSipAccountListItem) => ({ title: account.name, value: account.name }));
906
+ const current = contactForm.name.trim();
907
+ if (current && !options.some((option) => option.value === current)) {
908
+ options.unshift({ title: current, value: current });
909
+ }
910
+ return options;
911
+ });
912
+
913
+ /** The SIP account behind the picked name, or null for a legacy / unpicked name. */
914
+ const selectedSipAccount = computed(() => {
915
+ const name = contactForm.name.trim();
916
+ const match = sipAccounts.value.find((account: HidSipAccountListItem) => account.name === name);
917
+ return (match ?? null) as HidSipAccountListItem | null;
918
+ });
919
+
867
920
  const visibleRows = computed(() => activeTab.value === "intercom" ? filteredIntercomRows.value : filteredContacts.value);
868
921
  const pages = computed(() => Math.max(1, Math.ceil(visibleRows.value.length / limit)));
869
922
  const pageRange = computed(() => {
@@ -976,14 +1029,11 @@ const contactReaderRow = computed(() =>
976
1029
  );
977
1030
  const isContactReaderPeerToPeer = computed(() => contactReaderRow.value?.operatingMode === "Peer-to-Peer");
978
1031
  const contactAddressPlaceholder = computed(() => (isContactReaderPeerToPeer.value ? "192.168.0.129" : "7100"));
979
- const contactAddressHint = computed(() => {
980
- if (!contactReaderRow.value) {
981
- return "Extension number (SIP Client) or local IP address (Peer-to-Peer), depending on the reader's operating mode.";
982
- }
983
- return isContactReaderPeerToPeer.value
984
- ? "Peer-to-Peer mode: enter the contact's local IP address."
985
- : "SIP Client mode: enter the contact's extension number.";
986
- });
1032
+ const contactAddressHint = computed(() => (
1033
+ selectedSipAccount.value
1034
+ ? "Extension of the selected SIP account."
1035
+ : "Filled from the SIP account of the name selected above."
1036
+ ));
987
1037
  const areSipCredentialFieldsDisabled = computed(() => !sipForm.enabled || isPeerToPeerMode.value);
988
1038
  const intercomDetailSections = computed(() => {
989
1039
  const row = selectedRow.value;
@@ -1399,6 +1449,37 @@ async function loadSipAccount() {
1399
1449
  }
1400
1450
  }
1401
1451
 
1452
+ async function loadSipAccounts() {
1453
+ if (!props.org || !props.site) return;
1454
+
1455
+ sipAccountsLoading.value = true;
1456
+ sipAccountsError.value = "";
1457
+ try {
1458
+ const response = await getSipAccounts(props.site, props.org);
1459
+ const rows = toRecord(response).data;
1460
+ sipAccounts.value = Array.isArray(rows) ? rows as HidSipAccountListItem[] : [];
1461
+ // An existing contact opened before the list arrived: once its name is
1462
+ // matched to an account, show that account's extension in the locked field.
1463
+ applySipAccountToContact(contactForm.name.trim());
1464
+ } catch (error: unknown) {
1465
+ sipAccounts.value = [];
1466
+ sipAccountsError.value = getErrorMessage(error);
1467
+ } finally {
1468
+ sipAccountsLoading.value = false;
1469
+ }
1470
+ }
1471
+
1472
+ /**
1473
+ * Picking a SIP account sets the address to its extension. The Address field
1474
+ * is always disabled, so this is the only way it gets a value; a name that is
1475
+ * not an account (a legacy contact) leaves whatever address it already had.
1476
+ */
1477
+ function applySipAccountToContact(name: string) {
1478
+ const account = sipAccounts.value.find((item: HidSipAccountListItem) => item.name === name);
1479
+ if (!account) return;
1480
+ contactForm.serverAddress = account.extension;
1481
+ }
1482
+
1402
1483
  async function connectWebPhone() {
1403
1484
  const account = sipAccount.value;
1404
1485
  if (!account) {
@@ -1442,8 +1523,10 @@ async function disconnectWebPhone() {
1442
1523
 
1443
1524
  async function startWebCall() {
1444
1525
  webPhoneActionLoading.value = true;
1526
+ const destination = webPhoneForm.destination;
1445
1527
  try {
1446
- await webPhone.call(webPhoneForm.destination);
1528
+ await webPhone.call(destination);
1529
+ void ringResidentPhone(destination);
1447
1530
  } catch (error: unknown) {
1448
1531
  showMessage(getErrorMessage(error), "error");
1449
1532
  } finally {
@@ -1451,6 +1534,50 @@ async function startWebCall() {
1451
1534
  }
1452
1535
  }
1453
1536
 
1537
+ /**
1538
+ * Wake the called resident's mobile so they are there to answer.
1539
+ *
1540
+ * Deliberately fired AFTER the INVITE and never awaited. The SIP leg is the
1541
+ * call: it is already ringing by the time this runs, and a resident whose
1542
+ * phone is asleep is the only thing this fixes. So a failure here is logged
1543
+ * and dropped rather than shown — telling the operator "call failed" for a
1544
+ * call that is ringing would be worse than a silent miss.
1545
+ *
1546
+ * A destination with no resident behind it (a staff extension, an external SIP
1547
+ * address) comes back `notified: false` with a reason and is not an error.
1548
+ */
1549
+ async function ringResidentPhone(destination: string) {
1550
+ if (!props.org || !props.site) return;
1551
+
1552
+ try {
1553
+ // No `readerId`: this call came from the web phone, not a door station.
1554
+ // The reader selected in the table above is whatever the operator happens
1555
+ // to be looking at, and sending it would tell the resident's app the call
1556
+ // arrived at a door it never touched.
1557
+ await notifyIntercomCall(props.site, {
1558
+ orgId: props.org,
1559
+ destination,
1560
+ callId: createCallId(),
1561
+ });
1562
+ } catch (error: unknown) {
1563
+ console.warn("[intercom] could not send the incoming-call push", error);
1564
+ }
1565
+ }
1566
+
1567
+ /**
1568
+ * A per-call id, so a second push for the same call replaces the first on the
1569
+ * resident's lock screen rather than stacking a second ringing card.
1570
+ * `randomUUID` needs a secure context, which the web phone already requires —
1571
+ * getUserMedia does not run without one — but the fallback keeps a call from
1572
+ * failing on that account alone.
1573
+ */
1574
+ function createCallId() {
1575
+ if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
1576
+ return crypto.randomUUID();
1577
+ }
1578
+ return `call-${Date.now()}-${Math.random().toString(16).slice(2)}`;
1579
+ }
1580
+
1454
1581
  async function answerWebCall() {
1455
1582
  webPhoneActionLoading.value = true;
1456
1583
  try {
@@ -1508,6 +1635,9 @@ function openContactDialog(contact?: ContactRow) {
1508
1635
  contactForm.location = contact?.location === "N/A" ? "" : contact?.location || selectedReader?.location || "";
1509
1636
  contactForm.serverAddress = contact?.serverAddress === "N/A" ? "" : contact?.serverAddress || "";
1510
1637
  contactDialog.value = true;
1638
+ // Fetched on every open, not cached: an account is provisioned the first
1639
+ // time a user opens Web Call, so the list can grow between two dialogs.
1640
+ void loadSipAccounts();
1511
1641
  }
1512
1642
 
1513
1643
  function openContactView(contact: ContactRow) {
@@ -2096,6 +2226,10 @@ export default {
2096
2226
  line-height: 1.4;
2097
2227
  }
2098
2228
 
2229
+ .field-hint--error {
2230
+ color: var(--err);
2231
+ }
2232
+
2099
2233
  .sip-settings-dialog .field-label {
2100
2234
  margin-top: 14px;
2101
2235
  }
@@ -0,0 +1,332 @@
1
+ <!--
2
+ MY HID QR CODE.
3
+
4
+ The signed-in member's own pass for one reader. Every other HID screen acts on
5
+ somebody else - a resident being enrolled, a visitor being issued a pass. This
6
+ one has no subject picker at all, because the server takes the caller from the
7
+ session and there is no user id to send.
8
+
9
+ Issuing a code does NOT grant access. A member's door permission comes from the
10
+ HID permissions screen, and minting an access rule here would let anyone who
11
+ can press Generate admit themselves. So the screen reports what the permissions
12
+ screen says (`assigned`) and warns when a code would be refused at the door,
13
+ rather than handing out something that silently fails.
14
+ -->
15
+ <template>
16
+ <div class="hid-profile-qr">
17
+ <div class="hid-profile-qr__header">
18
+ <h2 class="hid-profile-qr__title">HID QR Code</h2>
19
+ <AppSelect
20
+ v-if="readerOptions.length"
21
+ v-model="selectedReaderId"
22
+ class="reader-select"
23
+ :items="readerOptions"
24
+ @update:model-value="loadProfile"
25
+ />
26
+ </div>
27
+
28
+ <v-card class="screen-modal hid-profile-qr__card">
29
+ <v-card-text class="screen-modal__body">
30
+ <div v-if="loading" class="hid-profile-qr__state">Loading...</div>
31
+
32
+ <div v-else-if="!readerOptions.length" class="hid-profile-qr__state">
33
+ No HID reader is set up for this site yet.
34
+ </div>
35
+
36
+ <template v-else>
37
+ <p class="hid-profile-qr__reader">
38
+ {{ profile?.readerName || "HID reader" }}
39
+ <span>{{ profile?.portalName || "Portal not configured" }}</span>
40
+ </p>
41
+
42
+ <!-- A code this reader cannot read is worse than no code, so the
43
+ capability is checked before anything is offered. -->
44
+ <v-alert
45
+ v-if="profile && !profile.qrEnabled"
46
+ type="warning"
47
+ variant="tonal"
48
+ density="compact"
49
+ class="mb-4"
50
+ >
51
+ This reader is not set up to read QR codes.
52
+ </v-alert>
53
+
54
+ <!-- The honest part: a code opens the door only for a member the
55
+ permissions screen already admits. `assigned` is null when the
56
+ lookup failed, which is not the same as "no". -->
57
+ <v-alert
58
+ v-else-if="profile && profile.assigned === false"
59
+ type="warning"
60
+ variant="tonal"
61
+ density="compact"
62
+ class="mb-4"
63
+ >
64
+ You are not assigned to this reader, so this code will be refused at
65
+ the door. Ask a property manager to add you on the HID permissions
66
+ screen.
67
+ </v-alert>
68
+
69
+ <div v-if="qrImage" class="hid-profile-qr__code">
70
+ <img :src="qrImage" alt="Your HID QR code" width="220" height="220" />
71
+ <p class="hid-profile-qr__issued">
72
+ Issued {{ formatIssuedAt(profile?.issuedAt) }}
73
+ </p>
74
+ </div>
75
+ <p v-else class="hid-profile-qr__state">
76
+ You have no QR code on this reader yet.
77
+ </p>
78
+
79
+ <div class="hid-profile-qr__actions">
80
+ <AppButton
81
+ :disabled="working || !profile?.qrEnabled"
82
+ @click="generate"
83
+ >
84
+ {{ profile?.issued ? "Regenerate" : "Generate QR Code" }}
85
+ </AppButton>
86
+ <AppButton
87
+ v-if="qrImage"
88
+ variant="ghost"
89
+ icon="mdi-download"
90
+ @click="downloadQr"
91
+ >
92
+ Download
93
+ </AppButton>
94
+ <AppButton
95
+ v-if="profile?.issued"
96
+ variant="ghost"
97
+ :disabled="working"
98
+ @click="remove"
99
+ >
100
+ Remove
101
+ </AppButton>
102
+ </div>
103
+
104
+ <p class="field-hint">
105
+ Regenerating replaces the previous code. The old one stops working
106
+ immediately.
107
+ </p>
108
+ </template>
109
+ </v-card-text>
110
+ </v-card>
111
+
112
+ <v-snackbar v-model="snackbar.show" :color="snackbar.color" timeout="4000">
113
+ {{ snackbar.message }}
114
+ </v-snackbar>
115
+ </div>
116
+ </template>
117
+
118
+ <script setup lang="ts">
119
+ import QRCode from "qrcode";
120
+ import type { HidProfileQr } from "../composables/useHidAmico";
121
+
122
+ const props = defineProps<{ site: string }>();
123
+
124
+ const { getReaders, getProfileQr, issueProfileQr, deleteProfileQr } = useHidAmico();
125
+
126
+ type HidReaderOption = { _id: string; name?: string; portalName?: string };
127
+
128
+ const readers = ref<HidReaderOption[]>([]);
129
+ const { selectHidReader, resolveForSite } = useHidReaderSelection();
130
+ const selectedReaderId = ref("");
131
+ const profile = ref<HidProfileQr | null>(null);
132
+ const qrImage = ref("");
133
+ const loading = ref(false);
134
+ const working = ref(false);
135
+ const snackbar = reactive({ show: false, color: "success", message: "" });
136
+
137
+ const readerOptions = computed(() => readers.value.map((reader) => ({
138
+ title: `${reader.name || reader._id} — ${reader.portalName || "Portal not configured"}`,
139
+ value: reader._id,
140
+ })));
141
+
142
+ function showToast(message: string, color: "success" | "error" = "success") {
143
+ snackbar.message = message;
144
+ snackbar.color = color;
145
+ snackbar.show = true;
146
+ }
147
+
148
+ function toRecord(value: unknown): Record<string, any> {
149
+ return value && typeof value === "object" ? (value as Record<string, any>) : {};
150
+ }
151
+
152
+ function errorMessage(error: unknown) {
153
+ const record = toRecord(error);
154
+ return String(toRecord(record.data).message || record.message || "Something went wrong.");
155
+ }
156
+
157
+ function formatIssuedAt(value?: string) {
158
+ if (!value) return "";
159
+ const date = new Date(value);
160
+ return Number.isNaN(date.getTime()) ? "" : date.toLocaleString();
161
+ }
162
+
163
+ /**
164
+ * The image is drawn here, never fetched. The value is the credential itself,
165
+ * so keeping it on this page and out of any URL is the point.
166
+ */
167
+ async function renderQr(value: string) {
168
+ if (!value) {
169
+ qrImage.value = "";
170
+ return;
171
+ }
172
+ try {
173
+ qrImage.value = await QRCode.toDataURL(value, { width: 440, margin: 1 });
174
+ } catch (error) {
175
+ console.error("Unable to render the HID QR code:", error);
176
+ qrImage.value = "";
177
+ }
178
+ }
179
+
180
+ /**
181
+ * Saves the rendered code as a PNG.
182
+ *
183
+ * Straight off the data URL already in the page - no request, so the credential
184
+ * never travels again to be downloaded. Same anchor-click approach `VisitorForm`
185
+ * uses for a visitor pass, and the reader name is in the file name because a
186
+ * member can hold one code per reader.
187
+ */
188
+ function downloadQr() {
189
+ if (!qrImage.value) return;
190
+ const slug = String(profile.value?.readerName || "reader")
191
+ .trim()
192
+ .replace(/[^a-z0-9]+/gi, "-")
193
+ .replace(/^-|-$/g, "")
194
+ .toLowerCase();
195
+ const link = document.createElement("a");
196
+ link.href = qrImage.value;
197
+ link.download = `hid-qr-${slug || "reader"}.png`;
198
+ link.click();
199
+ }
200
+
201
+ async function loadReaders() {
202
+ if (!props.site) return;
203
+ const response = toRecord(await getReaders({ site: props.site, page: 1, limit: 100 }));
204
+ const data = toRecord(response.data);
205
+ const items = response.items ?? data.items ?? data.readers ?? [];
206
+ readers.value = (Array.isArray(items) ? items : []).filter((reader) => reader?._id);
207
+ /* Shared with every other HID screen — see `useHidReaderSelection`. The
208
+ resolver refuses a remembered reader that is not this site's, so a site
209
+ switch or a deleted reader falls back to the first rather than querying
210
+ an id the site does not own. */
211
+ selectedReaderId.value = resolveForSite(props.site, readers.value);
212
+ }
213
+
214
+ async function loadProfile() {
215
+ if (!selectedReaderId.value) return;
216
+ loading.value = true;
217
+ try {
218
+ const response = await getProfileQr(selectedReaderId.value);
219
+ profile.value = response?.data ?? null;
220
+ await renderQr(profile.value?.qrValue || "");
221
+ } catch (error: unknown) {
222
+ profile.value = null;
223
+ qrImage.value = "";
224
+ showToast(errorMessage(error), "error");
225
+ } finally {
226
+ loading.value = false;
227
+ }
228
+ }
229
+
230
+ async function generate() {
231
+ if (!selectedReaderId.value) return;
232
+ working.value = true;
233
+ try {
234
+ const response = await issueProfileQr(selectedReaderId.value);
235
+ profile.value = response?.data ?? null;
236
+ await renderQr(profile.value?.qrValue || "");
237
+ showToast("QR code generated.");
238
+ } catch (error: unknown) {
239
+ showToast(errorMessage(error), "error");
240
+ } finally {
241
+ working.value = false;
242
+ }
243
+ }
244
+
245
+ async function remove() {
246
+ if (!selectedReaderId.value) return;
247
+ if (!window.confirm("Remove your QR code from this reader?")) return;
248
+ working.value = true;
249
+ try {
250
+ const response = await deleteProfileQr(selectedReaderId.value);
251
+ profile.value = response?.data ?? null;
252
+ await renderQr("");
253
+ showToast("QR code removed.");
254
+ } catch (error: unknown) {
255
+ showToast(errorMessage(error), "error");
256
+ } finally {
257
+ working.value = false;
258
+ }
259
+ }
260
+
261
+ watch(
262
+ () => props.site,
263
+ async () => {
264
+ await loadReaders();
265
+ await loadProfile();
266
+ },
267
+ { immediate: true },
268
+ );
269
+
270
+ /* Publish every change, including the seed above: a screen that had to fall
271
+ back to the first reader should leave the others agreeing with it. */
272
+ watch(selectedReaderId, (value) => {
273
+ if (value) selectHidReader(props.site, value);
274
+ });
275
+ </script>
276
+
277
+ <style scoped>
278
+ .hid-profile-qr__header {
279
+ display: flex;
280
+ align-items: center;
281
+ gap: 12px;
282
+ flex-wrap: wrap;
283
+ }
284
+
285
+ .hid-profile-qr__title {
286
+ margin: 0;
287
+ font-size: 18px;
288
+ font-weight: 600;
289
+ }
290
+
291
+ .hid-profile-qr__card {
292
+ margin-top: 16px;
293
+ max-width: 460px;
294
+ }
295
+
296
+ .hid-profile-qr__reader {
297
+ margin: 0 0 14px;
298
+ font-size: 14px;
299
+ font-weight: 600;
300
+ }
301
+
302
+ .hid-profile-qr__reader span {
303
+ display: block;
304
+ color: var(--muted);
305
+ font-size: 12px;
306
+ font-weight: 500;
307
+ }
308
+
309
+ .hid-profile-qr__code {
310
+ display: grid;
311
+ place-items: center;
312
+ margin-bottom: 14px;
313
+ }
314
+
315
+ .hid-profile-qr__issued {
316
+ margin: 8px 0 0;
317
+ color: var(--muted);
318
+ font-size: 12px;
319
+ }
320
+
321
+ .hid-profile-qr__state {
322
+ color: var(--muted);
323
+ font-size: 13.5px;
324
+ padding: 8px 0 14px;
325
+ }
326
+
327
+ .hid-profile-qr__actions {
328
+ display: flex;
329
+ gap: 8px;
330
+ flex-wrap: wrap;
331
+ }
332
+ </style>
@@ -87,6 +87,7 @@
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)" />
90
91
  <v-list-item title="Sync HID Reader" @click="openSyncConfirm(item)" />
91
92
  <v-list-item title="Test Connection" @click="openTestConfirm(item)" />
92
93
  <v-list-item title="Edit" @click="openEdit(item)" />
@@ -241,6 +242,18 @@
241
242
  </v-card-actions>
242
243
  </v-card>
243
244
  </v-dialog>
245
+
246
+ <!-- Who may actually pass this reader. Enrolment makes a person
247
+ RECOGNISABLE; this is what puts them in the group the access rule is
248
+ attached to, and without it a recognised person is refused at the
249
+ door. Reloads the list on save so the reader's own counts stay true. -->
250
+ <HidAccessPermissions
251
+ v-model="permissionsDialog"
252
+ :site="props.site"
253
+ :org="props.org"
254
+ :reader="selectedReader"
255
+ @saved="loadReaders"
256
+ />
244
257
  </section>
245
258
  </template>
246
259
 
@@ -322,6 +335,13 @@ const props = defineProps({
322
335
  type: String,
323
336
  required: true,
324
337
  },
338
+ // The permission endpoints are org-scoped (`assertOrganizationSiteAccess`),
339
+ // and this component previously had no reason to know the org. Passed from
340
+ // the page, as `HidQrCodeConfiguration` already does.
341
+ org: {
342
+ type: String,
343
+ required: true,
344
+ },
325
345
  });
326
346
 
327
347
  const {
@@ -347,6 +367,7 @@ const viewDialog = ref(false);
347
367
  const confirmDialog = ref(false);
348
368
  const resultDialog = ref(false);
349
369
  const selectedReader = ref<HidRecord | null>(null);
370
+ const permissionsDialog = ref(false);
350
371
  const pendingAction = ref<"test" | "sync" | "delete" | null>(null);
351
372
  const actionStage = ref<"confirm" | "review" | "loading">("confirm");
352
373
  const resultSuccess = ref(true);
@@ -484,6 +505,11 @@ function openView(reader: HidRecord) {
484
505
  viewDialog.value = true;
485
506
  }
486
507
 
508
+ function openPermissions(reader: HidRecord) {
509
+ selectedReader.value = reader;
510
+ permissionsDialog.value = true;
511
+ }
512
+
487
513
  function openTestConfirm(reader?: HidRecord | null) {
488
514
  if (reader) selectedReader.value = reader;
489
515
  pendingAction.value = "test";