@7365admin1/layer-common 4.155.1 → 4.157.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 +16 -4
- package/components/Robot/Detail.vue +9 -1
- package/components/Robot/LiveView.vue +25 -2
- package/components/Robot/SetupPanel.vue +10 -9
- package/components/VehicleQrStickerDialog.vue +13 -5
- package/composables/useRobots.ts +1 -0
- package/package.json +1 -1
- package/utils/robot-config.ts +2 -0
- package/utils/robot-display.ts +4 -1
- package/utils/vehicle-qr-design.ts +22 -0
- package/utils/vehicle-qr-sticker.ts +37 -15
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @iservice365/layer-common
|
|
2
2
|
|
|
3
|
+
## 4.157.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- fb36f4d: Robots: OneWay V1.4 - Pause / Resume show for a brand with its own pause (no second "Resume patrol" while paused); live view gets Centre camera / Zoom + / Zoom − for brands with `cameraControl` (people who may command the robot); Super Admin setup shows only the forms the brand's setup returns, with the brand's own note (OneWay go-to-charge level); an empty setting box is no change.
|
|
8
|
+
|
|
9
|
+
## 4.156.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- fe3bb03: Vehicle QR stickers: new "Vehicle number on print-out" choice (Show / Hide). Hide leaves the plate number off the preview, print, saved sheet and PNG/JPEG pictures (file names use the sticker number); the serial number moves into the plate's place when it is on the sticker. Blank sticker codes are always printed.
|
|
14
|
+
|
|
3
15
|
## 4.155.1
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -3620,11 +3632,11 @@ Monthly report: a month that had patrols opens the list of that month's patrol r
|
|
|
3620
3632
|
`utils/console-tier.ts` + `composables/useConsoleTier.ts` mirror the server's
|
|
3621
3633
|
own rule from two endpoints the console already calls, unprojected:
|
|
3622
3634
|
|
|
3623
|
-
|
|
3624
|
-
|
|
3635
|
+
GET /api/members/user/:user/app/admin the Seven365 staff membership
|
|
3636
|
+
GET /api/roles/id/:role that membership's role document
|
|
3625
3637
|
|
|
3626
|
-
|
|
3627
|
-
|
|
3638
|
+
owner = member.type === "admin" && role.type === "admin" && role.default === true
|
|
3639
|
+
staff = member.type === "admin" && role.type === "admin"
|
|
3628
3640
|
|
|
3629
3641
|
`role.default` is the marker because it is the only property of a platform
|
|
3630
3642
|
staff role no API caller can set - `role.controller.ts` validates create and
|
|
@@ -80,7 +80,15 @@
|
|
|
80
80
|
<!-- Above the fold: camera | map, with the commands under the map they act on. -->
|
|
81
81
|
<div v-if="!noInterface" class="hero-detail__main" :class="{ 'hero-detail__main--single': !hasCamera }">
|
|
82
82
|
<section v-if="hasCamera" class="hero-detail__cam" aria-label="Camera">
|
|
83
|
-
<RobotLiveView
|
|
83
|
+
<RobotLiveView
|
|
84
|
+
v-if="caps?.liveVideo === true"
|
|
85
|
+
ref="livePanel"
|
|
86
|
+
panel
|
|
87
|
+
:robot-id="robotId"
|
|
88
|
+
:name="record?.name"
|
|
89
|
+
:offline="!online"
|
|
90
|
+
:camera-control="cmdOk === true && caps?.cameraControl === true && online"
|
|
91
|
+
/>
|
|
84
92
|
<p v-if="caps?.liveVideo === true && reportsPosition" class="hero-muted hero-detail__lag">{{ VIDEO_LAG_NOTE }}</p>
|
|
85
93
|
<div v-if="canDrive" class="hero-detail__video">
|
|
86
94
|
<v-btn variant="outlined" @click="driveOpen = true">Manual control</v-btn>
|
|
@@ -53,9 +53,15 @@
|
|
|
53
53
|
</template>
|
|
54
54
|
</div>
|
|
55
55
|
|
|
56
|
+
<div v-if="camError" class="hero-notice" role="alert">{{ camError }}</div>
|
|
56
57
|
<div v-if="on || !panel" class="hero-dialog__actions">
|
|
57
58
|
<v-btn v-if="error && !offline" variant="outlined" size="small" @click="restart">Retry</v-btn>
|
|
58
59
|
<v-btn v-if="url && plays && !error" variant="outlined" size="small" @click="fullScreen">Full screen</v-btn>
|
|
60
|
+
<span v-if="cameraControl && !offline" class="hero-live__cam" role="group" aria-label="Camera">
|
|
61
|
+
<v-btn variant="outlined" size="small" :disabled="camBusy" @click="camera('center')">Centre camera</v-btn>
|
|
62
|
+
<v-btn variant="outlined" size="small" :disabled="camBusy" aria-label="Zoom in" @click="camera('zoom-in')">Zoom +</v-btn>
|
|
63
|
+
<v-btn variant="outlined" size="small" :disabled="camBusy" aria-label="Zoom out" @click="camera('zoom-out')">Zoom −</v-btn>
|
|
64
|
+
</span>
|
|
59
65
|
<a v-if="url && !plays && kind !== 'rtmp'" class="hero-live__open" :href="url" target="_blank" rel="noopener noreferrer">Open in new tab</a>
|
|
60
66
|
<span class="hero-head__spacer" />
|
|
61
67
|
<v-btn v-if="!panel" variant="outlined" @click="emit('close')">Close</v-btn>
|
|
@@ -79,9 +85,26 @@ import {
|
|
|
79
85
|
writeLivePref,
|
|
80
86
|
} from "../../utils/robot-control";
|
|
81
87
|
|
|
82
|
-
|
|
88
|
+
// `cameraControl`: the brand turns / zooms its camera (OneWay) AND this person may command the robot.
|
|
89
|
+
const props = defineProps<{ robotId: string; name?: string; panel?: boolean; offline?: boolean; cameraControl?: boolean }>();
|
|
83
90
|
const emit = defineEmits<{ close: [] }>();
|
|
84
|
-
const { getLiveVideo } = useRobots();
|
|
91
|
+
const { getLiveVideo, sendRobotCommand } = useRobots();
|
|
92
|
+
|
|
93
|
+
/** One camera step (centre / zoom), sent once per press; the robot cloud's refusal is shown as it said it. */
|
|
94
|
+
const camBusy = ref(false);
|
|
95
|
+
const camError = ref("");
|
|
96
|
+
async function camera(action: "center" | "zoom-in" | "zoom-out") {
|
|
97
|
+
if (camBusy.value) return;
|
|
98
|
+
camBusy.value = true;
|
|
99
|
+
camError.value = "";
|
|
100
|
+
try {
|
|
101
|
+
await sendRobotCommand(props.robotId, { kind: "camera", action });
|
|
102
|
+
} catch (e: any) {
|
|
103
|
+
camError.value = e?.data?.message || e?.message || "The camera did not move.";
|
|
104
|
+
} finally {
|
|
105
|
+
camBusy.value = false;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
85
108
|
|
|
86
109
|
const titleId = `hero-live-title-${Math.random().toString(36).slice(2, 8)}`;
|
|
87
110
|
// "Always show live view": one choice per browser, like a dashboard layout. ponytail: localStorage, no table.
|
|
@@ -97,20 +97,20 @@
|
|
|
97
97
|
|
|
98
98
|
<!-- Names, dock, floor, settings (Ounitech) -->
|
|
99
99
|
<section v-if="caps.setupSettings === true" class="hero-setup__section" aria-label="Robot settings">
|
|
100
|
-
<div class="hero-section__title">Names, dock and floor</div>
|
|
101
|
-
<div class="hero-setup__form">
|
|
100
|
+
<div v-if="setup.robotName !== undefined || setup.sceneName !== undefined || setup.docked !== undefined" class="hero-section__title">Names, dock and floor</div>
|
|
101
|
+
<div v-if="setup.robotName !== undefined" class="hero-setup__form">
|
|
102
102
|
<label>Name in the Ounitech app <input v-model="names.robot" class="hero-input" maxlength="40" /></label>
|
|
103
103
|
<v-btn size="small" variant="outlined" :disabled="busy || !names.robot.trim() || names.robot.trim() === setup.robotName" @click="ask({ action: 'robot-name', name: names.robot.trim() })">Rename robot</v-btn>
|
|
104
104
|
</div>
|
|
105
|
-
<div class="hero-setup__form">
|
|
105
|
+
<div v-if="setup.sceneName !== undefined" class="hero-setup__form">
|
|
106
106
|
<label>Ounitech site name <input v-model="names.scene" class="hero-input" maxlength="40" /></label>
|
|
107
107
|
<v-btn size="small" variant="outlined" :disabled="busy || !names.scene.trim() || names.scene.trim() === setup.sceneName" @click="ask({ action: 'scene-name', name: names.scene.trim() })">Rename site</v-btn>
|
|
108
108
|
</div>
|
|
109
|
-
<div v-if="currentMap" class="hero-setup__form">
|
|
109
|
+
<div v-if="currentMap && setup.robotName !== undefined" class="hero-setup__form">
|
|
110
110
|
<label>Name of map shown ({{ currentMap.name }}) <input v-model="names.map" class="hero-input" maxlength="40" /></label>
|
|
111
111
|
<v-btn size="small" variant="outlined" :disabled="busy || !names.map.trim() || names.map.trim() === currentMap.name" @click="ask({ action: 'map-name', mapId: currentMap.mapId, name: names.map.trim() }, { map: currentMap.name })">Rename map</v-btn>
|
|
112
112
|
</div>
|
|
113
|
-
<div class="hero-setup__form">
|
|
113
|
+
<div v-if="setup.docked !== undefined" class="hero-setup__form">
|
|
114
114
|
<span>Dock: {{ setup.docked ? "the robot is on its dock and charging now." : "push the robot onto its dock (it must show Charging) to save the dock from here." }}</span>
|
|
115
115
|
<v-btn size="small" variant="outlined" :disabled="busy || !setup.docked" @click="ask({ action: 'dock-here' })">Save dock where the robot is</v-btn>
|
|
116
116
|
</div>
|
|
@@ -123,7 +123,8 @@
|
|
|
123
123
|
</div>
|
|
124
124
|
|
|
125
125
|
<div class="hero-section__title">Settings</div>
|
|
126
|
-
<p class="hero-muted">
|
|
126
|
+
<p v-if="setup.settingsNote" class="hero-muted">{{ setup.settingsNote }}</p>
|
|
127
|
+
<p v-else class="hero-muted">Only settings we can name are listed. Safety sensors, the time zone and Wi-Fi stay in the Ounitech app. Speeds can only be lowered here.</p>
|
|
127
128
|
<div v-if="setup.settings?.error" class="hero-notice hero-notice--error">{{ setup.settings.error }}</div>
|
|
128
129
|
<div v-for="s in settings" :key="s.key" class="hero-sched__row hero-setup__row">
|
|
129
130
|
<b>{{ s.label }}</b>
|
|
@@ -135,10 +136,10 @@
|
|
|
135
136
|
</div>
|
|
136
137
|
<v-btn v-if="settings.length" size="small" color="primary" variant="flat" :disabled="busy || !Object.keys(changedSettings).length" @click="ask({ action: 'settings', values: changedSettings })">Save settings</v-btn>
|
|
137
138
|
|
|
138
|
-
<div class="hero-section__title">Parts replaced</div>
|
|
139
|
-
<p class="hero-muted">After a brush, mop, filter or bag is replaced, reset its hours so the wear count starts again.</p>
|
|
139
|
+
<div v-if="setup.parts !== undefined" class="hero-section__title">Parts replaced</div>
|
|
140
|
+
<p v-if="setup.parts !== undefined" class="hero-muted">After a brush, mop, filter or bag is replaced, reset its hours so the wear count starts again.</p>
|
|
140
141
|
<div v-if="setup.parts?.error" class="hero-notice hero-notice--error">{{ setup.parts.error }}</div>
|
|
141
|
-
<div v-else-if="!parts.length" class="hero-sched__empty">The robot reports no parts.</div>
|
|
142
|
+
<div v-else-if="setup.parts !== undefined && !parts.length" class="hero-sched__empty">The robot reports no parts.</div>
|
|
142
143
|
<div v-for="p in parts" :key="p.code" class="hero-sched__row hero-setup__row">
|
|
143
144
|
<b>{{ p.part }}</b>
|
|
144
145
|
<span>{{ p.hours != null ? `${p.hours} h` : "hours not reported" }}{{ p.days != null ? ` · ${p.days} days` : "" }}</span>
|
|
@@ -157,13 +157,18 @@
|
|
|
157
157
|
data-test="vehicle-qr-text" />
|
|
158
158
|
</v-col>
|
|
159
159
|
<v-col v-if="design.shape === 'square' || design.text !== 'none'" cols="12" sm="6" md="4">
|
|
160
|
-
<v-select v-model="design.label" :items="LABEL_OPTIONS"
|
|
160
|
+
<v-select v-model="design.label" :items="LABEL_OPTIONS"
|
|
161
|
+
:label="design.plate === 'hide' ? 'Words on the sticker' : 'Words under the plate'" density="compact"
|
|
161
162
|
hide-details />
|
|
162
163
|
</v-col>
|
|
163
164
|
<v-col cols="12" sm="6" md="4">
|
|
164
165
|
<v-select v-model="design.serial" :items="SERIAL_OPTIONS" label="Serial number (No. 1, 2, 3 ...)" density="compact"
|
|
165
166
|
hide-details data-test="vehicle-qr-serial" />
|
|
166
167
|
</v-col>
|
|
168
|
+
<v-col v-if="!isBlank" cols="12" sm="6" md="4">
|
|
169
|
+
<v-select v-model="design.plate" :items="PLATE_OPTIONS" label="Vehicle number on print-out" density="compact"
|
|
170
|
+
hide-details data-test="vehicle-qr-plate" />
|
|
171
|
+
</v-col>
|
|
167
172
|
</v-row>
|
|
168
173
|
<div class="d-flex align-center flex-wrap">
|
|
169
174
|
<v-switch v-model="design.cutLines" label="Show cut lines" color="primary" density="compact" hide-details
|
|
@@ -252,6 +257,7 @@ import {
|
|
|
252
257
|
stickerSizeInfo,
|
|
253
258
|
stickerSizeLines,
|
|
254
259
|
stickerCardSvgs,
|
|
260
|
+
stickerFileLabel,
|
|
255
261
|
stickerWarning,
|
|
256
262
|
type StickerItem,
|
|
257
263
|
type StickerPlateRow,
|
|
@@ -262,12 +268,14 @@ import {
|
|
|
262
268
|
EYE_OPTIONS,
|
|
263
269
|
LABEL_OPTIONS,
|
|
264
270
|
SERIAL_OPTIONS,
|
|
271
|
+
PLATE_OPTIONS,
|
|
265
272
|
QR_SHAPE_OPTIONS,
|
|
266
273
|
QR_ECC,
|
|
267
274
|
STICKER_THEMES,
|
|
268
275
|
TEXT_OPTIONS,
|
|
269
276
|
frameOptionsFor,
|
|
270
277
|
normalizeDesign,
|
|
278
|
+
printedDesign,
|
|
271
279
|
rememberedDesign,
|
|
272
280
|
sizeOptionsFor,
|
|
273
281
|
stickerFaceSvg,
|
|
@@ -385,13 +393,13 @@ watch(
|
|
|
385
393
|
);
|
|
386
394
|
const frameItems = computed(() => frameOptionsFor(design.shape));
|
|
387
395
|
const sizeItems = computed(() => {
|
|
388
|
-
const look =
|
|
396
|
+
const look = printedDesign(design, isBlank.value, siteName.value);
|
|
389
397
|
return sizeOptionsFor(look, STICKER_QR_MODULES).map((o) => {
|
|
390
398
|
const info = stickerSizeInfo({ ...look, size: o.value });
|
|
391
399
|
return { value: o.value, title: `${o.title} - ${Math.round(info.shapeW)} mm wide, QR ${Math.round(info.qrMm)} mm` };
|
|
392
400
|
});
|
|
393
401
|
});
|
|
394
|
-
const sizeLines = computed(() => stickerSizeLines(
|
|
402
|
+
const sizeLines = computed(() => stickerSizeLines(printedDesign(design, isBlank.value, siteName.value)));
|
|
395
403
|
|
|
396
404
|
const onlyWithSticker = ref(false);
|
|
397
405
|
const shownPlates = computed(() => (onlyWithSticker.value ? plates.value.filter((p) => p.hasSticker) : plates.value));
|
|
@@ -504,7 +512,7 @@ function chosenItems() {
|
|
|
504
512
|
|
|
505
513
|
// The QR content and error correction (Q) are the same on every design.
|
|
506
514
|
function faceArgs(chosen: StickerItem[]) {
|
|
507
|
-
const look =
|
|
515
|
+
const look = printedDesign(design, isBlank.value, siteName.value);
|
|
508
516
|
const codes = chosen.map((i) => QRCode.create(i.qr, { errorCorrectionLevel: QR_ECC as QRCode.QRCodeErrorCorrectionLevel }).modules);
|
|
509
517
|
const faces = chosen.map((i, k) => stickerFaceSvg(codes[k], look, i.qr));
|
|
510
518
|
return [faces, { design: look, siteName: siteName.value, modules: codes[0].size }] as const;
|
|
@@ -533,7 +541,7 @@ async function saveImages(format: ImageFormat, dpi: number) {
|
|
|
533
541
|
const [faces, opts] = faceArgs(chosen);
|
|
534
542
|
const cards = stickerCardSvgs(chosen, faces, { ...opts, dpi });
|
|
535
543
|
const ext = format === "jpeg" ? "jpg" : "png";
|
|
536
|
-
const names = stickerFileNames(chosen.map((i) => i.
|
|
544
|
+
const names = stickerFileNames(chosen.map((i) => stickerFileLabel(i, opts.design)), ext);
|
|
537
545
|
const files = [];
|
|
538
546
|
for (const [k, c] of cards.entries()) files.push({ name: names[k], data: await svgToImage(c.svg, c.width, c.height, format, dpi) });
|
|
539
547
|
if (files.length === 1) saveFile(files[0].name, files[0].data, `image/${format}`);
|
package/composables/useRobots.ts
CHANGED
|
@@ -284,6 +284,7 @@ export default function useRobots() {
|
|
|
284
284
|
| { kind: "area"; areas: string[]; cleanTimes?: number; modeFlag?: number; subModeFlag?: number; levelFlag?: number }
|
|
285
285
|
| { kind: "spot"; points: Array<{ x: number; y: number }>; cleanTimes?: number; modeFlag?: number; subModeFlag?: number; levelFlag?: number }
|
|
286
286
|
| { kind: "pause" | "resume" | "cancel" | "patrol-resume" }
|
|
287
|
+
| { kind: "camera"; action: "center" | "zoom-in" | "zoom-out" }
|
|
287
288
|
| { kind: "navigate"; x: number; y: number; theta?: number }
|
|
288
289
|
| { kind: "relocalize"; floorNo: number; x: number; y: number; theta: number },
|
|
289
290
|
) {
|
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.157.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/robot-config.ts
CHANGED
|
@@ -66,6 +66,8 @@ export function settingsDiff(loaded: Array<{ key: string; value: unknown }> | nu
|
|
|
66
66
|
for (const s of loaded ?? []) {
|
|
67
67
|
if (!(s.key in edited)) continue;
|
|
68
68
|
const v = edited[s.key];
|
|
69
|
+
// An empty box is no change (a setting the robot does not report back starts empty).
|
|
70
|
+
if (v === null || v === undefined || v === "") continue;
|
|
69
71
|
const want = typeof s.value === "boolean" ? v === true : Number(v);
|
|
70
72
|
if (typeof want === "number" && !Number.isFinite(want)) continue;
|
|
71
73
|
if (want !== s.value) out[s.key] = want;
|
package/utils/robot-display.ts
CHANGED
|
@@ -317,6 +317,7 @@ const COMMAND_NEEDS: Readonly<Record<string, string>> = {
|
|
|
317
317
|
cancel: "pauseProcess",
|
|
318
318
|
navigate: "navigateToPoint",
|
|
319
319
|
relocalize: "relocalize",
|
|
320
|
+
// Not `camera` (cameraControl): a live-view step, not a job - it does not move the badge.
|
|
320
321
|
};
|
|
321
322
|
|
|
322
323
|
/** Telemetry a brand may declare - reporting only, never a command. */
|
|
@@ -461,7 +462,8 @@ export function visibleCommands(input: {
|
|
|
461
462
|
const caps = input.capabilities ?? {};
|
|
462
463
|
const patrol = input.type === "security" && caps.patrolControl === true;
|
|
463
464
|
return COMMANDS.filter((c) => {
|
|
464
|
-
|
|
465
|
+
// A brand with its own Resume (OneWay §4.14) carries on from where it paused: no second "Resume patrol" then.
|
|
466
|
+
if (c.kind === "patrol-resume") return patrol && ((input.mode === "PAUSED" && caps.pauseResume !== true) || (input.resumable === true && input.mode !== "WORKING" && input.mode !== "IN_TRANSIT" && input.mode !== "PAUSED"));
|
|
465
467
|
if (caps[COMMAND_NEEDS[c.kind]!] !== true) return false;
|
|
466
468
|
if (c.kind === "pause" && input.mode !== "WORKING") return false;
|
|
467
469
|
if (c.kind === "resume" && input.mode !== "PAUSED") return false;
|
|
@@ -1721,6 +1723,7 @@ export function robotAbilities(input: {
|
|
|
1721
1723
|
on("relocalize") && "can be told where it is",
|
|
1722
1724
|
on("sendToDock") && "returns to its charger",
|
|
1723
1725
|
on("liveVideo") && "streams live video",
|
|
1726
|
+
on("cameraControl") && "centres and zooms its camera",
|
|
1724
1727
|
on("manualDrive") && "can be driven by hand",
|
|
1725
1728
|
on("emergencyStop") && "stops at once with Emergency stop",
|
|
1726
1729
|
].filter(Boolean) as string[];
|
|
@@ -48,6 +48,8 @@ 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 always printed). */
|
|
52
|
+
export type PlateChoice = "show" | "hide";
|
|
51
53
|
|
|
52
54
|
export type StickerTheme = { id: string; title: string; ink: string; eye: string; paper: string };
|
|
53
55
|
|
|
@@ -65,6 +67,7 @@ export type StickerDesign = {
|
|
|
65
67
|
/** A thin grey line around each sticker to cut along. */
|
|
66
68
|
cutLines?: boolean;
|
|
67
69
|
serial?: SerialChoice;
|
|
70
|
+
plate?: PlateChoice;
|
|
68
71
|
};
|
|
69
72
|
|
|
70
73
|
export const DOT_OPTIONS: { value: DotShape; title: string }[] = [
|
|
@@ -146,6 +149,11 @@ export const SERIAL_OPTIONS: { value: SerialChoice; title: string }[] = [
|
|
|
146
149
|
{ value: "both", title: "On the sticker and the strip" },
|
|
147
150
|
];
|
|
148
151
|
|
|
152
|
+
export const PLATE_OPTIONS: { value: PlateChoice; title: string }[] = [
|
|
153
|
+
{ value: "show", title: "Show" },
|
|
154
|
+
{ value: "hide", title: "Hide (not printed)" },
|
|
155
|
+
];
|
|
156
|
+
|
|
149
157
|
export const LABEL_OPTIONS: { value: LabelChoice; title: string }[] = [
|
|
150
158
|
{ value: "app", title: "Scan with iSecure365 / iMA365" },
|
|
151
159
|
{ value: "verify", title: "Scan to verify vehicle" },
|
|
@@ -176,6 +184,7 @@ export const DEFAULT_STICKER_DESIGN: StickerDesign = {
|
|
|
176
184
|
text: "below",
|
|
177
185
|
cutLines: true,
|
|
178
186
|
serial: "sticker",
|
|
187
|
+
plate: "show",
|
|
179
188
|
};
|
|
180
189
|
|
|
181
190
|
/** A saved or typed-in design with anything unknown replaced by the default. */
|
|
@@ -199,6 +208,7 @@ export function normalizeDesign(raw: unknown): StickerDesign {
|
|
|
199
208
|
text: pick(r.text, TEXT_OPTIONS, d.text),
|
|
200
209
|
cutLines: typeof r.cutLines === "boolean" ? r.cutLines : true,
|
|
201
210
|
serial: pick(r.serial, SERIAL_OPTIONS, d.serial),
|
|
211
|
+
plate: pick(r.plate, PLATE_OPTIONS, d.plate!),
|
|
202
212
|
};
|
|
203
213
|
}
|
|
204
214
|
|
|
@@ -212,6 +222,18 @@ export function rememberedDesign(saved: unknown, savedSerial: unknown): StickerD
|
|
|
212
222
|
return normalizeDesign({ ...r, serial: savedSerial });
|
|
213
223
|
}
|
|
214
224
|
|
|
225
|
+
/**
|
|
226
|
+
* The design as printed. With the plate hidden on vehicle stickers, a shaped
|
|
227
|
+
* code whose tab under the shape would be left empty (no serial or words on
|
|
228
|
+
* 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.
|
|
230
|
+
*/
|
|
231
|
+
export function printedDesign(design: unknown, blank = false, siteName = ""): StickerDesign {
|
|
232
|
+
const d = normalizeDesign(design);
|
|
233
|
+
const tabEmpty = d.serial !== "sticker" && d.serial !== "both" && !stickerLabel(d, siteName);
|
|
234
|
+
return !blank && d.plate === "hide" && isSilhouette(d.shape) && d.text === "below" && tabEmpty ? { ...d, text: "none" } : d;
|
|
235
|
+
}
|
|
236
|
+
|
|
215
237
|
export function stickerTheme(id: string): StickerTheme {
|
|
216
238
|
return STICKER_THEMES.find((t) => t.id === id) ?? STICKER_THEMES[0];
|
|
217
239
|
}
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
stickerTheme,
|
|
19
19
|
type StickerDesign,
|
|
20
20
|
} from "./vehicle-qr-design.ts";
|
|
21
|
-
import { BLANK_STRIP_NOTE, plateLines } from "./vehicle-qr-blank.ts";
|
|
21
|
+
import { BLANK_STRIP_NOTE, 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;
|
|
@@ -203,6 +203,28 @@ export function stickerSerial(item: Pick<StickerItem, "serialNo">): string {
|
|
|
203
203
|
return Number.isInteger(n) && n > 0 ? `No. ${n}` : "";
|
|
204
204
|
}
|
|
205
205
|
|
|
206
|
+
/** 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). */
|
|
207
|
+
export function stickerFileLabel(item: StickerItem, design: Pick<StickerDesign, "plate">): string {
|
|
208
|
+
return shownPlateLines(item, design.plate === "hide").length ? text(item.plateNumber) : stickerSerial(item) || "sticker";
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/** The plate lines printed on a sticker: none when the plate is hidden - but a blank sticker's code is always printed (it is typed to link it). */
|
|
212
|
+
function shownPlateLines(item: StickerItem, hidePlate: boolean): string[] {
|
|
213
|
+
const plate = text(item.plateNumber);
|
|
214
|
+
return hidePlate && !item.blank && !isBlankCode(plate) ? [] : plateLines(plate);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* The big line(s) on the sticker and the small serial under them. With the
|
|
219
|
+
* plate hidden, the serial (when it is on the sticker) moves up into the
|
|
220
|
+
* plate's place, so the sticker keeps its usual look with no hole in it.
|
|
221
|
+
*/
|
|
222
|
+
function headLines(item: StickerItem, c: CardContext): { lines: string[]; serialText: string } {
|
|
223
|
+
const lines = shownPlateLines(item, c.hidePlate);
|
|
224
|
+
const serialText = c.serial ? stickerSerial(item) : "";
|
|
225
|
+
return lines.length || !serialText ? { lines, serialText } : { lines: [serialText], serialText: "" };
|
|
226
|
+
}
|
|
227
|
+
|
|
206
228
|
const serialOnSticker = (d: StickerDesign) => d.serial === "sticker" || d.serial === "both";
|
|
207
229
|
|
|
208
230
|
/** "Blk 4 #02-01". Tolerates a unit that already carries its level ("02-01"). */
|
|
@@ -369,7 +391,7 @@ function plateSizeMm(plate: string, boxW: number, max = 4.6): number {
|
|
|
369
391
|
* `items` (each sticker's frame + QR, already drawn for the chosen design).
|
|
370
392
|
* Every value is HTML-escaped - an owner or site name is typed by a person.
|
|
371
393
|
*/
|
|
372
|
-
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 };
|
|
394
|
+
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 };
|
|
373
395
|
|
|
374
396
|
function cardContext(design: StickerDesign, siteName: string | undefined, n: number): CardContext {
|
|
375
397
|
const g = stickerGeometry(design, n);
|
|
@@ -387,29 +409,29 @@ function cardContext(design: StickerDesign, siteName: string | undefined, n: num
|
|
|
387
409
|
wordsTop: mm(((g.qrTop ?? 0) + QR_MM + 0.8) * k),
|
|
388
410
|
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,
|
|
389
411
|
serial: serialOnSticker(design),
|
|
412
|
+
hidePlate: design.plate === "hide",
|
|
390
413
|
};
|
|
391
414
|
}
|
|
392
415
|
|
|
393
416
|
/** The sticker itself (frame + QR + plate words) - what goes on the car. */
|
|
394
417
|
function cardHtml(item: StickerItem, face: string, c: CardContext): string {
|
|
395
|
-
const lines =
|
|
418
|
+
const { lines, serialText } = headLines(item, c);
|
|
396
419
|
const plate = lines.map(escapeHtml).join("<br>");
|
|
397
420
|
const longest = lines.reduce((a, l) => (l.length > a.length ? l : a), "");
|
|
398
421
|
// a two-line code has no room for the words under it inside the tag
|
|
399
422
|
const label = c.label && !(c.tag && lines.length > 1) ? `<div class="hint">${escapeHtml(c.label)}</div>` : "";
|
|
400
423
|
// the serial takes the words' place inside a shape's tag (no room for both)
|
|
401
|
-
const serialText = c.serial ? stickerSerial(item) : "";
|
|
402
424
|
const serial = serialText ? `<div class="serial">${escapeHtml(serialText)}</div>` : "";
|
|
403
425
|
const tagWords = serial && c.tag ? (lines.length > 1 ? "" : serial) : label;
|
|
404
426
|
const words = c.shaped && !c.tag
|
|
405
427
|
? ""
|
|
406
428
|
: c.tag
|
|
407
429
|
? `<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">` +
|
|
408
|
-
`<div class="plate" style="font-size:${plateSizeMm(longest, c.tag.w, 4.6 * c.k)}mm">${plate}</div>` +
|
|
430
|
+
(lines.length ? `<div class="plate" style="font-size:${plateSizeMm(longest, c.tag.w, 4.6 * c.k)}mm">${plate}</div>` : "") +
|
|
409
431
|
tagWords +
|
|
410
432
|
`</div>`
|
|
411
|
-
: `<div class="words" style="top:${c.wordsTop}mm">` +
|
|
412
|
-
`<div class="plate"${lines.length > 1 ? ` style="font-size:${plateSizeMm(longest, c.cardW - 6, 4.6)}mm"` : ""}>${plate}</div>` +
|
|
433
|
+
: `<div class="words" style="top:${c.wordsTop}mm${!lines.length && !label ? ";justify-content:center" : ""}">` +
|
|
434
|
+
(lines.length ? `<div class="plate"${lines.length > 1 ? ` style="font-size:${plateSizeMm(longest, c.cardW - 6, 4.6)}mm"` : ""}>${plate}</div>` : "") +
|
|
413
435
|
serial +
|
|
414
436
|
label +
|
|
415
437
|
`<div class="brand"><span class="mark" style="background:${c.ink}">7</span>Powered by Seven365</div>` +
|
|
@@ -432,7 +454,7 @@ export function buildStickerDocument(
|
|
|
432
454
|
const c = cardContext(design, opts.siteName, n);
|
|
433
455
|
// the strip carries the number when chosen - and when the sticker has no room for it
|
|
434
456
|
// (a bare shape, or a two-line blank code filling a shape's tag)
|
|
435
|
-
const noRoom = (item: StickerItem) => (c.shaped && !c.tag) || (!!c.tag &&
|
|
457
|
+
const noRoom = (item: StickerItem) => (c.shaped && !c.tag) || (!!c.tag && shownPlateLines(item, c.hidePlate).length > 1);
|
|
436
458
|
const stripSerial = (item: StickerItem) => design.serial === "strip" || design.serial === "both" || (c.serial && noRoom(item));
|
|
437
459
|
const cells = items.map((item, i) => {
|
|
438
460
|
const { place, owner } = installerLine(item);
|
|
@@ -469,24 +491,23 @@ function svgLine(t: string, x: number, baseline: number, size: number, maxW: num
|
|
|
469
491
|
*/
|
|
470
492
|
function cardWordsSvg(item: StickerItem, c: CardContext): string {
|
|
471
493
|
if (c.shaped && !c.tag) return "";
|
|
472
|
-
const lines =
|
|
494
|
+
const { lines, serialText } = headLines(item, c);
|
|
473
495
|
const longest = lines.reduce((a, l) => (l.length > a.length ? l : a), "");
|
|
474
|
-
const serialText = c.serial ? stickerSerial(item) : "";
|
|
475
496
|
const box = c.tag ?? { x: 3, y: c.wordsTop, w: c.cardW - 6, h: c.layout.cardH - 2 - c.wordsTop };
|
|
476
497
|
const plateSize = c.tag
|
|
477
498
|
? plateSizeMm(longest, c.tag.w, 4.6 * c.k)
|
|
478
499
|
: lines.length > 1 ? plateSizeMm(longest, c.cardW - 6, 4.6) : 13 * PT;
|
|
479
500
|
const small = 5.8 * PT;
|
|
480
501
|
type Row = { h: number; draw: (top: number) => string };
|
|
481
|
-
const rows: Row[] = [
|
|
482
|
-
|
|
502
|
+
const rows: Row[] = [];
|
|
503
|
+
if (lines.length)
|
|
504
|
+
rows.push({
|
|
483
505
|
h: 1.1 * plateSize * lines.length,
|
|
484
506
|
draw: (top) =>
|
|
485
507
|
lines
|
|
486
508
|
.map((l, n) => svgLine(l, box.x + box.w / 2, top + (0.955 + 1.1 * n) * plateSize, plateSize, box.w, `font-weight="800" letter-spacing="0.3"`, 0.7))
|
|
487
509
|
.join(""),
|
|
488
|
-
}
|
|
489
|
-
];
|
|
510
|
+
});
|
|
490
511
|
const word = (t: string, bold: boolean): Row => ({
|
|
491
512
|
h: 1.2 * small,
|
|
492
513
|
draw: (top) => svgLine(t, box.x + box.w / 2, top + small, small, box.w, bold ? `font-weight="700" letter-spacing="0.15"` : `opacity="0.85"`),
|
|
@@ -517,7 +538,8 @@ function cardWordsSvg(item: StickerItem, c: CardContext): string {
|
|
|
517
538
|
const used = rows.reduce((n, r) => n + r.h, 0);
|
|
518
539
|
// the card spreads its rows top to bottom; a tag centres them with 0.6 mm between
|
|
519
540
|
const gap = c.tag ? 0.6 : rows.length > 1 ? Math.max(0, (box.h - used) / (rows.length - 1)) : 0;
|
|
520
|
-
|
|
541
|
+
// (a lone Seven365 line - plate hidden, nothing else - sits in the middle of the card)
|
|
542
|
+
let top = c.tag || rows.length === 1 ? box.y + (box.h - used - gap * (rows.length - 1)) / 2 : box.y;
|
|
521
543
|
const out = rows.map((r) => {
|
|
522
544
|
const svg = r.draw(top);
|
|
523
545
|
top += r.h + gap;
|