@7365admin1/layer-common 4.97.1-staging.621 → 4.97.1-staging.623

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.
@@ -376,10 +376,16 @@
376
376
  Replace Card
377
377
  </v-list-item-title>
378
378
  </v-list-item>
379
- <v-list-item :disabled="!isSelectedCardPhysical" @click="historyDialog = true">
379
+ <!-- Any card type: the details dialog fetches by card id alone.
380
+ It was gated to physical cards, and with nothing selected on
381
+ open it read as broken, so the hint says what is missing. -->
382
+ <v-list-item :disabled="!selectedCardInUnit" @click="historyDialog = true">
380
383
  <v-list-item-title class="text-subtitle-2 cursor-pointer">
381
384
  Card Details
382
385
  </v-list-item-title>
386
+ <v-list-item-subtitle v-if="!selectedCardInUnit" class="text-caption">
387
+ Select a card first
388
+ </v-list-item-subtitle>
383
389
  </v-list-item>
384
390
  <v-list-item
385
391
  @click="emit('delete')"
@@ -437,10 +443,6 @@ const props = defineProps({
437
443
  type: Boolean,
438
444
  default: false,
439
445
  },
440
- isSelectedCardPhysical: {
441
- type: Boolean,
442
- default: false,
443
- },
444
446
  siteId: {
445
447
  type: String,
446
448
  default: "",
@@ -849,6 +851,25 @@ function toggleCard(card: Record<string, any>) {
849
851
  props.selectedCardInUnit?._id === card._id ? null : card
850
852
  );
851
853
  }
854
+
855
+ // A unit with a single card opens with it selected, so More actions works
856
+ // without a click on a chip that is the only choice anyway.
857
+ const unitCards = computed(() =>
858
+ ["available", "assigned", "replaced", "deleted"].flatMap((state) => [
859
+ ...(props.unit?.[state]?.physical ?? []),
860
+ ...(props.unit?.[state]?.non_physical ?? []),
861
+ ])
862
+ );
863
+
864
+ watch(
865
+ () => [props.modelValue, props.unit?._id],
866
+ () => {
867
+ if (!props.modelValue || props.selectedCardInUnit) return;
868
+ if (unitCards.value.length === 1) {
869
+ emit("update:selectedCardInUnit", unitCards.value[0]);
870
+ }
871
+ }
872
+ );
852
873
  </script>
853
874
 
854
875
  <style scoped>
@@ -106,7 +106,6 @@
106
106
  :can-delete-access-card="canDeleteAccessCard"
107
107
  :can-assign-to-person="canUpdateAccessCard && canAssignAccessCard"
108
108
  :is-selected-card-assigned-physical="isSelectedCardAssignedPhysical"
109
- :is-selected-card-physical="isSelectedCardPhysical"
110
109
  :site-id="siteId"
111
110
  :org-id="orgId"
112
111
  @replace="openReplaceDialog()"
@@ -252,14 +251,6 @@ const isSelectedCardAssignedPhysical = computed(() =>
252
251
  ) ?? false
253
252
  );
254
253
 
255
- const isSelectedCardPhysical = computed(() =>
256
- ["available", "assigned", "replaced", "deleted"].some((state) =>
257
- selectedCard.value?.[state]?.physical?.some(
258
- (c: any) => c._id === selectedCardInUnit.value?._id
259
- )
260
- )
261
- );
262
-
263
254
  const { getUserTypeAccessCards, deleteCard: _deleteCard } = useAccessManagement();
264
255
 
265
256
  const statsRef = ref<{ refresh: () => void } | null>(null);
