@7365admin1/layer-common 4.97.1-staging.541 → 4.97.1-staging.543
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/components/AddPassKeyToVisitor.vue +5 -0
- package/components/DocumentManagement.vue +56 -3
- package/components/FeedbackHandlingSettings.vue +385 -0
- package/components/HandoverChecklistRecords.vue +223 -0
- package/components/HandoverChecklistSetup.vue +224 -0
- package/components/IncidentReportEmailsSettings.vue +88 -0
- package/components/KeyPressFilter.vue +43 -0
- package/components/KeyPressName.vue +14 -0
- package/components/KeyPressSelect.vue +31 -0
- package/components/KeySettingsPanel.vue +156 -0
- package/components/ListCsvExport.vue +71 -0
- package/components/MaStaffRegistrationSettings.vue +61 -0
- package/components/MemberSiteAccess.vue +51 -2
- package/components/PassInformation.vue +5 -0
- package/components/RolePermissionFormCreate.vue +33 -0
- package/components/SiteDataRetention.vue +286 -0
- package/components/SiteSettings.vue +48 -0
- package/components/SiteSettingsVisitorRegistration.vue +118 -0
- package/components/VisitorForm.vue +38 -3
- package/components/VisitorManagement.vue +3 -1
- package/composables/useDataRetention.ts +43 -0
- package/composables/useDocument.ts +13 -0
- package/composables/useFeedback.ts +12 -0
- package/composables/useHandoverChecklist.ts +111 -0
- package/composables/useKeyPresses.ts +57 -0
- package/composables/useMember.ts +6 -0
- package/composables/usePassKey.ts +4 -0
- package/composables/useSiteFeatureSettings.ts +37 -0
- package/composables/useVisitor.ts +22 -0
- package/package.json +2 -2
- package/types/key-log.d.ts +2 -0
- package/types/passKey.d.ts +2 -0
- package/utils/feedback-handling-settings.ts +139 -0
- package/utils/inventory-presets.ts +64 -0
- package/utils/key-presses.ts +55 -0
- package/utils/list-export.ts +39 -0
- package/utils/site-access.ts +13 -1
|
@@ -162,6 +162,17 @@ export default function useFeedback() {
|
|
|
162
162
|
);
|
|
163
163
|
}
|
|
164
164
|
|
|
165
|
+
/** A linked copy of this feedback for another provider at the same site. */
|
|
166
|
+
function sendToProvider(id: string, provider: string) {
|
|
167
|
+
return useNuxtApp().$api<Record<string, any>>(
|
|
168
|
+
"/api/feedbacks2/send-to-provider",
|
|
169
|
+
{
|
|
170
|
+
method: "POST",
|
|
171
|
+
body: { _id: id, provider },
|
|
172
|
+
}
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
|
|
165
176
|
function addFeedBackWorkOrder(payload: any) {
|
|
166
177
|
return useNuxtApp().$api<Record<string, any>>(
|
|
167
178
|
"/api/feedbacks2/create-work-order",
|
|
@@ -204,5 +215,6 @@ export default function useFeedback() {
|
|
|
204
215
|
updateStatusComplete,
|
|
205
216
|
addFeedBackWorkOrder,
|
|
206
217
|
updateStatusFeedback,
|
|
218
|
+
sendToProvider,
|
|
207
219
|
};
|
|
208
220
|
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Room handover / takeover checklists (API-core `/api/handover-checklists`).
|
|
3
|
+
* The managing agent sets up a checklist per room; guards fill one in at each
|
|
4
|
+
* handover (before use) and takeover (after use). No facility booking needed.
|
|
5
|
+
*/
|
|
6
|
+
export type THandoverItem = {
|
|
7
|
+
label: string;
|
|
8
|
+
quantity?: number | null;
|
|
9
|
+
tagNo?: string | null;
|
|
10
|
+
referencePhotoId?: string | null;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type THandoverTemplate = {
|
|
14
|
+
_id?: string;
|
|
15
|
+
title: string;
|
|
16
|
+
description?: string | null;
|
|
17
|
+
items: THandoverItem[];
|
|
18
|
+
updatedAt?: string;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export type THandoverRecordItem = THandoverItem & {
|
|
22
|
+
result: "in-order" | "not-in-order";
|
|
23
|
+
remarks?: string | null;
|
|
24
|
+
damagePhotoIds?: string[];
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export type THandoverRecord = {
|
|
28
|
+
_id: string;
|
|
29
|
+
templateId: string;
|
|
30
|
+
title: string;
|
|
31
|
+
stage: "handover" | "takeover";
|
|
32
|
+
items?: THandoverRecordItem[];
|
|
33
|
+
notInOrderCount?: number;
|
|
34
|
+
photoIds?: string[];
|
|
35
|
+
remarks?: string | null;
|
|
36
|
+
officerName?: string | null;
|
|
37
|
+
completedAt: string;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export const HANDOVER_STAGE_LABELS: Record<string, string> = {
|
|
41
|
+
handover: "Handover (before use)",
|
|
42
|
+
takeover: "Takeover (after use)",
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Ready-made checklists an MA can start from (renovation, move in / out). They
|
|
47
|
+
* only open the editor pre-filled; nothing is saved until the MA clicks Save.
|
|
48
|
+
*/
|
|
49
|
+
export const HANDOVER_STARTERS: Array<{ name: string; template: THandoverTemplate }> = [
|
|
50
|
+
{
|
|
51
|
+
name: "Lift & lobby protection (renovation)",
|
|
52
|
+
template: {
|
|
53
|
+
title: "Lift & lobby protection (renovation)",
|
|
54
|
+
description: "Check before renovation works start and again after they finish. Take photos of any damage.",
|
|
55
|
+
items: [
|
|
56
|
+
{ label: "Lift protection in place (wall panels and floor)" },
|
|
57
|
+
{ label: "Lobby floor protection in place" },
|
|
58
|
+
{ label: "Lift interior condition (walls, doors, floor, buttons)" },
|
|
59
|
+
{ label: "Lobby walls, doors and fittings condition" },
|
|
60
|
+
{ label: "Common corridor clean, no debris" },
|
|
61
|
+
],
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
name: "Move in / move out",
|
|
66
|
+
template: {
|
|
67
|
+
title: "Move in / move out",
|
|
68
|
+
description: "Check before the move starts and again after it ends. Take photos of any damage.",
|
|
69
|
+
items: [
|
|
70
|
+
{ label: "Lift protection in place" },
|
|
71
|
+
{ label: "Lobby floor protection in place" },
|
|
72
|
+
{ label: "Lift interior condition (walls, doors, floor, buttons)" },
|
|
73
|
+
{ label: "Lobby and corridor condition" },
|
|
74
|
+
{ label: "Loading bay / driveway clear and undamaged" },
|
|
75
|
+
],
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
];
|
|
79
|
+
|
|
80
|
+
export default function useHandoverChecklist() {
|
|
81
|
+
const base = "/api/handover-checklists";
|
|
82
|
+
|
|
83
|
+
function getTemplates(site: string) {
|
|
84
|
+
return useNuxtApp().$api<THandoverTemplate[]>(`${base}/templates/site/${site}`, { method: "GET" });
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function addTemplate(site: string, body: THandoverTemplate) {
|
|
88
|
+
return useNuxtApp().$api<{ _id: string }>(`${base}/templates/site/${site}`, { method: "POST", body });
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function updateTemplate(id: string, body: THandoverTemplate) {
|
|
92
|
+
return useNuxtApp().$api<Record<string, any>>(`${base}/templates/${id}`, { method: "PUT", body });
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function deleteTemplate(id: string) {
|
|
96
|
+
return useNuxtApp().$api<Record<string, any>>(`${base}/templates/${id}`, { method: "DELETE" });
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function getRecords(site: string, query: { page?: number; limit?: number; templateId?: string } = {}) {
|
|
100
|
+
return useNuxtApp().$api<{ items: THandoverRecord[]; total: number; page: number; limit: number }>(
|
|
101
|
+
`${base}/site/${site}`,
|
|
102
|
+
{ method: "GET", query },
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function getRecord(id: string) {
|
|
107
|
+
return useNuxtApp().$api<THandoverRecord>(`${base}/${id}`, { method: "GET" });
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return { getTemplates, addTemplate, updateTemplate, deleteTemplate, getRecords, getRecord };
|
|
111
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { readKeySettings, keyPressName, type TKeyPress } from "../utils/key-presses";
|
|
2
|
+
import useSite from "./useSite";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* One read per site per page load, shared by every caller (a list draws one
|
|
6
|
+
* press name per row). ponytail: never expires; a press added in another tab
|
|
7
|
+
* shows after a reload.
|
|
8
|
+
*/
|
|
9
|
+
const presses = new Map<string, Promise<TKeyPress[]>>();
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The site's key presses (`metadata.keySettings.cabinets`). Empty for a site
|
|
13
|
+
* that has none, which is every site until it adds one - every screen that
|
|
14
|
+
* uses this then looks exactly as before.
|
|
15
|
+
*/
|
|
16
|
+
export default function useKeyPresses(site: MaybeRefOrGetter<string>) {
|
|
17
|
+
const cabinets = ref<TKeyPress[]>([]);
|
|
18
|
+
const { getSiteById } = useSite();
|
|
19
|
+
|
|
20
|
+
async function load() {
|
|
21
|
+
const id = toValue(site);
|
|
22
|
+
// No site, or a site whose list is now empty: no press names left over.
|
|
23
|
+
if (!id) {
|
|
24
|
+
cabinets.value = [];
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (!presses.has(id)) {
|
|
28
|
+
presses.set(
|
|
29
|
+
id,
|
|
30
|
+
getSiteById(id)
|
|
31
|
+
.then((site) => readKeySettings(site).cabinets)
|
|
32
|
+
.catch(() => {
|
|
33
|
+
presses.delete(id);
|
|
34
|
+
return [];
|
|
35
|
+
}),
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
const list = await presses.get(id)!;
|
|
39
|
+
// A slower answer for a site the caller has since left is dropped.
|
|
40
|
+
if (toValue(site) === id) cabinets.value = Array.isArray(list) ? list : [];
|
|
41
|
+
}
|
|
42
|
+
watch(() => toValue(site), load, { immediate: true });
|
|
43
|
+
|
|
44
|
+
const nameOf = (id?: string | null) => keyPressName(cabinets.value, id);
|
|
45
|
+
/** For a key autocomplete's `item-props`: the press as the item's second line. */
|
|
46
|
+
const keyItemProps = (item: any) => {
|
|
47
|
+
const name = nameOf(item?.cabinet);
|
|
48
|
+
return name ? { subtitle: name } : {};
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/** After the site's presses are saved: read them again. */
|
|
52
|
+
function forget(id: string = toValue(site)) {
|
|
53
|
+
presses.delete(id);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return { cabinets, nameOf, keyItemProps, load, forget };
|
|
57
|
+
}
|
package/composables/useMember.ts
CHANGED
|
@@ -201,6 +201,12 @@ export default function useMember() {
|
|
|
201
201
|
org: string;
|
|
202
202
|
user: string;
|
|
203
203
|
sites: Array<{ site: string; role: string }>;
|
|
204
|
+
/**
|
|
205
|
+
* Is this person one of the Security Ops officers who visits sites? One
|
|
206
|
+
* value for the whole person, written onto every site they end up with.
|
|
207
|
+
* Omit it and the server leaves the mark exactly as it is.
|
|
208
|
+
*/
|
|
209
|
+
securityOps?: boolean;
|
|
204
210
|
removeOrgAccess?: boolean;
|
|
205
211
|
}) {
|
|
206
212
|
return useNuxtApp().$api<Record<string, any>>("/api/members/site-access", {
|
|
@@ -125,6 +125,7 @@ export default function usePassKey() {
|
|
|
125
125
|
statuses = [],
|
|
126
126
|
sortBy,
|
|
127
127
|
prefixAndName,
|
|
128
|
+
cabinets,
|
|
128
129
|
}: {
|
|
129
130
|
_ids?: any;
|
|
130
131
|
page?: number;
|
|
@@ -137,6 +138,8 @@ export default function usePassKey() {
|
|
|
137
138
|
statuses?: string[] | null;
|
|
138
139
|
sortBy?: object;
|
|
139
140
|
prefixAndName?: string;
|
|
141
|
+
/** Key press ids; "" = keys in no press. Left out = no press filter. */
|
|
142
|
+
cabinets?: string[];
|
|
140
143
|
}) {
|
|
141
144
|
return useNuxtApp().$api("/api/keys/search/v1", {
|
|
142
145
|
method: "POST",
|
|
@@ -152,6 +155,7 @@ export default function usePassKey() {
|
|
|
152
155
|
statuses,
|
|
153
156
|
sortBy,
|
|
154
157
|
prefixAndName,
|
|
158
|
+
...(cabinets?.length ? { cabinets } : {}),
|
|
155
159
|
},
|
|
156
160
|
});
|
|
157
161
|
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-site switches (`site.metadata.<key>`, core `site-feature-settings.util.ts`).
|
|
3
|
+
*
|
|
4
|
+
* Every settings panel that writes one saves ONLY its own switch through
|
|
5
|
+
* `PATCH /api/sites/:id/feature-settings` `{ field: "metadata.<key>", value }`.
|
|
6
|
+
* Never the whole `metadata`: a panel that sends back what it read could wipe
|
|
7
|
+
* a switch another panel (or another person) saved in the meantime. The
|
|
8
|
+
* server validates the value and refuses data retention and feedback handling
|
|
9
|
+
* changes from anyone but the site's owner (or Seven365).
|
|
10
|
+
*/
|
|
11
|
+
export const SITE_FEATURE_KEYS = [
|
|
12
|
+
"visitorFields",
|
|
13
|
+
"keySettings",
|
|
14
|
+
"incidentReportEmails",
|
|
15
|
+
"feedbackSettings",
|
|
16
|
+
"dataRetention",
|
|
17
|
+
"maStaffRegistration",
|
|
18
|
+
] as const;
|
|
19
|
+
|
|
20
|
+
export type TSiteFeatureKey = (typeof SITE_FEATURE_KEYS)[number];
|
|
21
|
+
|
|
22
|
+
/** The request body for one switch. */
|
|
23
|
+
export function siteFeatureSettingBody(key: TSiteFeatureKey, value: unknown) {
|
|
24
|
+
if (!SITE_FEATURE_KEYS.includes(key)) throw new Error(`Unknown site setting: ${key}`);
|
|
25
|
+
return { field: `metadata.${key}`, value };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export default function useSiteFeatureSettings() {
|
|
29
|
+
async function saveSiteFeature(siteId: string, key: TSiteFeatureKey, value: unknown) {
|
|
30
|
+
return await useNuxtApp().$api<Record<string, any>>(`/api/sites/${siteId}/feature-settings`, {
|
|
31
|
+
method: "PATCH",
|
|
32
|
+
body: siteFeatureSettingBody(key, value),
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return { saveSiteFeature };
|
|
37
|
+
}
|
|
@@ -273,3 +273,25 @@ export default function () {
|
|
|
273
273
|
visitorDataFromScannedQRCodeCheckIn,
|
|
274
274
|
};
|
|
275
275
|
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* The site's guardhouse registration switches (`site.metadata.visitorFields`).
|
|
279
|
+
* Anything a site never saved reads as "default" = today's form.
|
|
280
|
+
*/
|
|
281
|
+
export type TVisitorFieldSwitches = {
|
|
282
|
+
nric: "default" | "hidden";
|
|
283
|
+
contact: "default" | "hidden" | "required";
|
|
284
|
+
vehicle: "default" | "required";
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
export function getVisitorFieldSwitches(site: any): TVisitorFieldSwitches {
|
|
288
|
+
const v = site?.metadata?.visitorFields ?? {};
|
|
289
|
+
return {
|
|
290
|
+
nric: v.nric === "hidden" ? "hidden" : "default",
|
|
291
|
+
contact: v.contact === "hidden" || v.contact === "required" ? v.contact : "default",
|
|
292
|
+
vehicle: v.vehicle === "required" ? "required" : "default",
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/** Same words as the server's refusal, so the guard reads one message. */
|
|
297
|
+
export const VEHICLE_REQUIRED_MESSAGE = "This site requires a vehicle number for every visitor.";
|
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.97.1-staging.
|
|
5
|
+
"version": "4.97.1-staging.543",
|
|
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.",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"build": "nuxt build .playground",
|
|
38
38
|
"generate": "nuxt generate .playground",
|
|
39
39
|
"preview": "nuxt preview .playground",
|
|
40
|
-
"test": "esbuild composables/useANPRSettings.ts --format=esm --outfile=test/.build/useANPRSettings.mjs --log-level=error && esbuild composables/useSite.ts --format=esm --outfile=test/.build/useSite.mjs --log-level=error && esbuild composables/useVisitorSocket.ts --format=esm --outfile=test/.build/useVisitorSocket.mjs --log-level=error && esbuild composables/usePlateToastWindow.ts --format=esm --outfile=test/.build/usePlateToastWindow.mjs --log-level=error && esbuild utils/client-invite-modules.ts --bundle --platform=node --format=esm --outfile=test/.build/client-invite-modules.mjs --log-level=error && esbuild utils/robot-display.ts --bundle --platform=node --format=esm --outfile=test/.build/robot-display.mjs --log-level=error && esbuild utils/building-map.ts --bundle --platform=node --format=esm --outfile=test/.build/building-map.mjs --log-level=error && esbuild utils/robot-building.ts --bundle --platform=node --format=esm --outfile=test/.build/robot-building.mjs --log-level=error && esbuild utils/robot-fleet-core.ts --bundle --platform=node --format=esm --outfile=test/.build/robot-fleet-core.mjs --log-level=error && esbuild utils/rmf-editor.ts --bundle --platform=node --format=esm --outfile=test/.build/rmf-editor.mjs --log-level=error && node --experimental-strip-types --test \"test/*.test.mjs\" && yarn test:units",
|
|
40
|
+
"test": "esbuild composables/useANPRSettings.ts --format=esm --outfile=test/.build/useANPRSettings.mjs --log-level=error && esbuild composables/useSite.ts --format=esm --outfile=test/.build/useSite.mjs --log-level=error && esbuild composables/useSiteFeatureSettings.ts --format=esm --outfile=test/.build/useSiteFeatureSettings.mjs --log-level=error && esbuild composables/useVisitor.ts --format=esm --outfile=test/.build/useVisitor.mjs --log-level=error && esbuild composables/useVisitorSocket.ts --format=esm --outfile=test/.build/useVisitorSocket.mjs --log-level=error && esbuild composables/usePlateToastWindow.ts --format=esm --outfile=test/.build/usePlateToastWindow.mjs --log-level=error && esbuild utils/client-invite-modules.ts --bundle --platform=node --format=esm --outfile=test/.build/client-invite-modules.mjs --log-level=error && esbuild utils/robot-display.ts --bundle --platform=node --format=esm --outfile=test/.build/robot-display.mjs --log-level=error && esbuild utils/building-map.ts --bundle --platform=node --format=esm --outfile=test/.build/building-map.mjs --log-level=error && esbuild utils/robot-building.ts --bundle --platform=node --format=esm --outfile=test/.build/robot-building.mjs --log-level=error && esbuild utils/robot-fleet-core.ts --bundle --platform=node --format=esm --outfile=test/.build/robot-fleet-core.mjs --log-level=error && esbuild utils/rmf-editor.ts --bundle --platform=node --format=esm --outfile=test/.build/rmf-editor.mjs --log-level=error && node --experimental-strip-types --test \"test/*.test.mjs\" && yarn test:units",
|
|
41
41
|
"test:units": "node --experimental-strip-types --test \"utils/*.test.ts\"",
|
|
42
42
|
"release": "yarn run build && changeset publish"
|
|
43
43
|
},
|
package/types/key-log.d.ts
CHANGED
package/types/passKey.d.ts
CHANGED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Site Settings -> "Feedback handling" (TLR, 2026-10-13): the form behind
|
|
3
|
+
* `FeedbackHandlingSettings.vue`, stored on the site as
|
|
4
|
+
* `metadata.feedbackSettings` and validated by core
|
|
5
|
+
* (`site-feature-settings.util.ts`).
|
|
6
|
+
*
|
|
7
|
+
* A site that never saved this reads as: Mon-Fri 09:00-18:00, holidays not
|
|
8
|
+
* excluded, no routes, escalation off, nothing auto-closed - which is exactly
|
|
9
|
+
* today's behaviour, because the server does nothing without a route, an
|
|
10
|
+
* enabled escalation or a listed category.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export type TFeedbackWindowTarget = "ma" | "provider";
|
|
14
|
+
|
|
15
|
+
export type TFeedbackRouteForm = {
|
|
16
|
+
category: string;
|
|
17
|
+
provider: string;
|
|
18
|
+
officeHours: TFeedbackWindowTarget;
|
|
19
|
+
afterHours: TFeedbackWindowTarget;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/** `id` is the level's stable key (set by the server on its first save; "" for a new step). */
|
|
23
|
+
export type TEscalationLevelForm = { id: string; afterHours: number | string; users: string[]; emails: string[] };
|
|
24
|
+
|
|
25
|
+
export type TFeedbackHandlingForm = {
|
|
26
|
+
workingDays: number[];
|
|
27
|
+
officeStart: string;
|
|
28
|
+
officeEnd: string;
|
|
29
|
+
excludePublicHolidays: boolean;
|
|
30
|
+
routes: TFeedbackRouteForm[];
|
|
31
|
+
escalationEnabled: boolean;
|
|
32
|
+
workingTimeOnly: boolean;
|
|
33
|
+
levels: TEscalationLevelForm[];
|
|
34
|
+
autoCloseCategories: string[];
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const MAX_ESCALATION_LEVELS = 5;
|
|
38
|
+
|
|
39
|
+
/** Mon first, as people read a week. `value` is the stored 0 = Sunday. */
|
|
40
|
+
export const WEEK_DAYS = [
|
|
41
|
+
{ title: "Mon", value: 1 },
|
|
42
|
+
{ title: "Tue", value: 2 },
|
|
43
|
+
{ title: "Wed", value: 3 },
|
|
44
|
+
{ title: "Thu", value: 4 },
|
|
45
|
+
{ title: "Fri", value: 5 },
|
|
46
|
+
{ title: "Sat", value: 6 },
|
|
47
|
+
{ title: "Sun", value: 0 },
|
|
48
|
+
];
|
|
49
|
+
|
|
50
|
+
const HHMM = /^([01]\d|2[0-3]):[0-5]\d$/;
|
|
51
|
+
const EMAIL = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
52
|
+
const OBJECT_ID = /^[a-f0-9]{24}$/i;
|
|
53
|
+
|
|
54
|
+
const list = (v: unknown) => (Array.isArray(v) ? v : []);
|
|
55
|
+
|
|
56
|
+
/** The stored value (or nothing) as the form. */
|
|
57
|
+
export function feedbackHandlingForm(stored: any): TFeedbackHandlingForm {
|
|
58
|
+
const s = stored && typeof stored === "object" ? stored : {};
|
|
59
|
+
const days = list(s.workingDays).filter((d: unknown) => Number.isInteger(d) && (d as number) >= 0 && (d as number) <= 6);
|
|
60
|
+
return {
|
|
61
|
+
workingDays: days.length ? days : [1, 2, 3, 4, 5],
|
|
62
|
+
officeStart: HHMM.test(s.officeStart) ? s.officeStart : "09:00",
|
|
63
|
+
officeEnd: HHMM.test(s.officeEnd) ? s.officeEnd : "18:00",
|
|
64
|
+
excludePublicHolidays: s.excludePublicHolidays === true,
|
|
65
|
+
routes: list(s.routes).map((r: any) => ({
|
|
66
|
+
category: String(r?.category ?? ""),
|
|
67
|
+
provider: r?.provider ? String(r.provider) : "",
|
|
68
|
+
officeHours: r?.officeHours === "provider" ? "provider" : "ma",
|
|
69
|
+
afterHours: r?.afterHours === "provider" ? "provider" : "ma",
|
|
70
|
+
})),
|
|
71
|
+
escalationEnabled: s.escalation?.enabled === true,
|
|
72
|
+
workingTimeOnly: s.escalation?.workingTimeOnly === true,
|
|
73
|
+
levels: list(s.escalation?.levels).map((l: any) => ({
|
|
74
|
+
id: typeof l?.id === "string" ? l.id : "",
|
|
75
|
+
afterHours: Number(l?.afterHours) || 1,
|
|
76
|
+
users: list(l?.users).map(String),
|
|
77
|
+
emails: list(l?.emails).map(String),
|
|
78
|
+
})),
|
|
79
|
+
autoCloseCategories: list(s.autoCloseCategories).map(String),
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Plain-English problems that stop a save; empty = fine. */
|
|
84
|
+
export function feedbackHandlingErrors(form: TFeedbackHandlingForm): string[] {
|
|
85
|
+
const errors: string[] = [];
|
|
86
|
+
if (!form.workingDays.length) errors.push("Pick at least one office day.");
|
|
87
|
+
if (!HHMM.test(form.officeStart) || !HHMM.test(form.officeEnd) || form.officeEnd <= form.officeStart)
|
|
88
|
+
errors.push("Office hours must end after they start.");
|
|
89
|
+
const seen = new Set<string>();
|
|
90
|
+
form.routes.forEach((r, i) => {
|
|
91
|
+
const row = `Row ${i + 1}`;
|
|
92
|
+
if (!r.category.trim()) errors.push(`${row}: choose a category.`);
|
|
93
|
+
else if (seen.has(r.category.trim().toLowerCase())) errors.push(`${row}: ${r.category} is listed twice.`);
|
|
94
|
+
seen.add(r.category.trim().toLowerCase());
|
|
95
|
+
if ((r.officeHours === "provider" || r.afterHours === "provider") && !OBJECT_ID.test(r.provider))
|
|
96
|
+
errors.push(`${row}: choose which provider receives it.`);
|
|
97
|
+
});
|
|
98
|
+
if (form.escalationEnabled) {
|
|
99
|
+
if (!form.levels.length) errors.push("Add at least one escalation step, or turn escalation off.");
|
|
100
|
+
if (form.levels.length > MAX_ESCALATION_LEVELS) errors.push(`At most ${MAX_ESCALATION_LEVELS} escalation steps.`);
|
|
101
|
+
form.levels.forEach((l, i) => {
|
|
102
|
+
const step = `Step ${i + 1}`;
|
|
103
|
+
const hours = Number(l.afterHours);
|
|
104
|
+
if (!Number.isFinite(hours) || hours < 1 || hours > 1440) errors.push(`${step}: hours must be between 1 and 1440.`);
|
|
105
|
+
if (!l.users.length && !l.emails.length) errors.push(`${step}: choose somebody to notify.`);
|
|
106
|
+
for (const e of l.emails) if (!EMAIL.test(e.trim())) errors.push(`${step}: "${e}" is not an email address.`);
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
return errors;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** The form as the stored `metadata.feedbackSettings` value. */
|
|
113
|
+
export function feedbackSettingsFromForm(form: TFeedbackHandlingForm) {
|
|
114
|
+
return {
|
|
115
|
+
workingDays: [...form.workingDays].sort((a, b) => a - b),
|
|
116
|
+
officeStart: form.officeStart,
|
|
117
|
+
officeEnd: form.officeEnd,
|
|
118
|
+
excludePublicHolidays: form.excludePublicHolidays,
|
|
119
|
+
routes: form.routes.map((r) => ({
|
|
120
|
+
category: r.category.trim(),
|
|
121
|
+
officeHours: r.officeHours,
|
|
122
|
+
afterHours: r.afterHours,
|
|
123
|
+
provider: r.officeHours === "provider" || r.afterHours === "provider" ? r.provider : null,
|
|
124
|
+
})),
|
|
125
|
+
escalation: {
|
|
126
|
+
enabled: form.escalationEnabled,
|
|
127
|
+
workingTimeOnly: form.workingTimeOnly,
|
|
128
|
+
// A step keeps its id so a re-ordered or edited step is not sent again;
|
|
129
|
+
// a new step has none and the server gives it one.
|
|
130
|
+
levels: form.levels.map((l) => ({
|
|
131
|
+
...(l.id ? { id: l.id } : {}),
|
|
132
|
+
afterHours: Number(l.afterHours),
|
|
133
|
+
users: [...new Set(l.users)],
|
|
134
|
+
emails: [...new Set(l.emails.map((e) => e.trim().toLowerCase()))],
|
|
135
|
+
})),
|
|
136
|
+
},
|
|
137
|
+
autoCloseCategories: [...new Set(form.autoCloseCategories)],
|
|
138
|
+
};
|
|
139
|
+
}
|
|
@@ -143,3 +143,67 @@ export function inventoryControls(a?: Partial<TInventoryAccess> | null) {
|
|
|
143
143
|
unitPrice: c.canManage || c.canApprove || c.canHandle || c.canReports,
|
|
144
144
|
};
|
|
145
145
|
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Whole-role starting points (TLR A7), offered in the create-role dialog when
|
|
149
|
+
* the catalogue has every module they use. Keys are the security catalogue's
|
|
150
|
+
* own (`composables/useSecurityPermission.ts`). Applying one REPLACES the
|
|
151
|
+
* ticks in the dialog and saves nothing; the admin adjusts and saves.
|
|
152
|
+
*/
|
|
153
|
+
export type TRolePreset = {
|
|
154
|
+
key: string;
|
|
155
|
+
label: string;
|
|
156
|
+
description: string;
|
|
157
|
+
permissions: string[];
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* The Guardhouse officer's grants, by module, in the same nested form as the
|
|
162
|
+
* security catalogue that offers them (`useSecurityPermission.ts`). A grant
|
|
163
|
+
* list, not a check: `constants/permissions.ts` (what this package CHECKS)
|
|
164
|
+
* deliberately has no Passes & Keys entry, so the role editors there gain no
|
|
165
|
+
* extra checkbox.
|
|
166
|
+
*/
|
|
167
|
+
const GUARDHOUSE_OFFICER: Record<string, string[]> = {
|
|
168
|
+
// check-out is a visitor update on the server
|
|
169
|
+
"visitor-mgmt": ["add-visitor", "see-all-visitor", "see-visitor-details", "update-visitor"],
|
|
170
|
+
"daily-occurrence-books": ["see-all-daily-occurrence", "see-daily-occurrence-details"],
|
|
171
|
+
"daily-occurrence-entries": ["add-daily-occurrence-entries", "see-daily-occurrence-entries-details"],
|
|
172
|
+
"incident-reports": ["add-incident-report", "see-incident-reports", "see-incident-report-details"],
|
|
173
|
+
feedbacks: ["add-feedback", "see-all-feedback", "see-feedback-details"],
|
|
174
|
+
// issuing and taking back a key is a pass/key update on the server
|
|
175
|
+
"passes-and-keys-mgmt": ["see-all-passes-and-keys", "update-passes-and-keys"],
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
const grants = (byModule: Record<string, string[]>) =>
|
|
179
|
+
Object.entries(byModule).flatMap(([resource, actions]) => actions.map((action) => [resource, action].join(":")));
|
|
180
|
+
|
|
181
|
+
export const ROLE_PRESETS: TRolePreset[] = [
|
|
182
|
+
{
|
|
183
|
+
key: "guardhouse-officer",
|
|
184
|
+
label: "Guardhouse officer",
|
|
185
|
+
description:
|
|
186
|
+
"Register, see and check out visitors; fill in the daily occurrence book; raise and view incident reports and feedback; issue and take back passes and keys. No delete rights.",
|
|
187
|
+
permissions: grants(GUARDHOUSE_OFFICER),
|
|
188
|
+
},
|
|
189
|
+
];
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* The dialog state for `preset` against the offered catalogue, or null when
|
|
193
|
+
* the catalogue lacks any of it. Never returns an empty list: an empty
|
|
194
|
+
* permission list means "everything" on the server.
|
|
195
|
+
*/
|
|
196
|
+
export function applyRolePreset(
|
|
197
|
+
catalogue: Record<string, Record<string, unknown> | undefined>,
|
|
198
|
+
preset: TRolePreset,
|
|
199
|
+
): { selected: string[]; enabled: string[] } | null {
|
|
200
|
+
const offered = preset.permissions.every((p) => {
|
|
201
|
+
const [resource, action] = p.split(":");
|
|
202
|
+
return Boolean(catalogue?.[resource]?.[action]);
|
|
203
|
+
});
|
|
204
|
+
if (!offered || !preset.permissions.length) return null;
|
|
205
|
+
return {
|
|
206
|
+
selected: [...preset.permissions],
|
|
207
|
+
enabled: [...new Set(preset.permissions.map((p) => p.split(":")[0]))],
|
|
208
|
+
};
|
|
209
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Key presses (cabinets) and the Passes & keys site switches (TLR B8 / D2).
|
|
3
|
+
* Stored on the site as `metadata.keySettings`; read with the same defaults
|
|
4
|
+
* as core's `getKeySettings`, so a site that never saved anything reads as
|
|
5
|
+
* today: no presses, no daily list, check-out never blocked by the server.
|
|
6
|
+
*/
|
|
7
|
+
export type TKeyPress = { id: string; name: string };
|
|
8
|
+
|
|
9
|
+
export type TKeySettings = {
|
|
10
|
+
cabinets: TKeyPress[];
|
|
11
|
+
dailyUnreturnedAlert: boolean;
|
|
12
|
+
alertTime: string;
|
|
13
|
+
blockCheckoutWithKeys: boolean;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export function readKeySettings(site: any): TKeySettings {
|
|
17
|
+
const k = site?.metadata?.keySettings ?? {};
|
|
18
|
+
return {
|
|
19
|
+
cabinets: Array.isArray(k.cabinets)
|
|
20
|
+
? k.cabinets.filter((c: any) => c && typeof c.id === "string" && typeof c.name === "string")
|
|
21
|
+
: [],
|
|
22
|
+
dailyUnreturnedAlert: k.dailyUnreturnedAlert === true,
|
|
23
|
+
alertTime: typeof k.alertTime === "string" && /^([01]\d|2[0-3]):[0-5]\d$/.test(k.alertTime) ? k.alertTime : "18:00",
|
|
24
|
+
blockCheckoutWithKeys: k.blockCheckoutWithKeys === true,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** The press's name, or "" when the key has none (or one since removed). */
|
|
29
|
+
export function keyPressName(cabinets: TKeyPress[], id?: string | null): string {
|
|
30
|
+
if (!id) return "";
|
|
31
|
+
return cabinets.find((c) => c.id === id)?.name ?? "";
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The list as saved: names trimmed, empty rows dropped, and an id for each new
|
|
36
|
+
* row made from its name (lowercase letters, digits and dashes, unique). An
|
|
37
|
+
* existing row keeps its id, so renaming a press keeps every key in it.
|
|
38
|
+
*/
|
|
39
|
+
export function cleanKeyPresses(rows: Array<{ id?: string; name?: string }>): TKeyPress[] {
|
|
40
|
+
const out: TKeyPress[] = [];
|
|
41
|
+
const taken = new Set(rows.map((r) => r.id).filter(Boolean) as string[]);
|
|
42
|
+
for (const row of rows) {
|
|
43
|
+
const name = String(row.name ?? "").trim().slice(0, 60);
|
|
44
|
+
if (!name) continue;
|
|
45
|
+
let id = row.id;
|
|
46
|
+
if (!id) {
|
|
47
|
+
const base = name.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 34) || "press";
|
|
48
|
+
id = base;
|
|
49
|
+
for (let n = 2; taken.has(id); n++) id = `${base}-${n}`;
|
|
50
|
+
taken.add(id);
|
|
51
|
+
}
|
|
52
|
+
out.push({ id, name });
|
|
53
|
+
}
|
|
54
|
+
return out;
|
|
55
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CSV download of a list screen (TLR B6): the rows the list itself can read,
|
|
3
|
+
* through the same list API and filters, paged through to the end. Browser-safe.
|
|
4
|
+
*/
|
|
5
|
+
import { toCsv } from "./attendance-proxy.ts";
|
|
6
|
+
|
|
7
|
+
export type TExportColumn = { title: string; value: (row: any) => unknown };
|
|
8
|
+
|
|
9
|
+
/** Largest page the list APIs accept (core feedback / work-order: max 100). */
|
|
10
|
+
export const EXPORT_PAGE_SIZE = 100;
|
|
11
|
+
/** ponytail: hard cap, so one click never pulls an estate's whole history; raise or add a server export if hit. */
|
|
12
|
+
export const EXPORT_MAX_ROWS = 5000;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Every row from `fetchPage(1..n)`, stopping at the last page, an empty page,
|
|
16
|
+
* or `maxRows`. `fetchPage` returns the list API's `{ items, pages }`.
|
|
17
|
+
*/
|
|
18
|
+
export async function collectAllPages(
|
|
19
|
+
fetchPage: (page: number, limit: number) => Promise<{ items?: any[]; pages?: number } | null | undefined>,
|
|
20
|
+
maxRows = EXPORT_MAX_ROWS,
|
|
21
|
+
limit = EXPORT_PAGE_SIZE,
|
|
22
|
+
): Promise<{ rows: any[]; truncated: boolean }> {
|
|
23
|
+
const rows: any[] = [];
|
|
24
|
+
for (let page = 1; rows.length < maxRows; page++) {
|
|
25
|
+
const res = await fetchPage(page, limit);
|
|
26
|
+
const items = Array.isArray(res?.items) ? res!.items : [];
|
|
27
|
+
rows.push(...items);
|
|
28
|
+
const last = Number(res?.pages) || 0;
|
|
29
|
+
if (!items.length || page >= last) return { rows: rows.slice(0, maxRows), truncated: rows.length > maxRows };
|
|
30
|
+
}
|
|
31
|
+
return { rows: rows.slice(0, maxRows), truncated: true };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function listCsv(columns: TExportColumn[], rows: any[]): string {
|
|
35
|
+
return toCsv(
|
|
36
|
+
columns.map((c) => c.title),
|
|
37
|
+
rows.map((row) => columns.map((c) => c.value(row))),
|
|
38
|
+
);
|
|
39
|
+
}
|
package/utils/site-access.ts
CHANGED
|
@@ -8,7 +8,7 @@ export type SiteAccessRole = { _id: string; name: string; type?: string; scope?:
|
|
|
8
8
|
export type SiteAccessRow = {
|
|
9
9
|
site: string;
|
|
10
10
|
name: string;
|
|
11
|
-
membership: { role: string; roleName?: string } | null;
|
|
11
|
+
membership: { role: string; roleName?: string; securityOps?: boolean } | null;
|
|
12
12
|
roles: SiteAccessRole[];
|
|
13
13
|
};
|
|
14
14
|
export type SiteChoice = { site: string; name: string; on: boolean; role: string; roles: SiteAccessRole[]; replacedRole?: string };
|
|
@@ -31,6 +31,18 @@ export function initialChoices(rows: SiteAccessRow[]): SiteChoice[] {
|
|
|
31
31
|
});
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Is this person already marked as Security Ops?
|
|
36
|
+
*
|
|
37
|
+
* ONE ANSWER FOR THE WHOLE PERSON, because that is the question the switch
|
|
38
|
+
* asks: an officer is an officer everywhere they are sent. Any marked site
|
|
39
|
+
* means yes, so a person whose rows disagree (only reachable by an older client
|
|
40
|
+
* or a hand edit) reads as marked, and saving settles every row to one value.
|
|
41
|
+
*/
|
|
42
|
+
export function initialSecurityOps(rows: SiteAccessRow[]): boolean {
|
|
43
|
+
return (rows ?? []).some((r) => Boolean(r.membership?.securityOps));
|
|
44
|
+
}
|
|
45
|
+
|
|
34
46
|
/** One site's Role list: "Organisation roles" first, then "<Site> roles". */
|
|
35
47
|
export function roleItems(choice: Pick<SiteChoice, "name" | "roles">): RoleItem[] {
|
|
36
48
|
const org = choice.roles.filter(isOrgRole);
|