@7365admin1/layer-common 4.97.1-staging.693 → 4.97.1-staging.694

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.
@@ -27,9 +27,21 @@
27
27
  <p v-if="blankSummary" class="text-body-2 font-weight-medium mb-3" data-test="vehicle-qr-blank-summary">
28
28
  {{ blankSummaryText(blankSummary) }}
29
29
  </p>
30
- <v-text-field v-model.number="blankQty" type="number" :min="1" :max="BLANK_MAX_COUNT" label="How many stickers?"
31
- density="compact" variant="outlined" style="max-width: 240px" :hint="`1 to ${BLANK_MAX_COUNT} at a time`"
32
- persistent-hint data-test="vehicle-qr-blank-count" />
30
+ <v-radio-group v-model="blankKind" inline density="compact" hide-details class="mb-3" data-test="vehicle-qr-blank-kind">
31
+ <v-radio value="new" label="Make new stickers" data-test="vehicle-qr-blank-kind-new" />
32
+ <v-radio value="saved" label="Reprint saved stickers (not linked yet)" :disabled="!blankSummary?.available"
33
+ data-test="vehicle-qr-blank-kind-saved" />
34
+ </v-radio-group>
35
+ <v-text-field v-if="blankKind === 'new'" v-model.number="blankQty" type="number" :min="1" :max="BLANK_MAX_COUNT"
36
+ label="How many stickers?" density="compact" variant="outlined" style="max-width: 240px"
37
+ :hint="`1 to ${BLANK_MAX_COUNT} at a time`" persistent-hint data-test="vehicle-qr-blank-count" />
38
+ <template v-else>
39
+ <v-text-field v-model="savedSearch" label="Sticker number or code (optional)" density="compact" variant="outlined"
40
+ style="max-width: 360px" clearable persistent-hint
41
+ hint="Leave empty to see every saved sticker; untick the ones you do not need on the next step."
42
+ data-test="vehicle-qr-blank-saved-search" />
43
+ <p class="text-caption text-medium-emphasis mt-2 mb-0">{{ BLANK_LIST_NOTE }}</p>
44
+ </template>
33
45
  </div>
34
46
  <div v-if="mode === 'vehicles'" class="d-flex flex-wrap align-center ga-2 mb-2">
35
47
  <v-checkbox-btn :model-value="allOnPageTicked" :indeterminate="someOnPageTicked && !allOnPageTicked"
@@ -72,7 +84,8 @@
72
84
  {{ missing.length }} vehicle(s) could not be found and were skipped.
73
85
  </v-alert>
74
86
  <v-alert v-if="dropped" type="info" variant="tonal" density="compact" class="mb-3">
75
- {{ dropped }} more vehicle(s) were over the {{ STICKER_MAX_PER_REQUEST }} limit - print again for the rest.
87
+ <template v-if="isBlank">{{ dropped }} more saved sticker(s) were over the {{ SAVED_REPRINT_MAX }} limit - search by sticker number to print the rest.</template>
88
+ <template v-else>{{ dropped }} more vehicle(s) were over the {{ STICKER_MAX_PER_REQUEST }} limit - print again for the rest.</template>
76
89
  </v-alert>
77
90
  <v-table density="compact" fixed-header height="220">
78
91
  <thead>
@@ -84,7 +97,7 @@
84
97
  <td><v-checkbox-btn :model-value="ticked.includes(it.vehicleId)" :aria-label="`Print ${it.plateNumber}`"
85
98
  @update:model-value="(v: any) => (ticked = setIds(ticked, [it.vehicleId], !!v))" /></td>
86
99
  <template v-if="isBlank">
87
- <td class="font-weight-bold">{{ it.plateNumber }}</td>
100
+ <td class="font-weight-bold">{{ blankRowLabel(it) }}</td>
88
101
  <td class="text-medium-emphasis">{{ BLANK_STRIP_NOTE }}</td>
