@7365admin1/layer-common 4.31.0 → 4.32.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 +10 -4
- package/assets/css/robot-hero.css +227 -1
- package/components/Robot/BuildingMap.vue +403 -0
- package/components/Robot/LiftQueue.vue +247 -0
- package/components/Robot/MapEditor.vue +233 -0
- package/components/Robot/PatrolRoutes.vue +3 -3
- package/components/Robot/SiteScreen.vue +36 -1
- package/composables/useRobotBuilding.ts +66 -0
- package/package.json +2 -2
- package/utils/robot-building.ts +521 -0
- package/utils/robot-display.ts +29 -6
|
@@ -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>
|
|
@@ -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>
|