@7365admin1/layer-common 4.21.3 → 4.21.4-staging.340
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/CHANGELOG.md +4 -4
- package/components/AnprCameraBadge.vue +220 -0
- package/components/DocumentForm.vue +407 -112
- package/components/DocumentManagement.vue +213 -12
- package/components/EntryPass/QrTemplatePreview.vue +21 -25
- package/components/EntryPassInformation.vue +119 -24
- package/components/Facility/BookingSetup.vue +63 -0
- package/components/HidAccessLogDashboard.vue +29 -5
- package/components/HidAccessPermissions.vue +424 -0
- package/components/HidIntercomManagement.vue +48 -1
- package/components/HidProfileQrCode.vue +323 -0
- package/components/HidReaderManagement.vue +26 -0
- package/components/HidReaderUserRoster.vue +32 -2
- package/components/HidUserEnrollment.vue +833 -152
- package/components/Input/NRICNumber.vue +14 -2
- package/components/InvitationClientForm.vue +19 -1
- package/components/PlateNumberDisplay.vue +105 -1
- package/components/VehicleForm.vue +324 -3
- package/components/VehicleManagement.vue +346 -51
- package/components/VisitorManagement.vue +434 -5
- package/composables/useAccessManagement.ts +5 -0
- package/composables/useDocument.ts +7 -0
- package/composables/useFacility.ts +11 -0
- package/composables/useHidAmico.ts +97 -0
- package/composables/useHidNavigation.ts +25 -1
- package/composables/usePeople.ts +19 -0
- package/composables/useVehicle.ts +101 -1
- package/composables/useWebUsb.ts +14 -11
- package/package.json +1 -1
- package/pages/[org]/[site]/access-mgmt/administrator/index.vue +1 -1
- package/pages/[org]/[site]/access-mgmt/hid-cards/index.vue +1 -1
- package/pages/[org]/[site]/access-mgmt/hid-qr-code/index.vue +23 -0
- package/pages/[org]/[site]/access-mgmt/hid-readers/index.vue +1 -1
- package/types/document.d.ts +14 -0
- package/types/facility.d.ts +4 -0
- package/types/people.d.ts +5 -2
- package/types/vehicle.d.ts +57 -2
- package/utils/hid-permission-assignments.ts +190 -0
- package/utils/vehicle-actions.ts +45 -17
|
@@ -8,8 +8,12 @@
|
|
|
8
8
|
:counter="maxlength"
|
|
9
9
|
@input="onInput"
|
|
10
10
|
:loading="loading"
|
|
11
|
+
:type="masked && !shown ? 'password' : 'text'"
|
|
12
|
+
:append-inner-icon="masked ? (shown ? 'mdi-eye-off' : 'mdi-eye') : undefined"
|
|
13
|
+
autocomplete="off"
|
|
11
14
|
outlined
|
|
12
15
|
clearable
|
|
16
|
+
@click:append-inner="shown = !shown"
|
|
13
17
|
/>
|
|
14
18
|
</template>
|
|
15
19
|
|
|
@@ -31,9 +35,16 @@ const props = defineProps({
|
|
|
31
35
|
loading: {
|
|
32
36
|
type: Boolean,
|
|
33
37
|
default: false
|
|
38
|
+
},
|
|
39
|
+
/** Shown as *** with an eye to reveal it, like a password. */
|
|
40
|
+
masked: {
|
|
41
|
+
type: Boolean,
|
|
42
|
+
default: false
|
|
34
43
|
}
|
|
35
44
|
})
|
|
36
45
|
|
|
46
|
+
const shown = ref(false)
|
|
47
|
+
|
|
37
48
|
const emit = defineEmits(['update:modelValue'])
|
|
38
49
|
|
|
39
50
|
const model = defineModel({required: true})
|
|
@@ -41,8 +52,9 @@ const model = defineModel({required: true})
|
|
|
41
52
|
function onInput(event) {
|
|
42
53
|
const value = typeof event === 'string' ? event : event?.target?.value || ''
|
|
43
54
|
|
|
44
|
-
|
|
45
|
-
|
|
55
|
+
// Same rule as the Whitelist (Bulk) sheet (`bulkIdNumber`): capitals,
|
|
56
|
+
// digits and symbols such as - or /, but no spaces, commas or dots.
|
|
57
|
+
const formatted = value.replace(/[\s,.]/g, '').toUpperCase()
|
|
46
58
|
|
|
47
59
|
model.value = formatted || ""
|
|
48
60
|
}
|
|
@@ -388,9 +388,27 @@ watch(
|
|
|
388
388
|
const roles = ref<any[]>([])
|
|
389
389
|
const { getRoles } = useRole()
|
|
390
390
|
|
|
391
|
+
/*
|
|
392
|
+
* `type` is the ROLE type, not the service the client subscribes to, and the
|
|
393
|
+
* only caller (`ClientMain.vue` "Invite Client") passes no `app` prop -- so
|
|
394
|
+
* this sent `type: ""` and the endpoint applied no type filter at all. The
|
|
395
|
+
* dropdown therefore listed every org-less role of every type, which includes
|
|
396
|
+
* the platform's OWN staff roles (`type: "admin"` -- the two rows the console's
|
|
397
|
+
* `/super-admin/role-permissions` screen edits). Offering a Seven365 console
|
|
398
|
+
* staff role on a CLIENT invitation is the defect.
|
|
399
|
+
*
|
|
400
|
+
* A client admin's role is `type: "organization"`, which is what the client
|
|
401
|
+
* roles screen (`org/[organization]/roles-permissions.vue`) already lists. This
|
|
402
|
+
* narrows to exactly that. It is a narrowing of this one picker only: no role
|
|
403
|
+
* changes, no permission changes, and the org-less `organization` roles that
|
|
404
|
+
* were already being picked are all still offered.
|
|
405
|
+
*
|
|
406
|
+
* Keying off the selected service instead would empty the dropdown -- no
|
|
407
|
+
* org-less role carries a service type -- so `props.app` is not the filter.
|
|
408
|
+
*/
|
|
391
409
|
const { data: roleData, refresh: refreshRoles } = await useLazyAsyncData(
|
|
392
410
|
"roles",
|
|
393
|
-
() => getRoles({ org: org.value?._id, type:
|
|
411
|
+
() => getRoles({ org: org.value?._id, type: "organization", limit: 50 }),
|
|
394
412
|
{ watch: [() => props.app] }
|
|
395
413
|
)
|
|
396
414
|
|
|
@@ -1,6 +1,34 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div class="d-flex align-center ga-2 flex-wrap">
|
|
3
|
-
|
|
3
|
+
<!-- Each vehicle number with its ANPR camera badge beside it. -->
|
|
4
|
+
<template v-if="shownPlates.length">
|
|
5
|
+
<span v-for="plate in shownPlates" :key="plate._id ?? plate.plateNumber" class="plate-display__plate">
|
|
6
|
+
<span class="d-inline-flex align-center ga-1">
|
|
7
|
+
{{ plate.plateNumber }}
|
|
8
|
+
<AnprCameraBadge
|
|
9
|
+
v-if="showCameras"
|
|
10
|
+
:cameras="plate.anprCameras ?? []"
|
|
11
|
+
:plate-number="plate.plateNumber"
|
|
12
|
+
:plate-id="plate._id ?? ''"
|
|
13
|
+
:status="plate.status ?? ''"
|
|
14
|
+
:type="plate.type ?? ''"
|
|
15
|
+
:active-counts="activeCounts"
|
|
16
|
+
@synced="(result) => emit('synced', result)"
|
|
17
|
+
/>
|
|
18
|
+
</span>
|
|
19
|
+
<!-- A season pass's expiry under its number: green while valid, red
|
|
20
|
+
once it has passed - the camera no longer opens for it. -->
|
|
21
|
+
<span
|
|
22
|
+
v-if="showExpiry && expiryOf(plate)"
|
|
23
|
+
class="plate-display__expiry"
|
|
24
|
+
:class="expiryOf(plate)!.expired ? 'plate-display__expiry--expired' : 'plate-display__expiry--valid'"
|
|
25
|
+
>
|
|
26
|
+
<v-icon :icon="expiryOf(plate)!.expired ? 'mdi-alert-circle' : 'mdi-calendar-check'" size="13" />
|
|
27
|
+
{{ expiryOf(plate)!.expired ? "Expired" : "Expires" }} {{ expiryOf(plate)!.label }}
|
|
28
|
+
</span>
|
|
29
|
+
</span>
|
|
30
|
+
</template>
|
|
31
|
+
<span v-else-if="formatted">
|
|
4
32
|
{{ formatted }}
|
|
5
33
|
</span>
|
|
6
34
|
|
|
@@ -30,9 +58,55 @@ const props = defineProps({
|
|
|
30
58
|
showAll: {
|
|
31
59
|
type: Boolean,
|
|
32
60
|
default: false
|
|
61
|
+
},
|
|
62
|
+
/** A season pass's expiry date under each vehicle number. */
|
|
63
|
+
showExpiry: {
|
|
64
|
+
type: Boolean,
|
|
65
|
+
default: false
|
|
66
|
+
},
|
|
67
|
+
/** Active ANPR cameras per list at the site - lets the badge offer Sync. */
|
|
68
|
+
activeCounts: {
|
|
69
|
+
type: Object as PropType<{ allowed: number; blocked: number } | null>,
|
|
70
|
+
default: null
|
|
71
|
+
},
|
|
72
|
+
/** The ANPR camera badge beside each vehicle number. */
|
|
73
|
+
showCameras: {
|
|
74
|
+
type: Boolean,
|
|
75
|
+
default: false
|
|
33
76
|
}
|
|
34
77
|
})
|
|
35
78
|
|
|
79
|
+
/** Same as the Expiry Date field in the form: 09/21/2036 07:35 PM. */
|
|
80
|
+
function formatExpiry(date: Date): string {
|
|
81
|
+
const pad = (n: number) => String(n).padStart(2, "0")
|
|
82
|
+
const hours = date.getHours()
|
|
83
|
+
const hour12 = hours % 12 || 12
|
|
84
|
+
return (
|
|
85
|
+
`${pad(date.getMonth() + 1)}/${pad(date.getDate())}/${date.getFullYear()} ` +
|
|
86
|
+
`${pad(hour12)}:${pad(date.getMinutes())} ${hours < 12 ? "AM" : "PM"}`
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** The plate's expiry, as a date and whether it has passed. */
|
|
91
|
+
function expiryOf(plate: any): { label: string; expired: boolean } | null {
|
|
92
|
+
if (!plate?.end) return null
|
|
93
|
+
const end = new Date(plate.end)
|
|
94
|
+
if (Number.isNaN(end.getTime())) return null
|
|
95
|
+
return {
|
|
96
|
+
label: formatExpiry(end),
|
|
97
|
+
expired: end.getTime() <= Date.now(),
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const emit = defineEmits<{
|
|
102
|
+
(event: "synced", result: { ok: boolean; message: string }): void
|
|
103
|
+
}>()
|
|
104
|
+
|
|
105
|
+
const shownPlates = computed<any[]>(() => {
|
|
106
|
+
const plates = (props.plateNumbers ?? []).filter((v: any) => v?.plateNumber)
|
|
107
|
+
return props.showAll ? plates : plates.slice(0, 2)
|
|
108
|
+
})
|
|
109
|
+
|
|
36
110
|
const formatted = computed(() => {
|
|
37
111
|
if (!props.plateNumbers?.length) return props.defaultValue || ""
|
|
38
112
|
|
|
@@ -54,3 +128,33 @@ const extraCount = computed(() => {
|
|
|
54
128
|
: 0
|
|
55
129
|
})
|
|
56
130
|
</script>
|
|
131
|
+
|
|
132
|
+
<style scoped>
|
|
133
|
+
.plate-display__plate {
|
|
134
|
+
display: inline-flex;
|
|
135
|
+
flex-direction: column;
|
|
136
|
+
gap: 2px;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
.plate-display__expiry {
|
|
140
|
+
display: inline-flex;
|
|
141
|
+
align-items: center;
|
|
142
|
+
gap: 3px;
|
|
143
|
+
width: fit-content;
|
|
144
|
+
padding: 0 6px;
|
|
145
|
+
border-radius: 999px;
|
|
146
|
+
font-size: 11px;
|
|
147
|
+
font-weight: 600;
|
|
148
|
+
line-height: 18px;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
.plate-display__expiry--valid {
|
|
152
|
+
color: rgb(var(--v-theme-success));
|
|
153
|
+
background: rgba(var(--v-theme-success), 0.12);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
.plate-display__expiry--expired {
|
|
157
|
+
color: rgb(var(--v-theme-error));
|
|
158
|
+
background: rgba(var(--v-theme-error), 0.12);
|
|
159
|
+
}
|
|
160
|
+
</style>
|
|
@@ -69,6 +69,27 @@
|
|
|
69
69
|
the Season Pass dialog report. An empty field has nothing unresolved
|
|
70
70
|
to redraw, so it has nothing to gain from the remount.
|
|
71
71
|
-->
|
|
72
|
+
<!-- A Block Listed vehicle's block / level / unit: taken from the
|
|
73
|
+
visitor transaction it was blocked from, and shown read-only -
|
|
74
|
+
here and when the vehicle is edited later. -->
|
|
75
|
+
<template v-if="readonlyLocation">
|
|
76
|
+
<v-col cols="12">
|
|
77
|
+
<InputLabel class="text-capitalize" title="Block" />
|
|
78
|
+
<v-text-field :model-value="readonlyLocation.block || 'N/A'" density="comfortable" readonly
|
|
79
|
+
class="class-readonly" />
|
|
80
|
+
</v-col>
|
|
81
|
+
<v-col cols="12">
|
|
82
|
+
<InputLabel class="text-capitalize" title="Level" />
|
|
83
|
+
<v-text-field :model-value="readonlyLocation.level || 'N/A'" density="comfortable" readonly
|
|
84
|
+
class="class-readonly" />
|
|
85
|
+
</v-col>
|
|
86
|
+
<v-col cols="12">
|
|
87
|
+
<InputLabel class="text-capitalize" title="Unit" />
|
|
88
|
+
<v-text-field :model-value="readonlyLocation.unit || 'N/A'" density="comfortable" readonly
|
|
89
|
+
class="class-readonly" />
|
|
90
|
+
</v-col>
|
|
91
|
+
</template>
|
|
92
|
+
|
|
72
93
|
<v-col v-if="shouldShowField('block')" cols="12">
|
|
73
94
|
<InputLabel class="text-capitalize" title="Block" required />
|
|
74
95
|
<v-autocomplete
|
|
@@ -131,6 +152,7 @@
|
|
|
131
152
|
<InputNRICNumber
|
|
132
153
|
v-model="vehicle.nric"
|
|
133
154
|
density="comfortable"
|
|
155
|
+
masked
|
|
134
156
|
:disabled="
|
|
135
157
|
disablePrefilledInputs &&
|
|
136
158
|
type !== 'blocklist' &&
|
|
@@ -139,6 +161,23 @@
|
|
|
139
161
|
/>
|
|
140
162
|
</v-col>
|
|
141
163
|
|
|
164
|
+
<!-- Category is chosen only when ADDING a Block Listed vehicle in
|
|
165
|
+
Vehicle Mgmt. Blocked from a visitor transaction it is that
|
|
166
|
+
transaction's type and is shown read-only; editing a vehicle
|
|
167
|
+
never changes it. -->
|
|
168
|
+
<v-col v-if="showCategoryField" cols="12">
|
|
169
|
+
<InputLabel class="text-capitalize" title="Category" required />
|
|
170
|
+
<v-select
|
|
171
|
+
v-model="vehicle.category"
|
|
172
|
+
:items="blocklistCategoryOptions"
|
|
173
|
+
item-title="title"
|
|
174
|
+
item-value="value"
|
|
175
|
+
density="comfortable"
|
|
176
|
+
:readonly="!!prop.presetCategory"
|
|
177
|
+
:rules="[requiredRule]"
|
|
178
|
+
/>
|
|
179
|
+
</v-col>
|
|
180
|
+
|
|
142
181
|
<v-col v-if="shouldShowField('name')" cols="12">
|
|
143
182
|
<v-row>
|
|
144
183
|
<v-col cols="12">
|
|
@@ -236,7 +275,8 @@
|
|
|
236
275
|
</v-col>
|
|
237
276
|
</v-row>
|
|
238
277
|
|
|
239
|
-
|
|
278
|
+
<!-- One vehicle number per Block Listed vehicle. -->
|
|
279
|
+
<AppButton v-if="type !== 'blocklist'" variant="ghost" icon="mdi-plus" @click="addPlate">
|
|
240
280
|
Add Plate
|
|
241
281
|
</AppButton>
|
|
242
282
|
</template>
|
|
@@ -361,6 +401,50 @@
|
|
|
361
401
|
</AppButton>
|
|
362
402
|
</div>
|
|
363
403
|
|
|
404
|
+
<!--
|
|
405
|
+
A plate the site already holds - in any tab, with any status. Rather
|
|
406
|
+
than refusing, say where it is and let the person update that record:
|
|
407
|
+
Update saves what they entered on it and moves it to this form's tab.
|
|
408
|
+
-->
|
|
409
|
+
<v-dialog v-model="showExistingDialog" max-width="520" persistent>
|
|
410
|
+
<v-card class="screen-modal">
|
|
411
|
+
<div class="vehicle-form__head">
|
|
412
|
+
<v-card-title>Vehicle already exists</v-card-title>
|
|
413
|
+
<AppButton variant="icon" icon="mdi-close" aria-label="Close" @click="cancelExistingUpdate" />
|
|
414
|
+
</div>
|
|
415
|
+
<div class="screen-modal__body vehicle-existing__body">
|
|
416
|
+
<p v-for="item in existingPlates" :key="item._id" class="vehicle-existing__line">
|
|
417
|
+
<strong>{{ item.plateNumber }}</strong> is already in
|
|
418
|
+
<strong>{{ tabLabel(item.view) }}</strong>
|
|
419
|
+
(status: <strong>{{ formatVehicleStatus(item.status).label }}</strong>).
|
|
420
|
+
</p>
|
|
421
|
+
<p class="vehicle-existing__line">
|
|
422
|
+
<template v-if="existingPlates.every((item) => item.view === targetView)">
|
|
423
|
+
Update will save the details you entered on
|
|
424
|
+
{{ existingPlates.length > 1 ? "them" : "it" }} and keep
|
|
425
|
+
{{ existingPlates.length > 1 ? "them" : "it" }} in
|
|
426
|
+
<strong>{{ tabLabel(targetView) }}</strong>.
|
|
427
|
+
</template>
|
|
428
|
+
<template v-else>
|
|
429
|
+
Update will save the details you entered on
|
|
430
|
+
{{ existingPlates.length > 1 ? "them" : "it" }} and move
|
|
431
|
+
{{ existingPlates.length > 1 ? "them" : "it" }} to
|
|
432
|
+
<strong>{{ tabLabel(targetView) }}</strong>.
|
|
433
|
+
</template>
|
|
434
|
+
<template v-if="newPlatesAfterExisting.length">
|
|
435
|
+
{{ newPlatesAfterExisting.join(", ") }}
|
|
436
|
+
{{ newPlatesAfterExisting.length > 1 ? "are" : "is" }} new and will be added.
|
|
437
|
+
</template>
|
|
438
|
+
Do you want to proceed?
|
|
439
|
+
</p>
|
|
440
|
+
</div>
|
|
441
|
+
<div class="vehicle-form__footer">
|
|
442
|
+
<AppButton variant="ghost" :disabled="processing" @click="cancelExistingUpdate">Cancel</AppButton>
|
|
443
|
+
<AppButton :disabled="processing" @click="confirmExistingUpdate">Update</AppButton>
|
|
444
|
+
</div>
|
|
445
|
+
</v-card>
|
|
446
|
+
</v-dialog>
|
|
447
|
+
|
|
364
448
|
<v-dialog v-model="showMatchingPeopleDialog" max-width="700" persistent>
|
|
365
449
|
<v-card class="screen-modal vehicle-match" :loading="checkingUnit">
|
|
366
450
|
<div class="vehicle-form__head">
|
|
@@ -465,6 +549,31 @@ const prop = defineProps({
|
|
|
465
549
|
type: String,
|
|
466
550
|
default: "",
|
|
467
551
|
},
|
|
552
|
+
/**
|
|
553
|
+
* Blocking from a visitor transaction: the Block Listed category taken from
|
|
554
|
+
* its type (guest -> visitor, contractor / delivery / pick-up / drop-off as
|
|
555
|
+
* they are), and the plate to block.
|
|
556
|
+
*/
|
|
557
|
+
presetCategory: {
|
|
558
|
+
type: String,
|
|
559
|
+
default: "",
|
|
560
|
+
},
|
|
561
|
+
prefillPlate: {
|
|
562
|
+
type: String,
|
|
563
|
+
default: "",
|
|
564
|
+
},
|
|
565
|
+
/**
|
|
566
|
+
* Blocking from a visitor transaction: the visit's block / level / unit,
|
|
567
|
+
* saved on the Block Listed vehicle and shown read-only.
|
|
568
|
+
*/
|
|
569
|
+
presetLocation: {
|
|
570
|
+
type: Object as PropType<{
|
|
571
|
+
block?: { id: string; name: string };
|
|
572
|
+
level?: { id: string; name: string };
|
|
573
|
+
unit?: { id: string; name: string };
|
|
574
|
+
} | null>,
|
|
575
|
+
default: null,
|
|
576
|
+
},
|
|
468
577
|
});
|
|
469
578
|
|
|
470
579
|
const { requiredRule, debounce } = useUtils();
|
|
@@ -473,6 +582,8 @@ const {
|
|
|
473
582
|
getCustomSeasonPassTypes,
|
|
474
583
|
updateVehicle,
|
|
475
584
|
formatVehicleStatus,
|
|
585
|
+
checkExistingPlates,
|
|
586
|
+
moveVehicle,
|
|
476
587
|
} = useVehicle();
|
|
477
588
|
const { getSiteById, getSiteLevels, getSiteUnits } = useSiteSettings();
|
|
478
589
|
const { findPersonByNRICMultipleResult, getPeopleByUnit } = usePeople();
|
|
@@ -511,7 +622,90 @@ const vehicle = reactive<
|
|
|
511
622
|
plateNumber: "",
|
|
512
623
|
});
|
|
513
624
|
|
|
514
|
-
|
|
625
|
+
/**
|
|
626
|
+
* The read-only Block / Level / Unit of a Block Listed vehicle: from the
|
|
627
|
+
* visitor transaction when blocking from Visitor Mgmt, or the location the
|
|
628
|
+
* vehicle already has when it is edited. Null when there is none to show.
|
|
629
|
+
*/
|
|
630
|
+
const readonlyLocation = computed(() => {
|
|
631
|
+
if (prop.type !== "blocklist") return null;
|
|
632
|
+
|
|
633
|
+
if (prop.mode === "add") {
|
|
634
|
+
const loc = prop.presetLocation;
|
|
635
|
+
if (!loc) return null;
|
|
636
|
+
const out = {
|
|
637
|
+
block: loc.block?.name ?? "",
|
|
638
|
+
level: loc.level?.name ?? "",
|
|
639
|
+
unit: loc.unit?.name ?? "",
|
|
640
|
+
};
|
|
641
|
+
return out.block || out.level || out.unit ? out : null;
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
const data: any = prop.vehicleData ?? {};
|
|
645
|
+
const nameOf = (value: any) => {
|
|
646
|
+
if (!value) return "";
|
|
647
|
+
if (typeof value === "object") return String(value.name ?? "");
|
|
648
|
+
return String(prop.nameHints?.[String(value)] ?? "");
|
|
649
|
+
};
|
|
650
|
+
const hasAny = data.block || data.level || data.unit;
|
|
651
|
+
if (!hasAny) return null;
|
|
652
|
+
return {
|
|
653
|
+
block: nameOf(data.block),
|
|
654
|
+
level: nameOf(data.level),
|
|
655
|
+
unit: nameOf(data.unit) || String(data.unitName ?? ""),
|
|
656
|
+
};
|
|
657
|
+
});
|
|
658
|
+
|
|
659
|
+
const newPlateNumbers = ref<string[]>([prop.prefillPlate ? prop.prefillPlate : ""]);
|
|
660
|
+
|
|
661
|
+
type TBlocklistCategory = "visitor" | "contractor" | "delivery" | "pick-up" | "drop-off";
|
|
662
|
+
|
|
663
|
+
const BLOCKLIST_CATEGORY_LABELS: Record<TBlocklistCategory, string> = {
|
|
664
|
+
visitor: "Visitor",
|
|
665
|
+
contractor: "Contractor",
|
|
666
|
+
delivery: "Delivery",
|
|
667
|
+
"pick-up": "Pick-up",
|
|
668
|
+
"drop-off": "Drop-off",
|
|
669
|
+
};
|
|
670
|
+
|
|
671
|
+
function isBlocklistCategory(value: unknown): value is TBlocklistCategory {
|
|
672
|
+
return typeof value === "string" && value in BLOCKLIST_CATEGORY_LABELS;
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
/**
|
|
676
|
+
* Vehicle Mgmt offers Visitor and Contractor. A vehicle blocked from a visitor
|
|
677
|
+
* transaction brings its own type (Delivery, say), which is offered too so the
|
|
678
|
+
* field can show it.
|
|
679
|
+
*/
|
|
680
|
+
const blocklistCategoryOptions = computed(() => {
|
|
681
|
+
const values: TBlocklistCategory[] = ["visitor", "contractor"];
|
|
682
|
+
const extra = [prop.presetCategory, vehicle.category].filter(
|
|
683
|
+
(c): c is TBlocklistCategory => isBlocklistCategory(c) && !values.includes(c)
|
|
684
|
+
);
|
|
685
|
+
return [...values, ...new Set(extra)].map((value) => ({
|
|
686
|
+
title: BLOCKLIST_CATEGORY_LABELS[value],
|
|
687
|
+
value,
|
|
688
|
+
}));
|
|
689
|
+
});
|
|
690
|
+
|
|
691
|
+
/**
|
|
692
|
+
* The Category field is for ADDING a Block Listed vehicle only - editable in
|
|
693
|
+
* Vehicle Mgmt, read-only when it comes from a visitor transaction. Editing a
|
|
694
|
+
* vehicle does not show or change its category.
|
|
695
|
+
*/
|
|
696
|
+
const showCategoryField = computed(
|
|
697
|
+
() => prop.type === "blocklist" && prop.mode === "add"
|
|
698
|
+
);
|
|
699
|
+
|
|
700
|
+
/**
|
|
701
|
+
* What the server files the vehicle under: resident for a whitelist vehicle,
|
|
702
|
+
* season_pass for a season pass, visitor / contractor for a Block Listed one.
|
|
703
|
+
*/
|
|
704
|
+
function categoryForForm(formType: string, picked: unknown): TVehicle["category"] {
|
|
705
|
+
if (formType === "seasonpass") return "season_pass";
|
|
706
|
+
if (formType === "blocklist") return isBlocklistCategory(picked) ? picked : "visitor";
|
|
707
|
+
return "resident";
|
|
708
|
+
}
|
|
515
709
|
const disablePrefilledInputs = ref(true);
|
|
516
710
|
|
|
517
711
|
const blocksArray = ref<TDefaultOptionObj[]>([]);
|
|
@@ -686,6 +880,15 @@ if (prop.vehicleData) {
|
|
|
686
880
|
Object.assign(vehicle, existingVehicleData);
|
|
687
881
|
}
|
|
688
882
|
|
|
883
|
+
// Adding from a row copies that row's category (a resident's, say), and an
|
|
884
|
+
// older blocklist record may carry "Block Listed": a Block Listed vehicle
|
|
885
|
+
// starts as a visitor until the person picks.
|
|
886
|
+
if (showCategoryField.value && isBlocklistCategory(prop.presetCategory)) {
|
|
887
|
+
vehicle.category = prop.presetCategory;
|
|
888
|
+
} else if (showCategoryField.value && !isBlocklistCategory(vehicle.category)) {
|
|
889
|
+
vehicle.category = "visitor";
|
|
890
|
+
}
|
|
891
|
+
|
|
689
892
|
const {
|
|
690
893
|
data: blocksListData,
|
|
691
894
|
refresh: refreshBlockListData,
|
|
@@ -886,6 +1089,90 @@ function showMessage(msg: string, color: string) {
|
|
|
886
1089
|
messageSnackbar.value = true;
|
|
887
1090
|
}
|
|
888
1091
|
|
|
1092
|
+
/* ---- a plate the site already holds ------------------------------------ */
|
|
1093
|
+
|
|
1094
|
+
type TExistingPlate = Awaited<ReturnType<typeof checkExistingPlates>>["items"][number];
|
|
1095
|
+
|
|
1096
|
+
const showExistingDialog = ref(false);
|
|
1097
|
+
const existingPlates = ref<TExistingPlate[]>([]);
|
|
1098
|
+
const pendingPayload = ref<Partial<TVehiclePayload> | null>(null);
|
|
1099
|
+
|
|
1100
|
+
const TAB_LABELS: Record<string, string> = {
|
|
1101
|
+
residents: "Residents",
|
|
1102
|
+
"season-passes": "Season Passes",
|
|
1103
|
+
"block-listed": "Block Listed",
|
|
1104
|
+
};
|
|
1105
|
+
|
|
1106
|
+
function tabLabel(view: string) {
|
|
1107
|
+
return TAB_LABELS[view] ?? view;
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
/** The tab this form adds to. */
|
|
1111
|
+
const targetView = computed(() =>
|
|
1112
|
+
prop.type === "blocklist"
|
|
1113
|
+
? "block-listed"
|
|
1114
|
+
: prop.type === "seasonpass"
|
|
1115
|
+
? "season-passes"
|
|
1116
|
+
: "residents"
|
|
1117
|
+
);
|
|
1118
|
+
|
|
1119
|
+
const plateKey = (plate: unknown) => String(plate ?? "").replace(/\s+/g, "").toUpperCase();
|
|
1120
|
+
|
|
1121
|
+
function formPlates(payload: Partial<TVehiclePayload> | null): string[] {
|
|
1122
|
+
const plates = payload?.plateNumber;
|
|
1123
|
+
return (Array.isArray(plates) ? plates : [plates])
|
|
1124
|
+
.map((p) => String(p ?? "").trim())
|
|
1125
|
+
.filter(Boolean);
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
/** The plates in the form that the site does NOT hold yet. */
|
|
1129
|
+
const newPlatesAfterExisting = computed(() => {
|
|
1130
|
+
const taken = new Set(
|
|
1131
|
+
existingPlates.value.flatMap((item) => [plateKey(item.plateNumber), plateKey(item.input)])
|
|
1132
|
+
);
|
|
1133
|
+
return formPlates(pendingPayload.value).filter((p) => !taken.has(plateKey(p)));
|
|
1134
|
+
});
|
|
1135
|
+
|
|
1136
|
+
function cancelExistingUpdate() {
|
|
1137
|
+
showExistingDialog.value = false;
|
|
1138
|
+
existingPlates.value = [];
|
|
1139
|
+
pendingPayload.value = null;
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
async function confirmExistingUpdate() {
|
|
1143
|
+
const payload = pendingPayload.value;
|
|
1144
|
+
if (!payload) return;
|
|
1145
|
+
|
|
1146
|
+
errorMessage.value = "";
|
|
1147
|
+
processing.value = true;
|
|
1148
|
+
const messages: string[] = [];
|
|
1149
|
+
try {
|
|
1150
|
+
// Everything the form was filled in with, for the existing record - the
|
|
1151
|
+
// plate is the record's own, so it is not sent.
|
|
1152
|
+
const { plateNumber: _plates, ...details } = payload as any;
|
|
1153
|
+
for (const item of existingPlates.value) {
|
|
1154
|
+
const res = await moveVehicle(item._id, { ...details, site: prop.site });
|
|
1155
|
+
if (res?.message) messages.push(res.message);
|
|
1156
|
+
}
|
|
1157
|
+
|
|
1158
|
+
const remaining = newPlatesAfterExisting.value;
|
|
1159
|
+
if (remaining.length) {
|
|
1160
|
+
const res: any = await addVehicle({ ...payload, plateNumber: remaining });
|
|
1161
|
+
messages.push(res?.data || res?.message || "Vehicle added successfully.");
|
|
1162
|
+
}
|
|
1163
|
+
|
|
1164
|
+
showExistingDialog.value = false;
|
|
1165
|
+
showMessage(messages.join(" ") || "Vehicle updated.", "success");
|
|
1166
|
+
emit("done");
|
|
1167
|
+
} catch (error: any) {
|
|
1168
|
+
// Shown under the form. A record moved before the failure stays moved.
|
|
1169
|
+
showExistingDialog.value = false;
|
|
1170
|
+
errorMessage.value = errorConverter(error);
|
|
1171
|
+
} finally {
|
|
1172
|
+
processing.value = false;
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
|
|
889
1176
|
async function submit() {
|
|
890
1177
|
errorMessage.value = "";
|
|
891
1178
|
|
|
@@ -946,7 +1233,7 @@ async function submit() {
|
|
|
946
1233
|
if (prop.mode === "add") {
|
|
947
1234
|
payload = {
|
|
948
1235
|
...payload,
|
|
949
|
-
category,
|
|
1236
|
+
category: categoryForForm(prop.type || String(type), category),
|
|
950
1237
|
site,
|
|
951
1238
|
org,
|
|
952
1239
|
plateNumber: newPlateNumbers.value,
|
|
@@ -990,6 +1277,14 @@ async function submit() {
|
|
|
990
1277
|
payload = {
|
|
991
1278
|
...payload,
|
|
992
1279
|
remarks,
|
|
1280
|
+
// The visit's location, when blocked from a visitor transaction.
|
|
1281
|
+
...(prop.mode === "add" && prop.presetLocation
|
|
1282
|
+
? {
|
|
1283
|
+
...(prop.presetLocation.block?.id && { block: prop.presetLocation.block.id }),
|
|
1284
|
+
...(prop.presetLocation.level?.id && { level: prop.presetLocation.level.id }),
|
|
1285
|
+
...(prop.presetLocation.unit?.id && { unit: prop.presetLocation.unit.id }),
|
|
1286
|
+
}
|
|
1287
|
+
: {}),
|
|
993
1288
|
};
|
|
994
1289
|
}
|
|
995
1290
|
|
|
@@ -998,6 +1293,22 @@ async function submit() {
|
|
|
998
1293
|
// camera is switched off saves the vehicle but registers nothing, and this
|
|
999
1294
|
// used to announce "Vehicle added successfully." over the top of that.
|
|
1000
1295
|
if (prop.mode === "add") {
|
|
1296
|
+
// A plate the site already holds is not refused outright: say which
|
|
1297
|
+
// tab and status it is under and offer to update it instead.
|
|
1298
|
+
const plates = formPlates(payload);
|
|
1299
|
+
if (plates.length) {
|
|
1300
|
+
const found = await checkExistingPlates({
|
|
1301
|
+
site: String(payload.site || prop.site),
|
|
1302
|
+
plateNumbers: plates,
|
|
1303
|
+
});
|
|
1304
|
+
if (found?.items?.length) {
|
|
1305
|
+
existingPlates.value = found.items;
|
|
1306
|
+
pendingPayload.value = payload;
|
|
1307
|
+
showExistingDialog.value = true;
|
|
1308
|
+
return;
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1311
|
+
|
|
1001
1312
|
const res: any = await addVehicle(payload);
|
|
1002
1313
|
showMessage(res?.data || res?.message || "Vehicle added successfully.", "success");
|
|
1003
1314
|
} else if (prop.mode === "edit") {
|
|
@@ -1286,4 +1597,14 @@ onMounted(() => {
|
|
|
1286
1597
|
gap: 8px;
|
|
1287
1598
|
padding: 16px 20px 20px;
|
|
1288
1599
|
}
|
|
1600
|
+
|
|
1601
|
+
.vehicle-existing__body {
|
|
1602
|
+
padding: 4px 20px 0;
|
|
1603
|
+
}
|
|
1604
|
+
|
|
1605
|
+
.vehicle-existing__line {
|
|
1606
|
+
margin: 0 0 10px;
|
|
1607
|
+
font-size: var(--fs-cell);
|
|
1608
|
+
color: var(--text);
|
|
1609
|
+
}
|
|
1289
1610
|
</style>
|