@7365admin1/layer-common 4.22.0 → 4.22.1-staging.353
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 +4 -4
- package/components/AccessCardAddForm.vue +5 -4
- package/components/AccessCardAssignToUnitForm.vue +3 -2
- package/components/AccessCardPreviewDialog.vue +4 -3
- package/components/Dialog/UpdateMoreAction.vue +11 -1
- package/components/DocumentForm.vue +407 -112
- package/components/DocumentManagement.vue +213 -12
- package/components/EntryPass/QrTemplatePreview.vue +21 -25
- package/components/EntryPassInformation.vue +119 -24
- package/components/Facility/BookingSetup.vue +63 -0
- package/components/HidAccessLogDashboard.vue +29 -5
- package/components/HidAccessPermissions.vue +424 -0
- package/components/HidIntercomManagement.vue +148 -14
- package/components/HidProfileQrCode.vue +323 -0
- package/components/HidReaderManagement.vue +26 -0
- package/components/HidReaderUserRoster.vue +32 -2
- package/components/HidUserEnrollment.vue +833 -152
- package/components/InvitationClientForm.vue +19 -1
- package/components/Robot/Fleet.vue +712 -0
- package/components/Robot/Form.vue +256 -0
- package/components/Robot/Map3D.vue +1145 -0
- package/components/Robot/Plans.vue +63 -0
- package/components/Robot/SpotClean.vue +174 -0
- package/components/VisitorManagement.vue +267 -5
- package/composables/useAccessManagement.ts +5 -0
- package/composables/useDocument.ts +7 -0
- package/composables/useFacility.ts +11 -0
- package/composables/useHidAmico.ts +117 -0
- package/composables/useHidNavigation.ts +25 -1
- package/composables/usePeople.ts +19 -0
- package/composables/useRobots.ts +324 -0
- package/composables/useSiteCategory.ts +45 -0
- package/composables/useSiteEntryPassSettings.ts +26 -0
- package/composables/useWebUsb.ts +14 -11
- package/package.json +2 -2
- package/pages/[org]/[site]/access-mgmt/administrator/index.vue +1 -1
- package/pages/[org]/[site]/access-mgmt/hid-cards/index.vue +1 -1
- package/pages/[org]/[site]/access-mgmt/hid-qr-code/index.vue +23 -0
- package/pages/[org]/[site]/access-mgmt/hid-readers/index.vue +1 -1
- package/types/document.d.ts +14 -0
- package/types/facility.d.ts +4 -0
- package/types/people.d.ts +28 -1
- package/utils/building-map.ts +537 -0
- package/utils/hid-permission-assignments.ts +190 -0
- package/utils/occupancy-role.ts +109 -0
- package/utils/robot-display.ts +212 -0
|
@@ -0,0 +1,712 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<PageHeader :title="title">
|
|
3
|
+
<template #actions>
|
|
4
|
+
<AppButton v-if="canAdd" @click="dialog = true">Add Robot</AppButton>
|
|
5
|
+
</template>
|
|
6
|
+
</PageHeader>
|
|
7
|
+
|
|
8
|
+
<v-row no-gutters>
|
|
9
|
+
<v-col cols="12">
|
|
10
|
+
<AppCard class="table-card">
|
|
11
|
+
<CardToolbar :count="pageRange">
|
|
12
|
+
<template #left>
|
|
13
|
+
<AppButton
|
|
14
|
+
variant="icon"
|
|
15
|
+
icon="mdi-refresh"
|
|
16
|
+
aria-label="Refresh"
|
|
17
|
+
:loading="loading"
|
|
18
|
+
@click="load()"
|
|
19
|
+
/>
|
|
20
|
+
<AppField
|
|
21
|
+
v-model="search"
|
|
22
|
+
search
|
|
23
|
+
compact
|
|
24
|
+
placeholder="Search robots"
|
|
25
|
+
klass="app-toolbar__search"
|
|
26
|
+
@update:model-value="onSearch"
|
|
27
|
+
/>
|
|
28
|
+
</template>
|
|
29
|
+
<template #right>
|
|
30
|
+
<LocalPagination v-model="page" :length="pages" @update:model-value="load()" />
|
|
31
|
+
</template>
|
|
32
|
+
</CardToolbar>
|
|
33
|
+
|
|
34
|
+
<!--
|
|
35
|
+
The empty state distinguishes "nothing registered yet" from "we could
|
|
36
|
+
not load" - the two look identical if you only render an empty table,
|
|
37
|
+
and they need opposite actions from the person looking at the screen.
|
|
38
|
+
-->
|
|
39
|
+
<v-alert
|
|
40
|
+
v-if="error"
|
|
41
|
+
type="error"
|
|
42
|
+
variant="tonal"
|
|
43
|
+
class="ma-4"
|
|
44
|
+
:text="error"
|
|
45
|
+
/>
|
|
46
|
+
|
|
47
|
+
<div v-else-if="!loading && !items.length" class="robot-empty">
|
|
48
|
+
<v-icon size="56" class="mb-3">mdi-robot-outline</v-icon>
|
|
49
|
+
<p class="text-subtitle-1 font-weight-medium mb-1">No robots yet</p>
|
|
50
|
+
<p class="text-body-2 text-medium-emphasis mb-4">
|
|
51
|
+
{{
|
|
52
|
+
canAdd
|
|
53
|
+
? "Add a robot to see it here and send it to clean."
|
|
54
|
+
: "No robots have been added to this site yet."
|
|
55
|
+
}}
|
|
56
|
+
</p>
|
|
57
|
+
<AppButton v-if="canAdd" @click="dialog = true">Add Robot</AppButton>
|
|
58
|
+
</div>
|
|
59
|
+
|
|
60
|
+
<div v-else class="app-table-scroll">
|
|
61
|
+
<v-data-table
|
|
62
|
+
:loading="loading"
|
|
63
|
+
:headers="headers"
|
|
64
|
+
:items="items"
|
|
65
|
+
:items-per-page="limit"
|
|
66
|
+
fixed-header
|
|
67
|
+
hide-default-footer
|
|
68
|
+
style="max-height: calc(100vh - 200px)"
|
|
69
|
+
>
|
|
70
|
+
<template #item.name="{ item }">
|
|
71
|
+
<div class="d-flex align-center">
|
|
72
|
+
<v-icon size="20" color="primary" class="mr-3">mdi-robot-outline</v-icon>
|
|
73
|
+
<div>
|
|
74
|
+
<div class="font-weight-medium">{{ item.name }}</div>
|
|
75
|
+
<div class="text-caption text-medium-emphasis">
|
|
76
|
+
{{ item.robotSn || "Serial not yet known" }}
|
|
77
|
+
</div>
|
|
78
|
+
</div>
|
|
79
|
+
</div>
|
|
80
|
+
</template>
|
|
81
|
+
|
|
82
|
+
<template #item.state="{ item }">
|
|
83
|
+
<!--
|
|
84
|
+
Live state is fetched per robot AFTER the list renders. The list
|
|
85
|
+
itself comes from our database and is fast; each state call
|
|
86
|
+
crosses to the vendor's cloud. Blocking the table on the slowest
|
|
87
|
+
robot would make the whole screen feel broken.
|
|
88
|
+
-->
|
|
89
|
+
<v-chip v-if="!states[item._id]" size="small" label variant="tonal">
|
|
90
|
+
<v-progress-circular indeterminate size="12" width="2" class="mr-2" />
|
|
91
|
+
Checking
|
|
92
|
+
</v-chip>
|
|
93
|
+
<v-chip
|
|
94
|
+
v-else
|
|
95
|
+
size="small"
|
|
96
|
+
label
|
|
97
|
+
:color="display(item).color"
|
|
98
|
+
variant="tonal"
|
|
99
|
+
>
|
|
100
|
+
<v-icon start size="16">{{ display(item).icon }}</v-icon>
|
|
101
|
+
{{ display(item).label }}
|
|
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>
|
|
110
|
+
</template>
|
|
111
|
+
|
|
112
|
+
<template #item.floor="{ item }">
|
|
113
|
+
<div class="d-flex flex-column">
|
|
114
|
+
<span class="text-body-2 text-medium-emphasis">
|
|
115
|
+
{{ floorLabel(states[item._id]) }}
|
|
116
|
+
</span>
|
|
117
|
+
<!--
|
|
118
|
+
Battery is shown only when the brand reports one. A brand that
|
|
119
|
+
cannot measure it must not render as 0% - which reads as flat.
|
|
120
|
+
-->
|
|
121
|
+
<span
|
|
122
|
+
v-if="typeof states[item._id]?.batteryPercent === 'number'"
|
|
123
|
+
class="text-caption text-medium-emphasis"
|
|
124
|
+
>
|
|
125
|
+
{{ states[item._id].batteryPercent }}% battery
|
|
126
|
+
</span>
|
|
127
|
+
</div>
|
|
128
|
+
</template>
|
|
129
|
+
|
|
130
|
+
<template #item.actions="{ item }">
|
|
131
|
+
<div class="d-flex justify-end ga-2">
|
|
132
|
+
<AppButton
|
|
133
|
+
v-if="canCommand"
|
|
134
|
+
size="small"
|
|
135
|
+
variant="outlined"
|
|
136
|
+
:disabled="!canDispatch(states[item._id]) || busy === item._id"
|
|
137
|
+
:loading="busy === item._id && lastCommand === 'full'"
|
|
138
|
+
@click="send(item, { kind: 'full' }, 'full')"
|
|
139
|
+
>
|
|
140
|
+
Clean
|
|
141
|
+
</AppButton>
|
|
142
|
+
<AppButton
|
|
143
|
+
v-if="canCommand"
|
|
144
|
+
size="small"
|
|
145
|
+
variant="text"
|
|
146
|
+
:disabled="!canRecall(states[item._id]) || busy === item._id"
|
|
147
|
+
:loading="busy === item._id && lastCommand === 'return'"
|
|
148
|
+
@click="send(item, { kind: 'return' }, 'return')"
|
|
149
|
+
>
|
|
150
|
+
Return to dock
|
|
151
|
+
</AppButton>
|
|
152
|
+
<AppButton
|
|
153
|
+
v-if="canCommand"
|
|
154
|
+
size="small"
|
|
155
|
+
variant="text"
|
|
156
|
+
:disabled="!canDispatch(states[item._id]) || busy === item._id"
|
|
157
|
+
@click="openAreas(item)"
|
|
158
|
+
>
|
|
159
|
+
Clean area
|
|
160
|
+
</AppButton>
|
|
161
|
+
<AppButton size="small" variant="text" @click="openMap(item)">
|
|
162
|
+
View layout
|
|
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>
|
|
196
|
+
</div>
|
|
197
|
+
</template>
|
|
198
|
+
|
|
199
|
+
<template #bottom />
|
|
200
|
+
</v-data-table>
|
|
201
|
+
</div>
|
|
202
|
+
</AppCard>
|
|
203
|
+
</v-col>
|
|
204
|
+
</v-row>
|
|
205
|
+
|
|
206
|
+
<Snackbar v-model="toast" :text="toastText" :color="toastColor" />
|
|
207
|
+
|
|
208
|
+
<!--
|
|
209
|
+
The building in 3D, generated from this robot's own floor plan. Per robot
|
|
210
|
+
rather than per site because the maps come from the robot - it is the thing
|
|
211
|
+
that surveyed the building.
|
|
212
|
+
-->
|
|
213
|
+
<v-dialog v-model="mapDialog" width="960" scrollable>
|
|
214
|
+
<AppCard class="pa-0">
|
|
215
|
+
<v-toolbar density="comfortable" class="pl-4">
|
|
216
|
+
<span class="font-weight-medium text-h6">{{ mapRobot?.name }} — building layout</span>
|
|
217
|
+
<v-spacer />
|
|
218
|
+
<AppButton variant="icon" icon="mdi-close" aria-label="Close" @click="mapDialog = false" />
|
|
219
|
+
</v-toolbar>
|
|
220
|
+
<RobotMap3D
|
|
221
|
+
v-if="mapDialog && mapRobot"
|
|
222
|
+
:key="mapRobot._id"
|
|
223
|
+
:robot-id="mapRobot._id"
|
|
224
|
+
:robot-state="states[mapRobot._id] ?? null"
|
|
225
|
+
:can-edit="canEdit"
|
|
226
|
+
:robot-name="mapRobot.name"
|
|
227
|
+
:robot-brand="mapRobot.brand"
|
|
228
|
+
/>
|
|
229
|
+
</AppCard>
|
|
230
|
+
</v-dialog>
|
|
231
|
+
|
|
232
|
+
<!--
|
|
233
|
+
Choosing zones rather than cleaning everything. The areas come from the
|
|
234
|
+
robot's own maps, so the names are the ones its operator already knows.
|
|
235
|
+
-->
|
|
236
|
+
<v-dialog v-model="areaDialog" width="520" scrollable>
|
|
237
|
+
<AppCard class="pa-0">
|
|
238
|
+
<v-toolbar density="comfortable" class="pl-4">
|
|
239
|
+
<span class="font-weight-medium text-h6">Clean areas — {{ areaRobot?.name }}</span>
|
|
240
|
+
</v-toolbar>
|
|
241
|
+
<v-card-text style="max-height: 55vh">
|
|
242
|
+
<div v-if="loadingAreas" class="py-6 text-center">
|
|
243
|
+
<v-progress-circular indeterminate size="28" />
|
|
244
|
+
</div>
|
|
245
|
+
<v-alert v-else-if="areaError" type="error" variant="tonal" :text="areaError" />
|
|
246
|
+
<div v-else-if="!areaOptions.length" class="py-6 text-center text-body-2 text-medium-emphasis">
|
|
247
|
+
This robot's maps define no cleaning areas.
|
|
248
|
+
</div>
|
|
249
|
+
<template v-else>
|
|
250
|
+
<p class="text-body-2 text-medium-emphasis mb-3">
|
|
251
|
+
Pick the areas to clean. The robot cleans them in the order shown.
|
|
252
|
+
</p>
|
|
253
|
+
<v-checkbox
|
|
254
|
+
v-for="area in areaOptions"
|
|
255
|
+
:key="area.value"
|
|
256
|
+
v-model="chosenAreas"
|
|
257
|
+
:value="area.value"
|
|
258
|
+
:label="area.title"
|
|
259
|
+
density="compact"
|
|
260
|
+
hide-details
|
|
261
|
+
/>
|
|
262
|
+
</template>
|
|
263
|
+
</v-card-text>
|
|
264
|
+
<v-toolbar density="compact">
|
|
265
|
+
<v-row no-gutters>
|
|
266
|
+
<v-col cols="6">
|
|
267
|
+
<v-btn tile block variant="flat" size="48" class="text-none" color="#EFEFEF"
|
|
268
|
+
:disabled="sendingAreas" @click="areaDialog = false">Close</v-btn>
|
|
269
|
+
</v-col>
|
|
270
|
+
<v-col cols="6">
|
|
271
|
+
<v-btn tile block variant="flat" size="48" class="text-none" color="primary"
|
|
272
|
+
:loading="sendingAreas" :disabled="!chosenAreas.length" @click="sendAreas">
|
|
273
|
+
Clean {{ chosenAreas.length || "" }}
|
|
274
|
+
</v-btn>
|
|
275
|
+
</v-col>
|
|
276
|
+
</v-row>
|
|
277
|
+
</v-toolbar>
|
|
278
|
+
</AppCard>
|
|
279
|
+
</v-dialog>
|
|
280
|
+
|
|
281
|
+
<v-dialog v-model="dialog" width="460" persistent>
|
|
282
|
+
<RobotForm
|
|
283
|
+
:organization="organization"
|
|
284
|
+
:site="site"
|
|
285
|
+
:type="robotType"
|
|
286
|
+
@cancel="dialog = false"
|
|
287
|
+
@created="onCreated"
|
|
288
|
+
/>
|
|
289
|
+
</v-dialog>
|
|
290
|
+
|
|
291
|
+
<v-dialog v-model="editDialog" width="460" persistent>
|
|
292
|
+
<RobotForm
|
|
293
|
+
v-if="editDialog && actionRobot"
|
|
294
|
+
:key="actionRobot._id"
|
|
295
|
+
:organization="organization"
|
|
296
|
+
:site="site"
|
|
297
|
+
:type="robotType"
|
|
298
|
+
:robot="actionRobot"
|
|
299
|
+
@cancel="editDialog = false"
|
|
300
|
+
@saved="onSaved"
|
|
301
|
+
/>
|
|
302
|
+
</v-dialog>
|
|
303
|
+
|
|
304
|
+
<v-dialog v-model="plansDialog" width="560" scrollable>
|
|
305
|
+
<AppCard class="pa-0">
|
|
306
|
+
<v-toolbar density="comfortable" class="pl-4">
|
|
307
|
+
<span class="font-weight-medium text-h6">Schedule — {{ actionRobot?.name }}</span>
|
|
308
|
+
<v-spacer />
|
|
309
|
+
<AppButton variant="icon" icon="mdi-close" aria-label="Close" @click="plansDialog = false" />
|
|
310
|
+
</v-toolbar>
|
|
311
|
+
<RobotPlans v-if="plansDialog && actionRobot" :key="actionRobot._id" :robot-id="actionRobot._id" />
|
|
312
|
+
</AppCard>
|
|
313
|
+
</v-dialog>
|
|
314
|
+
|
|
315
|
+
<v-dialog v-model="spotDialog" width="720" scrollable>
|
|
316
|
+
<AppCard class="pa-0">
|
|
317
|
+
<v-toolbar density="comfortable" class="pl-4">
|
|
318
|
+
<span class="font-weight-medium text-h6">Spot clean — {{ actionRobot?.name }}</span>
|
|
319
|
+
</v-toolbar>
|
|
320
|
+
<RobotSpotClean
|
|
321
|
+
v-if="spotDialog && actionRobot"
|
|
322
|
+
:key="actionRobot._id"
|
|
323
|
+
:robot-id="actionRobot._id"
|
|
324
|
+
:robot-name="actionRobot.name"
|
|
325
|
+
@close="spotDialog = false"
|
|
326
|
+
@sent="onSpotSent"
|
|
327
|
+
/>
|
|
328
|
+
</AppCard>
|
|
329
|
+
</v-dialog>
|
|
330
|
+
|
|
331
|
+
<ConfirmDialog v-model="removeDialog" :loading="removing">
|
|
332
|
+
<template #title>Remove {{ actionRobot?.name }}?</template>
|
|
333
|
+
<template #description>
|
|
334
|
+
It stops appearing here and can no longer be sent to clean. To use it
|
|
335
|
+
again, add it back with its app key and token.
|
|
336
|
+
</template>
|
|
337
|
+
<template #footer>
|
|
338
|
+
<v-row no-gutters class="w-100">
|
|
339
|
+
<v-col cols="6" class="pr-2">
|
|
340
|
+
<v-btn block variant="outlined" class="text-none" :disabled="removing" @click="removeDialog = false">
|
|
341
|
+
Cancel
|
|
342
|
+
</v-btn>
|
|
343
|
+
</v-col>
|
|
344
|
+
<v-col cols="6" class="pl-2">
|
|
345
|
+
<v-btn block variant="flat" color="error" class="text-none" :loading="removing" @click="confirmRemove">
|
|
346
|
+
Remove
|
|
347
|
+
</v-btn>
|
|
348
|
+
</v-col>
|
|
349
|
+
</v-row>
|
|
350
|
+
</template>
|
|
351
|
+
</ConfirmDialog>
|
|
352
|
+
</template>
|
|
353
|
+
|
|
354
|
+
<script lang="ts" setup>
|
|
355
|
+
/**
|
|
356
|
+
* The fleet screen, shared by every application that shows robots.
|
|
357
|
+
*
|
|
358
|
+
* One component rather than a copy per app, so Property Management, Hygiene,
|
|
359
|
+
* the Seven365 console and the two mobile apps cannot drift into describing the
|
|
360
|
+
* same robot four different ways.
|
|
361
|
+
*
|
|
362
|
+
* What each app changes is only what it passes in: which robot `type` it
|
|
363
|
+
* presents, and which actions its user holds a permission for. The API narrows
|
|
364
|
+
* the result again on its own side, so a cleaning app asking for security robots
|
|
365
|
+
* gets nothing back rather than being trusted.
|
|
366
|
+
*/
|
|
367
|
+
import {
|
|
368
|
+
brandSpotCleans,
|
|
369
|
+
canDispatch,
|
|
370
|
+
canRecall,
|
|
371
|
+
canSpotClean,
|
|
372
|
+
floorLabel,
|
|
373
|
+
robotDisplay,
|
|
374
|
+
robotErrorMessage,
|
|
375
|
+
robotFaultText,
|
|
376
|
+
} from "../../utils/robot-display";
|
|
377
|
+
|
|
378
|
+
const props = withDefaults(
|
|
379
|
+
defineProps<{
|
|
380
|
+
organization: string;
|
|
381
|
+
site: string;
|
|
382
|
+
/** Which class of robot this application presents. */
|
|
383
|
+
robotType?: "cleaning" | "security";
|
|
384
|
+
title?: string;
|
|
385
|
+
canAdd?: boolean;
|
|
386
|
+
/** Whether this user may dispatch. Reads and writes are separate grants. */
|
|
387
|
+
canCommand?: boolean;
|
|
388
|
+
/** `robot-mgmt:update-robot` - rename a robot or set its serial. */
|
|
389
|
+
canEdit?: boolean;
|
|
390
|
+
/** `robot-mgmt:delete-robot` - remove a robot. */
|
|
391
|
+
canDelete?: boolean;
|
|
392
|
+
}>(),
|
|
393
|
+
{
|
|
394
|
+
robotType: "cleaning",
|
|
395
|
+
title: "Robots",
|
|
396
|
+
canAdd: false,
|
|
397
|
+
canCommand: false,
|
|
398
|
+
canEdit: false,
|
|
399
|
+
canDelete: false,
|
|
400
|
+
},
|
|
401
|
+
);
|
|
402
|
+
|
|
403
|
+
const { getRobots, getRobotState, sendRobotCommand, getRobotMaps, trackRobot, deleteRobot } =
|
|
404
|
+
useRobots();
|
|
405
|
+
|
|
406
|
+
/* ---- the row menu: schedule, spot clean, edit, remove ------------------ */
|
|
407
|
+
|
|
408
|
+
const actionRobot = ref<Record<string, any> | null>(null);
|
|
409
|
+
const plansDialog = ref(false);
|
|
410
|
+
const spotDialog = ref(false);
|
|
411
|
+
const editDialog = ref(false);
|
|
412
|
+
const removeDialog = ref(false);
|
|
413
|
+
const removing = ref(false);
|
|
414
|
+
|
|
415
|
+
function openPlans(robot: Record<string, any>) {
|
|
416
|
+
actionRobot.value = robot;
|
|
417
|
+
plansDialog.value = true;
|
|
418
|
+
}
|
|
419
|
+
function openSpot(robot: Record<string, any>) {
|
|
420
|
+
actionRobot.value = robot;
|
|
421
|
+
spotDialog.value = true;
|
|
422
|
+
}
|
|
423
|
+
function openEdit(robot: Record<string, any>) {
|
|
424
|
+
actionRobot.value = robot;
|
|
425
|
+
editDialog.value = true;
|
|
426
|
+
}
|
|
427
|
+
function openRemove(robot: Record<string, any>) {
|
|
428
|
+
actionRobot.value = robot;
|
|
429
|
+
removeDialog.value = true;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
async function onSpotSent(message: string) {
|
|
433
|
+
spotDialog.value = false;
|
|
434
|
+
showToast(message, "success");
|
|
435
|
+
const robot = actionRobot.value;
|
|
436
|
+
if (!robot) return;
|
|
437
|
+
// Re-read: the API returns no job id, so the robot's own state is the proof.
|
|
438
|
+
try {
|
|
439
|
+
states.value = { ...states.value, [robot._id]: await getRobotState(robot._id) };
|
|
440
|
+
} catch {
|
|
441
|
+
// The command was accepted; a failed re-read only leaves the old chip.
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
function onSaved() {
|
|
446
|
+
editDialog.value = false;
|
|
447
|
+
showToast("Robot saved.", "success");
|
|
448
|
+
load();
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
async function confirmRemove() {
|
|
452
|
+
const robot = actionRobot.value;
|
|
453
|
+
if (!robot) return;
|
|
454
|
+
removing.value = true;
|
|
455
|
+
try {
|
|
456
|
+
await deleteRobot(robot._id);
|
|
457
|
+
removeDialog.value = false;
|
|
458
|
+
showToast(`${robot.name} has been removed.`, "success");
|
|
459
|
+
load();
|
|
460
|
+
} catch (e) {
|
|
461
|
+
showToast(robotErrorMessage(e, "Could not remove the robot."), "error");
|
|
462
|
+
} finally {
|
|
463
|
+
removing.value = false;
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
// The house pattern is a local Snackbar with local state, as
|
|
468
|
+
// `AccessCardPreviewDialog.vue` does - there is no global toast composable.
|
|
469
|
+
const toast = ref(false);
|
|
470
|
+
const toastText = ref("");
|
|
471
|
+
const toastColor = ref<"success" | "error">("success");
|
|
472
|
+
|
|
473
|
+
function showToast(message: string, color: "success" | "error") {
|
|
474
|
+
toastText.value = message;
|
|
475
|
+
toastColor.value = color;
|
|
476
|
+
toast.value = true;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
const items = ref<Array<Record<string, any>>>([]);
|
|
480
|
+
const states = ref<Record<string, any>>({});
|
|
481
|
+
const loading = ref(false);
|
|
482
|
+
const error = ref("");
|
|
483
|
+
const search = ref("");
|
|
484
|
+
const page = ref(1);
|
|
485
|
+
const pages = ref(1);
|
|
486
|
+
const limit = 10;
|
|
487
|
+
const dialog = ref(false);
|
|
488
|
+
const mapDialog = ref(false);
|
|
489
|
+
const mapRobot = ref<Record<string, any> | null>(null);
|
|
490
|
+
|
|
491
|
+
const areaDialog = ref(false);
|
|
492
|
+
const areaRobot = ref<Record<string, any> | null>(null);
|
|
493
|
+
const areaOptions = ref<Array<{ title: string; value: string }>>([]);
|
|
494
|
+
const chosenAreas = ref<string[]>([]);
|
|
495
|
+
const loadingAreas = ref(false);
|
|
496
|
+
const sendingAreas = ref(false);
|
|
497
|
+
const areaError = ref("");
|
|
498
|
+
|
|
499
|
+
/** One open stream per robot, so they can all be stopped on unmount. */
|
|
500
|
+
const streams = new Map<string, { stop: () => void }>();
|
|
501
|
+
|
|
502
|
+
async function openAreas(robot: Record<string, any>) {
|
|
503
|
+
areaRobot.value = robot;
|
|
504
|
+
chosenAreas.value = [];
|
|
505
|
+
areaOptions.value = [];
|
|
506
|
+
areaError.value = "";
|
|
507
|
+
areaDialog.value = true;
|
|
508
|
+
loadingAreas.value = true;
|
|
509
|
+
try {
|
|
510
|
+
const res = await getRobotMaps(robot._id);
|
|
511
|
+
// Areas are per floor, and the same name can appear on more than one, so
|
|
512
|
+
// they are labelled with their floor rather than silently de-duplicated.
|
|
513
|
+
const options: Array<{ title: string; value: string }> = [];
|
|
514
|
+
for (const map of res?.items ?? []) {
|
|
515
|
+
for (const area of map.areaList ?? []) {
|
|
516
|
+
options.push({
|
|
517
|
+
title: `${area.areaName} — ${map.mapName?.trim() || `Floor ${map.floorNo}`}`,
|
|
518
|
+
value: area.areaName,
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
areaOptions.value = options;
|
|
523
|
+
} catch (e) {
|
|
524
|
+
areaError.value = robotErrorMessage(e, "Could not load this robot's areas.");
|
|
525
|
+
} finally {
|
|
526
|
+
loadingAreas.value = false;
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
async function sendAreas() {
|
|
531
|
+
const robot = areaRobot.value;
|
|
532
|
+
if (!robot || !chosenAreas.value.length) return;
|
|
533
|
+
sendingAreas.value = true;
|
|
534
|
+
try {
|
|
535
|
+
await sendRobotCommand(robot._id, { kind: "area", areas: [...chosenAreas.value] });
|
|
536
|
+
showToast(`${robot.name} has been sent to clean ${chosenAreas.value.length} area(s).`, "success");
|
|
537
|
+
areaDialog.value = false;
|
|
538
|
+
// Re-read rather than assume: the API returns no job id, so the robot's own
|
|
539
|
+
// state is the only truthful confirmation anything happened.
|
|
540
|
+
states.value = { ...states.value, [robot._id]: await getRobotState(robot._id) };
|
|
541
|
+
} catch (e) {
|
|
542
|
+
showToast(robotErrorMessage(e), "error");
|
|
543
|
+
} finally {
|
|
544
|
+
sendingAreas.value = false;
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
/**
|
|
549
|
+
* Follow each robot's position while this screen is open.
|
|
550
|
+
*
|
|
551
|
+
* The server holds one connection to the robot cloud for as long as each of
|
|
552
|
+
* these is open, so they are all stopped on unmount - leaving them running
|
|
553
|
+
* would consume the vendor's stream budget for a screen nobody is looking at.
|
|
554
|
+
*/
|
|
555
|
+
function watchRobots() {
|
|
556
|
+
stopWatching();
|
|
557
|
+
for (const robot of items.value) {
|
|
558
|
+
streams.set(
|
|
559
|
+
robot._id,
|
|
560
|
+
trackRobot(robot._id, (event) => {
|
|
561
|
+
if (event?.type === "pose" && event.pose) {
|
|
562
|
+
const current = states.value[robot._id] ?? {};
|
|
563
|
+
states.value = {
|
|
564
|
+
...states.value,
|
|
565
|
+
[robot._id]: {
|
|
566
|
+
...current,
|
|
567
|
+
mode: event.pose.mode ?? current.mode,
|
|
568
|
+
position: { x: event.pose.x, y: event.pose.y, theta: event.pose.theta },
|
|
569
|
+
},
|
|
570
|
+
};
|
|
571
|
+
return;
|
|
572
|
+
}
|
|
573
|
+
if (event?.type === "lost") {
|
|
574
|
+
// Losing the stream is not the same as the robot being idle: the last
|
|
575
|
+
// known mode would keep it advertised as ready for work forever.
|
|
576
|
+
const current = states.value[robot._id] ?? {};
|
|
577
|
+
states.value = {
|
|
578
|
+
...states.value,
|
|
579
|
+
[robot._id]: { ...current, mode: "UNAVAILABLE", dispatchable: false },
|
|
580
|
+
};
|
|
581
|
+
}
|
|
582
|
+
}),
|
|
583
|
+
);
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
function stopWatching() {
|
|
588
|
+
for (const stream of streams.values()) stream.stop();
|
|
589
|
+
streams.clear();
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
function openMap(robot: Record<string, any>) {
|
|
593
|
+
mapRobot.value = robot;
|
|
594
|
+
mapDialog.value = true;
|
|
595
|
+
}
|
|
596
|
+
const busy = ref("");
|
|
597
|
+
const lastCommand = ref("");
|
|
598
|
+
|
|
599
|
+
const headers = [
|
|
600
|
+
{ title: "Robot", value: "name", sortable: false },
|
|
601
|
+
{ title: "Status", value: "state", sortable: false },
|
|
602
|
+
{ title: "Floor", value: "floor", sortable: false },
|
|
603
|
+
{ title: "", value: "actions", sortable: false, align: "end" as const },
|
|
604
|
+
];
|
|
605
|
+
|
|
606
|
+
const pageRange = computed(() => {
|
|
607
|
+
if (!items.value.length) return "0 of 0";
|
|
608
|
+
const from = (page.value - 1) * limit + 1;
|
|
609
|
+
return `${from} - ${from + items.value.length - 1}`;
|
|
610
|
+
});
|
|
611
|
+
|
|
612
|
+
const display = (item: Record<string, any>) =>
|
|
613
|
+
robotDisplay(states.value[item._id]?.mode);
|
|
614
|
+
|
|
615
|
+
async function load() {
|
|
616
|
+
loading.value = true;
|
|
617
|
+
error.value = "";
|
|
618
|
+
try {
|
|
619
|
+
const res = await getRobots({
|
|
620
|
+
organization: props.organization,
|
|
621
|
+
site: props.site,
|
|
622
|
+
search: search.value,
|
|
623
|
+
page: page.value,
|
|
624
|
+
limit,
|
|
625
|
+
type: props.robotType,
|
|
626
|
+
});
|
|
627
|
+
items.value = res?.items ?? [];
|
|
628
|
+
pages.value = Math.max(1, Number(res?.totalPages ?? 1));
|
|
629
|
+
// Deliberately not awaited: the table renders from our own database
|
|
630
|
+
// immediately, and each robot's chip fills in as its cloud call returns.
|
|
631
|
+
loadStates().then(watchRobots);
|
|
632
|
+
} catch (e) {
|
|
633
|
+
error.value = robotErrorMessage(e, "Could not load the robots for this site.");
|
|
634
|
+
items.value = [];
|
|
635
|
+
} finally {
|
|
636
|
+
loading.value = false;
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
/**
|
|
641
|
+
* One state call per robot, each failing on its own.
|
|
642
|
+
*
|
|
643
|
+
* `allSettled`, not `all`: one robot that is off must not blank the status of
|
|
644
|
+
* every other robot on the site.
|
|
645
|
+
*/
|
|
646
|
+
async function loadStates() {
|
|
647
|
+
states.value = {};
|
|
648
|
+
await Promise.allSettled(
|
|
649
|
+
items.value.map(async (robot) => {
|
|
650
|
+
try {
|
|
651
|
+
states.value = { ...states.value, [robot._id]: await getRobotState(robot._id) };
|
|
652
|
+
} catch {
|
|
653
|
+
states.value = {
|
|
654
|
+
...states.value,
|
|
655
|
+
[robot._id]: { mode: "UNAVAILABLE", online: false, dispatchable: false },
|
|
656
|
+
};
|
|
657
|
+
}
|
|
658
|
+
}),
|
|
659
|
+
);
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
async function send(robot: Record<string, any>, command: any, kind: string) {
|
|
663
|
+
busy.value = robot._id;
|
|
664
|
+
lastCommand.value = kind;
|
|
665
|
+
try {
|
|
666
|
+
await sendRobotCommand(robot._id, command);
|
|
667
|
+
showToast(
|
|
668
|
+
kind === "return"
|
|
669
|
+
? `${robot.name} is returning to its dock.`
|
|
670
|
+
: `${robot.name} has been sent to clean.`,
|
|
671
|
+
"success",
|
|
672
|
+
);
|
|
673
|
+
// Re-read rather than assume: the API returns no job id, so the robot's own
|
|
674
|
+
// state is the only truthful confirmation that anything happened.
|
|
675
|
+
states.value = { ...states.value, [robot._id]: await getRobotState(robot._id) };
|
|
676
|
+
} catch (e) {
|
|
677
|
+
showToast(robotErrorMessage(e), "error");
|
|
678
|
+
} finally {
|
|
679
|
+
busy.value = "";
|
|
680
|
+
lastCommand.value = "";
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
let searchTimer: ReturnType<typeof setTimeout> | undefined;
|
|
685
|
+
function onSearch() {
|
|
686
|
+
clearTimeout(searchTimer);
|
|
687
|
+
searchTimer = setTimeout(() => {
|
|
688
|
+
page.value = 1;
|
|
689
|
+
load();
|
|
690
|
+
}, 350);
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
function onCreated() {
|
|
694
|
+
dialog.value = false;
|
|
695
|
+
page.value = 1;
|
|
696
|
+
load();
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
onMounted(load);
|
|
700
|
+
onBeforeUnmount(stopWatching);
|
|
701
|
+
</script>
|
|
702
|
+
|
|
703
|
+
<style scoped>
|
|
704
|
+
.robot-empty {
|
|
705
|
+
display: flex;
|
|
706
|
+
flex-direction: column;
|
|
707
|
+
align-items: center;
|
|
708
|
+
justify-content: center;
|
|
709
|
+
text-align: center;
|
|
710
|
+
padding: 56px 16px;
|
|
711
|
+
}
|
|
712
|
+
</style>
|