@7365admin1/layer-common 4.4.1 → 4.4.2-staging.291
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/Facility/BookingSetup.vue +63 -0
- package/components/HidIntercomManagement.vue +145 -42
- package/components/HidUserEnrollment.vue +712 -147
- package/components/InvitationClientForm.vue +19 -1
- package/components/RolePermissionMain.vue +32 -3
- package/components/VisitorManagement.vue +267 -5
- package/composables/useFacility.ts +11 -0
- package/composables/useHidAmico.ts +24 -0
- package/composables/useHidNavigation.ts +16 -0
- package/composables/usePeople.ts +19 -0
- package/package.json +1 -1
- package/types/facility.d.ts +4 -0
- package/utils/materialSymbols.ts +3 -0
- package/utils/org-modules.ts +40 -0
|
@@ -166,12 +166,12 @@
|
|
|
166
166
|
</TableMain>
|
|
167
167
|
|
|
168
168
|
<v-dialog v-model="formDialog" max-width="420" persistent>
|
|
169
|
-
<v-card
|
|
170
|
-
<v-card-title
|
|
169
|
+
<v-card class="screen-modal">
|
|
170
|
+
<v-card-title>
|
|
171
171
|
{{ selectedUser ? "Edit User Information" : "Enroll" }}
|
|
172
172
|
</v-card-title>
|
|
173
173
|
|
|
174
|
-
<v-card-text>
|
|
174
|
+
<v-card-text class="screen-modal__body">
|
|
175
175
|
<div class="photo-wrap">
|
|
176
176
|
<v-menu>
|
|
177
177
|
<template #activator="{ props: menuProps }">
|
|
@@ -213,6 +213,15 @@
|
|
|
213
213
|
/>
|
|
214
214
|
</v-list>
|
|
215
215
|
</v-menu>
|
|
216
|
+
<!-- Sits under the button because it describes what the button
|
|
217
|
+
is reporting: the reader holds a face, and this is its
|
|
218
|
+
reference. Nothing to show while enrolling - the value does not
|
|
219
|
+
exist until the reader has accepted a photo. -->
|
|
220
|
+
<p v-if="editFacialData" class="photo-facial">
|
|
221
|
+
<span class="photo-facial__label">Facial Data</span>
|
|
222
|
+
<span class="photo-facial__value">{{ editFacialData }}</span>
|
|
223
|
+
</p>
|
|
224
|
+
|
|
216
225
|
<input
|
|
217
226
|
ref="photoInput"
|
|
218
227
|
type="file"
|
|
@@ -222,29 +231,96 @@
|
|
|
222
231
|
/>
|
|
223
232
|
</div>
|
|
224
233
|
|
|
225
|
-
|
|
234
|
+
<!-- Block / Level / Unit / Resident. Enrolment only.
|
|
235
|
+
Enrollment is resident-only and the resident must already exist
|
|
236
|
+
in iService365 - you pick a person, you do not type one. Name is
|
|
237
|
+
therefore a mirror of that record, never an input, so the reader
|
|
238
|
+
can never end up holding a name the app does not know.
|
|
239
|
+
Every option is derived from the residents themselves, so a
|
|
240
|
+
block, level or unit only appears when somebody lives there.
|
|
241
|
+
The list loads on first touch of Block, not on dialog open.
|
|
242
|
+
Enrolment only, with no exception. Editing does not move
|
|
243
|
+
anybody: the record already carries its block, level and unit,
|
|
244
|
+
`openEdit` loads them into the form and `saveUser` writes them
|
|
245
|
+
back untouched, so the location survives an edit without being
|
|
246
|
+
asked for. A row that never had one keeps not having one; that
|
|
247
|
+
is not a reason to make somebody fill in a location before they
|
|
248
|
+
can change a PIN. -->
|
|
249
|
+
<template v-if="!selectedUser">
|
|
250
|
+
<div class="field-label">Block <span>*</span></div>
|
|
251
|
+
<!-- The listener sits on a wrapper, NOT on AppSelect: AppSelect
|
|
252
|
+
spreads `$attrs` over its v-menu activator AFTER the activator's
|
|
253
|
+
own bindings, so an `@click` here would replace the handler that
|
|
254
|
+
opens the dropdown. `focusin` covers keyboard users, and both
|
|
255
|
+
are idempotent - `ensureOccupancy()` fetches once.
|
|
256
|
+
AppSelect has no `loading` prop either; the placeholder carries
|
|
257
|
+
the loading and empty states instead. -->
|
|
258
|
+
<div @click="onBlockOpened" @focusin="onBlockOpened">
|
|
259
|
+
<AppSelect
|
|
260
|
+
v-model="form.block"
|
|
261
|
+
:items="blockOptions"
|
|
262
|
+
:placeholder="blockPlaceholder"
|
|
263
|
+
klass="mb-3"
|
|
264
|
+
@update:model-value="onBlockChanged"
|
|
265
|
+
/>
|
|
266
|
+
</div>
|
|
267
|
+
|
|
268
|
+
<div class="field-label">Level <span>*</span></div>
|
|
269
|
+
<AppSelect
|
|
270
|
+
v-model="form.level"
|
|
271
|
+
:items="levelOptions"
|
|
272
|
+
:disabled="!form.block"
|
|
273
|
+
placeholder="Select level"
|
|
274
|
+
klass="mb-3"
|
|
275
|
+
@update:model-value="onLevelChanged"
|
|
276
|
+
/>
|
|
277
|
+
|
|
278
|
+
<div class="field-label">Unit <span>*</span></div>
|
|
279
|
+
<AppSelect
|
|
280
|
+
v-model="form.unit"
|
|
281
|
+
:items="unitOptions"
|
|
282
|
+
:disabled="!form.level"
|
|
283
|
+
placeholder="Select unit"
|
|
284
|
+
klass="mb-3"
|
|
285
|
+
@update:model-value="onUnitChanged"
|
|
286
|
+
/>
|
|
287
|
+
</template>
|
|
288
|
+
|
|
289
|
+
<!-- Drawn only where it can offer something: while enrolling, or
|
|
290
|
+
while editing a record whose stored unit gives it a list. A row
|
|
291
|
+
with no unit has no candidates to show, and the dialog is then
|
|
292
|
+
purely the reader's own credentials - photo, PIN, password -
|
|
293
|
+
which is exactly the edit that must not be blocked. -->
|
|
294
|
+
<template v-if="!selectedUser || form.unit">
|
|
295
|
+
<div class="field-label">Resident <span>*</span></div>
|
|
296
|
+
<AppSelect
|
|
297
|
+
v-model="form.subjectId"
|
|
298
|
+
:items="subjectOptions"
|
|
299
|
+
:disabled="!form.unit"
|
|
300
|
+
:placeholder="unitResidentPlaceholder"
|
|
301
|
+
klass="mb-3"
|
|
302
|
+
@update:model-value="onResidentChanged"
|
|
303
|
+
/>
|
|
304
|
+
</template>
|
|
305
|
+
<!-- The duplicate check. It is reader-scoped: this resident holding a
|
|
306
|
+
HID user on another gate is normal and says nothing here. -->
|
|
307
|
+
<p v-if="checkingResident" class="field-hint">Checking enrollment...</p>
|
|
308
|
+
<p v-else-if="residentConflict" class="field-hint field-hint--error mb-3">
|
|
309
|
+
{{ residentConflictMessage }}
|
|
310
|
+
</p>
|
|
311
|
+
<p v-else-if="unitResidentNote" class="field-hint mb-3">
|
|
312
|
+
{{ unitResidentNote }}
|
|
313
|
+
</p>
|
|
314
|
+
|
|
315
|
+
<!-- Read-only: it restates the chosen resident, it does not collect
|
|
316
|
+
anything. `selectedUser` is the edit case, where the name is
|
|
317
|
+
whatever the reader already holds. -->
|
|
318
|
+
<div class="field-label">Name</div>
|
|
226
319
|
<AppField
|
|
227
320
|
v-model="form.name"
|
|
228
321
|
aria-label="Name"
|
|
229
|
-
placeholder="
|
|
230
|
-
|
|
231
|
-
/>
|
|
232
|
-
|
|
233
|
-
<div class="field-label">Link To <span>*</span></div>
|
|
234
|
-
<AppSelect
|
|
235
|
-
v-model="form.subjectCategory"
|
|
236
|
-
:items="subjectCategoryOptions"
|
|
237
|
-
placeholder="Select person type"
|
|
238
|
-
klass="mb-3"
|
|
239
|
-
@update:model-value="onSubjectCategoryChanged"
|
|
240
|
-
/>
|
|
241
|
-
|
|
242
|
-
<div class="field-label">Resident / Staff / Provider <span>*</span></div>
|
|
243
|
-
<AppSelect
|
|
244
|
-
v-model="form.subjectId"
|
|
245
|
-
:items="subjectOptions"
|
|
246
|
-
:loading="loadingSubjects"
|
|
247
|
-
placeholder="Select an existing site record"
|
|
322
|
+
placeholder="Select a resident above"
|
|
323
|
+
readonly
|
|
248
324
|
klass="mb-3"
|
|
249
325
|
/>
|
|
250
326
|
|
|
@@ -256,11 +332,11 @@
|
|
|
256
332
|
v-model="form.registration"
|
|
257
333
|
aria-label="Registration No."
|
|
258
334
|
placeholder="Enter registration no."
|
|
259
|
-
|
|
335
|
+
readonly
|
|
260
336
|
klass="mb-3"
|
|
261
337
|
/>
|
|
262
338
|
|
|
263
|
-
<div class="field-label">
|
|
339
|
+
<div class="field-label">PIN (optional)</div>
|
|
264
340
|
<!--
|
|
265
341
|
The handoff draws no password field anywhere (the sign-in screens
|
|
266
342
|
are the owner's own), so the reveal toggle is this product's, not
|
|
@@ -270,8 +346,8 @@
|
|
|
270
346
|
-->
|
|
271
347
|
<AppField
|
|
272
348
|
v-model="form.accessPin"
|
|
273
|
-
aria-label="
|
|
274
|
-
placeholder="Enter
|
|
349
|
+
aria-label="PIN"
|
|
350
|
+
placeholder="Enter pin"
|
|
275
351
|
inputmode="numeric"
|
|
276
352
|
autocomplete="new-password"
|
|
277
353
|
:type="showPin ? 'text' : 'password'"
|
|
@@ -280,7 +356,7 @@
|
|
|
280
356
|
<button
|
|
281
357
|
type="button"
|
|
282
358
|
class="app-field__trailing"
|
|
283
|
-
:aria-label="showPin ? 'Hide
|
|
359
|
+
:aria-label="showPin ? 'Hide PIN' : 'Show PIN'"
|
|
284
360
|
@click="showPin = !showPin"
|
|
285
361
|
>
|
|
286
362
|
<v-icon :icon="showPin ? 'mdi-eye-off' : 'mdi-eye'" size="18" />
|
|
@@ -295,28 +371,62 @@
|
|
|
295
371
|
<v-checkbox
|
|
296
372
|
v-if="selectedUser && pinEnrolled"
|
|
297
373
|
v-model="removePinRequested"
|
|
298
|
-
label="Remove current
|
|
374
|
+
label="Remove current PIN"
|
|
375
|
+
density="compact"
|
|
376
|
+
hide-details
|
|
377
|
+
/>
|
|
378
|
+
|
|
379
|
+
<!-- Password: the reader stores only a hash plus its salt, so there
|
|
380
|
+
is nothing to read back and the field is always empty on open.
|
|
381
|
+
Same reveal toggle as the PIN above. -->
|
|
382
|
+
<div class="field-label mt-3">Password (optional)</div>
|
|
383
|
+
<AppField
|
|
384
|
+
v-model="form.password"
|
|
385
|
+
aria-label="Password"
|
|
386
|
+
:placeholder="selectedUser && passwordSet ? 'Enter a new password' : 'Enter password'"
|
|
387
|
+
autocomplete="new-password"
|
|
388
|
+
:type="showPassword ? 'text' : 'password'"
|
|
389
|
+
>
|
|
390
|
+
<template #trailing>
|
|
391
|
+
<button
|
|
392
|
+
type="button"
|
|
393
|
+
class="app-field__trailing"
|
|
394
|
+
:aria-label="showPassword ? 'Hide password' : 'Show password'"
|
|
395
|
+
@click="showPassword = !showPassword"
|
|
396
|
+
>
|
|
397
|
+
<v-icon :icon="showPassword ? 'mdi-eye-off' : 'mdi-eye'" size="18" />
|
|
398
|
+
</button>
|
|
399
|
+
</template>
|
|
400
|
+
</AppField>
|
|
401
|
+
<p class="field-hint">
|
|
402
|
+
{{ selectedUser && passwordSet ? "A password is set. Leave blank to keep it." : "Used with the user ID on the reader keypad." }}
|
|
403
|
+
</p>
|
|
404
|
+
<v-checkbox
|
|
405
|
+
v-if="selectedUser && passwordSet"
|
|
406
|
+
v-model="removePasswordRequested"
|
|
407
|
+
label="Remove current password"
|
|
299
408
|
density="compact"
|
|
300
409
|
hide-details
|
|
301
410
|
/>
|
|
302
411
|
</v-card-text>
|
|
303
412
|
|
|
304
|
-
<!-- The
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
413
|
+
<!-- The shared modal footer: `screen-btn-ghost` + `screen-btn-primary`
|
|
414
|
+
on `v-btn`, the same pair every other module's dialog uses
|
|
415
|
+
(`assets/css/screens.css`). `v-btn` stays because the submit needs
|
|
416
|
+
`:loading`, which `AppButton` does not carry. -->
|
|
417
|
+
<v-card-actions class="screen-modal__footer">
|
|
308
418
|
<v-btn
|
|
309
|
-
class="text-none
|
|
419
|
+
class="text-none screen-btn-ghost"
|
|
310
420
|
variant="flat"
|
|
311
|
-
height="44"
|
|
312
421
|
@click="formDialog = false"
|
|
313
|
-
>Cancel</v-btn
|
|
314
422
|
>
|
|
423
|
+
Cancel
|
|
424
|
+
</v-btn>
|
|
315
425
|
<v-btn
|
|
316
|
-
class="text-none
|
|
426
|
+
class="text-none screen-btn-primary"
|
|
317
427
|
variant="flat"
|
|
318
|
-
height="44"
|
|
319
428
|
:loading="saving"
|
|
429
|
+
:disabled="Boolean(residentConflict) || checkingResident"
|
|
320
430
|
@click="saveUser"
|
|
321
431
|
>
|
|
322
432
|
Save
|
|
@@ -328,9 +438,9 @@
|
|
|
328
438
|
<HidCameraCaptureDialog v-model="cameraDialog" @capture="onCameraCapture" />
|
|
329
439
|
|
|
330
440
|
<v-dialog v-model="viewDialog" max-width="430">
|
|
331
|
-
<v-card
|
|
332
|
-
<v-card-title
|
|
333
|
-
<v-card-text>
|
|
441
|
+
<v-card class="screen-modal">
|
|
442
|
+
<v-card-title>User Information</v-card-title>
|
|
443
|
+
<v-card-text class="screen-modal__body">
|
|
334
444
|
<div class="detail-grid">
|
|
335
445
|
<span>Name</span><strong>{{ getName(selectedUser) }}</strong>
|
|
336
446
|
<span>User ID</span
|
|
@@ -347,21 +457,22 @@
|
|
|
347
457
|
><strong>{{
|
|
348
458
|
selectedUser ? getMappingStatus(selectedUser) : "N/A"
|
|
349
459
|
}}</strong>
|
|
350
|
-
<span>
|
|
460
|
+
<span>PIN</span
|
|
351
461
|
><strong>{{ selectedUser?.metadata?.pinEnrolled ? "Configured" : "N/A" }}</strong>
|
|
462
|
+
<span>Password</span
|
|
463
|
+
><strong>{{ selectedUser?.metadata?.passwordSet ? "Configured" : "N/A" }}</strong>
|
|
352
464
|
</div>
|
|
353
465
|
</v-card-text>
|
|
354
|
-
<v-card-actions>
|
|
355
|
-
<v-spacer />
|
|
466
|
+
<v-card-actions class="screen-modal__footer">
|
|
356
467
|
<AppButton variant="ghost" @click="viewDialog = false">Close</AppButton>
|
|
357
468
|
</v-card-actions>
|
|
358
469
|
</v-card>
|
|
359
470
|
</v-dialog>
|
|
360
471
|
|
|
361
472
|
<v-dialog v-model="cardDialog" max-width="560" persistent>
|
|
362
|
-
<v-card
|
|
363
|
-
<v-card-title
|
|
364
|
-
<v-card-text>
|
|
473
|
+
<v-card class="screen-modal">
|
|
474
|
+
<v-card-title>Physical HID Cards</v-card-title>
|
|
475
|
+
<v-card-text class="screen-modal__body">
|
|
365
476
|
<p class="hid-card-user">
|
|
366
477
|
{{ getName(cardUser) }}
|
|
367
478
|
<span>{{ cardUser ? formatHidUid(cardUser.hidUserId) : "" }}</span>
|
|
@@ -476,8 +587,7 @@
|
|
|
476
587
|
</AppButton>
|
|
477
588
|
</div>
|
|
478
589
|
</v-card-text>
|
|
479
|
-
<v-card-actions>
|
|
480
|
-
<v-spacer />
|
|
590
|
+
<v-card-actions class="screen-modal__footer">
|
|
481
591
|
<AppButton variant="ghost" :disabled="enrollingCard" @click="cardDialog = false">
|
|
482
592
|
Close
|
|
483
593
|
</AppButton>
|
|
@@ -486,31 +596,31 @@
|
|
|
486
596
|
</v-dialog>
|
|
487
597
|
|
|
488
598
|
<v-dialog v-model="deleteDialog" max-width="360" persistent>
|
|
489
|
-
<v-card
|
|
490
|
-
<v-card-title
|
|
491
|
-
<v-card-text class="text-body-2">
|
|
599
|
+
<v-card class="screen-modal">
|
|
600
|
+
<v-card-title>Delete</v-card-title>
|
|
601
|
+
<v-card-text class="screen-modal__body text-body-2">
|
|
492
602
|
Are you sure you want to permanently delete this HID user?
|
|
493
603
|
<div class="text-caption text-medium-emphasis mt-2">
|
|
494
604
|
This action will remove the user from the HID reader and mark the
|
|
495
605
|
identity as deleted.
|
|
496
606
|
</div>
|
|
497
607
|
</v-card-text>
|
|
498
|
-
<v-card-actions class="
|
|
608
|
+
<v-card-actions class="screen-modal__footer">
|
|
499
609
|
<v-btn
|
|
500
|
-
class="text-none
|
|
610
|
+
class="text-none screen-btn-ghost"
|
|
501
611
|
variant="flat"
|
|
502
|
-
height="44"
|
|
503
612
|
@click="deleteDialog = false"
|
|
504
|
-
>Cancel</v-btn
|
|
505
613
|
>
|
|
614
|
+
Cancel
|
|
615
|
+
</v-btn>
|
|
506
616
|
<v-btn
|
|
507
|
-
class="text-none
|
|
617
|
+
class="text-none screen-btn-primary"
|
|
508
618
|
variant="flat"
|
|
509
|
-
height="44"
|
|
510
619
|
:loading="deleting"
|
|
511
620
|
@click="deleteUser"
|
|
512
|
-
>Delete</v-btn
|
|
513
621
|
>
|
|
622
|
+
Delete
|
|
623
|
+
</v-btn>
|
|
514
624
|
</v-card-actions>
|
|
515
625
|
</v-card>
|
|
516
626
|
</v-dialog>
|
|
@@ -547,11 +657,13 @@ const {
|
|
|
547
657
|
getUserPinStatus,
|
|
548
658
|
setUserPin,
|
|
549
659
|
deleteUserPin,
|
|
660
|
+
getUserPasswordStatus,
|
|
661
|
+
setUserPassword,
|
|
662
|
+
deleteUserPassword,
|
|
550
663
|
runObjectOperation,
|
|
551
664
|
createIdentity,
|
|
552
665
|
updateIdentity,
|
|
553
666
|
deleteIdentity,
|
|
554
|
-
getPermissionCandidates,
|
|
555
667
|
} = useHidAmico();
|
|
556
668
|
|
|
557
669
|
type HidMetadata = Record<string, unknown> & {
|
|
@@ -566,6 +678,7 @@ type HidMetadata = Record<string, unknown> & {
|
|
|
566
678
|
lastAccessAt?: string;
|
|
567
679
|
facialScores?: Record<string, unknown>;
|
|
568
680
|
pinEnrolled?: boolean;
|
|
681
|
+
passwordSet?: boolean;
|
|
569
682
|
hidPhysicalCards?: HidCard[];
|
|
570
683
|
};
|
|
571
684
|
|
|
@@ -661,13 +774,61 @@ function hasFacialEnrollment(user?: HidUser | null) {
|
|
|
661
774
|
user?.metadata?.imageTimestamp
|
|
662
775
|
);
|
|
663
776
|
}
|
|
777
|
+
|
|
778
|
+
/**
|
|
779
|
+
* The reader's own reference for the enrolled face, shown while editing.
|
|
780
|
+
*
|
|
781
|
+
* We hold neither the image nor the biometric template - the reader does - so
|
|
782
|
+
* this value is the only handle on the enrollment there is. `getFacialData` is
|
|
783
|
+
* the roster's Facial Data column, reused here so the dialog and the table
|
|
784
|
+
* cannot disagree; it answers "N/A" when there is nothing, which is the case
|
|
785
|
+
* this must not draw a row for.
|
|
786
|
+
*/
|
|
787
|
+
const editFacialData = computed(() => {
|
|
788
|
+
if (!selectedUser.value) return "";
|
|
789
|
+
const value = String(getFacialData(selectedUser.value) ?? "").trim();
|
|
790
|
+
return value && value !== "N/A" ? value : "";
|
|
791
|
+
});
|
|
664
792
|
const removePinRequested = ref(false);
|
|
793
|
+
const passwordSet = ref(false);
|
|
794
|
+
const showPassword = ref(false);
|
|
795
|
+
const removePasswordRequested = ref(false);
|
|
665
796
|
const snackbar = reactive({
|
|
666
797
|
show: false,
|
|
667
798
|
color: "success",
|
|
668
799
|
message: "",
|
|
669
800
|
});
|
|
670
801
|
|
|
802
|
+
type OccupiedUnit = { _id: string; name: string; people: number };
|
|
803
|
+
type OccupiedLevel = { _id: string; name: string; units?: OccupiedUnit[] };
|
|
804
|
+
type OccupiedBlock = {
|
|
805
|
+
_id: string;
|
|
806
|
+
name: string;
|
|
807
|
+
block: number | null;
|
|
808
|
+
levels?: OccupiedLevel[];
|
|
809
|
+
};
|
|
810
|
+
type UnitPerson = {
|
|
811
|
+
_id: string;
|
|
812
|
+
name?: string;
|
|
813
|
+
unitName?: string;
|
|
814
|
+
/**
|
|
815
|
+
* The resident's app account, and the reason this field is read here.
|
|
816
|
+
*
|
|
817
|
+
* A HID identity is refused unless its subject is a valid permission subject
|
|
818
|
+
* at the site, and for a resident that means a `site.people` row WITH a
|
|
819
|
+
* linked user - `assertPermissionSubject` in `iservice365-core` filters on
|
|
820
|
+
* exactly this field. The permission model has no way to represent anyone
|
|
821
|
+
* else: `resolvePermissionUserBindings` binds reader access by user id and
|
|
822
|
+
* drops every row without one, so a resident enrolled without an account
|
|
823
|
+
* would end up on the reader holding no access rules at all.
|
|
824
|
+
*
|
|
825
|
+
* The picker this replaced was fed by that same server-side function, so it
|
|
826
|
+
* could never offer an unenrollable resident. The unit cascade asks People
|
|
827
|
+
* Management instead, which has no such filter - hence this one.
|
|
828
|
+
*/
|
|
829
|
+
user?: string | null;
|
|
830
|
+
};
|
|
831
|
+
|
|
671
832
|
const form = reactive({
|
|
672
833
|
reader: "",
|
|
673
834
|
block: "",
|
|
@@ -678,6 +839,7 @@ const form = reactive({
|
|
|
678
839
|
registration: "",
|
|
679
840
|
isAdministrator: false,
|
|
680
841
|
accessPin: "",
|
|
842
|
+
password: "",
|
|
681
843
|
photoPreview: "",
|
|
682
844
|
subjectCategory: "resident" as THidPermissionCategory,
|
|
683
845
|
subjectId: "",
|
|
@@ -685,18 +847,131 @@ const form = reactive({
|
|
|
685
847
|
|
|
686
848
|
const route = useRoute();
|
|
687
849
|
const orgId = computed(() => String(route.params.org || ""));
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
const
|
|
696
|
-
|
|
697
|
-
|
|
850
|
+
|
|
851
|
+
// The cascade runs on People Management's own endpoints, the same pair the
|
|
852
|
+
// resident forms use:
|
|
853
|
+
// GET /api/people/site/:site/occupied-structure - blocks/levels/units that
|
|
854
|
+
// actually have an occupant, so the picker cannot offer an empty unit
|
|
855
|
+
// GET /api/people/unit/:unit - who is in the chosen one
|
|
856
|
+
// Both are fetched on FIRST USE, never when the dialog opens.
|
|
857
|
+
const { getOccupiedStructure, getPeopleByUnit } = usePeople();
|
|
858
|
+
|
|
859
|
+
// `resident,tenant` matches the occupancy endpoint's own default, so the units
|
|
860
|
+
// it offers and the people this returns are the same set. Asking the two
|
|
861
|
+
// halves different questions is how a unit ends up offered but empty.
|
|
862
|
+
const OCCUPANT_TYPES = "resident,tenant";
|
|
863
|
+
|
|
864
|
+
const occupiedBlocks = ref<OccupiedBlock[]>([]);
|
|
865
|
+
const occupancyLoaded = ref(false);
|
|
866
|
+
const loadingOccupancy = ref(false);
|
|
867
|
+
const unitPeople = ref<UnitPerson[]>([]);
|
|
868
|
+
const loadingUnitPeople = ref(false);
|
|
869
|
+
|
|
870
|
+
// "Is this resident already enrolled on THIS reader?" - the reader keeps its own
|
|
871
|
+
// user table, so the same person at a different gate is normal and does not
|
|
872
|
+
// count. Held here rather than derived, because it is the answer to a request.
|
|
873
|
+
//
|
|
874
|
+
// The server refuses the duplicate as well (`createIdentity` in
|
|
875
|
+
// `iservice365-core`), but by the time it answers, `saveUser` has already
|
|
876
|
+
// created a user on the physical device and has to roll it back. Asking here
|
|
877
|
+
// keeps that off the reader entirely.
|
|
878
|
+
const residentConflict = ref<HidUser | null>(null);
|
|
879
|
+
const checkingResident = ref(false);
|
|
880
|
+
|
|
881
|
+
// One spelling of a block, used by the picker and by the label stamped onto the
|
|
882
|
+
// record. Two copies of this expression is how the dropdown and the Unit column
|
|
883
|
+
// drift apart.
|
|
884
|
+
function formatBlockTitle(block?: OccupiedBlock | null) {
|
|
885
|
+
if (!block) return "";
|
|
886
|
+
return block.name
|
|
887
|
+
? `Block ${block.block} (${block.name})`
|
|
888
|
+
: `Block ${block.block ?? ""}`.trim();
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
const blockOptions = computed(() => occupiedBlocks.value.map((block) => ({
|
|
892
|
+
title: formatBlockTitle(block),
|
|
893
|
+
value: String(block._id ?? ""),
|
|
894
|
+
})));
|
|
895
|
+
|
|
896
|
+
const levelOptions = computed(() => {
|
|
897
|
+
const block = occupiedBlocks.value.find((item) => String(item._id ?? "") === form.block);
|
|
898
|
+
return (block?.levels ?? []).map((level) => ({
|
|
899
|
+
title: String(level.name ?? ""),
|
|
900
|
+
value: String(level._id ?? ""),
|
|
901
|
+
}));
|
|
902
|
+
});
|
|
903
|
+
|
|
904
|
+
const unitOptions = computed(() => {
|
|
905
|
+
const block = occupiedBlocks.value.find((item) => String(item._id ?? "") === form.block);
|
|
906
|
+
const level = (block?.levels ?? []).find((item) => String(item._id ?? "") === form.level);
|
|
907
|
+
return (level?.units ?? []).map((unit) => ({
|
|
908
|
+
title: String(unit.name ?? ""),
|
|
909
|
+
value: String(unit._id ?? ""),
|
|
910
|
+
}));
|
|
911
|
+
});
|
|
912
|
+
|
|
913
|
+
// Only the residents the server will actually accept - see `UnitPerson.user`.
|
|
914
|
+
// Offering the rest produced "The linked HID identity subject is not active at
|
|
915
|
+
// this site." at the very end of enrollment, after a user had already been
|
|
916
|
+
// written to the reader.
|
|
917
|
+
const enrollableUnitPeople = computed(() =>
|
|
918
|
+
unitPeople.value.filter((person) => Boolean(person.user)),
|
|
919
|
+
);
|
|
920
|
+
|
|
921
|
+
const unenrollableUnitPeopleCount = computed(
|
|
922
|
+
() => unitPeople.value.length - enrollableUnitPeople.value.length,
|
|
923
|
+
);
|
|
924
|
+
|
|
925
|
+
// `_id` here is `site.people._id`, which is exactly the `person` that
|
|
926
|
+
// `createIdentity` maps a HID user to.
|
|
927
|
+
const subjectOptions = computed(() => enrollableUnitPeople.value.map((person) => ({
|
|
928
|
+
title: String(person.name ?? "Resident"),
|
|
929
|
+
value: String(person._id ?? ""),
|
|
698
930
|
})));
|
|
699
931
|
|
|
932
|
+
// Says why somebody the operator can see in People Management is missing here.
|
|
933
|
+
// Without it the unit just looks empty and the screen looks broken.
|
|
934
|
+
const unitResidentNote = computed(() => {
|
|
935
|
+
if (!form.unit || loadingUnitPeople.value || !unenrollableUnitPeopleCount.value) return "";
|
|
936
|
+
const count = unenrollableUnitPeopleCount.value;
|
|
937
|
+
const subject = count === 1 ? "1 resident" : `${count} residents`;
|
|
938
|
+
const verb = count === 1 ? "is" : "are";
|
|
939
|
+
return `${subject} in this unit ${verb} not listed: HID enrollment needs a resident app account, and ${count === 1 ? "that person has" : "they have"} none yet.`;
|
|
940
|
+
});
|
|
941
|
+
|
|
942
|
+
const blockPlaceholder = computed(() => {
|
|
943
|
+
if (loadingOccupancy.value) return "Loading...";
|
|
944
|
+
if (occupancyLoaded.value && !blockOptions.value.length) {
|
|
945
|
+
return "No occupied units at this site";
|
|
946
|
+
}
|
|
947
|
+
return "Select block";
|
|
948
|
+
});
|
|
949
|
+
|
|
950
|
+
const unitResidentPlaceholder = computed(() => {
|
|
951
|
+
if (!form.unit) return "Select a unit first";
|
|
952
|
+
if (loadingUnitPeople.value) return "Loading residents...";
|
|
953
|
+
if (enrollableUnitPeople.value.length) return "Select a resident";
|
|
954
|
+
// The two empty cases are different problems with different fixes, so they
|
|
955
|
+
// do not share a sentence: nobody lives here, versus nobody here can be
|
|
956
|
+
// enrolled yet. `unitResidentNote` carries the detail for the second.
|
|
957
|
+
return unitPeople.value.length
|
|
958
|
+
? "No resident here can be enrolled yet"
|
|
959
|
+
: "No residents in this unit";
|
|
960
|
+
});
|
|
961
|
+
|
|
962
|
+
// Names the HID user that is in the way, so the operator can go and edit it
|
|
963
|
+
// rather than being told only that something is wrong.
|
|
964
|
+
const residentConflictMessage = computed(() => {
|
|
965
|
+
const conflict = residentConflict.value;
|
|
966
|
+
if (!conflict) return "";
|
|
967
|
+
const label = [getName(conflict), formatHidUid(conflict.hidUserId)]
|
|
968
|
+
.filter(Boolean)
|
|
969
|
+
.join(" · ");
|
|
970
|
+
return label
|
|
971
|
+
? `Already enrolled on this reader as ${label}. Edit that HID user instead of enrolling again.`
|
|
972
|
+
: "Already enrolled on this reader. Edit that HID user instead of enrolling again.";
|
|
973
|
+
});
|
|
974
|
+
|
|
700
975
|
const cardForm = reactive({
|
|
701
976
|
cardType: "pacs" as "pacs" | "csn",
|
|
702
977
|
facilityCode: "",
|
|
@@ -821,16 +1096,49 @@ async function loadUsers() {
|
|
|
821
1096
|
|
|
822
1097
|
loading.value = true;
|
|
823
1098
|
try {
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
1099
|
+
// `userType: "user"` is REQUIRED here, not a nicety. The reader keeps
|
|
1100
|
+
// visitors in the same `users` table, marked `user_type_id = 1`, and the
|
|
1101
|
+
// API's default is `all`. Visitor rows are written by our own visitor-QR
|
|
1102
|
+
// issuance and are never removed - revoke only pushes `end_time` into the
|
|
1103
|
+
// past - so without this filter the enrollment roster counts every visitor
|
|
1104
|
+
// pass ever issued and drifts further from the reader's own Users screen
|
|
1105
|
+
// with each one. This screen enrolls and edits real people; visitors are
|
|
1106
|
+
// owned by the visitor module.
|
|
1107
|
+
let clientFiltersVisitors = false;
|
|
1108
|
+
let response: unknown;
|
|
1109
|
+
try {
|
|
1110
|
+
response = await getReaderUsers(selectedReaderId.value, {
|
|
1111
|
+
page: page.value,
|
|
1112
|
+
limit: limit.value,
|
|
1113
|
+
search: search.value.trim(),
|
|
1114
|
+
status: status.value.toLowerCase() as "mapped" | "unmapped" | "",
|
|
1115
|
+
userType: "user",
|
|
1116
|
+
});
|
|
1117
|
+
} catch (error: unknown) {
|
|
1118
|
+
if (!isUnsupportedUserTypeFilter(error)) throw error;
|
|
1119
|
+
|
|
1120
|
+
// A deployed API can lag behind this shared layer. Keep the roster
|
|
1121
|
+
// correct on one that has not added `userType` yet, the same way
|
|
1122
|
+
// HidReaderUserRoster does, rather than failing the whole screen.
|
|
1123
|
+
clientFiltersVisitors = true;
|
|
1124
|
+
response = await getReaderUsers(selectedReaderId.value, {
|
|
1125
|
+
page: 1,
|
|
1126
|
+
limit: 100,
|
|
1127
|
+
search: search.value.trim(),
|
|
1128
|
+
status: status.value.toLowerCase() as "mapped" | "unmapped" | "",
|
|
1129
|
+
});
|
|
1130
|
+
}
|
|
830
1131
|
const responseRecord = toRecord(response);
|
|
831
1132
|
const responseData = toRecord(responseRecord.data);
|
|
832
1133
|
const responseItems = responseRecord.items ?? responseData.items ?? [];
|
|
833
|
-
const
|
|
1134
|
+
const allItems = (Array.isArray(responseItems) ? responseItems : []).map(toHidUser);
|
|
1135
|
+
const matchingItems = clientFiltersVisitors
|
|
1136
|
+
? allItems.filter((user) => !isVisitorUser(user))
|
|
1137
|
+
: allItems;
|
|
1138
|
+
const pageStart = (page.value - 1) * limit.value;
|
|
1139
|
+
const pageItems = clientFiltersVisitors
|
|
1140
|
+
? matchingItems.slice(pageStart, pageStart + limit.value)
|
|
1141
|
+
: matchingItems;
|
|
834
1142
|
administratorUserIds.value = new Set(
|
|
835
1143
|
pageItems
|
|
836
1144
|
.filter((user) => user.isAdministrator === true)
|
|
@@ -838,9 +1146,17 @@ async function loadUsers() {
|
|
|
838
1146
|
.filter((userId: number | undefined): userId is number => Boolean(userId)),
|
|
839
1147
|
);
|
|
840
1148
|
users.value = pageItems;
|
|
841
|
-
total.value =
|
|
842
|
-
|
|
843
|
-
|
|
1149
|
+
total.value = clientFiltersVisitors
|
|
1150
|
+
? matchingItems.length
|
|
1151
|
+
: Number(responseRecord.total ?? responseData.total ?? users.value.length);
|
|
1152
|
+
pages.value = clientFiltersVisitors
|
|
1153
|
+
? Math.max(1, Math.ceil(total.value / limit.value))
|
|
1154
|
+
: Number(responseRecord.pages ?? responseData.pages ?? 1);
|
|
1155
|
+
// The server's `pageRange` counts the unfiltered page, so it cannot be
|
|
1156
|
+
// trusted once this screen has done the filtering itself.
|
|
1157
|
+
serverPageRange.value = clientFiltersVisitors
|
|
1158
|
+
? ""
|
|
1159
|
+
: String(responseRecord.pageRange ?? responseData.pageRange ?? "");
|
|
844
1160
|
if (props.cardManagement) {
|
|
845
1161
|
await loadVisibleUserCards(users.value);
|
|
846
1162
|
}
|
|
@@ -870,6 +1186,10 @@ function resetForm() {
|
|
|
870
1186
|
form.registration = "";
|
|
871
1187
|
form.isAdministrator = false;
|
|
872
1188
|
form.accessPin = "";
|
|
1189
|
+
form.password = "";
|
|
1190
|
+
passwordSet.value = false;
|
|
1191
|
+
showPassword.value = false;
|
|
1192
|
+
removePasswordRequested.value = false;
|
|
873
1193
|
pinEnrolled.value = false;
|
|
874
1194
|
showPin.value = false;
|
|
875
1195
|
removePinRequested.value = false;
|
|
@@ -879,32 +1199,165 @@ function resetForm() {
|
|
|
879
1199
|
facialEnrolled.value = false;
|
|
880
1200
|
form.subjectCategory = "resident";
|
|
881
1201
|
form.subjectId = "";
|
|
1202
|
+
residentConflict.value = null;
|
|
1203
|
+
checkingResident.value = false;
|
|
882
1204
|
}
|
|
883
1205
|
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
1206
|
+
|
|
1207
|
+
/** Surface what the API actually said - a bare "unable to load" hides the
|
|
1208
|
+
* difference between a permission refusal, a bad id and a server fault. */
|
|
1209
|
+
function apiReason(error: unknown) {
|
|
1210
|
+
const record = toRecord(error);
|
|
1211
|
+
const data = toRecord(record.data);
|
|
1212
|
+
return toText(data.message) || toText(record.message) || toText(record.statusMessage);
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1215
|
+
// Called when the Block select is first touched, not when the dialog opens.
|
|
1216
|
+
async function ensureOccupancy() {
|
|
1217
|
+
if (!props.site || occupancyLoaded.value || loadingOccupancy.value) return;
|
|
1218
|
+
loadingOccupancy.value = true;
|
|
1219
|
+
try {
|
|
1220
|
+
const response = toRecord(await getOccupiedStructure(props.site, {
|
|
1221
|
+
type: OCCUPANT_TYPES,
|
|
1222
|
+
status: "active",
|
|
1223
|
+
}));
|
|
1224
|
+
const data = toRecord(response.data);
|
|
1225
|
+
const blocks = response.blocks ?? data.blocks ?? [];
|
|
1226
|
+
occupiedBlocks.value = (Array.isArray(blocks) ? blocks : []) as OccupiedBlock[];
|
|
1227
|
+
occupancyLoaded.value = true;
|
|
1228
|
+
} catch (error: unknown) {
|
|
1229
|
+
console.error("Unable to load occupied units:", error);
|
|
1230
|
+
occupiedBlocks.value = [];
|
|
1231
|
+
const reason = apiReason(error);
|
|
1232
|
+
showToast(
|
|
1233
|
+
reason ? `Unable to load units: ${reason}` : "Unable to load units for this site.",
|
|
1234
|
+
"error",
|
|
1235
|
+
);
|
|
1236
|
+
} finally {
|
|
1237
|
+
loadingOccupancy.value = false;
|
|
889
1238
|
}
|
|
890
|
-
|
|
1239
|
+
}
|
|
1240
|
+
|
|
1241
|
+
async function loadUnitPeople() {
|
|
1242
|
+
unitPeople.value = [];
|
|
1243
|
+
if (!form.unit) return;
|
|
1244
|
+
loadingUnitPeople.value = true;
|
|
891
1245
|
try {
|
|
892
|
-
const response = await
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
category: form.subjectCategory,
|
|
896
|
-
page: 1,
|
|
897
|
-
limit: 500,
|
|
1246
|
+
const response = await getPeopleByUnit(form.unit, {
|
|
1247
|
+
status: "active",
|
|
1248
|
+
type: OCCUPANT_TYPES,
|
|
898
1249
|
});
|
|
899
|
-
|
|
1250
|
+
const record = toRecord(response);
|
|
1251
|
+
const rows = Array.isArray(response)
|
|
1252
|
+
? response
|
|
1253
|
+
: record.data ?? record.items ?? [];
|
|
1254
|
+
unitPeople.value = (Array.isArray(rows) ? rows : []) as UnitPerson[];
|
|
1255
|
+
} catch (error: unknown) {
|
|
1256
|
+
console.error("Unable to load residents for the unit:", error);
|
|
1257
|
+
const reason = apiReason(error);
|
|
1258
|
+
showToast(
|
|
1259
|
+
reason ? `Unable to load residents: ${reason}` : "Unable to load residents for this unit.",
|
|
1260
|
+
"error",
|
|
1261
|
+
);
|
|
900
1262
|
} finally {
|
|
901
|
-
|
|
1263
|
+
loadingUnitPeople.value = false;
|
|
902
1264
|
}
|
|
903
1265
|
}
|
|
904
1266
|
|
|
905
|
-
|
|
1267
|
+
function onBlockChanged() {
|
|
1268
|
+
form.level = "";
|
|
1269
|
+
form.unit = "";
|
|
1270
|
+
unitPeople.value = [];
|
|
1271
|
+
clearResidentSelection();
|
|
1272
|
+
}
|
|
1273
|
+
|
|
1274
|
+
// Wrapper `@click`/`@focusin` on the Block select: load once, on first touch.
|
|
1275
|
+
async function onBlockOpened() {
|
|
1276
|
+
await ensureOccupancy();
|
|
1277
|
+
}
|
|
1278
|
+
|
|
1279
|
+
function onLevelChanged() {
|
|
1280
|
+
form.unit = "";
|
|
1281
|
+
unitPeople.value = [];
|
|
1282
|
+
clearResidentSelection();
|
|
1283
|
+
}
|
|
1284
|
+
|
|
1285
|
+
async function onUnitChanged() {
|
|
1286
|
+
clearResidentSelection();
|
|
1287
|
+
await loadUnitPeople();
|
|
1288
|
+
}
|
|
1289
|
+
|
|
1290
|
+
function clearResidentSelection() {
|
|
906
1291
|
form.subjectId = "";
|
|
907
|
-
|
|
1292
|
+
residentConflict.value = null;
|
|
1293
|
+
// Name only ever mirrors a chosen resident, so it clears with the choice.
|
|
1294
|
+
if (!selectedUser.value) form.name = "";
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1297
|
+
// The auto-fill the whole cascade exists for.
|
|
1298
|
+
async function onResidentChanged() {
|
|
1299
|
+
const person = unitPeople.value.find(
|
|
1300
|
+
(item) => String(item._id) === String(form.subjectId),
|
|
1301
|
+
);
|
|
1302
|
+
form.name = String(person?.name ?? "");
|
|
1303
|
+
await checkResidentEnrollment();
|
|
1304
|
+
}
|
|
1305
|
+
|
|
1306
|
+
/**
|
|
1307
|
+
* The HID user this resident already holds on the selected reader, or null.
|
|
1308
|
+
*
|
|
1309
|
+
* `subject`, not `person`. The same resident is stored under different ids
|
|
1310
|
+
* depending on which screen wrote the row - the permissions screen keys on
|
|
1311
|
+
* their user account, this screen on the record the picker offered - so a
|
|
1312
|
+
* filter on one field alone reports "not enrolled" for somebody who plainly is.
|
|
1313
|
+
* `subject` follows the record to its account and matches every link field,
|
|
1314
|
+
* which is exactly what the server does before it accepts an enrollment.
|
|
1315
|
+
*
|
|
1316
|
+
* Reader-scoped by the endpoint itself.
|
|
1317
|
+
*/
|
|
1318
|
+
async function findResidentIdentity(readerId: string, personId: string) {
|
|
1319
|
+
const response = await getIdentities(readerId, {
|
|
1320
|
+
page: 1,
|
|
1321
|
+
// A resident should hold at most one, but ask for a few: on the edit screen
|
|
1322
|
+
// the first row back can be the very identity being edited, and skipping it
|
|
1323
|
+
// must not hide a real second one behind it.
|
|
1324
|
+
limit: 10,
|
|
1325
|
+
subject: personId,
|
|
1326
|
+
});
|
|
1327
|
+
const responseRecord = toRecord(response);
|
|
1328
|
+
const responseData = toRecord(responseRecord.data);
|
|
1329
|
+
const responseItems =
|
|
1330
|
+
responseRecord.items ?? responseData.items ?? responseData.identities ?? [];
|
|
1331
|
+
const identities = (Array.isArray(responseItems) ? responseItems : []).map(toHidUser);
|
|
1332
|
+
const editingId = String(selectedUser.value?._id ?? "");
|
|
1333
|
+
|
|
1334
|
+
return (
|
|
1335
|
+
identities.find((identity) => !editingId || String(identity._id ?? "") !== editingId) ?? null
|
|
1336
|
+
);
|
|
1337
|
+
}
|
|
1338
|
+
|
|
1339
|
+
/**
|
|
1340
|
+
* Sets `residentConflict` for the currently selected resident.
|
|
1341
|
+
*
|
|
1342
|
+
* Fails OPEN: if the lookup itself errors the operator is not blocked, because
|
|
1343
|
+
* the server refuses the duplicate anyway. This is a courtesy check that keeps
|
|
1344
|
+
* a doomed enrollment off the physical reader, not the guard itself.
|
|
1345
|
+
*/
|
|
1346
|
+
async function checkResidentEnrollment() {
|
|
1347
|
+
residentConflict.value = null;
|
|
1348
|
+
const readerId = selectedReaderId.value || form.reader || readers.value[0]?._id;
|
|
1349
|
+
if (!readerId || !form.subjectId || form.subjectCategory !== "resident") return null;
|
|
1350
|
+
|
|
1351
|
+
checkingResident.value = true;
|
|
1352
|
+
try {
|
|
1353
|
+
residentConflict.value = await findResidentIdentity(readerId, form.subjectId);
|
|
1354
|
+
return residentConflict.value;
|
|
1355
|
+
} catch (error: unknown) {
|
|
1356
|
+
console.error("Unable to check whether this resident is already enrolled:", error);
|
|
1357
|
+
return null;
|
|
1358
|
+
} finally {
|
|
1359
|
+
checkingResident.value = false;
|
|
1360
|
+
}
|
|
908
1361
|
}
|
|
909
1362
|
|
|
910
1363
|
async function openEnroll() {
|
|
@@ -916,7 +1369,6 @@ async function openEnroll() {
|
|
|
916
1369
|
]);
|
|
917
1370
|
form.hidUserId = hidUserId;
|
|
918
1371
|
form.registration = registration;
|
|
919
|
-
await loadSubjectCandidates();
|
|
920
1372
|
formDialog.value = true;
|
|
921
1373
|
}
|
|
922
1374
|
|
|
@@ -931,6 +1383,10 @@ async function openEdit(user: HidUser) {
|
|
|
931
1383
|
form.registration = user.registration ?? "";
|
|
932
1384
|
form.isAdministrator = hasAdministratorRule(user);
|
|
933
1385
|
form.accessPin = "";
|
|
1386
|
+
form.password = "";
|
|
1387
|
+
showPassword.value = false;
|
|
1388
|
+
removePasswordRequested.value = false;
|
|
1389
|
+
passwordSet.value = Boolean(user.metadata?.passwordSet);
|
|
934
1390
|
pinEnrolled.value = Boolean(user.metadata?.pinEnrolled);
|
|
935
1391
|
removePinRequested.value = false;
|
|
936
1392
|
form.photoPreview = "";
|
|
@@ -941,17 +1397,31 @@ async function openEdit(user: HidUser) {
|
|
|
941
1397
|
? "service_provider"
|
|
942
1398
|
: "property_management";
|
|
943
1399
|
form.subjectId = String(user.person || user.member || user.serviceProvider || "");
|
|
944
|
-
|
|
1400
|
+
// The resident this user already holds is not a conflict with itself. A real
|
|
1401
|
+
// one only appears if the operator reassigns the row to somebody else.
|
|
1402
|
+
residentConflict.value = null;
|
|
1403
|
+
// The location is not drawn when editing, but it is still carried: these
|
|
1404
|
+
// three form fields are what `saveUser` writes back and what `buildUnitLabel`
|
|
1405
|
+
// resolves into the Unit column, so a save must not blank them.
|
|
1406
|
+
//
|
|
1407
|
+
// `ensureOccupancy` is what lets `buildUnitLabel` turn them back into names.
|
|
1408
|
+
// The unit's residents are loaded too, because the Resident select IS drawn
|
|
1409
|
+
// here and its options come from that list - without it the select shows the
|
|
1410
|
+
// stored id instead of a name.
|
|
1411
|
+
await ensureOccupancy();
|
|
1412
|
+
if (form.unit) await loadUnitPeople();
|
|
945
1413
|
selectedPhotoFile.value = null;
|
|
946
1414
|
removePhotoRequested.value = false;
|
|
947
1415
|
formDialog.value = true;
|
|
948
1416
|
|
|
949
1417
|
try {
|
|
950
|
-
const
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
1418
|
+
const hidUserId = toHidNumericId(user.hidUserId);
|
|
1419
|
+
const [pinStatus, passwordStatus] = await Promise.all([
|
|
1420
|
+
getUserPinStatus(form.reader, hidUserId),
|
|
1421
|
+
getUserPasswordStatus(form.reader, hidUserId),
|
|
1422
|
+
]);
|
|
1423
|
+
pinEnrolled.value = Boolean(pinStatus?.data?.pinEnrolled);
|
|
1424
|
+
passwordSet.value = Boolean(passwordStatus?.data?.passwordSet);
|
|
955
1425
|
} catch {
|
|
956
1426
|
// Preserve the last known status if the reader is temporarily offline.
|
|
957
1427
|
}
|
|
@@ -1030,12 +1500,28 @@ function onPhotoChange(event: Event) {
|
|
|
1030
1500
|
async function saveUser() {
|
|
1031
1501
|
const readerId =
|
|
1032
1502
|
selectedReaderId.value || form.reader || readers.value[0]?._id;
|
|
1033
|
-
|
|
1034
|
-
|
|
1503
|
+
// A resident is required to ENROL, because an identity has to be linked to
|
|
1504
|
+
// somebody. It is not required to edit: the reader holds users we never
|
|
1505
|
+
// enrolled, and changing a photo, a PIN or a password on one of those is a
|
|
1506
|
+
// reader-side operation that has nothing to say about who they are. Demanding
|
|
1507
|
+
// a resident there refuses a save for a field the dialog does not even draw.
|
|
1508
|
+
const missing = !readerId
|
|
1509
|
+
? "a reader"
|
|
1510
|
+
: !selectedUser.value && !form.subjectId
|
|
1511
|
+
? "a resident"
|
|
1512
|
+
: !form.name
|
|
1513
|
+
? "a name"
|
|
1514
|
+
: !form.hidUserId
|
|
1515
|
+
? "an ID"
|
|
1516
|
+
: !form.registration
|
|
1517
|
+
? "a registration number"
|
|
1518
|
+
: "";
|
|
1519
|
+
if (missing) {
|
|
1520
|
+
showToast(`This HID user needs ${missing} before it can be saved.`, "error");
|
|
1035
1521
|
return;
|
|
1036
1522
|
}
|
|
1037
1523
|
if (form.accessPin && !/^\d{1,32}$/.test(form.accessPin)) {
|
|
1038
|
-
showToast("
|
|
1524
|
+
showToast("PIN must contain numbers only.", "error");
|
|
1039
1525
|
return;
|
|
1040
1526
|
}
|
|
1041
1527
|
if (selectedPhotoFile.value && (!selectedReader.value?.portalId || !selectedReader.value?.portalName)) {
|
|
@@ -1043,6 +1529,16 @@ async function saveUser() {
|
|
|
1043
1529
|
return;
|
|
1044
1530
|
}
|
|
1045
1531
|
|
|
1532
|
+
// Re-asked here, not trusted from the select: the dialog can sit open while
|
|
1533
|
+
// somebody else enrolls the same resident, and the reader is only ever
|
|
1534
|
+
// written to below this line. A duplicate caught here costs one request; the
|
|
1535
|
+
// same duplicate caught by the server costs a created HID user and a rollback.
|
|
1536
|
+
const alreadyEnrolled = await checkResidentEnrollment();
|
|
1537
|
+
if (alreadyEnrolled) {
|
|
1538
|
+
showToast(residentConflictMessage.value, "error");
|
|
1539
|
+
return;
|
|
1540
|
+
}
|
|
1541
|
+
|
|
1046
1542
|
saving.value = true;
|
|
1047
1543
|
let newlyCreatedHidUserId: number | undefined;
|
|
1048
1544
|
try {
|
|
@@ -1056,22 +1552,33 @@ async function saveUser() {
|
|
|
1056
1552
|
return;
|
|
1057
1553
|
}
|
|
1058
1554
|
|
|
1555
|
+
// The link is sent only when the form actually holds one. Sending
|
|
1556
|
+
// `person: ""` is not "leave it alone", it is "clear it": the server reads
|
|
1557
|
+
// an empty string as a link being removed and then refuses the write for
|
|
1558
|
+
// having no subject at all. Omitting the keys is what makes it keep the
|
|
1559
|
+
// subject the record already has.
|
|
1560
|
+
const subjectLink = form.subjectId
|
|
1561
|
+
? {
|
|
1562
|
+
person: form.subjectCategory === "resident" ? form.subjectId : "",
|
|
1563
|
+
member: form.subjectCategory === "property_management" ? form.subjectId : "",
|
|
1564
|
+
serviceProvider: form.subjectCategory === "service_provider" ? form.subjectId : "",
|
|
1565
|
+
type: (form.subjectCategory === "resident"
|
|
1566
|
+
? "resident"
|
|
1567
|
+
: form.subjectCategory === "service_provider"
|
|
1568
|
+
? "contractor"
|
|
1569
|
+
: "staff") as
|
|
1570
|
+
| "resident"
|
|
1571
|
+
| "staff"
|
|
1572
|
+
| "contractor"
|
|
1573
|
+
| "visitor"
|
|
1574
|
+
| "unknown",
|
|
1575
|
+
}
|
|
1576
|
+
: {};
|
|
1577
|
+
|
|
1059
1578
|
const payload = {
|
|
1060
1579
|
hidUserId: String(hidUser.id),
|
|
1061
1580
|
registration: form.registration,
|
|
1062
|
-
|
|
1063
|
-
member: form.subjectCategory === "property_management" ? form.subjectId : "",
|
|
1064
|
-
serviceProvider: form.subjectCategory === "service_provider" ? form.subjectId : "",
|
|
1065
|
-
type: (form.subjectCategory === "resident"
|
|
1066
|
-
? "resident"
|
|
1067
|
-
: form.subjectCategory === "service_provider"
|
|
1068
|
-
? "contractor"
|
|
1069
|
-
: "staff") as
|
|
1070
|
-
| "resident"
|
|
1071
|
-
| "staff"
|
|
1072
|
-
| "contractor"
|
|
1073
|
-
| "visitor"
|
|
1074
|
-
| "unknown",
|
|
1581
|
+
...subjectLink,
|
|
1075
1582
|
status: "active" as const,
|
|
1076
1583
|
metadata: {
|
|
1077
1584
|
name: form.name,
|
|
@@ -1088,6 +1595,7 @@ async function saveUser() {
|
|
|
1088
1595
|
imageTimestamp: selectedUser.value?.metadata?.imageTimestamp || "",
|
|
1089
1596
|
facialScores: selectedUser.value?.metadata?.facialScores || {},
|
|
1090
1597
|
pinEnrolled: pinEnrolled.value,
|
|
1598
|
+
passwordSet: passwordSet.value,
|
|
1091
1599
|
hidPhysicalCards: selectedUser.value?.metadata?.hidPhysicalCards || [],
|
|
1092
1600
|
},
|
|
1093
1601
|
};
|
|
@@ -1097,17 +1605,22 @@ async function saveUser() {
|
|
|
1097
1605
|
const facialResult = await syncFacialImage(readerId, hidUser.id);
|
|
1098
1606
|
applyFacialResult(payload.metadata, facialResult);
|
|
1099
1607
|
payload.metadata.pinEnrolled = await syncAccessPin(readerId, hidUser.id);
|
|
1608
|
+
payload.metadata.passwordSet = await syncPassword(readerId, hidUser.id);
|
|
1100
1609
|
if (selectedUser.value._id) {
|
|
1101
1610
|
await updateIdentity(selectedUser.value._id, payload);
|
|
1102
|
-
} else {
|
|
1611
|
+
} else if (form.subjectId) {
|
|
1103
1612
|
await saveIdentityOnReader(readerId, payload);
|
|
1104
1613
|
}
|
|
1614
|
+
// else: a user the reader holds and we have never linked. The photo, PIN
|
|
1615
|
+
// and password above are already on the device; creating an identity for
|
|
1616
|
+
// it would need a subject we deliberately no longer ask for here.
|
|
1105
1617
|
} else {
|
|
1106
1618
|
const created = await createHidUserOnReader(readerId, hidUser);
|
|
1107
1619
|
if (created) newlyCreatedHidUserId = hidUser.id;
|
|
1108
1620
|
const facialResult = await syncFacialImage(readerId, hidUser.id);
|
|
1109
1621
|
applyFacialResult(payload.metadata, facialResult);
|
|
1110
1622
|
payload.metadata.pinEnrolled = await syncAccessPin(readerId, hidUser.id);
|
|
1623
|
+
payload.metadata.passwordSet = await syncPassword(readerId, hidUser.id);
|
|
1111
1624
|
await saveIdentityOnReader(readerId, payload);
|
|
1112
1625
|
selectedReaderId.value = readerId;
|
|
1113
1626
|
}
|
|
@@ -1143,6 +1656,25 @@ async function saveUser() {
|
|
|
1143
1656
|
}
|
|
1144
1657
|
}
|
|
1145
1658
|
|
|
1659
|
+
async function syncPassword(readerId: string, hidUserId: number) {
|
|
1660
|
+
// Mirrors syncAccessPin. Removal wins over a typed value, and a blank field
|
|
1661
|
+
// means "leave whatever is on the reader alone" - the hash cannot be read
|
|
1662
|
+
// back, so blank can never mean "clear it".
|
|
1663
|
+
if (removePasswordRequested.value) {
|
|
1664
|
+
await deleteUserPassword(readerId, hidUserId);
|
|
1665
|
+
passwordSet.value = false;
|
|
1666
|
+
form.password = "";
|
|
1667
|
+
return false;
|
|
1668
|
+
}
|
|
1669
|
+
if (form.password) {
|
|
1670
|
+
await setUserPassword(readerId, hidUserId, form.password);
|
|
1671
|
+
form.password = "";
|
|
1672
|
+
passwordSet.value = true;
|
|
1673
|
+
return true;
|
|
1674
|
+
}
|
|
1675
|
+
return passwordSet.value;
|
|
1676
|
+
}
|
|
1677
|
+
|
|
1146
1678
|
async function syncAccessPin(readerId: string, hidUserId: number) {
|
|
1147
1679
|
if (removePinRequested.value) {
|
|
1148
1680
|
await deleteUserPin(readerId, hidUserId);
|
|
@@ -1447,6 +1979,21 @@ function toHidUserObject(identity: Pick<HidUser, "hidUserId" | "name" | "registr
|
|
|
1447
1979
|
};
|
|
1448
1980
|
}
|
|
1449
1981
|
|
|
1982
|
+
function isVisitorUser(user: HidUser) {
|
|
1983
|
+
// The reader marks visitors with `user_type_id = 1`; a real user leaves the
|
|
1984
|
+
// field null. `metadata.hidUserTypeId` is what our API forwards it as.
|
|
1985
|
+
return Number(user.metadata?.hidUserTypeId ?? user.user_type_id) === 1;
|
|
1986
|
+
}
|
|
1987
|
+
|
|
1988
|
+
function isUnsupportedUserTypeFilter(error: unknown) {
|
|
1989
|
+
const record = toRecord(error);
|
|
1990
|
+
const data = toRecord(record.data);
|
|
1991
|
+
const message = toText(data.message) || toText(record.message);
|
|
1992
|
+
const normalized = message.toLowerCase();
|
|
1993
|
+
return normalized.includes("usertype")
|
|
1994
|
+
&& (normalized.includes("not allowed") || normalized.includes("unknown"));
|
|
1995
|
+
}
|
|
1996
|
+
|
|
1450
1997
|
function toHidNumericId(value: unknown) {
|
|
1451
1998
|
const raw = String(value ?? "").trim();
|
|
1452
1999
|
if (!raw) return undefined;
|
|
@@ -1649,8 +2196,21 @@ function getPhysicalCardSubtitle(card: HidCard) {
|
|
|
1649
2196
|
}
|
|
1650
2197
|
|
|
1651
2198
|
function buildUnitLabel() {
|
|
1652
|
-
|
|
1653
|
-
|
|
2199
|
+
// `form.block/level/unit` hold ObjectIds, so the label has to resolve them
|
|
2200
|
+
// back to names through the occupancy tree. Joining the raw values would
|
|
2201
|
+
// stamp "665f.../665f.../665f..." onto the record and into the Unit column.
|
|
2202
|
+
const block = occupiedBlocks.value.find((item) => String(item._id ?? "") === form.block);
|
|
2203
|
+
const level = (block?.levels ?? []).find((item) => String(item._id ?? "") === form.level);
|
|
2204
|
+
const unit = (level?.units ?? []).find((item) => String(item._id ?? "") === form.unit);
|
|
2205
|
+
const parts = [
|
|
2206
|
+
formatBlockTitle(block),
|
|
2207
|
+
String(level?.name ?? ""),
|
|
2208
|
+
String(unit?.name ?? ""),
|
|
2209
|
+
].filter(Boolean);
|
|
2210
|
+
// Editing a record enrolled before the cascade existed: keep its stored
|
|
2211
|
+
// label rather than blanking it.
|
|
2212
|
+
if (!parts.length) return String(selectedUser.value?.metadata?.unitLabel ?? "");
|
|
2213
|
+
return parts.join(" / ");
|
|
1654
2214
|
}
|
|
1655
2215
|
|
|
1656
2216
|
function getName(user?: HidUser | null) {
|
|
@@ -1937,12 +2497,6 @@ function toHidCard(value: unknown): HidCard {
|
|
|
1937
2497
|
max-width: 320px;
|
|
1938
2498
|
}
|
|
1939
2499
|
|
|
1940
|
-
.small-title {
|
|
1941
|
-
font-size: 14px;
|
|
1942
|
-
font-weight: 700;
|
|
1943
|
-
color: var(--text);
|
|
1944
|
-
}
|
|
1945
|
-
|
|
1946
2500
|
/* Was `#4f5a66` / `#e53935` - the same two greys on both themes. */
|
|
1947
2501
|
.field-label {
|
|
1948
2502
|
color: var(--text2);
|
|
@@ -1964,12 +2518,42 @@ function toHidCard(value: unknown): HidCard {
|
|
|
1964
2518
|
line-height: 1.45;
|
|
1965
2519
|
}
|
|
1966
2520
|
|
|
2521
|
+
/* Same line, saying the field is refused rather than explained. `--err` is the
|
|
2522
|
+
token the required-field asterisk already uses. */
|
|
2523
|
+
.field-hint--error {
|
|
2524
|
+
color: var(--err);
|
|
2525
|
+
}
|
|
2526
|
+
|
|
1967
2527
|
.photo-wrap {
|
|
1968
2528
|
display: grid;
|
|
1969
2529
|
place-items: center;
|
|
1970
2530
|
margin-bottom: 14px;
|
|
1971
2531
|
}
|
|
1972
2532
|
|
|
2533
|
+
.photo-facial {
|
|
2534
|
+
margin: 10px 0 0;
|
|
2535
|
+
text-align: center;
|
|
2536
|
+
}
|
|
2537
|
+
|
|
2538
|
+
/* The same small muted word `.field-label` uses, so the caption reads as a
|
|
2539
|
+
field label rather than as a second heading. */
|
|
2540
|
+
.photo-facial__label {
|
|
2541
|
+
display: block;
|
|
2542
|
+
color: var(--muted);
|
|
2543
|
+
font-size: 12px;
|
|
2544
|
+
font-weight: 600;
|
|
2545
|
+
}
|
|
2546
|
+
|
|
2547
|
+
.photo-facial__value {
|
|
2548
|
+
display: block;
|
|
2549
|
+
margin-top: 2px;
|
|
2550
|
+
font-size: 13.5px;
|
|
2551
|
+
font-weight: 500;
|
|
2552
|
+
/* The reader's reference is a long unbroken number; let it wrap rather than
|
|
2553
|
+
widen the dialog. */
|
|
2554
|
+
word-break: break-all;
|
|
2555
|
+
}
|
|
2556
|
+
|
|
1973
2557
|
.photo-button {
|
|
1974
2558
|
width: 120px;
|
|
1975
2559
|
height: 120px;
|
|
@@ -2143,25 +2727,6 @@ function toHidCard(value: unknown): HidCard {
|
|
|
2143
2727
|
color: var(--muted);
|
|
2144
2728
|
}
|
|
2145
2729
|
|
|
2146
|
-
/* The split footer bar. The handoff does not draw one, so the SHAPE is the
|
|
2147
|
-
screen's own; only the colours change - `#062d42` was a fixed navy that sat
|
|
2148
|
-
on the dark card unchanged. Same treatment as panel 2. */
|
|
2149
|
-
.action-cancel,
|
|
2150
|
-
.action-submit {
|
|
2151
|
-
flex: 1;
|
|
2152
|
-
border-radius: 0;
|
|
2153
|
-
}
|
|
2154
|
-
|
|
2155
|
-
.action-cancel {
|
|
2156
|
-
background: var(--card);
|
|
2157
|
-
color: var(--text2);
|
|
2158
|
-
}
|
|
2159
|
-
|
|
2160
|
-
.action-submit {
|
|
2161
|
-
background: var(--accent-strong);
|
|
2162
|
-
color: var(--on-accent-strong);
|
|
2163
|
-
}
|
|
2164
|
-
|
|
2165
2730
|
@media (max-width: 960px) {
|
|
2166
2731
|
.hid-user-filters :deep(.app-field),
|
|
2167
2732
|
.hid-user-filters :deep(.app-select) {
|