@7365admin1/layer-common 4.97.1-staging.642 → 4.97.1-staging.644

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.
@@ -9,6 +9,21 @@
9
9
 
10
10
  <template v-if="engine">
11
11
  <div class="d-flex flex-wrap align-center ga-3 my-3">
12
+ <v-select
13
+ v-if="groups.length"
14
+ :model-value="group"
15
+ :items="groups"
16
+ item-title="name"
17
+ item-value="name"
18
+ label="Camera group"
19
+ density="comfortable"
20
+ hide-details
21
+ clearable
22
+ class="cctv-live__group"
23
+ :max-width="smAndDown ? undefined : 260"
24
+ data-test="camera-group"
25
+ @update:model-value="pickGroup"
26
+ />
12
27
  <v-btn-toggle v-model="tiles" mandatory density="comfortable" divided color="primary" aria-label="Grid size">
13
28
  <v-btn v-for="l in GRID_LAYOUTS" :key="l.key" :value="l.key" size="small">{{ l.key === 1 ? "Single" : l.key }}</v-btn>
14
29
  </v-btn-toggle>
@@ -26,8 +41,16 @@
26
41
  :hint="`Up to ${tiles}. Empty = the first ${tiles} on this engine.`"
27
42
  class="cctv-live__picker"
28
43
  :max-width="smAndDown ? undefined : 420"
44
+ @update:model-value="group = null"
29
45
  />
46
+ <template v-if="canManage && cameras.length">
47
+ <v-btn size="small" variant="tonal" prepend-icon="mdi-content-save-outline" :disabled="!picked.length" @click="openSave">Save as group</v-btn>
48
+ <v-btn v-if="group" size="small" variant="text" color="error" prepend-icon="mdi-delete-outline" @click="removeOpen = true">Delete group</v-btn>
49
+ </template>
30
50
  </div>
51
+ <p v-if="canManage && cameras.length && !groups.length" class="hero-muted mt-n1 mb-2">
52
+ Tip: pick the cameras you watch together, then press Save as group. Everyone on this site can then show them with one choice.
53
+ </p>
31
54
 
32
55
  <v-progress-linear v-if="loading" indeterminate />
33
56
  <CctvEngineNotice v-else-if="error" :error="error" retry @retry="loadCameras" />
@@ -40,36 +63,92 @@
40
63
  <CctvEngineLiveTile v-for="c in shown" :key="`${engine}/${c.name}`" :engine-id="engine" :camera="c.name" />
41
64
  </div>
42
65
  </template>
66
+
67
+ <v-dialog v-model="saveOpen" max-width="460">
68
+ <v-card>
69
+ <v-card-title>Save these cameras as a group</v-card-title>
70
+ <v-card-text>
71
+ <p class="hero-muted">{{ picked.length }} camera{{ picked.length === 1 ? "" : "s" }}: {{ picked.slice(0, MAX_GROUP_CAMERAS).join(", ") }}</p>
72
+ <v-text-field v-model="groupName" label="Group name (e.g. Gate cameras)" density="comfortable" counter="40" maxlength="40" autofocus />
73
+ <p class="hero-muted mb-0">A group with the same name is replaced.</p>
74
+ <CctvEngineNotice v-if="saveError" class="mt-2" :error="saveError" />
75
+ </v-card-text>
76
+ <v-card-actions>
77
+ <v-spacer />
78
+ <v-btn variant="text" @click="saveOpen = false">Cancel</v-btn>
79
+ <v-btn color="primary" :loading="saving" :disabled="!groupName.trim()" @click="saveGroup">Save group</v-btn>
80
+ </v-card-actions>
81
+ </v-card>
82
+ </v-dialog>
83
+
84
+ <v-dialog v-model="removeOpen" max-width="420">
85
+ <v-card>
86
+ <v-card-title>Delete the group "{{ group }}"?</v-card-title>
87
+ <v-card-text>
88
+ Only the saved group is removed. The cameras keep working.
89
+ <CctvEngineNotice v-if="saveError" class="mt-2" :error="saveError" />
90
+ </v-card-text>
91
+ <v-card-actions>
92
+ <v-spacer />
93
+ <v-btn variant="text" @click="removeOpen = false">Keep</v-btn>
94
+ <v-btn color="error" :loading="saving" @click="removeGroup">Delete</v-btn>
95
+ </v-card-actions>
96
+ </v-card>
97
+ </v-dialog>
43
98
  </div>
44
99
  </template>
45
100
 
46
101
  <script setup lang="ts">
47
102
  import { computed, ref, watch } from "vue";
48
103
  import { useDisplay } from "vuetify";
