@7365admin1/layer-common 4.159.0 → 4.161.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 +16 -4
- package/components/CctvEngine/DetectionCreate.vue +260 -0
- package/components/CctvEngine/DetectionDetail.vue +266 -0
- package/components/CctvEngine/Detections.vue +135 -0
- package/components/CctvEngine/EventDetail.vue +108 -0
- package/components/CctvEngine/Events.vue +6 -84
- package/components/CctvEngine/Search.vue +177 -0
- package/components/CctvEngine/Shell.vue +3 -1
- package/composables/useCctvEngine.ts +24 -0
- package/package.json +1 -1
- package/plugins/secure-member.client.ts +15 -2
- package/utils/cctv-engine.ts +122 -1
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Smart detection: teach the engine to recognise what an area looks like (clean or rubbish, door open or shut...).
|
|
3
|
+
Lists the detections for an engine with where each one is up to; open one to sort its photos and teach it.
|
|
4
|
+
Needs the "Manage zones and smart detection" permission (cctv-engine:manage-zones).
|
|
5
|
+
-->
|
|
6
|
+
<template>
|
|
7
|
+
<div>
|
|
8
|
+
<CctvEngineCameraPicker v-model:engine="engine" :site="site" no-camera />
|
|
9
|
+
|
|
10
|
+
<template v-if="engine">
|
|
11
|
+
<template v-if="selected">
|
|
12
|
+
<CctvEngineDetectionDetail
|
|
13
|
+
:key="engine + selected"
|
|
14
|
+
:engine="engine"
|
|
15
|
+
:name="selected"
|
|
16
|
+
:teaching="teachingNames.has(selected)"
|
|
17
|
+
@back="selected = ''"
|
|
18
|
+
@changed="load(true)"
|
|
19
|
+
@taught="startTeaching(selected)"
|
|
20
|
+
@deleted="onDeleted"
|
|
21
|
+
/>
|
|
22
|
+
</template>
|
|
23
|
+
<template v-else>
|
|
24
|
+
<div class="d-flex align-center flex-wrap ga-2 mt-3">
|
|
25
|
+
<p class="hero-muted flex-grow-1 mb-0">
|
|
26
|
+
Teach the engine to tell what an area looks like, for example a bin area that is clean or full of rubbish.
|
|
27
|
+
It can raise an alert for the results you choose.
|
|
28
|
+
</p>
|
|
29
|
+
<v-btn color="primary" prepend-icon="mdi-plus" @click="creating = true">New smart detection</v-btn>
|
|
30
|
+
</div>
|
|
31
|
+
|
|
32
|
+
<v-progress-linear v-if="loading" indeterminate class="mt-3" />
|
|
33
|
+
<CctvEngineNotice v-else-if="error" class="mt-3" :error="error" retry @retry="load()" />
|
|
34
|
+
<CctvEngineNotice
|
|
35
|
+
v-else-if="!items.length"
|
|
36
|
+
class="mt-3"
|
|
37
|
+
title="No smart detections yet"
|
|
38
|
+
body="Press New smart detection, draw a box over an area on a camera, and name the results you want to tell apart."
|
|
39
|
+
/>
|
|
40
|
+
<v-row v-else class="mt-1">
|
|
41
|
+
<v-col v-for="c in items" :key="c.name" cols="12" sm="6" md="4">
|
|
42
|
+
<v-card variant="outlined" class="h-100" @click="selected = c.name">
|
|
43
|
+
<v-card-title class="text-subtitle-1">{{ c.name }}</v-card-title>
|
|
44
|
+
<v-card-text>
|
|
45
|
+
<v-chip size="small" label :color="statusOf(c).color" class="mb-2">{{ statusOf(c).title }}</v-chip>
|
|
46
|
+
<div class="hero-muted">Camera: {{ c.camera }}</div>
|
|
47
|
+
<div class="hero-muted">Results: {{ (c.states ?? []).join(", ") }}</div>
|
|
48
|
+
<div class="hero-muted">Alerts on: {{ (c.alertStates ?? []).join(", ") || "none" }}</div>
|
|
49
|
+
<div v-if="c.engineUnreachable" class="text-warning mt-1">The engine could not be reached, so this may be out of date.</div>
|
|
50
|
+
</v-card-text>
|
|
51
|
+
</v-card>
|
|
52
|
+
</v-col>
|
|
53
|
+
</v-row>
|
|
54
|
+
</template>
|
|
55
|
+
|
|
56
|
+
<CctvEngineDetectionCreate v-model="creating" :engine="engine" @created="onCreated" />
|
|
57
|
+
</template>
|
|
58
|
+
|
|
59
|
+
<v-snackbar v-model="snack.open" timeout="6000" multi-line>{{ snack.text }}</v-snackbar>
|
|
60
|
+
</div>
|
|
61
|
+
</template>
|
|
62
|
+
|
|
63
|
+
<script setup lang="ts">
|
|
64
|
+
import { onBeforeUnmount, reactive, ref, watch } from "vue";
|
|
65
|
+
import { classifierStatus, type TClassifier } from "../../utils/cctv-engine";
|
|
66
|
+
|
|
67
|
+
defineProps<{ site: string; access?: unknown }>();
|
|
68
|
+
const { listClassifiers } = useCctvEngine();
|
|
69
|
+
|
|
70
|
+
const engine = ref("");
|
|
71
|
+
const items = ref<TClassifier[]>([]);
|
|
72
|
+
const loading = ref(false);
|
|
73
|
+
const error = ref<unknown>(null);
|
|
74
|
+
const selected = ref("");
|
|
75
|
+
const creating = ref(false);
|
|
76
|
+
const snack = reactive({ open: false, text: "" });
|
|
77
|
+
|
|
78
|
+
// Teach runs on the engine in the background. Remember which were started here and check every 10 s until each
|
|
79
|
+
// one's last-trained time moves on (ponytail: only trainings started on this screen are tracked).
|
|
80
|
+
const teachingNames = ref<Set<string>>(new Set());
|
|
81
|
+
const taughtBefore = new Map<string, string | null>();
|
|
82
|
+
let timer: ReturnType<typeof setInterval> | undefined;
|
|
83
|
+
|
|
84
|
+
const statusOf = (c: TClassifier) => classifierStatus(c, { teaching: teachingNames.value.has(c.name) });
|
|
85
|
+
|
|
86
|
+
async function load(quiet = false) {
|
|
87
|
+
if (!quiet) loading.value = true;
|
|
88
|
+
error.value = null;
|
|
89
|
+
try {
|
|
90
|
+
const res: any = await listClassifiers(engine.value);
|
|
91
|
+
items.value = res?.items ?? [];
|
|
92
|
+
checkTeaching();
|
|
93
|
+
} catch (e) {
|
|
94
|
+
error.value = e;
|
|
95
|
+
if (!quiet) items.value = [];
|
|
96
|
+
} finally {
|
|
97
|
+
loading.value = false;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function startTeaching(name: string) {
|
|
102
|
+
taughtBefore.set(name, items.value.find((c) => c.name === name)?.training?.lastTrainedAt ?? null);
|
|
103
|
+
teachingNames.value = new Set(teachingNames.value).add(name);
|
|
104
|
+
clearInterval(timer);
|
|
105
|
+
timer = setInterval(() => load(true), 10000);
|
|
106
|
+
}
|
|
107
|
+
function checkTeaching() {
|
|
108
|
+
const still = new Set<string>();
|
|
109
|
+
for (const name of teachingNames.value) {
|
|
110
|
+
const c = items.value.find((x) => x.name === name);
|
|
111
|
+
if (c && (c.training?.lastTrainedAt ?? null) === taughtBefore.get(name)) still.add(name);
|
|
112
|
+
}
|
|
113
|
+
teachingNames.value = still;
|
|
114
|
+
if (!still.size) clearInterval(timer);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function onCreated(message: string) {
|
|
118
|
+
Object.assign(snack, { open: true, text: message });
|
|
119
|
+
load(true);
|
|
120
|
+
}
|
|
121
|
+
function onDeleted() {
|
|
122
|
+
Object.assign(snack, { open: true, text: "Smart detection deleted." });
|
|
123
|
+
selected.value = "";
|
|
124
|
+
load(true);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
watch(engine, () => {
|
|
128
|
+
selected.value = "";
|
|
129
|
+
items.value = [];
|
|
130
|
+
teachingNames.value = new Set();
|
|
131
|
+
clearInterval(timer);
|
|
132
|
+
if (engine.value) load();
|
|
133
|
+
});
|
|
134
|
+
onBeforeUnmount(() => clearInterval(timer));
|
|
135
|
+
</script>
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
One event in a dialog: picture, clip (when there is one), and the facts. Used by Events and Smart search.
|
|
3
|
+
Pass the event row to open it; it emits `close` when dismissed. Smart detection results have a photo and no clip.
|
|
4
|
+
-->
|
|
5
|
+
<template>
|
|
6
|
+
<v-dialog :model-value="!!event" max-width="900" scrollable @update:model-value="(v: boolean) => !v && $emit('close')">
|
|
7
|
+
<v-card v-if="event">
|
|
8
|
+
<v-card-title class="d-flex align-center">
|
|
9
|
+
<span class="flex-grow-1">{{ title }}</span>
|
|
10
|
+
<v-btn icon="mdi-close" variant="text" aria-label="Close" @click="$emit('close')" />
|
|
11
|
+
</v-card-title>
|
|
12
|
+
<v-card-text>
|
|
13
|
+
<v-progress-linear v-if="mediaLoading" indeterminate />
|
|
14
|
+
<img v-if="snapshot" :src="snapshot" :alt="`Snapshot of ${title}`" class="cctv-ev__img" />
|
|
15
|
+
<CctvEngineNotice v-else-if="!mediaLoading && event.hasSnapshot === false" title="No picture saved" body="The engine did not keep a snapshot for this event." />
|
|
16
|
+
<CctvEngineNotice v-if="mediaError" :error="mediaError" />
|
|
17
|
+
|
|
18
|
+
<template v-if="!isClassification">
|
|
19
|
+
<video v-if="clip" :src="clip" controls autoplay class="cctv-ev__img mt-3" />
|
|
20
|
+
<v-btn v-else-if="event.hasClip" class="mt-3" prepend-icon="mdi-play" :loading="clipLoading" @click="loadClip">Play clip</v-btn>
|
|
21
|
+
<div v-else class="hero-muted mt-3">No video clip was saved for this event.</div>
|
|
22
|
+
</template>
|
|
23
|
+
|
|
24
|
+
<v-table density="compact" class="mt-4">
|
|
25
|
+
<tbody>
|
|
26
|
+
<tr><th>Camera</th><td>{{ event.camera }}</td></tr>
|
|
27
|
+
<tr><th>When</th><td>{{ when(event.startTime) }}<template v-if="event.endTime"> to {{ when(event.endTime) }}</template></td></tr>
|
|
28
|
+
<template v-if="isClassification">
|
|
29
|
+
<tr><th>Result</th><td>{{ event.label }}</td></tr>
|
|
30
|
+
<tr><th>Smart detection</th><td>{{ event.subLabel }}</td></tr>
|
|
31
|
+
</template>
|
|
32
|
+
<tr v-else><th>Object</th><td>{{ event.label }}<template v-if="event.subLabel"> ({{ event.subLabel }})</template></td></tr>
|
|
33
|
+
<tr v-if="event.faceName"><th>Face</th><td>{{ event.faceName }}</td></tr>
|
|
34
|
+
<tr v-if="event.plate"><th>Plate</th><td>{{ event.plate }}</td></tr>
|
|
35
|
+
<tr v-if="!isClassification"><th>Zones</th><td>{{ (event.zones ?? []).join(", ") || "None" }}<template v-if="(event.enteredZones ?? []).length"> (entered: {{ event.enteredZones.join(" then ") }})</template></td></tr>
|
|
36
|
+
<tr><th>Confidence</th><td>{{ scoreText(event.score) }}</td></tr>
|
|
37
|
+
<tr v-if="event.incident"><th>Incident</th><td>An incident report was created for this alert.</td></tr>
|
|
38
|
+
</tbody>
|
|
39
|
+
</v-table>
|
|
40
|
+
</v-card-text>
|
|
41
|
+
</v-card>
|
|
42
|
+
</v-dialog>
|
|
43
|
+
</template>
|
|
44
|
+
|
|
45
|
+
<script setup lang="ts">
|
|
46
|
+
import { computed, onBeforeUnmount, ref, watch } from "vue";
|
|
47
|
+
import { classificationTitle } from "../../utils/cctv-engine";
|
|
48
|
+
|
|
49
|
+
const props = defineProps<{ event: any | null }>();
|
|
50
|
+
defineEmits<{ (e: "close"): void }>();
|
|
51
|
+
const { eventSnapshot, eventClip } = useCctvEngine();
|
|
52
|
+
|
|
53
|
+
const snapshot = ref("");
|
|
54
|
+
const clip = ref("");
|
|
55
|
+
const mediaLoading = ref(false);
|
|
56
|
+
const clipLoading = ref(false);
|
|
57
|
+
const mediaError = ref<unknown>(null);
|
|
58
|
+
|
|
59
|
+
const isClassification = computed(() => props.event?.kind === "classification");
|
|
60
|
+
const title = computed(() => {
|
|
61
|
+
const e = props.event;
|
|
62
|
+
if (!e) return "";
|
|
63
|
+
if (e.kind === "classification") return classificationTitle(e);
|
|
64
|
+
return [e.label, e.faceName && `- ${e.faceName}`, e.plate && `- ${e.plate}`].filter(Boolean).join(" ") || "Event";
|
|
65
|
+
});
|
|
66
|
+
const when = (v?: string) => (v ? new Date(v).toLocaleString() : "");
|
|
67
|
+
const scoreText = (s?: number) => (typeof s === "number" ? `${Math.round(s <= 1 ? s * 100 : s)}%` : "Not given");
|
|
68
|
+
|
|
69
|
+
function freeMedia() {
|
|
70
|
+
if (snapshot.value) URL.revokeObjectURL(snapshot.value);
|
|
71
|
+
if (clip.value) URL.revokeObjectURL(clip.value);
|
|
72
|
+
snapshot.value = clip.value = "";
|
|
73
|
+
mediaError.value = null;
|
|
74
|
+
}
|
|
75
|
+
async function show(e: any | null) {
|
|
76
|
+
freeMedia();
|
|
77
|
+
if (!e || e.hasSnapshot === false) return;
|
|
78
|
+
mediaLoading.value = true;
|
|
79
|
+
try {
|
|
80
|
+
const url = await eventSnapshot(e._id);
|
|
81
|
+
// The person may have closed it or opened another one while this loaded.
|
|
82
|
+
if (props.event?._id === e._id) snapshot.value = url;
|
|
83
|
+
else URL.revokeObjectURL(url);
|
|
84
|
+
} catch (err) {
|
|
85
|
+
mediaError.value = err;
|
|
86
|
+
} finally {
|
|
87
|
+
mediaLoading.value = false;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
async function loadClip() {
|
|
91
|
+
clipLoading.value = true;
|
|
92
|
+
mediaError.value = null;
|
|
93
|
+
try {
|
|
94
|
+
clip.value = await eventClip(props.event._id);
|
|
95
|
+
} catch (err) {
|
|
96
|
+
mediaError.value = err;
|
|
97
|
+
} finally {
|
|
98
|
+
clipLoading.value = false;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
watch(() => props.event, show, { immediate: true });
|
|
103
|
+
onBeforeUnmount(freeMedia);
|
|
104
|
+
</script>
|
|
105
|
+
|
|
106
|
+
<style scoped>
|
|
107
|
+
.cctv-ev__img { width: 100%; max-height: 60vh; object-fit: contain; background: #000; border-radius: 8px; }
|
|
108
|
+
</style>
|
|
@@ -39,47 +39,17 @@
|
|
|
39
39
|
<v-pagination v-if="pages > 1" v-model="page" :length="pages" :total-visible="smAndDown ? 3 : 7" class="mt-2" @update:model-value="load" />
|
|
40
40
|
<div v-if="pageRange" class="hero-muted text-center">{{ pageRange }}</div>
|
|
41
41
|
|
|
42
|
-
<
|
|
43
|
-
<v-card v-if="current">
|
|
44
|
-
<v-card-title class="d-flex align-center">
|
|
45
|
-
<span class="flex-grow-1">{{ titleOf(current) }}</span>
|
|
46
|
-
<v-btn icon="mdi-close" variant="text" aria-label="Close" @click="closeDetail" />
|
|
47
|
-
</v-card-title>
|
|
48
|
-
<v-card-text>
|
|
49
|
-
<v-progress-linear v-if="mediaLoading" indeterminate />
|
|
50
|
-
<img v-if="snapshot" :src="snapshot" :alt="`Snapshot of ${titleOf(current)}`" class="cctv-ev__img" />
|
|
51
|
-
<CctvEngineNotice v-else-if="!mediaLoading && current.hasSnapshot === false" title="No picture saved" body="The engine did not keep a snapshot for this event." />
|
|
52
|
-
<CctvEngineNotice v-if="mediaError" :error="mediaError" />
|
|
53
|
-
|
|
54
|
-
<video v-if="clip" :src="clip" controls autoplay class="cctv-ev__img mt-3" />
|
|
55
|
-
<v-btn v-else-if="current.hasClip" class="mt-3" prepend-icon="mdi-play" :loading="clipLoading" @click="loadClip">Play clip</v-btn>
|
|
56
|
-
<div v-else class="hero-muted mt-3">No video clip was saved for this event.</div>
|
|
57
|
-
|
|
58
|
-
<v-table density="compact" class="mt-4">
|
|
59
|
-
<tbody>
|
|
60
|
-
<tr><th>Camera</th><td>{{ current.camera }}</td></tr>
|
|
61
|
-
<tr><th>When</th><td>{{ when(current.startTime) }}<template v-if="current.endTime"> to {{ when(current.endTime) }}</template></td></tr>
|
|
62
|
-
<tr><th>Object</th><td>{{ current.label }}<template v-if="current.subLabel"> ({{ current.subLabel }})</template></td></tr>
|
|
63
|
-
<tr v-if="current.faceName"><th>Face</th><td>{{ current.faceName }}</td></tr>
|
|
64
|
-
<tr v-if="current.plate"><th>Plate</th><td>{{ current.plate }}</td></tr>
|
|
65
|
-
<tr><th>Zones</th><td>{{ (current.zones ?? []).join(", ") || "None" }}<template v-if="(current.enteredZones ?? []).length"> (entered: {{ current.enteredZones.join(" then ") }})</template></td></tr>
|
|
66
|
-
<tr><th>Confidence</th><td>{{ scoreText(current.score) }}</td></tr>
|
|
67
|
-
<tr v-if="current.incident"><th>Incident</th><td>An incident report was created for this alert.</td></tr>
|
|
68
|
-
</tbody>
|
|
69
|
-
</v-table>
|
|
70
|
-
</v-card-text>
|
|
71
|
-
</v-card>
|
|
72
|
-
</v-dialog>
|
|
42
|
+
<CctvEngineEventDetail :event="current" @close="current = null" />
|
|
73
43
|
</div>
|
|
74
44
|
</template>
|
|
75
45
|
|
|
76
46
|
<script setup lang="ts">
|
|
77
|
-
import { computed,
|
|
47
|
+
import { computed, reactive, ref } from "vue";
|
|
78
48
|
import { useDisplay } from "vuetify";
|
|
79
|
-
import { EVENT_KINDS, EVENT_SEVERITIES, type TEventFilters } from "../../utils/cctv-engine";
|
|
49
|
+
import { classificationTitle, EVENT_KINDS, EVENT_SEVERITIES, type TEventFilters } from "../../utils/cctv-engine";
|
|
80
50
|
|
|
81
51
|
const props = defineProps<{ site: string; access?: unknown }>();
|
|
82
|
-
const { listEvents
|
|
52
|
+
const { listEvents } = useCctvEngine();
|
|
83
53
|
const { smAndDown } = useDisplay();
|
|
84
54
|
|
|
85
55
|
const f = reactive<TEventFilters>({});
|
|
@@ -117,59 +87,11 @@ function clear() {
|
|
|
117
87
|
|
|
118
88
|
const kindTitle = (k: string) => EVENT_KINDS.find((x) => x.value === k)?.title ?? k;
|
|
119
89
|
const when = (v?: string) => (v ? new Date(v).toLocaleString() : "");
|
|
120
|
-
const
|
|
121
|
-
const titleOf = (e: any) => [e.label, e.faceName && `- ${e.faceName}`, e.plate && `- ${e.plate}`].filter(Boolean).join(" ") || "Event";
|
|
90
|
+
const titleOf = (e: any) => e.kind === "classification" ? classificationTitle(e) : [e.label, e.faceName && `- ${e.faceName}`, e.plate && `- ${e.plate}`].filter(Boolean).join(" ") || "Event";
|
|
122
91
|
const subtitleOf = (e: any) => `${e.camera} - ${when(e.startTime)}${(e.zones ?? []).length ? ` - ${e.zones.join(", ")}` : ""}`;
|
|
123
92
|
|
|
124
|
-
// ---- detail
|
|
125
|
-
const detailOpen = ref(false);
|
|
126
93
|
const current = ref<any>(null);
|
|
127
|
-
const
|
|
128
|
-
const clip = ref("");
|
|
129
|
-
const mediaLoading = ref(false);
|
|
130
|
-
const clipLoading = ref(false);
|
|
131
|
-
const mediaError = ref<unknown>(null);
|
|
132
|
-
|
|
133
|
-
function freeMedia() {
|
|
134
|
-
if (snapshot.value) URL.revokeObjectURL(snapshot.value);
|
|
135
|
-
if (clip.value) URL.revokeObjectURL(clip.value);
|
|
136
|
-
snapshot.value = clip.value = "";
|
|
137
|
-
mediaError.value = null;
|
|
138
|
-
}
|
|
139
|
-
async function open(e: any) {
|
|
140
|
-
freeMedia();
|
|
141
|
-
current.value = e;
|
|
142
|
-
detailOpen.value = true;
|
|
143
|
-
if (e.hasSnapshot === false) return;
|
|
144
|
-
mediaLoading.value = true;
|
|
145
|
-
try {
|
|
146
|
-
snapshot.value = await eventSnapshot(e._id);
|
|
147
|
-
} catch (err) {
|
|
148
|
-
mediaError.value = err;
|
|
149
|
-
} finally {
|
|
150
|
-
mediaLoading.value = false;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
async function loadClip() {
|
|
154
|
-
clipLoading.value = true;
|
|
155
|
-
mediaError.value = null;
|
|
156
|
-
try {
|
|
157
|
-
clip.value = await eventClip(current.value._id);
|
|
158
|
-
} catch (err) {
|
|
159
|
-
mediaError.value = err;
|
|
160
|
-
} finally {
|
|
161
|
-
clipLoading.value = false;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
function closeDetail() {
|
|
165
|
-
detailOpen.value = false;
|
|
166
|
-
freeMedia();
|
|
167
|
-
}
|
|
168
|
-
onBeforeUnmount(freeMedia);
|
|
94
|
+
const open = (e: any) => (current.value = e);
|
|
169
95
|
|
|
170
96
|
load();
|
|
171
97
|
</script>
|
|
172
|
-
|
|
173
|
-
<style scoped>
|
|
174
|
-
.cctv-ev__img { width: 100%; max-height: 60vh; object-fit: contain; background: #000; border-radius: 8px; }
|
|
175
|
-
</style>
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Smart search: describe what you are looking for in words ("person with a red umbrella") and the site's own
|
|
3
|
+
engine finds the best matching pictures from past events. Free; nothing leaves the site's engine.
|
|
4
|
+
Opens a result in the same detail window the Events screen uses.
|
|
5
|
+
-->
|
|
6
|
+
<template>
|
|
7
|
+
<div>
|
|
8
|
+
<CctvEngineCameraPicker v-model:engine="engine" :site="site" no-camera />
|
|
9
|
+
|
|
10
|
+
<template v-if="engine">
|
|
11
|
+
<v-form class="mt-3" @submit.prevent="run">
|
|
12
|
+
<v-row dense>
|
|
13
|
+
<v-col cols="12" md="7">
|
|
14
|
+
<v-text-field
|
|
15
|
+
v-model="text"
|
|
16
|
+
label="Describe what you are looking for"
|
|
17
|
+
placeholder="e.g. person with a red umbrella, white van, bicycle"
|
|
18
|
+
density="comfortable"
|
|
19
|
+
prepend-inner-icon="mdi-text-search"
|
|
20
|
+
clearable
|
|
21
|
+
hide-details
|
|
22
|
+
autofocus
|
|
23
|
+
/>
|
|
24
|
+
</v-col>
|
|
25
|
+
<v-col cols="8" md="3">
|
|
26
|
+
<v-select
|
|
27
|
+
v-model="camera"
|
|
28
|
+
:items="cameras"
|
|
29
|
+
item-title="name"
|
|
30
|
+
item-value="name"
|
|
31
|
+
label="Camera (optional)"
|
|
32
|
+
density="comfortable"
|
|
33
|
+
clearable
|
|
34
|
+
hide-details
|
|
35
|
+
:no-data-text="'No cameras found for this engine'"
|
|
36
|
+
/>
|
|
37
|
+
</v-col>
|
|
38
|
+
<v-col cols="4" md="2" class="d-flex align-center">
|
|
39
|
+
<v-btn type="submit" color="primary" block :loading="loading" :disabled="loading">Search</v-btn>
|
|
40
|
+
</v-col>
|
|
41
|
+
</v-row>
|
|
42
|
+
</v-form>
|
|
43
|
+
<div class="hero-muted mt-1">Free to use. The search runs on the engine at your site, so pictures stay there.</div>
|
|
44
|
+
|
|
45
|
+
<CctvEngineNotice v-if="problem" class="mt-3" tone="info" title="Check what you typed" :body="problem" />
|
|
46
|
+
<v-progress-linear v-if="loading" indeterminate class="mt-3" />
|
|
47
|
+
<CctvEngineNotice
|
|
48
|
+
v-else-if="searchOff"
|
|
49
|
+
class="mt-3"
|
|
50
|
+
tone="info"
|
|
51
|
+
title="Smart search is not switched on yet"
|
|
52
|
+
:body="searchOff"
|
|
53
|
+
/>
|
|
54
|
+
<CctvEngineNotice v-else-if="error" class="mt-3" :error="error" retry @retry="run" />
|
|
55
|
+
<CctvEngineNotice
|
|
56
|
+
v-else-if="searched && !items.length"
|
|
57
|
+
class="mt-3"
|
|
58
|
+
title="Nothing matched"
|
|
59
|
+
body="Try fewer or simpler words (for example 'van' instead of 'white delivery van'), pick a different camera, or check the engine is Online in Engines & health."
|
|
60
|
+
/>
|
|
61
|
+
<CctvEngineNotice
|
|
62
|
+
v-else-if="!searched"
|
|
63
|
+
class="mt-3"
|
|
64
|
+
title="Search the pictures your cameras have saved"
|
|
65
|
+
body="Type what you want to find, for example 'person with a red umbrella', and press Search. The best matches come first."
|
|
66
|
+
/>
|
|
67
|
+
|
|
68
|
+
<v-row v-if="items.length" class="mt-1">
|
|
69
|
+
<v-col v-for="e in items" :key="e._id" cols="6" sm="4" md="3">
|
|
70
|
+
<v-card variant="outlined" class="cctv-sr__card" @click="current = e">
|
|
71
|
+
<div class="cctv-sr__thumb">
|
|
72
|
+
<img v-if="thumbs[e._id]" :src="thumbs[e._id]" :alt="`Picture of ${e.label}`" />
|
|
73
|
+
<v-icon v-else icon="mdi-image-off-outline" size="32" />
|
|
74
|
+
</div>
|
|
75
|
+
<div class="pa-2">
|
|
76
|
+
<div class="font-weight-medium text-truncate">{{ classificationTitle(e) || "Event" }}</div>
|
|
77
|
+
<div class="hero-muted text-truncate">{{ e.camera }}</div>
|
|
78
|
+
<div class="hero-muted">{{ when(e.startTime) }}</div>
|
|
79
|
+
</div>
|
|
80
|
+
</v-card>
|
|
81
|
+
</v-col>
|
|
82
|
+
</v-row>
|
|
83
|
+
</template>
|
|
84
|
+
|
|
85
|
+
<CctvEngineEventDetail :event="current" @close="current = null" />
|
|
86
|
+
</div>
|
|
87
|
+
</template>
|
|
88
|
+
|
|
89
|
+
<script setup lang="ts">
|
|
90
|
+
import { onBeforeUnmount, ref, watch } from "vue";
|
|
91
|
+
import { buildSearchQuery, classificationTitle } from "../../utils/cctv-engine";
|
|
92
|
+
|
|
93
|
+
defineProps<{ site: string; access?: unknown }>();
|
|
94
|
+
const { listCameras, searchEvents, eventSnapshot } = useCctvEngine();
|
|
95
|
+
|
|
96
|
+
const engine = ref("");
|
|
97
|
+
const camera = ref<string | null>(null);
|
|
98
|
+
const cameras = ref<any[]>([]);
|
|
99
|
+
const text = ref("");
|
|
100
|
+
const items = ref<any[]>([]);
|
|
101
|
+
const thumbs = ref<Record<string, string>>({});
|
|
102
|
+
const loading = ref(false);
|
|
103
|
+
const searched = ref(false);
|
|
104
|
+
const problem = ref("");
|
|
105
|
+
const searchOff = ref("");
|
|
106
|
+
const error = ref<unknown>(null);
|
|
107
|
+
const current = ref<any>(null);
|
|
108
|
+
|
|
109
|
+
const when = (v?: string) => (v ? new Date(v).toLocaleString() : "");
|
|
110
|
+
|
|
111
|
+
function freeThumbs() {
|
|
112
|
+
Object.values(thumbs.value).forEach((u) => URL.revokeObjectURL(u));
|
|
113
|
+
thumbs.value = {};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
async function run() {
|
|
117
|
+
problem.value = searchOff.value = "";
|
|
118
|
+
error.value = null;
|
|
119
|
+
const q = buildSearchQuery(text.value, camera.value);
|
|
120
|
+
if (!q.ok) {
|
|
121
|
+
problem.value = q.problem;
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
loading.value = true;
|
|
125
|
+
freeThumbs();
|
|
126
|
+
try {
|
|
127
|
+
const res: any = await searchEvents(engine.value, q.query);
|
|
128
|
+
items.value = res?.items ?? [];
|
|
129
|
+
searched.value = true;
|
|
130
|
+
loadThumbs(items.value);
|
|
131
|
+
} catch (e: any) {
|
|
132
|
+
items.value = [];
|
|
133
|
+
// "Not switched on" is an answer, not a failure: show the server's own words as an info notice.
|
|
134
|
+
if (e?.data?.code === "SEARCH_OFF") searchOff.value = String(e.data.message || "Smart search is not switched on in this camera engine yet. Ask your Seven365 contact to switch it on.");
|
|
135
|
+
else error.value = e;
|
|
136
|
+
} finally {
|
|
137
|
+
loading.value = false;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Pictures need the signed-in session, so each is fetched as a blob; a failed one just shows a placeholder.
|
|
142
|
+
async function loadThumbs(rows: any[]) {
|
|
143
|
+
const shown = items.value;
|
|
144
|
+
await Promise.all(
|
|
145
|
+
rows.filter((e) => e.hasSnapshot !== false).map(async (e) => {
|
|
146
|
+
try {
|
|
147
|
+
const url = await eventSnapshot(e._id);
|
|
148
|
+
if (items.value === shown) thumbs.value = { ...thumbs.value, [e._id]: url };
|
|
149
|
+
else URL.revokeObjectURL(url);
|
|
150
|
+
} catch {
|
|
151
|
+
/* placeholder stays */
|
|
152
|
+
}
|
|
153
|
+
}),
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
watch(engine, async (id) => {
|
|
158
|
+
camera.value = null;
|
|
159
|
+
cameras.value = [];
|
|
160
|
+
items.value = [];
|
|
161
|
+
searched.value = false;
|
|
162
|
+
freeThumbs();
|
|
163
|
+
if (!id) return;
|
|
164
|
+
try {
|
|
165
|
+
cameras.value = ((await listCameras(id)) as any)?.items ?? [];
|
|
166
|
+
} catch {
|
|
167
|
+
/* the camera filter is optional; search still works */
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
onBeforeUnmount(freeThumbs);
|
|
171
|
+
</script>
|
|
172
|
+
|
|
173
|
+
<style scoped>
|
|
174
|
+
.cctv-sr__card { cursor: pointer; height: 100%; }
|
|
175
|
+
.cctv-sr__thumb { aspect-ratio: 16 / 9; background: #111; display: flex; align-items: center; justify-content: center; color: #aaa; overflow: hidden; }
|
|
176
|
+
.cctv-sr__thumb img { width: 100%; height: 100%; object-fit: cover; }
|
|
177
|
+
</style>
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
<div class="cctv-shell">
|
|
9
9
|
<h2 class="hero-title">CCTV Engine</h2>
|
|
10
10
|
<p class="hero-muted mb-3">
|
|
11
|
-
Cameras analysed by the iSecure365 engine at the site: live view, events, playback, zones, plates and alerts.
|
|
11
|
+
Cameras analysed by the iSecure365 engine at the site: live view, events, smart search, playback, zones, smart detection, plates and alerts.
|
|
12
12
|
This sits next to the CCTV wall and does not change it.
|
|
13
13
|
</p>
|
|
14
14
|
|
|
@@ -77,6 +77,8 @@ const VIEWS: Record<TCctvSection, any> = {
|
|
|
77
77
|
faces: resolveComponent("CctvEngineFaces"),
|
|
78
78
|
alerts: resolveComponent("CctvEngineAlerts"),
|
|
79
79
|
engines: resolveComponent("CctvEngineEngines"),
|
|
80
|
+
search: resolveComponent("CctvEngineSearch"),
|
|
81
|
+
detections: resolveComponent("CctvEngineDetections"),
|
|
80
82
|
};
|
|
81
83
|
const view = computed(() => VIEWS[current.value]);
|
|
82
84
|
|
|
@@ -68,6 +68,27 @@ export default function useCctvEngine() {
|
|
|
68
68
|
const eventSnapshot = (id: string) => blobUrl(`/api/cctv-events/${id}/snapshot.jpg`);
|
|
69
69
|
const eventClip = (id: string) => blobUrl(`/api/cctv-events/${id}/clip.mp4`);
|
|
70
70
|
|
|
71
|
+
// ---- smart search (same event rows as listEvents, best match first)
|
|
72
|
+
const searchEvents = (engineId: string, query: Record<string, string | number>) =>
|
|
73
|
+
api(`/api/cctv-engines/${engineId}/search`, { method: "GET", query });
|
|
74
|
+
|
|
75
|
+
// ---- smart detection (custom training). Photos are read as blobs like snapshots.
|
|
76
|
+
const cls = (engineId: string, name?: string) =>
|
|
77
|
+
`/api/cctv-engines/${engineId}/classifiers${name ? "/" + enc(name) : ""}`;
|
|
78
|
+
const listClassifiers = (engineId: string) => api(cls(engineId), { method: "GET" });
|
|
79
|
+
const createClassifier = (engineId: string, body: Record<string, any>) => api(cls(engineId), { method: "POST", body });
|
|
80
|
+
const updateClassifier = (engineId: string, name: string, body: { alertStates: string[] }) =>
|
|
81
|
+
api(cls(engineId, name), { method: "PATCH", body });
|
|
82
|
+
const deleteClassifier = (engineId: string, name: string) => api(cls(engineId, name), { method: "DELETE" });
|
|
83
|
+
const classifierPhotos = (engineId: string, name: string) => api(`${cls(engineId, name)}/photos`, { method: "GET" });
|
|
84
|
+
const classifierPhoto = (engineId: string, name: string, file: string, state?: string) =>
|
|
85
|
+
blobUrl(`${cls(engineId, name)}/photo`, state ? { file, state } : { file });
|
|
86
|
+
const sortClassifierPhoto = (engineId: string, name: string, file: string, state: string) =>
|
|
87
|
+
api(`${cls(engineId, name)}/sort`, { method: "POST", body: { file, state } });
|
|
88
|
+
const discardClassifierPhotos = (engineId: string, name: string, files: string[], state?: string) =>
|
|
89
|
+
api(`${cls(engineId, name)}/discard`, { method: "POST", body: state ? { files, state } : { files } });
|
|
90
|
+
const trainClassifier = (engineId: string, name: string) => api(`${cls(engineId, name)}/train`, { method: "POST" });
|
|
91
|
+
|
|
71
92
|
// ---- zones & wrong-way rules
|
|
72
93
|
const getZones = (engineId: string, camera: string) => api(`${cam(engineId, camera)}/zones`, { method: "GET" });
|
|
73
94
|
const saveZones = (engineId: string, camera: string, body: TZonesBody) =>
|
|
@@ -111,6 +132,9 @@ export default function useCctvEngine() {
|
|
|
111
132
|
webrtcAnswer, blobUrl, latestImage,
|
|
112
133
|
listRecordings, cameraClip, createExport, listExports, downloadExport,
|
|
113
134
|
listEvents, getEvent, eventSnapshot, eventClip,
|
|
135
|
+
searchEvents,
|
|
136
|
+
listClassifiers, createClassifier, updateClassifier, deleteClassifier, classifierPhotos, classifierPhoto,
|
|
137
|
+
sortClassifierPhoto, discardClassifierPhotos, trainClassifier,
|
|
114
138
|
getZones, saveZones, listWrongWayRules, createWrongWayRule, updateWrongWayRule, deleteWrongWayRule,
|
|
115
139
|
listPlates, createPlate, updatePlate, deletePlate,
|
|
116
140
|
listFaces, enrolFace, deleteFace,
|
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.
|
|
5
|
+
"version": "4.161.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.",
|
|
@@ -39,6 +39,19 @@ export const LOOKUP_TIMEOUT_MS = 5000;
|
|
|
39
39
|
*/
|
|
40
40
|
export const SEND_SITE = false;
|
|
41
41
|
|
|
42
|
+
/*
|
|
43
|
+
* Per app opt in, ahead of the switch above: an app that sets
|
|
44
|
+
* `runtimeConfig.public.roleFollowsSite` to true (or the env var
|
|
45
|
+
* `NUXT_PUBLIC_ROLE_FOLLOWS_SITE=true`) sends the site now, so its role follows
|
|
46
|
+
* the site while every other app keeps today's answer. Declare the key in the
|
|
47
|
+
* APP's own nuxt.config, never in this layer's, or an env var in any app's
|
|
48
|
+
* deploy could turn it on there. Absent or misspelled means off.
|
|
49
|
+
*/
|
|
50
|
+
export function roleFollowsSite(): boolean {
|
|
51
|
+
const value = useRuntimeConfig().public.roleFollowsSite;
|
|
52
|
+
return SEND_SITE || value === true || value === "true";
|
|
53
|
+
}
|
|
54
|
+
|
|
42
55
|
function bounded<T>(request: Promise<T>): Promise<T> {
|
|
43
56
|
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
44
57
|
const timeout = new Promise<never>((_, reject) => {
|
|
@@ -111,7 +124,7 @@ export default defineNuxtPlugin(() => {
|
|
|
111
124
|
// it when the answer can actually DIFFER: the first resolution, or a site
|
|
112
125
|
// change while Q16 is on. While Q16 is held a site change re-asks the same
|
|
113
126
|
// question, so the resolved role stays on screen and nothing flickers.
|
|
114
|
-
if (resolvedFor === null ||
|
|
127
|
+
if (resolvedFor === null || roleFollowsSite()) userAppRoleStatus.value = "loading";
|
|
115
128
|
inFlightKey = key;
|
|
116
129
|
inFlight = run(userId, site, staffOrg).finally(() => {
|
|
117
130
|
inFlight = null;
|
|
@@ -139,7 +152,7 @@ export default defineNuxtPlugin(() => {
|
|
|
139
152
|
// adds is Q16 itself. Sending `org` as well would change the fallback
|
|
140
153
|
// too, and that is a separate change.
|
|
141
154
|
const member = await bounded(
|
|
142
|
-
getByUserType(userId, APP, undefined,
|
|
155
|
+
getByUserType(userId, APP, undefined, roleFollowsSite() && site ? site : undefined),
|
|
143
156
|
);
|
|
144
157
|
hasMemberDocument = true;
|
|
145
158
|
id.value = member.org ?? "";
|