@7365admin1/layer-common 4.2.28 → 4.3.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
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @iservice365/layer-common
|
|
2
2
|
|
|
3
|
+
## 4.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 9d151eb: release switching to different organization with app redirection
|
|
8
|
+
|
|
9
|
+
## 4.2.29
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 5600bf9: ANPR plate toast: restart the 20-second window when a plate is replaced
|
|
14
|
+
|
|
15
|
+
A second plate read arriving before the first toast expired inherited whatever
|
|
16
|
+
was left of the first plate's window, so a read at 19s was visible for about a
|
|
17
|
+
second. Vuetify only restarts a snackbar's countdown when `modelValue` or
|
|
18
|
+
`timeout` actually change value, and re-showing the open toast changed neither.
|
|
19
|
+
The toast now owns its own window and restarts it on every read.
|
|
20
|
+
|
|
3
21
|
## 4.2.28
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
|
@@ -830,11 +848,11 @@
|
|
|
830
848
|
`utils/console-tier.ts` + `composables/useConsoleTier.ts` mirror the server's
|
|
831
849
|
own rule from two endpoints the console already calls, unprojected:
|
|
832
850
|
|
|
833
|
-
|
|
834
|
-
|
|
851
|
+
GET /api/members/user/:user/app/admin the Seven365 staff membership
|
|
852
|
+
GET /api/roles/id/:role that membership's role document
|
|
835
853
|
|
|
836
|
-
|
|
837
|
-
|
|
854
|
+
owner = member.type === "admin" && role.type === "admin" && role.default === true
|
|
855
|
+
staff = member.type === "admin" && role.type === "admin"
|
|
838
856
|
|
|
839
857
|
`role.default` is the marker because it is the only property of a platform
|
|
840
858
|
staff role no API caller can set - `role.controller.ts` validates create and
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
<v-snackbar
|
|
44
44
|
v-if="!isUnregisteredVisitorRoute && enableUnregisteredSnackbar && canViewVisitor"
|
|
45
45
|
v-model="snackBarMessage.modal"
|
|
46
|
-
:timeout="
|
|
46
|
+
:timeout="-1"
|
|
47
47
|
location="bottom center"
|
|
48
48
|
class="app-toast anpr-toast"
|
|
49
49
|
multi-line
|
|
@@ -153,7 +153,6 @@ const visitorList = ref<TVisitorSocketData[]>([]);
|
|
|
153
153
|
const lastPlateNumber = ref("");
|
|
154
154
|
|
|
155
155
|
const snackBarMessage = reactive({
|
|
156
|
-
timeout: 3000,
|
|
157
156
|
/** The camera's raw read. `plateToast` decides what is drawn for it. */
|
|
158
157
|
plateNumber: "",
|
|
159
158
|
modal: false,
|
|
@@ -161,6 +160,10 @@ const snackBarMessage = reactive({
|
|
|
161
160
|
|
|
162
161
|
const plateCopy = computed(() => plateToast(snackBarMessage.plateNumber));
|
|
163
162
|
|
|
163
|
+
const plateToastWindow = createPlateToastWindow(() => {
|
|
164
|
+
snackBarMessage.modal = false;
|
|
165
|
+
});
|
|
166
|
+
|
|
164
167
|
const permanentMessageDialog = reactive({
|
|
165
168
|
modal: false,
|
|
166
169
|
text: "",
|
|
@@ -257,7 +260,9 @@ const showPlate = (plateNumber: string) => {
|
|
|
257
260
|
|
|
258
261
|
snackBarMessage.plateNumber = plateNumber;
|
|
259
262
|
snackBarMessage.modal = true;
|
|
260
|
-
|
|
263
|
+
// Restart the 20s window from zero. A replacement plate gets a full window
|
|
264
|
+
// of its own; without this it inherited whatever was left of the one before.
|
|
265
|
+
plateToastWindow.restart();
|
|
261
266
|
};
|
|
262
267
|
|
|
263
268
|
const connectSocket = () => {
|
|
@@ -385,6 +390,10 @@ const onEscape = (event: KeyboardEvent) => {
|
|
|
385
390
|
watch(
|
|
386
391
|
() => snackBarMessage.modal,
|
|
387
392
|
(open) => {
|
|
393
|
+
// Every route to a closed toast - the close button, Escape, the
|
|
394
|
+
// unregistered tab, the site setting - lands here, so the outstanding
|
|
395
|
+
// window is dropped in one place rather than at each of them.
|
|
396
|
+
if (!open) plateToastWindow.cancel();
|
|
388
397
|
if (typeof document === "undefined") return;
|
|
389
398
|
if (open) document.addEventListener("keydown", onEscape);
|
|
390
399
|
else document.removeEventListener("keydown", onEscape);
|
|
@@ -392,6 +401,7 @@ watch(
|
|
|
392
401
|
);
|
|
393
402
|
|
|
394
403
|
onUnmounted(() => {
|
|
404
|
+
plateToastWindow.cancel();
|
|
395
405
|
if (typeof document !== "undefined") {
|
|
396
406
|
document.removeEventListener("keydown", onEscape);
|
|
397
407
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where each line of business lives.
|
|
3
|
+
*
|
|
4
|
+
* An organisation's `nature` says which of the seven vertical apps it belongs
|
|
5
|
+
* to, and every one of those apps' base URLs is already in this layer's
|
|
6
|
+
* runtime config. Without this map each app had to carry its own copy, which is
|
|
7
|
+
* how a switcher ends up able to LIST an organisation it cannot open.
|
|
8
|
+
*
|
|
9
|
+
* `real_estate_developer` is deliberately absent: it is an allowed nature with
|
|
10
|
+
* no app of its own, and `appUrl` answers "" for it rather than guessing.
|
|
11
|
+
*/
|
|
12
|
+
const APP_URL_KEY_BY_NATURE: Record<string, string> = {
|
|
13
|
+
security_agency: "APP_SECURITY",
|
|
14
|
+
property_management_agency: "APP_PROPERTY_MANAGEMENT",
|
|
15
|
+
cleaning_services: "APP_HYGIENE",
|
|
16
|
+
mechanical_electrical_services: "APP_MECHANICAL_ELECTRICAL",
|
|
17
|
+
pest_control_services: "APP_PEST_CONTROL",
|
|
18
|
+
landscaping_services: "APP_LANDSCAPING",
|
|
19
|
+
pool_maintenance_services: "APP_POOL_MAINTENANCE",
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export default function useAppLinks() {
|
|
23
|
+
const config = useRuntimeConfig().public as unknown as Record<string, string>;
|
|
24
|
+
|
|
25
|
+
/** The base URL of the app this nature belongs to, or "" when there is none. */
|
|
26
|
+
function appUrl(nature = ""): string {
|
|
27
|
+
const key = APP_URL_KEY_BY_NATURE[nature];
|
|
28
|
+
|
|
29
|
+
return key ? config[key] || "" : "";
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Where to land somebody switching into `org`. Returns "" when the app is
|
|
34
|
+
* unknown or unconfigured, so a caller can fall back to navigating locally
|
|
35
|
+
* rather than sending them to a broken URL.
|
|
36
|
+
*/
|
|
37
|
+
function appDashboardUrl(nature = "", org = "", site = ""): string {
|
|
38
|
+
const base = appUrl(nature);
|
|
39
|
+
|
|
40
|
+
return base ? `${base}/${org}/${site || "site"}/dashboard` : "";
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return { appUrl, appDashboardUrl, APP_URL_KEY_BY_NATURE };
|
|
44
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WHICH SITE to open an organisation at.
|
|
3
|
+
*
|
|
4
|
+
* `organizations.defaultSite` is the intended answer - `customer-site.service`
|
|
5
|
+
* sets it to the first site an organisation is ever given - but it is not a
|
|
6
|
+
* guarantee:
|
|
7
|
+
*
|
|
8
|
+
* - an organisation abandoned before the site step has none at all, and the
|
|
9
|
+
* switcher can list it, because the list is every organisation you belong
|
|
10
|
+
* to rather than every one that is finished;
|
|
11
|
+
* - a `defaultSite` can name a site that has since been removed or is no
|
|
12
|
+
* longer active, and the sites list is the only thing that knows.
|
|
13
|
+
*
|
|
14
|
+
* Both used to end the same way: the app built `…/<org>/site/dashboard` with
|
|
15
|
+
* the literal word "site" where an id belongs. So the stored answer is CHECKED
|
|
16
|
+
* against the list, and the first live site stands in when it does not hold up.
|
|
17
|
+
*/
|
|
18
|
+
export default function useOrgSite() {
|
|
19
|
+
const { getAll } = useCustomerSite();
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The site id to open `org` at, or "" when it has no usable site.
|
|
23
|
+
*
|
|
24
|
+
* `preferred` is tried first and kept only if the organisation really has it.
|
|
25
|
+
* A failed lookup falls back to `preferred` rather than blocking the switch -
|
|
26
|
+
* a stale id is still a better guess than a placeholder.
|
|
27
|
+
*/
|
|
28
|
+
async function resolveOrgSite(org = "", preferred = ""): Promise<string> {
|
|
29
|
+
if (!org) return "";
|
|
30
|
+
|
|
31
|
+
const clean = preferred && preferred !== "site" ? preferred : "";
|
|
32
|
+
|
|
33
|
+
const response: any = await getAll({ org, limit: 50 }).catch(() => null);
|
|
34
|
+
|
|
35
|
+
if (!response) return clean;
|
|
36
|
+
|
|
37
|
+
const items: any[] = response?.items ?? [];
|
|
38
|
+
|
|
39
|
+
// Customer-site rows carry the site id in `.site`; a raw site document
|
|
40
|
+
// carries its own `._id`. Accept either, the same way onboarding does.
|
|
41
|
+
const ids = items
|
|
42
|
+
.map((item) => String(item?.site || item?._id || ""))
|
|
43
|
+
.filter(Boolean);
|
|
44
|
+
|
|
45
|
+
if (clean && ids.includes(clean)) return clean;
|
|
46
|
+
|
|
47
|
+
return ids[0] || "";
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return { resolveOrgSite };
|
|
51
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The 20-second window a plate toast stays up for.
|
|
3
|
+
*
|
|
4
|
+
* Vuetify does NOT restart a snackbar's countdown when an already-open
|
|
5
|
+
* snackbar is re-shown with the same timeout. `VSnackbar` starts its timer
|
|
6
|
+
* from two watchers only -
|
|
7
|
+
*
|
|
8
|
+
* watch(isActive, startTimeout)
|
|
9
|
+
* watch(() => props.timeout, startTimeout)
|
|
10
|
+
*
|
|
11
|
+
* - and a Vue watcher does not fire when the value it watches is assigned the
|
|
12
|
+
* value it already holds. Re-showing the toast with `modal = true` and
|
|
13
|
+
* `timeout = 20000` while both were already `true` and `20000` therefore left
|
|
14
|
+
* the FIRST plate's timer running: a replacement read arriving at 19s
|
|
15
|
+
* inherited the 1s that was left of the plate before it, and was gone before
|
|
16
|
+
* the guard could read it.
|
|
17
|
+
*
|
|
18
|
+
* So the window is owned here instead of by Vuetify. The snackbar runs with
|
|
19
|
+
* `timeout: -1` (Vuetify's "never close on your own") and every plate clears
|
|
20
|
+
* the outstanding timer and starts a fresh one. This is the same shape the
|
|
21
|
+
* React Native app already uses (`visitor-socket-monitor.tsx`), which is why
|
|
22
|
+
* the defect never appeared there.
|
|
23
|
+
*/
|
|
24
|
+
export const PLATE_TOAST_MS = 20000;
|
|
25
|
+
|
|
26
|
+
export type TPlateToastWindow = {
|
|
27
|
+
/** Start the window, or restart it from zero if one is already running. */
|
|
28
|
+
restart: () => void;
|
|
29
|
+
/** Drop the outstanding window - the toast was closed by something else. */
|
|
30
|
+
cancel: () => void;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const createPlateToastWindow = (
|
|
34
|
+
close: () => void,
|
|
35
|
+
ms: number = PLATE_TOAST_MS,
|
|
36
|
+
): TPlateToastWindow => {
|
|
37
|
+
let handle: ReturnType<typeof setTimeout> | null = null;
|
|
38
|
+
|
|
39
|
+
const cancel = () => {
|
|
40
|
+
if (handle !== null) {
|
|
41
|
+
clearTimeout(handle);
|
|
42
|
+
handle = null;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
restart: () => {
|
|
48
|
+
cancel();
|
|
49
|
+
handle = setTimeout(() => {
|
|
50
|
+
handle = null;
|
|
51
|
+
close();
|
|
52
|
+
}, ms);
|
|
53
|
+
},
|
|
54
|
+
cancel,
|
|
55
|
+
};
|
|
56
|
+
};
|
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.3.0",
|
|
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.",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"build": "nuxt build .playground",
|
|
37
37
|
"generate": "nuxt generate .playground",
|
|
38
38
|
"preview": "nuxt preview .playground",
|
|
39
|
-
"test": "esbuild composables/useVisitorSocket.ts --format=esm --outfile=test/.build/useVisitorSocket.mjs --log-level=error && node --experimental-strip-types --test \"test/*.test.mjs\" && yarn test:units",
|
|
39
|
+
"test": "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 && node --experimental-strip-types --test \"test/*.test.mjs\" && yarn test:units",
|
|
40
40
|
"test:units": "node --experimental-strip-types --test \"utils/*.test.ts\"",
|
|
41
41
|
"release": "yarn run build && changeset publish"
|
|
42
42
|
},
|