@7365admin1/layer-common 4.32.0 → 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.
Files changed (65) hide show
  1. package/CHANGELOG.md +4 -4
  2. package/assets/css/robot-hero.css +26 -0
  3. package/components/AccessCardAddForm.vue +5 -4
  4. package/components/AccessCardAssignToUnitForm.vue +3 -2
  5. package/components/AccessCardPreviewDialog.vue +4 -3
  6. package/components/Dialog/DeleteConfirmation.vue +17 -2
  7. package/components/Dialog/ReusablePrompt.vue +26 -3
  8. package/components/Dialog/UpdateMoreAction.vue +11 -1
  9. package/components/DocumentForm.vue +407 -112
  10. package/components/DocumentManagement.vue +213 -12
  11. package/components/EntryPass/QrTemplatePreview.vue +21 -25
  12. package/components/EntryPassInformation.vue +119 -24
  13. package/components/Facility/BookingSetup.vue +63 -0
  14. package/components/HidAccessLogDashboard.vue +41 -8
  15. package/components/HidAccessPermissions.vue +424 -0
  16. package/components/HidIntercomManagement.vue +148 -14
  17. package/components/HidProfileQrCode.vue +332 -0
  18. package/components/HidReaderManagement.vue +26 -0
  19. package/components/HidReaderUserRoster.vue +44 -3
  20. package/components/HidUserEnrollment.vue +845 -155
  21. package/components/InvitationClientForm.vue +19 -1
  22. package/components/NotificationBell.vue +39 -3
  23. package/components/Robot/ActivityLog.vue +113 -0
  24. package/components/Robot/AlertsTable.vue +1 -0
  25. package/components/Robot/Detail.vue +8 -5
  26. package/components/Robot/Form.vue +170 -214
  27. package/components/Robot/MiniMap.vue +7 -1
  28. package/components/Robot/SiteAlerts.vue +117 -0
  29. package/components/Robot/SiteScreen.vue +69 -5
  30. package/components/VehicleForm.vue +45 -2
  31. package/components/VehicleManagement.vue +95 -10
  32. package/components/VisitorManagement.vue +267 -5
  33. package/composables/useAccessManagement.ts +5 -0
  34. package/composables/useCleaningPermission.ts +4 -4
  35. package/composables/useCommonPermission.ts +16 -0
  36. package/composables/useDocument.ts +7 -0
  37. package/composables/useFacility.ts +11 -0
  38. package/composables/useHidAmico.ts +117 -0
  39. package/composables/useHidNavigation.ts +25 -1
  40. package/composables/useHidReaderSelection.ts +50 -0
  41. package/composables/useLandscapingPermission.ts +4 -4
  42. package/composables/useMechanicalElectricalPermission.ts +4 -4
  43. package/composables/usePeople.ts +19 -0
  44. package/composables/usePestControlPermission.ts +4 -4
  45. package/composables/usePoolMaintenancePermission.ts +4 -4
  46. package/composables/useRobotBuilding.ts +9 -12
  47. package/composables/useRobots.ts +53 -4
  48. package/composables/useSecurityPermission.ts +4 -10
  49. package/composables/useSiteCategory.ts +45 -0
  50. package/composables/useSiteEntryPassSettings.ts +26 -0
  51. package/composables/useWebUsb.ts +14 -11
  52. package/package.json +1 -1
  53. package/pages/[org]/[site]/access-mgmt/administrator/index.vue +1 -1
  54. package/pages/[org]/[site]/access-mgmt/hid-cards/index.vue +1 -1
  55. package/pages/[org]/[site]/access-mgmt/hid-qr-code/index.vue +23 -0
  56. package/pages/[org]/[site]/access-mgmt/hid-readers/index.vue +1 -1
  57. package/types/document.d.ts +14 -0
  58. package/types/facility.d.ts +4 -0
  59. package/types/people.d.ts +28 -1
  60. package/utils/hid-permission-assignments.ts +190 -0
  61. package/utils/hid-reader-selection.ts +52 -0
  62. package/utils/notification-target.ts +75 -0
  63. package/utils/occupancy-role.ts +109 -0
  64. package/utils/robot-display.ts +146 -0
  65. package/utils/vehicle-actions.ts +12 -4
@@ -1,254 +1,210 @@
1
1
  <template>