89
102
  </template>
90
103
  <template v-else>
@@ -210,8 +223,10 @@
210
223
  <v-spacer />
211
224
  <v-btn variant="text" class="text-none" @click="close(false)">Cancel</v-btn>
212
225
  <v-btn v-if="step === 'select'" color="primary" variant="flat" class="text-none"
213
- :disabled="mode === 'blank' ? !blankCount(blankQty) : !selected.length" :loading="loading" @click="goReview">
214
- <template v-if="mode === 'blank'">Preview {{ blankCount(blankQty) }} blank sticker{{ blankCount(blankQty) === 1 ? "" : "s" }}</template>
226
+ :disabled="mode === 'blank' ? (blankKind === 'new' ? !blankCount(blankQty) : !blankSummary?.available) : !selected.length"
227
+ :loading="loading" @click="goReview">
228
+ <template v-if="mode === 'blank' && blankKind === 'saved'">Show saved stickers</template>
229
+ <template v-else-if="mode === 'blank'">Preview {{ blankCount(blankQty) }} blank sticker{{ blankCount(blankQty) === 1 ? "" : "s" }}</template>
215
230
  <template v-else>Preview {{ selected.length }} sticker{{ selected.length === 1 ? "" : "s" }}</template>
216
231
  </v-btn>
217
232
  <template v-if="step === 'review'">
@@ -245,7 +260,7 @@
245
260
  <script lang="ts" setup>
246
261
  import QRCode from "qrcode";
247
262
  import useVehicle from "../composables/useVehicle";
248
- import { BLANK_DEFAULT_COUNT, BLANK_MAX_COUNT, BLANK_STRIP_NOTE, STICKER_NEW_NOTE, STICKER_SAME_NOTE, blankCount, blankStickerItems, blankSummaryText, reprintItems, type BlankSummary } from "../utils/vehicle-qr-blank";
263
+ import { BLANK_DEFAULT_COUNT, BLANK_LIST_NOTE, BLANK_MAX_COUNT, BLANK_STRIP_NOTE, SAVED_REPRINT_MAX, blankRowLabel, savedBlankItems, STICKER_NEW_NOTE, STICKER_SAME_NOTE, blankCount, blankStickerItems, blankSummaryText, reprintItems, type BlankSummary } from "../utils/vehicle-qr-blank";
249
264
  import { errorConverter } from "../utils/data";
250
265
  import { saveFile, stickerBundleName, stickerFileNames, svgToImage, zipFiles, type ImageFormat } from "../utils/vehicle-qr-export";
