@7365admin1/layer-common 4.97.1-staging.628 → 4.97.1-staging.630

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.
@@ -85,6 +85,7 @@
85
85
  hide-details="auto"
86
86
  item-title="label"
87
87
  item-value="value"
88
+ item-props="props"
88
89
  :rules="[requiredRule]"
89
90
  />
90
91
  </v-col>
@@ -147,8 +148,14 @@
147
148
  <span class="screen-hint">Loading available count...</span>
148
149
  </template>
149
150
  <template v-else-if="availableCount !== null">
150
- <span :class="availableCount === 0 ? 'text-error' : 'screen-hint'">
151
+ <span :class="notEnoughCards ? 'text-error' : 'screen-hint'">
151
152
  Available: {{ availableCount }}
153
+ <template v-if="availableCount === 0">
154
+ - No spare cards available. Add access cards first.
155
+ </template>
156
+ <template v-else-if="notEnoughCards">
157
+ - {{ totalRequired }} needed for {{ form.units.length }} units
158
+ </template>
152
159
  </span>
153
160
  </template>
154
161
  </div>
@@ -175,7 +182,7 @@
175
182
  block
176
183
  variant="flat"
177
184
  class="text-none screen-btn-primary"
178
- :disabled="!validForm || loading || availableCount === 0 || (availableCount !== null && form.quantity > availableCount)"
185
+ :disabled="!validForm || loading || availableLoading || notEnoughCards"
179
186
  :loading="loading"
180
187
  @click="submit"
181
188
  >
@@ -200,6 +207,7 @@ const {
200
207
  getLiftAccessLevels: _getLiftAccessLevels,
201
208
  assignAccessCard: _assignAccessCard,
202
209
  getAvailableAccessCards: _getAvailableAccessCards,
210
+ getAllAccessCardsCounts: _getAllAccessCardsCounts,
203
211
  getBlockLevelUnitList: _getBlockLevelUnitList,
204
212
  } = useAccessManagement();
205
213
  const { requiredRule } = useUtils();
@@ -226,10 +234,31 @@ const form = ref({
226
234
  liftAccessLevel: null as string | null,
227
235
  });
228
236
 
229
- const typeItems = [
230
- { label: "Physical Access Card", value: "NFC" },
231
- { label: "Non Physical Access Card", value: "QRCODE" },
232
- ];
237
+ // Site-wide spare cards per type; null until known, so a failed read never
238
+ // disables a type.
239
+ const spareByType = ref<{ NFC: number | null; QRCODE: number | null }>({
240
+ NFC: null,
241
+ QRCODE: null,
242
+ });
243
+
244
+ const typeItems = computed(() =>
245
+ [
246
+ { label: "Physical Access Card", value: "NFC" as const },
247
+ { label: "Non Physical Access Card", value: "QRCODE" as const },
248
+ ].map((t) => ({
249
+ ...t,
250
+ label: spareByType.value[t.value] === 0 ? `${t.label} (none spare)` : t.label,
251
+ props: { disabled: spareByType.value[t.value] === 0 },
252
+ }))
253
+ );
254
+
255
+ // The API needs `quantity` cards for EACH selected unit.
256
+ const totalRequired = computed(
257
+ () => (form.value.quantity || 0) * Math.max(form.value.units.length, 1)
258
+ );
259
+ const notEnoughCards = computed(
260
+ () => availableCount.value !== null && totalRequired.value > availableCount.value
261
+ );
233
262
 
234
263
  const NO_SELECTION = { name: "No Selection", no: null };
235
264
  const accessLevelItems = ref<{ name: string; no: string | null }[]>([]);
@@ -248,17 +277,21 @@ function minQuantityRule(v: number) {
248
277
  }
249
278
 