49
- import { GRID_LAYOUTS, gridColumns, pickGridCameras } from "../../utils/cctv-engine";
104
+ import {
105
+ CCTV_PERMISSIONS,
106
+ GRID_LAYOUTS,
107
+ MAX_GROUP_CAMERAS,
108
+ gridColumns,
109
+ groupCameras,
110
+ layoutFor,
111
+ pickGridCameras,
112
+ saveGroupIn,
113
+ type TCameraGroup,
114
+ } from "../../utils/cctv-engine";
50
115
 
51
- defineProps<{ site: string; access?: unknown }>();
116
+ const props = defineProps<{ site: string; access?: { can: (p: any) => boolean } }>();
52
117
 
53
- const { listCameras } = useCctvEngine();
118
+ const { listCameras, updateEngine } = useCctvEngine();
54
119
  const { smAndDown } = useDisplay();
120
+ const canManage = computed(() => props.access?.can(CCTV_PERMISSIONS.manageEngine) ?? false);
55
121
 
56
122
  const engine = ref("");
123
+ const engines = ref<any[]>([]);
57
124
  const tiles = ref<number>(4);
58
125
  const picked = ref<string[]>([]);
126
+ const group = ref<string | null>(null);
59
127
  const cameras = ref<{ name: string }[]>([]);
60
128
  const loading = ref(false);
61
129
  const error = ref<unknown>(null);
62
130
 
131
+ const groups = computed<TCameraGroup[]>(() => engines.value.find((e) => e._id === engine.value)?.cameraGroups ?? []);
63
132
  const shown = computed(() => pickGridCameras(cameras.value, picked.value.slice(0, tiles.value), tiles.value));
64
133
  const columns = computed(() => gridColumns(tiles.value, smAndDown.value));
65
134
 
66
135
  function onEngines(list: any[]) {
136
+ engines.value = list;
67
137
  if (!engine.value && list[0]) engine.value = list[0]._id;
68
138
  }
69
139
 
140
+ function pickGroup(name: string | null) {
141
+ group.value = name;
142
+ if (!name) return;
143
+ const names = groupCameras(groups.value.find((g) => g.name === name), cameras.value);
144
+ picked.value = names;
145
+ tiles.value = layoutFor(names.length);
146
+ }
147
+
70
148
  async function loadCameras() {
71
149
  cameras.value = [];
72
150
  picked.value = [];
151
+ group.value = null;
73
152
  error.value = null;
74
153
  if (!engine.value) return;
75
154
  loading.value = true;
@@ -83,10 +162,53 @@ async function loadCameras() {
83
162
  }
84
163
  }
85
164
 
165
+ // ---- save / delete groups (manage-engine)
166
+ const saveOpen = ref(false);
167
+ const removeOpen = ref(false);
168
+ const groupName = ref("");
169
+ const saving = ref(false);
170
+ const saveError = ref<unknown>(null);
171
+
172
+ function openSave() {
173
+ groupName.value = group.value ?? "";
174
+ saveError.value = null;
175
+ saveOpen.value = true;
176
+ }
177
+
178
+ async function store(next: TCameraGroup[]) {
179
+ saving.value = true;
180
+ saveError.value = null;
181
+ try {
182
+ const res: any = await updateEngine(engine.value, { cameraGroups: next });
183
+ const saved = res?.cameraGroups ?? next;
184
+ engines.value = engines.value.map((e) => (e._id === engine.value ? { ...e, cameraGroups: saved } : e));
185
+ return true;
186
+ } catch (e) {
187
+ saveError.value = e;
188
+ return false;
189
+ } finally {
190
+ saving.value = false;
191
+ }
192
+ }
193
+
194
+ async function saveGroup() {
195
+ const next = saveGroupIn(groups.value, groupName.value, picked.value);
196
+ if (!next || !(await store(next))) return;
197
+ saveOpen.value = false;
198
+ group.value = next.find((g) => g.name.toLowerCase() === groupName.value.trim().toLowerCase())?.name ?? null;
199
+ }
200
+
201
+ async function removeGroup() {
202
+ if (!(await store(groups.value.filter((g) => g.name !== group.value)))) return;
203
+ removeOpen.value = false;
204
+ group.value = null;
205
+ }
206
+
86
207
  watch(engine, loadCameras, { immediate: true });
87
208
  </script>
88
209
 
89
210
  <style scoped>
90
211
  .cctv-live__grid { display: grid; gap: 8px; }
91
212
  .cctv-live__picker { min-width: 220px; flex: 1; }
213
+ .cctv-live__group { min-width: 180px; }
92
214
  </style>
@@ -1771,6 +1771,35 @@
1771
1771
  </v-card>
1772
1772
  </v-dialog>
1773
1773
 
