@7365admin1/layer-common 4.97.1-staging.674 → 4.97.1-staging.676
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/SiteSettings.vue +66 -1
- package/components/VehicleQrStickerDialog.vue +6 -2
- package/composables/useVehicle.ts +10 -4
- package/middleware/terms-gate.global.ts +10 -0
- package/package.json +1 -1
- package/plugins/secure-member.client.ts +167 -10
- package/utils/vehicle-qr-blank.ts +22 -5
- package/utils/vehicle-qr-design.ts +2 -2
- package/utils/vehicle-qr-sticker.ts +10 -5
|
@@ -218,6 +218,33 @@
|
|
|
218
218
|
When on, staff can print a QR sticker for each vehicle from Vehicle Mgmt, and guards can scan it to see
|
|
219
219
|
which unit the vehicle belongs to.
|
|
220
220
|
</p>
|
|
221
|
+
<v-divider class="my-4" />
|
|
222
|
+
<div class="text-subtitle-2 mb-2">Sticker serial number</div>
|
|
223
|
+
<v-row dense>
|
|
224
|
+
<v-col cols="12" sm="6" md="4">
|
|
225
|
+
<v-text-field v-model="vehicleQrPrefix" label="Serial number prefix (optional)" placeholder="e.g. TLR"
|
|
226
|
+
density="compact" variant="outlined" maxlength="8" :rules="[vehicleQrPrefixRule]"
|
|
227
|
+
hint="Letters, numbers or dashes, up to 8" persistent-hint data-test="vehicle-qr-serial-prefix"
|
|
228
|
+
@update:model-value="(v: string) => (vehicleQrPrefix = cleanSerialPrefix(v))" />
|
|
229
|
+
</v-col>
|
|
230
|
+
<v-col cols="12" sm="6" md="3">
|
|
231
|
+
<v-select v-model="vehicleQrDigits" :items="[1, 2, 3, 4, 5, 6]" label="Digits" density="compact"
|
|
232
|
+
variant="outlined" :disabled="!vehicleQrPrefix" hint="Zeros in front, e.g. 3 = 001" persistent-hint
|
|
233
|
+
data-test="vehicle-qr-serial-digits" />
|
|
234
|
+
</v-col>
|
|
235
|
+
<v-col cols="12" md="5" class="d-flex align-center flex-wrap">
|
|
236
|
+
<span class="text-body-2 mr-3" data-test="vehicle-qr-serial-example">
|
|
237
|
+
First sticker: <b>{{ vehicleQrExample }}</b>
|
|
238
|
+
</span>
|
|
239
|
+
<v-btn color="primary" variant="flat" size="small" class="text-none" :loading="vehicleQrSerialSaving"
|
|
240
|
+
:disabled="!vehicleQrSerialChanged || vehicleQrPrefixRule(vehicleQrPrefix) !== true"
|
|
241
|
+
data-test="vehicle-qr-serial-save" @click="saveVehicleQrSerial">Save</v-btn>
|
|
242
|
+
</v-col>
|
|
243
|
+
</v-row>
|
|
244
|
+
<p class="text-caption text-medium-emphasis mt-2 mb-0">
|
|
245
|
+
Changes how sticker numbers are printed and shown from now on (the numbers themselves stay the same).
|
|
246
|
+
Stickers already on cars keep what was printed on them.
|
|
247
|
+
</p>
|
|
221
248
|
</v-expansion-panel-text>
|
|
222
249
|
</v-expansion-panel>
|
|
223
250
|
|
|
@@ -292,6 +319,7 @@ import useSiteSettings from "../composables/useSiteSettings";
|
|
|
292
319
|
import useUtils from "../composables/useUtils";
|
|
293
320
|
import useANPRSettings from "../composables/useANPRSettings";
|
|
294
321
|
import useVehicle from "../composables/useVehicle";
|
|
322
|
+
import { SERIAL_DEFAULT_DIGITS, SERIAL_PREFIX_PATTERN, cleanSerialPrefix, formatStickerSerial } from "../utils/vehicle-qr-blank";
|
|
295
323
|
|
|
296
324
|
const props = defineProps({
|
|
297
325
|
siteId: { type: String, required: true },
|
|
@@ -494,17 +522,54 @@ const route = useRoute();
|
|
|
494
522
|
const { getVehicleQrSettings, setVehicleQrSettings } = useVehicle();
|
|
495
523
|
const vehicleQrEnabled = ref(false);
|
|
496
524
|
const vehicleQrSaving = ref(false);
|
|
525
|
+
// Sticker serial number: prefix ("" = none, prints "No. 1") and digits.
|
|
526
|
+
const vehicleQrPrefix = ref("");
|
|
527
|
+
const vehicleQrDigits = ref(SERIAL_DEFAULT_DIGITS);
|
|
528
|
+
const vehicleQrSaved = ref({ prefix: "", digits: SERIAL_DEFAULT_DIGITS });
|
|
529
|
+
const vehicleQrSerialSaving = ref(false);
|
|
530
|
+
const vehicleQrPrefixRule = (v: string) =>
|
|
531
|
+
SERIAL_PREFIX_PATTERN.test(cleanSerialPrefix(v)) || "Use letters, numbers or dashes only (up to 8)";
|
|
532
|
+
const vehicleQrExample = computed(() => formatStickerSerial(1, vehicleQrPrefix.value, vehicleQrDigits.value));
|
|
533
|
+
const vehicleQrSerialChanged = computed(
|
|
534
|
+
() => vehicleQrPrefix.value !== vehicleQrSaved.value.prefix || vehicleQrDigits.value !== vehicleQrSaved.value.digits,
|
|
535
|
+
);
|
|
536
|
+
|
|
537
|
+
function applyVehicleQrSerial(res: { serialPrefix?: string; serialDigits?: number } | null | undefined) {
|
|
538
|
+
const prefix = res?.serialPrefix ?? "";
|
|
539
|
+
const digits = res?.serialDigits ?? SERIAL_DEFAULT_DIGITS;
|
|
540
|
+
vehicleQrSaved.value = { prefix, digits };
|
|
541
|
+
vehicleQrPrefix.value = prefix;
|
|
542
|
+
vehicleQrDigits.value = digits;
|
|
543
|
+
}
|
|
497
544
|
|
|
498
545
|
await useLazyAsyncData(`vehicle-qr-${props.siteId}`, async () => {
|
|
499
546
|
if (!canManageVehicleQr.value) return null;
|
|
500
547
|
try {
|
|
501
|
-
|
|
548
|
+
const res = await getVehicleQrSettings(props.siteId);
|
|
549
|
+
vehicleQrEnabled.value = !!res?.enabled;
|
|
550
|
+
applyVehicleQrSerial(res);
|
|
502
551
|
} catch {
|
|
503
552
|
vehicleQrEnabled.value = false;
|
|
504
553
|
}
|
|
505
554
|
return null;
|
|
506
555
|
});
|
|
507
556
|
|
|
557
|
+
async function saveVehicleQrSerial() {
|
|
558
|
+
vehicleQrSerialSaving.value = true;
|
|
559
|
+
try {
|
|
560
|
+
const res = await setVehicleQrSettings(props.siteId, {
|
|
561
|
+
serialPrefix: cleanSerialPrefix(vehicleQrPrefix.value),
|
|
562
|
+
serialDigits: vehicleQrDigits.value,
|
|
563
|
+
});
|
|
564
|
+
applyVehicleQrSerial(res);
|
|
565
|
+
show("Sticker serial number saved", "success");
|
|
566
|
+
} catch (e: any) {
|
|
567
|
+
show(e?.data?.message || "Could not save the sticker serial number", "error");
|
|
568
|
+
} finally {
|
|
569
|
+
vehicleQrSerialSaving.value = false;
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
|
|
508
573
|
async function saveVehicleQr(value: boolean | null) {
|
|
509
574
|
const enabled = !!value;
|
|
510
575
|
vehicleQrSaving.value = true;
|
|
@@ -162,14 +162,18 @@
|
|
|
162
162
|
hide-details />
|
|
163
163
|
</v-col>
|
|
164
164
|
<v-col cols="12" sm="6" md="4">
|
|
165
|
-
<v-select v-model="design.serial" :items="SERIAL_OPTIONS" label="Serial number
|
|
165
|
+
<v-select v-model="design.serial" :items="SERIAL_OPTIONS" label="Serial number" density="compact"
|
|
166
166
|
hide-details data-test="vehicle-qr-serial" />
|
|
167
167
|
</v-col>
|
|
168
168
|
<v-col v-if="!isBlank" cols="12" sm="6" md="4">
|
|
169
|
-
<v-select v-model="design.plate" :items="PLATE_OPTIONS" label="
|
|
169
|
+
<v-select v-model="design.plate" :items="PLATE_OPTIONS" label="Plate number on the sticker" density="compact"
|
|
170
170
|
hide-details data-test="vehicle-qr-plate" />
|
|
171
171
|
</v-col>
|
|
172
172
|
</v-row>
|
|
173
|
+
<v-alert v-if="!isBlank && design.plate === 'hide' && design.serial === 'off'" type="info" variant="tonal"
|
|
174
|
+
density="compact" class="mt-2" data-test="vehicle-qr-qr-only-hint">
|
|
175
|
+
No plate number and no serial number: each sticker will print the QR code only.
|
|
176
|
+
</v-alert>
|
|
173
177
|
<div class="d-flex align-center flex-wrap">
|
|
174
178
|
<v-switch v-model="design.cutLines" label="Show cut lines" color="primary" density="compact" hide-details
|
|
175
179
|
inset class="mt-1 mr-4" data-test="vehicle-qr-cut-lines" />
|
|
@@ -276,17 +276,23 @@ function getSpecificVehicleById(id: string){
|
|
|
276
276
|
|
|
277
277
|
// Vehicle QR stickers (core vehicle-qr). Per-site switch, bulk sticker data,
|
|
278
278
|
// and re-issue (the old sticker stops working).
|
|
279
|
+
type VehicleQrSettings = { site: string; enabled: boolean; serialPrefix: string; serialDigits: number };
|
|
280
|
+
|
|
279
281
|
function getVehicleQrSettings(site: string) {
|
|
280
|
-
return useNuxtApp().$api<
|
|
282
|
+
return useNuxtApp().$api<VehicleQrSettings>(
|
|
281
283
|
`/api/vehicles/qr/settings/site/${site}`,
|
|
282
284
|
{ method: "GET" },
|
|
283
285
|
);
|
|
284
286
|
}
|
|
285
287
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
+
/** Only the fields sent change (`true`/`false` = the switch alone). */
|
|
289
|
+
function setVehicleQrSettings(
|
|
290
|
+
site: string,
|
|
291
|
+
change: boolean | Partial<Pick<VehicleQrSettings, "enabled" | "serialPrefix" | "serialDigits">>,
|
|
292
|
+
) {
|
|
293
|
+
return useNuxtApp().$api<VehicleQrSettings>(
|
|
288
294
|
`/api/vehicles/qr/settings/site/${site}`,
|
|
289
|
-
{ method: "PUT", body: { enabled } },
|
|
295
|
+
{ method: "PUT", body: typeof change === "boolean" ? { enabled: change } : change },
|
|
290
296
|
);
|
|
291
297
|
}
|
|
292
298
|
|
|
@@ -8,6 +8,16 @@ import { termsGateRedirect } from "../utils/terms-gate";
|
|
|
8
8
|
*/
|
|
9
9
|
export default defineNuxtRouteMiddleware(async (to) => {
|
|
10
10
|
const { cookieConfig } = useRuntimeConfig().public;
|
|
11
|
+
// This runs before the permission guard (plugins/secure-member.client.ts) and
|
|
12
|
+
// then waits for its own answer. Let that guard's independent lookups travel
|
|
13
|
+
// alongside it instead of starting only once this one is done.
|
|
14
|
+
if (import.meta.client) {
|
|
15
|
+
try {
|
|
16
|
+
(useNuxtApp() as any).$warmSession?.(to);
|
|
17
|
+
} catch {
|
|
18
|
+
// A head start only: the guard asks for everything itself.
|
|
19
|
+
}
|
|
20
|
+
}
|
|
11
21
|
const redirect = await termsGateRedirect({
|
|
12
22
|
client: import.meta.client,
|
|
13
23
|
sid: useCookie("sid", cookieConfig).value,
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@7365admin1/layer-common",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "4.97.1-staging.
|
|
5
|
+
"version": "4.97.1-staging.676",
|
|
6
6
|
"author": "7365admin1",
|
|
7
7
|
"main": "./nuxt.config.ts",
|
|
8
8
|
"//files": "What a consumer extending this layer actually loads. Without this npm ships the whole working tree - the changesets, the CI workflows, the render harness in tools/ and any scratch directory that happened to exist at publish time. Nuxt resolves a layer by directory, so every runtime directory below has to stay listed; adding a new top-level runtime directory means adding it here too.",
|
|
@@ -68,6 +68,39 @@ function idParam(value: unknown) {
|
|
|
68
68
|
return hexSchema.safeParse(value).success ? String(value) : "";
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
+
/*
|
|
72
|
+
* SIGN-IN SPEED (owner, 2026-11-12: "when I click login it is very slow").
|
|
73
|
+
*
|
|
74
|
+
* The guard below used to ask its questions one after another - staff view,
|
|
75
|
+
* member, role, module list, organisation - and the terms gate (a middleware
|
|
76
|
+
* that runs first) asked its own before any of them. On a hard page load that is
|
|
77
|
+
* five or six round trips in a row before the first screen can paint. Most of
|
|
78
|
+
* them do not depend on each other, so they now go out together:
|
|
79
|
+
*
|
|
80
|
+
* - `prefetch(key, start)` starts a lookup (or reuses one already started)
|
|
81
|
+
* and keeps the promise for a few seconds; `take(key, start)` is what the
|
|
82
|
+
* guard calls: it uses that promise if there is one, otherwise it starts the
|
|
83
|
+
* lookup right there, exactly as before. Each promise is used once, and an
|
|
84
|
+
* old one is ignored, so a later navigation always asks the server again.
|
|
85
|
+
* - `warmSession(to)` (provided as `$warmSession`) lets the terms middleware
|
|
86
|
+
* start these lookups while it waits for its own answer.
|
|
87
|
+
*
|
|
88
|
+
* Nothing is cached beyond that hand-over and every answer is read by the same
|
|
89
|
+
* code as before, so who may see what is unchanged.
|
|
90
|
+
*/
|
|
91
|
+
export const PREFETCH_TTL_MS = 10_000;
|
|
92
|
+
|
|
93
|
+
/*
|
|
94
|
+
* The first navigation after a sign-in lands on the app's "SIGN IN AS you" page
|
|
95
|
+
* (no site in the address) and then opens the site's dashboard moments later.
|
|
96
|
+
* While Q16 is held the member lookup sends no site, so asking it again for the
|
|
97
|
+
* site returns the very same answer. Within this window that second ask is
|
|
98
|
+
* skipped; a site switch later in the session still re-asks (Q16 is unchanged).
|
|
99
|
+
*/
|
|
100
|
+
export const LANDING_FRESH_MS = 60_000;
|
|
101
|
+
|
|
102
|
+
type Prefetched = { at: number; promise: Promise<any> };
|
|
103
|
+
|
|
71
104
|
export default defineNuxtPlugin(() => {
|
|
72
105
|
const router = useRouter();
|
|
73
106
|
const { getByUserType, getDeniedModules } = useMember();
|
|
@@ -80,7 +113,7 @@ export default defineNuxtPlugin(() => {
|
|
|
80
113
|
// "Open as Seven365 staff": the server holds the view against the session.
|
|
81
114
|
// While it covers the route's organisation, staff work there with full setup
|
|
82
115
|
// rights instead of their own (absent) membership. Nothing is written.
|
|
83
|
-
const { loadStaffView } = useStaffView();
|
|
116
|
+
const { loadStaffView, staffView, staffViewLoaded } = useStaffView();
|
|
84
117
|
let staffViewActive = false;
|
|
85
118
|
let lastStaffOrg = "";
|
|
86
119
|
|
|
@@ -94,6 +127,38 @@ export default defineNuxtPlugin(() => {
|
|
|
94
127
|
let inFlight: Promise<void> | null = null;
|
|
95
128
|
let inFlightKey: string | null = null;
|
|
96
129
|
let hasMemberDocument = false;
|
|
130
|
+
let resolvedAt = 0;
|
|
131
|
+
|
|
132
|
+
const prefetched = new Map<string, Prefetched>();
|
|
133
|
+
|
|
134
|
+
function prefetch<T>(key: string, start: () => Promise<T>): Promise<T> {
|
|
135
|
+
const hit = prefetched.get(key);
|
|
136
|
+
if (hit && Date.now() - hit.at < PREFETCH_TTL_MS) return hit.promise;
|
|
137
|
+
const promise = start();
|
|
138
|
+
// Nobody may be waiting for it (a navigation that never got this far); the
|
|
139
|
+
// caller that does wait still sees the failure.
|
|
140
|
+
promise.catch(() => {});
|
|
141
|
+
prefetched.set(key, { at: Date.now(), promise });
|
|
142
|
+
return promise;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** Each started lookup is handed over once; an old or missing one is started afresh. */
|
|
146
|
+
function take<T>(key: string, start: () => Promise<T>): Promise<T> {
|
|
147
|
+
const hit = prefetched.get(key);
|
|
148
|
+
prefetched.delete(key);
|
|
149
|
+
return hit && Date.now() - hit.at < PREFETCH_TTL_MS ? hit.promise : start();
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const memberKey = (userId: string, site: string) => `member:${userId}|${site}`;
|
|
153
|
+
const startMember = (userId: string, site: string) => () =>
|
|
154
|
+
bounded(
|
|
155
|
+
getByUserType(
|
|
156
|
+
userId,
|
|
157
|
+
useRuntimeConfig().public.APP,
|
|
158
|
+
undefined,
|
|
159
|
+
roleFollowsSite() && site ? site : undefined,
|
|
160
|
+
),
|
|
161
|
+
);
|
|
97
162
|
|
|
98
163
|
// The client's module list is decided per org|site, so it has its own key.
|
|
99
164
|
// `deniedWanted` is the latest key asked for: an older answer that lands after
|
|
@@ -101,6 +166,25 @@ export default defineNuxtPlugin(() => {
|
|
|
101
166
|
let deniedFor: string | null = null;
|
|
102
167
|
let deniedWanted: string | null = null;
|
|
103
168
|
|
|
169
|
+
const deniedKey = (userId: string, org: string, site: string) => `denied:${userId}|${org}|${site}`;
|
|
170
|
+
const askDenied = (userId: string, org: string, site: string) => () =>
|
|
171
|
+
getDeniedModules(userId, useRuntimeConfig().public.APP, org || undefined, site || undefined);
|
|
172
|
+
/** Start the module-list lookup early; `resolveDenied` picks the answer up. */
|
|
173
|
+
const startDenied = (userId: string, org: string, site: string) =>
|
|
174
|
+
prefetch(deniedKey(userId, org, site), askDenied(userId, org, site));
|
|
175
|
+
|
|
176
|
+
// See LANDING_FRESH_MS. Only from "no site yet" to a site, only for the same
|
|
177
|
+
// person, only while the member lookup does not send the site.
|
|
178
|
+
function landingAnswerStillHolds(userId: string, site: string, staffOrg: string) {
|
|
179
|
+
return (
|
|
180
|
+
!!site &&
|
|
181
|
+
!staffOrg &&
|
|
182
|
+
!roleFollowsSite() &&
|
|
183
|
+
resolvedFor === `${userId}|` &&
|
|
184
|
+
Date.now() - resolvedAt < LANDING_FRESH_MS
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
|
|
104
188
|
// Deliberately never redirects and never throws.
|
|
105
189
|
//
|
|
106
190
|
// `GET /api/members/user/:id/app/:type` returns 404 for any account holding no
|
|
@@ -111,6 +195,10 @@ export default defineNuxtPlugin(() => {
|
|
|
111
195
|
async function resolveAppRole(userId: string, site: string, staffOrg = "") {
|
|
112
196
|
const key = `${userId}|${site}${staffOrg ? `|staff:${staffOrg}` : ""}`;
|
|
113
197
|
if (resolvedFor === key) return;
|
|
198
|
+
if (landingAnswerStillHolds(userId, site, staffOrg)) {
|
|
199
|
+
resolvedFor = key;
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
114
202
|
if (inFlight) {
|
|
115
203
|
// A lookup for the SAME key is the one we want: await it and stop, which
|
|
116
204
|
// is what this did before there was a key. One for another site is not,
|
|
@@ -133,14 +221,13 @@ export default defineNuxtPlugin(() => {
|
|
|
133
221
|
}
|
|
134
222
|
|
|
135
223
|
async function run(userId: string, site: string, staffOrg = "") {
|
|
136
|
-
const APP = useRuntimeConfig().public.APP;
|
|
137
|
-
|
|
138
224
|
staffViewActive = !!staffOrg;
|
|
139
225
|
if (staffOrg) {
|
|
140
226
|
hasMemberDocument = true;
|
|
141
227
|
id.value = staffOrg;
|
|
142
228
|
userAppRole.value = STAFF_VIEW_ROLE;
|
|
143
229
|
resolvedFor = `${userId}|${site}|staff:${staffOrg}`;
|
|
230
|
+
resolvedAt = Date.now();
|
|
144
231
|
userAppRoleStatus.value = "resolved";
|
|
145
232
|
return;
|
|
146
233
|
}
|
|
@@ -151,11 +238,12 @@ export default defineNuxtPlugin(() => {
|
|
|
151
238
|
// membership it has always answered with -- so the only behaviour this
|
|
152
239
|
// adds is Q16 itself. Sending `org` as well would change the fallback
|
|
153
240
|
// too, and that is a separate change.
|
|
154
|
-
const member = await
|
|
155
|
-
getByUserType(userId, APP, undefined, roleFollowsSite() && site ? site : undefined),
|
|
156
|
-
);
|
|
241
|
+
const member = await take(memberKey(userId, site), startMember(userId, site));
|
|
157
242
|
hasMemberDocument = true;
|
|
158
243
|
id.value = member.org ?? "";
|
|
244
|
+
// The client's module list is asked for this org and site and does not
|
|
245
|
+
// need the role, so it goes out while the role is being read.
|
|
246
|
+
startDenied(userId, id.value ?? "", site);
|
|
159
247
|
userAppRole.value = member.role ? await bounded(getRoleById(member.role)) : null;
|
|
160
248
|
} catch (error) {
|
|
161
249
|
// Anything that is not a 404 is transient. Stay unresolved so the next
|
|
@@ -178,6 +266,7 @@ export default defineNuxtPlugin(() => {
|
|
|
178
266
|
}
|
|
179
267
|
|
|
180
268
|
resolvedFor = `${userId}|${site}`;
|
|
269
|
+
resolvedAt = Date.now();
|
|
181
270
|
userAppRoleStatus.value = "resolved";
|
|
182
271
|
}
|
|
183
272
|
|
|
@@ -201,8 +290,7 @@ export default defineNuxtPlugin(() => {
|
|
|
201
290
|
|
|
202
291
|
let denied: string[] = [];
|
|
203
292
|
try {
|
|
204
|
-
const
|
|
205
|
-
const res = await getDeniedModules(userId, APP, org || undefined, site || undefined);
|
|
293
|
+
const res: any = await take(deniedKey(userId, org, site), askDenied(userId, org, site));
|
|
206
294
|
const list = (res as any)?.denied;
|
|
207
295
|
if (Array.isArray(list)) denied = list.filter((k): k is string => typeof k === "string");
|
|
208
296
|
} catch {
|
|
@@ -214,6 +302,64 @@ export default defineNuxtPlugin(() => {
|
|
|
214
302
|
userAppModulesDenied.value = denied;
|
|
215
303
|
}
|
|
216
304
|
|
|
305
|
+
// The staff view belongs to the session, not to an organisation, and is read
|
|
306
|
+
// once per page load (`loadStaffView` keeps its answer), so one key serves
|
|
307
|
+
// every route.
|
|
308
|
+
const viewKey = (userId: string) => `view:${userId}`;
|
|
309
|
+
const startView = () => bounded(loadStaffView());
|
|
310
|
+
/**
|
|
311
|
+
* May the member / module-list lookups start before the staff view is read?
|
|
312
|
+
* Staff working inside a client are given full setup rights and NO member
|
|
313
|
+
* document is looked up for them (test/staff-view-role.test.mjs), so on an
|
|
314
|
+
* organisation's page they wait for the view - unless it is already known not
|
|
315
|
+
* to cover this organisation. A page with no organisation is never opened as
|
|
316
|
+
* staff, so nothing there depends on the view.
|
|
317
|
+
*/
|
|
318
|
+
const viewSettled = (routeOrg: string) =>
|
|
319
|
+
!routeOrg || (staffViewLoaded.value && !staffViewCovers(staffView.value, routeOrg));
|
|
320
|
+
const orgKey = (org: string) => `org:${org}`;
|
|
321
|
+
const startOrg = (org: string) => () => bounded(getById(org));
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Start every lookup the guard is about to need that does not depend on
|
|
325
|
+
* another lookup's answer, so they travel together instead of in a row. Reads
|
|
326
|
+
* nothing and decides nothing: the guard still takes each answer in its
|
|
327
|
+
* original order and applies it exactly as before. Called by the terms-gate
|
|
328
|
+
* middleware (which runs first and then waits for its own answer) and by the
|
|
329
|
+
* guard itself.
|
|
330
|
+
*/
|
|
331
|
+
function warmSession(to: { params?: Record<string, any>; meta?: Record<string, any> }) {
|
|
332
|
+
const userId = useCookie("user").value ?? "";
|
|
333
|
+
if (!userId) return;
|
|
334
|
+
const site = idParam(to.params?.site);
|
|
335
|
+
const routeOrg = idParam(to.params?.org) || idParam(to.params?.organization);
|
|
336
|
+
|
|
337
|
+
// Read the staff view at the first page of a session, wherever it is: the
|
|
338
|
+
// organisation's pages that follow then find it already answered.
|
|
339
|
+
prefetch(viewKey(userId), startView);
|
|
340
|
+
|
|
341
|
+
// The membership, only when the guard is going to ask for it (and not for
|
|
342
|
+
// someone already working inside a client as Seven365 staff).
|
|
343
|
+
if (
|
|
344
|
+
viewSettled(routeOrg) &&
|
|
345
|
+
!staffViewActive &&
|
|
346
|
+
!inFlight &&
|
|
347
|
+
resolvedFor !== `${userId}|${site}` &&
|
|
348
|
+
!landingAnswerStillHolds(userId, site, "")
|
|
349
|
+
) {
|
|
350
|
+
prefetch(memberKey(userId, site), startMember(userId, site));
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
// The client's module list for a site of an organisation we already know.
|
|
354
|
+
const org = id.value ?? "";
|
|
355
|
+
if (viewSettled(routeOrg) && hasMemberDocument && !staffViewActive && org && deniedFor !== `${userId}|${org}|${site}`) {
|
|
356
|
+
startDenied(userId, org, site);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
// The organisation document is read for member pages and needs no role.
|
|
360
|
+
if (to.meta?.memberOnly && routeOrg) prefetch(orgKey(routeOrg), startOrg(routeOrg));
|
|
361
|
+
}
|
|
362
|
+
|
|
217
363
|
router.beforeEach(async (to) => {
|
|
218
364
|
const userId = useCookie("user").value ?? "";
|
|
219
365
|
|
|
@@ -225,8 +371,16 @@ export default defineNuxtPlugin(() => {
|
|
|
225
371
|
// Awaited, so no gate is ever evaluated against an unresolved role.
|
|
226
372
|
const site = idParam(to.params.site);
|
|
227
373
|
const routeOrg = idParam(to.params.org) || idParam(to.params.organization);
|
|
374
|
+
// The lookups below that do not depend on each other are started together
|
|
375
|
+
// (`warmSession`, or right here when nothing warmed them first) and read in
|
|
376
|
+
// the same order as before.
|
|
377
|
+
warmSession(to);
|
|
378
|
+
|
|
228
379
|
// Only an organisation's pages can be opened as staff, so only they ask.
|
|
229
|
-
const view =
|
|
380
|
+
const view =
|
|
381
|
+
userId && routeOrg
|
|
382
|
+
? await take(viewKey(userId), startView).catch(() => null)
|
|
383
|
+
: null;
|
|
230
384
|
const staffOrg = staffViewCovers(view, routeOrg) ? routeOrg : "";
|
|
231
385
|
lastStaffOrg = staffOrg;
|
|
232
386
|
|
|
@@ -271,7 +425,7 @@ export default defineNuxtPlugin(() => {
|
|
|
271
425
|
}
|
|
272
426
|
|
|
273
427
|
try {
|
|
274
|
-
const orgResult = await
|
|
428
|
+
const orgResult = await take(orgKey(org), startOrg(org));
|
|
275
429
|
if (orgResult) orgNature.value = orgResult.nature ?? "";
|
|
276
430
|
} catch (error) {
|
|
277
431
|
// Cosmetic only, and it never blocked navigation before either.
|
|
@@ -302,6 +456,8 @@ export default defineNuxtPlugin(() => {
|
|
|
302
456
|
return Promise.resolve();
|
|
303
457
|
}
|
|
304
458
|
lastRefreshAt = Date.now();
|
|
459
|
+
// The point of this refresh is a FRESH answer: nothing started earlier.
|
|
460
|
+
prefetched.clear();
|
|
305
461
|
const site = idParam(router.currentRoute.value.params.site);
|
|
306
462
|
|
|
307
463
|
refreshing = (async () => {
|
|
@@ -319,6 +475,7 @@ export default defineNuxtPlugin(() => {
|
|
|
319
475
|
return {
|
|
320
476
|
provide: {
|
|
321
477
|
refreshAppRole,
|
|
478
|
+
warmSession,
|
|
322
479
|
},
|
|
323
480
|
};
|
|
324
481
|
});
|
|
@@ -15,7 +15,7 @@ export const BLANK_TOKEN_LENGTH = 24;
|
|
|
15
15
|
/** What the installer strip says under a blank sticker. */
|
|
16
16
|
export const BLANK_STRIP_NOTE = "Not linked yet - link it in Vehicles > Link QR sticker, or scan it with iMA365 / iSecure365";
|
|
17
17
|
|
|
18
|
-
export type BlankItem = { token: string; qr: string; code: string; serialNo?: number };
|
|
18
|
+
export type BlankItem = { token: string; qr: string; code: string; serialNo?: number; serialLabel?: string | null };
|
|
19
19
|
|
|
20
20
|
/** A whole number 1..500, or 0 when the field is empty or not a number. */
|
|
21
21
|
export function blankCount(value: unknown): number {
|
|
@@ -25,7 +25,7 @@ export function blankCount(value: unknown): number {
|
|
|
25
25
|
|
|
26
26
|
/** Sticker items for the normal sticker flow: token = the unique key, the code is printed in the plate slot. */
|
|
27
27
|
export function blankStickerItems(items: BlankItem[]): StickerItem[] {
|
|
28
|
-
return items.map((i) => ({ vehicleId: i.token, qr: i.qr, token: i.token, plateNumber: i.code, status: "active", blank: true, ...(i.serialNo ? { serialNo: i.serialNo } : {}) }));
|
|
28
|
+
return items.map((i) => ({ vehicleId: i.token, qr: i.qr, token: i.token, plateNumber: i.code, status: "active", blank: true, ...(i.serialNo ? { serialNo: i.serialNo, serialLabel: i.serialLabel ?? null } : {}) }));
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
/**
|
|
@@ -94,12 +94,29 @@ export function qrStickerSummary(plates: Array<{ hasQrSticker?: boolean }>): { l
|
|
|
94
94
|
return { label: `${linked} of ${total}`, color: "warning" };
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
/** The list's sticker numbers for one row ("No. 5", or "SBA123A:
|
|
98
|
-
export function qrStickerNumbers(plates: Array<{ hasQrSticker?: boolean; qrSerial?: number; plateNumber?: string }>): string[] {
|
|
97
|
+
/** The list's sticker numbers for one row ("TLR005" / "No. 5", or "SBA123A: TLR005" when the row has several plates). */
|
|
98
|
+
export function qrStickerNumbers(plates: Array<{ hasQrSticker?: boolean; qrSerial?: number; qrSerialLabel?: string | null; plateNumber?: string }>): string[] {
|
|
99
99
|
const many = plates.length > 1;
|
|
100
100
|
return plates
|
|
101
101
|
.filter((p) => p?.hasQrSticker === true && Number.isInteger(p.qrSerial) && Number(p.qrSerial) > 0)
|
|
102
|
-
.map((p) =>
|
|
102
|
+
.map((p) => {
|
|
103
|
+
const label = String(p.qrSerialLabel ?? "").trim() || `No. ${p.qrSerial}`;
|
|
104
|
+
return many ? `${p.plateNumber}: ${label}` : label;
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** The site's sticker number settings (Site Settings > Vehicle QR stickers). */
|
|
109
|
+
export const SERIAL_PREFIX_PATTERN = /^[A-Z0-9-]{0,8}$/;
|
|
110
|
+
export const SERIAL_DEFAULT_DIGITS = 3;
|
|
111
|
+
|
|
112
|
+
/** Same rule as the server: (1, "TLR", 3) -> "TLR001", (1234, "TLR", 3) -> "TLR1234", no prefix -> "No. 1". */
|
|
113
|
+
export function formatStickerSerial(n: number, prefix?: string | null, digits: number = SERIAL_DEFAULT_DIGITS): string {
|
|
114
|
+
return prefix ? prefix + String(n).padStart(digits, "0") : `No. ${n}`;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** What a person typed as the prefix, as it will be saved: trimmed, capitals. */
|
|
118
|
+
export function cleanSerialPrefix(input: unknown): string {
|
|
119
|
+
return String(input ?? "").trim().toUpperCase();
|
|
103
120
|
}
|
|
104
121
|
|
|
105
122
|
export type BlankSummary = { printed: number; linked: number; available: number };
|
|
@@ -150,8 +150,8 @@ export const SERIAL_OPTIONS: { value: SerialChoice; title: string }[] = [
|
|
|
150
150
|
];
|
|
151
151
|
|
|
152
152
|
export const PLATE_OPTIONS: { value: PlateChoice; title: string }[] = [
|
|
153
|
-
{ value: "show", title: "Show" },
|
|
154
|
-
{ value: "hide", title: "Hide
|
|
153
|
+
{ value: "show", title: "Show (default)" },
|
|
154
|
+
{ value: "hide", title: "Hide - QR and serial number only" },
|
|
155
155
|
];
|
|
156
156
|
|
|
157
157
|
export const LABEL_OPTIONS: { value: LabelChoice; title: string }[] = [
|
|
@@ -179,6 +179,8 @@ export type StickerItem = {
|
|
|
179
179
|
blank?: boolean;
|
|
180
180
|
/** The sticker's running number at its site (1, 2, 3 ...). */
|
|
181
181
|
serialNo?: number;
|
|
182
|
+
/** That number as the site prints it ("TLR001", or "No. 1" with no prefix) - from the server. */
|
|
183
|
+
serialLabel?: string | null;
|
|
182
184
|
};
|
|
183
185
|
|
|
184
186
|
export type StickerPlateRow = {
|
|
@@ -194,13 +196,16 @@ export type StickerPlateRow = {
|
|
|
194
196
|
const text = (v: unknown) => (v == null ? "" : String(v).trim());
|
|
195
197
|
|
|
196
198
|
/**
|
|
197
|
-
* The sticker's running number at its site
|
|
198
|
-
*
|
|
199
|
-
*
|
|
199
|
+
* The sticker's running number at its site as the site prints it: the
|
|
200
|
+
* server's `serialLabel` ("TLR001" with a prefix set in Site Settings), else
|
|
201
|
+
* "No. 12". The server gives each sticker the next number when it is first
|
|
202
|
+
* printed (1, 2, 3 ...) and it never changes, so No. 1 stays Mrs Tan's
|
|
203
|
+
* sticker. "" when the server sent no number.
|
|
200
204
|
*/
|
|
201
|
-
export function stickerSerial(item: Pick<StickerItem, "serialNo">): string {
|
|
205
|
+
export function stickerSerial(item: Pick<StickerItem, "serialNo" | "serialLabel">): string {
|
|
202
206
|
const n = Number(item?.serialNo);
|
|
203
|
-
|
|
207
|
+
if (!Number.isInteger(n) || n < 1) return "";
|
|
208
|
+
return text(item?.serialLabel) || `No. ${n}`;
|
|
204
209
|
}
|
|
205
210
|
|
|
206
211
|
/** What a saved picture is named after: the plate - or, with the plate hidden, the sticker's number (the file name must not give the plate away either). */
|