@7365admin1/layer-common 4.30.0 → 4.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -4
- package/assets/css/robot-hero.css +489 -1
- package/components/Robot/BuildingMap.vue +403 -0
- package/components/Robot/Detail.vue +445 -0
- package/components/Robot/Fleet.vue +3 -1
- package/components/Robot/FloorPlan.vue +43 -0
- package/components/Robot/LiftQueue.vue +247 -0
- package/components/Robot/LivePlan.vue +59 -0
- package/components/Robot/MapEditor.vue +233 -0
- package/components/Robot/Mark.vue +17 -0
- package/components/Robot/MiniMap.vue +120 -0
- package/components/Robot/PatrolRoutes.vue +48 -0
- package/components/Robot/SiteFleet.vue +266 -0
- package/components/Robot/SiteHeader.vue +64 -0
- package/components/Robot/SiteScreen.vue +195 -0
- package/components/Robot/Table.vue +4 -1
- package/composables/useRobotBuilding.ts +66 -0
- package/composables/useRobotLive.ts +18 -0
- package/composables/useRobots.ts +52 -1
- package/package.json +2 -2
- package/utils/robot-building.ts +521 -0
- package/utils/robot-display.ts +520 -9
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<!--
|
|
3
|
+
LIVE MINI-MAP (README §2): the robots on screen on one floor, positions
|
|
4
|
+
animated linearly over each telemetry tick, never a frozen dot - a lost
|
|
5
|
+
feed lays "Reconnecting…" over the plan. Security adds the patrol routes.
|
|
6
|
+
Robots that cannot report a floor are listed below, not placed.
|
|
7
|
+
-->
|
|
8
|
+
<div class="hero-mini">
|
|
9
|
+
<div class="hero-mini__head">
|
|
10
|
+
<span class="hero-aside__title">Live mini-map</span>
|
|
11
|
+
<span class="hero-head__spacer" />
|
|
12
|
+
<v-btn variant="outlined" class="hero-iconbtn" title="Full screen" aria-label="Full screen" @click="plan?.toggleFullscreen()">
|
|
13
|
+
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
|
|
14
|
+
<path d="M8 3H5a2 2 0 0 0-2 2v3m18 0V5a2 2 0 0 0-2-2h-3m0 18h3a2 2 0 0 0 2-2v-3M3 16v3a2 2 0 0 0 2 2h3" />
|
|
15
|
+
</svg>
|
|
16
|
+
</v-btn>
|
|
17
|
+
<select v-if="floors.length" :value="floor" class="hero-input hero-select hero-select--sm" aria-label="Floor" @change="chosen = Number(($event.target as HTMLSelectElement).value)">
|
|
18
|
+
<option v-for="f in floors" :key="f" :value="f">{{ floorName(f) }}</option>
|
|
19
|
+
</select>
|
|
20
|
+
</div>
|
|
21
|
+
|
|
22
|
+
<RobotFloorPlan ref="plan">
|
|
23
|
+
<RobotPatrolRoutes v-if="type === 'security' && floorRoutes.length" :routes="floorRoutes" />
|
|
24
|
+
<button
|
|
25
|
+
v-for="r in robots"
|
|
26
|
+
:key="r.id"
|
|
27
|
+
type="button"
|
|
28
|
+
class="hero-bot"
|
|
29
|
+
:title="r.name"
|
|
30
|
+
:style="{ left: r.left, top: r.top, transition: `left ${tickMs}ms linear, top ${tickMs}ms linear`, '--hero-bot': toneColor(r) }"
|
|
31
|
+
@click="emit('open', r.id)"
|
|
32
|
+
>
|
|
33
|
+
<span class="hero-bot__ping" aria-hidden="true" />
|
|
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>
|
|
36
|
+
</button>
|
|
37
|
+
<RobotReconnecting v-if="!connected" />
|
|
38
|
+
</RobotFloorPlan>
|
|
39
|
+
|
|
40
|
+
<div class="hero-mini__foot">
|
|
41
|
+
<span>Floor plan from robot (placeholder)</span>
|
|
42
|
+
<span v-if="type === 'security'"><span class="hero-mini__legend" aria-hidden="true" />Patrol routes</span>
|
|
43
|
+
<span v-if="floor !== null" class="hero-mini__count">{{ robots.length }} on {{ floorName(floor) }}</span>
|
|
44
|
+
</div>
|
|
45
|
+
<div v-if="unplaced" class="hero-notice">{{ unplaced }}</div>
|
|
46
|
+
</div>
|
|
47
|
+
</template>
|
|
48
|
+
|
|
49
|
+
<script setup lang="ts">
|
|
50
|
+
import { computed, ref } from "vue";
|
|
51
|
+
import RobotFloorPlan from "./FloorPlan.vue";
|
|
52
|
+
import RobotPatrolRoutes from "./PatrolRoutes.vue";
|
|
53
|
+
import RobotReconnecting from "./Reconnecting.vue";
|
|
54
|
+
import {
|
|
55
|
+
brandName,
|
|
56
|
+
floorLabel,
|
|
57
|
+
mapFloors,
|
|
58
|
+
mapRobots,
|
|
59
|
+
pickFloor,
|
|
60
|
+
robotStatus,
|
|
61
|
+
unplacedRobots,
|
|
62
|
+
unplacedText,
|
|
63
|
+
type TLiveRobotState,
|
|
64
|
+
type TMapRobot,
|
|
65
|
+
type TPatrolRouteView,
|
|
66
|
+
} from "../../utils/robot-display";
|
|
67
|
+
|
|
68
|
+
const props = withDefaults(
|
|
69
|
+
defineProps<{
|
|
70
|
+
/** The robots on screen (the table's page): `{ _id, name, type, brand }`. */
|
|
71
|
+
rows: Array<Record<string, any>>;
|
|
72
|
+
states: Record<string, TLiveRobotState>;
|
|
73
|
+
type?: "cleaning" | "security";
|
|
74
|
+
/** Patrol routes by robot id (security only). */
|
|
75
|
+
routes?: Record<string, TPatrolRouteView[]>;
|
|
76
|
+
/** False = the live feed is down: "Reconnecting…" over the plan. */
|
|
77
|
+
connected?: boolean;
|
|
78
|
+
brands?: Array<{ brand?: unknown; displayName?: unknown }>;
|
|
79
|
+
/** One telemetry tick; positions glide across it. */
|
|
80
|
+
tickMs?: number;
|
|
81
|
+
}>(),
|
|
82
|
+
{ type: "cleaning", routes: () => ({}), connected: true, brands: () => [], tickMs: 4000 },
|
|
83
|
+
);
|
|
84
|
+
const emit = defineEmits<{ open: [id: string] }>();
|
|
85
|
+
|
|
86
|
+
const plan = ref<InstanceType<typeof RobotFloorPlan> | null>(null);
|
|
87
|
+
const ids = computed(() => props.rows.map((r) => String(r._id)));
|
|
88
|
+
const floors = computed(() => mapFloors(ids.value, props.states));
|
|
89
|
+
const chosen = ref<number | null>(null);
|
|
90
|
+
const floor = computed(() => pickFloor(floors.value, chosen.value, ids.value, props.states));
|
|
91
|
+
const robots = computed(() => mapRobots(props.rows, props.states, floor.value));
|
|
92
|
+
const floorName = (f: number) => floorLabel({ floorNo: f, floorKnown: true });
|
|
93
|
+
|
|
94
|
+
/** The routes walked on this floor, once each. A route with no floor is drawn on its robot's floor. */
|
|
95
|
+
const floorRoutes = computed(() => {
|
|
96
|
+
const seen = new Map<string, TPatrolRouteView>();
|
|
97
|
+
for (const id of ids.value) {
|
|
98
|
+
const st = props.states[id];
|
|
99
|
+
for (const r of props.routes[id] ?? []) {
|
|
100
|
+
const f = r.floorNo ?? (st?.floorKnown ? st.floorNo : null);
|
|
101
|
+
if (f === floor.value && !seen.has(r.id)) seen.set(r.id, r);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return [...seen.values()];
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
const unplaced = computed(() =>
|
|
108
|
+
unplacedText(unplacedRobots(props.rows, props.states).map((r) => brandName(r.brand, props.brands))),
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
const TONE: Record<string, string> = {
|
|
112
|
+
success: "rgb(var(--v-theme-success))",
|
|
113
|
+
warning: "rgb(var(--v-theme-warning))",
|
|
114
|
+
info: "rgb(var(--v-theme-info))",
|
|
115
|
+
error: "rgb(var(--v-theme-error))",
|
|
116
|
+
accent: "var(--hero-accent)",
|
|
117
|
+
ink: "var(--hero-text)",
|
|
118
|
+
};
|
|
119
|
+
const toneColor = (r: TMapRobot) => TONE[robotStatus(r.mode, r.type).tone] ?? TONE.ink;
|
|
120
|
+
</script>
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<!-- Dashed, animated patrol routes, numbered checkpoints and route-name tags, over a Plan. -->
|
|
3
|
+
<svg class="hero-plan__svg" viewBox="0 0 400 300" preserveAspectRatio="none" aria-hidden="true">
|
|
4
|
+
<path
|
|
5
|
+
v-for="r in routes"
|
|
6
|
+
:key="r.id"
|
|
7
|
+
class="hero-plan__route"
|
|
8
|
+
:class="{ 'hero-plan__route--anim': animate }"
|
|
9
|
+
:d="routePathD(r.checkpoints)"
|
|
10
|
+
vector-effect="non-scaling-stroke"
|
|
11
|
+
/>
|
|
12
|
+
</svg>
|
|
13
|
+
<div
|
|
14
|
+
v-for="t in routeTags(routes)"
|
|
15
|
+
:key="`tag-${t.key}`"
|
|
16
|
+
class="hero-routetag"
|
|
17
|
+
:class="{ 'hero-routetag--lg': large }"
|
|
18
|
+
:style="{ left: insideLeft(t.left, large ? `${t.name} · ${t.count} pts` : t.name, large ? 6.4 : 5.8, large ? 14 : 12), top: t.top }"
|
|
19
|
+
>
|
|
20
|
+
{{ t.name }}<template v-if="large"> · {{ t.count }} pts</template>
|
|
21
|
+
</div>
|
|
22
|
+
<template v-for="m in routeMarks(routes)" :key="m.key">
|
|
23
|
+
<div
|
|
24
|
+
class="hero-cp"
|
|
25
|
+
:class="{ 'hero-cp--lg': large, 'hero-cp--current': large && m.current }"
|
|
26
|
+
:style="{ left: m.left, top: m.top }"
|
|
27
|
+
:title="m.label"
|
|
28
|
+
>
|
|
29
|
+
{{ m.n }}
|
|
30
|
+
</div>
|
|
31
|
+
<div class="hero-cp__label" :class="{ 'hero-cp__label--lg': large }" :style="{ left: insideLeft(m.left, m.label, large ? 6.2 : 5.6, 4), top: m.top }">{{ m.label }}</div>
|
|
32
|
+
</template>
|
|
33
|
+
</template>
|
|
34
|
+
|
|
35
|
+
<script setup lang="ts">
|
|
36
|
+
import { insideLeft, routeMarks, routePathD, routeTags, type TPatrolRouteView } from "../../utils/robot-display";
|
|
37
|
+
|
|
38
|
+
withDefaults(
|
|
39
|
+
defineProps<{
|
|
40
|
+
routes: TPatrolRouteView[];
|
|
41
|
+
/** The dash walks (heroDash 1.6s) - always on the mini-map; on detail while the robot patrols. */
|
|
42
|
+
animate?: boolean;
|
|
43
|
+
/** Detail-plan sizes: 14px checkpoints, the current one filled, "· N pts" on the tag. */
|
|
44
|
+
large?: boolean;
|
|
45
|
+
}>(),
|
|
46
|
+
{ animate: true, large: false },
|
|
47
|
+
);
|
|
48
|
+
</script>
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<!--
|
|
3
|
+
Site fleet overview (README §2): kicker + "{Site} · Cleaning robots",
|
|
4
|
+
"+ Add robot" when set-up is permitted, the six-cell summary, the robot
|
|
5
|
+
table (server pages - it pages past page 1) and the live mini-map.
|
|
6
|
+
-->
|
|
7
|
+
<div class="hero-head">
|
|
8
|
+
<div>
|
|
9
|
+
<button v-if="backToNetwork" type="button" class="hero-back hero-back--sm" @click="emit('network')">‹ Network</button>
|
|
10
|
+
<div class="hero-kicker hero-kicker--accent">{{ clientName || summary?.client?.name }}</div>
|
|
11
|
+
<h2 class="hero-title">{{ siteName || summary?.site?.name }} · {{ typeLabel(type) }} robots</h2>
|
|
12
|
+
</div>
|
|
13
|
+
<span class="hero-head__spacer" />
|
|
14
|
+
<v-btn v-if="canSetup" color="primary" variant="flat" @click="emit('add')">+ Add robot</v-btn>
|
|
15
|
+
</div>
|
|
16
|
+
|
|
17
|
+
<RobotSummaryStrip :key="`${site}:${type}`" class="hero-summary--six" :cells="cells" label="Site summary" />
|
|
18
|
+
|
|
19
|
+
<div class="hero-split">
|
|
20
|
+
<div class="hero-split__main hero-split__main--fleet">
|
|
21
|
+
<div v-if="error" class="hero-notice" role="alert">{{ error }}</div>
|
|
22
|
+
<RobotTable
|
|
23
|
+
v-else
|
|
24
|
+
:headers="headers"
|
|
25
|
+
:items="rows"
|
|
26
|
+
:items-length="total"
|
|
27
|
+
:page="page"
|
|
28
|
+
:items-per-page="limit"
|
|
29
|
+
:loading="loading"
|
|
30
|
+
:empty-title="empty.title"
|
|
31
|
+
:empty-hint="empty.hint"
|
|
32
|
+
compact
|
|
33
|
+
hover
|
|
34
|
+
paged-foot
|
|
35
|
+
item-value="_id"
|
|
36
|
+
@update:page="onPage"
|
|
37
|
+
@click:row="onRow"
|
|
38
|
+
>
|
|
39
|
+
<template #item.name="{ item }"><span class="hero-table__name">{{ item.name }}</span></template>
|
|
40
|
+
<template #item.brand="{ item }"><span class="hero-dim">{{ brandName(item.brand, brands) }}</span></template>
|
|
41
|
+
<template #item.capability="{ item }">
|
|
42
|
+
<span v-if="capsOf(item)" class="hero-tag hero-tag--neutral hero-tag--xs">{{ capabilityLabel(capsOf(item)) }}</span>
|
|
43
|
+
</template>
|
|
44
|
+
<template #item.status="{ item }">
|
|
45
|
+
<RobotStatusChip v-if="statusOf(item).kind === 'live'" :mode="statusOf(item).mode" :type="item.type" />
|
|
46
|
+
<RobotStatusChip v-else-if="statusOf(item).kind === 'offline'" mode="UNAVAILABLE" :type="item.type" />
|
|
47
|
+
<RobotStatusChip v-else-if="statusOf(item).kind === 'none'" mode="UNKNOWN" :type="item.type" />
|
|
48
|
+
<span v-else-if="statusOf(item).kind === 'reconnecting'" class="hero-tag hero-tag--neutral">Reconnecting</span>
|
|
49
|
+
<span v-else class="hero-muted">Checking…</span>
|
|
50
|
+
</template>
|
|
51
|
+
<template #item.battery="{ item }"><RobotBattery v-if="live(item)?.ok" :value="live(item)?.batteryPercent" /></template>
|
|
52
|
+
<template #item.floor="{ item }">
|
|
53
|
+
<RobotFloorLabel
|
|
54
|
+
v-if="live(item)?.ok || live(item)?.monitorable === false"
|
|
55
|
+
:floor-no="live(item)?.floorNo"
|
|
56
|
+
:floor-known="live(item)?.floorKnown === true"
|
|
57
|
+
/>
|
|
58
|
+
</template>
|
|
59
|
+
<template #item.fault="{ item }">
|
|
60
|
+
<RobotFaultBadge v-if="faultOf(item)" :code="faultOf(item)?.code" :message="faultOf(item)?.message" compact />
|
|
61
|
+
</template>
|
|
62
|
+
<template #item.lastSeen="{ item }"><span class="hero-num hero-seen">{{ seenText(item) }}</span></template>
|
|
63
|
+
<template #item.go><span class="hero-go" aria-hidden="true">›</span></template>
|
|
64
|
+
</RobotTable>
|
|
65
|
+
</div>
|
|
66
|
+
|
|
67
|
+
<aside class="hero-split__aside hero-split__aside--map">
|
|
68
|
+
<RobotMiniMap
|
|
69
|
+
:rows="rows"
|
|
70
|
+
:states="states"
|
|
71
|
+
:type="type"
|
|
72
|
+
:routes="routes"
|
|
73
|
+
:connected="connected"
|
|
74
|
+
:brands="brands"
|
|
75
|
+
@open="onMapOpen"
|
|
76
|
+
/>
|
|
77
|
+
</aside>
|
|
78
|
+
</div>
|
|
79
|
+
</template>
|
|
80
|
+
|
|
81
|
+
<script setup lang="ts">
|
|
82
|
+
import { computed, onBeforeUnmount, ref, watch } from "vue";
|
|
83
|
+
import RobotSummaryStrip from "./SummaryStrip.vue";
|
|
84
|
+
import RobotTable from "./Table.vue";
|
|
85
|
+
import RobotStatusChip from "./StatusChip.vue";
|
|
86
|
+
import RobotBattery from "./Battery.vue";
|
|
87
|
+
import RobotFloorLabel from "./FloorLabel.vue";
|
|
88
|
+
import RobotFaultBadge from "./FaultBadge.vue";
|
|
89
|
+
import RobotMiniMap from "./MiniMap.vue";
|
|
90
|
+
import useRobotLive, { siteStatesFeed } from "../../composables/useRobotLive";
|
|
91
|
+
import {
|
|
92
|
+
agoText,
|
|
93
|
+
brandName,
|
|
94
|
+
capabilityLabel,
|
|
95
|
+
listMeta,
|
|
96
|
+
robotErrorMessage,
|
|
97
|
+
rowStatus,
|
|
98
|
+
siteEmptyText,
|
|
99
|
+
siteSummaryCells,
|
|
100
|
+
typeLabel,
|
|
101
|
+
type TPatrolRouteView,
|
|
102
|
+
} from "../../utils/robot-display";
|
|
103
|
+
|
|
104
|
+
const props = withDefaults(
|
|
105
|
+
defineProps<{
|
|
106
|
+
organization: string;
|
|
107
|
+
site: string;
|
|
108
|
+
siteName?: string;
|
|
109
|
+
clientName?: string;
|
|
110
|
+
type?: "cleaning" | "security";
|
|
111
|
+
/** Add / edit / remove permitted (the app's add-robot grant, or Super Admin). */
|
|
112
|
+
canSetup?: boolean;
|
|
113
|
+
/** Show "‹ Network" (Super Admin drilled in). */
|
|
114
|
+
backToNetwork?: boolean;
|
|
115
|
+
/** Bumped by the parent to reload (after add / edit / remove). */
|
|
116
|
+
reloadKey?: number;
|
|
117
|
+
limit?: number;
|
|
118
|
+
}>(),
|
|
119
|
+
{ siteName: "", clientName: "", type: "cleaning", canSetup: false, backToNetwork: false, reloadKey: 0, limit: 25 },
|
|
120
|
+
);
|
|
121
|
+
const emit = defineEmits<{
|
|
122
|
+
open: [robot: any];
|
|
123
|
+
add: [];
|
|
124
|
+
network: [];
|
|
125
|
+
/** The live feed's health, the site's open-fault count and its names, for the header. */
|
|
126
|
+
status: [status: { connected: boolean; faults: number; siteName: string; clientName: string }];
|
|
127
|
+
}>();
|
|
128
|
+
|
|
129
|
+
const { getSiteFleet, getSiteSummary, getRobotBrands, getPatrolRoutes } = useRobots();
|
|
130
|
+
|
|
131
|
+
const headers = [
|
|
132
|
+
{ title: "Name", key: "name", sortable: false },
|
|
133
|
+
{ title: "Brand", key: "brand", sortable: false },
|
|
134
|
+
{ title: "Capability", key: "capability", sortable: false },
|
|
135
|
+
{ title: "Status", key: "status", sortable: false },
|
|
136
|
+
{ title: "Battery", key: "battery", sortable: false },
|
|
137
|
+
{ title: "Floor", key: "floor", sortable: false },
|
|
138
|
+
{ title: "Fault", key: "fault", sortable: false },
|
|
139
|
+
{ title: "Last seen", key: "lastSeen", sortable: false },
|
|
140
|
+
{ title: "", key: "go", sortable: false, align: "end" as const },
|
|
141
|
+
];
|
|
142
|
+
|
|
143
|
+
const rows = ref<Array<Record<string, any>>>([]);
|
|
144
|
+
const total = ref(0);
|
|
145
|
+
const page = ref(1);
|
|
146
|
+
const loading = ref(true);
|
|
147
|
+
const error = ref("");
|
|
148
|
+
const summary = ref<Record<string, any> | null>(null);
|
|
149
|
+
const brands = ref<Array<Record<string, any>>>([]);
|
|
150
|
+
const now = ref(Date.now());
|
|
151
|
+
|
|
152
|
+
const cells = computed(() => siteSummaryCells(summary.value, props.type));
|
|
153
|
+
const empty = computed(() => siteEmptyText(props.type, props.canSetup));
|
|
154
|
+
|
|
155
|
+
async function loadList(): Promise<void> {
|
|
156
|
+
loading.value = true;
|
|
157
|
+
error.value = "";
|
|
158
|
+
try {
|
|
159
|
+
const res = await getSiteFleet(props.organization, props.site, { page: page.value, limit: props.limit, type: props.type });
|
|
160
|
+
rows.value = res?.items ?? [];
|
|
161
|
+
const meta = listMeta(res, props.limit);
|
|
162
|
+
total.value = meta.total;
|
|
163
|
+
// A page that emptied (its last robot removed) steps back rather than sitting blank.
|
|
164
|
+
if (!rows.value.length && page.value > meta.pages) {
|
|
165
|
+
page.value = meta.pages;
|
|
166
|
+
return loadList();
|
|
167
|
+
}
|
|
168
|
+
} catch (e) {
|
|
169
|
+
rows.value = [];
|
|
170
|
+
total.value = 0;
|
|
171
|
+
error.value = robotErrorMessage(e, "Could not load the robots for this site.");
|
|
172
|
+
} finally {
|
|
173
|
+
loading.value = false;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
async function loadSummary() {
|
|
178
|
+
try {
|
|
179
|
+
summary.value = await getSiteSummary(props.organization, props.site, { type: props.type });
|
|
180
|
+
} catch {
|
|
181
|
+
// The strip keeps its last numbers; the table says what failed.
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function onPage(next: number) {
|
|
186
|
+
page.value = next;
|
|
187
|
+
loadList();
|
|
188
|
+
}
|
|
189
|
+
function onRow(_e: unknown, ctx: { item: any }) {
|
|
190
|
+
emit("open", ctx.item);
|
|
191
|
+
}
|
|
192
|
+
function onMapOpen(id: string) {
|
|
193
|
+
const row = rows.value.find((r) => String(r._id) === id);
|
|
194
|
+
if (row) emit("open", row);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/* ---- live state of the robots on screen (4 s poll; swappable feed) ---- */
|
|
198
|
+
const ids = computed(() => rows.value.map((r) => String(r._id)));
|
|
199
|
+
const { states, connected } = useRobotLive(ids, siteStatesFeed());
|
|
200
|
+
const live = (row: any) => states.value[String(row._id)] ?? null;
|
|
201
|
+
const statusOf = (row: any) => rowStatus(row, live(row));
|
|
202
|
+
/** The brand's declared capabilities, once read; a no-interface brand declares none. */
|
|
203
|
+
function capsOf(row: any) {
|
|
204
|
+
const s = live(row);
|
|
205
|
+
if (s?.ok) return s.capabilities ?? {};
|
|
206
|
+
if (s && s.monitorable === false) return {};
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
209
|
+
/** The live fault when the robot answers, else its stored open fault. */
|
|
210
|
+
const faultOf = (row: any) => (live(row)?.ok ? live(row)?.fault ?? null : row.fault ?? null);
|
|
211
|
+
function seenText(row: any) {
|
|
212
|
+
if (live(row)?.monitorable === false) return "—";
|
|
213
|
+
return agoText(live(row)?.lastSeenAt ?? row.lastSeenAt, now.value) || "—";
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/* ---- patrol routes for the security robots on screen ---- */
|
|
217
|
+
const routes = ref<Record<string, TPatrolRouteView[]>>({});
|
|
218
|
+
async function loadRoutes() {
|
|
219
|
+
if (props.type !== "security") {
|
|
220
|
+
routes.value = {};
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
const next: Record<string, TPatrolRouteView[]> = {};
|
|
224
|
+
await Promise.allSettled(
|
|
225
|
+
ids.value.map(async (id) => {
|
|
226
|
+
const res = await getPatrolRoutes(id);
|
|
227
|
+
if (res?.supported) next[id] = res.routes ?? [];
|
|
228
|
+
}),
|
|
229
|
+
);
|
|
230
|
+
routes.value = next;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/* ---- refresh: the summary every 8 s, the "last seen" clock every second ---- */
|
|
234
|
+
let ticks = 0;
|
|
235
|
+
const timer = setInterval(() => {
|
|
236
|
+
now.value = Date.now();
|
|
237
|
+
if (typeof document !== "undefined" && document.visibilityState === "hidden") return;
|
|
238
|
+
if (++ticks % 8 === 0) loadSummary();
|
|
239
|
+
}, 1000);
|
|
240
|
+
onBeforeUnmount(() => clearInterval(timer));
|
|
241
|
+
|
|
242
|
+
watch(
|
|
243
|
+
[() => props.organization, () => props.site, () => props.type, () => props.reloadKey],
|
|
244
|
+
(next, old) => {
|
|
245
|
+
const sameView = !!old && old[0] === next[0] && old[1] === next[1] && old[2] === next[2];
|
|
246
|
+
if (!sameView) {
|
|
247
|
+
page.value = 1;
|
|
248
|
+
summary.value = null;
|
|
249
|
+
}
|
|
250
|
+
loadList();
|
|
251
|
+
loadSummary();
|
|
252
|
+
},
|
|
253
|
+
{ immediate: true },
|
|
254
|
+
);
|
|
255
|
+
watch(ids, loadRoutes);
|
|
256
|
+
getRobotBrands().then(
|
|
257
|
+
(res) => (brands.value = res?.items ?? []),
|
|
258
|
+
() => undefined,
|
|
259
|
+
);
|
|
260
|
+
|
|
261
|
+
watch(
|
|
262
|
+
[connected, () => summary.value?.faults?.count ?? 0, () => summary.value?.site?.name ?? "", () => summary.value?.client?.name ?? ""],
|
|
263
|
+
([up, faults, siteName, clientName]) => emit("status", { connected: up, faults, siteName, clientName }),
|
|
264
|
+
{ immediate: true },
|
|
265
|
+
);
|
|
266
|
+
</script>
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<!--
|
|
3
|
+
The shared shell header (README "Shared shell"), inside the app's own
|
|
4
|
+
layout: HERO mark + org line, Site select (only with more than one site),
|
|
5
|
+
Cleaning | Security (only when the account has both types), then the live
|
|
6
|
+
indicator, the bell with the open-fault count and the role tag.
|
|
7
|
+
-->
|
|
8
|
+
<header class="hero-header">
|
|
9
|
+
<div class="hero-brand">
|
|
10
|
+
<RobotMark :size="30" />
|
|
11
|
+
<div>
|
|
12
|
+
<div class="hero-brand__name">HERO</div>
|
|
13
|
+
<div class="hero-brand__org">{{ orgName }}</div>
|
|
14
|
+
</div>
|
|
15
|
+
</div>
|
|
16
|
+
<div v-if="sites.length > 1" class="hero-header__site">
|
|
17
|
+
<span class="hero-filters__label">Site</span>
|
|
18
|
+
<select class="hero-input hero-select" :value="site" aria-label="Site" @change="emit('update:site', ($event.target as HTMLSelectElement).value)">
|
|
19
|
+
<option v-for="s in sites" :key="s._id" :value="s._id">{{ s.name }}</option>
|
|
20
|
+
</select>
|
|
21
|
+
</div>
|
|
22
|
+
<div v-if="types.length > 1" class="hero-switch" role="group" aria-label="Robot type">
|
|
23
|
+
<button
|
|
24
|
+
v-for="t in types"
|
|
25
|
+
:key="t"
|
|
26
|
+
type="button"
|
|
27
|
+
class="hero-switch__opt"
|
|
28
|
+
:aria-pressed="t === type"
|
|
29
|
+
@click="emit('update:type', t)"
|
|
30
|
+
>
|
|
31
|
+
{{ typeLabel(t) }}
|
|
32
|
+
</button>
|
|
33
|
+
</div>
|
|
34
|
+
<span class="hero-head__spacer" />
|
|
35
|
+
<div class="hero-header__right">
|
|
36
|
+
<RobotLiveIndicator :connected="connected" />
|
|
37
|
+
<RobotBell :count="faults" @click="emit('bell')" />
|
|
38
|
+
<span class="hero-tag hero-tag--neutral">{{ role }}</span>
|
|
39
|
+
</div>
|
|
40
|
+
<span class="hero-bar__sweep" :class="{ 'hero-bar__sweep--off': !connected }" aria-hidden="true" />
|
|
41
|
+
</header>
|
|
42
|
+
</template>
|
|
43
|
+
|
|
44
|
+
<script setup lang="ts">
|
|
45
|
+
import RobotMark from "./Mark.vue";
|
|
46
|
+
import RobotLiveIndicator from "./LiveIndicator.vue";
|
|
47
|
+
import RobotBell from "./Bell.vue";
|
|
48
|
+
import { typeLabel, type TRobotType } from "../../utils/robot-display";
|
|
49
|
+
|
|
50
|
+
withDefaults(
|
|
51
|
+
defineProps<{
|
|
52
|
+
orgName?: string;
|
|
53
|
+
sites?: Array<{ _id: string; name: string }>;
|
|
54
|
+
site?: string;
|
|
55
|
+
types?: TRobotType[];
|
|
56
|
+
type?: TRobotType;
|
|
57
|
+
connected?: boolean;
|
|
58
|
+
faults?: number;
|
|
59
|
+
role?: string;
|
|
60
|
+
}>(),
|
|
61
|
+
{ orgName: "", sites: () => [], site: "", types: () => ["cleaning"], type: "cleaning", connected: true, faults: 0, role: "View-only" },
|
|
62
|
+
);
|
|
63
|
+
const emit = defineEmits<{ "update:site": [id: string]; "update:type": [type: TRobotType]; bell: [] }>();
|
|
64
|
+
</script>
|