251
266
  import {
@@ -313,6 +328,9 @@ async function loadBlankSummary() {
313
328
  // "vehicles" = stickers for chosen vehicles; "blank" = codes made in advance, linked to a vehicle later.
314
329
  const mode = ref<"vehicles" | "blank">("vehicles");
315
330
  const blankQty = ref<number | string>(BLANK_DEFAULT_COUNT);
331
+ // "new" = generate a fresh batch; "saved" = print again stickers already made and not linked yet.
332
+ const blankKind = ref<"new" | "saved">("new");
333
+ const savedSearch = ref("");
316
334
  const isBlank = ref(false); // the mode the shown review was made in
317
335
 
318
336
  const step = ref<"select" | "review">("select");
@@ -428,6 +446,8 @@ watch(
428
446
  docHtml.value = "";
429
447
  step.value = "select";
430
448
  mode.value = "vehicles";
449
+ blankKind.value = "new";
450
+ savedSearch.value = "";
431
451
  isBlank.value = false;
432
452
  plates.value = stickerPlateRows(props.rows);
433
453
  selected.value = defaultPlateIds(plates.value);
@@ -466,6 +486,31 @@ async function goReview() {
466
486
  loading.value = true;
467
487
  error.value = "";
468
488
  try {
489
+ if (mode.value === "blank" && blankKind.value === "saved" && !props.vehicleIds.length) {
490
+ const found: Array<Record<string, any>> = [];
491
+ let page = 1;
492
+ let total = 0;
493
+ let name = "";
494
+ do {
495
+ const res = await getAvailableBlankVehicleQr(props.site, { search: savedSearch.value || "", page, limit: 100 });
496
+ found.push(...(res?.items ?? []));
497
+ total = res?.total ?? 0;
498
+ name = String(res?.site?.name ?? name);
499
+ page += 1;
500
+ } while (found.length < total && found.length < SAVED_REPRINT_MAX);
501
+ items.value = savedBlankItems(found);
502
+ if (!items.value.length) {
503
+ error.value = savedSearch.value ? "No saved sticker matches that number or code." : "No saved stickers to reprint.";
504
+ return;
505
+ }
506
+ siteName.value = name;
507
+ missing.value = [];
508
+ dropped.value = Math.max(total - found.length, 0);
509
+ ticked.value = items.value.map((i) => i.vehicleId);
510
+ isBlank.value = true;
511
+ step.value = "review";
512
+ return;
513
+ }
469
514
  if (mode.value === "blank" && !props.vehicleIds.length) {
470
515
  const blank = await getBlankVehicleQrStickers(props.site, blankCount(blankQty.value));
471
516
  items.value = blankStickerItems(blank?.items ?? []);
@@ -329,13 +329,15 @@ function getSpecificVehicleById(id: string){
329
329
  }
330
330
 
331
331
  // Blank codes saved when printed and still free to link, plus {printed, linked, available}.
332
+ // `search` matches the code or the sticker number; `qr` lets a saved sticker be printed again.
332
333
  function getAvailableBlankVehicleQr(site: string, query: { search?: string; page?: number; limit?: number } = {}) {
333
334
  return useNuxtApp().$api<{
335
+ site?: { _id: string; name: string };
334
336
  summary: { printed: number; linked: number; available: number };
335
337
  total: number;
336
338
  page: number;
337
339
  limit: number;
338
- items: Array<{ token: string; code: string }>;
340
+ items: Array<{ token: string; code: string; qr?: string; serialNo?: number | null; serialLabel?: string | null }>;
339
341
  }>(`/api/vehicles/qr/blank-stickers/site/${site}`, { query });
340
342
  }
341
343
 
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.693",
5
+ "version": "4.97.1-staging.694",
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.",
@@ -28,6 +28,23 @@ export function blankStickerItems(items: BlankItem[]): StickerItem[] {
28
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
+ /** Most saved stickers one reprint loads (the list endpoint pages 100 at a time). */
32
+ export const SAVED_REPRINT_MAX = BLANK_MAX_COUNT;
33
+
34
+ /** Saved (unlinked) blank stickers as printable items; a row the server sent without its QR is skipped. */
35
+ export function savedBlankItems(items: Array<Partial<BlankItem> & { serialNo?: number | null }>): StickerItem[] {
36
+ return blankStickerItems(
37
+ items
38
+ .filter((i): i is BlankItem => !!i?.token && !!i?.qr && !!i?.code)
39
+ .map((i) => ({ token: i.token, qr: i.qr, code: i.code, ...(i.serialNo ? { serialNo: i.serialNo, serialLabel: i.serialLabel ?? null } : {}) })),
40
+ );
41
+ }
42
+
43
+ /** The reprint list's code cell: "TLR001 - ABCD-..." when the sticker has a number. */
44
+ export function blankRowLabel(item: { plateNumber?: string; serialLabel?: string | null }): string {
45
+ return item.serialLabel ? `${item.serialLabel} - ${item.plateNumber ?? ""}` : String(item.plateNumber ?? "");
46
+ }
47
+
31
48
  /**
32
49
  * The token a sticker's QR carries: older stickers hold "S365V:<token>", newer
33
50
  * ones a link ".../q/<token>" (a phone camera opens a "no data" page).