250
279
  function maxQuantityRule(v: number) {
251
- if (availableCount.value !== null && v > availableCount.value) {
252
- return `Quantity cannot exceed available (${availableCount.value})`;
280
+ const units = Math.max(form.value.units.length, 1);
281
+ if (availableCount.value !== null && v * units > availableCount.value) {
282
+ return units > 1
283
+ ? `Quantity x ${units} units cannot exceed available (${availableCount.value})`
284
+ : `Quantity cannot exceed available (${availableCount.value})`;
253
285
  }
254
286
  return true;
255
287
  }
256
288
 
289
+ // Always fetched - with no level picked it counts the cards with no level,
290
+ // which are exactly the ones the API will assign. Only the latest answer is
291
+ // kept, so a slow reply for an old selection cannot overwrite a newer one.
292
+ let availableRequest = 0;
257
293
  async function fetchAvailableCount() {
258
- if (!form.value.accessLevel && !form.value.liftAccessLevel) {
259
- availableCount.value = null;
260
- return;
261
- }
294
+ const request = ++availableRequest;
262
295
  availableLoading.value = true;
263
296
  availableCount.value = null;
264
297
  try {
@@ -269,6 +302,7 @@ async function fetchAvailableCount() {
269
302
  accessLevel: form.value.accessLevel,
270
303
  liftAccessLevel: form.value.liftAccessLevel,
271
304
  });
305
+ if (request !== availableRequest) return;
272
306
  const data: { counts: { count: number }[] }[] = res.data ?? [];
273
307
  availableCount.value = data.reduce(
274
308
  (total, item) =>
@@ -276,9 +310,28 @@ async function fetchAvailableCount() {
276
310
  0
277
311
  );
278
312
  } catch {
279
- availableCount.value = null;
313
+ if (request === availableRequest) availableCount.value = null;
280
314
  } finally {
281
- availableLoading.value = false;
315
+ if (request === availableRequest) availableLoading.value = false;
316
+ }
317
+ }
318
+
319
+ async function fetchSpareByType() {
320
+ try {
321
+ const res = await _getAllAccessCardsCounts({
322
+ site: siteId.value,
323
+ userType: form.value.userType,
324
+ });
325
+ spareByType.value = {
326
+ NFC: res?.data?.available_physical ?? null,
327
+ QRCODE: res?.data?.available_non_physical ?? null,
328
+ };
329
+ // Start on a type that has spare cards when the default has none.
330
+ if (spareByType.value.NFC === 0 && (spareByType.value.QRCODE ?? 0) > 0) {
331
+ form.value.type = "QRCODE";
332
+ }
333
+ } catch {
334
+ // Leave both unknown; the matching count below still guards Assign.
282
335
  }
283
336
  }
284
337
 
@@ -293,6 +346,8 @@ onMounted(async () => {
293
346
  buildingLoading.value = true;
294
347
  levelsLoading.value = true;
295
348
 
349
+ fetchSpareByType();
350
+
296
351
  const [blockLevelResult, acmResult] = await Promise.allSettled([
297
352
  _getBlockLevelUnitList(siteId.value),
298
353
  getEncryptedAcmUrl(siteId.value),
@@ -407,6 +462,8 @@ async function submit() {
407
462
  error?.data?.message ||
408
463
  "Failed to assign access card.";
409
464
  emit("error", msg);
465
+ // Cards may have run out since the count was read - show the real number.
466
+ fetchAvailableCount();
410
467
  } finally {
411
468
  loading.value = false;
412
469
  }
@@ -1,6 +1,6 @@
1
1
  <!--
2
2
  New smart detection, in two steps.
3
- Step 1: name it, pick a camera, drag a box over the area to watch on the camera's latest picture.
3
+ Step 1: name it, pick a camera, drag a box over the area to watch on the camera's live view.
4
4
  Step 2: list the results (what the area can look like) and which ones should raise an alert.
5
5
  The box is saved as fractions of the picture (0..1) so it stays right at any screen size.
6
6
  -->
@@ -42,26 +42,23 @@
42
42
  </v-row>
43
43
 
44
44
  <template v-if="camera">
45
- <v-progress-linear v-if="imgLoading" indeterminate class="mb-2" />
46
45
  <div
47
46
  ref="stage"
48
47
  class="cctv-dc__stage"
49
48
  role="img"
50
- :aria-label="`Latest picture from ${camera}. Drag to draw a box over the area.`"
49
+ :aria-label="`Live view of ${camera}. Drag to draw a box over the area.`"
51
50
  @pointerdown.prevent="down"
52
51
  @pointermove="move"
53
52
  @pointerup="up"
54
53
  @pointercancel="up"
55
54
  >
56
- <img v-if="image" :src="image" alt="" class="cctv-dc__img" draggable="false" />
57
- <div v-else-if="!imgLoading" class="cctv-dc__none">No picture available yet. The engine may be offline. You can still draw a box.</div>
55
+ <CctvEngineLiveTile :key="`${engine}/${camera}`" :engine-id="engine" :camera="camera" natural class="cctv-dc__live" />
58
56
  <div v-if="box" class="cctv-dc__box" :style="boxStyle" />
59
57
  </div>
60
58
  <div class="hero-muted mt-1">
61
59
  <template v-if="cropIsUsable(crop)">Area set. Drag again to change it.</template>
62
60
  <template v-else>Press and drag on the picture to draw a box around the area. Make it big enough to see clearly.</template>
63
61
  </div>
64
- <CctvEngineNotice v-if="imgError" class="mt-2" tone="info" :error="imgError" title="The latest picture could not be loaded" body="The engine may be offline. You can still draw a box on the grey area." />
65
62
  </template>
66
63
  </template>
67
64
 
@@ -115,7 +112,7 @@
115
112
  </template>
116
113
 
117
114
  <script setup lang="ts">
118
- import { computed, onBeforeUnmount, ref, watch } from "vue";
115
+ import { computed, ref, watch } from "vue";
119
116
  import {
120
117
  cropFromDrag, cropIsUsable, DEFAULT_RESULTS, detectionNameProblem, MIN_PHOTOS_PER_RESULT, resultsProblem, toWord,
121
118
  type TCrop,
@@ -123,7 +120,7 @@ import {
123
120
 
124
121
  const props = defineProps<{ modelValue: boolean; engine: string }>();
125
122
  const emit = defineEmits<{ (e: "update:modelValue", v: boolean): void; (e: "created", message: string): void }>();
126
- const { listCameras, latestImage, createClassifier } = useCctvEngine();
123
+ const { listCameras, createClassifier } = useCctvEngine();
127
124
 
128
125
  const step = ref(1);
129
126
  const name = ref("");
@@ -131,9 +128,6 @@ const camera = ref("");
131
128
  const cameras = ref<any[]>([]);
132
129
  const camLoading = ref(false);
133
130
  const camError = ref<unknown>(null);
134
- const image = ref("");
135
- const imgLoading = ref(false);
136
- const imgError = ref<unknown>(null);
137
131
  const crop = ref<TCrop | null>(null);
138
132
  const states = ref<string[]>([...DEFAULT_RESULTS]);
139
133
  const alertStates = ref<string[]>(["rubbish"]);
@@ -176,11 +170,6 @@ function setStates(v: string[]) {
176
170
  alertStates.value = alertStates.value.filter((a) => clean.includes(a));
177
171
  }
178
172
 
179
- function freeImage() {
180
- if (image.value) URL.revokeObjectURL(image.value);
181
- image.value = "";
182
- }
183
-
184
173
  async function loadCameras() {
185
174
  cameras.value = [];
186
175
  camError.value = null;
@@ -194,20 +183,6 @@ async function loadCameras() {
194
183
  camLoading.value = false;
195
184
  }
196
185
  }
197
- async function loadImage() {
198
- freeImage();
199
- crop.value = null;
200
- imgError.value = null;
201
- if (!camera.value) return;
202
- imgLoading.value = true;
203
- try {
204
- image.value = await latestImage(props.engine, camera.value);
205
- } catch (e) {
206
- imgError.value = e;
207
- } finally {
208
- imgLoading.value = false;
209
- }
210
- }
211
186
 
212
187
  async function create() {
213
188
  saving.value = true;
@@ -236,7 +211,6 @@ function reset() {
236
211
  states.value = [...DEFAULT_RESULTS];
237
212
  alertStates.value = ["rubbish"];
238
213
  error.value = null;
239
- freeImage();
240
214
  }
241
215
  function close(v: boolean) {
242
216
  emit("update:modelValue", v);
@@ -248,13 +222,11 @@ watch(() => props.modelValue, (open) => {
248
222
  loadCameras();
249
223
  }
250
224
  }, { immediate: true });
251
- watch(camera, loadImage);
252
- onBeforeUnmount(freeImage);
225
+ watch(camera, () => (crop.value = null));
253
226
  </script>
254
227
 
255
228
  <style scoped>
256
229
  .cctv-dc__stage { position: relative; background: #111; border-radius: 10px; overflow: hidden; min-height: 180px; user-select: none; cursor: crosshair; touch-action: none; }
257
- .cctv-dc__img { width: 100%; display: block; pointer-events: none; }
258
- .cctv-dc__none { color: #ddd; padding: 60px 16px; text-align: center; font-size: 13px; aspect-ratio: 16 / 9; }
230
+ .cctv-dc__live { pointer-events: none; }
259
231
  .cctv-dc__box { position: absolute; border: 2px solid #fff; background: rgba(30, 136, 229, 0.3); box-shadow: 0 0 0 1px #1e88e5; pointer-events: none; }
260
232
  </style>
@@ -4,7 +4,7 @@
4
4
  Offline engine / failures are shown on the tile in plain words with a Try again button.
5
5
  -->
6
6
  <template>
7
- <div class="cctv-tile" :class="{ 'cctv-tile--big': big }" data-test="cctv-tile">
7
+ <div class="cctv-tile" :class="{ 'cctv-tile--big': big, 'cctv-tile--natural': natural }" data-test="cctv-tile">
8
8
  <video v-show="mode === 'live'" ref="video" autoplay muted playsinline class="cctv-tile__media" />
9
9
  <img v-if="mode === 'still' && still" :src="still" :alt="`Latest picture from ${camera}`" class="cctv-tile__media" />
10
10
 
@@ -37,7 +37,8 @@
37
37
  import { computed, onBeforeUnmount, onMounted, ref, watch } from "vue";
38
38
  import { cctvNotice, STILL_REFRESH_MS } from "../../utils/cctv-engine";
39
39
 
40
- const props = defineProps<{ engineId: string; camera: string; big?: boolean }>();
40
+ // natural: keep the camera's own shape (no 16:9 box) so drawings laid over the tile line up with the picture.
41
+ const props = defineProps<{ engineId: string; camera: string; big?: boolean; natural?: boolean }>();
41
42
 
42
43
  const { webrtcAnswer, latestImage } = useCctvEngine();
43
44
 
@@ -176,6 +177,8 @@ onBeforeUnmount(stop);
176
177
  <style scoped>
177
178
  .cctv-tile { position: relative; background: #000; aspect-ratio: 16 / 9; border-radius: 10px; overflow: hidden; color: #fff; }
178
179
  .cctv-tile__media { width: 100%; height: 100%; object-fit: contain; display: block; }
180
+ .cctv-tile--natural { aspect-ratio: auto; min-height: 180px; border-radius: 0; }
181
+ .cctv-tile--natural .cctv-tile__media { height: auto; }
179
182
  .cctv-tile__msg { position: absolute; inset: 0; display: flex; flex-direction: column; gap: 6px; align-items: center; justify-content: center; text-align: center; padding: 12px; font-size: 12px; overflow: auto; }
180
183
  .cctv-tile__bar { position: absolute; left: 0; right: 0; bottom: 0; display: flex; align-items: center; gap: 6px; padding: 4px 8px; background: linear-gradient(transparent, rgba(0, 0, 0, 0.75)); }
181
184
  .cctv-tile__name { flex: 1; font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@@ -1,5 +1,5 @@
1
1
  <!--
2
- Zones & wrong-way. Draw areas on the camera's latest picture (click to add corners). Zones name an area
2
+ Zones & wrong-way. Draw areas on the camera's live view (click to add corners). Zones name an area
3
3
  (for alerts and wrong-way rules); masks tell the engine to ignore an area (motion / objects).
4
4
  Coordinates are saved as fractions of the picture (0..1), so they stay right at any screen size.
5
5
  -->
@@ -17,11 +17,10 @@
17
17
  class="cctv-zn__stage"
18
18
  :class="{ 'cctv-zn__stage--draw': canEdit }"
19
19
  role="img"
20
- :aria-label="`Latest picture from ${camera}. ${canEdit ? 'Click to add a corner.' : ''}`"
20
+ :aria-label="`Live view of ${camera}. ${canEdit ? 'Click to add a corner.' : ''}`"
21
21
  @click="addPoint"
22
22
  >
23
- <img v-if="image" :src="image" alt="" class="cctv-zn__img" draggable="false" />
24
- <div v-else class="cctv-zn__none">No picture available yet - you can still draw, but placing is easier with a picture.</div>
23
+ <CctvEngineLiveTile :key="`${engine}/${camera}`" :engine-id="engine" :camera="camera" natural />
25
24
  <svg viewBox="0 0 1 1" preserveAspectRatio="none" class="cctv-zn__svg" aria-hidden="true">
26
25
  <polygon v-for="(z, i) in zones" :key="`z${i}`" :points="svg(z.points)" :fill="color(i, 0.25)" :stroke="color(i, 1)" stroke-width="2" vector-effect="non-scaling-stroke" />
27
26
  <polygon v-for="(m, i) in masks" :key="`m${i}`" :points="svg(m.points)" fill="rgba(0,0,0,0.45)" stroke="#fff" stroke-dasharray="6 4" stroke-width="2" vector-effect="non-scaling-stroke" />
@@ -65,7 +64,6 @@
65
64
  </div>
66
65
  </v-col>
67
66
  </v-row>
68
- <CctvEngineNotice v-if="imageError && !error" class="mt-2" :error="imageError" title="The latest picture could not be loaded" body="The engine may be offline. You can still draw, then save when it is back." tone="info" />
69
67
  </template>
70
68
 
71
69
  <v-divider class="my-6" />
@@ -74,14 +72,14 @@
74
72
  </template>
75
73
 
76
74
  <script setup lang="ts">
77
- import { computed, onBeforeUnmount, ref, watch } from "vue";
75
+ import { computed, ref, watch } from "vue";
78
76
  import {
79
77
  buildZonesBody, CCTV_PERMISSIONS, isValidPolygon, pointFromClick, polygonToSvgPoints, readZonesReply,
80
78
  type TMask, type TPoint, type TZone,
81
79
  } from "../../utils/cctv-engine";
82
80
 
83
81
  const props = defineProps<{ site: string; access?: { can: (p: any) => boolean } }>();
84
- const { getZones, saveZones, latestImage } = useCctvEngine();
82
+ const { getZones, saveZones } = useCctvEngine();
85
83
 
86
84
  const engine = ref("");
87
85
  const camera = ref("");
@@ -98,8 +96,6 @@ const masks = ref<TMask[]>([]);
98
96
  const draft = ref<TPoint[]>([]);
99
97
  const kind = ref<"zone" | "motion" | "object">("zone");
100
98
  const zoneName = ref("");
101
- const image = ref("");
102
- const imageError = ref<unknown>(null);
103
99
  const loading = ref(false);
104
100
  const error = ref<unknown>(null);
105
101
  const saving = ref(false);
@@ -134,26 +130,19 @@ function readZones(res: any) {
134
130
  ({ zones: zones.value, masks: masks.value } = readZonesReply(res));
135
131
  }
136
132
 
137
- function freeImage() {
138
- if (image.value) URL.revokeObjectURL(image.value);
139
- image.value = "";
140
- }
141
-
142
133
  async function load() {
143
134
  zones.value = [];
144
135
  masks.value = [];
145
136
  draft.value = [];
146
137
  saveMsg.value = "";
147
138
  error.value = null;
148
- imageError.value = null;
149
- freeImage();
150
139
  if (!engine.value || !camera.value) return;
151
140
  loading.value = true;
152
- const [z, img] = await Promise.allSettled([getZones(engine.value, camera.value), latestImage(engine.value, camera.value)]);
153
- if (z.status === "fulfilled") readZones(z.value);
154
- else error.value = z.reason;
155
- if (img.status === "fulfilled") image.value = img.value;
156
- else imageError.value = img.reason;
141
+ try {
142
+ readZones(await getZones(engine.value, camera.value));
143
+ } catch (e) {
144
+ error.value = e;
145
+ }
157
146
  loading.value = false;
158
147
  }
159
148
 
@@ -176,14 +165,11 @@ async function save() {
176
165
  }
177
166
 
178
167
  watch([engine, camera], load);
179
- onBeforeUnmount(freeImage);
180
168
  </script>
181
169
 
182
170
  <style scoped>
183
171
  .cctv-zn__stage { position: relative; background: #111; border-radius: 10px; overflow: hidden; min-height: 180px; user-select: none; }
184
172
  .cctv-zn__stage--draw { cursor: crosshair; }
185
- .cctv-zn__img { width: 100%; display: block; }
186
- .cctv-zn__none { color: #ddd; padding: 60px 16px; text-align: center; font-size: 13px; aspect-ratio: 16 / 9; }
187
173
  .cctv-zn__svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
188
174
  .cctv-zn__dot { position: absolute; width: 10px; height: 10px; margin: -5px 0 0 -5px; border-radius: 50%; background: #fff; border: 2px solid #1e88e5; pointer-events: none; }
189
175
  </style>
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.628",
5
+ "version": "4.97.1-staging.630",
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.",