@@ -0,0 +1,134 @@
1
+ <!--
2
+ Alert settings (one set per site): which sightings count as an alert, who is told, when not to disturb,
3
+ and whether an incident is raised. Leaving "what", "zones" or "cameras" empty means "any".
4
+ Alerts never change a Virtual Patrol step or saved patrol record.
5
+ -->
6
+ <template>
7
+ <div>
8
+ <v-progress-linear v-if="loading" indeterminate />
9
+ <CctvEngineNotice v-else-if="error" :error="error" retry @retry="load" />
10
+ <v-form v-else :disabled="!canEdit" @submit.prevent="save">
11
+ <p class="hero-muted">
12
+ An <strong>alert</strong> is raised when the engine sees something matching the choices below. Leave a box empty to mean "any".
13
+ Example: labels <em>person</em>, zone <em>fence</em>, quiet hours off = anyone in the fence zone, day or night.
14
+ </p>
15
+ <div v-if="!canEdit" class="hero-notice mb-3">You can read these settings but not change them. Ask a site admin for cctv-engine:manage-alerts.</div>
16
+
17
+ <v-combobox v-model="form.labels" label="Objects that raise an alert (car, person, ...)" multiple chips closable-chips density="comfortable" hint="Type a word and press Enter. Empty = any object." persistent-hint />
18
+ <v-combobox v-model="form.zones" label="Only in these zones" multiple chips closable-chips density="comfortable" class="mt-3" hint="Zone names from Zones & wrong-way. Empty = anywhere." persistent-hint />
19
+ <v-combobox v-model="form.cameras" label="Only on these cameras" multiple chips closable-chips density="comfortable" class="mt-3" hint="Camera names as the engine shows them. Empty = all cameras." persistent-hint />
20
+
21
+ <v-select
22
+ v-model="form.notifyRoles"
23
+ :items="roles"
24
+ item-title="name"
25
+ item-value="_id"
26
+ label="Tell people with these roles"
27
+ multiple
28
+ chips
29
+ closable-chips
30
+ density="comfortable"
31
+ class="mt-3"
32
+ :loading="rolesLoading"
33
+ :hint="rolesProblem || 'They get a notification with the picture. Nobody is told if this is empty.'"
34
+ persistent-hint
35
+ />
36
+
37
+ <v-switch v-model="form.notifyGuards" color="primary" label="Also notify the guards on duty" hide-details class="mt-2" />
38
+ <v-switch v-model="form.createIncident" color="primary" label="Create an incident report for each alert" hide-details />
39
+
40
+ <v-switch v-model="quiet" color="primary" label="Quiet hours (no notifications between these times)" hide-details />
41
+ <v-row v-if="quiet" dense>
42
+ <v-col cols="6"><v-text-field v-model="form.quietStart" type="time" label="From" density="comfortable" /></v-col>
43
+ <v-col cols="6"><v-text-field v-model="form.quietEnd" type="time" label="Until" density="comfortable" /></v-col>
44
+ <v-col cols="12" class="hero-muted">Alerts are still recorded during quiet hours; only the notifications are held back.</v-col>
45
+ </v-row>
46
+
47
+ <div v-if="canEdit" class="mt-4">
48
+ <v-btn type="submit" color="primary" :loading="saving">Save alert settings</v-btn>
49
+ <div v-if="msg" class="mt-2" role="status">{{ msg }}</div>
50
+ <CctvEngineNotice v-if="saveError" class="mt-2" :error="saveError" />
51
+ </div>
52
+ </v-form>
53
+ </div>
54
+ </template>
55
+
56
+ <script setup lang="ts">
57
+ import { computed, reactive, ref } from "vue";
58
+ import { CCTV_PERMISSIONS } from "../../utils/cctv-engine";
59
+
60
+ const props = defineProps<{ site: string; access?: { can: (p: any) => boolean } }>();
61
+ const { getAlertSettings, saveAlertSettings } = useCctvEngine();
62
+ const { getRoles } = useRole();
63
+ const canEdit = computed(() => props.access?.can(CCTV_PERMISSIONS.manageAlerts) ?? false);
64
+
65
+ const form = reactive({
66
+ labels: [] as string[], zones: [] as string[], cameras: [] as string[], notifyRoles: [] as string[],
67
+ createIncident: false, notifyGuards: false, quietStart: "22:00", quietEnd: "06:00",
68
+ });
69
+ const quiet = ref(false);
70
+ const loading = ref(true);
71
+ const error = ref<unknown>(null);
72
+ const saving = ref(false);
73
+ const msg = ref("");
74
+ const saveError = ref<unknown>(null);
75
+
76
+ const roles = ref<any[]>([]);
77
+ const rolesLoading = ref(false);
78
+ const rolesProblem = ref("");
79
+
80
+ async function load() {
81
+ loading.value = true;
82
+ error.value = null;
83
+ try {
84
+ const s: any = await getAlertSettings(props.site);
85
+ const d = s ?? {};
86
+ Object.assign(form, {
87
+ labels: d.labels ?? [], zones: d.zones ?? [], cameras: d.cameras ?? [], notifyRoles: d.notifyRoles ?? [],
88
+ createIncident: !!d.createIncident, notifyGuards: !!d.notifyGuards,
89
+ });
90
+ quiet.value = !!d.quietHours?.start && !!d.quietHours?.end;
91
+ if (quiet.value) Object.assign(form, { quietStart: d.quietHours.start, quietEnd: d.quietHours.end });
92
+ } catch (e) {
93
+ // "No settings yet" is not an error: start from the defaults.
94
+ if (Number((e as any)?.statusCode ?? (e as any)?.status) !== 404) error.value = e;
95
+ } finally {
96
+ loading.value = false;
97
+ }
98
+ rolesLoading.value = true;
99
+ try {
100
+ const r: any = await getRoles({ site: props.site, limit: 100 });
101
+ roles.value = r?.items ?? [];
102
+ if (!roles.value.length) rolesProblem.value = "No roles were found for this site.";
103
+ } catch {
104
+ rolesProblem.value = "Roles could not be loaded, so this list cannot be changed right now. Reload the page to try again.";
105
+ } finally {
106
+ rolesLoading.value = false;
107
+ }
108
+ }
109
+
110
+ async function save() {
111
+ saving.value = true;
112
+ msg.value = "";
113
+ saveError.value = null;
114
+ const clean = (l: string[]) => [...new Set(l.map((x) => String(x).trim()).filter(Boolean))];
115
+ try {
116
+ await saveAlertSettings(props.site, {
117
+ labels: clean(form.labels).map((x) => x.toLowerCase()),
118
+ zones: clean(form.zones),
119
+ cameras: clean(form.cameras),
120
+ notifyRoles: form.notifyRoles,
121
+ createIncident: form.createIncident,
122
+ notifyGuards: form.notifyGuards,
123
+ quietHours: quiet.value ? { start: form.quietStart, end: form.quietEnd } : null,
124
+ });
125
+ msg.value = "Saved.";
126
+ } catch (e) {
127
+ saveError.value = e;
128
+ } finally {
129
+ saving.value = false;
130
+ }
131
+ }
132
+
133
+ load();
134
+ </script>
@@ -0,0 +1,107 @@
1
+ <!--
2
+ Pick an engine and one of its cameras. Used by Playback, Zones and Faces.
3
+ Says what to do when there is no engine yet, or when the engine is offline.
4
+ -->
5
+ <template>
6
+ <div>
7
+ <v-progress-linear v-if="loading" indeterminate class="mb-2" />
8
+ <CctvEngineNotice v-else-if="error" :error="error" retry @retry="load" />
9
+ <CctvEngineNotice
10
+ v-else-if="!engines.length"
11
+ title="No engine has been added yet"
12
+ body="Add an engine in the Engines & health tab first. It is the box at the site that analyses the cameras."
13
+ />
14
+ <v-row v-else dense>
15
+ <v-col cols="12" :sm="noCamera ? 12 : 6">
16
+ <v-select
17
+ :model-value="engine"
18
+ :items="engines"
19
+ item-title="name"
20
+ item-value="_id"
21
+ label="Engine"
22
+ density="comfortable"
23
+ hide-details
24
+ @update:model-value="pickEngine"
25
+ />
26
+ </v-col>
27
+ <v-col v-if="!noCamera" cols="12" sm="6">
28
+ <v-select
29
+ :model-value="camera"
30
+ :items="cameras"
31
+ item-title="name"
32
+ item-value="name"
33
+ label="Camera"
34
+ density="comfortable"
35
+ :loading="camLoading"
36
+ :no-data-text="camError ? 'Cameras could not be read' : 'This engine has no cameras yet'"
37
+ :hint="camHint"
38
+ persistent-hint
39
+ @update:model-value="(v: string) => $emit('update:camera', v)"
40
+ />
41
+ </v-col>
42
+ </v-row>
43
+ </div>
44
+ </template>
45
+
46
+ <script setup lang="ts">
47
+ import { computed, onMounted, ref, watch } from "vue";
48
+ import { cctvNotice } from "../../utils/cctv-engine";
49
+
50
+ const props = defineProps<{ site: string; engine?: string; camera?: string; noCamera?: boolean }>();
51
+ const emit = defineEmits<{
52
+ (e: "update:engine", v: string): void;
53
+ (e: "update:camera", v: string): void;
54
+ (e: "engines", v: any[]): void;
55
+ }>();
56
+
57
+ const { listEngines, listCameras } = useCctvEngine();
58
+ const engines = ref<any[]>([]);
59
+ const cameras = ref<any[]>([]);
60
+ const loading = ref(true);
61
+ const camLoading = ref(false);
62
+ const error = ref<unknown>(null);
63
+ const camError = ref<unknown>(null);
64
+
65
+ const camHint = computed(() =>
66
+ camError.value ? cctvNotice(camError.value).body : "",
67
+ );
68
+
69
+ async function load() {
70
+ loading.value = true;
71
+ error.value = null;
72
+ try {
73
+ const res: any = await listEngines(props.site);
74
+ engines.value = res?.items ?? [];
75
+ emit("engines", engines.value);
76
+ if (!props.engine && engines.value[0]) emit("update:engine", engines.value[0]._id);
77
+ } catch (e) {
78
+ error.value = e;
79
+ } finally {
80
+ loading.value = false;
81
+ }
82
+ }
83
+
84
+ async function loadCameras() {
85
+ cameras.value = [];
86
+ camError.value = null;
87
+ if (!props.engine || props.noCamera) return;
88
+ camLoading.value = true;
89
+ try {
90
+ const res: any = await listCameras(props.engine);
91
+ cameras.value = res?.items ?? [];
92
+ if (!props.camera && cameras.value[0]) emit("update:camera", cameras.value[0].name);
93
+ } catch (e) {
94
+ camError.value = e;
95
+ } finally {
96
+ camLoading.value = false;
97
+ }
98
+ }
99
+
100
+ function pickEngine(v: string) {
101
+ emit("update:engine", v);
102
+ emit("update:camera", "");
103
+ }
104
+
105
+ onMounted(load);
106
+ watch(() => props.engine, loadCameras, { immediate: true });
107
+ </script>
@@ -0,0 +1,289 @@
1
+ <!--
2
+ Engines & health. An engine is the box at the site that analyses the cameras. Add one, install the agent with
3
+ the command shown ONCE, then watch it come Online. Per engine: cameras' frame rate, detector speed, CPU / GPU, storage.
4
+ -->
5
+ <template>
6
+ <div>
7
+ <div class="d-flex align-center flex-wrap ga-2">
8
+ <h3 class="hero-title flex-grow-1">Engines</h3>
9
+ <v-btn variant="text" prepend-icon="mdi-refresh" :loading="loading" @click="load">Refresh</v-btn>
10
+ <v-btn v-if="canEdit" color="primary" prepend-icon="mdi-plus" @click="openWizard">Add engine</v-btn>
11
+ </div>
12
+
13
+ <v-progress-linear v-if="loading && !engines.length" indeterminate />
14
+ <CctvEngineNotice v-else-if="error" :error="error" retry @retry="load" />
15
+ <CctvEngineNotice
16
+ v-else-if="!engines.length"
17
+ title="No engine added yet"
18
+ body="An engine is a small computer at the site that watches the cameras and sends events here. Press Add engine to get its install command. Nothing is open inbound at the site; it connects out to us."
19
+ />
20
+ <v-expansion-panels v-else v-model="open" variant="accordion" class="mt-2" @update:model-value="onOpen">
21
+ <v-expansion-panel v-for="e in engines" :key="e._id" :value="e._id">
22
+ <v-expansion-panel-title>
23
+ <div class="d-flex align-center flex-wrap ga-2 w-100">
24
+ <strong>{{ e.name }}</strong>
25
+ <v-chip size="small" label :color="statusView(e.status).color">{{ statusView(e.status).title }}</v-chip>
26
+ <span class="hero-muted">Last seen: {{ lastSeenText(e.lastSeenAt) }}</span>
27
+ </div>
28
+ </v-expansion-panel-title>
29
+ <v-expansion-panel-text>
30
+ <p class="hero-muted">{{ statusView(e.status).help }}</p>
31
+ <v-progress-linear v-if="health[e._id]?.loading" indeterminate />
32
+ <CctvEngineNotice v-else-if="health[e._id]?.error" :error="health[e._id].error" retry @retry="loadHealth(e._id)" />
33
+ <template v-else-if="health[e._id]?.data">
34
+ <v-row dense>
35
+ <v-col cols="6" sm="3"><div class="hero-muted">CPU</div><strong>{{ pct(health[e._id].data.cpuPercent) }}</strong></v-col>
36
+ <v-col cols="6" sm="3"><div class="hero-muted">GPU</div><strong>{{ pct(health[e._id].data.gpuPercent) }}</strong></v-col>
37
+ <v-col cols="6" sm="3"><div class="hero-muted">Detector speed</div><strong>{{ health[e._id].data.detectorMs == null ? "Not reported" : `${health[e._id].data.detectorMs} ms per picture` }}</strong></v-col>
38
+ <v-col cols="6" sm="3"><div class="hero-muted">Storage</div><strong>{{ storageText(health[e._id].data.storage) }}</strong></v-col>
39
+ </v-row>
40
+ <v-table density="compact" class="mt-3">
41
+ <thead><tr><th>Camera</th><th>Picture rate</th><th>Detection rate</th><th>State</th></tr></thead>
42
+ <tbody>
43
+ <tr v-if="!health[e._id].data.cameras.length"><td colspan="4" class="hero-muted">The engine has not reported any cameras yet. Reports come every minute while it is Online.</td></tr>
44
+ <tr v-for="c in health[e._id].data.cameras" :key="c.name">
45
+ <td>{{ c.name }}</td>
46
+ <td>{{ c.fps == null ? "Not reported" : `${c.fps} fps` }}</td>
47
+ <td>{{ c.detectFps == null ? "Not reported" : `${c.detectFps} fps` }}</td>
48
+ <td><v-chip v-if="c.online != null" size="x-small" label :color="c.online ? 'success' : 'error'">{{ c.online ? "Receiving" : "No picture" }}</v-chip></td>
49
+ </tr>
50
+ </tbody>
51
+ </v-table>
52
+ </template>
53
+ <div v-if="canEdit" class="d-flex flex-wrap ga-2 mt-4">
54
+ <v-btn size="small" variant="tonal" prepend-icon="mdi-key-change" @click="askRotate(e)">Rotate agent key</v-btn>
55
+ <v-btn size="small" variant="text" color="error" prepend-icon="mdi-delete-outline" @click="askRemove(e)">Remove engine</v-btn>
56
+ </div>
57
+ </v-expansion-panel-text>
58
+ </v-expansion-panel>
59
+ </v-expansion-panels>
60
+
61
+ <!-- Add-engine wizard -->
62
+ <v-dialog v-model="wizard" max-width="640" persistent scrollable>
63
+ <v-card>
64
+ <v-card-title>{{ step === 1 ? "Add an engine" : "Install the agent" }}</v-card-title>
65
+ <v-card-text>
66
+ <template v-if="step === 1">
67
+ <p class="hero-muted">Step 1 of 2. Give the box a name and say what it is. You can change these later.</p>
68
+ <v-text-field v-model="form.name" label="Name (e.g. Main gate box)" density="comfortable" />
69
+ <v-select v-model="form.detector" :items="DETECTORS" label="Detector" density="comfortable" hint="What does the object detection. If unsure, pick CPU." persistent-hint />
70
+ <v-text-field v-model.number="form.maxCameras" type="number" min="1" label="How many cameras can it handle" density="comfortable" class="mt-3" />
71
+ <v-textarea v-model="form.notes" label="Notes (optional)" rows="2" density="comfortable" />
72
+ <div v-if="problem" class="text-error" role="alert">{{ problem }}</div>
73
+ <CctvEngineNotice v-if="formError" class="mt-2" :error="formError" />
74
+ </template>
75
+ <template v-else>
76
+ <p class="hero-muted">Step 2 of 2. Run the command below on the box at the site. It connects out to us, so nothing needs opening on the site's firewall.</p>
77
+ <CctvEngineNotice tone="error" title="Copy this key now - it is shown only once" body="We store it scrambled and cannot show it again. If you lose it, use Rotate agent key to make a new one (the old key stops working)." />
78
+ <div class="text-subtitle-2 mt-3">Agent key</div>
79
+ <div class="cctv-en__code" data-test="agent-key">{{ issued.key }}</div>
80
+ <v-btn size="small" variant="tonal" prepend-icon="mdi-content-copy" class="mt-1" @click="copy(issued.key, 'key')">{{ copied === "key" ? "Copied" : "Copy key" }}</v-btn>
81
+ <div class="text-subtitle-2 mt-4">Install command</div>
82
+ <div class="cctv-en__code" data-test="install-command">{{ issued.command }}</div>
83
+ <v-btn size="small" variant="tonal" prepend-icon="mdi-content-copy" class="mt-1" @click="copy(issued.command, 'cmd')">{{ copied === "cmd" ? "Copied" : "Copy command" }}</v-btn>
84
+ <div v-if="copyFailed" class="hero-muted mt-1">Copy did not work in this browser - select the text above and copy it by hand.</div>
85
+ <v-checkbox v-model="saved" color="primary" hide-details class="mt-3" label="I have copied the key and saved it somewhere safe" />
86
+ <p class="hero-muted mt-2">After you run the command, the engine shows <strong>Online</strong> in the list within a minute.</p>
87
+ </template>
88
+ </v-card-text>
89
+ <v-card-actions>
90
+ <v-spacer />
91
+ <template v-if="step === 1">
92
+ <v-btn variant="text" @click="wizard = false">Cancel</v-btn>
93
+ <v-btn color="primary" :loading="saving" @click="create">Create engine</v-btn>
94
+ </template>
95
+ <v-btn v-else color="primary" :disabled="!saved" @click="closeKey">Done</v-btn>
96
+ </v-card-actions>
97
+ </v-card>
98
+ </v-dialog>
99
+
100
+ <v-dialog v-model="rotateOpen" max-width="460">
101
+ <v-card>
102
+ <v-card-title>Rotate the agent key?</v-card-title>
103
+ <v-card-text>
104
+ A new key is made and shown once. The <strong>old key stops working at once</strong>, so the engine will show Offline until you run the new install command on the box.
105
+ <CctvEngineNotice v-if="actionError" class="mt-3" :error="actionError" />
106
+ </v-card-text>
107
+ <v-card-actions>
108
+ <v-spacer />
109
+ <v-btn variant="text" @click="rotateOpen = false">Cancel</v-btn>
110
+ <v-btn color="warning" :loading="saving" @click="doRotate">Rotate key</v-btn>
111
+ </v-card-actions>
112
+ </v-card>
113
+ </v-dialog>
114
+
115
+ <v-dialog v-model="removeOpen" max-width="460">
116
+ <v-card>
117
+ <v-card-title>Remove {{ target?.name }}?</v-card-title>
118
+ <v-card-text>
119
+ The engine is disconnected and hidden. Events already saved stay. To use the box again, add it as a new engine.
120
+ <CctvEngineNotice v-if="actionError" class="mt-3" :error="actionError" />
121
+ </v-card-text>
122
+ <v-card-actions>
123
+ <v-spacer />
124
+ <v-btn variant="text" @click="removeOpen = false">Keep</v-btn>
125
+ <v-btn color="error" :loading="saving" @click="doRemove">Remove</v-btn>
126
+ </v-card-actions>
127
+ </v-card>
128
+ </v-dialog>
129
+ </div>
130
+ </template>
131
+
132
+ <script setup lang="ts">
133
+ import { computed, onBeforeUnmount, reactive, ref } from "vue";
134
+ import { CCTV_PERMISSIONS, engineStatusView, lastSeenText, summariseHealth } from "../../utils/cctv-engine";
135
+
136
+ const props = defineProps<{ site: string; access?: { can: (p: any) => boolean } }>();
137
+ const { listEngines, createEngine, rotateKey, deleteEngine, getHealth } = useCctvEngine();
138
+ const canEdit = computed(() => props.access?.can(CCTV_PERMISSIONS.manageEngine) ?? false);
139
+
140
+ const DETECTORS = [
141
+ { value: "cpu", title: "CPU (no graphics card)" },
142
+ { value: "gpu", title: "Graphics card (GPU)" },
143
+ { value: "coral", title: "Coral accelerator" },
144
+ { value: "other", title: "Something else" },
145
+ ];
146
+ const statusView = engineStatusView;
147
+ const pct = (n?: number | null) => (n == null ? "Not reported" : `${Math.round(n)}%`);
148
+ const storageText = (s?: { usedMb: number; totalMb: number } | null) =>
149
+ !s || !(s.totalMb > 0) ? "Not reported" : `${Math.round((s.usedMb / s.totalMb) * 100)}% full`;
150
+
151
+ const engines = ref<any[]>([]);
152
+ const loading = ref(false);
153
+ const error = ref<unknown>(null);
154
+ const open = ref<string | undefined>();
155
+ const health = reactive<Record<string, { loading?: boolean; error?: unknown; data?: ReturnType<typeof summariseHealth> }>>({});
156
+
157
+ async function load() {
158
+ loading.value = true;
159
+ error.value = null;
160
+ try {
161
+ const res: any = await listEngines(props.site);
162
+ engines.value = res?.items ?? [];
163
+ } catch (e) {
164
+ error.value = e;
165
+ } finally {
166
+ loading.value = false;
167
+ }
168
+ }
169
+ async function loadHealth(id: string) {
170
+ health[id] = { loading: true };
171
+ try {
172
+ const res: any = await getHealth(id);
173
+ health[id] = { data: summariseHealth(res?.stats) };
174
+ } catch (e) {
175
+ health[id] = { error: e };
176
+ }
177
+ }
178
+ const onOpen = (id: unknown) => typeof id === "string" && loadHealth(id);
179
+
180
+ // ---- add-engine wizard
181
+ const wizard = ref(false);
182
+ const step = ref(1);
183
+ const form = reactive({ name: "", detector: "cpu", maxCameras: 4, notes: "" });
184
+ const saving = ref(false);
185
+ const problem = ref("");
186
+ const formError = ref<unknown>(null);
187
+ const issued = reactive({ key: "", command: "" });
188
+ const saved = ref(false);
189
+ const copied = ref("");
190
+ const copyFailed = ref(false);
191
+
192
+ function openWizard() {
193
+ Object.assign(form, { name: "", detector: "cpu", maxCameras: 4, notes: "" });
194
+ step.value = 1;
195
+ problem.value = "";
196
+ formError.value = null;
197
+ wizard.value = true;
198
+ }
199
+ function showKey(res: any) {
200
+ issued.key = res?.agentKey ?? "";
201
+ issued.command = res?.installCommand ?? "";
202
+ saved.value = false;
203
+ copied.value = "";
204
+ copyFailed.value = false;
205
+ step.value = 2;
206
+ wizard.value = true;
207
+ }
208
+ async function create() {
209
+ if (!form.name.trim()) return void (problem.value = "Give the engine a name.");
210
+ if (!(form.maxCameras >= 1)) return void (problem.value = "Say how many cameras it can handle (1 or more).");
211
+ problem.value = "";
212
+ saving.value = true;
213
+ formError.value = null;
214
+ try {
215
+ const res: any = await createEngine({ site: props.site, name: form.name.trim(), hardware: { detector: form.detector, maxCameras: Math.round(form.maxCameras), notes: form.notes.trim() } });
216
+ showKey(res);
217
+ await load();
218
+ } catch (e) {
219
+ formError.value = e;
220
+ } finally {
221
+ saving.value = false;
222
+ }
223
+ }
224
+ async function copy(text: string, which: string) {
225
+ copyFailed.value = false;
226
+ try {
227
+ await navigator.clipboard.writeText(text);
228
+ copied.value = which;
229
+ } catch {
230
+ copyFailed.value = true;
231
+ }
232
+ }
233
+ function closeKey() {
234
+ // The key never lives past this dialog.
235
+ issued.key = issued.command = "";
236
+ wizard.value = false;
237
+ }
238
+ onBeforeUnmount(() => (issued.key = issued.command = ""));
239
+
240
+ // ---- rotate / remove
241
+ const target = ref<any>(null);
242
+ const rotateOpen = ref(false);
243
+ const removeOpen = ref(false);
244
+ const actionError = ref<unknown>(null);
245
+ function askRotate(e: any) {
246
+ target.value = e;
247
+ actionError.value = null;
248
+ rotateOpen.value = true;
249
+ }
250
+ function askRemove(e: any) {
251
+ target.value = e;
252
+ actionError.value = null;
253
+ removeOpen.value = true;
254
+ }
255
+ async function doRotate() {
256
+ saving.value = true;
257
+ actionError.value = null;
258
+ try {
259
+ const res: any = await rotateKey(target.value._id);
260
+ rotateOpen.value = false;
261
+ showKey(res);
262
+ await load();
263
+ } catch (e) {
264
+ actionError.value = e;
265
+ } finally {
266
+ saving.value = false;
267
+ }
268
+ }
269
+ async function doRemove() {
270
+ saving.value = true;
271
+ actionError.value = null;
272
+ try {
273
+ await deleteEngine(target.value._id);
274
+ removeOpen.value = false;
275
+ open.value = undefined;
276
+ await load();
277
+ } catch (e) {
278
+ actionError.value = e;
279
+ } finally {
280
+ saving.value = false;
281
+ }
282
+ }
283
+
284
+ load();
285
+ </script>
286
+
287
+ <style scoped>
288
+ .cctv-en__code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; padding: 8px 10px; border-radius: 6px; background: rgba(128, 128, 128, 0.15); word-break: break-all; user-select: all; }
289
+ </style>