@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
@@ -0,0 +1,247 @@
1
+ <template>
2
+ <!--
3
+ LIFT QUEUE (README §5): one card per lift on the site's building map -
4
+ header "Lift 1 · 1 riding · 2 waiting" and the car's status, an animated
5
+ shaft (floor rails, waiting robots blinking at their floor, the car moving
6
+ between floors with its doors), and the rows: n · robot · from → to ·
7
+ wait · state. Read from the lift-sessions API every 3 s; the car is
8
+ SIMULATED until a lift driver exists (said on the card).
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">{{ kicker }}</div>
14
+ <h2 class="hero-title">Lift queue</h2>
15
+ </div>
16
+ </div>
17
+
18
+ <div v-if="error" class="hero-notice" role="alert">{{ error }}</div>
19
+ <div v-else-if="!connected" class="hero-notice" role="status">Reconnecting… the lift queue shows its last reading.</div>
20
+
21
+ <div v-if="loading && !cards.length" class="hero-lifts" role="status" aria-label="Loading the lift queue">
22
+ <div v-for="i in 2" :key="i" class="hero-lift hero-lift--skel"><span class="hero-skel__row" /><span class="hero-skel__row" /><span class="hero-skel__row" /></div>
23
+ </div>
24
+ <div v-else-if="!cards.length && !error && connected" class="hero-notice hero-notice--panel">
25
+ <div class="hero-notice__title">No lifts on this building map yet.</div>
26
+ <div class="hero-notice__body">
27
+ {{ canEditMap ? "Add a lift shaft on Building map → Edit map; robots that change floors queue here." : "A manager adds lift shafts on the building map; robots that change floors queue here." }}
28
+ </div>
29
+ </div>
30
+
31
+ <div v-else class="hero-lifts">
32
+ <div v-for="l in cards" :key="l.name" class="hero-lift">
33
+ <div class="hero-lift__head">
34
+ <span class="hero-lift__name">{{ l.name }}</span>
35
+ <span class="hero-lift__sub">{{ l.sub }}</span>
36
+ <span class="hero-lift__car"><span class="hero-lift__cardot" :class="[`hero-lift__cardot--${l.carTone}`, { 'hero-lift__cardot--blink': l.riding }]" aria-hidden="true" />{{ l.carText }}</span>
37
+ </div>
38
+
39
+ <div class="hero-lift__shaft" :style="{ height: `${l.shaftH}px` }" :title="l.simulated ? 'Simulated lift - no real lift is controlled yet' : undefined">
40
+ <div class="hero-lift__labels">
41
+ <div v-for="f in l.rails" :key="f.floorNo" class="hero-lift__floor" :class="{ 'hero-lift__floor--lit': f.lit }" :style="{ top: `${f.top}px` }">
42
+ <span class="hero-lift__floorname">{{ f.name }}</span>
43
+ <span v-for="w in f.waiting" :key="w" class="hero-lift__waiting" :title="w" />
44
+ </div>
45
+ </div>
46
+ <div class="hero-lift__well">
47
+ <div v-for="f in l.rails" :key="f.floorNo" class="hero-lift__rail" :style="{ top: `${f.top}px` }" />
48
+ <div class="hero-lift__flow" :style="{ opacity: l.riding ? 1 : 0 }" />
49
+ <div
50
+ class="hero-lift__carbox"
51
+ :class="`hero-lift__carbox--${l.carTone}`"
52
+ :style="{ height: `${l.carH}px`, top: `${l.fromTop}px`, '--from': `${l.fromTop}px`, '--to': `${l.toTop}px`, animation: l.riding ? 'heroLift 6s ease-in-out infinite alternate' : 'none' }"
53
+ >
54
+ <span class="hero-lift__carlabel">{{ l.carLabel }}</span>
55
+ <div class="hero-lift__doors" :style="{ animation: l.riding ? 'heroDoors 6s ease-in-out infinite' : 'none' }" />
56
+ </div>
57
+ </div>
58
+ </div>
59
+
60
+ <div class="hero-lift__rows">
61
+ <div v-if="l.empty" class="hero-lift__empty">No robots using this lift.</div>
62
+ <div v-else class="hero-lift__list">
63
+ <div
64
+ v-for="q in l.rows"
65
+ :key="q.key"
66
+ class="hero-lift-row hero-lift-row--click"
67
+ :class="{ 'hero-lift-row--act': canCommand }"
68
+ role="button"
69
+ tabindex="0"
70
+ @click="q.robotId && emit('open', q.robotId)"
71
+ @keydown.enter="q.robotId && emit('open', q.robotId)"
72
+ >
73
+ <span class="hero-lift-row__n">{{ q.n }}</span>
74
+ <div class="hero-lift-row__who"><b>{{ q.robot }}</b><span class="hero-lift-row__route"> · {{ q.from }} → {{ q.to }}</span></div>
75
+ <span class="hero-lift-row__wait">{{ q.wait }}</span>
76
+ <span class="hero-chip" :class="`hero-tone--${liftState(q.state).tone}`">{{ liftState(q.state).label }}</span>
77
+ <button
78
+ v-if="canCommand"
79
+ type="button"
80
+ class="hero-lift-row__release"
81
+ :style="{ visibility: q.state === 'riding' || q.state === 'requested' ? 'visible' : 'hidden' }"
82
+ :disabled="busy === q.key"
83
+ @click.stop="release(q)"
84
+ >
85
+ {{ q.state === "riding" ? "Release" : "Leave queue" }}
86
+ </button>
87
+ <span v-if="liftState(q.state).stripe !== 'none'" class="hero-lift-row__stripe" :class="`hero-lift-row__stripe--${liftState(q.state).stripe}`" aria-hidden="true" />
88
+ </div>
89
+ </div>
90
+
91
+ <form v-if="canCommand && demoRobots.length" class="hero-lift__ask" @submit.prevent="ask(l)">
92
+ <select v-model="askRobot[l.name]" class="hero-input hero-select hero-select--sm" aria-label="Robot">
93
+ <option value="" disabled>Robot</option>
94
+ <option v-for="r in demoRobots" :key="String(r._id)" :value="String(r._id)">{{ r.name }}</option>
95
+ </select>
96
+ <select v-model.number="askFrom[l.name]" class="hero-input hero-select hero-select--sm" aria-label="From floor">
97
+ <option v-for="f in l.rails.map((x) => x.floorNo).slice().reverse()" :key="f" :value="f">{{ floorName(f) }}</option>
98
+ </select>
99
+ <span class="hero-muted">→</span>
100
+ <select v-model.number="askTo[l.name]" class="hero-input hero-select hero-select--sm" aria-label="To floor">
101
+ <option v-for="f in l.rails.map((x) => x.floorNo).slice().reverse()" :key="f" :value="f">{{ floorName(f) }}</option>
102
+ </select>
103
+ <v-btn type="submit" variant="outlined" size="small" :loading="busy === l.name" :disabled="!askRobot[l.name]">Request lift</v-btn>
104
+ <span class="hero-muted hero-lift__simnote">Demo robots only · simulated lift</span>
105
+ </form>
106
+ </div>
107
+ </div>
108
+ </div>
109
+ <RobotToast v-model="toast" />
110
+ </template>
111
+
112
+ <script setup lang="ts">
113
+ import { computed, onBeforeUnmount, ref, toRef, watch } from "vue";
114
+ import RobotToast from "./Toast.vue";
115
+ import useRobotBuilding from "../../composables/useRobotBuilding";
116
+ import { floorName, liftState, robotErrorMessage } from "../../utils/robot-display";
117
+ import { liftCard, type TLiftRowView } from "../../utils/robot-building";
118
+
119
+ const props = withDefaults(
120
+ defineProps<{
121
+ organization: string;
122
+ site: string;
123
+ siteName?: string;
124
+ clientName?: string;
125
+ type?: "cleaning" | "security";
126
+ /** Request / release a lift for a demo robot (the update-robot grant). */
127
+ canCommand?: boolean;
128
+ canEditMap?: boolean;
129
+ backToNetwork?: boolean;
130
+ pollMs?: number;
131
+ }>(),
132
+ { siteName: "", clientName: "", type: "cleaning", canCommand: false, canEditMap: false, backToNetwork: false, pollMs: 3000 },
133
+ );
134
+ const emit = defineEmits<{
135
+ open: [id: string];
136
+ network: [];
137
+ status: [status: { connected: boolean; faults: number; siteName: string; clientName: string }];
138
+ }>();
139
+
140
+ const { rows, map, names, loading: mapLoading, error: mapError } = useRobotBuilding(
141
+ toRef(props, "organization"),
142
+ toRef(props, "site"),
143
+ toRef(props, "type"),
144
+ );
145
+ const kicker = computed(() => [props.clientName || names.value.clientName, props.siteName || names.value.siteName].filter(Boolean).join(" · "));
146
+ const { getLiftQueue, requestLift, releaseLiftSession } = useRobots();
147
+
148
+ /* ---- the queue, every 3 s while the page is visible ---- */
149
+ const items = ref<Array<Record<string, any>>>([]);
150
+ const connected = ref(true);
151
+ const queueLoading = ref(false);
152
+ const now = ref(Date.now());
153
+ const loading = computed(() => mapLoading.value || queueLoading.value);
154
+ const error = computed(() => mapError.value);
155
+
156
+ async function poll() {
157
+ const id = map.value?._id;
158
+ if (!id) return void (items.value = []);
159
+ if (typeof document !== "undefined" && document.visibilityState === "hidden") return;
160
+ try {
161
+ items.value = (await getLiftQueue(String(id)))?.items ?? [];
162
+ connected.value = true;
163
+ } catch {
164
+ connected.value = false;
165
+ } finally {
166
+ queueLoading.value = false;
167
+ now.value = Date.now();
168
+ }
169
+ }
170
+ let timer: ReturnType<typeof setInterval> | undefined;
171
+ watch(
172
+ () => map.value?._id,
173
+ (id) => {
174
+ clearInterval(timer);
175
+ items.value = [];
176
+ if (!id) return;
177
+ queueLoading.value = true;
178
+ poll();
179
+ timer = setInterval(poll, props.pollMs);
180
+ },
181
+ { immediate: true },
182
+ );
183
+ onBeforeUnmount(() => clearInterval(timer));
184
+
185
+ /**
186
+ * Scope isolation: only robots of the type on screen, that this app may see,
187
+ * are shown riding or waiting; another type's ride leaves the car unlabelled.
188
+ */
189
+ const allowed = computed(() => new Set(rows.value.map((r) => String(r._id))));
190
+ const scoped = (s: any) => s && allowed.value.has(String(s.robotId));
191
+ const cards = computed(() =>
192
+ items.value.map((lift) =>
193
+ liftCard(
194
+ { ...lift, active: scoped(lift.active) ? lift.active : null, queue: (lift.queue ?? []).filter(scoped), recent: (lift.recent ?? []).filter(scoped) },
195
+ now.value,
196
+ ),
197
+ ),
198
+ );
199
+
200
+ /* ---- manager actions: demo robots only (the lift is simulated) ---- */
201
+ const demoRobots = computed(() => rows.value.filter((r) => r.brand === "demo" || r.demo === true));
202
+ const askRobot = ref<Record<string, string>>({});
203
+ const askFrom = ref<Record<string, number>>({});
204
+ const askTo = ref<Record<string, number>>({});
205
+ watch(cards, (list) => {
206
+ for (const l of list) {
207
+ const fl = l.rails.map((x) => x.floorNo);
208
+ if (!(l.name in askFrom.value)) askFrom.value[l.name] = fl[fl.length - 1] ?? 1;
209
+ if (!(l.name in askTo.value)) askTo.value[l.name] = fl[0] ?? 1;
210
+ if (!askRobot.value[l.name] && demoRobots.value[0]) askRobot.value[l.name] = String(demoRobots.value[0]._id);
211
+ }
212
+ });
213
+ const busy = ref("");
214
+ const toast = ref("");
215
+ async function ask(l: { name: string }) {
216
+ const robotId = askRobot.value[l.name];
217
+ if (!robotId || !map.value?._id) return;
218
+ busy.value = l.name;
219
+ try {
220
+ await requestLift(String(map.value._id), l.name, { robotId, fromFloor: askFrom.value[l.name]!, toFloor: askTo.value[l.name]! });
221
+ toast.value = `Lift requested → ${rows.value.find((r) => String(r._id) === robotId)?.name ?? "robot"}`;
222
+ await poll();
223
+ } catch (e) {
224
+ toast.value = robotErrorMessage(e, "The lift could not be requested.");
225
+ } finally {
226
+ busy.value = "";
227
+ }
228
+ }
229
+ async function release(q: TLiftRowView) {
230
+ busy.value = q.key;
231
+ try {
232
+ await releaseLiftSession(q.key);
233
+ toast.value = q.state === "riding" ? `Lift released · ${q.robot}` : `${q.robot} left the queue`;
234
+ await poll();
235
+ } catch (e) {
236
+ toast.value = robotErrorMessage(e, "The lift could not be released.");
237
+ } finally {
238
+ busy.value = "";
239
+ }
240
+ }
241
+
242
+ watch(
243
+ [connected, () => rows.value.filter((r) => r.fault).length, () => names.value.siteName, () => names.value.clientName],
244
+ ([up, faults, siteName, clientName]) => emit("status", { connected: up, faults, siteName, clientName }),
245
+ { immediate: true },
246
+ );
247
+ </script>
@@ -0,0 +1,233 @@
1
+ <template>
2
+ <!--
3
+ Map editor (README §4 "Edit mode"): Wall · Zone · Door · Lift shaft · Move
4
+ · Delete | Undo ⌃Z | Save, one floor at a time on a flat 2D plan. A click
5
+ places the tool's shape; Move = click a shape, then its destination;
6
+ Delete = click a shape. Keyboard: Tab to the plan, arrows move the
7
+ cursor, Enter places. Save checks in plain words first, then writes the
8
+ building map through the API (versioned; a stale save is refused).
9
+ -->
10
+ <div ref="root" class="hero-editor" :class="{ 'hero-editor--fs': isFs }">
11
+ <div class="hero-editor__bar">
12
+ <div class="hero-seg" role="toolbar" aria-label="Map editor tools">
13
+ <button v-for="t in MAP_TOOLS" :key="t.id" type="button" class="hero-seg__opt" :aria-pressed="tool === t.id" @click="pickTool(t.id)">{{ t.label }}</button>
14
+ <button type="button" class="hero-seg__opt hero-seg__opt--undo" @click="state = editorReduce(state, { type: 'undo' })">Undo <span class="hero-seg__kbd">⌃Z</span></button>
15
+ <button type="button" class="hero-seg__opt hero-seg__opt--save" :disabled="saving" @click="save">{{ saving ? "Saving…" : "Save" }}</button>
16
+ </div>
17
+ <select v-model.number="floor" class="hero-input hero-select hero-editor__floor" aria-label="Floor">
18
+ <option v-for="f in floors" :key="f" :value="f">{{ floorName(f) }}</option>
19
+ </select>
20
+ <input
21
+ v-if="tool === 'zone'"
22
+ v-model="zoneName"
23
+ class="hero-input hero-editor__zone"
24
+ aria-label="Zone name"
25
+ placeholder="Zone name (required to save)"
26
+ @input="state = editorReduce(state, { type: 'rename', name: zoneName })"
27
+ />
28
+ <span class="hero-editor__hint">{{ TOOL_HINTS[tool] }}</span>
29
+ <v-btn variant="outlined" class="hero-editor__fs" @click="fullscreen">
30
+ <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>
31
+ Full screen
32
+ </v-btn>
33
+ </div>
34
+
35
+ <div v-if="state.notice" class="hero-editor__notice" :class="{ 'hero-editor__notice--ok': state.notice.ok }" role="status" aria-live="polite">{{ state.notice.text }}</div>
36
+
37
+ <div class="hero-editor__split">
38
+ <div
39
+ ref="plan"
40
+ class="hero-editor__plan"
41
+ tabindex="0"
42
+ role="application"
43
+ :aria-label="`Floor plan ${floorName(floor)}. Arrow keys move the cursor, Enter places.`"
44
+ @click="onPlanClick"
45
+ @keydown="onKey"
46
+ @blur="keyboard = false"
47
+ >
48
+ <span class="hero-editor__room" style="left: 8%; top: 10%; width: 34%; height: 30%" aria-hidden="true" />
49
+ <span class="hero-editor__room" style="left: 58%; top: 10%; width: 34%; height: 44%" aria-hidden="true" />
50
+ <span class="hero-editor__room" style="left: 8%; top: 62%; width: 60%; height: 28%" aria-hidden="true" />
51
+ <svg class="hero-editor__svg" viewBox="0 0 100 100" preserveAspectRatio="none" aria-hidden="true">
52
+ <template v-for="s in visible" :key="s.id">
53
+ <polygon v-if="s.kind === 'zone'" class="hero-editor__zone-shape" :class="{ 'hero-editor__sel': state.moving === s.id }" :points="pts(s)" vector-effect="non-scaling-stroke" />
54
+ <line v-else-if="s.kind === 'wall'" class="hero-editor__wall" :class="{ 'hero-editor__sel': state.moving === s.id }" :x1="s.points[0]!.x" :y1="s.points[0]!.y" :x2="s.points[1]!.x" :y2="s.points[1]!.y" />
55
+ </template>
56
+ </svg>
57
+ <template v-for="s in visible" :key="`l-${s.id}`">
58
+ <div v-if="s.kind === 'zone'" class="hero-editor__label" :style="boxStyle(s)" :title="shapeTitle(s)">{{ s.name || "Unnamed zone" }}</div>
59
+ <div v-else-if="s.kind === 'lift'" class="hero-editor__lift" :class="{ 'hero-editor__sel': state.moving === s.id }" :style="boxStyle(s)" :title="shapeTitle(s)">Lift</div>
60
+ <div v-else-if="s.kind === 'door'" class="hero-editor__door" :class="{ 'hero-editor__sel': state.moving === s.id }" :style="{ left: `${shapeAnchor(s).x}%`, top: `${shapeAnchor(s).y}%` }" :title="shapeTitle(s)" />
61
+ </template>
62
+ <span v-if="keyboard" class="hero-editor__cursor" :style="{ left: `${cursor.x}%`, top: `${cursor.y}%` }" aria-hidden="true" />
63
+ </div>
64
+
65
+ <aside class="hero-editor__aside">
66
+ <div class="hero-aside__title hero-editor__asidetitle">On {{ floorName(floor) }}</div>
67
+ <div v-for="s in visible" :key="`r-${s.id}`" class="hero-editor__row">
68
+ <span>{{ shapeTitle(s) }}</span><span class="hero-editor__pos">{{ shapeAnchor(s).x }}, {{ shapeAnchor(s).y }}</span>
69
+ </div>
70
+ <div v-if="!visible.length" class="hero-muted">Nothing drawn yet. Pick a tool and click the plan.</div>
71
+ <div class="hero-editor__note">The plan image comes from the robot; everything here is drawn on top of it. Keyboard: Tab to the plan, arrow keys move the cursor, Enter places.</div>
72
+ </aside>
73
+ </div>
74
+ </div>
75
+ </template>
76
+
77
+ <script setup lang="ts">
78
+ import { computed, onBeforeUnmount, onMounted, ref, watch } from "vue";
79
+ import { floorName, MAP_TOOLS } from "../../utils/robot-display";
80
+ import {
81
+ editorProblem,
82
+ editorReduce,
83
+ emptyEditor,
84
+ saveErrorText,
85
+ savedNotice,
86
+ shapeAnchor,
87
+ shapeBox,
88
+ shapesFromMap,
89
+ shapesOnFloor,
90
+ shapeTitle,
91
+ toMapBody,
92
+ TOOL_HINTS,
93
+ type TEditorShape,
94
+ type TEditorState,
95
+ type TEditorTool,
96
+ } from "../../utils/robot-building";
97
+
98
+ const props = withDefaults(
99
+ defineProps<{
100
+ /** The site's saved building map, or null (the first save creates it). */
101
+ map?: Record<string, any> | null;
102
+ floors: number[];
103
+ siteName?: string;
104
+ /** The robot a first save is attached to - maps are stored per robot. */
105
+ ownerRobotId?: string;
106
+ /** The floor to open on. */
107
+ startFloor?: number | null;
108
+ }>(),
109
+ { map: null, siteName: "", ownerRobotId: "", startFloor: null },
110
+ );
111
+ const emit = defineEmits<{ saved: [] }>();
112
+ const { createBuildingMap, updateBuildingMap } = useRobots();
113
+
114
+ const state = ref<TEditorState>(emptyEditor(shapesFromMap(props.map)));
115
+ /** A newer map (after our own save, or another tab's) replaces the shapes only while nothing is unsaved. */
116
+ watch(
117
+ () => props.map,
118
+ (m) => {
119
+ if (!state.value.dirty) state.value = { ...emptyEditor(shapesFromMap(m)), notice: state.value.notice };
120
+ },
121
+ );
122
+
123
+ const tool = ref<TEditorTool>("wall");
124
+ const zoneName = ref("");
125
+ const floor = ref<number>(props.startFloor !== null && props.floors.includes(props.startFloor) ? props.startFloor : props.floors[0] ?? 1);
126
+ watch(() => props.floors, (f) => {
127
+ if (!f.includes(floor.value)) floor.value = f[0] ?? 1;
128
+ });
129
+ const visible = computed(() => shapesOnFloor(state.value.shapes, floor.value));
130
+
131
+ function pickTool(id: TEditorTool) {
132
+ tool.value = id;
133
+ state.value = editorReduce(state.value, { type: "tool" });
134
+ }
135
+
136
+ /* ---- the plan: a click (or Enter at the keyboard cursor) ---- */
137
+ const plan = ref<HTMLElement | null>(null);
138
+ const cursor = ref({ x: 50, y: 50 });
139
+ const keyboard = ref(false);
140
+
141
+ /** The topmost shape under a point (walls and doors get a little slack). */
142
+ function hit(x: number, y: number): TEditorShape | null {
143
+ for (const s of [...visible.value].reverse()) {
144
+ const b = shapeBox(s);
145
+ const pad = s.kind === "wall" || s.kind === "door" ? 1.8 : 0;
146
+ if (x >= b.x - pad && x <= b.x + b.w + pad && y >= b.y - pad && y <= b.y + b.h + pad) return s;
147
+ }
148
+ return null;
149
+ }
150
+ function act(x: number, y: number) {
151
+ const target = hit(x, y);
152
+ // Move with a shape picked: this point is its destination, even over another shape.
153
+ if (target && !(tool.value === "move" && state.value.moving)) {
154
+ state.value = editorReduce(state.value, { type: "pick", id: target.id, tool: tool.value, zoneName: zoneName.value });
155
+ if (tool.value === "move" && target.kind === "zone") zoneName.value = target.name ?? "";
156
+ return;
157
+ }
158
+ state.value = editorReduce(state.value, { type: "place", tool: tool.value, floorNo: floor.value, x, y, zoneName: zoneName.value, floors: props.floors });
159
+ }
160
+ function onPlanClick(e: MouseEvent) {
161
+ const r = (e.currentTarget as HTMLElement).getBoundingClientRect();
162
+ const clamp = (v: number) => Math.max(0, Math.min(98, v));
163
+ act(clamp(((e.clientX - r.left) / r.width) * 100), clamp(((e.clientY - r.top) / r.height) * 100));
164
+ }
165
+ function onKey(e: KeyboardEvent) {
166
+ const step = e.shiftKey ? 10 : 2;
167
+ const move: Record<string, [number, number]> = { ArrowLeft: [-step, 0], ArrowRight: [step, 0], ArrowUp: [0, -step], ArrowDown: [0, step] };
168
+ if (move[e.key]) {
169
+ e.preventDefault();
170
+ keyboard.value = true;
171
+ const [dx, dy] = move[e.key]!;
172
+ cursor.value = { x: Math.max(0, Math.min(98, cursor.value.x + dx)), y: Math.max(0, Math.min(98, cursor.value.y + dy)) };
173
+ } else if (e.key === "Enter" || e.key === " ") {
174
+ e.preventDefault();
175
+ keyboard.value = true;
176
+ act(cursor.value.x, cursor.value.y);
177
+ }
178
+ }
179
+
180
+ /** Ctrl/Cmd+Z anywhere in the editor except while typing a name. */
181
+ function onUndoKey(e: KeyboardEvent) {
182
+ if (!(e.ctrlKey || e.metaKey) || e.key.toLowerCase() !== "z" || e.shiftKey) return;
183
+ if ((e.target as HTMLElement)?.tagName === "INPUT") return;
184
+ e.preventDefault();
185
+ state.value = editorReduce(state.value, { type: "undo" });
186
+ }
187
+ onMounted(() => window.addEventListener("keydown", onUndoKey));
188
+ onBeforeUnmount(() => window.removeEventListener("keydown", onUndoKey));
189
+
190
+ /* ---- save ---- */
191
+ const saving = ref(false);
192
+ async function save() {
193
+ const problem = editorProblem(state.value);
194
+ if (problem) return void (state.value = editorReduce(state.value, { type: "notice", text: problem, ok: false }));
195
+ if (!props.map?._id && !props.ownerRobotId) {
196
+ return void (state.value = editorReduce(state.value, {
197
+ type: "notice",
198
+ text: "Can't save yet: this site has no robot to keep the map with. Add a robot to the site first, then draw the map.",
199
+ ok: false,
200
+ }));
201
+ }
202
+ const name = String(props.map?.name || `${props.siteName || "Site"} building`).slice(0, 60);
203
+ const body = toMapBody(state.value.shapes, name, props.map);
204
+ saving.value = true;
205
+ try {
206
+ if (props.map?._id) await updateBuildingMap(String(props.map._id), { ...body, version: Number(props.map.version) || 1 });
207
+ else await createBuildingMap({ ...body, robotId: props.ownerRobotId });
208
+ state.value = editorReduce(state.value, { type: "saved", text: savedNotice(new Date(), state.value.shapes.length, props.siteName) });
209
+ emit("saved");
210
+ } catch (e) {
211
+ state.value = editorReduce(state.value, { type: "notice", text: saveErrorText(e), ok: false });
212
+ } finally {
213
+ saving.value = false;
214
+ }
215
+ }
216
+
217
+ /* ---- drawing helpers + full screen ---- */
218
+ const pts = (s: TEditorShape) => s.points.map((p) => `${p.x},${p.y}`).join(" ");
219
+ function boxStyle(s: TEditorShape) {
220
+ const b = shapeBox(s);
221
+ return { left: `${b.x}%`, top: `${b.y}%`, width: `${b.w}%`, height: `${b.h}%` };
222
+ }
223
+ const root = ref<HTMLElement | null>(null);
224
+ const isFs = ref(false);
225
+ const onFs = () => (isFs.value = document.fullscreenElement === root.value);
226
+ onMounted(() => document.addEventListener("fullscreenchange", onFs));
227
+ onBeforeUnmount(() => document.removeEventListener("fullscreenchange", onFs));
228
+ function fullscreen() {
229
+ if (document.fullscreenElement) document.exitFullscreen?.();
230
+ else root.value?.requestFullscreen?.();
231
+ }
232
+ defineExpose({ root });
233
+ </script>
@@ -15,7 +15,7 @@
15
15
  :key="`tag-${t.key}`"
