@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
|
@@ -98,7 +98,7 @@
|
|
|
98
98
|
@update:model-value="(v: any) => (ticked = setIds(ticked, [it.vehicleId], !!v))" /></td>
|
|
99
99
|
<template v-if="isBlank">
|
|
100
100
|
<td class="font-weight-bold">{{ blankRowLabel(it) }}</td>
|
|
101
|
-
<td class="text-medium-emphasis">{{
|
|
101
|
+
<td class="text-medium-emphasis">{{ blankStripNote(it, design) }}</td>
|
|
102
102
|
</template>
|
|
103
103
|
<template v-else>
|
|
104
104
|
<td>{{ installerLine(it).place || "-" }}</td>
|
|
@@ -117,10 +117,19 @@
|
|
|
117
117
|
</v-table>
|
|
118
118
|
<v-alert v-if="isBlank && design.shape !== 'square' && design.text === 'none'" type="warning" variant="tonal"
|
|
119
119
|
density="compact" class="my-2" data-test="vehicle-qr-blank-notext">
|
|
120
|
-
With "No text" the sticker's code
|
|
121
|
-
|
|
120
|
+
With "No text" nothing is printed under the shape - neither the sticker's code nor its number - so these stickers
|
|
121
|
+
can only be linked by scanning them with iMA365 / iSecure365. Pick another Text option to print it.
|
|
122
122
|
</v-alert>
|
|
123
|
-
<
|
|
123
|
+
<v-alert v-if="isBlank && design.blankCode === 'hide' && blankWithoutNumber" type="info" variant="tonal"
|
|
124
|
+
density="compact" class="my-2" data-test="vehicle-qr-blank-code-kept">
|
|
125
|
+
{{ blankWithoutNumber }} sticker(s) have no sticker number, so their long code is still printed on them.
|
|
126
|
+
</v-alert>
|
|
127
|
+
<p v-if="isBlank && design.blankCode === 'hide'" class="text-caption text-medium-emphasis my-2">
|
|
128
|
+
Each sticker has a cut-off strip under the dashed line saying it is not linked yet - cut it off before pasting
|
|
129
|
+
the sticker on the car. To link one, pick its sticker number in Vehicles > Link QR sticker, or scan it with
|
|
130
|
+
iMA365 / iSecure365.
|
|
131
|
+
</p>
|
|
132
|
+
<p v-else-if="isBlank" class="text-caption text-medium-emphasis my-2">
|
|
124
133
|
Each sticker has a cut-off strip under the dashed line saying it is not linked yet - cut it off before pasting
|
|
125
134
|
the sticker on the car. The code on the sticker is what you type in Vehicles > Link QR sticker.
|
|
126
135
|
</p>
|
|
@@ -178,6 +187,10 @@
|
|
|
178
187
|
<v-select v-model="design.serial" :items="SERIAL_OPTIONS" label="Serial number" density="compact"
|
|
179
188
|
hide-details data-test="vehicle-qr-serial" />
|
|
180
189
|
</v-col>
|
|
190
|
+
<v-col v-if="isBlank" cols="12" sm="6" md="4">
|
|
191
|
+
<v-select v-model="design.blankCode" :items="BLANK_CODE_OPTIONS" label="Sticker code (long code)"
|
|
192
|
+
density="compact" hide-details data-test="vehicle-qr-blank-code" />
|
|
193
|
+
</v-col>
|
|
181
194
|
<v-col v-if="!isBlank" cols="12" sm="6" md="4">
|
|
182
195
|
<v-select v-model="design.plate" :items="PLATE_OPTIONS" label="Plate number on the sticker" density="compact"
|
|
183
196
|
hide-details data-test="vehicle-qr-plate" />
|
|
@@ -260,7 +273,7 @@
|
|
|
260
273
|
<script lang="ts" setup>
|
|
261
274
|
import QRCode from "qrcode";
|
|
262
275
|
import useVehicle from "../composables/useVehicle";
|
|
263
|
-
import { BLANK_DEFAULT_COUNT, BLANK_LIST_NOTE, BLANK_MAX_COUNT,
|
|
276
|
+
import { BLANK_DEFAULT_COUNT, BLANK_LIST_NOTE, BLANK_MAX_COUNT, SAVED_REPRINT_MAX, blankRowLabel, savedBlankItems, STICKER_NEW_NOTE, STICKER_SAME_NOTE, blankCount, blankStickerItems, blankSummaryText, reprintItems, type BlankSummary } from "../utils/vehicle-qr-blank";
|
|
264
277
|
import { errorConverter } from "../utils/data";
|
|
265
278
|
import { saveFile, stickerBundleName, stickerFileNames, svgToImage, zipFiles, type ImageFormat } from "../utils/vehicle-qr-export";
|
|
266
279
|
import {
|
|
@@ -277,11 +290,14 @@ import {
|
|
|
277
290
|
stickerSizeLines,
|
|
278
291
|
stickerCardSvgs,
|
|
279
292
|
stickerFileLabel,
|
|
293
|
+
stickerSerial,
|
|
280
294
|
stickerWarning,
|
|
295
|
+
blankStripNote,
|
|
281
296
|
type StickerItem,
|
|
282
297
|
type StickerPlateRow,
|
|
283
298
|
} from "../utils/vehicle-qr-sticker";
|
|
284
299
|
import {
|
|
300
|
+
BLANK_CODE_OPTIONS,
|
|
285
301
|
DEFAULT_STICKER_DESIGN,
|
|
286
302
|
DOT_OPTIONS,
|
|
287
303
|
EYE_OPTIONS,
|
|
@@ -337,6 +353,8 @@ const step = ref<"select" | "review">("select");
|
|
|
337
353
|
const plates = ref<StickerPlateRow[]>([]);
|
|
338
354
|
const selected = ref<string[]>([]);
|
|
339
355
|
const items = ref<StickerItem[]>([]);
|
|
356
|
+
// "Sticker code: Hide" keeps the code on a blank that has no number (never neither).
|
|
357
|
+
const blankWithoutNumber = computed(() => items.value.filter((i) => i.blank && !stickerSerial(i)).length);
|
|
340
358
|
const ticked = ref<string[]>([]);
|
|
341
359
|
const missing = ref<string[]>([]);
|
|
342
360
|
const dropped = ref(0);
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { TSiteJoinRequest, TSiteJoinRequestStatus, TSiteNameMatch } from "../utils/site-join-request";
|
|
2
|
+
|
|
1
3
|
export default function useCustomerSite() {
|
|
2
4
|
function add(payload: TCustomerSite) {
|
|
3
5
|
return useNuxtApp().$api<Record<string, any>>("/api/customer-sites", {
|
|
@@ -110,7 +112,55 @@ async function deleteById(id: string) {
|
|
|
110
112
|
return useNuxtApp().$api<Record<string, any>>(`/api/customer-sites/provider-changes/${id}/cancel`, { method: "POST" });
|
|
111
113
|
}
|
|
112
114
|
|
|
115
|
+
// Site already exists under another company -> ask its managing agent for
|
|
116
|
+
// access (spec 2026-11-16-site-exists-ma-approval). Types: utils/site-join-request.ts.
|
|
117
|
+
function checkSiteName(org: string, name: string) {
|
|
118
|
+
return useNuxtApp().$api<{ matches: TSiteNameMatch[] }>("/api/customer-sites/name-check", {
|
|
119
|
+
method: "GET",
|
|
120
|
+
query: { org, name },
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
function createJoinRequest(org: string, site: string, note?: string) {
|
|
124
|
+
return useNuxtApp().$api<TSiteJoinRequest>("/api/customer-sites/join-requests", {
|
|
125
|
+
method: "POST",
|
|
126
|
+
body: { org, site, ...(note?.trim() ? { note: note.trim() } : {}) },
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
function getJoinRequests(
|
|
130
|
+
org: string,
|
|
131
|
+
query: { box: "incoming" | "outgoing"; status?: TSiteJoinRequestStatus; page?: number; limit?: number }
|
|
132
|
+
) {
|
|
133
|
+
return useNuxtApp().$api<{ items: TSiteJoinRequest[]; total: number; page: number; limit: number; canApprove?: boolean }>(
|
|
134
|
+
"/api/customer-sites/join-requests",
|
|
135
|
+
{ method: "GET", query: { org, ...query } }
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
function approveJoinRequest(id: string, org: string) {
|
|
139
|
+
return useNuxtApp().$api<TSiteJoinRequest>(`/api/customer-sites/join-requests/${id}/approve`, {
|
|
140
|
+
method: "PUT",
|
|
141
|
+
body: { org },
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
function rejectJoinRequest(id: string, org: string, reason?: string) {
|
|
145
|
+
return useNuxtApp().$api<TSiteJoinRequest>(`/api/customer-sites/join-requests/${id}/reject`, {
|
|
146
|
+
method: "PUT",
|
|
147
|
+
body: { org, ...(reason?.trim() ? { reason: reason.trim() } : {}) },
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
function cancelJoinRequest(id: string, org: string) {
|
|
151
|
+
return useNuxtApp().$api<TSiteJoinRequest>(`/api/customer-sites/join-requests/${id}/cancel`, {
|
|
152
|
+
method: "PUT",
|
|
153
|
+
body: { org },
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
|
|
113
157
|
return {
|
|
158
|
+
checkSiteName,
|
|
159
|
+
createJoinRequest,
|
|
160
|
+
getJoinRequests,
|
|
161
|
+
approveJoinRequest,
|
|
162
|
+
rejectJoinRequest,
|
|
163
|
+
cancelJoinRequest,
|
|
114
164
|
previewProviderChange,
|
|
115
165
|
applyProviderChange,
|
|
116
166
|
listProviderChanges,
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { orderedBlankPicks, type BlankPick } from "../utils/vehicle-qr-blank";
|
|
2
|
+
|
|
1
3
|
export default function useVehicle() {
|
|
2
4
|
async function getVehicles({
|
|
3
5
|
search = "",
|
|
@@ -330,17 +332,35 @@ function getSpecificVehicleById(id: string){
|
|
|
330
332
|
|
|
331
333
|
// Blank codes saved when printed and still free to link, plus {printed, linked, available}.
|
|
332
334
|
// `search` matches the code or the sticker number; `qr` lets a saved sticker be printed again.
|
|
333
|
-
function getAvailableBlankVehicleQr(site: string, query: { search?: string; page?: number; limit?: number } = {}) {
|
|
335
|
+
function getAvailableBlankVehicleQr(site: string, query: { search?: string; page?: number; limit?: number; sort?: "serial" } = {}) {
|
|
334
336
|
return useNuxtApp().$api<{
|
|
335
337
|
site?: { _id: string; name: string };
|
|
336
338
|
summary: { printed: number; linked: number; available: number };
|
|
337
339
|
total: number;
|
|
338
340
|
page: number;
|
|
339
341
|
limit: number;
|
|
340
|
-
items:
|
|
342
|
+
items: BlankPick[];
|
|
343
|
+
/** With `sort=serial`: the first available sticker (lowest number). */
|
|
344
|
+
next?: BlankPick | null;
|
|
341
345
|
}>(`/api/vehicles/qr/blank-stickers/site/${site}`, { query });
|
|
342
346
|
}
|
|
343
347
|
|
|
348
|
+
/**
|
|
349
|
+
* Blank stickers for a pick-list: by sticker number, the NEXT one first.
|
|
350
|
+
* Asks for `sort=serial`; a server without it yet refuses the unknown field
|
|
351
|
+
* (400), so the list is asked again without it and sorted here.
|
|
352
|
+
*/
|
|
353
|
+
async function getBlankStickersBySerial(site: string, query: { search?: string; limit?: number } = {}) {
|
|
354
|
+
let res: Awaited<ReturnType<typeof getAvailableBlankVehicleQr>>;
|
|
355
|
+
try {
|
|
356
|
+
res = await getAvailableBlankVehicleQr(site, { ...query, sort: "serial" });
|
|
357
|
+
} catch (e: any) {
|
|
358
|
+
if ((e?.statusCode ?? e?.status ?? e?.response?.status) !== 400) throw e;
|
|
359
|
+
res = await getAvailableBlankVehicleQr(site, query);
|
|
360
|
+
}
|
|
361
|
+
return { summary: res?.summary ?? null, ...orderedBlankPicks(res) };
|
|
362
|
+
}
|
|
363
|
+
|
|
344
364
|
// `token` is sent as typed - the server ignores case, spaces and dashes.
|
|
345
365
|
function linkVehicleQr(token: string, vehicleId: string, replace?: boolean) {
|
|
346
366
|
return useNuxtApp().$api<Record<string, any>>("/api/vehicles/qr/link", {
|
|
@@ -381,6 +401,7 @@ function getSpecificVehicleById(id: string){
|
|
|
381
401
|
undoReissueVehicleQr,
|
|
382
402
|
getBlankVehicleQrStickers,
|
|
383
403
|
getAvailableBlankVehicleQr,
|
|
404
|
+
getBlankStickersBySerial,
|
|
384
405
|
linkVehicleQr,
|
|
385
406
|
unlinkVehicleQr,
|
|
386
407
|
};
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@7365admin1/layer-common",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "4.
|
|
5
|
+
"version": "4.185.0",
|
|
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.",
|
package/utils/building-block.ts
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
|
-
/** The
|
|
1
|
+
/** The default block label: "Blk 3", "Blk 12A" - used as the block's name when no name is typed. */
|
|
2
2
|
export const blockLabel = (block: number | string | null | undefined): string => `Blk ${block}`;
|
|
3
3
|
|
|
4
|
+
/** The name a block is saved with: what was typed (e.g. "Barbeque Pit"), or "Blk N" when left empty. */
|
|
5
|
+
export function blockNameFor(block: number | string | null | undefined, typed?: string | null): string {
|
|
6
|
+
return String(typed ?? "").trim() || blockLabel(block);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** How a block shows in lists: "Blk 7", or "Blk 7 - Barbeque Pit" when it has its own name. */
|
|
10
|
+
export function blockDisplay(block: number | string | null | undefined, name?: string | null): string {
|
|
11
|
+
if (block === null || block === undefined || block === "") return String(name ?? "").trim();
|
|
12
|
+
const label = blockLabel(block);
|
|
13
|
+
const own = String(name ?? "").trim();
|
|
14
|
+
return own && own.toLowerCase() !== label.toLowerCase() ? `${label} - ${own}` : label;
|
|
15
|
+
}
|
|
16
|
+
|
|
4
17
|
export const BLOCK_NO_MESSAGE = "Block No must be a number from 1 to 9999, optionally followed by one letter (for example 12 or 12A).";
|
|
5
18
|
|
|
6
19
|
/**
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* "This site already exists" + access requests to the site's managing agent
|
|
3
|
+
* (spec 2026-11-16-site-exists-ma-approval). Pure helpers for the Add Site
|
|
4
|
+
* form and the Access requests list, so the wording and the rules are tested
|
|
5
|
+
* once here instead of living inside the components.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/** One row of GET /api/customer-sites/name-check. */
|
|
9
|
+
export type TSiteNameMatch = {
|
|
10
|
+
site: string;
|
|
11
|
+
name: string;
|
|
12
|
+
match: "duplicate" | "near-duplicate";
|
|
13
|
+
sameOrg: boolean;
|
|
14
|
+
managedBy: string[];
|
|
15
|
+
linked: boolean;
|
|
16
|
+
pendingRequest: string | null;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export type TSiteJoinRequestStatus = "pending" | "approved" | "rejected" | "cancelled";
|
|
20
|
+
|
|
21
|
+
/** A `site.join-requests` document as the API returns it. */
|
|
22
|
+
export type TSiteJoinRequest = {
|
|
23
|
+
_id: string;
|
|
24
|
+
site: string;
|
|
25
|
+
siteName: string;
|
|
26
|
+
siteOrg?: string;
|
|
27
|
+
requesterOrg: string;
|
|
28
|
+
requesterOrgName?: string;
|
|
29
|
+
requestedBy?: string | { _id?: string; name?: string; email?: string };
|
|
30
|
+
requestedByName?: string;
|
|
31
|
+
approverOrgs?: string[];
|
|
32
|
+
status: TSiteJoinRequestStatus;
|
|
33
|
+
note?: string;
|
|
34
|
+
reason?: string;
|
|
35
|
+
decidedAt?: string | null;
|
|
36
|
+
createdAt?: string;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* What the form does with one match:
|
|
41
|
+
* - `same-org`: one of our own sites - the server's existing message still decides.
|
|
42
|
+
* - `linked`: another company's site we already serve - nothing to request.
|
|
43
|
+
* - `pending`: we already asked; waiting for the managing agent.
|
|
44
|
+
* - `requestable`: same site, another company - Save is blocked, ask for access.
|
|
45
|
+
* - `near`: similar name only - a warning, Save stays allowed.
|
|
46
|
+
*/
|
|
47
|
+
export type TSiteMatchState = "same-org" | "linked" | "pending" | "requestable" | "near";
|
|
48
|
+
|
|
49
|
+
export const SITE_NAME_CHECK_MIN = 3;
|
|
50
|
+
|
|
51
|
+
export function shouldCheckSiteName(name?: string | null): boolean {
|
|
52
|
+
return String(name ?? "").trim().length >= SITE_NAME_CHECK_MIN;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function siteMatchState(m: TSiteNameMatch): TSiteMatchState {
|
|
56
|
+
if (m.sameOrg) return "same-org";
|
|
57
|
+
if (m.match !== "duplicate") return "near";
|
|
58
|
+
if (m.linked) return "linked";
|
|
59
|
+
if (m.pendingRequest) return "pending";
|
|
60
|
+
return "requestable";
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function managedByText(managedBy?: string[] | null): string {
|
|
64
|
+
const names = (managedBy ?? []).map((n) => String(n ?? "").trim()).filter(Boolean);
|
|
65
|
+
return names.length ? names.join(", ") : "another company";
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** "<name> - managed by X" - one line per match in the alert. */
|
|
69
|
+
export function siteMatchLabel(m: TSiteNameMatch): string {
|
|
70
|
+
if (m.sameOrg) return `${m.name} - already one of your sites`;
|
|
71
|
+
return `${m.name} - managed by ${managedByText(m.managedBy)}`;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** The match that stops Save: the same site already run by another company. */
|
|
75
|
+
export function blockingSiteMatch(matches?: TSiteNameMatch[] | null): TSiteNameMatch | null {
|
|
76
|
+
return (matches ?? []).find((m) => !m.sameOrg && m.match === "duplicate") ?? null;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function hasNearSiteMatch(matches?: TSiteNameMatch[] | null): boolean {
|
|
80
|
+
return (matches ?? []).some((m) => siteMatchState(m) === "near");
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Plain sentence under the matches for the blocking match, by state. */
|
|
84
|
+
export function siteMatchMessage(m: TSiteNameMatch): string {
|
|
85
|
+
switch (siteMatchState(m)) {
|
|
86
|
+
case "linked":
|
|
87
|
+
return `Already linked - your company already serves ${m.name}. You can find it on your Sites list.`;
|
|
88
|
+
case "pending":
|
|
89
|
+
return `Request pending - you have already asked ${managedByText(m.managedBy)} for access. You will be notified when they answer.`;
|
|
90
|
+
case "requestable":
|
|
91
|
+
return `${m.name} is already set up by ${managedByText(m.managedBy)}. Instead of adding it again, ask them to give your company access.`;
|
|
92
|
+
case "near":
|
|
93
|
+
return "A site with a similar name already exists. If this is a different property, you can carry on.";
|
|
94
|
+
default:
|
|
95
|
+
return "";
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* A 409 `{ code: "SITE_EXISTS" }` from Save (someone created the site while
|
|
101
|
+
* the form was open) turned into the same match the name-check gives, so the
|
|
102
|
+
* form shows the same "Request access" offer. Anything else -> null.
|
|
103
|
+
*/
|
|
104
|
+
export function siteExistsFromError(err: any): TSiteNameMatch | null {
|
|
105
|
+
const data = err?.data ?? err?.response?._data;
|
|
106
|
+
if (!data || data.code !== "SITE_EXISTS" || !data.site) return null;
|
|
107
|
+
return {
|
|
108
|
+
site: String(data.site),
|
|
109
|
+
name: String(data.name ?? ""),
|
|
110
|
+
match: "duplicate",
|
|
111
|
+
sameOrg: false,
|
|
112
|
+
managedBy: Array.isArray(data.managedBy) ? data.managedBy.map(String) : [],
|
|
113
|
+
linked: false,
|
|
114
|
+
pendingRequest: null,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const STATUS_LABELS: Record<TSiteJoinRequestStatus, string> = {
|
|
119
|
+
pending: "Pending",
|
|
120
|
+
approved: "Approved",
|
|
121
|
+
rejected: "Rejected",
|
|
122
|
+
cancelled: "Cancelled",
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
export function joinRequestStatusLabel(status?: string | null): string {
|
|
126
|
+
return STATUS_LABELS[status as TSiteJoinRequestStatus] ?? "Unknown";
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** Who asked: a populated user, a name field, or nothing. */
|
|
130
|
+
export function joinRequestRequester(r: Pick<TSiteJoinRequest, "requestedBy" | "requestedByName">): string {
|
|
131
|
+
if (r.requestedByName) return r.requestedByName;
|
|
132
|
+
const by = r.requestedBy;
|
|
133
|
+
if (by && typeof by === "object") return by.name || by.email || "";
|
|
134
|
+
return "";
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** One sentence per card saying where the request stands. */
|
|
138
|
+
export function joinRequestStateLine(r: TSiteJoinRequest, box: "incoming" | "outgoing"): string {
|
|
139
|
+
const who = r.requesterOrgName || "This company";
|
|
140
|
+
if (box === "incoming") {
|
|
141
|
+
switch (r.status) {
|
|
142
|
+
case "pending":
|
|
143
|
+
return `${who} asks to be linked to ${r.siteName}. Approving adds the site to their Sites list; they will not see your other sites.`;
|
|
144
|
+
case "approved":
|
|
145
|
+
return `Approved - ${who} now has ${r.siteName} on their Sites list.`;
|
|
146
|
+
case "rejected":
|
|
147
|
+
return `Rejected - ${who} was told${r.reason ? `: "${r.reason}"` : "."}`;
|
|
148
|
+
default:
|
|
149
|
+
return `${who} cancelled this request.`;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
switch (r.status) {
|
|
153
|
+
case "pending":
|
|
154
|
+
return `Waiting for the managing agent of ${r.siteName} to answer. You will be notified.`;
|
|
155
|
+
case "approved":
|
|
156
|
+
return `Approved - ${r.siteName} is now on your Sites list.`;
|
|
157
|
+
case "rejected":
|
|
158
|
+
return `The managing agent declined this request${r.reason ? `: "${r.reason}"` : "."}`;
|
|
159
|
+
default:
|
|
160
|
+
return "You cancelled this request.";
|
|
161
|
+
}
|
|
162
|
+
}
|
|
@@ -148,3 +148,63 @@ export function blankSummaryText(s: Partial<BlankSummary> | null | undefined): s
|
|
|
148
148
|
|
|
149
149
|
/** Shown beside the pick-list: stickers printed before the list existed were never saved. */
|
|
150
150
|
export const BLANK_LIST_NOTE = "Stickers printed before 9 Oct 2026 are not in this list - scan them or type their code.";
|
|
151
|
+
|
|
152
|
+
/** The strip under a blank sticker printed WITHOUT its long code: link it by its number, never "type the code". */
|
|
153
|
+
export const BLANK_STRIP_NOTE_NUMBER = "Not linked yet - link it by its sticker number in Vehicles > Link QR sticker, or scan it with iMA365 / iSecure365";
|
|
154
|
+
|
|
155
|
+
/** One saved blank sticker in a pick-list (GET /api/vehicles/qr/blank-stickers/site/:site). */
|
|
156
|
+
export type BlankPick = { token: string; code: string; qr?: string; serialNo?: number | null; serialLabel?: string | null };
|
|
157
|
+
|
|
158
|
+
const serialOf = (i: Pick<BlankPick, "serialNo">) => {
|
|
159
|
+
const n = Number(i?.serialNo);
|
|
160
|
+
return Number.isInteger(n) && n > 0 ? n : 0;
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
/** The number a pick-list shows: "TLR002", "No. 2", or "" when the sticker has none. */
|
|
164
|
+
export function blankPickSerial(i: Pick<BlankPick, "serialNo" | "serialLabel">): string {
|
|
165
|
+
const n = serialOf(i);
|
|
166
|
+
return n ? String(i.serialLabel ?? "").trim() || `No. ${n}` : "";
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** "TLR002 - ABCD-EFGH-..." - or just the code for a sticker with no number. */
|
|
170
|
+
export function blankPickLabel(i: BlankPick): string {
|
|
171
|
+
const sn = blankPickSerial(i);
|
|
172
|
+
return sn ? `${sn} - ${i.code}` : i.code;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** Ascending by sticker number; stickers with no number last, in the order they came. */
|
|
176
|
+
export function sortBlankBySerial<T extends Pick<BlankPick, "serialNo">>(items: T[]): T[] {
|
|
177
|
+
return items
|
|
178
|
+
.map((item, at) => ({ item, at, n: serialOf(item) }))
|
|
179
|
+
.sort((a, b) => (a.n && b.n ? a.n - b.n : a.n ? -1 : b.n ? 1 : 0) || a.at - b.at)
|
|
180
|
+
.map((x) => x.item);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* The pick-list in sticker-number order with the NEXT sticker on top. A server
|
|
185
|
+
* that took `sort=serial` sends its order and `next`; an older one sends
|
|
186
|
+
* neither, so the list is sorted here and the lowest number is next.
|
|
187
|
+
*/
|
|
188
|
+
export function orderedBlankPicks<T extends BlankPick>(res: { items?: T[] | null; next?: T | null } | null | undefined): { items: T[]; next: T | null } {
|
|
189
|
+
const raw = Array.isArray(res?.items) ? res!.items! : [];
|
|
190
|
+
const items = res?.next ? [...raw] : sortBlankBySerial(raw);
|
|
191
|
+
const next = res?.next ?? items[0] ?? null;
|
|
192
|
+
if (!next) return { items, next: null };
|
|
193
|
+
return { items: [next, ...items.filter((i) => i.token !== next.token)], next };
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* What a pick-list's text means as a code to link: a picked "TLR002 - ABCD-..."
|
|
198
|
+
* line, a sticker number typed on its own ("tlr002"), or a typed / scanned code
|
|
199
|
+
* (sent as is - the server reads it).
|
|
200
|
+
*/
|
|
201
|
+
export function pickedStickerCode(text: unknown, items: BlankPick[] = []): string {
|
|
202
|
+
const t = String(text ?? "").trim();
|
|
203
|
+
if (!t) return "";
|
|
204
|
+
const byLabel = items.find((i) => blankPickLabel(i) === t);
|
|
205
|
+
if (byLabel) return byLabel.code;
|
|
206
|
+
const bySerial = items.find((i) => blankPickSerial(i) && blankPickSerial(i).toUpperCase() === t.toUpperCase());
|
|
207
|
+
if (bySerial) return bySerial.code;
|
|
208
|
+
const at = t.lastIndexOf(" - ");
|
|
209
|
+
return at >= 0 ? t.slice(at + 3).trim() : t;
|
|
210
|
+
}
|
|
@@ -48,8 +48,10 @@ export type LabelChoice = "app" | "verify" | "scanme" | "site" | "none";
|
|
|
48
48
|
export type TextChoice = "below" | "none";
|
|
49
49
|
/** Where the sticker's running number ("No. 12") is printed: not at all, on the sticker, on the cut-off strip, or both. */
|
|
50
50
|
export type SerialChoice = "off" | "sticker" | "strip" | "both";
|
|
51
|
-
/** The vehicle's plate number on the print-out: shown, or left off (a blank sticker's code is
|
|
51
|
+
/** The vehicle's plate number on the print-out: shown, or left off (a blank sticker's code is set by `blankCode`). */
|
|
52
52
|
export type PlateChoice = "show" | "hide";
|
|
53
|
+
/** Blank stickers: print the long 24-character code, or leave it off and print the sticker number in its place (one with no number keeps its code). */
|
|
54
|
+
export type BlankCodeChoice = "print" | "hide";
|
|
53
55
|
|
|
54
56
|
export type StickerTheme = { id: string; title: string; ink: string; eye: string; paper: string };
|
|
55
57
|
|
|
@@ -68,6 +70,7 @@ export type StickerDesign = {
|
|
|
68
70
|
cutLines?: boolean;
|
|
69
71
|
serial?: SerialChoice;
|
|
70
72
|
plate?: PlateChoice;
|
|
73
|
+
blankCode?: BlankCodeChoice;
|
|
71
74
|
};
|
|
72
75
|
|
|
73
76
|
export const DOT_OPTIONS: { value: DotShape; title: string }[] = [
|
|
@@ -154,6 +157,11 @@ export const PLATE_OPTIONS: { value: PlateChoice; title: string }[] = [
|
|
|
154
157
|
{ value: "hide", title: "Hide - QR and serial number only" },
|
|
155
158
|
];
|
|
156
159
|
|
|
160
|
+
export const BLANK_CODE_OPTIONS: { value: BlankCodeChoice; title: string }[] = [
|
|
161
|
+
{ value: "print", title: "Print (default)" },
|
|
162
|
+
{ value: "hide", title: "Hide - QR code and sticker number only" },
|
|
163
|
+
];
|
|
164
|
+
|
|
157
165
|
export const LABEL_OPTIONS: { value: LabelChoice; title: string }[] = [
|
|
158
166
|
{ value: "app", title: "Scan with iSecure365 / iMA365" },
|
|
159
167
|
{ value: "verify", title: "Scan to verify vehicle" },
|
|
@@ -185,6 +193,7 @@ export const DEFAULT_STICKER_DESIGN: StickerDesign = {
|
|
|
185
193
|
cutLines: true,
|
|
186
194
|
serial: "sticker",
|
|
187
195
|
plate: "show",
|
|
196
|
+
blankCode: "print",
|
|
188
197
|
};
|
|
189
198
|
|
|
190
199
|
/** A saved or typed-in design with anything unknown replaced by the default. */
|
|
@@ -209,6 +218,7 @@ export function normalizeDesign(raw: unknown): StickerDesign {
|
|
|
209
218
|
cutLines: typeof r.cutLines === "boolean" ? r.cutLines : true,
|
|
210
219
|
serial: pick(r.serial, SERIAL_OPTIONS, d.serial),
|
|
211
220
|
plate: pick(r.plate, PLATE_OPTIONS, d.plate!),
|
|
221
|
+
blankCode: pick(r.blankCode, BLANK_CODE_OPTIONS, d.blankCode!),
|
|
212
222
|
};
|
|
213
223
|
}
|
|
214
224
|
|
|
@@ -226,7 +236,7 @@ export function rememberedDesign(saved: unknown, savedSerial: unknown): StickerD
|
|
|
226
236
|
* The design as printed. With the plate hidden on vehicle stickers, a shaped
|
|
227
237
|
* code whose tab under the shape would be left empty (no serial or words on
|
|
228
238
|
* it) is printed with no tab, so no bare paper tab hangs under the shape.
|
|
229
|
-
* Blank stickers always print their code in the tab, so they keep it.
|
|
239
|
+
* Blank stickers always print their code or sticker number in the tab, so they keep it.
|
|
230
240
|
*/
|
|
231
241
|
export function printedDesign(design: unknown, blank = false, siteName = ""): StickerDesign {
|
|
232
242
|
const d = normalizeDesign(design);
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
stickerTheme,
|
|
19
19
|
type StickerDesign,
|
|
20
20
|
} from "./vehicle-qr-design.ts";
|
|
21
|
-
import { BLANK_STRIP_NOTE, isBlankCode, plateLines } from "./vehicle-qr-blank.ts";
|
|
21
|
+
import { BLANK_STRIP_NOTE, BLANK_STRIP_NOTE_NUMBER, isBlankCode, plateLines } from "./vehicle-qr-blank.ts";
|
|
22
22
|
|
|
23
23
|
/** The server's most vehicles per request (POST /api/vehicles/qr/stickers). */
|
|
24
24
|
export const STICKER_MAX_PER_REQUEST = 500;
|
|
@@ -208,12 +208,27 @@ export function stickerSerial(item: Pick<StickerItem, "serialNo" | "serialLabel"
|
|
|
208
208
|
return text(item?.serialLabel) || `No. ${n}`;
|
|
209
209
|
}
|
|
210
210
|
|
|
211
|
-
/**
|
|
212
|
-
|
|
211
|
+
/**
|
|
212
|
+
* A blank sticker printed with its sticker number in place of the long code
|
|
213
|
+
* (design "Sticker code: Hide"). Only when it HAS a number - a sticker never
|
|
214
|
+
* goes out with neither the code nor a number on it.
|
|
215
|
+
*/
|
|
216
|
+
export function blankCodeHidden(item: Pick<StickerItem, "blank" | "serialNo" | "serialLabel">, design: Pick<StickerDesign, "blankCode">): boolean {
|
|
217
|
+
return !!item.blank && design.blankCode === "hide" && !!stickerSerial(item);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** The strip under a blank sticker: link by number when the code is not on it. */
|
|
221
|
+
export function blankStripNote(item: Pick<StickerItem, "blank" | "serialNo" | "serialLabel">, design: Pick<StickerDesign, "blankCode">): string {
|
|
222
|
+
return blankCodeHidden(item, design) ? BLANK_STRIP_NOTE_NUMBER : BLANK_STRIP_NOTE;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/** What a saved picture is named after: the plate - or, with the plate (or a blank's code) hidden, the sticker's number (the file name must not give the plate away either). */
|
|
226
|
+
export function stickerFileLabel(item: StickerItem, design: Pick<StickerDesign, "plate" | "blankCode">): string {
|
|
227
|
+
if (blankCodeHidden(item, design)) return stickerSerial(item);
|
|
213
228
|
return shownPlateLines(item, design.plate === "hide").length ? text(item.plateNumber) : stickerSerial(item) || "sticker";
|
|
214
229
|
}
|
|
215
230
|
|
|
216
|
-
/** The plate lines printed on a sticker: none when the plate is hidden -
|
|
231
|
+
/** The plate lines printed on a sticker: none when the plate is hidden - a blank sticker's code is printed unless `blankCodeHidden` (see `headLines`). */
|
|
217
232
|
function shownPlateLines(item: StickerItem, hidePlate: boolean): string[] {
|
|
218
233
|
const plate = text(item.plateNumber);
|
|
219
234
|
return hidePlate && !item.blank && !isBlankCode(plate) ? [] : plateLines(plate);
|
|
@@ -222,9 +237,12 @@ function shownPlateLines(item: StickerItem, hidePlate: boolean): string[] {
|
|
|
222
237
|
/**
|
|
223
238
|
* The big line(s) on the sticker and the small serial under them. With the
|
|
224
239
|
* plate hidden, the serial (when it is on the sticker) moves up into the
|
|
225
|
-
* plate's place, so the sticker keeps its usual look with no hole in it.
|
|
240
|
+
* plate's place, so the sticker keeps its usual look with no hole in it. A
|
|
241
|
+
* blank sticker with its code hidden prints its number there whatever the
|
|
242
|
+
* serial choice - the number is how it is linked.
|
|
226
243
|
*/
|
|
227
244
|
function headLines(item: StickerItem, c: CardContext): { lines: string[]; serialText: string } {
|
|
245
|
+
if (blankCodeHidden(item, c)) return { lines: [stickerSerial(item)], serialText: "" };
|
|
228
246
|
const lines = shownPlateLines(item, c.hidePlate);
|
|
229
247
|
const serialText = c.serial ? stickerSerial(item) : "";
|
|
230
248
|
return lines.length || !serialText ? { lines, serialText } : { lines: [serialText], serialText: "" };
|
|
@@ -391,12 +409,24 @@ function plateSizeMm(plate: string, boxW: number, max = 4.6): number {
|
|
|
391
409
|
return Math.round(Math.min(max, (boxW / Math.max(plate.length, 1) - 0.3) / 0.74) * 100) / 100;
|
|
392
410
|
}
|
|
393
411
|
|
|
412
|
+
/**
|
|
413
|
+
* Plate size inside a shape's tag. With the serial printed under it (a blank
|
|
414
|
+
* sticker's two-line code + its number), the plate shrinks so both fit the tag:
|
|
415
|
+
* lines at 1.1 x size, the serial row 1.2 x 5.8 pt, 0.6 mm between.
|
|
416
|
+
*/
|
|
417
|
+
export function tagPlateSizeMm(longest: string, tag: { w: number; h: number }, lines: number, withSerial: boolean, k = 1): number {
|
|
418
|
+
const size = plateSizeMm(longest, tag.w, 4.6 * k);
|
|
419
|
+
if (!withSerial || !lines) return size;
|
|
420
|
+
const room = (tag.h - 1.2 * 5.8 * PT - 0.6) / (1.1 * lines);
|
|
421
|
+
return Math.round(Math.max(0.5, Math.min(size, room)) * 100) / 100;
|
|
422
|
+
}
|
|
423
|
+
|
|
394
424
|
/**
|
|
395
425
|
* One full HTML document: A4 sheets of stickers. `faceSvgs` is parallel to
|
|
396
426
|
* `items` (each sticker's frame + QR, already drawn for the chosen design).
|
|
397
427
|
* Every value is HTML-escaped - an owner or site name is typed by a person.
|
|
398
428
|
*/
|
|
399
|
-
type CardContext = { cardW: number; ink: string; label: string; layout: SheetLayout; k: number; shaped: boolean; bare: boolean; wordsTop: number; tag: { x: number; y: number; w: number; h: number } | null; serial: boolean; hidePlate: boolean };
|
|
429
|
+
type CardContext = { blankCode?: StickerDesign["blankCode"]; cardW: number; ink: string; label: string; layout: SheetLayout; k: number; shaped: boolean; bare: boolean; wordsTop: number; tag: { x: number; y: number; w: number; h: number } | null; serial: boolean; hidePlate: boolean };
|
|
400
430
|
|
|
401
431
|
function cardContext(design: StickerDesign, siteName: string | undefined, n: number): CardContext {
|
|
402
432
|
const g = stickerGeometry(design, n);
|
|
@@ -415,6 +445,7 @@ function cardContext(design: StickerDesign, siteName: string | undefined, n: num
|
|
|
415
445
|
tag: g.band ? { x: mm(g.band.x * k), y: mm(g.band.y * k), w: mm(g.band.w * k), h: mm(g.band.h * k) } : null,
|
|
416
446
|
serial: serialOnSticker(design),
|
|
417
447
|
hidePlate: design.plate === "hide",
|
|
448
|
+
blankCode: design.blankCode,
|
|
418
449
|
};
|
|
419
450
|
}
|
|
420
451
|
|
|
@@ -425,18 +456,18 @@ function cardHtml(item: StickerItem, face: string, c: CardContext): string {
|
|
|
425
456
|
const longest = lines.reduce((a, l) => (l.length > a.length ? l : a), "");
|
|
426
457
|
// a two-line code has no room for the words under it inside the tag
|
|
427
458
|
const label = c.label && !(c.tag && lines.length > 1) ? `<div class="hint">${escapeHtml(c.label)}</div>` : "";
|
|
428
|
-
// the serial takes the words' place inside a shape's tag
|
|
459
|
+
// the serial takes the words' place inside a shape's tag; a two-line blank code shrinks to make room for it
|
|
429
460
|
const serial = serialText ? `<div class="serial">${escapeHtml(serialText)}</div>` : "";
|
|
430
|
-
const tagWords = serial && c.tag ?
|
|
461
|
+
const tagWords = serial && c.tag ? serial : label;
|
|
431
462
|
const words = c.shaped && !c.tag
|
|
432
463
|
? ""
|
|
433
464
|
: c.tag
|
|
434
465
|
? `<div class="words band" style="left:${c.tag.x}mm;right:auto;top:${c.tag.y}mm;width:${c.tag.w}mm;height:${c.tag.h}mm">` +
|
|
435
|
-
(lines.length ? `<div class="plate" style="font-size:${
|
|
466
|
+
(lines.length ? `<div class="plate" style="font-size:${tagPlateSizeMm(longest, c.tag, lines.length, !!serial && lines.length > 1, c.k)}mm">${plate}</div>` : "") +
|
|
436
467
|
tagWords +
|
|
437
468
|
`</div>`
|
|
438
469
|
: `<div class="words" style="top:${c.wordsTop}mm${!lines.length && !label ? ";justify-content:center" : ""}">` +
|
|
439
|
-
(lines.length ? `<div class="plate"${lines.length > 1 ? ` style="font-size:${plateSizeMm(longest, c.cardW - 6, 4.6)}mm"` : ""}>${plate}</div>` : "") +
|
|
470
|
+
(lines.length ? `<div class="plate"${lines.length > 1 || blankCodeHidden(item, c) ? ` style="font-size:${plateSizeMm(longest, c.cardW - 6, 4.6)}mm"` : ""}>${plate}</div>` : "") +
|
|
440
471
|
serial +
|
|
441
472
|
label +
|
|
442
473
|
`<div class="brand"><span class="mark" style="background:${c.ink}">7</span>Powered by Seven365</div>` +
|
|
@@ -457,13 +488,12 @@ export function buildStickerDocument(
|
|
|
457
488
|
const design = opts.design ?? DEFAULT_STICKER_DESIGN;
|
|
458
489
|
const n = opts.modules ?? STICKER_QR_MODULES;
|
|
459
490
|
const c = cardContext(design, opts.siteName, n);
|
|
460
|
-
// the strip carries the number when chosen - and when the sticker has no
|
|
461
|
-
|
|
462
|
-
const noRoom = (item: StickerItem) => (c.shaped && !c.tag) || (!!c.tag && shownPlateLines(item, c.hidePlate).length > 1);
|
|
491
|
+
// the strip carries the number when chosen - and when the sticker has no words at all (a bare shape)
|
|
492
|
+
const noRoom = (_item: StickerItem) => c.shaped && !c.tag;
|
|
463
493
|
const stripSerial = (item: StickerItem) => design.serial === "strip" || design.serial === "both" || (c.serial && noRoom(item));
|
|
464
494
|
const cells = items.map((item, i) => {
|
|
465
495
|
const { place, owner } = installerLine(item);
|
|
466
|
-
const [noteHead, noteRest] =
|
|
496
|
+
const [noteHead, noteRest] = blankStripNote(item, design).split(" - ");
|
|
467
497
|
const sn = stripSerial(item) ? `<span class="sn">${escapeHtml(stickerSerial(item))}</span>` : "";
|
|
468
498
|
const strip = item.blank
|
|
469
499
|
? `<div class="cut${c.bare ? " free" : ""} blank"><div>${sn}<b>${escapeHtml(noteHead)}</b></div><div>${escapeHtml(noteRest)}</div></div>`
|
|
@@ -500,8 +530,8 @@ function cardWordsSvg(item: StickerItem, c: CardContext): string {
|
|
|
500
530
|
const longest = lines.reduce((a, l) => (l.length > a.length ? l : a), "");
|
|
501
531
|
const box = c.tag ?? { x: 3, y: c.wordsTop, w: c.cardW - 6, h: c.layout.cardH - 2 - c.wordsTop };
|
|
502
532
|
const plateSize = c.tag
|
|
503
|
-
?
|
|
504
|
-
: lines.length > 1 ? plateSizeMm(longest, c.cardW - 6, 4.6) : 13 * PT;
|
|
533
|
+
? tagPlateSizeMm(longest, c.tag, lines.length, !!serialText && lines.length > 1, c.k)
|
|
534
|
+
: lines.length > 1 || blankCodeHidden(item, c) ? plateSizeMm(longest, c.cardW - 6, 4.6) : 13 * PT;
|
|
505
535
|
const small = 5.8 * PT;
|
|
506
536
|
type Row = { h: number; draw: (top: number) => string };
|
|
507
537
|
const rows: Row[] = [];
|
|
@@ -519,7 +549,7 @@ function cardWordsSvg(item: StickerItem, c: CardContext): string {
|
|
|
519
549
|
});
|
|
520
550
|
const label = c.label && !(c.tag && lines.length > 1) ? c.label : "";
|
|
521
551
|
if (c.tag) {
|
|
522
|
-
if (serialText
|
|
552
|
+
if (serialText) rows.push(word(serialText, true));
|
|
523
553
|
else if (!serialText && label) rows.push(word(label, false));
|
|
524
554
|
} else {
|
|
525
555
|
if (serialText) rows.push(word(serialText, true));
|