@7365admin1/layer-common 4.10.2 → 4.11.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,19 @@
1
1
  # @iservice365/layer-common
2
2
 
3
+ ## 4.11.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 0253a52: anpr sync vehicle list
8
+
9
+ ## 4.10.3
10
+
11
+ ### Patch Changes
12
+
13
+ - ab4fb5a: The client's module list now governs the permission gates this package spreads into the staff apps. `useAreaPermission`, `useUnitPermission`, `useAttendancePermission`, `useBulletinBoardPermission`, `useScheduleTaskPermission`, `useServiceProviderPermission`, `useEquipmentItemPermission` and `useEquipmentManagementPermission` — 43 gates — now ask the deny list immediately before their `*` short-circuit, the order `DashboardMain` already uses. The apps closed the same hole in their own gates, but these are re-exported from here and an app PR could not reach them (40 of hygiene's 47 spread-in gates, 43 of landscape's 43, 38 of M&E's 45).
14
+
15
+ Inert and fails open: no client has an enforced list, so an absent, empty or unreadable list denies nothing. `useSettingsPermission` is deliberately untouched (`site-settings` is always allowed and can never be denied), as are the schedule gates that match any `*-schedule-mgmt` string.
16
+
3
17
  ## 4.10.2
4
18
 
5
19
  ### Patch Changes
@@ -1059,11 +1073,11 @@
1059
1073
  `utils/console-tier.ts` + `composables/useConsoleTier.ts` mirror the server's
1060
1074
  own rule from two endpoints the console already calls, unprojected:
1061
1075
 
1062
- GET /api/members/user/:user/app/admin the Seven365 staff membership
1063
- GET /api/roles/id/:role that membership's role document
1076
+ GET /api/members/user/:user/app/admin the Seven365 staff membership
1077
+ GET /api/roles/id/:role that membership's role document
1064
1078
 
1065
- owner = member.type === "admin" && role.type === "admin" && role.default === true
1066
- staff = member.type === "admin" && role.type === "admin"
1079
+ owner = member.type === "admin" && role.type === "admin" && role.default === true
1080
+ staff = member.type === "admin" && role.type === "admin"
1067
1081
 
1068
1082
  `role.default` is the marker because it is the only property of a platform
1069
1083
  staff role no API caller can set - `role.controller.ts` validates create and
@@ -126,6 +126,17 @@
126
126
  density="comfortable"
127
127
  :rules="[requiredRule]"
128
128
  />
129
+
130
+ <!-- Saving writes the site's vehicles to the camera, one plate at
131
+ a time - say so, because it can take a while. -->
132
+ <v-alert
133
+ v-if="fillNotice"
134
+ class="mb-4"
135
+ variant="tonal"
136
+ density="compact"
137
+ type="info"
138
+ :text="fillNotice"
139
+ />
129
140
  </v-col>
130
141
 
131
142
  <!-- <v-col v-if="isANPR" cols="12">
@@ -205,12 +216,135 @@
205
216
  </v-col>
206
217
  </v-row>
207
218
  </v-card-actions>
