@7365admin1/layer-common 4.21.4-staging.350 → 4.21.4-staging.351
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/components/Robot/Fleet.vue +179 -2
- package/components/Robot/Form.vue +37 -12
- package/components/Robot/Map3D.vue +63 -24
- package/components/Robot/Plans.vue +63 -0
- package/components/Robot/SpotClean.vue +174 -0
- package/composables/useRobots.ts +23 -0
- package/package.json +1 -1
- package/utils/building-map.ts +40 -8
- package/utils/robot-display.ts +89 -0
|
@@ -100,6 +100,13 @@
|
|
|
100
100
|
<v-icon start size="16">{{ display(item).icon }}</v-icon>
|
|
101
101
|
{{ display(item).label }}
|
|
102
102
|
</v-chip>
|
|
103
|
+
<!-- The robot's own fault, in its words, under the chip. -->
|
|
104
|
+
<div
|
|
105
|
+
v-if="robotFaultText(states[item._id])"
|
|
106
|
+
class="text-caption text-error mt-1"
|
|
107
|
+
>
|
|
108
|
+
{{ robotFaultText(states[item._id]) }}
|
|
109
|
+
</div>
|
|
103
110
|
</template>
|
|
104
111
|
|
|
105
112
|
<template #item.floor="{ item }">
|
|
@@ -154,6 +161,38 @@
|
|
|
154
161
|
<AppButton size="small" variant="text" @click="openMap(item)">
|
|
155
162
|
View layout
|
|
156
163
|
</AppButton>
|
|
164
|
+
<v-menu location="bottom end">
|
|
165
|
+
<template #activator="{ props: menu }">
|
|
166
|
+
<AppButton
|
|
167
|
+
v-bind="menu"
|
|
168
|
+
variant="icon"
|
|
169
|
+
icon="mdi-dots-vertical"
|
|
170
|
+
:aria-label="`More actions for ${item.name}`"
|
|
171
|
+
/>
|
|
172
|
+
</template>
|
|
173
|
+
<v-list density="compact">
|
|
174
|
+
<v-list-item title="Schedule" prepend-icon="mdi-calendar-clock" @click="openPlans(item)" />
|
|
175
|
+
<!--
|
|
176
|
+
Only for a brand that can take a click on the plan. A brand
|
|
177
|
+
without it gets no control, not one the server refuses.
|
|
178
|
+
-->
|
|
179
|
+
<v-list-item
|
|
180
|
+
v-if="canCommand && brandSpotCleans(states[item._id])"
|
|
181
|
+
title="Spot clean"
|
|
182
|
+
prepend-icon="mdi-target"
|
|
183
|
+
:disabled="!canSpotClean(states[item._id])"
|
|
184
|
+
@click="openSpot(item)"
|
|
185
|
+
/>
|
|
186
|
+
<v-list-item v-if="canEdit" title="Edit" prepend-icon="mdi-pencil-outline" @click="openEdit(item)" />
|
|
187
|
+
<v-list-item
|
|
188
|
+
v-if="canDelete"
|
|
189
|
+
title="Remove"
|
|
190
|
+
prepend-icon="mdi-delete-outline"
|
|
191
|
+
base-color="error"
|
|
192
|
+
@click="openRemove(item)"
|
|
193
|
+
/>
|
|
194
|
+
</v-list>
|
|
195
|
+
</v-menu>
|
|
157
196
|
</div>
|
|
158
197
|
</template>
|
|
159
198
|
|
|
@@ -245,6 +284,68 @@
|
|
|
245
284
|
@created="onCreated"
|
|
246
285
|
/>
|
|
247
286
|
</v-dialog>
|
|
287
|
+
|
|
288
|
+
<v-dialog v-model="editDialog" width="460" persistent>
|
|
289
|
+
<RobotForm
|
|
290
|
+
v-if="editDialog && actionRobot"
|
|
291
|
+
:key="actionRobot._id"
|
|
292
|
+
:organization="organization"
|
|
293
|
+
:site="site"
|
|
294
|
+
:type="robotType"
|
|
295
|
+
:robot="actionRobot"
|
|
296
|
+
@cancel="editDialog = false"
|
|
297
|
+
@saved="onSaved"
|
|
298
|
+
/>
|
|
299
|
+
</v-dialog>
|
|
300
|
+
|
|
301
|
+
<v-dialog v-model="plansDialog" width="560" scrollable>
|
|
302
|
+
<AppCard class="pa-0">
|
|
303
|
+
<v-toolbar density="comfortable" class="pl-4">
|
|
304
|
+
<span class="font-weight-medium text-h6">Schedule — {{ actionRobot?.name }}</span>
|
|
305
|
+
<v-spacer />
|
|
306
|
+
<AppButton variant="icon" icon="mdi-close" aria-label="Close" @click="plansDialog = false" />
|
|
307
|
+
</v-toolbar>
|
|
308
|
+
<RobotPlans v-if="plansDialog && actionRobot" :key="actionRobot._id" :robot-id="actionRobot._id" />
|
|
309
|
+
</AppCard>
|
|
310
|
+
</v-dialog>
|
|
311
|
+
|
|
312
|
+
<v-dialog v-model="spotDialog" width="720" scrollable>
|
|
313
|
+
<AppCard class="pa-0">
|
|
314
|
+
<v-toolbar density="comfortable" class="pl-4">
|
|
315
|
+
<span class="font-weight-medium text-h6">Spot clean — {{ actionRobot?.name }}</span>
|
|
316
|
+
</v-toolbar>
|
|
317
|
+
<RobotSpotClean
|
|
318
|
+
v-if="spotDialog && actionRobot"
|
|
319
|
+
:key="actionRobot._id"
|
|
320
|
+
:robot-id="actionRobot._id"
|
|
321
|
+
:robot-name="actionRobot.name"
|
|
322
|
+
@close="spotDialog = false"
|
|
323
|
+
@sent="onSpotSent"
|
|
324
|
+
/>
|
|
325
|
+
</AppCard>
|
|
326
|
+
</v-dialog>
|
|
327
|
+
|
|
328
|
+
<ConfirmDialog v-model="removeDialog" :loading="removing">
|
|
329
|
+
<template #title>Remove {{ actionRobot?.name }}?</template>
|
|
330
|
+
<template #description>
|
|
331
|
+
It stops appearing here and can no longer be sent to clean. To use it
|
|
332
|
+
again, add it back with its app key and token.
|
|
333
|
+
</template>
|
|
334
|
+
<template #footer>
|
|
335
|
+
<v-row no-gutters class="w-100">
|
|
336
|
+
<v-col cols="6" class="pr-2">
|
|
337
|
+
<v-btn block variant="outlined" class="text-none" :disabled="removing" @click="removeDialog = false">
|
|
338
|
+
Cancel
|
|
339
|
+
</v-btn>
|
|
340
|
+
</v-col>
|
|
341
|
+
<v-col cols="6" class="pl-2">
|
|
342
|
+
<v-btn block variant="flat" color="error" class="text-none" :loading="removing" @click="confirmRemove">
|
|
343
|
+
Remove
|
|
344
|
+
</v-btn>
|
|
345
|
+
</v-col>
|
|
346
|
+
</v-row>
|
|
347
|
+
</template>
|
|
348
|
+
</ConfirmDialog>
|
|
248
349
|
</template>
|
|
249
350
|
|
|
250
351
|
<script lang="ts" setup>
|
|
@@ -261,11 +362,14 @@
|
|
|
261
362
|
* gets nothing back rather than being trusted.
|
|
262
363
|
*/
|
|
263
364
|
import {
|
|
365
|
+
brandSpotCleans,
|
|
264
366
|
canDispatch,
|
|
265
367
|
canRecall,
|
|
368
|
+
canSpotClean,
|
|
266
369
|
floorLabel,
|
|
267
370
|
robotDisplay,
|
|
268
371
|
robotErrorMessage,
|
|
372
|
+
robotFaultText,
|
|
269
373
|
} from "../../utils/robot-display";
|
|
270
374
|
|
|
271
375
|
const props = withDefaults(
|
|
@@ -278,11 +382,84 @@ const props = withDefaults(
|
|
|
278
382
|
canAdd?: boolean;
|
|
279
383
|
/** Whether this user may dispatch. Reads and writes are separate grants. */
|
|
280
384
|
canCommand?: boolean;
|
|
385
|
+
/** `robot-mgmt:update-robot` - rename a robot or set its serial. */
|
|
386
|
+
canEdit?: boolean;
|
|
387
|
+
/** `robot-mgmt:delete-robot` - remove a robot. */
|
|
388
|
+
canDelete?: boolean;
|
|
281
389
|
}>(),
|
|
282
|
-
{
|
|
390
|
+
{
|
|
391
|
+
robotType: "cleaning",
|
|
392
|
+
title: "Robots",
|
|
393
|
+
canAdd: false,
|
|
394
|
+
canCommand: false,
|
|
395
|
+
canEdit: false,
|
|
396
|
+
canDelete: false,
|
|
397
|
+
},
|
|
283
398
|
);
|
|
284
399
|
|
|
285
|
-
const { getRobots, getRobotState, sendRobotCommand, getRobotMaps, trackRobot } =
|
|
400
|
+
const { getRobots, getRobotState, sendRobotCommand, getRobotMaps, trackRobot, deleteRobot } =
|
|
401
|
+
useRobots();
|
|
402
|
+
|
|
403
|
+
/* ---- the row menu: schedule, spot clean, edit, remove ------------------ */
|
|
404
|
+
|
|
405
|
+
const actionRobot = ref<Record<string, any> | null>(null);
|
|
406
|
+
const plansDialog = ref(false);
|
|
407
|
+
const spotDialog = ref(false);
|
|
408
|
+
const editDialog = ref(false);
|
|
409
|
+
const removeDialog = ref(false);
|
|
410
|
+
const removing = ref(false);
|
|
411
|
+
|
|
412
|
+
function openPlans(robot: Record<string, any>) {
|
|
413
|
+
actionRobot.value = robot;
|
|
414
|
+
plansDialog.value = true;
|
|
415
|
+
}
|
|
416
|
+
function openSpot(robot: Record<string, any>) {
|
|
417
|
+
actionRobot.value = robot;
|
|
418
|
+
spotDialog.value = true;
|
|
419
|
+
}
|
|
420
|
+
function openEdit(robot: Record<string, any>) {
|
|
421
|
+
actionRobot.value = robot;
|
|
422
|
+
editDialog.value = true;
|
|
423
|
+
}
|
|
424
|
+
function openRemove(robot: Record<string, any>) {
|
|
425
|
+
actionRobot.value = robot;
|
|
426
|
+
removeDialog.value = true;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
async function onSpotSent(message: string) {
|
|
430
|
+
spotDialog.value = false;
|
|
431
|
+
showToast(message, "success");
|
|
432
|
+
const robot = actionRobot.value;
|
|
433
|
+
if (!robot) return;
|
|
434
|
+
// Re-read: the API returns no job id, so the robot's own state is the proof.
|
|
435
|
+
try {
|
|
436
|
+
states.value = { ...states.value, [robot._id]: await getRobotState(robot._id) };
|
|
437
|
+
} catch {
|
|
438
|
+
// The command was accepted; a failed re-read only leaves the old chip.
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
function onSaved() {
|
|
443
|
+
editDialog.value = false;
|
|
444
|
+
showToast("Robot saved.", "success");
|
|
445
|
+
load();
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
async function confirmRemove() {
|
|
449
|
+
const robot = actionRobot.value;
|
|
450
|
+
if (!robot) return;
|
|
451
|
+
removing.value = true;
|
|
452
|
+
try {
|
|
453
|
+
await deleteRobot(robot._id);
|
|
454
|
+
removeDialog.value = false;
|
|
455
|
+
showToast(`${robot.name} has been removed.`, "success");
|
|
456
|
+
load();
|
|
457
|
+
} catch (e) {
|
|
458
|
+
showToast(robotErrorMessage(e, "Could not remove the robot."), "error");
|
|
459
|
+
} finally {
|
|
460
|
+
removing.value = false;
|
|
461
|
+
}
|
|
462
|
+
}
|
|
286
463
|
|
|
287
464
|
// The house pattern is a local Snackbar with local state, as
|
|
288
465
|
// `AccessCardPreviewDialog.vue` does - there is no global toast composable.
|
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<v-card width="100%">
|
|
3
3
|
<v-toolbar density="comfortable" class="pl-4 py-2">
|
|
4
|
-
<span class="font-weight-medium text-h6">
|
|
4
|
+
<span class="font-weight-medium text-h6">
|
|
5
|
+
{{ editing ? `Edit ${robot?.name ?? "robot"}` : `Add ${typeLabel} robot` }}
|
|
6
|
+
</span>
|
|
5
7
|
</v-toolbar>
|
|
6
8
|
|
|
7
9
|
<v-card-text class="pa-0" style="max-height: 70vh; overflow-y: auto">
|
|
8
10
|
<v-form ref="form" @submit.prevent="submit">
|
|
9
11
|
<v-row no-gutters class="px-6 pt-4">
|
|
10
12
|
<v-col cols="12" class="mb-2">
|
|
11
|
-
<p class="text-body-2 text-medium-emphasis">
|
|
13
|
+
<p v-if="editing" class="text-body-2 text-medium-emphasis">
|
|
14
|
+
Rename the robot or set its serial. To change its brand or its app
|
|
15
|
+
key and token, remove the robot and add it again.
|
|
16
|
+
</p>
|
|
17
|
+
<p v-else class="text-body-2 text-medium-emphasis">
|
|
12
18
|
The app key and token come from your robot supplier. They are used
|
|
13
19
|
to talk to the robot and are never shown again once saved.
|
|
14
20
|
</p>
|
|
@@ -25,7 +31,7 @@
|
|
|
25
31
|
/>
|
|
26
32
|
</v-col>
|
|
27
33
|
|
|
28
|
-
<v-col cols="12">
|
|
34
|
+
<v-col v-if="!editing" cols="12">
|
|
29
35
|
<InputLabel class="font-weight-bold" title="Brand" required />
|
|
30
36
|
<AppSelect
|
|
31
37
|
v-model="brand"
|
|
@@ -42,7 +48,7 @@
|
|
|
42
48
|
</p>
|
|
43
49
|
</v-col>
|
|
44
50
|
|
|
45
|
-
<v-col cols="12">
|
|
51
|
+
<v-col v-if="!editing" cols="12">
|
|
46
52
|
<InputLabel class="font-weight-bold" title="App key" required />
|
|
47
53
|
<v-text-field
|
|
48
54
|
v-model="appKey"
|
|
@@ -53,7 +59,7 @@
|
|
|
53
59
|
/>
|
|
54
60
|
</v-col>
|
|
55
61
|
|
|
56
|
-
<v-col cols="12">
|
|
62
|
+
<v-col v-if="!editing" cols="12">
|
|
57
63
|
<InputLabel class="font-weight-bold" title="App token" required />
|
|
58
64
|
<!--
|
|
59
65
|
Masked like a password because that is what it is: this token signs
|
|
@@ -111,7 +117,7 @@
|
|
|
111
117
|
:loading="saving"
|
|
112
118
|
@click="submit"
|
|
113
119
|
>
|
|
114
|
-
Add robot
|
|
120
|
+
{{ editing ? "Save" : "Add robot" }}
|
|
115
121
|
</v-btn>
|
|
116
122
|
</v-col>
|
|
117
123
|
</v-row>
|
|
@@ -140,23 +146,26 @@ const props = withDefaults(
|
|
|
140
146
|
organization: string;
|
|
141
147
|
site: string;
|
|
142
148
|
type?: "cleaning" | "security";
|
|
149
|
+
/** When given, the form edits this robot instead of adding one. */
|
|
150
|
+
robot?: Record<string, any> | null;
|
|
143
151
|
}>(),
|
|
144
|
-
{ type: "cleaning" },
|
|
152
|
+
{ type: "cleaning", robot: null },
|
|
145
153
|
);
|
|
146
154
|
|
|
147
|
-
const emit = defineEmits<{ cancel: []; created: [] }>();
|
|
155
|
+
const emit = defineEmits<{ cancel: []; created: []; saved: [] }>();
|
|
148
156
|
|
|
149
|
-
const { createRobot, getRobotBrands } = useRobots();
|
|
157
|
+
const { createRobot, updateRobot, getRobotBrands } = useRobots();
|
|
158
|
+
const editing = computed(() => !!props.robot?._id);
|
|
150
159
|
const { requiredRule } = useUtils();
|
|
151
160
|
|
|
152
161
|
const form = ref();
|
|
153
|
-
const name = ref("");
|
|
162
|
+
const name = ref(props.robot?.name ?? "");
|
|
154
163
|
const brand = ref("");
|
|
155
164
|
const brands = ref<Array<Record<string, any>>>([]);
|
|
156
165
|
const loadingBrands = ref(false);
|
|
157
166
|
const appKey = ref("");
|
|
158
167
|
const appToken = ref("");
|
|
159
|
-
const robotSn = ref("");
|
|
168
|
+
const robotSn = ref(props.robot?.robotSn ?? "");
|
|
160
169
|
const reveal = ref(false);
|
|
161
170
|
const saving = ref(false);
|
|
162
171
|
const error = ref("");
|
|
@@ -201,7 +210,9 @@ async function loadBrands() {
|
|
|
201
210
|
}
|
|
202
211
|
}
|
|
203
212
|
|
|
204
|
-
onMounted(
|
|
213
|
+
onMounted(() => {
|
|
214
|
+
if (!editing.value) loadBrands();
|
|
215
|
+
});
|
|
205
216
|
|
|
206
217
|
async function submit() {
|
|
207
218
|
const { valid } = await form.value?.validate?.() ?? { valid: false };
|
|
@@ -209,6 +220,20 @@ async function submit() {
|
|
|
209
220
|
|
|
210
221
|
saving.value = true;
|
|
211
222
|
error.value = "";
|
|
223
|
+
if (editing.value) {
|
|
224
|
+
try {
|
|
225
|
+
await updateRobot(props.robot!._id, {
|
|
226
|
+
name: name.value.trim(),
|
|
227
|
+
robotSn: robotSn.value.trim(),
|
|
228
|
+
});
|
|
229
|
+
emit("saved");
|
|
230
|
+
} catch (e) {
|
|
231
|
+
error.value = robotErrorMessage(e, "Could not save the robot.");
|
|
232
|
+
} finally {
|
|
233
|
+
saving.value = false;
|
|
234
|
+
}
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
212
237
|
try {
|
|
213
238
|
await createRobot({
|
|
214
239
|
name: name.value.trim(),
|
|
@@ -104,6 +104,7 @@ import {
|
|
|
104
104
|
gridFromImageData,
|
|
105
105
|
levelSolids,
|
|
106
106
|
projectPoint,
|
|
107
|
+
stackedElevations,
|
|
107
108
|
wallCorners,
|
|
108
109
|
wallsFromOccupancyGrid,
|
|
109
110
|
type TView,
|
|
@@ -134,15 +135,25 @@ const tilted = ref(true);
|
|
|
134
135
|
|
|
135
136
|
const wallCount = computed(() => solids.value.length);
|
|
136
137
|
|
|
137
|
-
|
|
138
|
-
|
|
138
|
+
/**
|
|
139
|
+
* "All levels" stacks every floor the robot has mapped, one storey apart.
|
|
140
|
+
* A sentinel rather than null, because null already means "nothing chosen".
|
|
141
|
+
*/
|
|
142
|
+
const ALL_LEVELS = -1_000_000;
|
|
143
|
+
|
|
144
|
+
const floorOptions = computed(() => {
|
|
145
|
+
const floors = maps.value
|
|
139
146
|
.map((m) => ({ title: m.mapName?.trim() || `Floor ${m.floorNo}`, value: m.floorNo }))
|
|
140
|
-
.sort((a, b) => a.value - b.value)
|
|
141
|
-
|
|
147
|
+
.sort((a, b) => a.value - b.value);
|
|
148
|
+
return floors.length > 1
|
|
149
|
+
? [...floors, { title: "All levels (stacked)", value: ALL_LEVELS }]
|
|
150
|
+
: floors;
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
const stacked = computed(() => selectedFloor.value === ALL_LEVELS);
|
|
142
154
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
);
|
|
155
|
+
/** Each floor's height in the stack; a single floor sits at zero. */
|
|
156
|
+
const elevations = computed(() => stackedElevations(maps.value.map((m) => Number(m.floorNo))));
|
|
146
157
|
|
|
147
158
|
/* ------------------------------------------------------------------ load */
|
|
148
159
|
|
|
@@ -167,22 +178,48 @@ async function load() {
|
|
|
167
178
|
}
|
|
168
179
|
}
|
|
169
180
|
|
|
170
|
-
/**
|
|
181
|
+
/**
|
|
182
|
+
* Fetch the selected floor's plan - or every floor's, stacked - trace the
|
|
183
|
+
* walls and extrude them. Stacking uses only what the robot's maps already
|
|
184
|
+
* return (floor number, plan image, scale, origin); floors sit one storey
|
|
185
|
+
* apart because the maps carry no height.
|
|
186
|
+
*/
|
|
171
187
|
async function buildLevel() {
|
|
172
|
-
const map = currentMap.value;
|
|
173
188
|
solids.value = [];
|
|
174
|
-
|
|
189
|
+
const chosen = stacked.value
|
|
190
|
+
? [...maps.value].sort((a, b) => a.floorNo - b.floorNo)
|
|
191
|
+
: maps.value.filter((m) => m.floorNo === selectedFloor.value);
|
|
192
|
+
|
|
193
|
+
if (!chosen.length || chosen.some((m) => !m.backgroundFileKey)) {
|
|
175
194
|
error.value = "This floor has no plan image.";
|
|
176
195
|
return;
|
|
177
196
|
}
|
|
178
197
|
|
|
179
|
-
const
|
|
180
|
-
const
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
198
|
+
const keys = chosen.map((m) => m.backgroundFileKey);
|
|
199
|
+
const files = await getRobotMapImages(props.robotId, keys);
|
|
200
|
+
|
|
201
|
+
const built: TWallSolid[] = [];
|
|
202
|
+
for (const map of chosen) {
|
|
203
|
+
const url = files?.items?.find((f: any) => f.fileKey === map.backgroundFileKey)?.url;
|
|
204
|
+
if (!url) {
|
|
205
|
+
error.value = "The floor plan image could not be fetched.";
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
const level = await traceLevel(map, url, stacked.value ? elevations.value.get(Number(map.floorNo)) ?? 0 : 0);
|
|
209
|
+
if (!level) return;
|
|
210
|
+
built.push(...level);
|
|
184
211
|
}
|
|
185
212
|
|
|
213
|
+
solids.value = built;
|
|
214
|
+
draw();
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** One floor plan image to extruded wall boxes, at a given height. */
|
|
218
|
+
async function traceLevel(
|
|
219
|
+
map: Record<string, any>,
|
|
220
|
+
url: string,
|
|
221
|
+
elevationM: number,
|
|
222
|
+
): Promise<TWallSolid[] | null> {
|
|
186
223
|
const image = await loadImage(url);
|
|
187
224
|
imageHeight.value = image.height;
|
|
188
225
|
|
|
@@ -192,7 +229,7 @@ async function buildLevel() {
|
|
|
192
229
|
const wctx = work.getContext("2d", { willReadFrequently: true });
|
|
193
230
|
if (!wctx) {
|
|
194
231
|
error.value = "This browser could not read the floor plan image.";
|
|
195
|
-
return;
|
|
232
|
+
return null;
|
|
196
233
|
}
|
|
197
234
|
wctx.drawImage(image, 0, 0);
|
|
198
235
|
|
|
@@ -200,10 +237,10 @@ async function buildLevel() {
|
|
|
200
237
|
const grid = gridFromImageData(data, image.width, image.height);
|
|
201
238
|
const { vertices, walls } = wallsFromOccupancyGrid(grid, { minRunPx: 6 });
|
|
202
239
|
|
|
203
|
-
|
|
240
|
+
return levelSolids(
|
|
204
241
|
{
|
|
205
242
|
name: map.mapName ?? `L${map.floorNo}`,
|
|
206
|
-
elevationM
|
|
243
|
+
elevationM,
|
|
207
244
|
scaleMPerPx: Number(map.resolution) || 0.05,
|
|
208
245
|
originXM: Number(map.originX) || 0,
|
|
209
246
|
originYM: Number(map.originY) || 0,
|
|
@@ -212,8 +249,6 @@ async function buildLevel() {
|
|
|
212
249
|
},
|
|
213
250
|
image.height,
|
|
214
251
|
);
|
|
215
|
-
|
|
216
|
-
draw();
|
|
217
252
|
}
|
|
218
253
|
|
|
219
254
|
/**
|
|
@@ -257,8 +292,10 @@ function draw() {
|
|
|
257
292
|
});
|
|
258
293
|
|
|
259
294
|
// Painter's algorithm: with no depth buffer, draw order IS the depth test.
|
|
295
|
+
// Lower storeys first when stacked - seen from above, a floor hides the one
|
|
296
|
+
// beneath it, never the other way round.
|
|
260
297
|
const ordered = [...solids.value].sort(
|
|
261
|
-
(a, b) => depthOf(a.centre, view) - depthOf(b.centre, view),
|
|
298
|
+
(a, b) => a.centre.z - b.centre.z || depthOf(a.centre, view) - depthOf(b.centre, view),
|
|
262
299
|
);
|
|
263
300
|
|
|
264
301
|
for (const solid of ordered) drawBox(ctx, solid, view);
|
|
@@ -301,10 +338,12 @@ function drawRobot(ctx: CanvasRenderingContext2D, view: TView) {
|
|
|
301
338
|
const state = props.robotState;
|
|
302
339
|
const pos = state?.position;
|
|
303
340
|
if (!pos || state?.floorKnown !== true) return;
|
|
304
|
-
if (state.floorNo !== selectedFloor.value) return;
|
|
341
|
+
if (!stacked.value && state.floorNo !== selectedFloor.value) return;
|
|
305
342
|
|
|
306
|
-
|
|
307
|
-
const
|
|
343
|
+
// Stacked, the robot stands on its own storey.
|
|
344
|
+
const z = stacked.value ? elevations.value.get(Number(state.floorNo)) ?? 0 : 0;
|
|
345
|
+
const base = projectPoint(pos.x, pos.y, z, view);
|
|
346
|
+
const top = projectPoint(pos.x, pos.y, z + 0.9, view);
|
|
308
347
|
|
|
309
348
|
ctx.beginPath();
|
|
310
349
|
ctx.moveTo(base.x, base.y);
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="pa-4">
|
|
3
|
+
<div v-if="loading" class="py-6 text-center">
|
|
4
|
+
<v-progress-circular indeterminate size="28" />
|
|
5
|
+
</div>
|
|
6
|
+
<v-alert v-else-if="error" type="error" variant="tonal" :text="error" />
|
|
7
|
+
<div v-else-if="!plans.length" class="py-6 text-center text-body-2 text-medium-emphasis">
|
|
8
|
+
This robot has no cleaning schedule.
|
|
9
|
+
</div>
|
|
10
|
+
<v-list v-else density="compact" class="pa-0">
|
|
11
|
+
<v-list-item v-for="(plan, i) in plans" :key="plan.planId ?? i" class="px-0">
|
|
12
|
+
<v-list-item-title class="font-weight-medium">
|
|
13
|
+
{{ plan.summary.days }} · {{ plan.summary.time }}
|
|
14
|
+
<v-chip
|
|
15
|
+
size="x-small"
|
|
16
|
+
label
|
|
17
|
+
variant="tonal"
|
|
18
|
+
class="ml-2"
|
|
19
|
+
:color="plan.summary.enabled ? 'success' : 'default'"
|
|
20
|
+
>
|
|
21
|
+
{{ plan.summary.enabled ? "On" : "Off" }}
|
|
22
|
+
</v-chip>
|
|
23
|
+
</v-list-item-title>
|
|
24
|
+
<v-list-item-subtitle>
|
|
25
|
+
{{ plan.summary.jobs.join(" · ") || "No jobs in this plan" }}
|
|
26
|
+
</v-list-item-subtitle>
|
|
27
|
+
</v-list-item>
|
|
28
|
+
</v-list>
|
|
29
|
+
<!--
|
|
30
|
+
Read-only on purpose: the schedule lives in the robot maker's cloud, and no
|
|
31
|
+
brand's adapter offers editing it through this platform yet.
|
|
32
|
+
-->
|
|
33
|
+
<p class="text-caption text-medium-emphasis mt-3 mb-0">
|
|
34
|
+
Schedules are set in the robot maker's own app and shown here as they are.
|
|
35
|
+
</p>
|
|
36
|
+
</div>
|
|
37
|
+
</template>
|
|
38
|
+
|
|
39
|
+
<script lang="ts" setup>
|
|
40
|
+
/** The cleaning schedule a robot's cloud holds, shown read-only. */
|
|
41
|
+
import { planSummary, robotErrorMessage } from "../../utils/robot-display";
|
|
42
|
+
|
|
43
|
+
const props = defineProps<{ robotId: string }>();
|
|
44
|
+
const { getRobotPlans } = useRobots();
|
|
45
|
+
|
|
46
|
+
const plans = ref<Array<Record<string, any>>>([]);
|
|
47
|
+
const loading = ref(true);
|
|
48
|
+
const error = ref("");
|
|
49
|
+
|
|
50
|
+
onMounted(async () => {
|
|
51
|
+
try {
|
|
52
|
+
const res = await getRobotPlans(props.robotId);
|
|
53
|
+
plans.value = (res?.items ?? []).map((p: Record<string, any>) => ({
|
|
54
|
+
...p,
|
|
55
|
+
summary: planSummary(p),
|
|
56
|
+
}));
|
|
57
|
+
} catch (e) {
|
|
58
|
+
error.value = robotErrorMessage(e, "Could not load this robot's schedule.");
|
|
59
|
+
} finally {
|
|
60
|
+
loading.value = false;
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
</script>
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="pa-4">
|
|
3
|
+
<AppSelect
|
|
4
|
+
v-if="maps.length > 1"
|
|
5
|
+
v-model="floorNo"
|
|
6
|
+
:items="floorOptions"
|
|
7
|
+
item-title="title"
|
|
8
|
+
item-value="value"
|
|
9
|
+
label="Level"
|
|
10
|
+
density="compact"
|
|
11
|
+
hide-details
|
|
12
|
+
class="mb-3"
|
|
13
|
+
style="max-width: 220px"
|
|
14
|
+
/>
|
|
15
|
+
<div v-if="loading" class="py-6 text-center">
|
|
16
|
+
<v-progress-circular indeterminate size="28" />
|
|
17
|
+
</div>
|
|
18
|
+
<v-alert v-else-if="error" type="error" variant="tonal" :text="error" />
|
|
19
|
+
<template v-else>
|
|
20
|
+
<p class="text-body-2 text-medium-emphasis mb-2">
|
|
21
|
+
Click the spot on the floor plan you want cleaned.
|
|
22
|
+
</p>
|
|
23
|
+
<div class="spot-plan">
|
|
24
|
+
<img
|
|
25
|
+
ref="img"
|
|
26
|
+
:src="imageUrl"
|
|
27
|
+
alt="Floor plan"
|
|
28
|
+
class="spot-plan__img"
|
|
29
|
+
@click="pick"
|
|
30
|
+
/>
|
|
31
|
+
<div
|
|
32
|
+
v-if="picked"
|
|
33
|
+
class="spot-plan__marker"
|
|
34
|
+
:style="{ left: `${picked.left}%`, top: `${picked.top}%` }"
|
|
35
|
+
/>
|
|
36
|
+
</div>
|
|
37
|
+
</template>
|
|
38
|
+
<div class="d-flex justify-end ga-2 mt-3">
|
|
39
|
+
<AppButton variant="text" :disabled="sending" @click="$emit('close')">Close</AppButton>
|
|
40
|
+
<AppButton :loading="sending" :disabled="!picked" @click="send">Clean this spot</AppButton>
|
|
41
|
+
</div>
|
|
42
|
+
</div>
|
|
43
|
+
</template>
|
|
44
|
+
|
|
45
|
+
<script lang="ts" setup>
|
|
46
|
+
/**
|
|
47
|
+
* Spot cleaning by clicking the robot's own floor plan.
|
|
48
|
+
*
|
|
49
|
+
* The click is taken in the plan's PIXELS - the frame the spot command uses -
|
|
50
|
+
* so no metre conversion happens here. Offered only for brands declaring
|
|
51
|
+
* `spotClean`; the server refuses the rest by name as well.
|
|
52
|
+
*/
|
|
53
|
+
import { robotErrorMessage, spotPolygon } from "../../utils/robot-display";
|
|
54
|
+
|
|
55
|
+
const props = defineProps<{ robotId: string; robotName?: string }>();
|
|
56
|
+
const emit = defineEmits<{ close: []; sent: [message: string] }>();
|
|
57
|
+
|
|
58
|
+
const { getRobotMaps, getRobotMapImages, sendRobotCommand } = useRobots();
|
|
59
|
+
|
|
60
|
+
const maps = ref<Array<Record<string, any>>>([]);
|
|
61
|
+
const floorNo = ref<number | null>(null);
|
|
62
|
+
const imageUrl = ref("");
|
|
63
|
+
const img = ref<HTMLImageElement | null>(null);
|
|
64
|
+
const picked = ref<{ x: number; y: number; left: number; top: number } | null>(null);
|
|
65
|
+
const loading = ref(true);
|
|
66
|
+
const sending = ref(false);
|
|
67
|
+
const error = ref("");
|
|
68
|
+
|
|
69
|
+
const floorOptions = computed(() =>
|
|
70
|
+
maps.value.map((m) => ({ title: m.mapName?.trim() || `Floor ${m.floorNo}`, value: m.floorNo })),
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
async function loadImage() {
|
|
74
|
+
const map = maps.value.find((m) => m.floorNo === floorNo.value);
|
|
75
|
+
picked.value = null;
|
|
76
|
+
imageUrl.value = "";
|
|
77
|
+
if (!map?.backgroundFileKey) {
|
|
78
|
+
error.value = "This floor has no plan image.";
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const files = await getRobotMapImages(props.robotId, [map.backgroundFileKey]);
|
|
82
|
+
imageUrl.value = files?.items?.find((f: any) => f.fileKey === map.backgroundFileKey)?.url ?? "";
|
|
83
|
+
if (!imageUrl.value) error.value = "The floor plan image could not be fetched.";
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
onMounted(async () => {
|
|
87
|
+
try {
|
|
88
|
+
const res = await getRobotMaps(props.robotId);
|
|
89
|
+
maps.value = res?.items ?? [];
|
|
90
|
+
if (!maps.value.length) {
|
|
91
|
+
error.value = "This robot has no floor maps yet.";
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
floorNo.value = maps.value[0].floorNo;
|
|
95
|
+
await loadImage();
|
|
96
|
+
} catch (e) {
|
|
97
|
+
error.value = robotErrorMessage(e, "Could not load this robot's floor plan.");
|
|
98
|
+
} finally {
|
|
99
|
+
loading.value = false;
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
watch(floorNo, async (next, prev) => {
|
|
104
|
+
if (prev === null || next === prev) return;
|
|
105
|
+
loading.value = true;
|
|
106
|
+
error.value = "";
|
|
107
|
+
try {
|
|
108
|
+
await loadImage();
|
|
109
|
+
} catch (e) {
|
|
110
|
+
error.value = robotErrorMessage(e, "Could not load this floor.");
|
|
111
|
+
} finally {
|
|
112
|
+
loading.value = false;
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
/** Screen point to plan pixel: the image is scaled to fit, its pixels are not. */
|
|
117
|
+
function pick(event: MouseEvent) {
|
|
118
|
+
const el = img.value;
|
|
119
|
+
if (!el || !el.naturalWidth) return;
|
|
120
|
+
const rect = el.getBoundingClientRect();
|
|
121
|
+
const fx = (event.clientX - rect.left) / rect.width;
|
|
122
|
+
const fy = (event.clientY - rect.top) / rect.height;
|
|
123
|
+
picked.value = {
|
|
124
|
+
x: fx * el.naturalWidth,
|
|
125
|
+
y: fy * el.naturalHeight,
|
|
126
|
+
left: fx * 100,
|
|
127
|
+
top: fy * 100,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
async function send() {
|
|
132
|
+
const el = img.value;
|
|
133
|
+
if (!picked.value || !el) return;
|
|
134
|
+
sending.value = true;
|
|
135
|
+
try {
|
|
136
|
+
await sendRobotCommand(props.robotId, {
|
|
137
|
+
kind: "spot",
|
|
138
|
+
points: spotPolygon(picked.value.x, picked.value.y, {
|
|
139
|
+
width: el.naturalWidth,
|
|
140
|
+
height: el.naturalHeight,
|
|
141
|
+
}),
|
|
142
|
+
});
|
|
143
|
+
emit("sent", `${props.robotName ?? "The robot"} has been sent to clean that spot.`);
|
|
144
|
+
} catch (e) {
|
|
145
|
+
error.value = robotErrorMessage(e);
|
|
146
|
+
} finally {
|
|
147
|
+
sending.value = false;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
</script>
|
|
151
|
+
|
|
152
|
+
<style scoped>
|
|
153
|
+
.spot-plan {
|
|
154
|
+
position: relative;
|
|
155
|
+
width: 100%;
|
|
156
|
+
}
|
|
157
|
+
.spot-plan__img {
|
|
158
|
+
display: block;
|
|
159
|
+
width: 100%;
|
|
160
|
+
cursor: crosshair;
|
|
161
|
+
image-rendering: pixelated;
|
|
162
|
+
border: 1px solid rgba(0, 0, 0, 0.12);
|
|
163
|
+
}
|
|
164
|
+
.spot-plan__marker {
|
|
165
|
+
position: absolute;
|
|
166
|
+
width: 14px;
|
|
167
|
+
height: 14px;
|
|
168
|
+
margin: -7px 0 0 -7px;
|
|
169
|
+
border-radius: 50%;
|
|
170
|
+
background: #ff5a1f;
|
|
171
|
+
box-shadow: 0 0 0 3px rgba(255, 90, 31, 0.3);
|
|
172
|
+
pointer-events: none;
|
|
173
|
+
}
|
|
174
|
+
</style>
|
package/composables/useRobots.ts
CHANGED
|
@@ -53,6 +53,27 @@ export default function useRobots() {
|
|
|
53
53
|
});
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
/**
|
|
57
|
+
* Rename a robot, or set its serial. The brand and the credentials are not
|
|
58
|
+
* editable: a wrong credential is replaced by removing the robot and adding
|
|
59
|
+
* it again, because the old value is never shown.
|
|
60
|
+
*/
|
|
61
|
+
function updateRobot(id: string, payload: { name?: string; robotSn?: string }) {
|
|
62
|
+
return useNuxtApp().$api<Record<string, any>>(`/api/robots/${id}`, {
|
|
63
|
+
method: "PATCH",
|
|
64
|
+
query: { appSlug },
|
|
65
|
+
body: payload,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Remove a robot. It stops listing and answering; the record is kept. */
|
|
70
|
+
function deleteRobot(id: string) {
|
|
71
|
+
return useNuxtApp().$api<Record<string, any>>(`/api/robots/${id}`, {
|
|
72
|
+
method: "DELETE",
|
|
73
|
+
query: { appSlug },
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
56
77
|
/** Live state — mode, online, whether it can take a job right now. */
|
|
57
78
|
function getRobotState(id: string) {
|
|
58
79
|
return useNuxtApp().$api<Record<string, any>>(
|
|
@@ -204,6 +225,8 @@ export default function useRobots() {
|
|
|
204
225
|
getRobotBrands,
|
|
205
226
|
trackRobot,
|
|
206
227
|
createRobot,
|
|
228
|
+
updateRobot,
|
|
229
|
+
deleteRobot,
|
|
207
230
|
getRobotState,
|
|
208
231
|
getRobotMaps,
|
|
209
232
|
getRobotMapImages,
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@7365admin1/layer-common",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "4.21.4-staging.
|
|
5
|
+
"version": "4.21.4-staging.351",
|
|
6
6
|
"author": "7365admin1",
|
|
7
7
|
"main": "./nuxt.config.ts",
|
|
8
8
|
"//files": "What a consumer extending this layer actually loads. Without this npm ships the whole working tree - the changesets, the CI workflows, the render harness in tools/ and any scratch directory that happened to exist at publish time. Nuxt resolves a layer by directory, so every runtime directory below has to stay listed; adding a new top-level runtime directory means adding it here too.",
|
package/utils/building-map.ts
CHANGED
|
@@ -333,12 +333,23 @@ export function fitView(
|
|
|
333
333
|
const bounds = solidsBounds(solids);
|
|
334
334
|
if (!bounds) return base;
|
|
335
335
|
|
|
336
|
-
|
|
336
|
+
// Heights count too: a stacked building's top storey must fit on the canvas,
|
|
337
|
+
// not just its footprint. A single level spans 0..wall height as before.
|
|
338
|
+
let minZ = Infinity;
|
|
339
|
+
let maxZ = -Infinity;
|
|
340
|
+
for (const w of solids) {
|
|
341
|
+
minZ = Math.min(minZ, w.centre.z - w.heightM / 2);
|
|
342
|
+
maxZ = Math.max(maxZ, w.centre.z + w.heightM / 2);
|
|
343
|
+
}
|
|
344
|
+
const corners = [
|
|
337
345
|
{ x: bounds.minX, y: bounds.minY },
|
|
338
346
|
{ x: bounds.maxX, y: bounds.minY },
|
|
339
347
|
{ x: bounds.maxX, y: bounds.maxY },
|
|
340
348
|
{ x: bounds.minX, y: bounds.maxY },
|
|
341
|
-
]
|
|
349
|
+
];
|
|
350
|
+
const projected = [0, minZ, maxZ].flatMap((z) =>
|
|
351
|
+
corners.map((p) => projectPoint(p.x, p.y, z, { ...base, zoom: 1, originPx: { x: 0, y: 0 } })),
|
|
352
|
+
);
|
|
342
353
|
|
|
343
354
|
const spanX = Math.max(...projected.map((p) => p.x)) - Math.min(...projected.map((p) => p.x));
|
|
344
355
|
const spanY = Math.max(...projected.map((p) => p.y)) - Math.min(...projected.map((p) => p.y));
|
|
@@ -350,12 +361,12 @@ export function fitView(
|
|
|
350
361
|
? Math.min(usableW / spanX, usableH / spanY)
|
|
351
362
|
: base.zoom;
|
|
352
363
|
|
|
353
|
-
const
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
364
|
+
const unit = { ...base, zoom, originPx: { x: 0, y: 0 } };
|
|
365
|
+
const all = [0, minZ, maxZ].flatMap((z) => corners.map((p) => projectPoint(p.x, p.y, z, unit)));
|
|
366
|
+
const centre = {
|
|
367
|
+
x: (Math.min(...all.map((p) => p.x)) + Math.max(...all.map((p) => p.x))) / 2,
|
|
368
|
+
y: (Math.min(...all.map((p) => p.y)) + Math.max(...all.map((p) => p.y))) / 2,
|
|
369
|
+
};
|
|
359
370
|
|
|
360
371
|
return {
|
|
361
372
|
rotation,
|
|
@@ -364,3 +375,24 @@ export function fitView(
|
|
|
364
375
|
originPx: { x: canvas.width / 2 - centre.x, y: canvas.height / 2 - centre.y },
|
|
365
376
|
};
|
|
366
377
|
}
|
|
378
|
+
|
|
379
|
+
/** Storey height used to stack levels when the plans carry no elevation. */
|
|
380
|
+
export const STOREY_HEIGHT_M = 4;
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* Where each floor sits when the building is shown stacked.
|
|
384
|
+
*
|
|
385
|
+
* The robot's maps give a floor NUMBER and nothing about height, so floors are
|
|
386
|
+
* stacked in number order one storey apart. Missing numbers do not leave gaps:
|
|
387
|
+
* a robot mapping floors 1 and 5 shows two levels, not five.
|
|
388
|
+
*
|
|
389
|
+
* ponytail: equal storeys. Real heights need building-map persistence, which
|
|
390
|
+
* is an owner decision still open.
|
|
391
|
+
*/
|
|
392
|
+
export function stackedElevations(
|
|
393
|
+
floorNos: number[],
|
|
394
|
+
storeyM = STOREY_HEIGHT_M,
|
|
395
|
+
): Map<number, number> {
|
|
396
|
+
const ordered = [...new Set(floorNos.filter((n) => Number.isFinite(n)))].sort((a, b) => a - b);
|
|
397
|
+
return new Map(ordered.map((floorNo, i) => [floorNo, i * storeyM]));
|
|
398
|
+
}
|
package/utils/robot-display.ts
CHANGED
|
@@ -121,3 +121,92 @@ export function robotErrorMessage(error: unknown, fallback = "Could not reach th
|
|
|
121
121
|
if (typeof e?.message === "string" && e.message.trim()) return e.message.trim();
|
|
122
122
|
return fallback;
|
|
123
123
|
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* May the "Spot clean" control be offered?
|
|
127
|
+
*
|
|
128
|
+
* Only when the robot could take a job now AND its brand says it can take a
|
|
129
|
+
* click on the plan (`spotClean`). A brand without it - Ounitech, until its
|
|
130
|
+
* pixel frame is verified - gets no control rather than one the server refuses.
|
|
131
|
+
*/
|
|
132
|
+
export function canSpotClean(state: {
|
|
133
|
+
online?: unknown;
|
|
134
|
+
dispatchable?: unknown;
|
|
135
|
+
capabilities?: Record<string, unknown> | null;
|
|
136
|
+
} | null | undefined): boolean {
|
|
137
|
+
return canDispatch(state) && state?.capabilities?.spotClean === true;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** Whether the brand can take a spot at all, busy or not - decides if the control exists. */
|
|
141
|
+
export function brandSpotCleans(state: { capabilities?: Record<string, unknown> | null } | null | undefined) {
|
|
142
|
+
return state?.capabilities?.spotClean === true;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** The fault the robot is reporting, in its own words, or null. */
|
|
146
|
+
export function robotFaultText(state: { fault?: { message?: unknown; code?: unknown } | null } | null | undefined): string | null {
|
|
147
|
+
const fault = state?.fault;
|
|
148
|
+
if (!fault) return null;
|
|
149
|
+
const text = typeof fault.message === "string" && fault.message.trim()
|
|
150
|
+
? fault.message.trim()
|
|
151
|
+
: typeof fault.code === "string" ? fault.code : "";
|
|
152
|
+
return text ? `Fault: ${text}` : null;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* A small square around a clicked pixel, as the polygon a spot command takes.
|
|
157
|
+
*
|
|
158
|
+
* A spot command needs at least three points (a single point encloses
|
|
159
|
+
* nothing). Clamped to the image so a click on the edge stays on the plan.
|
|
160
|
+
*/
|
|
161
|
+
export function spotPolygon(
|
|
162
|
+
x: number,
|
|
163
|
+
y: number,
|
|
164
|
+
size: { width: number; height: number },
|
|
165
|
+
half = 10,
|
|
166
|
+
): Array<{ x: number; y: number }> {
|
|
167
|
+
const cx = (v: number) => Math.round(Math.min(Math.max(v, 0), Math.max(size.width - 1, 0)));
|
|
168
|
+
const cy = (v: number) => Math.round(Math.min(Math.max(v, 0), Math.max(size.height - 1, 0)));
|
|
169
|
+
return [
|
|
170
|
+
{ x: cx(x - half), y: cy(y - half) },
|
|
171
|
+
{ x: cx(x + half), y: cy(y - half) },
|
|
172
|
+
{ x: cx(x + half), y: cy(y + half) },
|
|
173
|
+
{ x: cx(x - half), y: cy(y + half) },
|
|
174
|
+
];
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const DAY_NAMES = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* A cleaning schedule, as a person reads it.
|
|
181
|
+
*
|
|
182
|
+
* The vendor's `dateList` is 1-7, Monday first. An unknown day number is
|
|
183
|
+
* dropped rather than shown as a blank - but a plan with NO valid days says so,
|
|
184
|
+
* instead of reading like "every day".
|
|
185
|
+
*/
|
|
186
|
+
export function planSummary(plan: Record<string, any> | null | undefined) {
|
|
187
|
+
const days = [...new Set((Array.isArray(plan?.dateList) ? plan!.dateList : [])
|
|
188
|
+
.filter((d: unknown) => Number.isInteger(d) && (d as number) >= 1 && (d as number) <= 7))]
|
|
189
|
+
.sort((a: any, b: any) => a - b) as number[];
|
|
190
|
+
|
|
191
|
+
const dayText =
|
|
192
|
+
days.length === 7 ? "Every day"
|
|
193
|
+
: days.length ? days.map((d) => DAY_NAMES[d - 1]).join(", ")
|
|
194
|
+
: "No days set";
|
|
195
|
+
|
|
196
|
+
const start = typeof plan?.startTime === "string" ? plan.startTime : "";
|
|
197
|
+
const end = typeof plan?.endTime === "string" ? plan.endTime : "";
|
|
198
|
+
const time = start && end ? `${start}–${end}` : start || end || "No time set";
|
|
199
|
+
|
|
200
|
+
const jobs = (Array.isArray(plan?.jobList) ? plan!.jobList : []).map((job: any) => {
|
|
201
|
+
const floor = typeof job?.floorNo === "number" ? `Floor ${job.floorNo}` : "Floor unknown";
|
|
202
|
+
const passes = typeof job?.cleanTimes === "number" ? `${job.cleanTimes} pass${job.cleanTimes === 1 ? "" : "es"}` : "";
|
|
203
|
+
return [floor, passes].filter(Boolean).join(" · ");
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
return {
|
|
207
|
+
days: dayText,
|
|
208
|
+
time,
|
|
209
|
+
enabled: plan?.enableFlag === true || plan?.enableFlag === 1,
|
|
210
|
+
jobs,
|
|
211
|
+
};
|
|
212
|
+
}
|