1774
+ <!-- A visit holding nothing has no return step to stop at, so it asks here. -->
1775
+ <ConfirmDialog
1776
+ v-model="dialog.confirmCheckout"
1777
+ :loading="loading.checkingOut"
1778
+ >
1779
+ <template #title>Check Out Visitor</template>
1780
+ <template #description>
1781
+ Are you sure you want to check out {{ checkoutConfirmName }}?
1782
+ </template>
1783
+ <template #footer>
1784
+ <v-spacer />
1785
+ <v-btn
1786
+ class="text-capitalize"
1787
+ variant="text"
1788
+ text="Cancel"
1789
+ :disabled="loading.checkingOut"
1790
+ @click="dialog.confirmCheckout = false"
1791
+ />
1792
+ <v-btn
1793
+ class="text-capitalize font-weight-bold"
1794
+ color="red"
1795
+ variant="flat"
1796
+ text="Check Out"
1797
+ :loading="loading.checkingOut"
1798
+ @click="confirmCheckout"
1799
+ />
1800
+ </template>
1801
+ </ConfirmDialog>
1802
+
1774
1803
  <v-dialog v-model="hidQrDialog" max-width="440" persistent>
1775
1804
  <v-card>
1776
1805
  <v-toolbar color="transparent" density="comfortable" class="px-2">
@@ -2386,6 +2415,7 @@ const dialog = reactive({
2386
2415
  returnNfcCard: false,
2387
2416
  approveRejectVisitorDialog: false,
2388
2417
  blockVehicle: false,
2418
+ confirmCheckout: false,
2389
2419
  });
2390
2420
 
2391
2421
  /* ---- Block a visitor's vehicle ------------------------------------------ */
@@ -3928,8 +3958,8 @@ function showCheckOutButton(item: Record<string, any>) {
3928
3958
 
3929
3959
  /**
3930
3960
  * Check Out, in iSecure's order: a held pass or key goes to the return
3931
- * statuses first, an NFC card to the card return, and only a visit holding
3932
- * neither checks out straight away. Each path is an update of the visit.
3961
+ * statuses first, an NFC card to the card return, and a visit holding neither
3962
+ * asks for confirmation. Each path is an update of the visit.
3933
3963
  */
3934
3964
  function handleCheckout(userId: string, visitorObj?: Record<string, any>) {
3935
3965
  if (!userId) {
@@ -3957,7 +3987,15 @@ function handleCheckout(userId: string, visitorObj?: Record<string, any>) {
3957
3987
  openNfcDialog(visitor);
3958
3988
  return;
3959
3989
  }
3960
- proceedCheckout();
3990
+ checkoutConfirmName.value = visitor?.name || "this visitor";
3991
+ dialog.confirmCheckout = true;
3992
+ }
3993
+
3994
+ const checkoutConfirmName = ref("");
3995
+
3996
+ async function confirmCheckout() {
3997
+ await proceedCheckout();
3998
+ dialog.confirmCheckout = false;
3961
3999
  }
3962
4000
 
3963
4001
  /** A visit holding nothing: just the check-out. */
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.642",
5
+ "version": "4.97.1-staging.644",
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.",
@@ -234,6 +234,32 @@ export function pickGridCameras<T extends { name: string }>(all: readonly T[], p
234
234
  return [...chosen, ...rest].slice(0, tiles);
235
235
  }
236
236
 
237
+ // --------------------------------------------------------------------------- saved camera groups
238
+
239
+ export type TCameraGroup = { name: string; cameras: string[] };
240
+ export const MAX_GROUP_CAMERAS = 16;
241
+
242
+ /** The smallest grid that holds `count` cameras (16 at most). */
243
+ export function layoutFor(count: number): number {
244
+ return (GRID_LAYOUTS.find((l) => l.key >= count) ?? GRID_LAYOUTS[GRID_LAYOUTS.length - 1]).key;
245
+ }
246
+
247
+ /** A group's cameras that the engine still has, in the group's order (a removed camera simply drops out). */
248
+ export function groupCameras(group: TCameraGroup | null | undefined, cameras: readonly { name: string }[]): string[] {
249
+ if (!group) return [];
250
+ const have = new Set(cameras.map((c) => c.name));
251
+ return group.cameras.filter((n) => have.has(n));
252
+ }
253
+
254
+ /** Add a group, or replace the one with the same name (any case). Returns a new list; null when the name or cameras are missing. */
255
+ export function saveGroupIn(groups: readonly TCameraGroup[], name: string, cameras: readonly string[]): TCameraGroup[] | null {
256
+ const n = name.trim();
257
+ if (!n || !cameras.length) return null;
258
+ const g = { name: n, cameras: cameras.slice(0, MAX_GROUP_CAMERAS) };
259
+ const i = groups.findIndex((x) => x.name.toLowerCase() === n.toLowerCase());
260
+ return i < 0 ? [...groups, g] : groups.map((x, j) => (j === i ? g : x));
261
+ }
262
+
237
263
  /** Latest-picture fallback: refresh every 2 s. The tick is part of the address so the browser never reuses a stale frame. */
238
264
  export const STILL_REFRESH_MS = 2000;
239
265