@7365admin1/layer-common 4.10.3 → 4.11.1-staging.313
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 +10 -4
- package/components/CameraForm.vue +460 -3
- package/components/CameraMain.vue +118 -1
- package/components/CameraPlateSyncDialog.vue +626 -0
- package/components/DocumentForm.vue +407 -112
- package/components/DocumentManagement.vue +213 -12
- package/components/EntryPass/QrTemplatePreview.vue +21 -25
- package/components/Facility/BookingSetup.vue +63 -0
- package/components/HidIntercomManagement.vue +193 -43
- package/components/HidProfileQrCode.vue +323 -0
- package/components/HidReaderUserRoster.vue +32 -2
- package/components/HidUserEnrollment.vue +771 -212
- package/components/InvitationClientForm.vue +19 -1
- package/components/Layout/Header.vue +26 -0
- package/components/NotificationBell.vue +321 -0
- package/components/VehicleForm.vue +11 -3
- package/components/VisitorManagement.vue +267 -5
- package/composables/useDocument.ts +7 -0
- package/composables/useFacility.ts +11 -0
- package/composables/useHidAmico.ts +97 -0
- package/composables/useHidNavigation.ts +25 -1
- package/composables/useNotification.ts +78 -0
- package/composables/usePeople.ts +19 -0
- package/composables/useSiteSettings.ts +114 -2
- package/composables/useWebUsb.ts +14 -11
- package/package.json +1 -1
- package/pages/[org]/[site]/access-mgmt/hid-qr-code/index.vue +23 -0
- package/types/document.d.ts +14 -0
- package/types/facility.d.ts +4 -0
- package/types/people.d.ts +4 -1
- package/utils/anpr-direction.ts +70 -0
- package/utils/camera-plate-sync.ts +141 -0
- package/utils/materialSymbols.ts +3 -0
|
@@ -0,0 +1,626 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<v-card width="100%" class="screen-modal">
|
|
3
|
+
<!-- The camera's TYPE is the headline - it decides which plates go on -
|
|
4
|
+
with the camera's name and address underneath. -->
|
|
5
|
+
<v-card-title class="d-flex align-center flex-wrap ga-2">
|
|
6
|
+
<span>{{ isSavedCamera ? "Sync vehicles to" : "Add vehicles to" }}</span>
|
|
7
|
+
<v-chip
|
|
8
|
+
color="primary"
|
|
9
|
+
variant="flat"
|
|
10
|
+
label
|
|
11
|
+
prepend-icon="mdi-cctv"
|
|
12
|
+
class="font-weight-bold plate-sync__type"
|
|
13
|
+
>
|
|
14
|
+
{{ cameraTypeLabel }} camera
|
|
15
|
+
</v-chip>
|
|
16
|
+
</v-card-title>
|
|
17
|
+
|
|
18
|
+
<div class="px-6 pb-2 text-body-1">
|
|
19
|
+
<span v-if="prop.camera.name" class="font-weight-medium">
|
|
20
|
+
{{ prop.camera.name }}
|
|
21
|
+
</span>
|
|
22
|
+
<span v-if="prop.camera.name && prop.camera.host" class="mx-1">·</span>
|
|
23
|
+
<span class="text-medium-emphasis">{{ prop.camera.host }}</span>
|
|
24
|
+
</div>
|
|
25
|
+
|
|
26
|
+
<v-card-text class="screen-modal__body pa-5">
|
|
27
|
+
<!-- 1. Clearing the camera first, when the person chose to. -->
|
|
28
|
+
<v-alert
|
|
29
|
+
v-if="clearLists"
|
|
30
|
+
class="mb-4"
|
|
31
|
+
variant="tonal"
|
|
32
|
+
density="compact"
|
|
33
|
+
:type="clearAlertType"
|
|
34
|
+
>
|
|
35
|
+
<div class="d-flex align-center flex-wrap ga-2">
|
|
36
|
+
<v-progress-circular
|
|
37
|
+
v-if="clearState === 'clearing'"
|
|
38
|
+
indeterminate
|
|
39
|
+
size="16"
|
|
40
|
+
width="2"
|
|
41
|
+
/>
|
|
42
|
+
<span class="flex-grow-1">{{ clearText }}</span>
|
|
43
|
+
</div>
|
|
44
|
+
</v-alert>
|
|
45
|
+
|
|
46
|
+
<!-- 2. The counts, kept apart for the allowed list and the blocklist. -->
|
|
47
|
+
<div v-if="rowsLoaded" class="mb-2">
|
|
48
|
+
<div
|
|
49
|
+
v-for="group in countGroups"
|
|
50
|
+
:key="group.key"
|
|
51
|
+
class="d-flex align-center flex-wrap ga-2 mb-1"
|
|
52
|
+
>
|
|
53
|
+
<span class="text-body-2 font-weight-medium plate-sync__label">
|
|
54
|
+
{{ group.label }}
|
|
55
|
+
</span>
|
|
56
|
+
<v-chip size="small" variant="tonal" color="success">
|
|
57
|
+
Added {{ group.counts.added }}
|
|
58
|
+
</v-chip>
|
|
59
|
+
<v-chip size="small" variant="tonal" color="error">
|
|
60
|
+
Failed {{ group.counts.failed }}
|
|
61
|
+
</v-chip>
|
|
62
|
+
<v-chip size="small" variant="tonal">
|
|
63
|
+
Pending {{ group.counts.pending }}
|
|
64
|
+
</v-chip>
|
|
65
|
+
<span class="text-caption text-medium-emphasis ml-auto">
|
|
66
|
+
{{ group.counts.total }} plate(s)
|
|
67
|
+
</span>
|
|
68
|
+
</div>
|
|
69
|
+
</div>
|
|
70
|
+
|
|
71
|
+
<v-progress-linear
|
|
72
|
+
v-if="rowsLoaded && counts.total"
|
|
73
|
+
class="mb-4"
|
|
74
|
+
:model-value="progress"
|
|
75
|
+
:color="counts.failed ? 'warning' : 'success'"
|
|
76
|
+
height="6"
|
|
77
|
+
rounded
|
|
78
|
+
/>
|
|
79
|
+
|
|
80
|
+
<v-alert
|
|
81
|
+
v-if="loadError"
|
|
82
|
+
class="mb-4"
|
|
83
|
+
type="error"
|
|
84
|
+
variant="tonal"
|
|
85
|
+
density="compact"
|
|
86
|
+
:text="loadError"
|
|
87
|
+
/>
|
|
88
|
+
|
|
89
|
+
<v-alert
|
|
90
|
+
v-if="stopMessage"
|
|
91
|
+
class="mb-4"
|
|
92
|
+
type="warning"
|
|
93
|
+
variant="tonal"
|
|
94
|
+
density="compact"
|
|
95
|
+
:text="stopMessage"
|
|
96
|
+
/>
|
|
97
|
+
|
|
98
|
+
<!-- 3. Every plate, with its own progress. -->
|
|
99
|
+
<v-data-table
|
|
100
|
+
v-if="rowsLoaded && rows.length"
|
|
101
|
+
:headers="headers"
|
|
102
|
+
:items="rows"
|
|
103
|
+
item-value="id"
|
|
104
|
+
density="compact"
|
|
105
|
+
fixed-header
|
|
106
|
+
hide-default-footer
|
|
107
|
+
:items-per-page="-1"
|
|
108
|
+
height="380"
|
|
109
|
+
>
|
|
110
|
+
<template #item.plateNumber="{ item }">
|
|
111
|
+
<span class="font-weight-medium">{{ item.plateNumber }}</span>
|
|
112
|
+
<v-chip
|
|
113
|
+
v-if="item.list === 'blocked'"
|
|
114
|
+
class="ml-1"
|
|
115
|
+
size="x-small"
|
|
116
|
+
color="error"
|
|
117
|
+
variant="tonal"
|
|
118
|
+
>
|
|
119
|
+
Blocked
|
|
120
|
+
</v-chip>
|
|
121
|
+
<v-chip
|
|
122
|
+
v-else-if="item.kind === 'Season pass'"
|
|
123
|
+
class="ml-1"
|
|
124
|
+
size="x-small"
|
|
125
|
+
variant="tonal"
|
|
126
|
+
>
|
|
127
|
+
Season pass
|
|
128
|
+
</v-chip>
|
|
129
|
+
</template>
|
|
130
|
+
|
|
131
|
+
<template #item.status="{ item }">
|
|
132
|
+
<div class="d-flex align-center ga-1">
|
|
133
|
+
<v-chip
|
|
134
|
+
size="small"
|
|
135
|
+
variant="tonal"
|
|
136
|
+
:color="statusColour(item.status)"
|
|
137
|
+
>
|
|
138
|
+
<v-progress-circular
|
|
139
|
+
v-if="item.status === 'adding'"
|
|
140
|
+
class="mr-1"
|
|
141
|
+
indeterminate
|
|
142
|
+
size="12"
|
|
143
|
+
width="2"
|
|
144
|
+
/>
|
|
145
|
+
{{ statusLabel(item.status) }}
|
|
146
|
+
</v-chip>
|
|
147
|
+
|
|
148
|
+
<v-tooltip v-if="item.status === 'failed' && item.error" location="top">
|
|
149
|
+
<template #activator="{ props: tip }">
|
|
150
|
+
<v-icon v-bind="tip" size="small" color="error">
|
|
151
|
+
mdi-information-outline
|
|
152
|
+
</v-icon>
|
|
153
|
+
</template>
|
|
154
|
+
{{ item.error }}
|
|
155
|
+
</v-tooltip>
|
|
156
|
+
|
|
157
|
+
<v-btn
|
|
158
|
+
v-if="item.status === 'failed'"
|
|
159
|
+
size="x-small"
|
|
160
|
+
variant="text"
|
|
161
|
+
class="text-none"
|
|
162
|
+
prepend-icon="mdi-refresh"
|
|
163
|
+
:disabled="busy"
|
|
164
|
+
@click="retryRow(item)"
|
|
165
|
+
>
|
|
166
|
+
Retry
|
|
167
|
+
</v-btn>
|
|
168
|
+
</div>
|
|
169
|
+
</template>
|
|
170
|
+
</v-data-table>
|
|
171
|
+
|
|
172
|
+
<p
|
|
173
|
+
v-else-if="rowsLoaded"
|
|
174
|
+
class="text-body-2 text-medium-emphasis my-4"
|
|
175
|
+
>
|
|
176
|
+
There are no vehicle plates to add to this camera.
|
|
177
|
+
</p>
|
|
178
|
+
|
|
179
|
+
<div v-else-if="!loadError && clearState !== 'failed'" class="d-flex justify-center my-8">
|
|
180
|
+
<v-progress-circular indeterminate />
|
|
181
|
+
</div>
|
|
182
|
+
|
|
183
|
+
<!-- 4. What Done will do, when not everything is on the camera. -->
|
|
184
|
+
<v-alert
|
|
185
|
+
v-if="rowsLoaded && !busy && (counts.failed || counts.pending)"
|
|
186
|
+
class="mt-4"
|
|
187
|
+
type="info"
|
|
188
|
+
variant="tonal"
|
|
189
|
+
density="compact"
|
|
190
|
+
:text="missingText"
|
|
191
|
+
/>
|
|
192
|
+
|
|
193
|
+
<v-alert
|
|
194
|
+
v-if="saveError"
|
|
195
|
+
class="mt-4"
|
|
196
|
+
type="error"
|
|
197
|
+
variant="tonal"
|
|
198
|
+
density="compact"
|
|
199
|
+
:text="saveError"
|
|
200
|
+
/>
|
|
201
|
+
</v-card-text>
|
|
202
|
+
|
|
203
|
+
<v-card-actions class="screen-modal__footer">
|
|
204
|
+
<div class="d-flex flex-wrap justify-end ga-2 w-100">
|
|
205
|
+
<!-- Only offered once something has gone wrong: this modal is
|
|
206
|
+
otherwise closed by Done, which adds the camera. -->
|
|
207
|
+
<v-btn
|
|
208
|
+
v-if="canCancel"
|
|
209
|
+
variant="outlined"
|
|
210
|
+
class="text-none screen-btn-ghost"
|
|
211
|
+
:disabled="busy"
|
|
212
|
+
@click="emit('cancel')"
|
|
213
|
+
text="Cancel"
|
|
214
|
+
/>
|
|
215
|
+
|
|
216
|
+
<v-btn
|
|
217
|
+
v-if="running"
|
|
218
|
+
variant="outlined"
|
|
219
|
+
class="text-none"
|
|
220
|
+
:disabled="stopRequested"
|
|
221
|
+
@click="stopRequested = true"
|
|
222
|
+
:text="stopRequested ? 'Stopping…' : 'Stop'"
|
|
223
|
+
/>
|
|
224
|
+
|
|
225
|
+
<v-btn
|
|
226
|
+
v-else-if="canRetry"
|
|
227
|
+
variant="outlined"
|
|
228
|
+
class="text-none"
|
|
229
|
+
prepend-icon="mdi-refresh"
|
|
230
|
+
:disabled="busy"
|
|
231
|
+
@click="start"
|
|
232
|
+
:text="retryLabel"
|
|
233
|
+
/>
|
|
234
|
+
|
|
235
|
+
<v-btn
|
|
236
|
+
variant="flat"
|
|
237
|
+
class="text-none screen-btn-primary"
|
|
238
|
+
:disabled="!canFinish"
|
|
239
|
+
:loading="saving"
|
|
240
|
+
@click="done"
|
|
241
|
+
text="Done"
|
|
242
|
+
/>
|
|
243
|
+
</div>
|
|
244
|
+
</v-card-actions>
|
|
245
|
+
</v-card>
|
|
246
|
+
</template>
|
|
247
|
+
|
|
248
|
+
<script setup lang="ts">
|
|
249
|
+
import useSiteSettings from "../composables/useSiteSettings";
|
|
250
|
+
import { cameraErrorConverter, errorConverter } from "../utils/data";
|
|
251
|
+
import {
|
|
252
|
+
plateSyncCounts,
|
|
253
|
+
plateSyncCountsByList,
|
|
254
|
+
rowsToRetry,
|
|
255
|
+
runPlateQueue,
|
|
256
|
+
type PlateSyncRow,
|
|
257
|
+
type PlateSyncStatus,
|
|
258
|
+
} from "../utils/camera-plate-sync";
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Adding a new ANPR camera, with the site's vehicles written to it one plate at
|
|
262
|
+
* a time while the person watches.
|
|
263
|
+
*
|
|
264
|
+
* 1. If they chose to, the camera's allowed list and blocklist are cleared.
|
|
265
|
+
* 2. Every plate the camera receives is listed (blocked plates first), and
|
|
266
|
+
* written one per request: pending, adding, added or failed - a failed one
|
|
267
|
+
* can be retried on its own, and Retry carries on with every failed and
|
|
268
|
+
* pending plate. The run stops by itself on a login refusal or after a few
|
|
269
|
+
* failures in a row (see `utils/camera-plate-sync.ts`).
|
|
270
|
+
* 3. **Done** saves the camera - without touching the device again - and
|
|
271
|
+
* closes. If saving fails the error is shown, and Cancel appears.
|
|
272
|
+
*
|
|
273
|
+
* The camera is NOT saved until Done: nothing here creates a record. Plates
|
|
274
|
+
* already written stay on the camera if the person cancels.
|
|
275
|
+
*
|
|
276
|
+
* With `cameraId` it syncs a camera that is ALREADY saved instead ("Sync
|
|
277
|
+
* vehicles" in the camera list): the same steps through the camera's own
|
|
278
|
+
* routes - the server uses its stored login - and Done simply closes.
|
|
279
|
+
*/
|
|
280
|
+
|
|
281
|
+
const prop = defineProps({
|
|
282
|
+
site: {
|
|
283
|
+
type: String,
|
|
284
|
+
required: true,
|
|
285
|
+
},
|
|
286
|
+
/** The camera exactly as the form would save it. */
|
|
287
|
+
camera: {
|
|
288
|
+
type: Object as PropType<Record<string, any>>,
|
|
289
|
+
required: true,
|
|
290
|
+
},
|
|
291
|
+
/** The person's answer to "clear this camera's plate lists first?". */
|
|
292
|
+
clearLists: {
|
|
293
|
+
type: Boolean,
|
|
294
|
+
default: false,
|
|
295
|
+
},
|
|
296
|
+
/** A camera that is already saved: sync it rather than add it. */
|
|
297
|
+
cameraId: {
|
|
298
|
+
type: String,
|
|
299
|
+
default: "",
|
|
300
|
+
},
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
const emit = defineEmits(["done", "cancel"]);
|
|
304
|
+
|
|
305
|
+
const {
|
|
306
|
+
getNewCameraPlates,
|
|
307
|
+
clearNewCamera,
|
|
308
|
+
addNewCameraPlate,
|
|
309
|
+
addCamera,
|
|
310
|
+
getCameraPlates,
|
|
311
|
+
clearCamera,
|
|
312
|
+
addCameraPlate,
|
|
313
|
+
} = useSiteSettings();
|
|
314
|
+
|
|
315
|
+
const isSavedCamera = computed(() => Boolean(prop.cameraId));
|
|
316
|
+
|
|
317
|
+
const headers = [
|
|
318
|
+
{ title: "Name", key: "name" },
|
|
319
|
+
{ title: "Block", key: "block" },
|
|
320
|
+
{ title: "Level", key: "level" },
|
|
321
|
+
{ title: "Unit", key: "unit" },
|
|
322
|
+
{ title: "Vehicle No.", key: "plateNumber" },
|
|
323
|
+
{ title: "Status", key: "status", width: 190 },
|
|
324
|
+
];
|
|
325
|
+
|
|
326
|
+
/** Login and address of the camera, as the new-camera API takes them. */
|
|
327
|
+
const device = computed(() => ({
|
|
328
|
+
host: String(prop.camera.host ?? ""),
|
|
329
|
+
username: String(prop.camera.username ?? ""),
|
|
330
|
+
password: String(prop.camera.password ?? ""),
|
|
331
|
+
name: String(prop.camera.name ?? ""),
|
|
332
|
+
direction: String(prop.camera.direction ?? ""),
|
|
333
|
+
}));
|
|
334
|
+
|
|
335
|
+
const cameraName = computed(
|
|
336
|
+
() => prop.camera.name || prop.camera.host || "the camera"
|
|
337
|
+
);
|
|
338
|
+
|
|
339
|
+
/** The camera's type as the camera form names it. */
|
|
340
|
+
const CAMERA_TYPE_LABELS: Record<string, string> = {
|
|
341
|
+
entry: "Entry",
|
|
342
|
+
exit: "Exit",
|
|
343
|
+
both: "Both Entry and Exit",
|
|
344
|
+
visitors: "Visitors",
|
|
345
|
+
residents: "Residents",
|
|
346
|
+
};
|
|
347
|
+
|
|
348
|
+
const cameraTypeLabel = computed(() => {
|
|
349
|
+
const direction = String(prop.camera.direction ?? "").trim().toLowerCase();
|
|
350
|
+
return CAMERA_TYPE_LABELS[direction] ?? (direction || "Unknown");
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
const clearState = ref<"idle" | "clearing" | "cleared" | "failed">("idle");
|
|
354
|
+
const clearError = ref("");
|
|
355
|
+
const rows = ref<PlateSyncRow[]>([]);
|
|
356
|
+
const rowsLoaded = ref(false);
|
|
357
|
+
const loadError = ref("");
|
|
358
|
+
const running = ref(false);
|
|
359
|
+
const stopRequested = ref(false);
|
|
360
|
+
const stopMessage = ref("");
|
|
361
|
+
const saving = ref(false);
|
|
362
|
+
const saveError = ref("");
|
|
363
|
+
|
|
364
|
+
const counts = computed(() => plateSyncCounts(rows.value));
|
|
365
|
+
|
|
366
|
+
const countsByList = computed(() => plateSyncCountsByList(rows.value));
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* One row of counts per list the camera receives. A Visitors camera takes
|
|
370
|
+
* blocked plates only, so it shows the blocklist row alone.
|
|
371
|
+
*/
|
|
372
|
+
const countGroups = computed(() =>
|
|
373
|
+
[
|
|
374
|
+
{
|
|
375
|
+
key: "allowed",
|
|
376
|
+
label: "Allowed list",
|
|
377
|
+
counts: countsByList.value.allowed,
|
|
378
|
+
},
|
|
379
|
+
{ key: "blocked", label: "Blocklist", counts: countsByList.value.blocked },
|
|
380
|
+
].filter((group) => group.counts.total > 0)
|
|
381
|
+
);
|
|
382
|
+
|
|
383
|
+
/** "2 on the allowed list and 1 on the blocklist", leaving out a list with none. */
|
|
384
|
+
function perListPhrase(
|
|
385
|
+
pick: (counts: { failed: number; pending: number; added: number }) => number
|
|
386
|
+
) {
|
|
387
|
+
const parts: string[] = [];
|
|
388
|
+
const allowed = pick(countsByList.value.allowed);
|
|
389
|
+
const blocked = pick(countsByList.value.blocked);
|
|
390
|
+
if (allowed) parts.push(`${allowed} on the allowed list`);
|
|
391
|
+
if (blocked) parts.push(`${blocked} on the blocklist`);
|
|
392
|
+
return parts.join(" and ");
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
const missingText = computed(
|
|
396
|
+
() =>
|
|
397
|
+
`${counts.value.failed + counts.value.pending} plate(s) are not on the ` +
|
|
398
|
+
`camera (${perListPhrase((c) => c.failed + c.pending)}). Retry them, or ` +
|
|
399
|
+
(isSavedCamera.value
|
|
400
|
+
? `press Done to close - you can sync this camera again later.`
|
|
401
|
+
: `press Done to add the camera without them.`)
|
|
402
|
+
);
|
|
403
|
+
|
|
404
|
+
const progress = computed(() =>
|
|
405
|
+
counts.value.total
|
|
406
|
+
? ((counts.value.added + counts.value.failed) / counts.value.total) * 100
|
|
407
|
+
: 0
|
|
408
|
+
);
|
|
409
|
+
|
|
410
|
+
const busy = computed(
|
|
411
|
+
() => running.value || saving.value || clearState.value === "clearing"
|
|
412
|
+
);
|
|
413
|
+
|
|
414
|
+
const clearAlertType = computed(() =>
|
|
415
|
+
clearState.value === "failed"
|
|
416
|
+
? "error"
|
|
417
|
+
: clearState.value === "cleared"
|
|
418
|
+
? "success"
|
|
419
|
+
: "info"
|
|
420
|
+
);
|
|
421
|
+
|
|
422
|
+
const clearText = computed(() => {
|
|
423
|
+
if (clearState.value === "clearing") {
|
|
424
|
+
return "Clearing the camera's allowed list and blocklist…";
|
|
425
|
+
}
|
|
426
|
+
if (clearState.value === "cleared") {
|
|
427
|
+
return "The camera's allowed list and blocklist were cleared.";
|
|
428
|
+
}
|
|
429
|
+
if (clearState.value === "failed") return clearError.value;
|
|
430
|
+
return "The camera's allowed list and blocklist will be cleared first.";
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
/** Done: only once the list is in, nothing is running, and clearing worked. */
|
|
434
|
+
const canFinish = computed(
|
|
435
|
+
() =>
|
|
436
|
+
rowsLoaded.value &&
|
|
437
|
+
!busy.value &&
|
|
438
|
+
(!prop.clearLists || clearState.value === "cleared")
|
|
439
|
+
);
|
|
440
|
+
|
|
441
|
+
const canRetry = computed(
|
|
442
|
+
() =>
|
|
443
|
+
!busy.value &&
|
|
444
|
+
(clearState.value === "failed" ||
|
|
445
|
+
Boolean(loadError.value) ||
|
|
446
|
+
counts.value.failed > 0 ||
|
|
447
|
+
counts.value.pending > 0)
|
|
448
|
+
);
|
|
449
|
+
|
|
450
|
+
const retryLabel = computed(() => {
|
|
451
|
+
if (clearState.value === "failed") return "Retry clearing";
|
|
452
|
+
if (loadError.value) return "Retry";
|
|
453
|
+
const left = counts.value.failed + counts.value.pending;
|
|
454
|
+
return `Retry ${left} plate(s)`;
|
|
455
|
+
});
|
|
456
|
+
|
|
457
|
+
/** Cancel is offered only once something has gone wrong. */
|
|
458
|
+
const canCancel = computed(
|
|
459
|
+
() =>
|
|
460
|
+
Boolean(saveError.value) ||
|
|
461
|
+
Boolean(loadError.value) ||
|
|
462
|
+
clearState.value === "failed"
|
|
463
|
+
);
|
|
464
|
+
|
|
465
|
+
function statusLabel(status: PlateSyncStatus) {
|
|
466
|
+
if (status === "adding") return "Adding…";
|
|
467
|
+
if (status === "added") return "Added";
|
|
468
|
+
if (status === "failed") return "Failed";
|
|
469
|
+
return "Pending";
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
function statusColour(status: PlateSyncStatus) {
|
|
473
|
+
if (status === "added") return "success";
|
|
474
|
+
if (status === "failed") return "error";
|
|
475
|
+
if (status === "adding") return "info";
|
|
476
|
+
return undefined;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
async function write(row: PlateSyncRow) {
|
|
480
|
+
const plate = {
|
|
481
|
+
vehicle: row.vehicle,
|
|
482
|
+
list: row.list,
|
|
483
|
+
// Kept what was on the camera: look first, so nothing gets two copies.
|
|
484
|
+
onlyIfMissing: !prop.clearLists,
|
|
485
|
+
};
|
|
486
|
+
try {
|
|
487
|
+
return isSavedCamera.value
|
|
488
|
+
? await addCameraPlate(prop.cameraId, plate)
|
|
489
|
+
: await addNewCameraPlate(prop.site, device.value, plate);
|
|
490
|
+
} catch (error: any) {
|
|
491
|
+
return { ok: false, reason: errorConverter(error) };
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
async function run(targets: PlateSyncRow[]) {
|
|
496
|
+
if (!targets.length) return;
|
|
497
|
+
|
|
498
|
+
running.value = true;
|
|
499
|
+
stopRequested.value = false;
|
|
500
|
+
stopMessage.value = "";
|
|
501
|
+
|
|
502
|
+
try {
|
|
503
|
+
const result = await runPlateQueue(targets, write, {
|
|
504
|
+
shouldStop: () => stopRequested.value,
|
|
505
|
+
});
|
|
506
|
+
stopMessage.value = result.message;
|
|
507
|
+
} finally {
|
|
508
|
+
running.value = false;
|
|
509
|
+
stopRequested.value = false;
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* Clear (if chosen and not done yet), load the list (if not loaded yet), then
|
|
515
|
+
* write every failed and pending plate. Retry calls this again, so it carries
|
|
516
|
+
* on from wherever it stopped.
|
|
517
|
+
*/
|
|
518
|
+
async function start() {
|
|
519
|
+
saveError.value = "";
|
|
520
|
+
|
|
521
|
+
if (prop.clearLists && clearState.value !== "cleared") {
|
|
522
|
+
clearState.value = "clearing";
|
|
523
|
+
clearError.value = "";
|
|
524
|
+
try {
|
|
525
|
+
if (isSavedCamera.value) await clearCamera(prop.cameraId);
|
|
526
|
+
else await clearNewCamera(prop.site, device.value);
|
|
527
|
+
clearState.value = "cleared";
|
|
528
|
+
} catch (error: any) {
|
|
529
|
+
clearState.value = "failed";
|
|
530
|
+
clearError.value = errorConverter(error);
|
|
531
|
+
return;
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
if (!rowsLoaded.value) {
|
|
536
|
+
loadError.value = "";
|
|
537
|
+
try {
|
|
538
|
+
const response = isSavedCamera.value
|
|
539
|
+
? await getCameraPlates(prop.cameraId)
|
|
540
|
+
: await getNewCameraPlates(prop.site, {
|
|
541
|
+
host: device.value.host,
|
|
542
|
+
direction: device.value.direction,
|
|
543
|
+
});
|
|
544
|
+
rows.value = (response?.items ?? []).map((item: any) => ({
|
|
545
|
+
...item,
|
|
546
|
+
status: "pending" as PlateSyncStatus,
|
|
547
|
+
error: "",
|
|
548
|
+
}));
|
|
549
|
+
rowsLoaded.value = true;
|
|
550
|
+
} catch (error: any) {
|
|
551
|
+
loadError.value = errorConverter(error);
|
|
552
|
+
return;
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
await run(rowsToRetry(rows.value));
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
function retryRow(row: PlateSyncRow) {
|
|
560
|
+
if (busy.value) return;
|
|
561
|
+
return run([row]);
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
/**
|
|
565
|
+
* Save the camera - the device has already been filled, so do not do it
|
|
566
|
+
* again. A saved camera being synced has nothing to save: Done just reports.
|
|
567
|
+
*/
|
|
568
|
+
async function done() {
|
|
569
|
+
saving.value = true;
|
|
570
|
+
saveError.value = "";
|
|
571
|
+
|
|
572
|
+
try {
|
|
573
|
+
const res = isSavedCamera.value
|
|
574
|
+
? { message: `Vehicles synced to ${cameraName.value}.` }
|
|
575
|
+
: await addCamera({
|
|
576
|
+
...(prop.camera as any),
|
|
577
|
+
skipPlateSync: true,
|
|
578
|
+
});
|
|
579
|
+
|
|
580
|
+
const { added, failed, pending } = counts.value;
|
|
581
|
+
const { allowed, blocked } = countsByList.value;
|
|
582
|
+
const missing = failed + pending;
|
|
583
|
+
const addedWhere = perListPhrase((c) => c.added);
|
|
584
|
+
const missingWhere = perListPhrase((c) => c.failed + c.pending);
|
|
585
|
+
const note =
|
|
586
|
+
(prop.clearLists ? " The camera's plate lists were cleared" : "") +
|
|
587
|
+
(prop.clearLists ? ` and ${added}` : ` ${added}`) +
|
|
588
|
+
` plate(s) were added to it` +
|
|
589
|
+
(addedWhere ? ` (${addedWhere})` : "") +
|
|
590
|
+
(missing ? `; ${missing} could not be added (${missingWhere}).` : ".");
|
|
591
|
+
|
|
592
|
+
emit("done", `${res?.message ?? "ANPR camera added."}${note}`, {
|
|
593
|
+
clearedLists: prop.clearLists ? ["allowed", "blocked"] : [],
|
|
594
|
+
addedPlates: {
|
|
595
|
+
added,
|
|
596
|
+
failed,
|
|
597
|
+
pending,
|
|
598
|
+
allowedAdded: allowed.added,
|
|
599
|
+
allowedFailed: allowed.failed,
|
|
600
|
+
allowedPending: allowed.pending,
|
|
601
|
+
blockedAdded: blocked.added,
|
|
602
|
+
blockedFailed: blocked.failed,
|
|
603
|
+
blockedPending: blocked.pending,
|
|
604
|
+
},
|
|
605
|
+
});
|
|
606
|
+
} catch (error: any) {
|
|
607
|
+
saveError.value = cameraErrorConverter(error, "anpr");
|
|
608
|
+
} finally {
|
|
609
|
+
saving.value = false;
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
onMounted(start);
|
|
614
|
+
</script>
|
|
615
|
+
|
|
616
|
+
<style scoped>
|
|
617
|
+
/* The camera type in the title: big enough to notice at a glance. */
|
|
618
|
+
.plate-sync__type {
|
|
619
|
+
font-size: 1rem;
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
/* Lines the two rows of counts up under each other. */
|
|
623
|
+
.plate-sync__label {
|
|
624
|
+
min-width: 6.5rem;
|
|
625
|
+
}
|
|
626
|
+
</style>
|