@7365admin1/layer-common 4.25.0 → 4.26.1-staging.354
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 +18 -4
- package/components/AccessCardAddForm.vue +5 -4
- package/components/AccessCardAssignToUnitForm.vue +3 -2
- package/components/AccessCardPreviewDialog.vue +4 -3
- package/components/Dialog/UpdateMoreAction.vue +11 -1
- package/components/DocumentForm.vue +407 -112
- package/components/DocumentManagement.vue +213 -12
- package/components/EntryPass/QrTemplatePreview.vue +21 -25
- package/components/EntryPassInformation.vue +119 -24
- package/components/Facility/BookingSetup.vue +63 -0
- package/components/HidAccessLogDashboard.vue +29 -5
- package/components/HidAccessPermissions.vue +424 -0
- package/components/HidIntercomManagement.vue +148 -14
- package/components/HidProfileQrCode.vue +323 -0
- package/components/HidReaderManagement.vue +26 -0
- package/components/HidReaderUserRoster.vue +32 -2
- package/components/HidUserEnrollment.vue +833 -152
- package/components/InvitationClientForm.vue +19 -1
- package/components/Robot/Fleet.vue +182 -2
- package/components/Robot/Form.vue +37 -12
- package/components/Robot/Map3D.vue +803 -40
- package/components/Robot/Plans.vue +63 -0
- package/components/Robot/SpotClean.vue +174 -0
- package/components/RolePermissionFormCreate.vue +163 -19
- package/components/RolePermissionFormPreviewUpdate.vue +230 -19
- package/components/RolePermissionMain.vue +19 -0
- package/components/VisitorManagement.vue +267 -5
- package/composables/useAccessManagement.ts +5 -0
- package/composables/useDocument.ts +7 -0
- package/composables/useFacility.ts +11 -0
- package/composables/useHidAmico.ts +117 -0
- package/composables/useHidNavigation.ts +25 -1
- package/composables/usePeople.ts +19 -0
- package/composables/useRobots.ts +111 -0
- package/composables/useSiteCategory.ts +45 -0
- package/composables/useSiteEntryPassSettings.ts +26 -0
- package/composables/useWebUsb.ts +14 -11
- package/package.json +1 -1
- package/pages/[org]/[site]/access-mgmt/administrator/index.vue +1 -1
- package/pages/[org]/[site]/access-mgmt/hid-cards/index.vue +1 -1
- package/pages/[org]/[site]/access-mgmt/hid-qr-code/index.vue +23 -0
- package/pages/[org]/[site]/access-mgmt/hid-readers/index.vue +1 -1
- package/types/document.d.ts +14 -0
- package/types/facility.d.ts +4 -0
- package/types/people.d.ts +28 -1
- package/utils/building-map.ts +179 -8
- package/utils/hid-permission-assignments.ts +190 -0
- package/utils/occupancy-role.ts +109 -0
- package/utils/permission-labels.ts +30 -0
- package/utils/robot-display.ts +89 -0
package/composables/useRobots.ts
CHANGED
|
@@ -53,6 +53,27 @@ export default function useRobots() {
|
|
|
53
53
|
});
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
/**
|
|
57
|
+
* Rename a robot, or set its serial. The brand and the credentials are not
|
|
58
|
+
* editable: a wrong credential is replaced by removing the robot and adding
|
|
59
|
+
* it again, because the old value is never shown.
|
|
60
|
+
*/
|
|
61
|
+
function updateRobot(id: string, payload: { name?: string; robotSn?: string }) {
|
|
62
|
+
return useNuxtApp().$api<Record<string, any>>(`/api/robots/${id}`, {
|
|
63
|
+
method: "PATCH",
|
|
64
|
+
query: { appSlug },
|
|
65
|
+
body: payload,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Remove a robot. It stops listing and answering; the record is kept. */
|
|
70
|
+
function deleteRobot(id: string) {
|
|
71
|
+
return useNuxtApp().$api<Record<string, any>>(`/api/robots/${id}`, {
|
|
72
|
+
method: "DELETE",
|
|
73
|
+
query: { appSlug },
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
56
77
|
/** Live state — mode, online, whether it can take a job right now. */
|
|
57
78
|
function getRobotState(id: string) {
|
|
58
79
|
return useNuxtApp().$api<Record<string, any>>(
|
|
@@ -199,11 +220,101 @@ export default function useRobots() {
|
|
|
199
220
|
);
|
|
200
221
|
}
|
|
201
222
|
|
|
223
|
+
/* ---------------------------------------- building maps and lifts */
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* A robot's saved building maps, newest first (a summary; `getBuildingMap`
|
|
227
|
+
* has the full layout). No saved map is normal - the 3D view then shows the
|
|
228
|
+
* robot's own floor plans exactly as before.
|
|
229
|
+
*/
|
|
230
|
+
function listBuildingMaps(robotId: string, { page = 1, limit = 10 } = {}) {
|
|
231
|
+
return useNuxtApp().$api<Record<string, any>>("/api/robots/building-maps", {
|
|
232
|
+
method: "GET",
|
|
233
|
+
query: { robot: robotId, page, limit, appSlug },
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function getBuildingMap(mapId: string) {
|
|
238
|
+
return useNuxtApp().$api<Record<string, any>>(`/api/robots/building-maps/${mapId}`, {
|
|
239
|
+
method: "GET",
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/** Save a first map for a robot's building. The estate comes from the robot. */
|
|
244
|
+
function createBuildingMap(payload: Record<string, any> & { robotId: string }) {
|
|
245
|
+
return useNuxtApp().$api<Record<string, any>>("/api/robots/building-maps", {
|
|
246
|
+
method: "POST",
|
|
247
|
+
query: { appSlug },
|
|
248
|
+
body: payload,
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Save an edited map. `version` is the one the editor loaded; if somebody
|
|
254
|
+
* else saved since, the server refuses (409) rather than overwrite them.
|
|
255
|
+
*/
|
|
256
|
+
function updateBuildingMap(mapId: string, payload: Record<string, any> & { version: number }) {
|
|
257
|
+
return useNuxtApp().$api<Record<string, any>>(`/api/robots/building-maps/${mapId}`, {
|
|
258
|
+
method: "PATCH",
|
|
259
|
+
body: payload,
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function deleteBuildingMap(mapId: string) {
|
|
264
|
+
return useNuxtApp().$api<Record<string, any>>(`/api/robots/building-maps/${mapId}`, {
|
|
265
|
+
method: "DELETE",
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/** Every lift on the map: the (simulated) car, who holds it, who is waiting. */
|
|
270
|
+
function getLiftQueue(mapId: string) {
|
|
271
|
+
return useNuxtApp().$api<Record<string, any>>(`/api/robots/building-maps/${mapId}/lifts`, {
|
|
272
|
+
method: "GET",
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
function requestLift(
|
|
277
|
+
mapId: string,
|
|
278
|
+
liftName: string,
|
|
279
|
+
payload: { robotId: string; fromFloor: number; toFloor: number },
|
|
280
|
+
) {
|
|
281
|
+
return useNuxtApp().$api<Record<string, any>>(
|
|
282
|
+
`/api/robots/building-maps/${mapId}/lifts/${encodeURIComponent(liftName)}/sessions`,
|
|
283
|
+
{ method: "POST", query: { appSlug }, body: payload },
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/** Give the lift back, or leave the queue. */
|
|
288
|
+
function releaseLiftSession(sessionId: string) {
|
|
289
|
+
return useNuxtApp().$api<Record<string, any>>(`/api/robots/lift-sessions/${sessionId}/release`, {
|
|
290
|
+
method: "POST",
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/** This robot's open lift request and its place in the queue, or null. */
|
|
295
|
+
function getRobotLiftSession(robotId: string) {
|
|
296
|
+
return useNuxtApp().$api<Record<string, any>>(`/api/robots/${robotId}/lift-session`, {
|
|
297
|
+
method: "GET",
|
|
298
|
+
query: { appSlug },
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
|
|
202
302
|
return {
|
|
303
|
+
listBuildingMaps,
|
|
304
|
+
getBuildingMap,
|
|
305
|
+
createBuildingMap,
|
|
306
|
+
updateBuildingMap,
|
|
307
|
+
deleteBuildingMap,
|
|
308
|
+
getLiftQueue,
|
|
309
|
+
requestLift,
|
|
310
|
+
releaseLiftSession,
|
|
311
|
+
getRobotLiftSession,
|
|
203
312
|
getRobots,
|
|
204
313
|
getRobotBrands,
|
|
205
314
|
trackRobot,
|
|
206
315
|
createRobot,
|
|
316
|
+
updateRobot,
|
|
317
|
+
deleteRobot,
|
|
207
318
|
getRobotState,
|
|
208
319
|
getRobotMaps,
|
|
209
320
|
getRobotMapImages,
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE CATEGORY OF THE SITE THE USER IS CURRENTLY IN.
|
|
3
|
+
*
|
|
4
|
+
* One shared answer, published once by the application's layout from the site
|
|
5
|
+
* it already loaded for the switcher, and read by anything that has to behave
|
|
6
|
+
* differently on a commercial or industrial site - the business Add Tenant
|
|
7
|
+
* form, the tenant list. Publishing it rather than re-fetching it per
|
|
8
|
+
* component means no two screens can disagree about which site this is.
|
|
9
|
+
*
|
|
10
|
+
* READ FROM THE CUSTOMER-SITE RECORD, NOT THE SITE RECORD. Both carry a
|
|
11
|
+
* `category` and `customer-site.service` keeps them equal (it writes the site
|
|
12
|
+
* on create and on update), but `siteSchema` DEFAULTS the site's own copy to
|
|
13
|
+
* `commercial` - so a site created without an explicit category reads back as
|
|
14
|
+
* commercial there even when it is a residential estate. The customer-site
|
|
15
|
+
* copy has no default: it is either the category somebody chose or nothing.
|
|
16
|
+
*
|
|
17
|
+
* An empty category means "not published yet" or "never set", and every
|
|
18
|
+
* caller must behave as it did before this existed - never assume commercial
|
|
19
|
+
* from silence.
|
|
20
|
+
*/
|
|
21
|
+
const BUSINESS_SITE_CATEGORIES: string[] = ["commercial", "industrial"];
|
|
22
|
+
|
|
23
|
+
export default function useSiteCategory() {
|
|
24
|
+
const siteCategory = useState<string>("current-site-category", () => "");
|
|
25
|
+
|
|
26
|
+
function setSiteCategory(value?: string | null) {
|
|
27
|
+
siteCategory.value = typeof value === "string" ? value : "";
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The categories whose units are LET TO A BUSINESS rather than lived in.
|
|
32
|
+
*
|
|
33
|
+
* These are the sites where a unit has an owner, an occupier and often a
|
|
34
|
+
* person in charge who is neither, so they are the sites that ask for a
|
|
35
|
+
* tenant's standing and print it back (see `OCCUPANCY_ROLE_OPTIONS`).
|
|
36
|
+
*
|
|
37
|
+
* The category never changes what the APPLICATION is called: the rail says
|
|
38
|
+
* Property Management on every site it serves.
|
|
39
|
+
*/
|
|
40
|
+
const isBusinessSite = computed(() =>
|
|
41
|
+
BUSINESS_SITE_CATEGORIES.includes(siteCategory.value),
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
return { siteCategory, isBusinessSite, setSiteCategory };
|
|
45
|
+
}
|
|
@@ -27,9 +27,35 @@ export default function useSiteEntryPassSettings() {
|
|
|
27
27
|
);
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
/**
|
|
31
|
+
* The encrypted ACM URL the access-card screens hand to API-core, which
|
|
32
|
+
* decrypts it and sends the ACM commands to that host.
|
|
33
|
+
*
|
|
34
|
+
* Resolves the site's own "Enter entrypass URL" setting first, the way
|
|
35
|
+
* `VisitorForm` does for contractor passes. The access-card forms used to
|
|
36
|
+
* call `/api/encrypt-acm-url` with no `url`, so every site's door/lift
|
|
37
|
+
* levels and access groups came from the route's hardcoded default host
|
|
38
|
+
* whatever the site had configured. A site with no URL set, or whose
|
|
39
|
+
* settings cannot be read, still gets that default.
|
|
40
|
+
*/
|
|
41
|
+
async function getEncryptedAcmUrl(siteId: string): Promise<string> {
|
|
42
|
+
let rawUrl = "";
|
|
43
|
+
try {
|
|
44
|
+
const settings: any = await getBySiteId(siteId);
|
|
45
|
+
rawUrl = String(settings?.data?.settings?.url ?? "").trim();
|
|
46
|
+
} catch {
|
|
47
|
+
// No entry pass settings for this site yet - the default host applies.
|
|
48
|
+
}
|
|
49
|
+
const { encrypted } = await $fetch<{ encrypted: string }>(
|
|
50
|
+
`/api/encrypt-acm-url${rawUrl ? `?url=${encodeURIComponent(rawUrl)}` : ""}`,
|
|
51
|
+
);
|
|
52
|
+
return encrypted;
|
|
53
|
+
}
|
|
54
|
+
|
|
30
55
|
return {
|
|
31
56
|
getBySiteId,
|
|
32
57
|
getById,
|
|
33
58
|
save,
|
|
59
|
+
getEncryptedAcmUrl,
|
|
34
60
|
};
|
|
35
61
|
}
|
package/composables/useWebUsb.ts
CHANGED
|
@@ -345,16 +345,19 @@ export default function useWebUsb() {
|
|
|
345
345
|
70,
|
|
346
346
|
);
|
|
347
347
|
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
348
|
+
// The pass used to print five copies of the same QR - four 140px ones at
|
|
349
|
+
// the corners around a 250px centre - so a strip could be cut apart. It now
|
|
350
|
+
// prints a single large QR filling that same band (y 90 to 440, above the
|
|
351
|
+
// company name at y 470), which scans far more reliably on a thermal print.
|
|
352
|
+
// Generated at the size it is drawn at: the old corner copies were
|
|
353
|
+
// downscaled from the 250px canvas, which softened their modules.
|
|
354
|
+
const qrSize = 350;
|
|
355
|
+
const qrCanvas = await QRCode.toCanvas(qrUrlImage, {
|
|
356
|
+
width: qrSize,
|
|
357
|
+
margin: 1,
|
|
358
|
+
});
|
|
352
359
|
|
|
353
|
-
ctx.drawImage(qrCanvas,
|
|
354
|
-
ctx.drawImage(qrCanvas, canvas.width - qrSmall - margin, 90, qrSmall, qrSmall);
|
|
355
|
-
ctx.drawImage(qrCanvas, (canvas.width - qrCenter) / 2, 110, qrCenter, qrCenter);
|
|
356
|
-
ctx.drawImage(qrCanvas, margin, 300, qrSmall, qrSmall);
|
|
357
|
-
ctx.drawImage(qrCanvas, canvas.width - qrSmall - margin, 300, qrSmall, qrSmall);
|
|
360
|
+
ctx.drawImage(qrCanvas, (canvas.width - qrSize) / 2, 90, qrSize, qrSize);
|
|
358
361
|
|
|
359
362
|
ctx.font = "25px Arial";
|
|
360
363
|
ctx.fillText(companyName || "", canvas.width / 2, 470);
|
|
@@ -401,8 +404,8 @@ export default function useWebUsb() {
|
|
|
401
404
|
/**
|
|
402
405
|
* The self-service onboarding QR: one large QR code, a "SCAN QR CODE"-style
|
|
403
406
|
* subtext, and a dark site-name banner along the bottom - a single-purpose
|
|
404
|
-
* gate sign, not the
|
|
405
|
-
*
|
|
407
|
+
* gate sign, not the visitor-pass receipt `createReceiptLayout` produces
|
|
408
|
+
* (that one pairs its QR with company, date, access and instruction lines).
|
|
406
409
|
*/
|
|
407
410
|
async function createOnboardingQrLayout(
|
|
408
411
|
qrUrlImage: string,
|
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.
|
|
5
|
+
"version": "4.26.1-staging.354",
|
|
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.",
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
:org="orgId"
|
|
6
6
|
message="Enable HID as a service for this site before managing physical HID cards."
|
|
7
7
|
>
|
|
8
|
-
<HidUserEnrollment :site="siteId" card-management />
|
|
8
|
+
<HidUserEnrollment :site="siteId" :org="orgId" card-management />
|
|
9
9
|
</HidEnabledGate>
|
|
10
10
|
</v-container>
|
|
11
11
|
</template>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<v-container fluid>
|
|
3
|
+
<HidEnabledGate
|
|
4
|
+
:site="siteId"
|
|
5
|
+
:org="orgId"
|
|
6
|
+
message="Enable HID as a service for this site before generating a QR code."
|
|
7
|
+
>
|
|
8
|
+
<HidProfileQrCode :site="siteId" />
|
|
9
|
+
</HidEnabledGate>
|
|
10
|
+
</v-container>
|
|
11
|
+
</template>
|
|
12
|
+
|
|
13
|
+
<script setup lang="ts">
|
|
14
|
+
definePageMeta({
|
|
15
|
+
layout: "default",
|
|
16
|
+
middleware: ["01-auth", "02-org"],
|
|
17
|
+
memberOnly: true,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const route = useRoute();
|
|
21
|
+
const siteId = computed(() => String(route.params.site ?? ""));
|
|
22
|
+
const orgId = computed(() => String(route.params.org ?? ""));
|
|
23
|
+
</script>
|
package/types/document.d.ts
CHANGED
|
@@ -3,4 +3,18 @@ declare type TDocument = {
|
|
|
3
3
|
name: string;
|
|
4
4
|
attachment: string;
|
|
5
5
|
type: string;
|
|
6
|
+
/**
|
|
7
|
+
* Set at upload or renewal, absent when the document never expires.
|
|
8
|
+
*
|
|
9
|
+
* An ISO instant on the way out of the API and a `YYYY-MM-DD` string on the
|
|
10
|
+
* way back in, which is what `InputDatePicker` binds to - hence the loose
|
|
11
|
+
* type rather than `string`.
|
|
12
|
+
*/
|
|
13
|
+
expiryDate?: string | Date | null;
|
|
14
|
+
remarks?: string;
|
|
15
|
+
size?: number;
|
|
16
|
+
parentId?: string | null;
|
|
17
|
+
createdAt?: string | Date;
|
|
18
|
+
updatedAt?: string | Date;
|
|
19
|
+
status?: string;
|
|
6
20
|
};
|
package/types/facility.d.ts
CHANGED
|
@@ -73,6 +73,10 @@ declare type TFacility = {
|
|
|
73
73
|
hourInterval?: number;
|
|
74
74
|
isBookingFeeEnabled: boolean;
|
|
75
75
|
isGuestEnabled: boolean;
|
|
76
|
+
/** Residents may complete this facility's checklist themselves. */
|
|
77
|
+
isResidentChecklistEnabled?: boolean;
|
|
78
|
+
/** Security may complete it. Mutually exclusive with the above. */
|
|
79
|
+
isSecurityChecklistEnabled?: boolean;
|
|
76
80
|
bookingAmount: number | null;
|
|
77
81
|
peakBookingFeeAmount?: number | null;
|
|
78
82
|
bookingFeeGuestAmount?: number | null;
|
package/types/people.d.ts
CHANGED
|
@@ -22,11 +22,38 @@ declare type TPeople = {
|
|
|
22
22
|
email?: string;
|
|
23
23
|
files?: { name: string, id: string }[];
|
|
24
24
|
isOwner?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Owner / occupant / person-in-charge, as the BUSINESS people form asks it.
|
|
27
|
+
* Absent on everyone else - `isOwner` is still the flag that decides unit
|
|
28
|
+
* ownership, and the server derives it from this when it is sent. See
|
|
29
|
+
* `OccupancyRoles` in core's `person.model.ts`.
|
|
30
|
+
*/
|
|
31
|
+
occupancyRole?: TOccupancyRole;
|
|
32
|
+
// Link to this person's `users` row. Empty for the person types that carry
|
|
33
|
+
// no login, and empty for a resident whose account was never written.
|
|
34
|
+
user?: string;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
declare type TOccupancyRole = "owner" | "occupant" | "person-in-charge";
|
|
38
|
+
|
|
39
|
+
/** One standing and everything the product says about it. See `utils/occupancy-role.ts`. */
|
|
40
|
+
declare type TOccupancyRoleOption = {
|
|
41
|
+
value: TOccupancyRole;
|
|
42
|
+
/** The label a stored role is printed with. */
|
|
43
|
+
title: string;
|
|
44
|
+
/** The row menu's wording. */
|
|
45
|
+
action: string;
|
|
46
|
+
/** The confirmation's heading and its sentence. */
|
|
47
|
+
prompt: string;
|
|
48
|
+
description: string;
|
|
25
49
|
};
|
|
26
50
|
|
|
27
51
|
declare type TPlateNumber = { plateNumber: string, recNo?: string, _id?: string, status: TVehicleStatus, type: TVehicleType, anprCameras?: TVehicleAnprCamera[] };
|
|
28
52
|
|
|
29
53
|
|
|
30
|
-
|
|
54
|
+
// `""` is the FORM's "nothing picked yet" - it is stripped from the payload
|
|
55
|
+
// before it is sent, because absence is what the server reads as "never
|
|
56
|
+
// asked". See `PeopleFormMgmt.vue`.
|
|
57
|
+
declare type TPeoplePayload = Pick<TGuest, "name" | "block" | "level" | "unit" | "unitName" | "contact" | "plateNumber" | "nric" | "contact" | "remarks" | "org" | "site" | "start" | "end" | "type" | "isOwner"> & { status?: string; user?: string; occupancyRole?: TOccupancyRole | "" }
|
|
31
58
|
|
|
32
59
|
declare type TPeopleType = "guest" | "resident" | "tenant"
|
package/utils/building-map.ts
CHANGED
|
@@ -47,6 +47,8 @@ export type TWallSolid = {
|
|
|
47
47
|
thicknessM: number;
|
|
48
48
|
heightM: number;
|
|
49
49
|
yaw: number;
|
|
50
|
+
/** What the box is, so the renderer can colour it. Absent = a wall. */
|
|
51
|
+
kind?: "wall" | "door" | "lift" | "car";
|
|
50
52
|
};
|
|
51
53
|
|
|
52
54
|
/* ------------------------------------------------- image to occupancy grid */
|
|
@@ -333,12 +335,23 @@ export function fitView(
|
|
|
333
335
|
const bounds = solidsBounds(solids);
|
|
334
336
|
if (!bounds) return base;
|
|
335
337
|
|
|
336
|
-
|
|
338
|
+
// Heights count too: a stacked building's top storey must fit on the canvas,
|
|
339
|
+
// not just its footprint. A single level spans 0..wall height as before.
|
|
340
|
+
let minZ = Infinity;
|
|
341
|
+
let maxZ = -Infinity;
|
|
342
|
+
for (const w of solids) {
|
|
343
|
+
minZ = Math.min(minZ, w.centre.z - w.heightM / 2);
|
|
344
|
+
maxZ = Math.max(maxZ, w.centre.z + w.heightM / 2);
|
|
345
|
+
}
|
|
346
|
+
const corners = [
|
|
337
347
|
{ x: bounds.minX, y: bounds.minY },
|
|
338
348
|
{ x: bounds.maxX, y: bounds.minY },
|
|
339
349
|
{ x: bounds.maxX, y: bounds.maxY },
|
|
340
350
|
{ x: bounds.minX, y: bounds.maxY },
|
|
341
|
-
]
|
|
351
|
+
];
|
|
352
|
+
const projected = [0, minZ, maxZ].flatMap((z) =>
|
|
353
|
+
corners.map((p) => projectPoint(p.x, p.y, z, { ...base, zoom: 1, originPx: { x: 0, y: 0 } })),
|
|
354
|
+
);
|
|
342
355
|
|
|
343
356
|
const spanX = Math.max(...projected.map((p) => p.x)) - Math.min(...projected.map((p) => p.x));
|
|
344
357
|
const spanY = Math.max(...projected.map((p) => p.y)) - Math.min(...projected.map((p) => p.y));
|
|
@@ -350,12 +363,12 @@ export function fitView(
|
|
|
350
363
|
? Math.min(usableW / spanX, usableH / spanY)
|
|
351
364
|
: base.zoom;
|
|
352
365
|
|
|
353
|
-
const
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
366
|
+
const unit = { ...base, zoom, originPx: { x: 0, y: 0 } };
|
|
367
|
+
const all = [0, minZ, maxZ].flatMap((z) => corners.map((p) => projectPoint(p.x, p.y, z, unit)));
|
|
368
|
+
const centre = {
|
|
369
|
+
x: (Math.min(...all.map((p) => p.x)) + Math.max(...all.map((p) => p.x))) / 2,
|
|
370
|
+
y: (Math.min(...all.map((p) => p.y)) + Math.max(...all.map((p) => p.y))) / 2,
|
|
371
|
+
};
|
|
359
372
|
|
|
360
373
|
return {
|
|
361
374
|
rotation,
|
|
@@ -364,3 +377,161 @@ export function fitView(
|
|
|
364
377
|
originPx: { x: canvas.width / 2 - centre.x, y: canvas.height / 2 - centre.y },
|
|
365
378
|
};
|
|
366
379
|
}
|
|
380
|
+
|
|
381
|
+
/** Storey height used to stack levels when the plans carry no elevation. */
|
|
382
|
+
export const STOREY_HEIGHT_M = 4;
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* Where each floor sits when the building is shown stacked.
|
|
386
|
+
*
|
|
387
|
+
* The robot's maps give a floor NUMBER and nothing about height, so floors are
|
|
388
|
+
* stacked in number order one storey apart. Missing numbers do not leave gaps:
|
|
389
|
+
* a robot mapping floors 1 and 5 shows two levels, not five.
|
|
390
|
+
*
|
|
391
|
+
* ponytail: equal storeys. Real heights need building-map persistence, which
|
|
392
|
+
* is an owner decision still open.
|
|
393
|
+
*/
|
|
394
|
+
export function stackedElevations(
|
|
395
|
+
floorNos: number[],
|
|
396
|
+
storeyM = STOREY_HEIGHT_M,
|
|
397
|
+
): Map<number, number> {
|
|
398
|
+
const ordered = [...new Set(floorNos.filter((n) => Number.isFinite(n)))].sort((a, b) => a - b);
|
|
399
|
+
return new Map(ordered.map((floorNo, i) => [floorNo, i * storeyM]));
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/* ------------------------------------------------ saved map features */
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* The saved building map's editable features, in site metres - the shapes
|
|
406
|
+
* `@7365admin1/core` validates in `robot-building-map.model.ts`.
|
|
407
|
+
*/
|
|
408
|
+
export type TMapPointM = { x: number; y: number };
|
|
409
|
+
export type TMapDoor = {
|
|
410
|
+
name: string;
|
|
411
|
+
floorNo: number;
|
|
412
|
+
type: "hinged" | "sliding";
|
|
413
|
+
start: TMapPointM;
|
|
414
|
+
end: TMapPointM;
|
|
415
|
+
};
|
|
416
|
+
export type TMapLift = {
|
|
417
|
+
name: string;
|
|
418
|
+
x: number;
|
|
419
|
+
y: number;
|
|
420
|
+
widthM: number;
|
|
421
|
+
depthM: number;
|
|
422
|
+
floors: number[];
|
|
423
|
+
};
|
|
424
|
+
|
|
425
|
+
/** A door is shorter than a wall and sits in it. */
|
|
426
|
+
export const DOOR_HEIGHT_M = 2.1;
|
|
427
|
+
export const DOOR_THICKNESS_M = 0.18;
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* Each floor's height: the saved elevation where somebody set one, otherwise
|
|
431
|
+
* one storey above the floor below. So a building with no saved heights stacks
|
|
432
|
+
* exactly as it did before a map was saved.
|
|
433
|
+
*/
|
|
434
|
+
export function levelElevations(
|
|
435
|
+
floorNos: number[],
|
|
436
|
+
saved: Array<{ floorNo: number; elevationM?: number | null }> = [],
|
|
437
|
+
storeyM = STOREY_HEIGHT_M,
|
|
438
|
+
): Map<number, number> {
|
|
439
|
+
const out = new Map<number, number>();
|
|
440
|
+
for (const [floorNo, z] of stackedElevations(floorNos, storeyM)) {
|
|
441
|
+
const set = saved.find((l) => l.floorNo === floorNo)?.elevationM;
|
|
442
|
+
out.set(floorNo, typeof set === "number" && Number.isFinite(set) ? set : z);
|
|
443
|
+
}
|
|
444
|
+
return out;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
/** A door as a box standing in its wall. Null for a zero-length door. */
|
|
448
|
+
export function doorSolid(door: TMapDoor, elevationM: number): TWallSolid | null {
|
|
449
|
+
const lengthM = Math.hypot(door.end.x - door.start.x, door.end.y - door.start.y);
|
|
450
|
+
if (!(lengthM > 0)) return null;
|
|
451
|
+
return {
|
|
452
|
+
kind: "door",
|
|
453
|
+
centre: {
|
|
454
|
+
x: (door.start.x + door.end.x) / 2,
|
|
455
|
+
y: (door.start.y + door.end.y) / 2,
|
|
456
|
+
z: elevationM + DOOR_HEIGHT_M / 2,
|
|
457
|
+
},
|
|
458
|
+
lengthM,
|
|
459
|
+
thicknessM: DOOR_THICKNESS_M,
|
|
460
|
+
heightM: DOOR_HEIGHT_M,
|
|
461
|
+
yaw: Math.atan2(door.end.y - door.start.y, door.end.x - door.start.x),
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* A lift shaft as one box from the lowest floor it serves to the top of the
|
|
467
|
+
* highest - through every storey in between, which is the point of drawing it.
|
|
468
|
+
* With `onlyFloor`, just that storey's slice (single-level view); null when
|
|
469
|
+
* the shaft does not stop there.
|
|
470
|
+
*/
|
|
471
|
+
export function liftSolid(
|
|
472
|
+
lift: TMapLift,
|
|
473
|
+
elevations: Map<number, number>,
|
|
474
|
+
onlyFloor?: number,
|
|
475
|
+
): TWallSolid | null {
|
|
476
|
+
if (onlyFloor !== undefined && !lift.floors.includes(onlyFloor)) return null;
|
|
477
|
+
const zs = onlyFloor !== undefined
|
|
478
|
+
? [0]
|
|
479
|
+
: lift.floors.filter((f) => elevations.has(f)).map((f) => elevations.get(f) ?? 0);
|
|
480
|
+
if (!zs.length) return null;
|
|
481
|
+
const bottom = Math.min(...zs);
|
|
482
|
+
const top = Math.max(...zs) + WALL_HEIGHT_M;
|
|
483
|
+
return {
|
|
484
|
+
kind: "lift",
|
|
485
|
+
centre: { x: lift.x, y: lift.y, z: (bottom + top) / 2 },
|
|
486
|
+
lengthM: lift.widthM,
|
|
487
|
+
thicknessM: lift.depthM,
|
|
488
|
+
heightM: top - bottom,
|
|
489
|
+
yaw: 0,
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* A screen point back to site metres, on the horizontal plane at height `z` -
|
|
495
|
+
* the exact inverse of `projectPoint`. The editor uses it to place what the
|
|
496
|
+
* pointer clicked; it always edits in the flat plan view.
|
|
497
|
+
*/
|
|
498
|
+
export function unprojectPoint(
|
|
499
|
+
sx: number,
|
|
500
|
+
sy: number,
|
|
501
|
+
view: TView,
|
|
502
|
+
z = 0,
|
|
503
|
+
): { x: number; y: number } {
|
|
504
|
+
const rx = (sx - view.originPx.x) / view.zoom;
|
|
505
|
+
const ry =
|
|
506
|
+
(sy - view.originPx.y + z * view.zoom * Math.sin(view.tilt)) /
|
|
507
|
+
(view.zoom * Math.cos(view.tilt));
|
|
508
|
+
const cos = Math.cos(view.rotation);
|
|
509
|
+
const sin = Math.sin(view.rotation);
|
|
510
|
+
return { x: rx * cos + ry * sin, y: -rx * sin + ry * cos };
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
/** Distance from a point to a segment, metres. The editor's door hit test. */
|
|
514
|
+
export function distanceToSegment(p: TMapPointM, a: TMapPointM, b: TMapPointM): number {
|
|
515
|
+
const dx = b.x - a.x;
|
|
516
|
+
const dy = b.y - a.y;
|
|
517
|
+
const len2 = dx * dx + dy * dy;
|
|
518
|
+
const t = len2 ? Math.max(0, Math.min(1, ((p.x - a.x) * dx + (p.y - a.y) * dy) / len2)) : 0;
|
|
519
|
+
return Math.hypot(p.x - (a.x + t * dx), p.y - (a.y + t * dy));
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
/** Is the point inside the lift's footprint? */
|
|
523
|
+
export function insideLift(p: TMapPointM, lift: TMapLift): boolean {
|
|
524
|
+
return Math.abs(p.x - lift.x) <= lift.widthM / 2 && Math.abs(p.y - lift.y) <= lift.depthM / 2;
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
/** The next free default name: Lift A, Lift B, ... / Door 1, Door 2, ... */
|
|
528
|
+
export function nextFeatureName(existing: string[], kind: "lift" | "door"): string {
|
|
529
|
+
const taken = new Set(existing);
|
|
530
|
+
for (let i = 0; i < 500; i++) {
|
|
531
|
+
const name = kind === "lift"
|
|
532
|
+
? `Lift ${i < 26 ? String.fromCharCode(65 + i) : i + 1}`
|
|
533
|
+
: `Door ${i + 1}`;
|
|
534
|
+
if (!taken.has(name)) return name;
|
|
535
|
+
}
|
|
536
|
+
return `${kind === "lift" ? "Lift" : "Door"} ${existing.length + 1}`;
|
|
537
|
+
}
|