@7365admin1/layer-common 4.5.1-staging.299 → 4.5.1-staging.300
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.
- package/components/HidProfileQrCode.vue +323 -0
- package/components/HidReaderUserRoster.vue +32 -2
- package/components/HidUserEnrollment.vue +59 -65
- package/composables/useHidAmico.ts +49 -0
- package/composables/useHidNavigation.ts +20 -12
- package/package.json +1 -1
- package/pages/[org]/[site]/access-mgmt/hid-qr-code/index.vue +23 -0
|
@@ -0,0 +1,323 @@
|
|
|
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 selectedReaderId = ref("");
|
|
130
|
+
const profile = ref<HidProfileQr | null>(null);
|
|
131
|
+
const qrImage = ref("");
|
|
132
|
+
const loading = ref(false);
|
|
133
|
+
const working = ref(false);
|
|
134
|
+
const snackbar = reactive({ show: false, color: "success", message: "" });
|
|
135
|
+
|
|
136
|
+
const readerOptions = computed(() => readers.value.map((reader) => ({
|
|
137
|
+
title: `${reader.name || reader._id} — ${reader.portalName || "Portal not configured"}`,
|
|
138
|
+
value: reader._id,
|
|
139
|
+
})));
|
|
140
|
+
|
|
141
|
+
function showToast(message: string, color: "success" | "error" = "success") {
|
|
142
|
+
snackbar.message = message;
|
|
143
|
+
snackbar.color = color;
|
|
144
|
+
snackbar.show = true;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function toRecord(value: unknown): Record<string, any> {
|
|
148
|
+
return value && typeof value === "object" ? (value as Record<string, any>) : {};
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function errorMessage(error: unknown) {
|
|
152
|
+
const record = toRecord(error);
|
|
153
|
+
return String(toRecord(record.data).message || record.message || "Something went wrong.");
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function formatIssuedAt(value?: string) {
|
|
157
|
+
if (!value) return "";
|
|
158
|
+
const date = new Date(value);
|
|
159
|
+
return Number.isNaN(date.getTime()) ? "" : date.toLocaleString();
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* The image is drawn here, never fetched. The value is the credential itself,
|
|
164
|
+
* so keeping it on this page and out of any URL is the point.
|
|
165
|
+
*/
|
|
166
|
+
async function renderQr(value: string) {
|
|
167
|
+
if (!value) {
|
|
168
|
+
qrImage.value = "";
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
try {
|
|
172
|
+
qrImage.value = await QRCode.toDataURL(value, { width: 440, margin: 1 });
|
|
173
|
+
} catch (error) {
|
|
174
|
+
console.error("Unable to render the HID QR code:", error);
|
|
175
|
+
qrImage.value = "";
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Saves the rendered code as a PNG.
|
|
181
|
+
*
|
|
182
|
+
* Straight off the data URL already in the page - no request, so the credential
|
|
183
|
+
* never travels again to be downloaded. Same anchor-click approach `VisitorForm`
|
|
184
|
+
* uses for a visitor pass, and the reader name is in the file name because a
|
|
185
|
+
* member can hold one code per reader.
|
|
186
|
+
*/
|
|
187
|
+
function downloadQr() {
|
|
188
|
+
if (!qrImage.value) return;
|
|
189
|
+
const slug = String(profile.value?.readerName || "reader")
|
|
190
|
+
.trim()
|
|
191
|
+
.replace(/[^a-z0-9]+/gi, "-")
|
|
192
|
+
.replace(/^-|-$/g, "")
|
|
193
|
+
.toLowerCase();
|
|
194
|
+
const link = document.createElement("a");
|
|
195
|
+
link.href = qrImage.value;
|
|
196
|
+
link.download = `hid-qr-${slug || "reader"}.png`;
|
|
197
|
+
link.click();
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
async function loadReaders() {
|
|
201
|
+
if (!props.site) return;
|
|
202
|
+
const response = toRecord(await getReaders({ site: props.site, page: 1, limit: 100 }));
|
|
203
|
+
const data = toRecord(response.data);
|
|
204
|
+
const items = response.items ?? data.items ?? data.readers ?? [];
|
|
205
|
+
readers.value = (Array.isArray(items) ? items : []).filter((reader) => reader?._id);
|
|
206
|
+
if (!selectedReaderId.value && readers.value.length) {
|
|
207
|
+
selectedReaderId.value = String(readers.value[0]._id);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
async function loadProfile() {
|
|
212
|
+
if (!selectedReaderId.value) return;
|
|
213
|
+
loading.value = true;
|
|
214
|
+
try {
|
|
215
|
+
const response = await getProfileQr(selectedReaderId.value);
|
|
216
|
+
profile.value = response?.data ?? null;
|
|
217
|
+
await renderQr(profile.value?.qrValue || "");
|
|
218
|
+
} catch (error: unknown) {
|
|
219
|
+
profile.value = null;
|
|
220
|
+
qrImage.value = "";
|
|
221
|
+
showToast(errorMessage(error), "error");
|
|
222
|
+
} finally {
|
|
223
|
+
loading.value = false;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
async function generate() {
|
|
228
|
+
if (!selectedReaderId.value) return;
|
|
229
|
+
working.value = true;
|
|
230
|
+
try {
|
|
231
|
+
const response = await issueProfileQr(selectedReaderId.value);
|
|
232
|
+
profile.value = response?.data ?? null;
|
|
233
|
+
await renderQr(profile.value?.qrValue || "");
|
|
234
|
+
showToast("QR code generated.");
|
|
235
|
+
} catch (error: unknown) {
|
|
236
|
+
showToast(errorMessage(error), "error");
|
|
237
|
+
} finally {
|
|
238
|
+
working.value = false;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
async function remove() {
|
|
243
|
+
if (!selectedReaderId.value) return;
|
|
244
|
+
if (!window.confirm("Remove your QR code from this reader?")) return;
|
|
245
|
+
working.value = true;
|
|
246
|
+
try {
|
|
247
|
+
const response = await deleteProfileQr(selectedReaderId.value);
|
|
248
|
+
profile.value = response?.data ?? null;
|
|
249
|
+
await renderQr("");
|
|
250
|
+
showToast("QR code removed.");
|
|
251
|
+
} catch (error: unknown) {
|
|
252
|
+
showToast(errorMessage(error), "error");
|
|
253
|
+
} finally {
|
|
254
|
+
working.value = false;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
watch(
|
|
259
|
+
() => props.site,
|
|
260
|
+
async () => {
|
|
261
|
+
await loadReaders();
|
|
262
|
+
await loadProfile();
|
|
263
|
+
},
|
|
264
|
+
{ immediate: true },
|
|
265
|
+
);
|
|
266
|
+
</script>
|
|
267
|
+
|
|
268
|
+
<style scoped>
|
|
269
|
+
.hid-profile-qr__header {
|
|
270
|
+
display: flex;
|
|
271
|
+
align-items: center;
|
|
272
|
+
gap: 12px;
|
|
273
|
+
flex-wrap: wrap;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
.hid-profile-qr__title {
|
|
277
|
+
margin: 0;
|
|
278
|
+
font-size: 18px;
|
|
279
|
+
font-weight: 600;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
.hid-profile-qr__card {
|
|
283
|
+
margin-top: 16px;
|
|
284
|
+
max-width: 460px;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
.hid-profile-qr__reader {
|
|
288
|
+
margin: 0 0 14px;
|
|
289
|
+
font-size: 14px;
|
|
290
|
+
font-weight: 600;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
.hid-profile-qr__reader span {
|
|
294
|
+
display: block;
|
|
295
|
+
color: var(--muted);
|
|
296
|
+
font-size: 12px;
|
|
297
|
+
font-weight: 500;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
.hid-profile-qr__code {
|
|
301
|
+
display: grid;
|
|
302
|
+
place-items: center;
|
|
303
|
+
margin-bottom: 14px;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
.hid-profile-qr__issued {
|
|
307
|
+
margin: 8px 0 0;
|
|
308
|
+
color: var(--muted);
|
|
309
|
+
font-size: 12px;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
.hid-profile-qr__state {
|
|
313
|
+
color: var(--muted);
|
|
314
|
+
font-size: 13.5px;
|
|
315
|
+
padding: 8px 0 14px;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
.hid-profile-qr__actions {
|
|
319
|
+
display: flex;
|
|
320
|
+
gap: 8px;
|
|
321
|
+
flex-wrap: wrap;
|
|
322
|
+
}
|
|
323
|
+
</style>
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
v-model="search"
|
|
28
28
|
search
|
|
29
29
|
placeholder="Search Amico user, UID or registration"
|
|
30
|
-
@keyup.enter="
|
|
30
|
+
@keyup.enter="onSearchSubmit"
|
|
31
31
|
/>
|
|
32
32
|
<AppSelect
|
|
33
33
|
v-model="userType"
|
|
@@ -284,6 +284,8 @@ async function loadUsers() {
|
|
|
284
284
|
return;
|
|
285
285
|
}
|
|
286
286
|
|
|
287
|
+
const sequence = loadUsersSequence.value + 1;
|
|
288
|
+
loadUsersSequence.value = sequence;
|
|
287
289
|
loading.value = true;
|
|
288
290
|
try {
|
|
289
291
|
let clientFiltersUserType = false;
|
|
@@ -319,6 +321,7 @@ async function loadUsers() {
|
|
|
319
321
|
const pageItems = clientFiltersUserType
|
|
320
322
|
? matchingItems.slice(pageStart, pageStart + 10)
|
|
321
323
|
: matchingItems;
|
|
324
|
+
if (sequence !== loadUsersSequence.value) return;
|
|
322
325
|
users.value = pageItems.map(toReaderUser);
|
|
323
326
|
total.value = clientFiltersUserType
|
|
324
327
|
? matchingItems.length
|
|
@@ -330,13 +333,15 @@ async function loadUsers() {
|
|
|
330
333
|
? ""
|
|
331
334
|
: toText(response.pageRange ?? data.pageRange);
|
|
332
335
|
} catch (error: unknown) {
|
|
336
|
+
if (sequence !== loadUsersSequence.value) return;
|
|
333
337
|
users.value = [];
|
|
334
338
|
total.value = 0;
|
|
335
339
|
pages.value = 1;
|
|
336
340
|
serverPageRange.value = "";
|
|
337
341
|
showToast(getErrorMessage(error), "error");
|
|
338
342
|
} finally {
|
|
339
|
-
|
|
343
|
+
// Only the newest load owns the spinner.
|
|
344
|
+
if (sequence === loadUsersSequence.value) loading.value = false;
|
|
340
345
|
}
|
|
341
346
|
}
|
|
342
347
|
|
|
@@ -350,6 +355,31 @@ function reloadFromFirstPage() {
|
|
|
350
355
|
loadUsers();
|
|
351
356
|
}
|
|
352
357
|
|
|
358
|
+
/**
|
|
359
|
+
* Typing is the search. It used to reload on `@keyup.enter` and on nothing
|
|
360
|
+
* else, so unless you guessed Enter was required the screen sent no request at
|
|
361
|
+
* all. Debounced, because each reload is a login/load/logout round trip to a
|
|
362
|
+
* reader over a VPN; Enter still works and skips the wait.
|
|
363
|
+
*/
|
|
364
|
+
const SEARCH_DEBOUNCE_MS = 400;
|
|
365
|
+
let searchDebounce: ReturnType<typeof setTimeout> | undefined;
|
|
366
|
+
|
|
367
|
+
function onSearchInput() {
|
|
368
|
+
clearTimeout(searchDebounce);
|
|
369
|
+
searchDebounce = setTimeout(reloadFromFirstPage, SEARCH_DEBOUNCE_MS);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
function onSearchSubmit() {
|
|
373
|
+
clearTimeout(searchDebounce);
|
|
374
|
+
reloadFromFirstPage();
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
watch(search, onSearchInput);
|
|
378
|
+
onBeforeUnmount(() => clearTimeout(searchDebounce));
|
|
379
|
+
|
|
380
|
+
/** Discards a load whose answer arrives after a newer one started. */
|
|
381
|
+
const loadUsersSequence = ref(0);
|
|
382
|
+
|
|
353
383
|
function hasFacialData(user: HidReaderUser) {
|
|
354
384
|
return user.metadata?.facialEnrolled === true || Boolean(toText(user.metadata?.facialData));
|
|
355
385
|
}
|
|
@@ -67,8 +67,8 @@
|
|
|
67
67
|
<AppField
|
|
68
68
|
v-model="search"
|
|
69
69
|
search
|
|
70
|
-
placeholder="Search"
|
|
71
|
-
@keyup.enter="
|
|
70
|
+
placeholder="Search name, UID or registration no."
|
|
71
|
+
@keyup.enter="onSearchSubmit"
|
|
72
72
|
/>
|
|
73
73
|
<AppSelect
|
|
74
74
|
v-if="!props.cardManagement"
|
|
@@ -96,6 +96,12 @@
|
|
|
96
96
|
<span class="app-cell--num">{{ formatHidUid(item.hidUserId) || "N/A" }}</span>
|
|
97
97
|
</template>
|
|
98
98
|
|
|
99
|
+
<!-- The reader allocates this alongside the UID. A row the reader holds
|
|
100
|
+
that we never enrolled has none, so it is not always present. -->
|
|
101
|
+
<template #[`item.registration`]="{ item }">
|
|
102
|
+
<span class="app-cell--num">{{ item.registration || "N/A" }}</span>
|
|
103
|
+
</template>
|
|
104
|
+
|
|
99
105
|
<!-- The shared chip. `utils/status.ts` now carries Mapped/Unmapped with
|
|
100
106
|
the same tones this screen's private `getMappingStatusClass` gave
|
|
101
107
|
them, so the map is one list rather than a fourth private copy. -->
|
|
@@ -553,42 +559,22 @@
|
|
|
553
559
|
/>
|
|
554
560
|
</template>
|
|
555
561
|
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
density="compact"
|
|
561
|
-
class="mt-4"
|
|
562
|
-
>
|
|
563
|
-
Present the physical card to the selected Amico reader. The request will time out after 30 seconds.
|
|
564
|
-
</v-alert>
|
|
565
|
-
|
|
562
|
+
<!-- Cards are assigned by entering the value. Reading one at the
|
|
563
|
+
reader was removed with its own progress alert and Cancel
|
|
564
|
+
button, which existed only to narrate that wait. The endpoints
|
|
565
|
+
behind it are untouched and still served by the API. -->
|
|
566
566
|
<div class="hid-card-actions mt-4">
|
|
567
567
|
<AppButton
|
|
568
568
|
variant="secondary"
|
|
569
|
-
:disabled="savingCard ||
|
|
569
|
+
:disabled="savingCard || !cardProfileConfigured"
|
|
570
570
|
@click="assignPhysicalCard"
|
|
571
571
|
>
|
|
572
572
|
Assign Manually
|
|
573
573
|
</AppButton>
|
|
574
|
-
<AppButton
|
|
575
|
-
icon="mdi-contactless-payment"
|
|
576
|
-
:disabled="savingCard || enrollingCard || !cardProfileConfigured"
|
|
577
|
-
@click="enrollPhysicalCard"
|
|
578
|
-
>
|
|
579
|
-
Read at Reader
|
|
580
|
-
</AppButton>
|
|
581
|
-
<AppButton
|
|
582
|
-
v-if="enrollingCard"
|
|
583
|
-
variant="ghost"
|
|
584
|
-
@click="cancelPhysicalCardEnrollment"
|
|
585
|
-
>
|
|
586
|
-
Cancel Reading
|
|
587
|
-
</AppButton>
|
|
588
574
|
</div>
|
|
589
575
|
</v-card-text>
|
|
590
576
|
<v-card-actions class="screen-modal__footer">
|
|
591
|
-
<AppButton variant="ghost"
|
|
577
|
+
<AppButton variant="ghost" @click="cardDialog = false">
|
|
592
578
|
Close
|
|
593
579
|
</AppButton>
|
|
594
580
|
</v-card-actions>
|
|
@@ -651,8 +637,6 @@ const {
|
|
|
651
637
|
deleteUserImage,
|
|
652
638
|
getUserCards,
|
|
653
639
|
assignUserCard,
|
|
654
|
-
enrollUserCard,
|
|
655
|
-
cancelUserCardEnrollment,
|
|
656
640
|
deleteUserCard,
|
|
657
641
|
getUserPinStatus,
|
|
658
642
|
setUserPin,
|
|
@@ -751,8 +735,6 @@ const physicalCardsByUserId = ref<Record<string, HidCard[]>>({});
|
|
|
751
735
|
const physicalCardErrorsByUserId = ref<Record<string, string>>({});
|
|
752
736
|
const loadingCards = ref(false);
|
|
753
737
|
const savingCard = ref(false);
|
|
754
|
-
const enrollingCard = ref(false);
|
|
755
|
-
const cardEnrollmentCancelled = ref(false);
|
|
756
738
|
const deletingCardId = ref("");
|
|
757
739
|
const showPin = ref(false);
|
|
758
740
|
const pinEnrolled = ref(false);
|
|
@@ -1013,6 +995,8 @@ const userHeaders = [
|
|
|
1013
995
|
{ title: "Name", value: "name", sortable: false },
|
|
1014
996
|
{ title: "Facial Data", value: "facialData", sortable: false },
|
|
1015
997
|
{ title: "UID", value: "hidUserId", sortable: false },
|
|
998
|
+
// Reads in the same order the dialog asks for them: UID then registration.
|
|
999
|
+
{ title: "Registration No.", value: "registration", sortable: false },
|
|
1016
1000
|
{ title: "Status", value: "status", sortable: false },
|
|
1017
1001
|
{ title: "", value: "action-table", sortable: false },
|
|
1018
1002
|
];
|
|
@@ -1042,6 +1026,32 @@ function reloadUsersFromFirstPage() {
|
|
|
1042
1026
|
loadUsers();
|
|
1043
1027
|
}
|
|
1044
1028
|
|
|
1029
|
+
/**
|
|
1030
|
+
* Typing is the search.
|
|
1031
|
+
*
|
|
1032
|
+
* The field used to reload on `@keyup.enter` and on nothing else, so a screen
|
|
1033
|
+
* that looks like every other search box did nothing at all unless you guessed
|
|
1034
|
+
* that Enter was required - no request left the browser.
|
|
1035
|
+
*
|
|
1036
|
+
* Debounced, because each reload is a login/load/logout round trip to a reader
|
|
1037
|
+
* over a VPN, not a database query. Enter still works and skips the wait.
|
|
1038
|
+
*/
|
|
1039
|
+
const SEARCH_DEBOUNCE_MS = 400;
|
|
1040
|
+
let searchDebounce: ReturnType<typeof setTimeout> | undefined;
|
|
1041
|
+
|
|
1042
|
+
function onSearchInput() {
|
|
1043
|
+
clearTimeout(searchDebounce);
|
|
1044
|
+
searchDebounce = setTimeout(reloadUsersFromFirstPage, SEARCH_DEBOUNCE_MS);
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
function onSearchSubmit() {
|
|
1048
|
+
clearTimeout(searchDebounce);
|
|
1049
|
+
reloadUsersFromFirstPage();
|
|
1050
|
+
}
|
|
1051
|
+
|
|
1052
|
+
watch(search, onSearchInput);
|
|
1053
|
+
onBeforeUnmount(() => clearTimeout(searchDebounce));
|
|
1054
|
+
|
|
1045
1055
|
const readerOptions = computed(() =>
|
|
1046
1056
|
readers.value.map((reader) => ({
|
|
1047
1057
|
title: `${reader.name || reader.deviceId || reader._id} — ${reader.portalName || "Portal not configured"}`,
|
|
@@ -1085,6 +1095,16 @@ async function loadReaders() {
|
|
|
1085
1095
|
}
|
|
1086
1096
|
}
|
|
1087
1097
|
|
|
1098
|
+
/**
|
|
1099
|
+
* Discards a load whose answer arrives after a newer one started.
|
|
1100
|
+
*
|
|
1101
|
+
* Each reload is a slow round trip to a reader over a VPN, and typing now fires
|
|
1102
|
+
* them, so "abc" can have three in flight at once. Without this the reply to
|
|
1103
|
+
* "a" can land last and repopulate the table with the wrong rows. Same monotonic
|
|
1104
|
+
* counter `HidAccessLogDashboard` uses.
|
|
1105
|
+
*/
|
|
1106
|
+
const loadUsersSequence = ref(0);
|
|
1107
|
+
|
|
1088
1108
|
async function loadUsers() {
|
|
1089
1109
|
if (!selectedReaderId.value) {
|
|
1090
1110
|
users.value = [];
|
|
@@ -1094,6 +1114,8 @@ async function loadUsers() {
|
|
|
1094
1114
|
return;
|
|
1095
1115
|
}
|
|
1096
1116
|
|
|
1117
|
+
const sequence = loadUsersSequence.value + 1;
|
|
1118
|
+
loadUsersSequence.value = sequence;
|
|
1097
1119
|
loading.value = true;
|
|
1098
1120
|
try {
|
|
1099
1121
|
// `userType: "user"` is REQUIRED here, not a nicety. The reader keeps
|
|
@@ -1139,6 +1161,7 @@ async function loadUsers() {
|
|
|
1139
1161
|
const pageItems = clientFiltersVisitors
|
|
1140
1162
|
? matchingItems.slice(pageStart, pageStart + limit.value)
|
|
1141
1163
|
: matchingItems;
|
|
1164
|
+
if (sequence !== loadUsersSequence.value) return;
|
|
1142
1165
|
administratorUserIds.value = new Set(
|
|
1143
1166
|
pageItems
|
|
1144
1167
|
.filter((user) => user.isAdministrator === true)
|
|
@@ -1161,6 +1184,7 @@ async function loadUsers() {
|
|
|
1161
1184
|
await loadVisibleUserCards(users.value);
|
|
1162
1185
|
}
|
|
1163
1186
|
} catch (error) {
|
|
1187
|
+
if (sequence !== loadUsersSequence.value) return;
|
|
1164
1188
|
console.error("Unable to load HID reader users:", error);
|
|
1165
1189
|
showToast("Unable to load HID users from reader.", "error");
|
|
1166
1190
|
users.value = [];
|
|
@@ -1171,7 +1195,9 @@ async function loadUsers() {
|
|
|
1171
1195
|
pages.value = 1;
|
|
1172
1196
|
serverPageRange.value = "";
|
|
1173
1197
|
} finally {
|
|
1174
|
-
|
|
1198
|
+
// Only the newest load owns the spinner; an older one finishing must not
|
|
1199
|
+
// clear it while that newer one is still running.
|
|
1200
|
+
if (sequence === loadUsersSequence.value) loading.value = false;
|
|
1175
1201
|
}
|
|
1176
1202
|
}
|
|
1177
1203
|
|
|
@@ -2132,38 +2158,6 @@ async function assignPhysicalCard() {
|
|
|
2132
2158
|
}
|
|
2133
2159
|
}
|
|
2134
2160
|
|
|
2135
|
-
async function enrollPhysicalCard() {
|
|
2136
|
-
const { readerId, hidUserId } = getCardReaderAndUser();
|
|
2137
|
-
if (!readerId || !hidUserId) return;
|
|
2138
|
-
|
|
2139
|
-
enrollingCard.value = true;
|
|
2140
|
-
cardEnrollmentCancelled.value = false;
|
|
2141
|
-
try {
|
|
2142
|
-
await enrollUserCard(readerId, hidUserId, cardForm.cardType, 30);
|
|
2143
|
-
await loadPhysicalCards();
|
|
2144
|
-
await loadUsers();
|
|
2145
|
-
showToast("Physical HID card read and enrolled on the reader.");
|
|
2146
|
-
} catch (error: unknown) {
|
|
2147
|
-
if (!cardEnrollmentCancelled.value) {
|
|
2148
|
-
showToast(getHidErrorMessage(error), "error");
|
|
2149
|
-
}
|
|
2150
|
-
} finally {
|
|
2151
|
-
enrollingCard.value = false;
|
|
2152
|
-
}
|
|
2153
|
-
}
|
|
2154
|
-
|
|
2155
|
-
async function cancelPhysicalCardEnrollment() {
|
|
2156
|
-
const { readerId } = getCardReaderAndUser();
|
|
2157
|
-
if (!readerId) return;
|
|
2158
|
-
cardEnrollmentCancelled.value = true;
|
|
2159
|
-
try {
|
|
2160
|
-
await cancelUserCardEnrollment(readerId);
|
|
2161
|
-
showToast("Physical HID card reading cancelled.");
|
|
2162
|
-
} catch (error: unknown) {
|
|
2163
|
-
showToast(getHidErrorMessage(error), "error");
|
|
2164
|
-
}
|
|
2165
|
-
}
|
|
2166
|
-
|
|
2167
2161
|
async function removePhysicalCard(card: HidCard) {
|
|
2168
2162
|
if (!window.confirm(`Remove physical HID card ${formatPhysicalCard(card)}?`)) return;
|
|
2169
2163
|
const { readerId, hidUserId } = getCardReaderAndUser();
|
|
@@ -28,6 +28,22 @@ export type HidReaderPayload = {
|
|
|
28
28
|
lastCallbackType?: string;
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
+
export type HidProfileQr = {
|
|
32
|
+
readerId: string;
|
|
33
|
+
userId: string;
|
|
34
|
+
memberId: string;
|
|
35
|
+
hidUserId: string;
|
|
36
|
+
registration: string;
|
|
37
|
+
readerName: string;
|
|
38
|
+
portalName: string;
|
|
39
|
+
qrEnabled: boolean;
|
|
40
|
+
issued: boolean;
|
|
41
|
+
qrValue: string;
|
|
42
|
+
issuedAt: string;
|
|
43
|
+
/** null when the permission lookup itself failed, so "unknown" stays distinct from "no". */
|
|
44
|
+
assigned: boolean | null;
|
|
45
|
+
};
|
|
46
|
+
|
|
31
47
|
type HidIdentityPayload = {
|
|
32
48
|
site?: string;
|
|
33
49
|
hidUserId?: string | number;
|
|
@@ -166,6 +182,36 @@ export default function useHidAmico() {
|
|
|
166
182
|
});
|
|
167
183
|
}
|
|
168
184
|
|
|
185
|
+
/**
|
|
186
|
+
* The signed-in member's own QR code on one reader.
|
|
187
|
+
*
|
|
188
|
+
* No user id in the path: the server takes the caller from the session, so
|
|
189
|
+
* these cannot be pointed at somebody else. `assigned` in the response says
|
|
190
|
+
* whether the HID permissions screen actually admits this member to the
|
|
191
|
+
* reader - issuing a code does not grant access, and the screen has to be
|
|
192
|
+
* able to say so.
|
|
193
|
+
*/
|
|
194
|
+
function getProfileQr(readerId: string) {
|
|
195
|
+
return useNuxtApp().$api<{ data: HidProfileQr }>(
|
|
196
|
+
`${basePath}/readers/${readerId}/profile-qr`,
|
|
197
|
+
{ method: "GET" },
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function issueProfileQr(readerId: string) {
|
|
202
|
+
return useNuxtApp().$api<{ data: HidProfileQr }>(
|
|
203
|
+
`${basePath}/readers/${readerId}/profile-qr`,
|
|
204
|
+
{ method: "POST" },
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function deleteProfileQr(readerId: string) {
|
|
209
|
+
return useNuxtApp().$api<{ data: HidProfileQr }>(
|
|
210
|
+
`${basePath}/readers/${readerId}/profile-qr`,
|
|
211
|
+
{ method: "DELETE" },
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
|
|
169
215
|
function createReader(payload: HidReaderPayload) {
|
|
170
216
|
return useNuxtApp().$api<HidApiRecord>(`${basePath}/readers`, {
|
|
171
217
|
method: "POST",
|
|
@@ -526,6 +572,9 @@ export default function useHidAmico() {
|
|
|
526
572
|
|
|
527
573
|
return {
|
|
528
574
|
getReaders,
|
|
575
|
+
getProfileQr,
|
|
576
|
+
issueProfileQr,
|
|
577
|
+
deleteProfileQr,
|
|
529
578
|
discoverReader,
|
|
530
579
|
createReader,
|
|
531
580
|
updateReader,
|
|
@@ -46,25 +46,33 @@ export default function useHidNavigation() {
|
|
|
46
46
|
},
|
|
47
47
|
},
|
|
48
48
|
{
|
|
49
|
+
// "HID Reader Users" now points at `access-mgmt/administrator`, not at
|
|
50
|
+
// `access-mgmt/hid-users`.
|
|
51
|
+
//
|
|
52
|
+
// Both routes mount a roster of the reader's users, but only this one
|
|
53
|
+
// can act on them. `administrator` renders HidUserEnrollment WITHOUT
|
|
54
|
+
// `card-management`, and that prop is what gates the Enroll action:
|
|
55
|
+
// <template v-if="!props.cardManagement" #actions>
|
|
56
|
+
// `hid-users` renders HidReaderUserRoster, which is read-only apart
|
|
57
|
+
// from PIN management. So the menu entry with this name used to lead
|
|
58
|
+
// to the screen that cannot enrol, while the screen that can was
|
|
59
|
+
// reachable only by typing the URL.
|
|
60
|
+
//
|
|
61
|
+
// `hid-users` is left in place and simply unlisted - the same state
|
|
62
|
+
// `administrator` was in - so any existing link to it still resolves.
|
|
49
63
|
title: "HID Reader Users",
|
|
50
64
|
route: {
|
|
51
|
-
name: "org-site-access-mgmt-
|
|
65
|
+
name: "org-site-access-mgmt-administrator",
|
|
52
66
|
params: { org, site },
|
|
53
67
|
},
|
|
54
68
|
},
|
|
55
69
|
{
|
|
56
|
-
// The
|
|
57
|
-
//
|
|
58
|
-
//
|
|
59
|
-
|
|
60
|
-
// <template v-if="!props.cardManagement" #actions>
|
|
61
|
-
// HID Cards mounts the same component WITH `card-management`, so it
|
|
62
|
-
// deliberately hides Enroll. Until now nothing linked to
|
|
63
|
-
// `administrator`, so the only screen that draws Enroll was
|
|
64
|
-
// reachable by typing the URL and Enroll looked missing entirely.
|
|
65
|
-
title: "Administrator",
|
|
70
|
+
// The signed-in member's own pass, not somebody else's. Every other
|
|
71
|
+
// entry in this group acts on a resident or a visitor; this one has
|
|
72
|
+
// no subject but the caller.
|
|
73
|
+
title: "HID QR Code",
|
|
66
74
|
route: {
|
|
67
|
-
name: "org-site-access-mgmt-
|
|
75
|
+
name: "org-site-access-mgmt-hid-qr-code",
|
|
68
76
|
params: { org, site },
|
|
69
77
|
},
|
|
70
78
|
},
|
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.5.1-staging.
|
|
5
|
+
"version": "4.5.1-staging.300",
|
|
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.",
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<v-container fluid>
|
|
3
|
+
<HidEnabledGate
|
|
4
|
+
:site="siteId"
|
|
5
|
+
:org="orgId"
|
|
6
|
+
message="Enable HID as a service for this site before generating a QR code."
|
|
7
|
+
>
|
|
8
|
+
<HidProfileQrCode :site="siteId" />
|
|
9
|
+
</HidEnabledGate>
|
|
10
|
+
</v-container>
|
|
11
|
+
</template>
|
|
12
|
+
|
|
13
|
+
<script setup lang="ts">
|
|
14
|
+
definePageMeta({
|
|
15
|
+
layout: "default",
|
|
16
|
+
middleware: ["01-auth", "02-org"],
|
|
17
|
+
memberOnly: true,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const route = useRoute();
|
|
21
|
+
const siteId = computed(() => String(route.params.site ?? ""));
|
|
22
|
+
const orgId = computed(() => String(route.params.org ?? ""));
|
|
23
|
+
</script>
|