@7365admin1/layer-common 4.8.1 → 4.9.1-staging.306

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.
Files changed (32) hide show
  1. package/CHANGELOG.md +29 -4
  2. package/components/CameraForm.vue +460 -3
  3. package/components/CameraMain.vue +118 -1
  4. package/components/CameraPlateSyncDialog.vue +626 -0
  5. package/components/EntryPass/QrTemplatePreview.vue +21 -25
  6. package/components/Facility/BookingSetup.vue +63 -0
  7. package/components/HidIntercomManagement.vue +193 -43
  8. package/components/HidProfileQrCode.vue +323 -0
  9. package/components/HidReaderUserRoster.vue +32 -2
  10. package/components/HidUserEnrollment.vue +771 -212
  11. package/components/InvitationClientForm.vue +19 -1
  12. package/components/VehicleForm.vue +11 -3
  13. package/components/VisitorManagement.vue +267 -5
  14. package/composables/useFacility.ts +11 -0
  15. package/composables/useHidAmico.ts +97 -0
  16. package/composables/useHidNavigation.ts +25 -1
  17. package/composables/useMechanicalElectricalPermission.ts +5 -1
  18. package/composables/usePeople.ts +19 -0
  19. package/composables/usePestControlPermission.ts +39 -0
  20. package/composables/usePoolMaintenancePermission.ts +39 -0
  21. package/composables/usePropertyPermission.ts +9 -0
  22. package/composables/useSecurityPermission.ts +118 -0
  23. package/composables/useSiteSettings.ts +114 -2
  24. package/composables/useWebUsb.ts +14 -11
  25. package/constants/permissions.ts +5 -0
  26. package/package.json +1 -1
  27. package/pages/[org]/[site]/access-mgmt/hid-qr-code/index.vue +23 -0
  28. package/types/facility.d.ts +4 -0
  29. package/types/people.d.ts +4 -1
  30. package/utils/anpr-direction.ts +70 -0
  31. package/utils/camera-plate-sync.ts +141 -0
  32. package/utils/materialSymbols.ts +3 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,30 @@
1
1
  # @iservice365/layer-common
2
2
 
3
+ ## 4.9.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 0769803: Offer the module permissions no role editor could grant yet (owner answers Q5,
8
+ Q9 and Q10). Catalogue-only: role editors offer more, no gate changes, and
9
+ nobody is granted anything.
10
+
11
+ - `useMechanicalElectricalPermission`, `usePestControlPermission` and
12
+ `usePoolMaintenancePermission` now offer `emergency-contact` with the seven
13
+ actions Cleaning and Landscape already offer (`see-all`, `see-details`,
14
+ `add-/update-/delete-emergency-contact`,
15
+ `add-/delete-emergency-contact-category`).
16
+ - `useSecurityPermission` now offers `emergency-contact` (the same seven),
17
+ `facility-booking-mgmt` (Property's five actions),
18
+ `passes-and-keys-mgmt:see-all-passes-and-keys`,
19
+ `resident-transactions:see-all-resident-transactions`,
20
+ `nfc-patrol:see-all-nfc-patrol`, `incident-reports:review-incident-report`,
21
+ and two new strings: `nfc-patrol:start-nfc-patrol` and `cctv-mgmt:see-all-cctv`.
22
+ - `usePropertyPermission` now offers `cctv-mgmt:see-all-cctv`.
23
+ - `constants/permissions.ts` records the two new strings as canonical.
24
+ - Bulletin was already offered by all five fleet catalogues as `bulletin-board`;
25
+ unchanged.
26
+ - Module counts: Security 30, Property 33, Pest 17, Pool 17, M&E 16.
27
+
3
28
  ## 4.8.1
4
29
 
5
30
  ### Patch Changes
@@ -1006,11 +1031,11 @@
1006
1031
  `utils/console-tier.ts` + `composables/useConsoleTier.ts` mirror the server's
1007
1032
  own rule from two endpoints the console already calls, unprojected:
1008
1033
 
1009
- GET /api/members/user/:user/app/admin the Seven365 staff membership
1010
- GET /api/roles/id/:role that membership's role document
1034
+ GET /api/members/user/:user/app/admin the Seven365 staff membership
1035
+ GET /api/roles/id/:role that membership's role document
1011
1036
 
1012
- owner = member.type === "admin" && role.type === "admin" && role.default === true
1013
- staff = member.type === "admin" && role.type === "admin"
1037
+ owner = member.type === "admin" && role.type === "admin" && role.default === true
1038
+ staff = member.type === "admin" && role.type === "admin"
1014
1039
 
1015
1040
  `role.default` is the marker because it is the only property of a platform
1016
1041
  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