@7365admin1/layer-common 4.31.0 → 4.32.1-staging.364

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 (63) hide show
  1. package/CHANGELOG.md +10 -4
  2. package/assets/css/robot-hero.css +227 -1
  3. package/components/AccessCardAddForm.vue +5 -4
  4. package/components/AccessCardAssignToUnitForm.vue +3 -2
  5. package/components/AccessCardPreviewDialog.vue +4 -3
  6. package/components/Dialog/DeleteConfirmation.vue +17 -2
  7. package/components/Dialog/ReusablePrompt.vue +26 -3
  8. package/components/Dialog/UpdateMoreAction.vue +11 -1
  9. package/components/DocumentForm.vue +407 -112
  10. package/components/DocumentManagement.vue +213 -12
  11. package/components/EntryPass/QrTemplatePreview.vue +21 -25
  12. package/components/EntryPassInformation.vue +119 -24
  13. package/components/Facility/BookingSetup.vue +63 -0
  14. package/components/HidAccessLogDashboard.vue +41 -8
  15. package/components/HidAccessPermissions.vue +424 -0
  16. package/components/HidIntercomManagement.vue +148 -14
  17. package/components/HidProfileQrCode.vue +332 -0
  18. package/components/HidReaderManagement.vue +26 -0
  19. package/components/HidReaderUserRoster.vue +44 -3
  20. package/components/HidUserEnrollment.vue +845 -155
  21. package/components/InvitationClientForm.vue +19 -1
  22. package/components/NotificationBell.vue +39 -3
  23. package/components/Robot/BuildingMap.vue +403 -0
  24. package/components/Robot/LiftQueue.vue +247 -0
  25. package/components/Robot/MapEditor.vue +233 -0
  26. package/components/Robot/PatrolRoutes.vue +3 -3
  27. package/components/Robot/SiteScreen.vue +36 -1
  28. package/components/VehicleForm.vue +45 -2
  29. package/components/VehicleManagement.vue +95 -10
  30. package/components/VisitorManagement.vue +267 -5
  31. package/composables/useAccessManagement.ts +5 -0
  32. package/composables/useCleaningPermission.ts +4 -4
  33. package/composables/useCommonPermission.ts +16 -0
  34. package/composables/useDocument.ts +7 -0
  35. package/composables/useFacility.ts +11 -0
  36. package/composables/useHidAmico.ts +117 -0
  37. package/composables/useHidNavigation.ts +25 -1
  38. package/composables/useHidReaderSelection.ts +50 -0
  39. package/composables/useLandscapingPermission.ts +4 -4
  40. package/composables/useMechanicalElectricalPermission.ts +4 -4
  41. package/composables/usePeople.ts +19 -0
  42. package/composables/usePestControlPermission.ts +4 -4
  43. package/composables/usePoolMaintenancePermission.ts +4 -4
  44. package/composables/useRobotBuilding.ts +66 -0
  45. package/composables/useSecurityPermission.ts +4 -10
  46. package/composables/useSiteCategory.ts +45 -0
  47. package/composables/useSiteEntryPassSettings.ts +26 -0
  48. package/composables/useWebUsb.ts +14 -11
  49. package/package.json +2 -2
  50. package/pages/[org]/[site]/access-mgmt/administrator/index.vue +1 -1
  51. package/pages/[org]/[site]/access-mgmt/hid-cards/index.vue +1 -1
  52. package/pages/[org]/[site]/access-mgmt/hid-qr-code/index.vue +23 -0
  53. package/pages/[org]/[site]/access-mgmt/hid-readers/index.vue +1 -1
  54. package/types/document.d.ts +14 -0
  55. package/types/facility.d.ts +4 -0
  56. package/types/people.d.ts +28 -1
  57. package/utils/hid-permission-assignments.ts +190 -0
  58. package/utils/hid-reader-selection.ts +52 -0
  59. package/utils/notification-target.ts +75 -0
  60. package/utils/occupancy-role.ts +109 -0
  61. package/utils/robot-building.ts +521 -0
  62. package/utils/robot-display.ts +29 -6
  63. package/utils/vehicle-actions.ts +12 -4