219
+
220
+ <!-- Changing a camera to Exit empties its allowed list and blocklist, and
221
+ an Entry / Both / Residents camera changed to Visitors empties its
222
+ allowed list - on the camera itself. Ask before saving; the API refuses
223
+ the change without this confirmation. -->
224
+ <v-dialog v-model="confirmClear" persistent width="540">
225
+ <DialogReusablePrompt
226
+ :prompt-title="clearPromptTitle"
227
+ :message="clearPromptMessage"
228
+ confirm-label="Yes, change and clear"
229
+ confirm-button-color="red"
230
+ :loading="disable"
231
+ @close="confirmClear = false"
232
+ @proceed="save({ confirmClearCameraLists: true })"
233
+ />
234
+ </v-dialog>
235
+
236
+ <!-- A new Entry / Both / Residents / Visitors camera, or a type change
237
+ that means the camera should now hold plates it did not (Visitors or
238
+ Exit to Entry / Both / Residents, Exit to Visitors): ask first whether
239
+ to add the site's vehicles to it now. "Not now" saves the camera
240
+ only; its vehicles can be added later with Sync vehicles in the
241
+ camera list. -->
242
+ <v-dialog v-model="askAddVehicles" persistent width="540">
243
+ <v-card class="screen-modal" width="100%" :disabled="disable" :loading="disable">
244
+ <v-card-text class="screen-modal__body pa-5 my-5 px-7 text-center">
245
+ <span class="screen-card-title d-block">
246
+ Add this site's vehicles to the camera now?
247
+ </span>
248
+ <span class="d-block mt-5">{{ addVehiclesMessage }}</span>
249
+ </v-card-text>
250
+
251
+ <div class="screen-modal__footer">
252
+ <v-btn
253
+ class="screen-btn-ghost"
254
+ variant="outlined"
255
+ :disabled="disable"
256
+ @click="askAddVehicles = false"
257
+ >
258
+ Cancel
259
+ </v-btn>
260
+ <v-btn
261
+ class="text-none"
262
+ variant="outlined"
263
+ :loading="disable"
264
+ @click="saveWithoutVehicles"
265
+ >
266
+ {{ prop.mode === "edit" ? "Not now, save changes only" : "Not now, add camera only" }}
267
+ </v-btn>
268
+ <v-btn
269
+ class="text-none screen-btn-primary"
270
+ variant="flat"
271
+ :disabled="disable"
272
+ @click="addVehiclesNow"
273
+ >
274
+ Yes, add vehicles
275
+ </v-btn>
276
+ </div>
277
+ </v-card>
278
+ </v-dialog>
279
+
280
+ <!-- A new ANPR camera may already hold plates - old ones, or ones added on
281
+ the camera's own page. Ask whether to clear them before the site's
282
+ vehicles are added; keeping them is the safe default. -->
283
+ <v-dialog v-model="askClearOnAdd" persistent width="540">
284
+ <v-card class="screen-modal" width="100%" :disabled="disable" :loading="disable">
285
+ <v-card-text class="screen-modal__body pa-5 my-5 px-7 text-center">
286
+ <span class="screen-card-title d-block">
287
+ Clear this camera's plate lists first?
288
+ </span>
289
+ <span class="d-block mt-5">{{ clearOnAddMessage }}</span>
290
+ </v-card-text>
291
+
292
+ <div class="screen-modal__footer">
293
+ <v-btn
294
+ class="screen-btn-ghost"
295
+ variant="outlined"
296
+ :disabled="disable"
297
+ @click="askClearOnAdd = false"
298
+ >
299
+ Cancel
300
+ </v-btn>
301
+ <v-btn
302
+ class="text-none"
303
+ variant="outlined"
304
+ :disabled="disable"
305
+ @click="startSync(false)"
306
+ >
307
+ No, keep them
308
+ </v-btn>
309
+ <v-btn
310
+ class="text-none"
311
+ variant="flat"
312
+ color="red"
313
+ :disabled="disable"
314
+ @click="startSync(true)"
315
+ >
316
+ Yes, clear all
317
+ </v-btn>
318
+ </div>
319
+ </v-card>
320
+ </v-dialog>
321
+
322
+ <!-- Then the site's vehicles go on the camera one plate at a time, with
323
+ each plate's progress shown. A new camera is saved by Done; an edited
324
+ one has already been saved (with its new type) and is synced by id.
325
+ Closed only by Done (or Cancel, once something has gone wrong) -
326
+ never by a click outside it. -->
327
+ <v-dialog v-model="syncOpen" persistent width="960" scrollable>
328
+ <CameraPlateSyncDialog
329
+ v-if="syncOpen && syncCamera"
330
+ :site="prop.site"
331
+ :camera="syncCamera"
332
+ :camera-id="syncCameraId"
333
+ :clear-lists="syncClear"
334
+ @done="handleSyncDone"
335
+ @cancel="handleSyncCancel"
336
+ />
337
+ </v-dialog>
208
338
  </v-card>
209
339
  </template>
210
340
 
211
341
  <script setup lang="ts">
212
342
  import useSiteSettings from "../composables/useSiteSettings";
213
343
  import { cameraErrorConverter } from "../utils/data";