16
16
  class="hero-routetag"
17
17
  :class="{ 'hero-routetag--lg': large }"
18
- :style="{ left: t.left, top: t.top }"
18
+ :style="{ left: insideLeft(t.left, large ? `${t.name} · ${t.count} pts` : t.name, large ? 6.4 : 5.8, large ? 14 : 12), top: t.top }"
19
19
  >
20
20
  {{ t.name }}<template v-if="large"> · {{ t.count }} pts</template>
21
21
  </div>
@@ -28,12 +28,12 @@
28
28
  >
29
29
  {{ m.n }}
30
30
  </div>
31
- <div class="hero-cp__label" :class="{ 'hero-cp__label--lg': large }" :style="{ left: m.left, top: m.top }">{{ m.label }}</div>
31
+ <div class="hero-cp__label" :class="{ 'hero-cp__label--lg': large }" :style="{ left: insideLeft(m.left, m.label, large ? 6.2 : 5.6, 4), top: m.top }">{{ m.label }}</div>
32
32
  </template>
33
33
  </template>
34
34
 
35
35
  <script setup lang="ts">
36
- import { routeMarks, routePathD, routeTags, type TPatrolRouteView } from "../../utils/robot-display";
36
+ import { insideLeft, routeMarks, routePathD, routeTags, type TPatrolRouteView } from "../../utils/robot-display";
37
37
 