@@ -388,9 +388,27 @@ watch(
388
388
  const roles = ref<any[]>([])
389
389
  const { getRoles } = useRole()
390
390
 
391
+ /*
392
+ * `type` is the ROLE type, not the service the client subscribes to, and the
393
+ * only caller (`ClientMain.vue` "Invite Client") passes no `app` prop -- so
394
+ * this sent `type: ""` and the endpoint applied no type filter at all. The
395
+ * dropdown therefore listed every org-less role of every type, which includes
396
+ * the platform's OWN staff roles (`type: "admin"` -- the two rows the console's
397
+ * `/super-admin/role-permissions` screen edits). Offering a Seven365 console
398
+ * staff role on a CLIENT invitation is the defect.
399
+ *
400
+ * A client admin's role is `type: "organization"`, which is what the client
401
+ * roles screen (`org/[organization]/roles-permissions.vue`) already lists. This
402
+ * narrows to exactly that. It is a narrowing of this one picker only: no role
403
+ * changes, no permission changes, and the org-less `organization` roles that
404
+ * were already being picked are all still offered.
405
+ *
406
+ * Keying off the selected service instead would empty the dropdown -- no
407
+ * org-less role carries a service type -- so `props.app` is not the filter.
408
+ */
391
409
  const { data: roleData, refresh: refreshRoles } = await useLazyAsyncData(
392
410
  "roles",
393
- () => getRoles({ org: org.value?._id, type: props.app, limit: 50 }),
411
+ () => getRoles({ org: org.value?._id, type: "organization", limit: 50 }),
394
412
  { watch: [() => props.app] }
395
413
  )
396
414
 
@@ -134,6 +134,7 @@ import {
134
134
  timeAgo,
135
135
  type TInboxItem,
136
136
  } from "../utils/notification-inbox";
137
+ import { notificationTarget } from "../utils/notification-target";
137
138
 
138
139
  /**
139
140
  * The top-bar notification feed for the web, in every signed-in app.
@@ -165,6 +166,8 @@ defineProps({
165
166
 
166
167
  const { getAll, getUnreadCount, markAsRead, markAllAsRead } = useNotification();
167
168
  const { currentUser } = useLocalAuth();
169
+ const route = useRoute();
170
+ const router = useRouter();
168
171
 
169
172
  const open = ref(false);
170
173
  const loading = ref(false);
@@ -269,16 +272,49 @@ function announce(fresh: TInboxItem[]) {
269
272
  }
270
273
  }
271
274
 
275
+ /**
276
+ * Clicking a row does two separate things, and the second one is why the row is
277
+ * a button at all: mark it read, and go to what it is about.
278
+ *
279
+ * They are kept apart deliberately. Marking read is best-effort and reverts on
280
+ * failure; navigation must not wait on that round trip, and must still happen
281
+ * for a row that was ALREADY read — a person re-opening the bell to find the
282
+ * order they were told about is the ordinary case, and the old early-return on
283
+ * `hasRead` would have sent them nowhere.
284
+ */
272
285
  async function openNotification(item: Record<string, any>) {
286
+ markRead(item);
287
+ await goToSubject(item);
288
+ }
289
+
290
+ function markRead(item: Record<string, any>) {
273
291
  if (item.hasRead) return;
274
292
  // Marked locally first: waiting on a round trip to move the dot reads as a dead control.
275
293
  item.hasRead = true;
276
294
  unread.value = Math.max(0, unread.value - 1);
277
- try {
278
- await markAsRead(String(item._id), userId.value);
279
- } catch {
295
+ markAsRead(String(item._id), userId.value).catch(() => {
280
296
  item.hasRead = false;
281
297
  unread.value += 1;
298
+ });
299
+ }
300
+
301
+ /**
302
+ * `hasRoute` is the whole reason an org-app route name may live in the shared
303
+ * layer: the ten apps that have no order queue simply do not match it, and the
304
+ * click there stays what it always was.
305
+ */
306
+ async function goToSubject(item: Record<string, any>) {
307
+ const target = notificationTarget(item as any, {
308
+ organization: String(route.params?.organization ?? ""),
309
+ });
310
+ if (!target) return;
311
+ if (typeof router.hasRoute !== "function" || !router.hasRoute(target.name)) return;
312
+
313
+ open.value = false;
314
+ try {
315
+ await router.push(target);
316
+ } catch {
317
+ // A cancelled or duplicate navigation is not worth an error in the top bar.
282
318
  }
283
319
  }
284
320
 
@@ -0,0 +1,403 @@
1
+ <template>
2
+ <!--
3
+ 3D BUILDING MAP (README §4): the site's floors as stacked planes seen in
4
+ CSS 3D, robots as status-colour squares with a pin and an upright name,
5
+ patrol routes for security, the lift shafts through every floor. Drag to
6
+ rotate, shift/right/middle-drag to pan, wheel to zoom; ISO/TOP/SIDE/UNDER
7
+ presets and a floor filter. "Edit map" (set-up permitted) swaps in the
8
+ 2D editor, which saves through the building-map API.
9
+ -->
10
+ <div class="hero-head">
11
+ <div>
12
+ <button v-if="backToNetwork" type="button" class="hero-back hero-back--sm" @click="emit('network')">‹ Network</button>
13
+ <div class="hero-kicker hero-kicker--accent">{{ clientName || names.clientName }}</div>
14
+ <h2 class="hero-title">{{ siteLabel }} · building map</h2>
15
+ </div>
16
+ <span class="hero-head__spacer" />
17
+ <v-btn variant="outlined" class="hero-btn-icon" @click="fullscreen(editing ? editor?.root : viewer)">
18
+ <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><path d="M8 3H5a2 2 0 0 0-2 2v3m18 0V5a2 2 0 0 0-2-2h-3m0 18h3a2 2 0 0 0 2-2v-3M3 16v3a2 2 0 0 0 2 2h3" /></svg>
19
+ Full screen
20
+ </v-btn>
21
+ <v-btn v-if="canEditMap" :variant="editing ? 'outlined' : 'flat'" :color="editing ? undefined : 'primary'" @click="editing = !editing">
22
+ {{ editing ? "Exit edit mode" : "Edit map" }}
23
+ </v-btn>
24
+ </div>
25
+
26
+ <div v-if="error" class="hero-notice" role="alert">{{ error }}</div>
27
+ <div v-else-if="!loading && emptyNote" class="hero-notice">{{ emptyNote }}</div>
28
+
29
+ <RobotMapEditor
30
+ v-if="editing && canEditMap"
31
+ ref="editor"
32
+ :map="map"
33
+ :floors="floors"
34
+ :site-name="siteLabel"
35
+ :owner-robot-id="ownerRobotId"
36
+ :start-floor="startFloor"
37
+ @saved="onSaved"
38
+ />
39
+
40
+ <div v-else class="hero-split hero-bmap">
41
+ <div
42
+ ref="viewer"
43
+ class="hero-bmap__viewer"
44
+ :class="{ 'hero-bmap__viewer--grab': !drag, 'hero-bmap__viewer--pan': drag?.mode === 'pan', 'hero-bmap__viewer--rotate': drag?.mode === 'rotate' }"
45
+ @mousedown="onDown"
46
+ @mousemove="onMove"
47
+ @mouseup="drag = null"
48
+ @mouseleave="drag = null"
49
+ @wheel.prevent="cam = { ...cam, zoom: wheelZoom(cam.zoom, $event.deltaY) }"
50
+ @contextmenu.prevent
51
+ >
52
+ <span class="hero-plan__scan" aria-hidden="true" />
53
+
54
+ <div class="hero-bmap__zoom">
55
+ <button type="button" title="Zoom in" aria-label="Zoom in" @click="cam = { ...cam, zoom: zoomIn(cam.zoom) }">+</button>
56
+ <button type="button" title="Zoom out" aria-label="Zoom out" @click="cam = { ...cam, zoom: zoomOut(cam.zoom) }">−</button>
57
+ <button type="button" title="Reset view" aria-label="Reset view" @click="cam = resetCamera(cam)">
58
+ <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><path d="M3 12a9 9 0 1 0 3-6.7L3 8" /><path d="M3 3v5h5" /></svg>
59
+ </button>
60
+ <button
61
+ type="button"
62
+ :title="cam.orbit ? 'Stop auto-orbit' : 'Start auto-orbit'"
63
+ :aria-label="cam.orbit ? 'Stop auto-orbit' : 'Start auto-orbit'"
64
+ :aria-pressed="cam.orbit"
65
+ :class="{ 'hero-bmap__orbit--on': cam.orbit }"
66
+ @click="cam = toggleOrbit(cam)"
67
+ >
68
+ <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><ellipse cx="12" cy="12" rx="10" ry="4" /><circle cx="12" cy="12" r="2.5" fill="currentColor" /></svg>
69
+ </button>
70
+ </div>
71
+
72
+ <div class="hero-bmap__bar">
73
+ <div class="hero-bmap__seg" role="group" aria-label="View angle">
74
+ <button v-for="(a, id) in MAP_ANGLES" :key="id" type="button" :aria-pressed="cam.angle === id" @click="cam = presetCamera(cam, id)">{{ a.label }}</button>
75
+ </div>
76
+ <div class="hero-bmap__seg" role="group" aria-label="Floor">
77
+ <button type="button" :aria-pressed="focus === null" @click="focus = null">All</button>
78
+ <button v-for="f in floors" :key="f" type="button" :aria-pressed="focus === f" @click="focus = f">{{ floorName(f) }}</button>
79
+ </div>
80
+ <span class="hero-bmap__readout">{{ cameraReadout(cam) }}</span>
81
+ <span class="hero-bmap__readout">Drag to rotate · shift+drag or right-drag to pan · scroll to zoom</span>
82
+ </div>
83
+
84
+ <div class="hero-bmap__live"><span class="hero-live__dot" :class="{ 'hero-live__dot--off': !connected }" aria-hidden="true" />Live telemetry</div>
85
+
86
+ <div v-if="loading" class="hero-bmap__loading" role="status">
87
+ <span v-for="i in 3" :key="i" class="hero-skel__row" />
88
+ <span class="hero-muted">Loading the building map…</span>
89
+ </div>
90
+ <RobotReconnecting v-else-if="!connected" />
91
+
92
+ <div class="hero-bmap__view" :style="{ transform: `translate(${cam.panX}px, ${cam.panY}px) scale(${cam.zoom})`, transition: drag ? 'none' : 'transform .25s ease' }">
93
+ <div
94
+ class="hero-bmap__stack"
95
+ :style="{
96
+ '--shift': `${stack.shift}px`,
97
+ transform: `rotateX(${cam.tilt}deg) rotateZ(${cam.turn}deg) translateZ(${stack.shift}px)`,
98
+ transition: drag ? 'none' : 'transform .6s ease',
99
+ animation: orbiting ? 'heroOrbit 18s ease-in-out infinite' : 'none',
100
+ }"
101
+ >
102
+ <div
103
+ v-for="(f, i) in floors3d"
104
+ :key="f.floorNo"
105
+ class="hero-bmap__floor"
106
+ :style="{ transform: `translateZ(${i * FLOOR_GAP_PX}px)`, opacity: f.dim, '--hero-fill': look.fill }"
107
+ >
108
+ <span class="hero-bmap__room" style="left: 8%; top: 10%; width: 34%; height: 30%" aria-hidden="true" />
109
+ <span class="hero-bmap__room" style="left: 58%; top: 10%; width: 34%; height: 44%" aria-hidden="true" />
110
+ <span class="hero-bmap__room" style="left: 8%; top: 62%; width: 60%; height: 28%" aria-hidden="true" />
111
+ <template v-if="!map">
112
+ <span class="hero-bmap__door" style="left: 42%; top: 22%" aria-hidden="true" />
113
+ <span class="hero-bmap__door" style="left: 58%; top: 30%" aria-hidden="true" />
114
+ </template>
115
+ <svg v-if="f.shapes.length" class="hero-plan__svg" viewBox="0 0 100 100" preserveAspectRatio="none" aria-hidden="true">
116
+ <template v-for="s in f.shapes" :key="s.id">
117
+ <polygon v-if="s.kind === 'zone'" class="hero-bmap__zone" :points="svgPoints(s)" vector-effect="non-scaling-stroke" />
118
+ <line v-else-if="s.kind === 'wall'" class="hero-bmap__wall" :x1="s.points[0]!.x" :y1="s.points[0]!.y" :x2="s.points[1]!.x" :y2="s.points[1]!.y" vector-effect="non-scaling-stroke" />
119
+ <line v-else-if="s.kind === 'door'" class="hero-bmap__doorline" :x1="s.points[0]!.x" :y1="s.points[0]!.y" :x2="s.points[1]!.x" :y2="s.points[1]!.y" vector-effect="non-scaling-stroke" />
120
+ </template>
121
+ </svg>
122
+
123
+ <template v-if="type === 'security'">
124
+ <svg class="hero-plan__svg" viewBox="0 0 400 300" preserveAspectRatio="none" aria-hidden="true">
125
+ <path v-for="r in f.routes" :key="r.id" class="hero-plan__route hero-plan__route--anim" :d="routePathD(r.checkpoints)" vector-effect="non-scaling-stroke" />
126
+ </svg>
127
+ <div v-for="t in routeTags(f.routes)" :key="`t-${t.key}`" class="hero-bmap__anchor" :style="{ left: t.left, top: t.top }">
128
+ <div class="hero-bmap__routetag" :style="{ transform: `translateZ(30px) ${unskew}` }">{{ t.name }}</div>
129
+ </div>
130
+ <div v-for="m in routeMarks(f.routes)" :key="`m-${m.key}`" class="hero-bmap__anchor" :style="{ left: m.left, top: m.top }">
131
+ <div class="hero-bmap__cp">{{ m.n }}</div>
132
+ <div class="hero-bmap__cplabel" :style="{ transform: `translateZ(8px) ${unskew}` }">{{ m.label }}</div>
133
+ </div>
134
+ </template>
135
+
136
+ <div
137
+ v-for="r in f.robots"
138
+ :key="r.id"
139
+ class="hero-bmap__anchor hero-bmap__bot"
140
+ :style="{ left: r.left, top: r.top, transition: `left ${tickMs}ms linear, top ${tickMs}ms linear`, '--hero-bot': toneColor(r) }"
141
+ >
142
+ <span class="hero-bmap__ping" aria-hidden="true" />
143
+ <span class="hero-bmap__body" aria-hidden="true" />
144
+ <span class="hero-bmap__pin" :style="{ height: `${look.pinH}px` }" aria-hidden="true" />
145
+ <span class="hero-bmap__pin hero-bmap__pin--y" :style="{ height: `${look.pinH}px` }" aria-hidden="true" />
146
+ <button type="button" class="hero-bmap__name" :style="{ transform: `translateZ(${look.pinZ}px) ${unskew}` }" @click.stop="emit('open', r.id)" @mousedown.stop>
147
+ {{ r.name }}
148
+ </button>
149
+ </div>
150
+
151
+ <div class="hero-bmap__floorlabel" :style="{ transform: `translateZ(6px) ${unskew}` }">{{ floorName(f.floorNo) }}</div>
152
+ </div>
153
+
154
+ <div
155
+ v-for="s in shafts"
156
+ :key="s.id"
157
+ class="hero-bmap__shaft"
158
+ :style="{ left: `${s.x}%`, top: `${s.y}%`, transform: `translateZ(${s.z}px)`, opacity: look.shaftOpacity }"
159
+ >
160
+ <span class="hero-bmap__shaftwall" :style="{ width: `${s.w}px`, height: `${s.h}px` }" />
161
+ <span class="hero-bmap__shaftwall hero-bmap__shaftwall--y" :style="{ width: `${s.h}px`, height: `${s.d}px` }" />
162
+ </div>
163
+ </div>
164
+ </div>
165
+
166
+ <div class="hero-bmap__legend">
167
+ <span><i class="hero-bmap__key hero-bmap__key--door" />Door</span>
168
+ <span><i class="hero-bmap__key hero-bmap__key--shaft" />Lift shaft</span>
169
+ <span><i class="hero-bmap__key hero-bmap__key--bot" />Robot (live)</span>
170
+ <span v-if="type === 'security'"><i class="hero-bmap__key hero-bmap__key--route" />Patrol route · numbered checkpoints</span>
171
+ </div>
172
+ </div>
173
+
174
+ <aside class="hero-bmap__aside">
175
+ <div class="hero-aside__title hero-bmap__asidetitle">Floors · top down</div>
176
+ <div v-for="f in legend" :key="f.floorNo" class="hero-bmap__legendrow">
177
+ <b>{{ floorName(f.floorNo) }}</b>
178
+ <div class="hero-bmap__chips">
179
+ <button v-for="r in f.robots" :key="r.id" type="button" class="hero-bmap__chip" @click="emit('open', r.id)"><span :class="`hero-tone--${tone(r)}`">{{ r.name }}</span></button>
180
+ <span v-if="!f.robots.length" class="hero-muted">—</span>
181
+ </div>
182
+ </div>
183
+ <div v-if="unplaced.length" class="hero-bmap__tray">
184
+ <div class="hero-aside__title">Floor unknown</div>
185
+ <div class="hero-bmap__chips">
186
+ <button v-for="r in unplaced" :key="String(r._id)" type="button" class="hero-bmap__chip" @click="emit('open', String(r._id))"><span :class="`hero-tone--${unplacedTone(r)}`">{{ r.name }}</span></button>
187
+ </div>
188
+ <div class="hero-bmap__traytext">{{ unplacedLine }}</div>
189
+ </div>
190
+ </aside>
191
+ </div>
192
+ </template>
193
+
194
+ <script setup lang="ts">
195
+ import { computed, onBeforeUnmount, ref, toRef, watch } from "vue";
196
+ import RobotMapEditor from "./MapEditor.vue";
197
+ import RobotReconnecting from "./Reconnecting.vue";
198
+ import useRobotBuilding from "../../composables/useRobotBuilding";
199
+ import useRobotLive, { siteStatesFeed } from "../../composables/useRobotLive";
200
+ import {
201
+ brandName,
202
+ floorName,
203
+ mapFloors,
204
+ mapRobots,
205
+ pickFloor,
206
+ robotStatus,
207
+ routeMarks,
208
+ routePathD,
209
+ routeTags,
210
+ rowStatus,
211
+ unplacedRobots,
212
+ unplacedText,
213
+ type TMapRobot,
214
+ type TPatrolRouteView,
215
+ } from "../../utils/robot-display";
216
+ import {
217
+ buildingFloors,
218
+ cameraReadout,
219
+ defaultCamera,
220
+ dragCamera,
221
+ dragMode,
222
+ floorOpacity,
223
+ FLOOR_GAP_PX,
224
+ MAP_ANGLES,
225
+ planeLook,
226
+ presetCamera,
227
+ resetCamera,
228
+ shapeBox,
229
+ shapesFromMap,
230
+ stackMetrics,
231
+ startDrag,
232
+ toggleOrbit,
233
+ wheelZoom,
234
+ zoomIn,
235
+ zoomOut,
236
+ type TEditorShape,
237
+ type TMapCamera,
238
+ } from "../../utils/robot-building";
239
+
240
+ const props = withDefaults(
241
+ defineProps<{
242
+ organization: string;
243
+ site: string;
244
+ siteName?: string;
245
+ clientName?: string;
246
+ type?: "cleaning" | "security";
247
+ /** Edit map: set-up permitted AND allowed to change robots (the API saves on update-robot). */
248
+ canEditMap?: boolean;
249
+ backToNetwork?: boolean;
250
+ /** One telemetry tick; positions glide across it. */
251
+ tickMs?: number;
252
+ }>(),
253
+ { siteName: "", clientName: "", type: "cleaning", canEditMap: false, backToNetwork: false, tickMs: 4000 },
254
+ );
255
+ const emit = defineEmits<{
256
+ open: [id: string];
257
+ network: [];
258
+ status: [status: { connected: boolean; faults: number; siteName: string; clientName: string }];
259
+ }>();
260
+
261
+ const { rows, map, names, loading, error, reload } = useRobotBuilding(
262
+ toRef(props, "organization"),
263
+ toRef(props, "site"),
264
+ toRef(props, "type"),
265
+ );
266
+ const siteLabel = computed(() => props.siteName || names.value.siteName || "This site");
267
+
268
+ /* ---- live states + patrol routes of the robots on screen ---- */
269
+ const ids = computed(() => rows.value.map((r) => String(r._id)));
270
+ const { states, connected } = useRobotLive(ids, siteStatesFeed());
271
+ const routes = ref<Record<string, TPatrolRouteView[]>>({});
272
+ const { getPatrolRoutes, getRobotBrands } = useRobots();
273
+ watch(ids, async (list) => {
274
+ if (props.type !== "security") return void (routes.value = {});
275
+ const next: Record<string, TPatrolRouteView[]> = {};
276
+ await Promise.allSettled(list.map(async (id) => {
277
+ const res = await getPatrolRoutes(id);
278
+ if (res?.supported) next[id] = res.routes ?? [];
279
+ }));
280
+ routes.value = next;
281
+ });
282
+ const brands = ref<Array<Record<string, any>>>([]);
283
+ getRobotBrands().then((res: any) => (brands.value = res?.items ?? []), () => undefined);
284
+
285
+ /* ---- floors, features, robots per floor ---- */
286
+ const shapes = computed<TEditorShape[]>(() => shapesFromMap(map.value));
287
+ const floors = computed(() => buildingFloors(mapFloors(ids.value, states.value), map.value));
288
+ const focus = ref<number | null>(null);
289
+ watch(floors, (f) => {
290
+ if (focus.value !== null && !f.includes(focus.value)) focus.value = null;
291
+ });
292
+ const floorRoutes = (floorNo: number) => {
293
+ const seen = new Map<string, TPatrolRouteView>();
294
+ for (const id of ids.value) {
295
+ const st = states.value[id];
296
+ for (const r of routes.value[id] ?? []) {
297
+ const f = r.floorNo ?? (st?.floorKnown ? st.floorNo : null);
298
+ if (f === floorNo && !seen.has(r.id)) seen.set(r.id, r);
299
+ }
300
+ }
301
+ return [...seen.values()];
302
+ };
303
+ const floors3d = computed(() =>
304
+ floors.value.map((floorNo) => ({
305
+ floorNo,
306
+ dim: floorOpacity(cam.value.tilt, focus.value, floorNo),
307
+ shapes: shapes.value.filter((s) => s.kind !== "lift" && s.floorNo === floorNo),
308
+ routes: props.type === "security" ? floorRoutes(floorNo) : [],
309
+ robots: mapRobots(rows.value, states.value, floorNo),
310
+ })),
311
+ );
312
+ const legend = computed(() => [...floors3d.value].reverse());
313
+ /** The editor opens on the busiest floor (the handoff's "best floor"). */
314
+ const startFloor = computed(() => pickFloor(floors.value, null, ids.value, states.value));
315
+
316
+ /** Each saved lift shaft: two red walls from its lowest served floor to its highest. */
317
+ const shafts = computed(() =>
318
+ shapes.value
319
+ .filter((s) => s.kind === "lift")
320
+ .map((s) => {
321
+ const served = (s.floors ?? []).map((f) => floors.value.indexOf(f)).filter((i) => i >= 0);
322
+ const lo = served.length ? Math.min(...served) : 0;
323
+ const hi = served.length ? Math.max(...served) : floors.value.length - 1;
324
+ const b = shapeBox(s);
325
+ return { id: s.id, x: b.x, y: b.y, z: lo * FLOOR_GAP_PX, w: Math.max(12, (b.w / 100) * 400), d: Math.max(12, (b.h / 100) * 260), h: (hi - lo) * FLOOR_GAP_PX + 8 };
326
+ }),
327
+ );
328
+
329
+ const unplaced = computed(() => unplacedRobots(rows.value, states.value));
330
+ const unplacedLine = computed(() => unplacedText(unplaced.value.map((r) => brandName(r.brand, brands.value))) ?? "");
331
+
332
+ const emptyNote = computed(() => {
333
+ if (!rows.value.length) return `No ${props.type === "security" ? "security" : "cleaning"} robots at this site yet - robots appear on their floor as soon as they report one.`;
334
+ if (!map.value) return props.canEditMap ? "No building map saved yet. Edit map to draw walls, zones, doors and lift shafts on each floor." : "No building map saved yet. A manager can draw one with Edit map.";
335
+ return "";
336
+ });
337
+
338
+ /* ---- tones ---- */
339
+ const tone = (r: TMapRobot) => robotStatus(r.mode, r.type).tone;
340
+ function unplacedTone(row: Record<string, any>) {
341
+ const st = rowStatus(row, states.value[String(row._id)] ?? null);
342
+ return st.kind === "live" ? robotStatus(st.mode, row.type).tone : "error";
343
+ }
344
+ const TONE: Record<string, string> = {
345
+ success: "rgb(var(--v-theme-success))",
346
+ warning: "rgb(var(--v-theme-warning))",
347
+ info: "rgb(var(--v-theme-info))",
348
+ error: "rgb(var(--v-theme-error))",
349
+ accent: "var(--hero-accent)",
350
+ ink: "var(--hero-text)",
351
+ };
352
+ const toneColor = (r: TMapRobot) => TONE[tone(r)] ?? TONE.ink;
353
+
354
+ /* ---- camera ---- */
355
+ const cam = ref<TMapCamera>(defaultCamera());
356
+ const drag = ref<{ mode: "pan" | "rotate"; x: number; y: number; start: TMapCamera } | null>(null);
357
+ const look = computed(() => planeLook(cam.value.tilt));
358
+ const stack = computed(() => stackMetrics(floors.value.length));
359
+ const orbiting = computed(() => cam.value.orbit && cam.value.angle === "iso" && !drag.value);
360
+ /** Keeps tags and labels upright whatever the view angle. */
361
+ const unskew = computed(() => `rotateZ(${-cam.value.turn}deg) rotateX(${-cam.value.tilt}deg)`);
362
+
363
+ function onDown(e: MouseEvent) {
364
+ if ((e.target as HTMLElement).closest("button")) return;
365
+ const mode = dragMode(e);
366
+ cam.value = startDrag(cam.value, mode);
367
+ drag.value = { mode, x: e.clientX, y: e.clientY, start: cam.value };
368
+ }
369
+ function onMove(e: MouseEvent) {
370
+ const d = drag.value;
371
+ if (d) cam.value = dragCamera(d.start, d.mode, e.clientX - d.x, e.clientY - d.y);
372
+ }
373
+
374
+ const svgPoints = (s: TEditorShape) => s.points.map((p) => `${p.x},${p.y}`).join(" ");
375
+
376
+ /* ---- full screen + edit ---- */
377
+ const viewer = ref<HTMLElement | null>(null);
378
+ const editor = ref<InstanceType<typeof RobotMapEditor> | null>(null);
379
+ function fullscreen(el?: HTMLElement | null) {
380
+ if (document.fullscreenElement) document.exitFullscreen?.();
381
+ else el?.requestFullscreen?.();
382
+ }
383
+ const editing = ref(false);
384
+ watch(() => props.canEditMap, (can) => {
385
+ if (!can) editing.value = false;
386
+ });
387
+ /** The robot a first save is attached to (maps are stored per robot): one of this site's. */
388
+ const ownerRobotId = computed(() => String(map.value?.robotId ?? rows.value[0]?._id ?? ""));
389
+ function onSaved() {
390
+ reload();
391
+ }
392
+
393
+ /* ---- header status (live + faults) ---- */
394
+ watch(
395
+ [connected, () => rows.value.filter((r) => r.fault).length, () => names.value.siteName, () => names.value.clientName],
396
+ ([up, faults, siteName, clientName]) => emit("status", { connected: up, faults, siteName, clientName }),
397
+ { immediate: true },
398
+ );
399
+
400
+ onBeforeUnmount(() => {
401
+ if (document.fullscreenElement) document.exitFullscreen?.();
402
+ });
403
+ </script>