@7365admin1/layer-common 4.32.1-staging.364 → 4.32.1-staging.365
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/assets/css/robot-hero.css +26 -0
- package/components/Robot/ActivityLog.vue +113 -0
- package/components/Robot/AlertsTable.vue +1 -0
- package/components/Robot/Detail.vue +8 -5
- package/components/Robot/Form.vue +170 -214
- package/components/Robot/MiniMap.vue +7 -1
- package/components/Robot/SiteAlerts.vue +117 -0
- package/components/Robot/SiteScreen.vue +69 -5
- package/composables/useRobotBuilding.ts +9 -12
- package/composables/useRobots.ts +53 -4
- package/package.json +1 -1
- package/utils/robot-display.ts +146 -0
|
@@ -699,6 +699,8 @@
|
|
|
699
699
|
.hero-bot__body { position: absolute; left: -7px; top: -7px; width: 14px; height: 14px; background: var(--hero-bot); outline: 2px solid var(--hero-bg); }
|
|
700
700
|
.hero-bot__tick { position: absolute; right: -5px; top: 5px; width: 5px; height: 4px; background: var(--hero-accent); }
|
|
701
701
|
.hero-bot__name { position: absolute; left: 10px; top: -18px; font-size: 10px; font-weight: 600; white-space: nowrap; background: var(--hero-bg); padding: 0 4px; line-height: 1.45; }
|
|
702
|
+
.hero-bot__name--left { left: auto; right: 10px; }
|
|
703
|
+
.hero-bot__name--below { top: 10px; }
|
|
702
704
|
|
|
703
705
|
/* Patrol checkpoints and route tags. */
|
|
704
706
|
.hero-cp {
|
|
@@ -839,6 +841,30 @@
|
|
|
839
841
|
.hero-dialog__body { font-size: 14px; opacity: 0.85; }
|
|
840
842
|
.hero-dialog__actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
|
|
841
843
|
|
|
844
|
+
/* ============================================ HERO phase (e): add / edit dialog, alerts, activity log */
|
|
845
|
+
|
|
846
|
+
/* The Remove dialog is the DS default (440px); Add / edit is 520px (README §8). */
|
|
847
|
+
.hero-dialog--form { width: 100%; }
|
|
848
|
+
.hero-form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
|
|
849
|
+
.hero-form-grid__full { grid-column: 1 / -1; }
|
|
850
|
+
@media (max-width: 480px) { .hero-form-grid { grid-template-columns: 1fr; } }
|
|
851
|
+
.hero-form-grid select.hero-input {
|
|
852
|
+
appearance: none;
|
|
853
|
+
padding-right: 30px;
|
|
854
|
+
background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
|
|
855
|
+
background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%;
|
|
856
|
+
background-size: 5px 5px;
|
|
857
|
+
background-repeat: no-repeat;
|
|
858
|
+
cursor: pointer;
|
|
859
|
+
}
|
|
860
|
+
/* The DS backdrop: neutral-900 at 50% (light grey over the dark theme, as in the prototype). */
|
|
861
|
+
.v-overlay.v-theme--hero-light > .v-overlay__scrim, .v-overlay.v-theme--hero-dark > .v-overlay__scrim { background: rgb(var(--v-hero-neutral-900)) !important; opacity: 0.5 !important; }
|
|
862
|
+
.hero-dialog__note { font-size: 12px; opacity: 0.65; }
|
|
863
|
+
.hero-notice--error { border-left-color: var(--hero-accent); }
|
|
864
|
+
.hero-input:disabled { opacity: 0.6; cursor: not-allowed; }
|
|
865
|
+
.hero-log__when { font-variant-numeric: tabular-nums; opacity: 0.7; white-space: nowrap; }
|
|
866
|
+
.hero-log__who, .hero-log__target { font-weight: 600; }
|
|
867
|
+
|
|
842
868
|
/* ----------------------------------------------------------- animations */
|
|
843
869
|
|
|
844
870
|
/* ============================================ HERO phase (d): building map, editor, lift queue */
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<!--
|
|
3
|
+
ACTIVITY LOG (README §7): When · Who · Action · Target - commands, robots
|
|
4
|
+
added / edited / removed (demo robots too), building-map saves and lift
|
|
5
|
+
requests, newest first, server paged. Read from the audit trail (read
|
|
6
|
+
only); the first page refreshes every 10 s while visible, so a command
|
|
7
|
+
sent from another screen appears at the top on its own.
|
|
8
|
+
-->
|
|
9
|
+
<div class="hero-head">
|
|
10
|
+
<div>
|
|
11
|
+
<button v-if="backToNetwork" type="button" class="hero-back hero-back--sm" @click="emit('network')">‹ Network</button>
|
|
12
|
+
<div class="hero-kicker hero-kicker--accent">{{ kicker }}</div>
|
|
13
|
+
<h2 class="hero-title">Activity log</h2>
|
|
14
|
+
</div>
|
|
15
|
+
</div>
|
|
16
|
+
|
|
17
|
+
<div v-if="error && !rows.length" class="hero-notice" role="alert">{{ error }}</div>
|
|
18
|
+
<div v-else-if="error" class="hero-notice" role="status">Reconnecting… the log shows its last reading.</div>
|
|
19
|
+
<RobotTable
|
|
20
|
+
v-if="!(error && !rows.length)"
|
|
21
|
+
:headers="headers"
|
|
22
|
+
:items="rows"
|
|
23
|
+
:items-length="total"
|
|
24
|
+
:page="page"
|
|
25
|
+
:items-per-page="limit"
|
|
26
|
+
:loading="loading"
|
|
27
|
+
noun="entries"
|
|
28
|
+
empty-title="No activity yet"
|
|
29
|
+
empty-hint="Commands, robots added or removed, building map saves and lift requests appear here as they happen."
|
|
30
|
+
compact
|
|
31
|
+
paged-foot
|
|
32
|
+
item-value="id"
|
|
33
|
+
@update:page="load"
|
|
34
|
+
>
|
|
35
|
+
<template #item.when="{ item }"><span class="hero-log__when">{{ item.when }}</span></template>
|
|
36
|
+
<template #item.who="{ item }"><span class="hero-log__who">{{ item.who }}</span></template>
|
|
37
|
+
<template #item.target="{ item }"><span class="hero-log__target">{{ item.target }}</span></template>
|
|
38
|
+
</RobotTable>
|
|
39
|
+
</template>
|
|
40
|
+
|
|
41
|
+
<script setup lang="ts">
|
|
42
|
+
import { computed, onBeforeUnmount, ref, watch } from "vue";
|
|
43
|
+
import RobotTable from "./Table.vue";
|
|
44
|
+
import { activityRow, listMeta } from "../../utils/robot-display";
|
|
45
|
+
|
|
46
|
+
const props = withDefaults(
|
|
47
|
+
defineProps<{
|
|
48
|
+
/** The site whose robots' activity to show; ignored with `network`. */
|
|
49
|
+
site?: string;
|
|
50
|
+
/** Seven365 Super Admin: every client's robots (`/robots/network/activity`). */
|
|
51
|
+
network?: boolean;
|
|
52
|
+
/** One robot only. */
|
|
53
|
+
robot?: string;
|
|
54
|
+
siteName?: string;
|
|
55
|
+
clientName?: string;
|
|
56
|
+
backToNetwork?: boolean;
|
|
57
|
+
limit?: number;
|
|
58
|
+
pollMs?: number;
|
|
59
|
+
}>(),
|
|
60
|
+
{ site: "", network: false, robot: "", siteName: "", clientName: "", backToNetwork: false, limit: 25, pollMs: 10000 },
|
|
61
|
+
);
|
|
62
|
+
const emit = defineEmits<{ network: [] }>();
|
|
63
|
+
|
|
64
|
+
const { getSiteActivity, getNetworkActivity } = useRobots();
|
|
65
|
+
const raw = ref<any[]>([]);
|
|
66
|
+
const total = ref(0);
|
|
67
|
+
const page = ref(1);
|
|
68
|
+
const loading = ref(true);
|
|
69
|
+
const error = ref("");
|
|
70
|
+
const now = ref(Date.now());
|
|
71
|
+
|
|
72
|
+
const rows = computed(() => raw.value.map((e) => activityRow(e, now.value)));
|
|
73
|
+
const kicker = computed(() => (props.network ? "Whole network" : [props.clientName, props.siteName].filter(Boolean).join(" · ")));
|
|
74
|
+
const headers = [
|
|
75
|
+
{ title: "When", key: "when", sortable: false },
|
|
76
|
+
{ title: "Who", key: "who", sortable: false },
|
|
77
|
+
{ title: "Action", key: "action", sortable: false },
|
|
78
|
+
{ title: "Target", key: "target", sortable: false },
|
|
79
|
+
];
|
|
80
|
+
|
|
81
|
+
async function load(next = page.value) {
|
|
82
|
+
page.value = next;
|
|
83
|
+
try {
|
|
84
|
+
const res = props.network
|
|
85
|
+
? await getNetworkActivity({ page: next, limit: props.limit })
|
|
86
|
+
: await getSiteActivity(props.site, { page: next, limit: props.limit, robot: props.robot });
|
|
87
|
+
raw.value = res?.items ?? [];
|
|
88
|
+
total.value = listMeta(res, props.limit).total;
|
|
89
|
+
error.value = "";
|
|
90
|
+
} catch (e) {
|
|
91
|
+
error.value = (e as any)?.data?.message || "Can't reach the activity log right now. Reconnecting…";
|
|
92
|
+
} finally {
|
|
93
|
+
loading.value = false;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Newest first: only the first page refreshes - an older page stays where the reader left it.
|
|
98
|
+
const timer = setInterval(() => {
|
|
99
|
+
now.value = Date.now();
|
|
100
|
+
if (typeof document !== "undefined" && document.visibilityState === "hidden") return;
|
|
101
|
+
if (page.value === 1) load(1);
|
|
102
|
+
}, props.pollMs);
|
|
103
|
+
onBeforeUnmount(() => clearInterval(timer));
|
|
104
|
+
|
|
105
|
+
watch(
|
|
106
|
+
[() => props.site, () => props.network, () => props.robot],
|
|
107
|
+
() => {
|
|
108
|
+
loading.value = true;
|
|
109
|
+
load(1);
|
|
110
|
+
},
|
|
111
|
+
{ immediate: true },
|
|
112
|
+
);
|
|
113
|
+
</script>
|
|
@@ -97,24 +97,25 @@
|
|
|
97
97
|
</div>
|
|
98
98
|
</div>
|
|
99
99
|
|
|
100
|
-
<v-dialog v-model="editOpen" width="
|
|
100
|
+
<v-dialog v-model="editOpen" width="520" persistent>
|
|
101
101
|
<RobotForm
|
|
102
102
|
v-if="editOpen && record"
|
|
103
103
|
:key="record._id"
|
|
104
104
|
:organization="String(record.client?._id ?? '')"
|
|
105
105
|
:site="String(record.site?._id ?? '')"
|
|
106
106
|
:type="robotType"
|
|
107
|
-
:
|
|
107
|
+
:types="types.length ? types : [robotType]"
|
|
108
|
+
:robot="{ ...record, brandName: brand }"
|
|
108
109
|
@cancel="editOpen = false"
|
|
109
110
|
@saved="onSaved"
|
|
110
111
|
/>
|
|
111
112
|
</v-dialog>
|
|
112
113
|
|
|
113
|
-
<v-dialog v-model="removeOpen" width="
|
|
114
|
+
<v-dialog v-model="removeOpen" width="440">
|
|
114
115
|
<div class="hero-dialog" role="alertdialog" aria-labelledby="hero-remove-title">
|
|
115
116
|
<div id="hero-remove-title" class="hero-dialog__title">Remove {{ record?.name }}?</div>
|
|
116
117
|
<div class="hero-dialog__body">
|
|
117
|
-
|
|
118
|
+
The robot is removed from {{ record?.site?.name || "this site" }} and stops reporting. Its activity history is kept. This cannot be undone from here.
|
|
118
119
|
</div>
|
|
119
120
|
<div class="hero-dialog__actions">
|
|
120
121
|
<v-btn variant="outlined" :disabled="removing" @click="removeOpen = false">Keep robot</v-btn>
|
|
@@ -174,9 +175,11 @@ const props = withDefaults(
|
|
|
174
175
|
canEdit?: boolean;
|
|
175
176
|
canCommand?: boolean;
|
|
176
177
|
canDelete?: boolean;
|
|
178
|
+
/** The robot types this app presents - the edit dialog shows Type only with both. */
|
|
179
|
+
types?: Array<"cleaning" | "security">;
|
|
177
180
|
tickMs?: number;
|
|
178
181
|
}>(),
|
|
179
|
-
{ backLabel: "", canEdit: false, canCommand: false, canDelete: false, tickMs: 1200 },
|
|
182
|
+
{ backLabel: "", canEdit: false, canCommand: false, canDelete: false, types: () => [], tickMs: 1200 },
|
|
180
183
|
);
|
|
181
184
|
const emit = defineEmits<{
|
|
182
185
|
back: [];
|
|
@@ -1,254 +1,210 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
<InputLabel class="font-weight-bold" title="Serial number" />
|
|
83
|
-
<v-text-field
|
|
84
|
-
v-model="robotSn"
|
|
85
|
-
density="comfortable"
|
|
86
|
-
placeholder="Optional — found automatically if left blank"
|
|
87
|
-
:disabled="saving"
|
|
88
|
-
/>
|
|
89
|
-
<p class="text-caption text-medium-emphasis mt-n3 mb-2">
|
|
90
|
-
Leave this blank unless the same key covers more than one robot.
|
|
91
|
-
</p>
|
|
92
|
-
</v-col>
|
|
93
|
-
|
|
94
|
-
<v-col cols="12" v-if="error">
|
|
95
|
-
<v-alert type="error" variant="tonal" class="mb-3" :text="error" />
|
|
96
|
-
</v-col>
|
|
97
|
-
</v-row>
|
|
98
|
-
</v-form>
|
|
99
|
-
</v-card-text>
|
|
100
|
-
|
|
101
|
-
<v-toolbar density="compact">
|
|
102
|
-
<v-row no-gutters>
|
|
103
|
-
<v-col cols="6">
|
|
104
|
-
<v-btn
|
|
105
|
-
tile block variant="flat" size="48"
|
|
106
|
-
class="text-none" color="#EFEFEF"
|
|
107
|
-
:disabled="saving"
|
|
108
|
-
@click="$emit('cancel')"
|
|
109
|
-
>
|
|
110
|
-
Close
|
|
111
|
-
</v-btn>
|
|
112
|
-
</v-col>
|
|
113
|
-
<v-col cols="6">
|
|
114
|
-
<v-btn
|
|
115
|
-
tile block variant="flat" size="48"
|
|
116
|
-
class="text-none" color="primary"
|
|
117
|
-
:loading="saving"
|
|
118
|
-
@click="submit"
|
|
119
|
-
>
|
|
120
|
-
{{ editing ? "Save" : "Add robot" }}
|
|
121
|
-
</v-btn>
|
|
122
|
-
</v-col>
|
|
123
|
-
</v-row>
|
|
124
|
-
</v-toolbar>
|
|
125
|
-
</v-card>
|
|
2
|
+
<!--
|
|
3
|
+
Add / edit robot (HERO README §8): a 520px dialog - Name · Type (only when
|
|
4
|
+
the account presents both types) · Brand (filtered by type; each option
|
|
5
|
+
shows its capability) · Site · App key · Token (password fields), the
|
|
6
|
+
credentials note with the brand's capability, Cancel / Save robot.
|
|
7
|
+
|
|
8
|
+
Credentials are write-only: the stored pair never reaches the browser, so
|
|
9
|
+
when editing both fields say "Saved · hidden. Enter to replace" and are
|
|
10
|
+
sent only when BOTH are typed (a replacement). Editing keeps the robot's
|
|
11
|
+
type, brand and site (a different brand is a different robot; a move is a
|
|
12
|
+
remove and add) - shown, not changeable.
|
|
13
|
+
-->
|
|
14
|
+
<form class="hero-dialog hero-dialog--form" :aria-labelledby="titleId" @submit.prevent="submit">
|
|
15
|
+
<div :id="titleId" class="hero-dialog__title">{{ editing ? "Edit robot" : "Add robot" }}</div>
|
|
16
|
+
<div class="hero-form-grid">
|
|
17
|
+
<div class="hero-field hero-form-grid__full">
|
|
18
|
+
<label :for="`${uid}-name`">Name</label>
|
|
19
|
+
<input :id="`${uid}-name`" v-model="name" class="hero-input" placeholder="e.g. HERO-C12" autocomplete="off" :disabled="saving" />
|
|
20
|
+
</div>
|
|
21
|
+
<div v-if="types.length > 1" class="hero-field">
|
|
22
|
+
<label :for="`${uid}-type`">Type</label>
|
|
23
|
+
<select :id="`${uid}-type`" v-model="type" class="hero-input" :disabled="saving || editing" @change="brand = ''">
|
|
24
|
+
<option v-for="t in types" :key="t" :value="t">{{ typeLabel(t) }}</option>
|
|
25
|
+
</select>
|
|
26
|
+
</div>
|
|
27
|
+
<div class="hero-field">
|
|
28
|
+
<label :for="`${uid}-brand`">Brand</label>
|
|
29
|
+
<select :id="`${uid}-brand`" v-model="brand" class="hero-input" :disabled="saving || editing || !options.length">
|
|
30
|
+
<option v-if="!options.length" value="">{{ loadingBrands ? "Loading brands…" : "No brand for this type" }}</option>
|
|
31
|
+
<option v-for="o in options" :key="o.value" :value="o.value">{{ o.label }}</option>
|
|
32
|
+
</select>
|
|
33
|
+
</div>
|
|
34
|
+
<div v-if="clients.length && !editing" class="hero-field hero-form-grid__full">
|
|
35
|
+
<label :for="`${uid}-client`">Client</label>
|
|
36
|
+
<select :id="`${uid}-client`" v-model="org" class="hero-input" :disabled="saving" @change="onClient">
|
|
37
|
+
<option value="" disabled>Choose a client</option>
|
|
38
|
+
<option v-for="c in clients" :key="c._id" :value="c._id">{{ c.name }}</option>
|
|
39
|
+
</select>
|
|
40
|
+
</div>
|
|
41
|
+
<div class="hero-field hero-form-grid__full">
|
|
42
|
+
<label :for="`${uid}-site`">Site</label>
|
|
43
|
+
<select :id="`${uid}-site`" v-model="site" class="hero-input" :disabled="saving || editing || !siteOptions.length">
|
|
44
|
+
<option v-if="!siteOptions.length" value="">{{ clients.length ? "Choose a client first" : "No site" }}</option>
|
|
45
|
+
<option v-for="s in siteOptions" :key="s._id" :value="s._id">{{ s.name }}</option>
|
|
46
|
+
</select>
|
|
47
|
+
</div>
|
|
48
|
+
<div class="hero-field">
|
|
49
|
+
<label :for="`${uid}-key`">App key</label>
|
|
50
|
+
<input
|
|
51
|
+
:id="`${uid}-key`"
|
|
52
|
+
v-model="appKey"
|
|
53
|
+
class="hero-input"
|
|
54
|
+
type="password"
|
|
55
|
+
autocomplete="new-password"
|
|
56
|
+
spellcheck="false"
|
|
57
|
+
:placeholder="credentialPlaceholder(editing)"
|
|
58
|
+
:disabled="saving"
|
|
59
|
+
/>
|
|
60
|
+
</div>
|
|
61
|
+
<div class="hero-field">
|
|
62
|
+
<label :for="`${uid}-token`">Token</label>
|
|
63
|
+
<input
|
|
64
|
+
:id="`${uid}-token`"
|
|
65
|
+
v-model="appToken"
|
|
66
|
+
class="hero-input"
|
|
67
|
+
type="password"
|
|
68
|
+
autocomplete="new-password"
|
|
69
|
+
spellcheck="false"
|
|
70
|
+
:placeholder="credentialPlaceholder(editing)"
|
|
71
|
+
:disabled="saving"
|
|
72
|
+
/>
|
|
73
|
+
</div>
|
|
74
|
+
</div>
|
|
75
|
+
<div class="hero-dialog__note">{{ CREDENTIALS_NOTE }} Capability: {{ note }}</div>
|
|
76
|
+
<div v-if="error" class="hero-notice hero-notice--error" role="alert">{{ error }}</div>
|
|
77
|
+
<div class="hero-dialog__actions">
|
|
78
|
+
<v-btn variant="outlined" :disabled="saving" @click="emit('cancel')">Cancel</v-btn>
|
|
79
|
+
<v-btn type="submit" color="primary" variant="flat" :loading="saving">Save robot</v-btn>
|
|
80
|
+
</div>
|
|
81
|
+
</form>
|
|
126
82
|
</template>
|
|
127
83
|
|
|
128
84
|
<script lang="ts" setup>
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
* exactly when the person filling this in should type it themselves.
|
|
141
|
-
*/
|
|
142
|
-
import { robotErrorMessage } from "../../utils/robot-display";
|
|
85
|
+
import { computed, onMounted, ref, useId, watch } from "vue";
|
|
86
|
+
import {
|
|
87
|
+
brandOptions,
|
|
88
|
+
capabilityNote,
|
|
89
|
+
credentialPatch,
|
|
90
|
+
credentialPlaceholder,
|
|
91
|
+
CREDENTIALS_NOTE,
|
|
92
|
+
robotErrorMessage,
|
|
93
|
+
typeLabel,
|
|
94
|
+
type TRobotType,
|
|
95
|
+
} from "../../utils/robot-display";
|
|
143
96
|
|
|
144
97
|
const props = withDefaults(
|
|
145
98
|
defineProps<{
|
|
146
|
-
organization
|
|
147
|
-
site
|
|
148
|
-
type
|
|
149
|
-
|
|
99
|
+
organization?: string;
|
|
100
|
+
site?: string;
|
|
101
|
+
/** The type to start on (the header's switch). */
|
|
102
|
+
type?: TRobotType;
|
|
103
|
+
/** The types this account presents - the Type select shows only with both (scope isolation). */
|
|
104
|
+
types?: TRobotType[];
|
|
105
|
+
/** The sites this person may add to; the current one when empty. */
|
|
106
|
+
sites?: Array<{ _id: string; name: string }>;
|
|
107
|
+
siteName?: string;
|
|
108
|
+
/** Super Admin: pick the client first (`update:client` asks the host for its sites). */
|
|
109
|
+
clients?: Array<{ _id: string; name: string }>;
|
|
110
|
+
/** When given, the dialog edits this robot (`{ _id, name, type, brand, site }`). */
|
|
150
111
|
robot?: Record<string, any> | null;
|
|
151
112
|
}>(),
|
|
152
|
-
{ type: "cleaning", robot: null },
|
|
113
|
+
{ organization: "", site: "", type: "cleaning", types: () => ["cleaning"], sites: () => [], siteName: "", clients: () => [], robot: null },
|
|
153
114
|
);
|
|
154
|
-
|
|
155
|
-
|
|
115
|
+
const emit = defineEmits<{
|
|
116
|
+
cancel: [];
|
|
117
|
+
created: [robot: { name: string; site: string }];
|
|
118
|
+
saved: [name: string];
|
|
119
|
+
"update:client": [org: string];
|
|
120
|
+
}>();
|
|
156
121
|
|
|
157
122
|
const { createRobot, updateRobot, getRobotBrands } = useRobots();
|
|
123
|
+
const uid = useId();
|
|
124
|
+
const titleId = `${uid}-title`;
|
|
158
125
|
const editing = computed(() => !!props.robot?._id);
|
|
159
|
-
const { requiredRule } = useUtils();
|
|
160
126
|
|
|
161
|
-
const
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
const
|
|
127
|
+
const name = ref(String(props.robot?.name ?? ""));
|
|
128
|
+
const type = ref<TRobotType>(
|
|
129
|
+
(props.robot?.type as TRobotType) ?? (props.types.includes(props.type) ? props.type : props.types[0] ?? "cleaning"),
|
|
130
|
+
);
|
|
131
|
+
const brand = ref(String(props.robot?.brand ?? ""));
|
|
132
|
+
const org = ref(props.organization);
|
|
133
|
+
const site = ref(String(props.robot?.site?._id ?? props.site ?? ""));
|
|
166
134
|
const appKey = ref("");
|
|
167
135
|
const appToken = ref("");
|
|
168
|
-
const robotSn = ref(props.robot?.robotSn ?? "");
|
|
169
|
-
const reveal = ref(false);
|
|
170
136
|
const saving = ref(false);
|
|
171
137
|
const error = ref("");
|
|
172
138
|
|
|
173
|
-
const
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
}
|
|
139
|
+
const brands = ref<Array<Record<string, any>>>([]);
|
|
140
|
+
const loadingBrands = ref(false);
|
|
141
|
+
const options = computed(() => {
|
|
142
|
+
const list = brandOptions(brands.value, type.value);
|
|
143
|
+
// Editing: the robot's own brand is shown even if this build no longer registers it.
|
|
144
|
+
if (editing.value && brand.value && !list.some((o) => o.value === brand.value)) {
|
|
145
|
+
return [{ value: brand.value, label: String(props.robot?.brandName ?? brand.value), capabilities: {} }, ...list];
|
|
146
|
+
}
|
|
147
|
+
return list;
|
|
148
|
+
});
|
|
149
|
+
// The first brand for the type is preselected, as in the prototype; editing keeps the robot's own.
|
|
150
|
+
watch(
|
|
151
|
+
options,
|
|
152
|
+
(list) => {
|
|
153
|
+
if (!list.some((o) => o.value === brand.value)) brand.value = list.length === 1 || !editing.value ? list[0]?.value ?? "" : brand.value;
|
|
154
|
+
},
|
|
155
|
+
{ immediate: true },
|
|
156
|
+
);
|
|
157
|
+
const note = computed(() => capabilityNote(options.value.find((o) => o.value === brand.value)?.capabilities, type.value));
|
|
189
158
|
|
|
190
|
-
const
|
|
191
|
-
|
|
192
|
-
|
|
159
|
+
const siteOptions = computed(() => {
|
|
160
|
+
if (props.sites.length) return props.sites;
|
|
161
|
+
const current = site.value || props.site;
|
|
162
|
+
return current ? [{ _id: current, name: String(props.robot?.site?.name ?? props.siteName ?? "") || "This site" }] : [];
|
|
193
163
|
});
|
|
164
|
+
watch(siteOptions, (list) => {
|
|
165
|
+
if (!list.some((s) => s._id === site.value)) site.value = list[0]?._id ?? "";
|
|
166
|
+
});
|
|
167
|
+
function onClient() {
|
|
168
|
+
site.value = "";
|
|
169
|
+
emit("update:client", org.value);
|
|
170
|
+
}
|
|
194
171
|
|
|
195
|
-
async
|
|
172
|
+
onMounted(async () => {
|
|
196
173
|
loadingBrands.value = true;
|
|
197
174
|
try {
|
|
198
|
-
|
|
199
|
-
brands.value = (res?.items ?? []).map((b: any) => ({
|
|
200
|
-
...b,
|
|
201
|
-
label: b.displayName ?? b.brand,
|
|
202
|
-
}));
|
|
203
|
-
// Only preselect when there is no choice to make. Guessing a brand is how a
|
|
204
|
-
// robot ends up being sent commands in a protocol it does not speak.
|
|
205
|
-
if (brands.value.length === 1) brand.value = brands.value[0].brand;
|
|
175
|
+
brands.value = (await getRobotBrands())?.items ?? [];
|
|
206
176
|
} catch {
|
|
207
177
|
brands.value = [];
|
|
208
178
|
} finally {
|
|
209
179
|
loadingBrands.value = false;
|
|
210
180
|
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
onMounted(() => {
|
|
214
|
-
if (!editing.value) loadBrands();
|
|
215
181
|
});
|
|
216
182
|
|
|
217
183
|
async function submit() {
|
|
218
|
-
const { valid } = await form.value?.validate?.() ?? { valid: false };
|
|
219
|
-
if (!valid) return;
|
|
220
|
-
|
|
221
|
-
saving.value = true;
|
|
222
184
|
error.value = "";
|
|
223
|
-
if (
|
|
224
|
-
|
|
225
|
-
|
|
185
|
+
if (!name.value.trim()) return void (error.value = "Give the robot a name.");
|
|
186
|
+
const creds = credentialPatch(appKey.value, appToken.value, editing.value);
|
|
187
|
+
if (!creds.ok) return void (error.value = creds.message);
|
|
188
|
+
saving.value = true;
|
|
189
|
+
try {
|
|
190
|
+
if (editing.value) {
|
|
191
|
+
await updateRobot(String(props.robot!._id), { name: name.value.trim(), ...creds.body });
|
|
192
|
+
emit("saved", name.value.trim());
|
|
193
|
+
} else {
|
|
194
|
+
if (!brand.value) throw new Error("Choose the robot's brand.");
|
|
195
|
+
if (!site.value) throw new Error("Choose the site the robot works at.");
|
|
196
|
+
await createRobot({
|
|
226
197
|
name: name.value.trim(),
|
|
227
|
-
|
|
198
|
+
brand: brand.value,
|
|
199
|
+
type: type.value,
|
|
200
|
+
appKey: creds.body.appKey!,
|
|
201
|
+
appToken: creds.body.appToken!,
|
|
202
|
+
metadata: { orgId: org.value, siteId: site.value },
|
|
228
203
|
});
|
|
229
|
-
emit("
|
|
230
|
-
} catch (e) {
|
|
231
|
-
error.value = robotErrorMessage(e, "Could not save the robot.");
|
|
232
|
-
} finally {
|
|
233
|
-
saving.value = false;
|
|
204
|
+
emit("created", { name: name.value.trim(), site: site.value });
|
|
234
205
|
}
|
|
235
|
-
return;
|
|
236
|
-
}
|
|
237
|
-
try {
|
|
238
|
-
await createRobot({
|
|
239
|
-
name: name.value.trim(),
|
|
240
|
-
brand: brand.value,
|
|
241
|
-
appKey: appKey.value.trim(),
|
|
242
|
-
appToken: appToken.value.trim(),
|
|
243
|
-
type: props.type,
|
|
244
|
-
// Sent only when the person typed one; an empty string would otherwise be
|
|
245
|
-
// stored and stop the server ever discovering the real serial.
|
|
246
|
-
...(robotSn.value.trim() ? { robotSn: robotSn.value.trim() } : {}),
|
|
247
|
-
metadata: { orgId: props.organization, siteId: props.site },
|
|
248
|
-
});
|
|
249
|
-
emit("created");
|
|
250
206
|
} catch (e) {
|
|
251
|
-
error.value = robotErrorMessage(e, "Could not add the robot.");
|
|
207
|
+
error.value = robotErrorMessage(e, editing.value ? "Could not save the robot." : "Could not add the robot.");
|
|
252
208
|
} finally {
|
|
253
209
|
saving.value = false;
|
|
254
210
|
}
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
>
|
|
33
33
|
<span class="hero-bot__ping" aria-hidden="true" />
|
|
34
34
|
<span class="hero-bot__body" :style="{ transform: r.rot }" aria-hidden="true"><span class="hero-bot__tick" /></span>
|
|
35
|
-
<span class="hero-bot__name">{{ r.name }}</span>
|
|
35
|
+
<span class="hero-bot__name" :class="tagClass(r)">{{ r.name }}</span>
|
|
36
36
|
</button>
|
|
37
37
|
<RobotReconnecting v-if="!connected" />
|
|
38
38
|
</RobotFloorPlan>
|
|
@@ -56,6 +56,7 @@ import {
|
|
|
56
56
|
floorLabel,
|
|
57
57
|
mapFloors,
|
|
58
58
|
mapRobots,
|
|
59
|
+
nameTagSide,
|
|
59
60
|
pickFloor,
|
|
60
61
|
robotStatus,
|
|
61
62
|
unplacedRobots,
|
|
@@ -116,5 +117,10 @@ const TONE: Record<string, string> = {
|
|
|
116
117
|
accent: "var(--hero-accent)",
|
|
117
118
|
ink: "var(--hero-text)",
|
|
118
119
|
};
|
|
120
|
+
/** Name tags stay inside the plan: flipped left near the right edge, below near the top. */
|
|
121
|
+
function tagClass(r: TMapRobot) {
|
|
122
|
+
const side = nameTagSide(r.left, r.top, r.name);
|
|
123
|
+
return { "hero-bot__name--left": side.flipX, "hero-bot__name--below": side.below };
|
|
124
|
+
}
|
|
119
125
|
const toneColor = (r: TMapRobot) => TONE[robotStatus(r.mode, r.type).tone] ?? TONE.ink;
|
|
120
126
|
</script>
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<!--
|
|
3
|
+
ALERTS (README §6), one site: kicker "{client} · {site}", "Faults & alerts"
|
|
4
|
+
and "Each occurrence notified once"; the table Code · Message · Robot ·
|
|
5
|
+
Site · Floor · Since · ›, faults first then robots not reporting, server
|
|
6
|
+
paged; "No active faults" when there are none. Every robot type this app
|
|
7
|
+
presents (the API narrows by app), refreshed every 10 s while visible.
|
|
8
|
+
-->
|
|
9
|
+
<div class="hero-head">
|
|
10
|
+
<div>
|
|
11
|
+
<button v-if="backToNetwork" type="button" class="hero-back hero-back--sm" @click="emit('network')">‹ Network</button>
|
|
12
|
+
<div class="hero-kicker hero-kicker--accent">{{ kicker }}</div>
|
|
13
|
+
<h2 class="hero-title">Faults & alerts</h2>
|
|
14
|
+
</div>
|
|
15
|
+
<span class="hero-head__spacer" />
|
|
16
|
+
<span class="hero-note">Each occurrence notified once</span>
|
|
17
|
+
</div>
|
|
18
|
+
|
|
19
|
+
<div v-if="error && !items.length" class="hero-notice" role="alert">{{ error }}</div>
|
|
20
|
+
<div v-else-if="error" class="hero-notice" role="status">Reconnecting… the alerts show their last reading.</div>
|
|
21
|
+
<RobotAlertsTable
|
|
22
|
+
v-if="!(error && !items.length)"
|
|
23
|
+
:items="items"
|
|
24
|
+
:total="total"
|
|
25
|
+
:page="page"
|
|
26
|
+
:items-per-page="limit"
|
|
27
|
+
:loading="loading"
|
|
28
|
+
:states="states"
|
|
29
|
+
:now="now"
|
|
30
|
+
@update:page="load"
|
|
31
|
+
@open="(f) => emit('open', String(f?.robot?._id ?? ''))"
|
|
32
|
+
/>
|
|
33
|
+
</template>
|
|
34
|
+
|
|
35
|
+
<script setup lang="ts">
|
|
36
|
+
import { computed, onBeforeUnmount, ref, watch } from "vue";
|
|
37
|
+
import RobotAlertsTable from "./AlertsTable.vue";
|
|
38
|
+
import useRobotLive, { siteStatesFeed } from "../../composables/useRobotLive";
|
|
39
|
+
import { listMeta } from "../../utils/robot-display";
|
|
40
|
+
|
|
41
|
+
const props = withDefaults(
|
|
42
|
+
defineProps<{
|
|
43
|
+
site: string;
|
|
44
|
+
siteName?: string;
|
|
45
|
+
clientName?: string;
|
|
46
|
+
backToNetwork?: boolean;
|
|
47
|
+
limit?: number;
|
|
48
|
+
pollMs?: number;
|
|
49
|
+
}>(),
|
|
50
|
+
{ siteName: "", clientName: "", backToNetwork: false, limit: 25, pollMs: 10000 },
|
|
51
|
+
);
|
|
52
|
+
const emit = defineEmits<{
|
|
53
|
+
open: [robotId: string];
|
|
54
|
+
network: [];
|
|
55
|
+
status: [status: { connected: boolean; faults: number; siteName: string; clientName: string }];
|
|
56
|
+
}>();
|
|
57
|
+
|
|
58
|
+
const { getSiteFaults } = useRobots();
|
|
59
|
+
const items = ref<any[]>([]);
|
|
60
|
+
const total = ref(0);
|
|
61
|
+
const faults = ref(0);
|
|
62
|
+
const page = ref(1);
|
|
63
|
+
const loading = ref(true);
|
|
64
|
+
const error = ref("");
|
|
65
|
+
const now = ref(Date.now());
|
|
66
|
+
|
|
67
|
+
const first = computed(() => items.value[0] ?? null);
|
|
68
|
+
const kicker = computed(() =>
|
|
69
|
+
[props.clientName || first.value?.client?.name, props.siteName || first.value?.site?.name].filter(Boolean).join(" · "),
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
async function load(next = page.value) {
|
|
73
|
+
page.value = next;
|
|
74
|
+
try {
|
|
75
|
+
const res = await getSiteFaults(props.site, { page: next, limit: props.limit });
|
|
76
|
+
items.value = res?.items ?? [];
|
|
77
|
+
total.value = listMeta(res, props.limit).total;
|
|
78
|
+
faults.value = Number(res?.faults ?? 0);
|
|
79
|
+
error.value = "";
|
|
80
|
+
} catch (e) {
|
|
81
|
+
error.value = (e as any)?.data?.message || "Can't reach the alerts right now. Reconnecting…";
|
|
82
|
+
} finally {
|
|
83
|
+
loading.value = false;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/* Floor: the live state of the robots on this page (never a guess - "Floor unknown"). */
|
|
88
|
+
const ids = computed(() => [...new Set(items.value.map((f) => String(f?.robot?._id ?? "")).filter(Boolean))]);
|
|
89
|
+
const { states, connected } = useRobotLive(ids, siteStatesFeed());
|
|
90
|
+
|
|
91
|
+
const timer = setInterval(() => {
|
|
92
|
+
now.value = Date.now();
|
|
93
|
+
if (typeof document !== "undefined" && document.visibilityState === "hidden") return;
|
|
94
|
+
load();
|
|
95
|
+
}, props.pollMs);
|
|
96
|
+
onBeforeUnmount(() => clearInterval(timer));
|
|
97
|
+
|
|
98
|
+
watch(
|
|
99
|
+
() => props.site,
|
|
100
|
+
() => {
|
|
101
|
+
loading.value = true;
|
|
102
|
+
load(1);
|
|
103
|
+
},
|
|
104
|
+
{ immediate: true },
|
|
105
|
+
);
|
|
106
|
+
watch(
|
|
107
|
+
[() => !error.value && connected.value, faults, kicker],
|
|
108
|
+
([up, count]) =>
|
|
109
|
+
emit("status", {
|
|
110
|
+
connected: up,
|
|
111
|
+
faults: count,
|
|
112
|
+
siteName: props.siteName || first.value?.site?.name || "",
|
|
113
|
+
clientName: props.clientName || first.value?.client?.name || "",
|
|
114
|
+
}),
|
|
115
|
+
{ immediate: true },
|
|
116
|
+
);
|
|
117
|
+
</script>
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
:types="types"
|
|
17
17
|
:type="type"
|
|
18
18
|
:connected="connected"
|
|
19
|
-
:faults="
|
|
19
|
+
:faults="alertCount"
|
|
20
20
|
:role="role"
|
|
21
21
|
@update:site="(id) => emit('update:site', id)"
|
|
22
22
|
@update:type="setType"
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
:can-edit="canEdit"
|
|
32
32
|
:can-command="canCommand"
|
|
33
33
|
:can-delete="canDelete"
|
|
34
|
+
:types="types"
|
|
34
35
|
@back="emit('back')"
|
|
35
36
|
@removed="onRemoved"
|
|
36
37
|
@status="(s) => (connected = s.connected)"
|
|
@@ -64,6 +65,26 @@
|
|
|
64
65
|
@network="emit('network')"
|
|
65
66
|
@status="onFleetStatus"
|
|
66
67
|
/>
|
|
68
|
+
<RobotSiteAlerts
|
|
69
|
+
v-else-if="view === 'alerts'"
|
|
70
|
+
:key="`alerts:${site}`"
|
|
71
|
+
:site="site"
|
|
72
|
+
:site-name="siteName || names.siteName"
|
|
73
|
+
:client-name="clientName || names.clientName"
|
|
74
|
+
:back-to-network="backToNetwork"
|
|
75
|
+
@open="(id) => emit('open', id)"
|
|
76
|
+
@network="emit('network')"
|
|
77
|
+
@status="onFleetStatus"
|
|
78
|
+
/>
|
|
79
|
+
<RobotActivityLog
|
|
80
|
+
v-else-if="view === 'log'"
|
|
81
|
+
:key="`log:${site}`"
|
|
82
|
+
:site="site"
|
|
83
|
+
:site-name="siteName || names.siteName"
|
|
84
|
+
:client-name="clientName || names.clientName"
|
|
85
|
+
:back-to-network="backToNetwork"
|
|
86
|
+
@network="emit('network')"
|
|
87
|
+
/>
|
|
67
88
|
<RobotSiteFleet
|
|
68
89
|
v-else
|
|
69
90
|
:organization="organization"
|
|
@@ -81,12 +102,15 @@
|
|
|
81
102
|
/>
|
|
82
103
|
</main>
|
|
83
104
|
|
|
84
|
-
<v-dialog v-model="addOpen" width="
|
|
105
|
+
<v-dialog v-model="addOpen" width="520" persistent>
|
|
85
106
|
<RobotForm
|
|
86
107
|
v-if="addOpen"
|
|
87
108
|
:organization="organization"
|
|
88
109
|
:site="site"
|
|
110
|
+
:site-name="siteName || names.siteName"
|
|
111
|
+
:sites="sites"
|
|
89
112
|
:type="type"
|
|
113
|
+
:types="types"
|
|
90
114
|
@cancel="addOpen = false"
|
|
91
115
|
@created="onCreated"
|
|
92
116
|
/>
|
|
@@ -96,13 +120,15 @@
|
|
|
96
120
|
</template>
|
|
97
121
|
|
|
98
122
|
<script setup lang="ts">
|
|
99
|
-
import { computed, ref, watch } from "vue";
|
|
123
|
+
import { computed, onBeforeUnmount, ref, watch } from "vue";
|
|
100
124
|
import RobotHero from "./Hero.vue";
|
|
101
125
|
import RobotSiteHeader from "./SiteHeader.vue";
|
|
102
126
|
import RobotSiteFleet from "./SiteFleet.vue";
|
|
103
127
|
import RobotDetail from "./Detail.vue";
|
|
104
128
|
import RobotBuildingMap from "./BuildingMap.vue";
|
|
105
129
|
import RobotLiftQueue from "./LiftQueue.vue";
|
|
130
|
+
import RobotSiteAlerts from "./SiteAlerts.vue";
|
|
131
|
+
import RobotActivityLog from "./ActivityLog.vue";
|
|
106
132
|
import RobotForm from "./Form.vue";
|
|
107
133
|
import RobotToast from "./Toast.vue";
|
|
108
134
|
import { roleLabel, type TRobotType } from "../../utils/robot-display";
|
|
@@ -123,8 +149,8 @@ const props = withDefaults(
|
|
|
123
149
|
type?: TRobotType;
|
|
124
150
|
/** One robot open, or none (the fleet). */
|
|
125
151
|
robotId?: string;
|
|
126
|
-
/** Which screen: the fleet (default), the 3D building map, or the
|
|
127
|
-
view?: "fleet" | "map" | "lifts";
|
|
152
|
+
/** Which screen: the fleet (default), the 3D building map, the lift queue, alerts or the activity log. A robot open wins. */
|
|
153
|
+
view?: "fleet" | "map" | "lifts" | "alerts" | "log";
|
|
128
154
|
canSetup?: boolean;
|
|
129
155
|
canEdit?: boolean;
|
|
130
156
|
canCommand?: boolean;
|
|
@@ -179,6 +205,44 @@ function onFleetStatus(s: { connected: boolean; faults: number; siteName: string
|
|
|
179
205
|
}
|
|
180
206
|
watch([connected, faults], ([c, f]) => emit("status", { connected: c, faults: f }));
|
|
181
207
|
|
|
208
|
+
/*
|
|
209
|
+
* The bell: the site's open faults (not robots merely offline - they are on
|
|
210
|
+
* Alerts too) for every robot type this app presents, the same count on every
|
|
211
|
+
* view. Read every 30 s while visible; clicking it opens Alerts (`bell`).
|
|
212
|
+
*/
|
|
213
|
+
const { getSiteFaults, getSiteSummary } = useRobots();
|
|
214
|
+
|
|
215
|
+
// The client and site names for the Alerts / Activity log kickers, known even
|
|
216
|
+
// before a fleet view has reported them.
|
|
217
|
+
watch(
|
|
218
|
+
() => [props.organization, props.site],
|
|
219
|
+
async ([org, site]) => {
|
|
220
|
+
if (!org || !site || (props.siteName && props.clientName)) return;
|
|
221
|
+
try {
|
|
222
|
+
const s = await getSiteSummary(org, site);
|
|
223
|
+
if (s?.site?.name) names.value = { siteName: s.site.name, clientName: s.client?.name ?? "" };
|
|
224
|
+
} catch {
|
|
225
|
+
// Names stay blank; the views still work.
|
|
226
|
+
}
|
|
227
|
+
},
|
|
228
|
+
{ immediate: true },
|
|
229
|
+
);
|
|
230
|
+
const alertCount = ref(0);
|
|
231
|
+
async function loadAlertCount() {
|
|
232
|
+
if (!props.site) return;
|
|
233
|
+
try {
|
|
234
|
+
alertCount.value = Number((await getSiteFaults(props.site, { limit: 1 }))?.faults ?? 0);
|
|
235
|
+
} catch {
|
|
236
|
+
// Keep the last count; the views say what failed.
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
watch(() => props.site, loadAlertCount, { immediate: true });
|
|
240
|
+
const bellTimer = setInterval(() => {
|
|
241
|
+
if (typeof document !== "undefined" && document.visibilityState === "hidden") return;
|
|
242
|
+
loadAlertCount();
|
|
243
|
+
}, 30000);
|
|
244
|
+
onBeforeUnmount(() => clearInterval(bellTimer));
|
|
245
|
+
|
|
182
246
|
const addOpen = ref(false);
|
|
183
247
|
const toast = ref("");
|
|
184
248
|
const reloadKey = ref(0);
|
|
@@ -3,18 +3,18 @@ import { computed, ref, watch, type Ref } from "vue";
|
|
|
3
3
|
/**
|
|
4
4
|
* One site's building for the HERO building map and lift queue: the robots
|
|
5
5
|
* at the site this app may see (the API narrows by app), the ones of the type
|
|
6
|
-
* on screen, and the site's saved building map - the newest map saved
|
|
7
|
-
*
|
|
6
|
+
* on screen, and the site's saved building map - the newest map saved at the
|
|
7
|
+
* SITE (`/building-maps?site=`), whichever robot type it was saved from: the
|
|
8
|
+
* building belongs to the site, so a map drawn in Hygiene shows in Security.
|
|
8
9
|
*
|
|
9
|
-
* ponytail: the first 50 robots at the site
|
|
10
|
-
* site-level map endpoint when a site holds more robots than that.
|
|
10
|
+
* ponytail: the first 50 robots at the site; the map read is one call.
|
|
11
11
|
*/
|
|
12
12
|
export default function useRobotBuilding(
|
|
13
13
|
organization: Ref<string>,
|
|
14
14
|
site: Ref<string>,
|
|
15
15
|
type: Ref<"cleaning" | "security">,
|
|
16
16
|
) {
|
|
17
|
-
const { getSiteFleet, getSiteSummary,
|
|
17
|
+
const { getSiteFleet, getSiteSummary, listSiteBuildingMaps, getBuildingMap } = useRobots();
|
|
18
18
|
|
|
19
19
|
/** Every robot at the site this app may see, both types where the app shows both. */
|
|
20
20
|
const all = ref<Array<Record<string, any>>>([]);
|
|
@@ -26,12 +26,9 @@ export default function useRobotBuilding(
|
|
|
26
26
|
/** The robots of the type on screen (scope isolation: the other type is never drawn). */
|
|
27
27
|
const rows = computed(() => all.value.filter((r) => r.type === type.value));
|
|
28
28
|
|
|
29
|
-
async function loadMap(
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
.flatMap((p) => (p.status === "fulfilled" ? p.value?.items ?? [] : []))
|
|
33
|
-
.sort((a: any, b: any) => new Date(b.updatedAt ?? 0).getTime() - new Date(a.updatedAt ?? 0).getTime());
|
|
34
|
-
return summaries[0] ? await getBuildingMap(String(summaries[0]._id)) : null;
|
|
29
|
+
async function loadMap() {
|
|
30
|
+
const newest = (await listSiteBuildingMaps(site.value, { limit: 1 }))?.items?.[0];
|
|
31
|
+
return newest ? await getBuildingMap(String(newest._id)) : null;
|
|
35
32
|
}
|
|
36
33
|
|
|
37
34
|
let run = 0;
|
|
@@ -47,7 +44,7 @@ export default function useRobotBuilding(
|
|
|
47
44
|
if (mine !== run) return;
|
|
48
45
|
all.value = fleet?.items ?? [];
|
|
49
46
|
names.value = { siteName: summary?.site?.name ?? "", clientName: summary?.client?.name ?? "" };
|
|
50
|
-
const found = await loadMap(
|
|
47
|
+
const found = await loadMap();
|
|
51
48
|
if (mine !== run) return;
|
|
52
49
|
map.value = found;
|
|
53
50
|
} catch (e: any) {
|
package/composables/useRobots.ts
CHANGED
|
@@ -85,6 +85,7 @@ export default function useRobots() {
|
|
|
85
85
|
*/
|
|
86
86
|
function createRobot(payload: {
|
|
87
87
|
name: string;
|
|
88
|
+
brand?: string;
|
|
88
89
|
appKey: string;
|
|
89
90
|
appToken: string;
|
|
90
91
|
type?: "cleaning" | "security";
|
|
@@ -98,11 +99,11 @@ export default function useRobots() {
|
|
|
98
99
|
}
|
|
99
100
|
|
|
100
101
|
/**
|
|
101
|
-
* Rename a robot,
|
|
102
|
-
*
|
|
103
|
-
*
|
|
102
|
+
* Rename a robot, set its serial, or REPLACE its credentials (both together;
|
|
103
|
+
* the stored pair is never shown, so it can only be replaced). The brand is
|
|
104
|
+
* not editable - a different brand is a different robot.
|
|
104
105
|
*/
|
|
105
|
-
function updateRobot(id: string, payload: { name?: string; robotSn?: string }) {
|
|
106
|
+
function updateRobot(id: string, payload: { name?: string; robotSn?: string; appKey?: string; appToken?: string }) {
|
|
106
107
|
return useNuxtApp().$api<Record<string, any>>(`/api/robots/${id}`, {
|
|
107
108
|
method: "PATCH",
|
|
108
109
|
query: { appSlug },
|
|
@@ -281,6 +282,50 @@ export default function useRobots() {
|
|
|
281
282
|
});
|
|
282
283
|
}
|
|
283
284
|
|
|
285
|
+
/**
|
|
286
|
+
* The SITE's saved building maps, newest first: the building belongs to the
|
|
287
|
+
* site, so a map saved from a cleaning robot is the Security app's too.
|
|
288
|
+
*/
|
|
289
|
+
function listSiteBuildingMaps(site: string, { page = 1, limit = 10 } = {}) {
|
|
290
|
+
return useNuxtApp().$api<Record<string, any>>("/api/robots/building-maps", {
|
|
291
|
+
method: "GET",
|
|
292
|
+
query: { site, page, limit, appSlug },
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/* ------------------------------------------ alerts + activity log */
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* The site's open faults and robots not reporting (Alerts, README §6),
|
|
300
|
+
* faults first, paged; `faults` = real faults only (the header bell).
|
|
301
|
+
* Narrowed to this app's robot types.
|
|
302
|
+
*/
|
|
303
|
+
function getSiteFaults(site: string, { page = 1, limit = 25, type = "" }: { page?: number; limit?: number; type?: string } = {}) {
|
|
304
|
+
return useNuxtApp().$api<Record<string, any>>("/api/robots/faults", {
|
|
305
|
+
method: "GET",
|
|
306
|
+
query: { site, page, limit, type: type || undefined, appSlug },
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Who did what to the site's robots (Activity log, README §7), newest
|
|
312
|
+
* first, paged; `robot` narrows to one robot. Read only.
|
|
313
|
+
*/
|
|
314
|
+
function getSiteActivity(site: string, { page = 1, limit = 25, robot = "", type = "" }: { page?: number; limit?: number; robot?: string; type?: string } = {}) {
|
|
315
|
+
return useNuxtApp().$api<Record<string, any>>("/api/robots/activity", {
|
|
316
|
+
method: "GET",
|
|
317
|
+
query: { site, page, limit, robot: robot || undefined, type: type || undefined, appSlug },
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/** The Activity log network-wide (Seven365 Super Admin only). */
|
|
322
|
+
function getNetworkActivity({ page = 1, limit = 25 }: { page?: number; limit?: number } = {}) {
|
|
323
|
+
return useNuxtApp().$api<Record<string, any>>("/api/robots/network/activity", {
|
|
324
|
+
method: "GET",
|
|
325
|
+
query: { page, limit },
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
|
|
284
329
|
function getBuildingMap(mapId: string) {
|
|
285
330
|
return useNuxtApp().$api<Record<string, any>>(`/api/robots/building-maps/${mapId}`, {
|
|
286
331
|
method: "GET",
|
|
@@ -348,6 +393,10 @@ export default function useRobots() {
|
|
|
348
393
|
|
|
349
394
|
return {
|
|
350
395
|
listBuildingMaps,
|
|
396
|
+
listSiteBuildingMaps,
|
|
397
|
+
getSiteFaults,
|
|
398
|
+
getSiteActivity,
|
|
399
|
+
getNetworkActivity,
|
|
351
400
|
getBuildingMap,
|
|
352
401
|
createBuildingMap,
|
|
353
402
|
updateBuildingMap,
|
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.32.1-staging.
|
|
5
|
+
"version": "4.32.1-staging.365",
|
|
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/robot-display.ts
CHANGED
|
@@ -1114,3 +1114,149 @@ export function spotPixels(points: Array<{ x: number; y: number }>, size: { widt
|
|
|
1114
1114
|
const cy = px.reduce((s, p) => s + p.y, 0) / px.length;
|
|
1115
1115
|
return spotPolygon(cx, cy, size);
|
|
1116
1116
|
}
|
|
1117
|
+
|
|
1118
|
+
/* ================================= alerts, activity log, add / edit (HERO phase e) */
|
|
1119
|
+
|
|
1120
|
+
/** The Activity log's "When": "14:02 · 4 min" / "14:02 · just now" (the prototype's fmtSince). */
|
|
1121
|
+
export function activityWhen(at: unknown, now: number = Date.now()): string {
|
|
1122
|
+
return sinceText(at, now).replace(/· now$/, "· just now");
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
/**
|
|
1126
|
+
* One console-audit row (`GET /robots/activity`) as the Activity log reads it
|
|
1127
|
+
* (README §7; the prototype's words): Who · Action · Target, e.g.
|
|
1128
|
+
* "Mei Lin" · "sent Clean all to" · "HERO-C03". Only the allow-listed audit
|
|
1129
|
+
* fields are read (names, command kind, lift floors) - never a credential,
|
|
1130
|
+
* which is never in the row either.
|
|
1131
|
+
*/
|
|
1132
|
+
export function activityRow(entry: Record<string, any> | null | undefined, now: number = Date.now()) {
|
|
1133
|
+
const a = (entry?.after ?? {}) as Record<string, any>;
|
|
1134
|
+
const b = (entry?.before ?? {}) as Record<string, any>;
|
|
1135
|
+
const name = String(a.name || b.name || "");
|
|
1136
|
+
const lift = () => `${a.liftName ?? "the lift"} (${floorName(a.fromFloor)} → ${floorName(a.toFloor)})`;
|
|
1137
|
+
let action: string;
|
|
1138
|
+
switch (entry?.action) {
|
|
1139
|
+
case "robot.added":
|
|
1140
|
+
action = "added robot";
|
|
1141
|
+
break;
|
|
1142
|
+
case "robot.updated":
|
|
1143
|
+
action = a.credentialsReplaced
|
|
1144
|
+
? "replaced the credentials of"
|
|
1145
|
+
: a.name && b.name && a.name !== b.name
|
|
1146
|
+
? `renamed ${b.name} to`
|
|
1147
|
+
: "edited robot";
|
|
1148
|
+
break;
|
|
1149
|
+
case "robot.removed":
|
|
1150
|
+
action = "removed robot";
|
|
1151
|
+
break;
|
|
1152
|
+
case "robot.commanded":
|
|
1153
|
+
action = `sent ${commandLabel(a.command)} to`;
|
|
1154
|
+
break;
|
|
1155
|
+
case "robot.map-saved":
|
|
1156
|
+
action = "saved building map";
|
|
1157
|
+
break;
|
|
1158
|
+
case "robot.map-updated":
|
|
1159
|
+
action = "edited building map";
|
|
1160
|
+
break;
|
|
1161
|
+
case "robot.map-removed":
|
|
1162
|
+
action = "removed building map";
|
|
1163
|
+
break;
|
|
1164
|
+
case "robot.lift-requested":
|
|
1165
|
+
action = `requested ${lift()} for`;
|
|
1166
|
+
break;
|
|
1167
|
+
case "robot.lift-released":
|
|
1168
|
+
action = `released ${lift()} for`;
|
|
1169
|
+
break;
|
|
1170
|
+
default:
|
|
1171
|
+
action = String(entry?.label ?? entry?.action ?? "").toLowerCase();
|
|
1172
|
+
}
|
|
1173
|
+
return {
|
|
1174
|
+
id: String(entry?.id ?? ""),
|
|
1175
|
+
when: activityWhen(entry?.when, now),
|
|
1176
|
+
who: String(entry?.actor?.name || "Someone"),
|
|
1177
|
+
action,
|
|
1178
|
+
target: name || "—",
|
|
1179
|
+
};
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
/**
|
|
1183
|
+
* The Add robot dialog's Brand options for a type (README §8: "filtered by
|
|
1184
|
+
* type; option shows capability"): only brands that make that class (a brand
|
|
1185
|
+
* declaring no `types` makes cleaning robots), as "Ounitech · Basic control".
|
|
1186
|
+
*/
|
|
1187
|
+
export function brandOptions(
|
|
1188
|
+
brands: Array<Record<string, any>> | null | undefined,
|
|
1189
|
+
type: unknown,
|
|
1190
|
+
): Array<{ value: string; label: string; capabilities: Record<string, unknown> }> {
|
|
1191
|
+
return (brands ?? [])
|
|
1192
|
+
.filter((b) => (Array.isArray(b?.types) && b.types.length ? b.types : ["cleaning"]).includes(type))
|
|
1193
|
+
.map((b) => ({
|
|
1194
|
+
value: String(b.brand),
|
|
1195
|
+
label: `${brandName(b.brand, brands as any)} · ${capabilityLabel(b.capabilities)}`,
|
|
1196
|
+
capabilities: (b.capabilities ?? {}) as Record<string, unknown>,
|
|
1197
|
+
}));
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
/**
|
|
1201
|
+
* "Basic control — no battery, floor or spot clean" (README §8), derived from
|
|
1202
|
+
* the brand's manifest: the command level, then what it cannot report (spot
|
|
1203
|
+
* clean only matters for a cleaning robot).
|
|
1204
|
+
*/
|
|
1205
|
+
export function capabilityNote(capabilities: Record<string, unknown> | null | undefined, type?: unknown): string {
|
|
1206
|
+
const caps = capabilities ?? {};
|
|
1207
|
+
const label = capabilityLabel(caps);
|
|
1208
|
+
if (label === "No interface") return `${label} — listed only, no monitoring`;
|
|
1209
|
+
if (label === "Read-only") return `${label} — reports only, takes no commands`;
|
|
1210
|
+
const missing = [
|
|
1211
|
+
caps.battery !== true && "battery",
|
|
1212
|
+
caps.floorReporting !== true && "floor",
|
|
1213
|
+
type !== "security" && caps.spotClean !== true && "spot clean",
|
|
1214
|
+
].filter(Boolean) as string[];
|
|
1215
|
+
if (!missing.length) return label === "Full control" ? `${label} — all commands available` : `${label} — some commands only`;
|
|
1216
|
+
const list = missing.length > 1 ? `${missing.slice(0, -1).join(", ")} or ${missing[missing.length - 1]}` : missing[0];
|
|
1217
|
+
return `${label} — no ${list}`;
|
|
1218
|
+
}
|
|
1219
|
+
|
|
1220
|
+
/**
|
|
1221
|
+
* The note under the credentials. The handoff says "stored encrypted"; they
|
|
1222
|
+
* are not encrypted at rest today (see HERO-PENDING_INTEGRATIONS), so the note
|
|
1223
|
+
* says only what is true: they are never shown again.
|
|
1224
|
+
*/
|
|
1225
|
+
export const CREDENTIALS_NOTE = "Credentials are never shown again after saving.";
|
|
1226
|
+
|
|
1227
|
+
/**
|
|
1228
|
+
* What the dialog sends for the credentials. Adding needs both. Editing sends
|
|
1229
|
+
* them ONLY when replaced - both typed; neither typed leaves the stored pair
|
|
1230
|
+
* alone; one without the other is refused before anything is sent.
|
|
1231
|
+
*/
|
|
1232
|
+
export function credentialPatch(
|
|
1233
|
+
appKey: unknown,
|
|
1234
|
+
appToken: unknown,
|
|
1235
|
+
editing: boolean,
|
|
1236
|
+
): { ok: true; body: { appKey?: string; appToken?: string } } | { ok: false; message: string } {
|
|
1237
|
+
const key = typeof appKey === "string" ? appKey.trim() : "";
|
|
1238
|
+
const token = typeof appToken === "string" ? appToken.trim() : "";
|
|
1239
|
+
if (key && token) return { ok: true, body: { appKey: key, appToken: token } };
|
|
1240
|
+
if (editing && !key && !token) return { ok: true, body: {} };
|
|
1241
|
+
return {
|
|
1242
|
+
ok: false,
|
|
1243
|
+
message: editing
|
|
1244
|
+
? "Enter both the app key and the token to replace them, or leave both empty."
|
|
1245
|
+
: "Enter the app key and the token from the brand portal.",
|
|
1246
|
+
};
|
|
1247
|
+
}
|
|
1248
|
+
|
|
1249
|
+
/**
|
|
1250
|
+
* Keep a robot's name tag inside the mini-map plan: flip it to the robot's
|
|
1251
|
+
* left near the right edge, and below the robot near the top edge.
|
|
1252
|
+
* ponytail: width estimated from the text (10px Archivo 600) against the
|
|
1253
|
+
* smallest plan (320px wide, 240 tall); measure if a tag must be exact.
|
|
1254
|
+
*/
|
|
1255
|
+
export function nameTagSide(left: unknown, top: unknown, name: unknown, planW = 320, planH = 240) {
|
|
1256
|
+
const pct = (v: unknown) => (typeof v === "string" ? parseFloat(v) : typeof v === "number" ? v : 0) || 0;
|
|
1257
|
+
const width = String(name ?? "").length * 6.2 + 8;
|
|
1258
|
+
return {
|
|
1259
|
+
flipX: (pct(left) / 100) * planW + 10 + width > planW,
|
|
1260
|
+
below: (pct(top) / 100) * planH < 20,
|
|
1261
|
+
};
|
|
1262
|
+
}
|