2
- <v-card width="100%">
3
- <v-toolbar density="comfortable" class="pl-4 py-2">
4
- <span class="font-weight-medium text-h6">
5
- {{ editing ? `Edit ${robot?.name ?? "robot"}` : `Add ${typeLabel} robot` }}
6
- </span>
7
- </v-toolbar>
8
-
9
- <v-card-text class="pa-0" style="max-height: 70vh; overflow-y: auto">
10
- <v-form ref="form" @submit.prevent="submit">
11
- <v-row no-gutters class="px-6 pt-4">
12
- <v-col cols="12" class="mb-2">
13
- <p v-if="editing" class="text-body-2 text-medium-emphasis">
14
- Rename the robot or set its serial. To change its brand or its app
15
- key and token, remove the robot and add it again.
16
- </p>
17
- <p v-else class="text-body-2 text-medium-emphasis">
18
- The app key and token come from your robot supplier. They are used
19
- to talk to the robot and are never shown again once saved.
20
- </p>
21
- </v-col>
22
-
23
- <v-col cols="12">
24
- <InputLabel class="font-weight-bold" title="Name" required />
25
- <v-text-field
26
- v-model="name"
27
- density="comfortable"
28
- placeholder="e.g. Cleaner 02"
29
- :rules="[requiredRule]"
30
- :disabled="saving"
31
- />
32
- </v-col>
33
-
34
- <v-col v-if="!editing" cols="12">
35
- <InputLabel class="font-weight-bold" title="Brand" required />
36
- <AppSelect
37
- v-model="brand"
38
- :items="brands"
39
- item-title="label"
40
- item-value="brand"
41
- density="comfortable"
42
- :loading="loadingBrands"
43
- :rules="[requiredRule]"
44
- :disabled="saving"
45
- />
46
- <p class="text-caption text-medium-emphasis mt-n3 mb-2">
47
- {{ brandHint }}
48
- </p>
49
- </v-col>
50
-
51
- <v-col v-if="!editing" cols="12">
52
- <InputLabel class="font-weight-bold" title="App key" required />
53
- <v-text-field
54
- v-model="appKey"
55
- density="comfortable"
56
- autocomplete="off"
57
- :rules="[requiredRule]"
58
- :disabled="saving"
59
- />
60
- </v-col>
61
-
62
- <v-col v-if="!editing" cols="12">
63
- <InputLabel class="font-weight-bold" title="App token" required />
64
- <!--
65
- Masked like a password because that is what it is: this token signs
66
- every command sent to the estate's robots. It is never returned by
67
- any read, so it cannot be recovered from the screen later either.
68
- -->
69
- <v-text-field
70
- v-model="appToken"
71
- density="comfortable"
72
- autocomplete="off"
73
- :type="reveal ? 'text' : 'password'"
74
- :append-inner-icon="reveal ? 'mdi-eye-off-outline' : 'mdi-eye-outline'"
75
- :rules="[requiredRule]"
76
- :disabled="saving"
77
- @click:append-inner="reveal = !reveal"
78
- />
79
- </v-col>
80
-
81
- <v-col cols="12">
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
- * Register a robot against a site.
131
- *
132
- * The credential pair travels up once and is never returned by any read, so
133
- * there is deliberately no edit-credentials path here: a wrong key is fixed by
134
- * removing the robot and adding it again, which is honest about the fact that
135
- * the old value is gone.
136
- *
137
- * The serial is optional because the supplier's Add-Robot flow has never asked
138
- * for one. When it is blank the server finds it from the robot cloud — and
139
- * refuses rather than guessing if the key covers more than one machine, which is
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: string;
147
- site: string;
148
- type?: "cleaning" | "security";
149
- /** When given, the form edits this robot instead of adding one. */
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
- const emit = defineEmits<{ cancel: []; created: []; saved: [] }>();
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 form = ref();
162
- const name = ref(props.robot?.name ?? "");
163
- const brand = ref("");
164
- const brands = ref<Array<Record<string, any>>>([]);
165
- const loadingBrands = ref(false);
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 typeLabel = computed(() => (props.type === "security" ? "security" : "cleaning"));
174
-
175
- /**
176
- * What each brand's protocol will actually allow, in plain words.
177
- *
178
- * The tier comes from Open-RMF's published categories, so this is not a Seven365
179
- * opinion - and somebody choosing a brand should know before they commit that
180
- * one of them cannot be paused or told where to go.
181
- */
182
- const TIER_HINT: Record<string, string> = {
183
- "full-control": "Full control — position, battery, navigation, pause and resume.",
184
- "traffic-light": "Position, battery, and pause/resume. No navigation to a point.",
185
- "read-only": "Position only. This brand cannot be given jobs through its API.",
186
- "no-interface":
187
- "Limited: the published API does not yet report battery or progress. Cleaning and return-to-dock work.",
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 brandHint = computed(() => {
191
- const chosen = brands.value.find((b) => b.brand === brand.value);
192
- return chosen ? TIER_HINT[chosen.tier] ?? "" : "Which robot this is. Ask your supplier if unsure.";
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 function loadBrands() {
172
+ onMounted(async () => {
196
173
  loadingBrands.value = true;
197
174
  try {
198
- const res = await getRobotBrands();
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 (editing.value) {
224
- try {
225
- await updateRobot(props.robot!._id, {
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
- robotSn: robotSn.value.trim(),
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("saved");
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 &amp; 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>