38
38
  withDefaults(
39
39
  defineProps<{
@@ -2,7 +2,8 @@
2
2
  <!--
3
3
  One estate's robots in the HERO look: the shared shell header (hidden when
4
4
  the host draws its own, e.g. the console's drill-down), then the site
5
- fleet overview, or one robot's detail when `robotId` is set. Every app
5
+ fleet overview, the building map or the lift queue (`view`), or one
6
+ robot's detail when `robotId` is set. Every app
6
7
  passes only its scope (org, site, the robot types it presents) and what
7
8
  this user's role may do; the API narrows again on its own side.
8
9
  -->
@@ -34,6 +35,35 @@
34
35
  @removed="onRemoved"
35
36
  @status="(s) => (connected = s.connected)"
36
37
  />
38
+ <RobotBuildingMap
39
+ v-else-if="view === 'map'"
40
+ :key="`map:${site}:${type}`"
41
+ :organization="organization"
42
+ :site="site"
43
+ :site-name="siteName"
44
+ :client-name="clientName"
45
+ :type="type"
46
+ :can-edit-map="canSetup && canEdit"
47
+ :back-to-network="backToNetwork"
48
+ @open="(id) => emit('open', id)"
49
+ @network="emit('network')"
50
+ @status="onFleetStatus"
51
+ />
52
+ <RobotLiftQueue
53
+ v-else-if="view === 'lifts'"
54
+ :key="`lifts:${site}:${type}`"
55
+ :organization="organization"
56
+ :site="site"
57
+ :site-name="siteName"
58
+ :client-name="clientName"
59
+ :type="type"
60
+ :can-command="canCommand"
61
+ :can-edit-map="canSetup && canEdit"
62
+ :back-to-network="backToNetwork"
63
+ @open="(id) => emit('open', id)"
64
+ @network="emit('network')"
65
+ @status="onFleetStatus"
66
+ />
37
67
  <RobotSiteFleet
38
68
  v-else
39
69
  :organization="organization"
@@ -71,6 +101,8 @@ import RobotHero from "./Hero.vue";
71
101
  import RobotSiteHeader from "./SiteHeader.vue";
72
102
  import RobotSiteFleet from "./SiteFleet.vue";
73
103
  import RobotDetail from "./Detail.vue";
104
+ import RobotBuildingMap from "./BuildingMap.vue";
105
+ import RobotLiftQueue from "./LiftQueue.vue";
74
106
  import RobotForm from "./Form.vue";
75
107
  import RobotToast from "./Toast.vue";
76
108
  import { roleLabel, type TRobotType } from "../../utils/robot-display";
@@ -91,6 +123,8 @@ const props = withDefaults(
91
123
  type?: TRobotType;
92
124
  /** One robot open, or none (the fleet). */
93
125
  robotId?: string;
126
+ /** Which screen: the fleet (default), the 3D building map, or the lift queue. A robot open wins. */
127
+ view?: "fleet" | "map" | "lifts";
94
128
  canSetup?: boolean;
95
129
  canEdit?: boolean;
96
130
  canCommand?: boolean;
@@ -107,6 +141,7 @@ const props = withDefaults(
107
141
  types: () => ["cleaning"],
108
142
  type: undefined,
109
143
  robotId: "",
144
+ view: "fleet",
110
145
  canSetup: false,
111
146
  canEdit: false,
112
147
  canCommand: false,