344
+ import {
345
+ listsClearedByDirectionChange,
346
+ listsFilledByDirectionChange,
347
+ } from "../utils/anpr-direction";
214
348
 
215
349
  const prop = defineProps({
216
350
  title: {
@@ -457,17 +591,308 @@ const hasChanges = computed(() => {
457
591
  return true;
458
592
  });
459
593
 
460
- async function submit() {
594
+ /* ---------------------- plate lists on a changed camera -------------------- */
595
+
596
+ const confirmClear = ref(false);
597
+
598
+ /** Which of the camera's plate lists this edit would empty, if any. */
599
+ const listsToClear = computed(() =>
600
+ prop.mode === "edit" && isANPR.value
601
+ ? listsClearedByDirectionChange(
602
+ prop.camera?.direction,
603
+ camera.value.direction
604
+ )
605
+ : { allow: false, block: false }
606
+ );
607
+
608
+ function directionLabel(value?: string) {
609
+ return (
610
+ anprDirectionOptions.value.find((option) => option.value === value)
611
+ ?.title ?? value ?? ""
612
+ );
613
+ }
614
+
615
+ const clearPromptTitle = computed(
616
+ () =>
617
+ `Change this camera from ${directionLabel(
618
+ prop.camera?.direction
619
+ )} to ${directionLabel(camera.value.direction)}?`
620
+ );
621
+
622
+ const clearPromptMessage = computed(() =>
623
+ listsToClear.value.block
624
+ ? "Every plate on this camera's allowed list AND its blocklist will be " +
625
+ "cleared from the camera, including plates added directly on it, " +
626
+ "because Exit cameras must not hold any. Whitelist and season pass " +
627
+ "vehicles will no longer be let in through this camera. Vehicle " +
628
+ "records and the plates on your other cameras are not affected."
629
+ : "Every plate on this camera's allowed list will be cleared from the " +
630
+ "camera, including plates added directly on it, because Visitors " +
631
+ "cameras must not hold whitelist or season pass plates. Those vehicles " +
632
+ "will no longer be let in through this camera. Blocked plates stay on " +
633
+ "it. Vehicle records and the plates on your other cameras are not " +
634
+ "affected."
635
+ );
636
+
637
+ /** Which lists saving will FILL with the site's vehicles, if any. */
638
+ /**
639
+ * An inactive camera being switched back on. Every vehicle add, edit and
640
+ * delete skips inactive cameras (they are the ones taken out of service), so
641
+ * this one missed everything done while it was off - vehicles added then are
642
+ * not on it, and vehicles deleted then are still on it. It is offered the
643
+ * same sync as a new camera.
644
+ */
645
+ const isReactivating = computed(
646
+ () =>
647
+ prop.mode === "edit" &&
648
+ prop.camera?.status === "inactive" &&
649
+ camera.value.status !== "inactive"
650
+ );
651
+
652
+ const listsToFill = computed(() => {
653
+ if (!isANPR.value || camera.value.status === "inactive") {
654
+ return { allow: false, block: false };
655
+ }
656
+ return listsFilledByDirectionChange(
657
+ prop.mode === "edit" && !isReactivating.value
658
+ ? prop.camera?.direction
659
+ : "",
660
+ camera.value.direction
661
+ );
662
+ });
663
+
664
+ /**
665
+ * Everything a camera of the chosen type holds, for the questions below: an
666
+ * edited camera is synced as a whole once its type is saved - the plates it
667
+ * already has are kept (or cleared, if the person says so) and the rest added.
668
+ */
669
+ const plateSetWords = computed(() => {
670
+ const { allow, block } = listsFilledByDirectionChange(
671
+ "",
672
+ camera.value.direction
673
+ );
674
+ return allow && block
675
+ ? "every whitelist, season pass and blocked plate at this site"
676
+ : allow
677
+ ? "every whitelist and season pass plate at this site"
678
+ : block
679
+ ? "every blocked plate at this site"
680
+ : "";
681
+ });
682
+
683
+ const fillNotice = computed(() => {
684
+ // A new camera is asked about on Submit instead - see `askAddVehicles`.
685
+ if (prop.mode !== "edit") return "";
686
+
687
+ const { allow, block } = listsToFill.value;
688
+ if (!allow && !block) return "";
689
+
690
+ if (isReactivating.value) {
691
+ return (
692
+ `This camera was inactive, so vehicles added, changed or deleted in the ` +
693
+ `meantime are not up to date on it. When you save, you will be asked ` +
694
+ `whether to bring it up to date now or later.`
695
+ );
696
+ }
697
+
698
+ return (
699
+ `As ${directionLabel(camera.value.direction)}, this camera holds ` +
700
+ `${plateSetWords.value}. When you save, you will be asked whether to ` +
701
+ `add them to this camera now or later.`
702
+ );
703
+ });
704
+
705
+ /* ------------------------- clearing a new camera -------------------------- */
706
+
707
+ const askAddVehicles = ref(false);
708
+ const askClearOnAdd = ref(false);
709
+
710
+ /** What "Add vehicles now?" is asking about, for this camera's type. */
711
+ const addVehiclesMessage = computed(
712
+ () =>
713
+ `Yes adds ${plateSetWords.value} to this camera now, one plate at a ` +
714
+ `time, and you can watch each one go on. ` +
715
+ (prop.mode === "edit"
716
+ ? `Not now saves your changes only - `
717
+ : `Not now adds the camera only - `) +
718
+ `you can add them later with Sync vehicles in the camera list.`
719
+ );
720
+
721
+ /** Yes: carry on to "clear the camera's lists first?", then the sync. */
722
+ function addVehiclesNow() {
723
+ askAddVehicles.value = false;
724
+ askClearOnAdd.value = true;
725
+ }
726
+
727
+ /** Not now: save the camera without touching the device. */
728
+ async function saveWithoutVehicles() {
729
+ if (prop.mode === "edit") {
730
+ await save({ skipPlateSync: true });
731
+ askAddVehicles.value = false;
732
+ return;
733
+ }
734
+
735
+ disable.value = true;
736
+ camera.value.guardPost = camera.value.guardPost ?? 0;
737
+
738
+ try {
739
+ const res = await addCamera({
740
+ ...camera.value,
741
+ ...addressPayload(),
742
+ skipPlateSync: true,
743
+ });
744
+ emit(
745
+ "success",
746
+ `${res?.message ?? "ANPR camera added."} Its vehicles were not added ` +
747
+ `yet - use Sync vehicles in the camera list to add them.`,
748
+ { clearedLists: [] }
749
+ );
750
+ } catch (error: any) {
751
+ emit("error", cameraErrorConverter(error, prop.type));
752
+ } finally {
753
+ disable.value = false;
754
+ askAddVehicles.value = false;
755
+ }
756
+ }
757
+
758
+ /* The plate-by-plate fill, and the save, happen in `CameraPlateSyncDialog`. */
759
+ const syncOpen = ref(false);
760
+ const syncClear = ref(false);
761
+ const syncCamera = ref<Record<string, any> | null>(null);
762
+ /** Set when syncing a camera that is already saved (an edited one). */
763
+ const syncCameraId = ref("");
764
+
765
+ /**
766
+ * Open the plate-by-plate sync. A NEW camera is saved by the sync dialog's
767
+ * Done. An EDITED camera is saved first - its new type, without filling it -
768
+ * and then synced by its id, so the plates go on one at a time with the
769
+ * person watching, exactly as for a new camera.
770
+ */
771
+ async function startSync(clear: boolean) {
772
+ camera.value.guardPost = camera.value.guardPost ?? 0;
773
+
774
+ if (prop.mode === "edit") {
775
+ const saved = await save({ skipPlateSync: true, emitSuccess: false });
776
+ if (!saved) return;
777
+ syncCameraId.value = String(camera.value._id ?? "");
778
+ } else {
779
+ syncCameraId.value = "";
780
+ }
781
+
782
+ syncCamera.value = { ...camera.value, ...addressPayload() };
783
+ syncClear.value = clear;
784
+ askClearOnAdd.value = false;
785
+ syncOpen.value = true;
786
+ }
787
+
788
+ function handleSyncDone(
789
+ message: string,
790
+ detail: { clearedLists?: string[]; addedPlates?: Record<string, number> }
791
+ ) {
792
+ syncOpen.value = false;
793
+ emit(
794
+ "success",
795
+ prop.mode === "edit" ? `The camera was updated. ${message}` : message,
796
+ detail
797
+ );
798
+ }
799
+
800
+ /**
801
+ * Cancel, offered only once something went wrong. A new camera was not
802
+ * saved, so the form is simply back. An edited camera already carries its new
803
+ * type, so say so and close.
804
+ */
805
+ function handleSyncCancel() {
806
+ syncOpen.value = false;
807
+ if (prop.mode !== "edit") return;
808
+ emit(
809
+ "success",
810
+ `The camera was updated, but its vehicles were not all added - use ` +
811
+ `Sync vehicles in the camera list to add them.`,
812
+ { clearedLists: [] }
813
+ );
814
+ }
815
+
816
+ /** A new, active ANPR camera: the device is written to, so ask first. */
817
+ const isNewActiveAnpr = computed(
818
+ () =>
819
+ prop.mode !== "edit" &&
820
+ isANPR.value &&
821
+ camera.value.status !== "inactive"
822
+ );
823
+
824
+ const clearOnAddMessage = computed(() => {
825
+ const what = plateSetWords.value;
826
+
827
+ return (
828
+ (isReactivating.value
829
+ ? `This camera was inactive, so it may still hold plates of vehicles ` +
830
+ `deleted or blocked in the meantime - Yes is recommended. `
831
+ : "") +
832
+ `Yes removes every plate already saved on this camera's allowed list and ` +
833
+ `blocklist - old plates and plates added directly on the camera. No ` +
834
+ `leaves them on the camera.` +
835
+ (what
836
+ ? ` Either way, ${what} is then added to it, one plate at a time, and ` +
837
+ `you can watch each one go on.`
838
+ : ` Exit cameras receive no vehicle plates.`)
839
+ );
840
+ });
841
+
842
+ function submit() {
843
+ if (listsToClear.value.allow || listsToClear.value.block) {
844
+ confirmClear.value = true;
845
+ return;
846
+ }
847
+
848
+ // A new camera that receives plates, or a type change that means the
849
+ // camera should now hold plates it did not: ask whether to add them now.
850
+ if (listsToFill.value.allow || listsToFill.value.block) {
851
+ askAddVehicles.value = true;
852
+ return;
853
+ }
854
+
855
+ // A new Exit camera receives none, so only the clear question applies.
856
+ if (isNewActiveAnpr.value) {
857
+ askClearOnAdd.value = true;
858
+ return;
859
+ }
860
+
861
+ return save();
862
+ }
863
+
864
+ /**
865
+ * Save the form. Returns whether it saved. `skipPlateSync` saves a type change
866
+ * without filling the camera (the vehicles are added by the sync dialog, or
867
+ * later); `emitSuccess: false` leaves the form open for that sync dialog.
868
+ */
869
+ async function save(
870
+ options: {
871
+ confirmClearCameraLists?: boolean;
872
+ skipPlateSync?: boolean;
873
+ emitSuccess?: boolean;
874
+ } = {}
875
+ ): Promise<boolean> {
876
+ const emitSuccess = options.emitSuccess !== false;
461
877
  disable.value = true;
462
878
  camera.value.guardPost = camera.value.guardPost ?? 0;
463
879
 
464
880
  try {
465
881
  if (prop.mode === "add") {
466
- await addCamera({ ...camera.value, ...addressPayload() });
882
+ const res = await addCamera({ ...camera.value, ...addressPayload() });
883
+
884
+ // Says what was cleared and written on the new camera.
885
+ if (res?.addedPlates || res?.clearedLists) {
886
+ emit("success", res?.message ?? "", {
887
+ clearedLists: res?.clearedLists ?? [],
888
+ addedPlates: res?.addedPlates,
889
+ });
890
+ return true;
891
+ }
467
892
  }
468
893
 
469
894
  if (prop.mode === "edit") {
470
- await updateSiteCamera(camera.value._id ?? "", {
895
+ const res = await updateSiteCamera(camera.value._id ?? "", {
471
896
  ...addressPayload(),
472
897
  username: camera.value.username,
473
898
  password: camera.value.password,
@@ -476,14 +901,46 @@ async function submit() {
476
901
  direction: camera.value.direction,
477
902
  status: camera.value.status,
478
903
  name: camera.value.name,
904
+ ...(options.confirmClearCameraLists
905
+ ? { confirmClearCameraLists: true }
906
+ : {}),
907
+ ...(options.skipPlateSync ? { skipPlateSync: true } : {}),
479
908
  });
909
+
910
+ // The sync dialog carries on from here and reports when it is done.
911
+ if (!emitSuccess) return true;
912
+
913
+ // Not now: the type is saved, the vehicles are not on the camera yet.
914
+ if (options.skipPlateSync) {
915
+ emit(
916
+ "success",
917
+ `${res?.message ?? "Camera updated."} Its vehicles were not added ` +
918
+ `yet - use Sync vehicles in the camera list to add them.`,
919
+ { clearedLists: [] }
920
+ );
921
+ return true;
922
+ }
923
+
924
+ // Says which lists were cleared on the camera, or how many plates were
925
+ // written to it, so the list can show it.
926
+ if (options.confirmClearCameraLists || res?.addedPlates) {
927
+ emit("success", res?.message ?? "", {
928
+ clearedLists: res?.clearedLists ?? [],
929
+ addedPlates: res?.addedPlates,
930
+ });
931
+ return true;
932
+ }
480
933
  }
481
934
 
482
935
  emit("success", `${prop.title} added successfully!`);
936
+ return true;
483
937
  } catch (error: any) {
484
938
  emit("error", cameraErrorConverter(error, prop.type));
939
+ return false;
485
940
  } finally {
486
941
  disable.value = false;
942
+ confirmClear.value = false;
943
+ askClearOnAdd.value = false;
487
944
  }
488
945
  }
489
946
 
@@ -207,6 +207,14 @@
207
207
  </v-list-item-title>
208
208
  </v-list-item>
209
209
 
210
+ <!-- Add the site's vehicles to a camera that was added
211
+ without them, or put its plates back. -->
212
+ <v-list-item v-if="canSyncVehicles" @click="openSyncVehicles()">
213
+ <v-list-item-title class="text-subtitle-2">
214
+ Sync vehicles
215
+ </v-list-item-title>
216
+ </v-list-item>
217
+
210
218
  <v-list-item @click="openDialogDelete()" class="text-red">
211
219
  <v-list-item-title class="text-subtitle-2">
212
220
  Delete
@@ -227,6 +235,53 @@
227
235
  style="z-index: 3000"
228
236
  />
229
237
 
238
+ <!-- Sync vehicles, step 1: clear the camera's lists first, or keep them. -->
239
+ <v-dialog v-model="dialogSyncAsk" persistent width="540">
240
+ <v-card class="screen-modal" width="100%">
241
+ <v-card-text class="screen-modal__body pa-5 my-5 px-7 text-center">
242
+ <span class="screen-card-title d-block">
243
+ Clear this camera's plate lists first?
244
+ </span>
245
+ <span class="d-block mt-5">{{ syncAskMessage }}</span>
246
+ </v-card-text>
247
+
248
+ <div class="screen-modal__footer">
249
+ <v-btn
250
+ class="screen-btn-ghost"
251
+ variant="outlined"
252
+ @click="dialogSyncAsk = false"
253
+ >
254
+ Cancel
255
+ </v-btn>
256
+ <v-btn class="text-none" variant="outlined" @click="startSyncVehicles(false)">
257
+ No, keep them
258
+ </v-btn>
259
+ <v-btn
260
+ class="text-none"
261
+ variant="flat"
262
+ color="red"
263
+ @click="startSyncVehicles(true)"
264
+ >
265
+ Yes, clear all
266
+ </v-btn>
267
+ </div>
268
+ </v-card>
269
+ </v-dialog>
270
+
271
+ <!-- Sync vehicles, step 2: plate by plate, with progress. Closed only by
272
+ Done (or Cancel, once something has gone wrong). -->
273
+ <v-dialog v-model="dialogSync" persistent width="960" scrollable>
274
+ <CameraPlateSyncDialog
275
+ v-if="dialogSync"
276
+ :site="prop.site"
277
+ :camera="camera"
278
+ :camera-id="camera._id ?? ''"
279
+ :clear-lists="syncClear"
280
+ @done="handleSyncDone"
281
+ @cancel="dialogSync = false"
282
+ />
283
+ </v-dialog>
284
+
230
285
  <v-dialog v-model="dialogDelete" persistent width="540">
231
286
  <v-card width="100%">
232
287
  <v-card-text
@@ -277,6 +332,10 @@
277
332
  import type { PropType } from "vue";
278
333
  import useSiteSettings from "../composables/useSiteSettings";
279
334
  import { cameraErrorConverter } from "../utils/data";
335
+ import {
336
+ isAllowCameraDirection,
337
+ isBlockCameraDirection,
338
+ } from "../utils/anpr-direction";
280
339
 
281
340
  const events = defineEmits(["update:value", "row-click"]);
282
341
 
@@ -483,7 +542,17 @@ function handleError(msg: string) {
483
542
  showMessage(msg, "error");
484
543
  }
485
544
 
486
- function handleSuccess() {
545
+ function handleSuccess(
546
+ msg?: string,
547
+ detail?: {
548
+ clearedLists?: string[];
549
+ addedPlates?: Record<string, number>;
550
+ }
551
+ ) {
552
+ // Only a save that cleared a camera's plate lists, or wrote the site's
553
+ // vehicles to it, reports back - say so, so the person knows it happened.
554
+ if (detail && msg) showMessage(msg, "success");
555
+
487
556
  if (dialogAdd.value) dialogAdd.value = false;
488
557
 
489
558
  if (dialogEdit.value) dialogEdit.value = false;
@@ -525,6 +594,54 @@ function handleRowClick(_: any, data: any) {
525
594
  camera.value = JSON.parse(JSON.stringify(data.item));
526
595
  }
527
596
 
597
+ /* ------------------------------ Sync vehicles ----------------------------- */
598
+
599
+ const dialogSyncAsk = ref(false);
600
+ const dialogSync = ref(false);
601
+ const syncClear = ref(false);
602
+
603
+ /** An active ANPR camera of a type that receives plates (not Exit). */
604
+ const canSyncVehicles = computed(
605
+ () =>
606
+ camera.value.type === "anpr" &&
607
+ camera.value.status !== "inactive" &&
608
+ Boolean(camera.value._id) &&
609
+ isBlockCameraDirection(camera.value.direction)
610
+ );
611
+
612
+ const syncAskMessage = computed(() => {
613
+ const what = isAllowCameraDirection(camera.value.direction)
614
+ ? "every whitelist, season pass and blocked plate at this site"
615
+ : "every blocked plate at this site";
616
+ return (
617
+ `The site's vehicles - ${what} - are added to this camera one plate at ` +
618
+ `a time. Yes first removes every plate on its allowed list and ` +
619
+ `blocklist, including plates added directly on the camera; until a ` +
620
+ `vehicle's plate is back on, that vehicle is not let in through this ` +
621
+ `camera. No keeps what is on the camera and adds only the plates it is ` +
622
+ `missing.`
623
+ );
624
+ });
625
+
626
+ function openSyncVehicles() {
627
+ dialogPreview.value = false;
628
+ dialogSyncAsk.value = true;
629
+ }
630
+
631
+ function startSyncVehicles(clear: boolean) {
632
+ syncClear.value = clear;
633
+ dialogSyncAsk.value = false;
634
+ dialogSync.value = true;
635
+ }
636
+
637
+ function handleSyncDone(
638
+ msg: string,
639
+ detail: { clearedLists?: string[]; addedPlates?: Record<string, number> }
640
+ ) {
641
+ dialogSync.value = false;
642
+ handleSuccess(msg, detail);
643
+ }
644
+
528
645
  async function submitDelete() {
529
646
  try {
530
647
  await deleteSiteCameraById(camera.value._id ?? "");