@7365admin1/layer-common 4.163.7 → 4.164.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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @iservice365/layer-common
2
2
 
3
+ ## 4.164.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 0305d43: CCTV Engine Live: saved camera groups - pick a group to show its cameras; users who manage engines can save the picked cameras as a group or delete one.
8
+
3
9
  ## 4.163.7
4
10
 
5
11
  ### Patch Changes
@@ -3748,11 +3754,11 @@ Monthly report: a month that had patrols opens the list of that month's patrol r
3748
3754
  `utils/console-tier.ts` + `composables/useConsoleTier.ts` mirror the server's
3749
3755
  own rule from two endpoints the console already calls, unprojected:
3750
3756
 
3751
- GET /api/members/user/:user/app/admin the Seven365 staff membership
3752
- GET /api/roles/id/:role that membership's role document
3757
+ GET /api/members/user/:user/app/admin the Seven365 staff membership
3758
+ GET /api/roles/id/:role that membership's role document
3753
3759
 
3754
- owner = member.type === "admin" && role.type === "admin" && role.default === true
3755
- staff = member.type === "admin" && role.type === "admin"
3760
+ owner = member.type === "admin" && role.type === "admin" && role.default === true
3761
+ staff = member.type === "admin" && role.type === "admin"
3756
3762
 
3757
3763
  `role.default` is the marker because it is the only property of a platform
3758
3764
  staff role no API caller can set - `role.controller.ts` validates create and
@@ -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>
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.163.7",
5
+ "version": "4.164.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.",
@@ -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