@7365admin1/layer-common 4.183.0 → 4.185.0
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 +21 -4
- package/components/BuildingForm.vue +28 -5
- package/components/BuildingManagement/buildings.vue +3 -3
- package/components/BuildingManagement/units.vue +2 -2
- package/components/SiteAccessRequests.vue +288 -0
- package/components/VehicleForm.vue +76 -2
- package/components/VehicleManagement.vue +18 -12
- package/components/VehicleQrStickerDialog.vue +23 -5
- package/composables/useCustomerSite.ts +50 -0
- package/composables/useVehicle.ts +23 -2
- package/package.json +1 -1
- package/utils/building-block.ts +14 -1
- package/utils/site-join-request.ts +162 -0
- package/utils/vehicle-qr-blank.ts +60 -0
- package/utils/vehicle-qr-design.ts +12 -2
- package/utils/vehicle-qr-sticker.ts +47 -17
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @iservice365/layer-common
|
|
2
2
|
|
|
3
|
+
## 4.185.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 08b96a7: Vehicle QR: blank stickers can be printed without the long code ("Sticker code (long code): Hide" - QR + sticker number only; a sticker with no number keeps its code). Add Vehicle can link a blank sticker as the vehicle is added (next sticker number pre-selected), and Link QR sticker lists stickers by number with the next one first and finds them by number.
|
|
8
|
+
|
|
9
|
+
## 4.184.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- d25e96e: Add Site: check the typed site name against other companies' sites and request access from the managing agent instead of creating a duplicate. New `useCustomerSite` calls (name-check, join requests), `utils/site-join-request` helpers and the `SiteAccessRequests` list (approve / reject / cancel).
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- 463259c: Vehicle QR stickers: a blank (not yet linked) sticker printed on a shape with a name tag (heart, star, shield ...) now keeps its sticker number on the sticker itself, under its code, on the print sheet and in Save as image. Before, the number went only to the cut-off strip.
|
|
18
|
+
- 7f86142: Building Management: Block Name is back as an optional field (add and edit). A facility block such as "Barbeque Pit" keeps its own name; leaving it empty still saves "Blk N". Block and unit lists show "Blk 7 - Barbeque Pit" when a block has its own name. Names only need to be unique within a site.
|
|
19
|
+
|
|
3
20
|
## 4.183.0
|
|
4
21
|
|
|
5
22
|
### Minor Changes
|
|
@@ -4011,11 +4028,11 @@ Monthly report: a month that had patrols opens the list of that month's patrol r
|
|
|
4011
4028
|
`utils/console-tier.ts` + `composables/useConsoleTier.ts` mirror the server's
|
|
4012
4029
|
own rule from two endpoints the console already calls, unprojected:
|
|
4013
4030
|
|
|
4014
|
-
|
|
4015
|
-
|
|
4031
|
+
GET /api/members/user/:user/app/admin the Seven365 staff membership
|
|
4032
|
+
GET /api/roles/id/:role that membership's role document
|
|
4016
4033
|
|
|
4017
|
-
|
|
4018
|
-
|
|
4034
|
+
owner = member.type === "admin" && role.type === "admin" && role.default === true
|
|
4035
|
+
staff = member.type === "admin" && role.type === "admin"
|
|
4019
4036
|
|
|
4020
4037
|
`role.default` is the marker because it is the only property of a platform
|
|
4021
4038
|
staff role no API caller can set - `role.controller.ts` validates create and
|
|
@@ -19,6 +19,18 @@
|
|
|
19
19
|
</v-row>
|
|
20
20
|
</v-col>
|
|
21
21
|
|
|
22
|
+
<v-col cols="12">
|
|
23
|
+
<v-row no-gutters>
|
|
24
|
+
<InputLabel class="text-capitalize font-weight-bold" title="Block Name (optional)" />
|
|
25
|
+
<v-col cols="12">
|
|
26
|
+
<v-text-field v-model="building.name" class="filter-field" density="comfortable" maxlength="60"
|
|
27
|
+
:placeholder="building.block ? `Leave empty for Blk ${building.block}` : 'e.g. Barbeque Pit'"
|
|
28
|
+
hint="Use a name for a facility guards send visitors to, e.g. Barbeque Pit. Empty = Blk + Block No."
|
|
29
|
+
persistent-hint></v-text-field>
|
|
30
|
+
</v-col>
|
|
31
|
+
</v-row>
|
|
32
|
+
</v-col>
|
|
33
|
+
|
|
22
34
|
<v-col cols="6" class="mt-2">
|
|
23
35
|
<v-row no-gutters>
|
|
24
36
|
<InputLabel class="text-capitalize font-weight-bold" title="No. of Levels" required />
|
|
@@ -47,6 +59,12 @@
|
|
|
47
59
|
|
|
48
60
|
<v-expand-transition>
|
|
49
61
|
<v-row v-if="prop.mode === 'edit'" no-gutters class="px-6">
|
|
62
|
+
<v-col cols="12" class="mb-2">
|
|
63
|
+
<InputLabel class="text-capitalize font-weight-bold" title="Block Name (optional)" />
|
|
64
|
+
<v-text-field v-model="building.name" class="filter-field" density="comfortable" maxlength="60"
|
|
65
|
+
:placeholder="`Leave empty for Blk ${building.block}`"
|
|
66
|
+
hint="Empty = Blk + Block No. Another property may use the same name." persistent-hint></v-text-field>
|
|
67
|
+
</v-col>
|
|
50
68
|
<template v-for="(level, levelIndex) in building.levels" :key="levelIndex">
|
|
51
69
|
<v-col cols="12">
|
|
52
70
|
<v-row no-gutters>
|
|
@@ -187,7 +205,7 @@
|
|
|
187
205
|
|
|
188
206
|
<script setup lang="ts">
|
|
189
207
|
import InputLabel from './InputLabel.vue';
|
|
190
|
-
import {
|
|
208
|
+
import { blockNameFor, normaliseBlock, BLOCK_NO_MESSAGE } from "../utils/building-block";
|
|
191
209
|
|
|
192
210
|
const prop = defineProps({
|
|
193
211
|
site: {
|
|
@@ -353,7 +371,7 @@ async function submit() {
|
|
|
353
371
|
try {
|
|
354
372
|
if (prop.mode === "add") {
|
|
355
373
|
const buildingPayload = { ...building.value };
|
|
356
|
-
//
|
|
374
|
+
// The block's own name if typed (e.g. "Barbeque Pit"), else "Blk 3". Unique within this site only.
|
|
357
375
|
const blockNo = normaliseBlock(buildingPayload.block);
|
|
358
376
|
if (blockNo === null) {
|
|
359
377
|
message.value = BLOCK_NO_MESSAGE;
|
|
@@ -364,9 +382,9 @@ async function submit() {
|
|
|
364
382
|
message.value = `Block ${blockNo} already exists. Choose a different Block No.`;
|
|
365
383
|
return;
|
|
366
384
|
}
|
|
367
|
-
const name =
|
|
385
|
+
const name = blockNameFor(blockNo, buildingPayload.name);
|
|
368
386
|
if (prop.blocks.some((b) => b.name?.trim().toLowerCase() === name.toLowerCase() && b.block !== blockNo)) {
|
|
369
|
-
message.value = `Another block is already named "${name}".
|
|
387
|
+
message.value = `Another block in this site is already named "${name}". Choose a different name.`;
|
|
370
388
|
return;
|
|
371
389
|
}
|
|
372
390
|
|
|
@@ -390,8 +408,13 @@ async function submit() {
|
|
|
390
408
|
|
|
391
409
|
const newLevels = [...newLevelsArray.value, ...(activeNewLevelInput.value.trim() ? [activeNewLevelInput.value.trim()] : [])];
|
|
392
410
|
|
|
411
|
+
const editedName = blockNameFor(building.value.block, building.value.name);
|
|
412
|
+
if (prop.blocks.some((b: any) => b._id !== building.value._id && b.name?.trim().toLowerCase() === editedName.toLowerCase())) {
|
|
413
|
+
message.value = `Another block in this site is already named "${editedName}". Choose a different name.`;
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
393
416
|
await updateById(building.value._id ?? "", {
|
|
394
|
-
name:
|
|
417
|
+
name: editedName,
|
|
395
418
|
block: building.value.block,
|
|
396
419
|
// levels: building.value.levels,
|
|
397
420
|
buildingFiles: (building.value.buildingFiles as string[] || []).map((id) => ({ id, name: buildingFilesNames.value[id] ?? "" })),
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
<template #prepend-additional>
|
|
23
23
|
<AppField v-model="searchInput" search compact placeholder="Search" klass="app-toolbar__search" />
|
|
24
24
|
</template>
|
|
25
|
-
<template #item.block="{ value }">{{ value
|
|
25
|
+
<template #item.block="{ value, item }">{{ blockDisplay(value, (item as any)?.name) }}</template>
|
|
26
26
|
<template #item.createdAt="{ value }">
|
|
27
27
|
{{ new Date(value).toLocaleDateString() }}
|
|
28
28
|
</template>
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
<v-row no-gutters class="mb-4">
|
|
56
56
|
<v-col cols="12">
|
|
57
57
|
<strong>Block:</strong>
|
|
58
|
-
{{ selectedBuilding?.block ?
|
|
58
|
+
{{ selectedBuilding?.block ? blockDisplay(selectedBuilding.block, selectedBuilding?.name) : "N/A" }}
|
|
59
59
|
</v-col>
|
|
60
60
|
|
|
61
61
|
<v-col cols="12">
|
|
@@ -158,7 +158,7 @@
|
|
|
158
158
|
// Relative import, never Nuxt auto-import: this layer's `utils/` are auto-imported
|
|
159
159
|
// into the consuming apps but not reliably into the layer's own components.
|
|
160
160
|
import { levelCount } from "../../utils/data";
|
|
161
|
-
import {
|
|
161
|
+
import { blockDisplay } from "../../utils/building-block";
|
|
162
162
|
|
|
163
163
|
|
|
164
164
|
const props = defineProps({
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
<AppField v-model="searchInput" search compact placeholder="Search" klass="app-toolbar__search" />
|
|
51
51
|
</template>
|
|
52
52
|
<template #item.block="{ value, item }">
|
|
53
|
-
{{ value
|
|
53
|
+
{{ blockDisplay(value, (item as any)?.buildingName) }}
|
|
54
54
|
</template>
|
|
55
55
|
</TableMain>
|
|
56
56
|
|
|
@@ -174,7 +174,7 @@
|
|
|
174
174
|
|
|
175
175
|
<script setup lang="ts">
|
|
176
176
|
import useImportTemplates from "../../composables/useImportTemplates";
|
|
177
|
-
import {
|
|
177
|
+
import { blockDisplay } from "../../utils/building-block";
|
|
178
178
|
import { saveBlob } from "../../composables/useInventory";
|
|
179
179
|
import { useDisplay } from 'vuetify/lib/composables/display.mjs';
|
|
180
180
|
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<!--
|
|
3
|
+
Access requests (spec 2026-11-16-site-exists-ma-approval): another company
|
|
4
|
+
typed the name of one of our sites in Add Site and asked to be linked to it
|
|
5
|
+
instead of creating a duplicate. "Requests to approve" is what we answer as
|
|
6
|
+
the site's managing agent; "Our requests" is what we asked of others.
|
|
7
|
+
Same card-per-item layout as ClientInvitations.
|
|
8
|
+
-->
|
|
9
|
+
<div v-if="visibleBoxes.length">
|
|
10
|
+
<div class="screen-card-title mt-6 mb-2" data-test="sites-access-requests-title">Access requests</div>
|
|
11
|
+
<AppCard class="table-card" data-test="site-access-requests">
|
|
12
|
+
<CardToolbar :count="total ? `${total} request${total === 1 ? '' : 's'}` : ''">
|
|
13
|
+
<template #tabs>
|
|
14
|
+
<button
|
|
15
|
+
v-for="t in visibleBoxes"
|
|
16
|
+
:key="t.value"
|
|
17
|
+
type="button"
|
|
18
|
+
role="tab"
|
|
19
|
+
class="app-tab"
|
|
20
|
+
:class="{ 'app-tab--active': box === t.value }"
|
|
21
|
+
:aria-selected="box === t.value"
|
|
22
|
+
:data-test="`site-access-tab-${t.value}`"
|
|
23
|
+
@click="box = t.value"
|
|
24
|
+
>
|
|
25
|
+
{{ t.label }}
|
|
26
|
+
</button>
|
|
27
|
+
</template>
|
|
28
|
+
<template #right>
|
|
29
|
+
<v-select
|
|
30
|
+
v-model="status"
|
|
31
|
+
:items="statuses"
|
|
32
|
+
density="compact"
|
|
33
|
+
variant="outlined"
|
|
34
|
+
aria-label="Request status"
|
|
35
|
+
hide-details
|
|
36
|
+
style="min-width: 150px"
|
|
37
|
+
data-test="site-access-status"
|
|
38
|
+
/>
|
|
39
|
+
<AppButton variant="icon" icon="mdi-refresh" aria-label="Refresh" @click="load" />
|
|
40
|
+
<LocalPagination v-if="pages > 1" v-model="page" :length="pages" @update:value="load" />
|
|
41
|
+
</template>
|
|
42
|
+
</CardToolbar>
|
|
43
|
+
|
|
44
|
+
<div class="pa-4 d-flex flex-column ga-3">
|
|
45
|
+
<div v-if="loading" class="screen-hint">Loading…</div>
|
|
46
|
+
<div v-else-if="loadError" class="text-error" role="alert">{{ loadError }}</div>
|
|
47
|
+
<div v-else-if="!items.length" class="screen-hint" data-test="site-access-empty">{{ emptyLine }}</div>
|
|
48
|
+
|
|
49
|
+
<AppCard v-for="item in items" :key="item._id" class="site-access">
|
|
50
|
+
<div class="d-flex align-start ga-3 pa-4">
|
|
51
|
+
<v-avatar color="primary" variant="tonal" size="44">
|
|
52
|
+
<v-icon>mdi-domain-plus</v-icon>
|
|
53
|
+
</v-avatar>
|
|
54
|
+
<div class="flex-grow-1">
|
|
55
|
+
<div class="screen-card-title">
|
|
56
|
+
{{ box === "incoming" ? item.requesterOrgName || "A company" : "You" }}
|
|
57
|
+
asked for access to {{ item.siteName }}
|
|
58
|
+
</div>
|
|
59
|
+
<div class="screen-hint site-access__meta">
|
|
60
|
+
<span v-if="joinRequestRequester(item)">Requested by {{ joinRequestRequester(item) }} · </span>
|
|
61
|
+
<span>Sent {{ day(item.createdAt) }}</span>
|
|
62
|
+
</div>
|
|
63
|
+
</div>
|
|
64
|
+
<StatusChip :status="item.status" :label="joinRequestStatusLabel(item.status)" />
|
|
65
|
+
</div>
|
|
66
|
+
|
|
67
|
+
<div class="px-4 pb-2 site-access__body">{{ joinRequestStateLine(item, box) }}</div>
|
|
68
|
+
<div v-if="item.note" class="px-4 pb-4 site-access__body">
|
|
69
|
+
<span class="font-weight-medium">Note:</span> {{ item.note }}
|
|
70
|
+
</div>
|
|
71
|
+
|
|
72
|
+
<div v-if="item.status === 'pending'" class="d-flex align-center ga-2 px-4 pb-4">
|
|
73
|
+
<template v-if="box === 'incoming'">
|
|
74
|
+
<v-btn variant="flat" class="screen-btn-primary" @click="ask(item, 'approve')">Approve</v-btn>
|
|
75
|
+
<v-btn variant="outlined" class="screen-btn-ghost" @click="ask(item, 'reject')">Reject</v-btn>
|
|
76
|
+
</template>
|
|
77
|
+
<v-btn v-else variant="outlined" class="screen-btn-ghost" @click="ask(item, 'cancel')">
|
|
78
|
+
Cancel request
|
|
79
|
+
</v-btn>
|
|
80
|
+
</div>
|
|
81
|
+
</AppCard>
|
|
82
|
+
</div>
|
|
83
|
+
|
|
84
|
+
<ConfirmDialog v-model="confirmOpen">
|
|
85
|
+
<template #title>{{ confirmTitle }}</template>
|
|
86
|
+
<template #description>
|
|
87
|
+
<p class="mb-3">{{ confirmText }}</p>
|
|
88
|
+
<v-textarea
|
|
89
|
+
v-if="pending?.action === 'reject'"
|
|
90
|
+
v-model="reason"
|
|
91
|
+
label="Reason (optional)"
|
|
92
|
+
variant="outlined"
|
|
93
|
+
rows="2"
|
|
94
|
+
auto-grow
|
|
95
|
+
maxlength="500"
|
|
96
|
+
hide-details
|
|
97
|
+
/>
|
|
98
|
+
<div v-if="actionError" class="text-error mt-2" role="alert">{{ actionError }}</div>
|
|
99
|
+
</template>
|
|
100
|
+
<template #footer>
|
|
101
|
+
<v-btn variant="outlined" class="screen-btn-ghost flex-grow-1" :disabled="working" @click="confirmOpen = false">
|
|
102
|
+
Back
|
|
103
|
+
</v-btn>
|
|
104
|
+
<v-btn variant="flat" class="screen-btn-primary flex-grow-1" :loading="working" @click="confirm">
|
|
105
|
+
{{ confirmButton }}
|
|
106
|
+
</v-btn>
|
|
107
|
+
</template>
|
|
108
|
+
</ConfirmDialog>
|
|
109
|
+
</AppCard>
|
|
110
|
+
</div>
|
|
111
|
+
</template>
|
|
112
|
+
|
|
113
|
+
<script setup lang="ts">
|
|
114
|
+
import type { TSiteJoinRequest, TSiteJoinRequestStatus } from "../utils/site-join-request";
|
|
115
|
+
|
|
116
|
+
const props = defineProps({
|
|
117
|
+
/** The organisation on screen. */
|
|
118
|
+
org: { type: String, required: true },
|
|
119
|
+
/** May add sites - only then is there an "Our requests" box to show. */
|
|
120
|
+
canRequest: { type: Boolean, default: true },
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
type Box = "incoming" | "outgoing";
|
|
124
|
+
type Action = "approve" | "reject" | "cancel";
|
|
125
|
+
|
|
126
|
+
const boxes: Array<{ value: Box; label: string }> = [
|
|
127
|
+
{ value: "incoming", label: "Requests to approve" },
|
|
128
|
+
{ value: "outgoing", label: "Our requests" },
|
|
129
|
+
];
|
|
130
|
+
const statuses: Array<{ title: string; value: TSiteJoinRequestStatus }> = [
|
|
131
|
+
{ title: "Pending", value: "pending" },
|
|
132
|
+
{ title: "Approved", value: "approved" },
|
|
133
|
+
{ title: "Rejected", value: "rejected" },
|
|
134
|
+
{ title: "Cancelled", value: "cancelled" },
|
|
135
|
+
];
|
|
136
|
+
|
|
137
|
+
const { getJoinRequests, approveJoinRequest, rejectJoinRequest, cancelJoinRequest } = useCustomerSite();
|
|
138
|
+
|
|
139
|
+
const limit = 20;
|
|
140
|
+
const box = ref<Box>("incoming");
|
|
141
|
+
const status = ref<TSiteJoinRequestStatus>("pending");
|
|
142
|
+
const page = ref(1);
|
|
143
|
+
const total = ref(0);
|
|
144
|
+
const pages = computed(() => Math.ceil(total.value / limit));
|
|
145
|
+
const items = ref<TSiteJoinRequest[]>([]);
|
|
146
|
+
const loading = ref(false);
|
|
147
|
+
const loadError = ref("");
|
|
148
|
+
|
|
149
|
+
const emptyLine = computed(() => {
|
|
150
|
+
if (box.value === "incoming") {
|
|
151
|
+
return status.value === "pending"
|
|
152
|
+
? "No company is waiting for access to your sites."
|
|
153
|
+
: `No ${status.value} requests.`;
|
|
154
|
+
}
|
|
155
|
+
return status.value === "pending"
|
|
156
|
+
? "You have no requests waiting for an answer."
|
|
157
|
+
: `You have no ${status.value} requests.`;
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
function day(value?: string | null) {
|
|
161
|
+
if (!value) return "";
|
|
162
|
+
const d = new Date(value);
|
|
163
|
+
return Number.isNaN(d.getTime())
|
|
164
|
+
? ""
|
|
165
|
+
: d.toLocaleDateString("en-GB", { day: "numeric", month: "short", year: "numeric" });
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/*
|
|
169
|
+
* Approving is a separate right (provider invites). The server answers the
|
|
170
|
+
* incoming box with `canApprove: false` and no items for someone without it;
|
|
171
|
+
* a 403 on either box is read the same way. Neither is shown as an error -
|
|
172
|
+
* the box just disappears and the other one opens.
|
|
173
|
+
*/
|
|
174
|
+
const deniedIncoming = ref(false);
|
|
175
|
+
const deniedOutgoing = ref(false);
|
|
176
|
+
const visibleBoxes = computed(() =>
|
|
177
|
+
boxes.filter((b) => (b.value === "incoming" ? !deniedIncoming.value : props.canRequest && !deniedOutgoing.value))
|
|
178
|
+
);
|
|
179
|
+
watch(
|
|
180
|
+
visibleBoxes,
|
|
181
|
+
(list) => {
|
|
182
|
+
if (list.length && !list.some((b) => b.value === box.value)) box.value = list[0].value;
|
|
183
|
+
},
|
|
184
|
+
{ immediate: true }
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
function deny(which: Box) {
|
|
188
|
+
if (which === "incoming") deniedIncoming.value = true;
|
|
189
|
+
else deniedOutgoing.value = true;
|
|
190
|
+
items.value = [];
|
|
191
|
+
total.value = 0;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const isForbidden = (err: any) => (err?.statusCode ?? err?.status ?? err?.response?.status) === 403;
|
|
195
|
+
|
|
196
|
+
let loadSeq = 0;
|
|
197
|
+
async function load() {
|
|
198
|
+
if (!visibleBoxes.value.some((b) => b.value === box.value)) return;
|
|
199
|
+
const seq = ++loadSeq; // a slower answer for an earlier tab/filter/page is dropped
|
|
200
|
+
const which = box.value;
|
|
201
|
+
loading.value = true;
|
|
202
|
+
loadError.value = "";
|
|
203
|
+
try {
|
|
204
|
+
const res = await getJoinRequests(props.org, { box: which, status: status.value, page: page.value, limit });
|
|
205
|
+
if (seq !== loadSeq) return;
|
|
206
|
+
if (which === "incoming" && res?.canApprove === false) return deny("incoming");
|
|
207
|
+
items.value = Array.isArray(res?.items) ? res.items : [];
|
|
208
|
+
total.value = Number(res?.total ?? 0);
|
|
209
|
+
} catch (err: any) {
|
|
210
|
+
if (seq !== loadSeq) return;
|
|
211
|
+
if (isForbidden(err)) return deny(which);
|
|
212
|
+
items.value = [];
|
|
213
|
+
total.value = 0;
|
|
214
|
+
loadError.value = err?.data?.message || "Could not load the access requests. Please try again.";
|
|
215
|
+
} finally {
|
|
216
|
+
if (seq === loadSeq) loading.value = false;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// Confirm dialog for every action.
|
|
221
|
+
const confirmOpen = ref(false);
|
|
222
|
+
const pending = ref<{ item: TSiteJoinRequest; action: Action } | null>(null);
|
|
223
|
+
const reason = ref("");
|
|
224
|
+
const working = ref(false);
|
|
225
|
+
const actionError = ref("");
|
|
226
|
+
|
|
227
|
+
function ask(item: TSiteJoinRequest, action: Action) {
|
|
228
|
+
pending.value = { item, action };
|
|
229
|
+
reason.value = "";
|
|
230
|
+
actionError.value = "";
|
|
231
|
+
confirmOpen.value = true;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const confirmTitle = computed(() => {
|
|
235
|
+
const p = pending.value;
|
|
236
|
+
if (!p) return "";
|
|
237
|
+
return { approve: "Approve access?", reject: "Reject request?", cancel: "Cancel your request?" }[p.action];
|
|
238
|
+
});
|
|
239
|
+
const confirmText = computed(() => {
|
|
240
|
+
const p = pending.value;
|
|
241
|
+
if (!p) return "";
|
|
242
|
+
const who = p.item.requesterOrgName || "This company";
|
|
243
|
+
return {
|
|
244
|
+
approve: `${who} will be linked to ${p.item.siteName} and can provide services there. They will be notified.`,
|
|
245
|
+
reject: `${who} will not be linked to ${p.item.siteName}. They will be notified, with your reason if you give one.`,
|
|
246
|
+
cancel: `Your request for ${p.item.siteName} will be withdrawn.`,
|
|
247
|
+
}[p.action];
|
|
248
|
+
});
|
|
249
|
+
const confirmButton = computed(
|
|
250
|
+
() => ({ approve: "Approve", reject: "Reject", cancel: "Cancel request" })[pending.value?.action ?? "approve"]
|
|
251
|
+
);
|
|
252
|
+
|
|
253
|
+
async function confirm() {
|
|
254
|
+
const p = pending.value;
|
|
255
|
+
if (!p) return;
|
|
256
|
+
working.value = true;
|
|
257
|
+
actionError.value = "";
|
|
258
|
+
try {
|
|
259
|
+
if (p.action === "approve") await approveJoinRequest(p.item._id, props.org);
|
|
260
|
+
else if (p.action === "reject") await rejectJoinRequest(p.item._id, props.org, reason.value);
|
|
261
|
+
else await cancelJoinRequest(p.item._id, props.org);
|
|
262
|
+
confirmOpen.value = false;
|
|
263
|
+
await load();
|
|
264
|
+
} catch (err: any) {
|
|
265
|
+
actionError.value = err?.data?.message || "That did not work. Please try again.";
|
|
266
|
+
} finally {
|
|
267
|
+
working.value = false;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
watch([box, status], () => {
|
|
272
|
+
page.value = 1;
|
|
273
|
+
load();
|
|
274
|
+
});
|
|
275
|
+
onMounted(load);
|
|
276
|
+
</script>
|
|
277
|
+
|
|
278
|
+
<style scoped>
|
|
279
|
+
.site-access :deep(.screen-card-title) {
|
|
280
|
+
display: block;
|
|
281
|
+
line-height: 1.35;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
.site-access__meta,
|
|
285
|
+
.site-access__body {
|
|
286
|
+
font-size: var(--fs-cell);
|
|
287
|
+
}
|
|
288
|
+
</style>
|
|
@@ -280,6 +280,24 @@
|
|
|
280
280
|
Add Plate
|
|
281
281
|
</AppButton>
|
|
282
282
|
</template>
|
|
283
|
+
|
|
284
|
+
<!--
|
|
285
|
+
A blank (pre-printed) QR sticker to link as the vehicle is
|
|
286
|
+
added: the next sticker number is picked already. Optional -
|
|
287
|
+
"No sticker" adds the vehicle alone. With several plates the
|
|
288
|
+
sticker goes on the first plate, as Link QR sticker does per plate.
|
|
289
|
+
-->
|
|
290
|
+
<div v-if="prop.qrLink && qrPickItems.length > 1" class="w-100 mt-3">
|
|
291
|
+
<InputLabel title="QR sticker" />
|
|
292
|
+
<v-autocomplete
|
|
293
|
+
v-model="qrPick"
|
|
294
|
+
:items="qrPickItems"
|
|
295
|
+
density="comfortable"
|
|
296
|
+
:hint="newPlateNumbers.filter(Boolean).length > 1 ? 'Linked to the first plate number above.' : 'Type a sticker number to find it.'"
|
|
297
|
+
persistent-hint
|
|
298
|
+
data-test="vehicle-form-qr-sticker"
|
|
299
|
+
/>
|
|
300
|
+
</div>
|
|
283
301
|
</template>
|
|
284
302
|
|
|
285
303
|
<template v-else-if="prop.mode === 'edit'">
|
|
@@ -493,6 +511,7 @@
|
|
|
493
511
|
|
|
494
512
|
<script setup lang="ts">
|
|
495
513
|
import { errorConverter } from "../utils/data";
|
|
514
|
+
import { blankPickLabel, type BlankPick } from "../utils/vehicle-qr-blank";
|
|
496
515
|
import { isPermissionRefusalError } from "../utils/permission-refusal";
|
|
497
516
|
const prop = defineProps({
|
|
498
517
|
type: {
|
|
@@ -543,6 +562,11 @@ const prop = defineProps({
|
|
|
543
562
|
* Blocking from a visitor transaction: the visit's block / level / unit,
|
|
544
563
|
* saved on the Block Listed vehicle and shown read-only.
|
|
545
564
|
*/
|
|
565
|
+
/** Offer a blank QR sticker to link on add (site has Vehicle QR on and the person may link). */
|
|
566
|
+
qrLink: {
|
|
567
|
+
type: Boolean,
|
|
568
|
+
default: false,
|
|
569
|
+
},
|
|
546
570
|
presetLocation: {
|
|
547
571
|
type: Object as PropType<{
|
|
548
572
|
block?: { id: string; name: string };
|
|
@@ -561,7 +585,51 @@ const {
|
|
|
561
585
|
formatVehicleStatus,
|
|
562
586
|
checkExistingPlates,
|
|
563
587
|
moveVehicle,
|
|
588
|
+
getBlankStickersBySerial,
|
|
589
|
+
linkVehicleQr,
|
|
564
590
|
} = useVehicle();
|
|
591
|
+
|
|
592
|
+
/*
|
|
593
|
+
* Link a blank QR sticker while adding (owner 2026-11-16). The host passes
|
|
594
|
+
* `qrLink` only when the site has Vehicle QR on and this person may link.
|
|
595
|
+
*/
|
|
596
|
+
const qrPicks = ref<BlankPick[]>([]);
|
|
597
|
+
const qrPick = ref("");
|
|
598
|
+
const qrPickItems = computed(() => [
|
|
599
|
+
...qrPicks.value.map((p) => ({ title: blankPickLabel(p), value: p.code })),
|
|
600
|
+
{ title: "No sticker", value: "" },
|
|
601
|
+
]);
|
|
602
|
+
onMounted(async () => {
|
|
603
|
+
if (!prop.qrLink || prop.mode !== "add") return;
|
|
604
|
+
try {
|
|
605
|
+
const res = await getBlankStickersBySerial(prop.site, { limit: 50 });
|
|
606
|
+
qrPicks.value = res.items;
|
|
607
|
+
qrPick.value = res.next?.code ?? "";
|
|
608
|
+
} catch {
|
|
609
|
+
qrPicks.value = []; // ponytail: no list, no picker - the vehicle still adds
|
|
610
|
+
}
|
|
611
|
+
});
|
|
612
|
+
|
|
613
|
+
/** After the add: link the picked sticker to the first new plate. A failure keeps the vehicle and says so. */
|
|
614
|
+
async function linkPickedSticker(plates: string[]): Promise<{ text: string; ok: boolean }> {
|
|
615
|
+
const code = qrPick.value;
|
|
616
|
+
const plate = plates[0];
|
|
617
|
+
if (!code || !plate) return { text: "", ok: true };
|
|
618
|
+
const label = blankPickLabel(qrPicks.value.find((p) => p.code === code) ?? { token: code, code });
|
|
619
|
+
try {
|
|
620
|
+
const found = await checkExistingPlates({ site: prop.site, plateNumbers: [plate] });
|
|
621
|
+
const key = (v: unknown) => String(v ?? "").replace(/[^A-Za-z0-9]/g, "").toUpperCase();
|
|
622
|
+
const id = found?.items?.find((i) => key(i.plateNumber) === key(plate))?._id;
|
|
623
|
+
if (!id) throw new Error("The new vehicle could not be found.");
|
|
624
|
+
await linkVehicleQr(code, String(id));
|
|
625
|
+
return { text: `QR sticker ${label.split(" - ")[0]} linked to ${plate}.`, ok: true };
|
|
626
|
+
} catch (error: any) {
|
|
627
|
+
return {
|
|
628
|
+
text: `Vehicle saved, but the QR sticker was not linked (${errorConverter(error)}). Link it from Link QR sticker on the vehicle.`,
|
|
629
|
+
ok: false,
|
|
630
|
+
};
|
|
631
|
+
}
|
|
632
|
+
}
|
|
565
633
|
const { getSiteById, getSiteLevels, getSiteUnits } = useSiteSettings();
|
|
566
634
|
const { findPersonByNRICMultipleResult, getPeopleByUnit } = usePeople();
|
|
567
635
|
const { getBlocksSelection, getLevelsSelection, getUnitSelection } =
|
|
@@ -1154,13 +1222,17 @@ async function confirmExistingUpdate() {
|
|
|
1154
1222
|
}
|
|
1155
1223
|
|
|
1156
1224
|
const remaining = newPlatesAfterExisting.value;
|
|
1225
|
+
let linkOk = true;
|
|
1157
1226
|
if (remaining.length) {
|
|
1158
1227
|
const res: any = await addVehicle({ ...payload, plateNumber: remaining });
|
|
1159
1228
|
messages.push(res?.data || res?.message || "Vehicle added successfully.");
|
|
1229
|
+
const linked = await linkPickedSticker(remaining);
|
|
1230
|
+
if (linked.text) messages.push(linked.text);
|
|
1231
|
+
linkOk = linked.ok;
|
|
1160
1232
|
}
|
|
1161
1233
|
|
|
1162
1234
|
showExistingDialog.value = false;
|
|
1163
|
-
showMessage(messages.join(" ") || "Vehicle updated.", "success");
|
|
1235
|
+
showMessage(messages.join(" ") || "Vehicle updated.", linkOk ? "success" : "warning");
|
|
1164
1236
|
emit("done");
|
|
1165
1237
|
} catch (error: any) {
|
|
1166
1238
|
// Shown under the form. A record moved before the failure stays moved.
|
|
@@ -1310,7 +1382,9 @@ async function submit() {
|
|
|
1310
1382
|
}
|
|
1311
1383
|
|
|
1312
1384
|
const res: any = await addVehicle(payload);
|
|
1313
|
-
|
|
1385
|
+
const added = res?.data || res?.message || "Vehicle added successfully.";
|
|
1386
|
+
const linked = await linkPickedSticker(plates);
|
|
1387
|
+
showMessage([added, linked.text].filter(Boolean).join(" "), linked.ok ? "success" : "warning");
|
|
1314
1388
|
} else if (prop.mode === "edit") {
|
|
1315
1389
|
const plateNumberId = prop.plateNumberId as string;
|
|
1316
1390
|
const res: any = await updateVehicle(plateNumberId, payload);
|
|
@@ -161,6 +161,7 @@
|
|
|
161
161
|
<v-dialog v-model="dialog.createVehicle" v-if="vehicleType" width="450" persistent>
|
|
162
162
|
<VehicleForm :type="vehicleType" :mode="mode" :vehicle-data="selectedVehicleObject"
|
|
163
163
|
:plate-number-id="selectedPlateNumberId" :name-hints="nameHints" @back="handleBackToSelection" @done="handleAddVehicleComplete"
|
|
164
|
+
:qr-link="qrActionsOn({ type: vehicleType })"
|
|
164
165
|
:org="org" :site="props.site" @close:all="handleCloseAll" @refused="handleFormRefused" />
|
|
165
166
|
</v-dialog>
|
|
166
167
|
|
|
@@ -429,10 +430,10 @@
|
|
|
429
430
|
<v-card data-test="vehicle-qr-link-dialog">
|
|
430
431
|
<v-card-title>Link QR sticker</v-card-title>
|
|
431
432
|
<v-card-text>
|
|
432
|
-
Pick an available sticker
|
|
433
|
-
{{ qrPlate?.plateNumber }} when scanned.
|
|
434
|
-
<v-combobox v-model="qrLinkCode" v-model:search="qrSearch" :items="qrCodes" no-filter clearable label="Sticker
|
|
435
|
-
placeholder="Pick or type ABCD-EFGH-JKMN-PQRS-TVWX-YZ01" density="compact" variant="outlined" class="mt-3"
|
|
433
|
+
Pick an available sticker (next number first) or type its sticker number, scan the sticker, or type the code
|
|
434
|
+
printed on it. It will show {{ qrPlate?.plateNumber }} when scanned.
|
|
435
|
+
<v-combobox v-model="qrLinkCode" v-model:search="qrSearch" :items="qrCodes" no-filter clearable label="Sticker"
|
|
436
|
+
placeholder="Pick, or type TLR002 / ABCD-EFGH-JKMN-PQRS-TVWX-YZ01" density="compact" variant="outlined" class="mt-3"
|
|
436
437
|
:disabled="qrBusy" :hint="qrLinkHint" persistent-hint hide-no-data data-test="vehicle-qr-link-code"
|
|
437
438
|
@keyup.enter="confirmLink(false)" />
|
|
438
439
|
<p v-if="qrSummary" class="text-caption mt-2" data-test="vehicle-qr-link-summary">{{ blankSummaryText(qrSummary) }}</p>
|
|
@@ -489,7 +490,7 @@ import {
|
|
|
489
490
|
// `error.message` put ofetch's own developer string in the delete dialog:
|
|
490
491
|
// `[PUT] "/api/vehicles/6a9691f25648d7633171c9e3": 502`.
|
|
491
492
|
import { errorConverter } from '../utils/data';
|
|
492
|
-
import { BLANK_LIST_NOTE, UNDO_REISSUE_NOTE, blankSummaryText, qrStickerNumbers, qrStickerSummary, stickerCodeHint, type BlankSummary } from '../utils/vehicle-qr-blank';
|
|
493
|
+
import { BLANK_LIST_NOTE, UNDO_REISSUE_NOTE, blankPickLabel, blankSummaryText, pickedStickerCode, qrStickerNumbers, qrStickerSummary, stickerCodeHint, type BlankPick, type BlankSummary } from '../utils/vehicle-qr-blank';
|
|
493
494
|
import { isPermissionRefusalError } from '../utils/permission-refusal';
|
|
494
495
|
|
|
495
496
|
|
|
@@ -606,7 +607,7 @@ const canAddBlocklist = computed(() => props.canManageBlocklist === true);
|
|
|
606
607
|
|
|
607
608
|
|
|
608
609
|
const { formatCamelCaseToWords, formatDate, debounce, maskNRIC } = useUtils();
|
|
609
|
-
const { getVehicles, deleteVehicle, formatVehicleStatus, approveVehicle, blockVehicle, unblockVehicle, getSpecificVehicleById, getActiveCameraCounts, getVehicleQrSettings, regenerateVehicleQr, undoReissueVehicleQr, linkVehicleQr, unlinkVehicleQr,
|
|
610
|
+
const { getVehicles, deleteVehicle, formatVehicleStatus, approveVehicle, blockVehicle, unblockVehicle, getSpecificVehicleById, getActiveCameraCounts, getVehicleQrSettings, regenerateVehicleQr, undoReissueVehicleQr, linkVehicleQr, unlinkVehicleQr, getBlankStickersBySerial } = useVehicle();
|
|
610
611
|
|
|
611
612
|
// Vehicle QR stickers: the site's switch (Settings) decides whether the print
|
|
612
613
|
// and re-issue actions exist; only people who may update vehicles get them.
|
|
@@ -672,26 +673,31 @@ const qrError = ref("");
|
|
|
672
673
|
const qrLinkHint = computed(() => (qrCodeToLink.value ? stickerCodeHint(qrCodeToLink.value) : ""));
|
|
673
674
|
// the combobox keeps a typed-but-not-committed code in its search text
|
|
674
675
|
const qrSearch = ref("");
|
|
675
|
-
|
|
676
|
+
// the pick-list's stickers ("TLR002 - ABCD-..."), by sticker number with the next one first
|
|
677
|
+
const qrPicks = ref<BlankPick[]>([]);
|
|
678
|
+
const qrCodes = computed(() => qrPicks.value.map(blankPickLabel));
|
|
676
679
|
const qrSummary = ref<BlankSummary | null>(null);
|
|
677
|
-
|
|
680
|
+
// a picked line or a typed sticker number becomes that sticker's code; a typed code is sent as is
|
|
681
|
+
const qrCodeToLink = computed(() => pickedStickerCode(qrLinkCode.value || qrSearch.value, qrPicks.value));
|
|
678
682
|
|
|
679
683
|
// Saved blank codes still free to link + the site's printed / linked / available count.
|
|
680
684
|
async function loadQrAvailable(search = "") {
|
|
681
685
|
// The Link dialog lists the blanks for whoever may link this plate.
|
|
682
686
|
if (!qrStickersOn.value && !(dialog.qrLink && qrActionsOn(qrPlate.value))) return;
|
|
683
687
|
try {
|
|
684
|
-
const res = await
|
|
685
|
-
qrSummary.value = res
|
|
686
|
-
|
|
688
|
+
const res = await getBlankStickersBySerial(props.site, { search, limit: 50 });
|
|
689
|
+
qrSummary.value = res.summary;
|
|
690
|
+
qrPicks.value = res.items;
|
|
687
691
|
} catch {
|
|
688
692
|
qrSummary.value = null;
|
|
689
|
-
|
|
693
|
+
qrPicks.value = [];
|
|
690
694
|
}
|
|
691
695
|
}
|
|
692
696
|
let qrSearchTimer: ReturnType<typeof setTimeout> | undefined;
|
|
693
697
|
watch(qrSearch, (v) => {
|
|
694
698
|
clearTimeout(qrSearchTimer);
|
|
699
|
+
// picking a line puts its label in the search text - that is not a search
|
|
700
|
+
if (qrCodes.value.includes(String(v ?? ""))) return;
|
|
695
701
|
if (dialog.qrLink) qrSearchTimer = setTimeout(() => loadQrAvailable(String(v ?? "")), 250);
|
|
696
702
|
});
|
|
697
703
|
watch(qrStickersOn, (on) => on && loadQrAvailable());
|