@7365admin1/layer-common 4.28.1-staging.357 → 4.28.1-staging.358
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/HidAccessLogDashboard.vue +12 -3
- package/components/HidProfileQrCode.vue +12 -3
- package/components/HidReaderUserRoster.vue +12 -1
- package/components/HidUserEnrollment.vue +12 -3
- package/composables/useHidReaderSelection.ts +50 -0
- package/package.json +1 -1
- package/utils/hid-reader-selection.ts +52 -0
|
@@ -376,6 +376,7 @@ const visitorRecords = ref<Record<string, HidAccessRecord>>({});
|
|
|
376
376
|
const logs = ref<HidAccessRecord[]>([]);
|
|
377
377
|
const liveAccessLogs = ref<HidAccessRecord[]>([]);
|
|
378
378
|
const administratorUserIds = ref<Set<number>>(new Set());
|
|
379
|
+
const { selectHidReader, resolveForSite } = useHidReaderSelection();
|
|
379
380
|
const selectedReaderId = ref("");
|
|
380
381
|
const activeTab = ref<AccessTab>("all");
|
|
381
382
|
const search = ref("");
|
|
@@ -592,9 +593,11 @@ async function loadReaders() {
|
|
|
592
593
|
if (!props.site) return;
|
|
593
594
|
const response = await getReaders({ site: props.site, page: 1, limit: 100 });
|
|
594
595
|
readers.value = response?.items ?? response?.data?.items ?? response?.data?.readers ?? [];
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
596
|
+
/* Shared with every other HID screen — see `useHidReaderSelection`. The
|
|
597
|
+
resolver refuses a remembered reader that is not this site's, so a site
|
|
598
|
+
switch or a deleted reader falls back to the first rather than querying
|
|
599
|
+
an id the site does not own. */
|
|
600
|
+
selectedReaderId.value = resolveForSite(props.site, readers.value);
|
|
598
601
|
}
|
|
599
602
|
|
|
600
603
|
async function loadDashboard() {
|
|
@@ -1572,6 +1575,12 @@ function escapeHtml(value: unknown) {
|
|
|
1572
1575
|
.replace(/"/g, """)
|
|
1573
1576
|
.replace(/'/g, "'");
|
|
1574
1577
|
}
|
|
1578
|
+
|
|
1579
|
+
/* Publish every change, including the seed above: a screen that had to fall
|
|
1580
|
+
back to the first reader should leave the others agreeing with it. */
|
|
1581
|
+
watch(selectedReaderId, (value) => {
|
|
1582
|
+
if (value) selectHidReader(props.site, value);
|
|
1583
|
+
});
|
|
1575
1584
|
</script>
|
|
1576
1585
|
|
|
1577
1586
|
<style scoped>
|
|
@@ -126,6 +126,7 @@ const { getReaders, getProfileQr, issueProfileQr, deleteProfileQr } = useHidAmic
|
|
|
126
126
|
type HidReaderOption = { _id: string; name?: string; portalName?: string };
|
|
127
127
|
|
|
128
128
|
const readers = ref<HidReaderOption[]>([]);
|
|
129
|
+
const { selectHidReader, resolveForSite } = useHidReaderSelection();
|
|
129
130
|
const selectedReaderId = ref("");
|
|
130
131
|
const profile = ref<HidProfileQr | null>(null);
|
|
131
132
|
const qrImage = ref("");
|
|
@@ -203,9 +204,11 @@ async function loadReaders() {
|
|
|
203
204
|
const data = toRecord(response.data);
|
|
204
205
|
const items = response.items ?? data.items ?? data.readers ?? [];
|
|
205
206
|
readers.value = (Array.isArray(items) ? items : []).filter((reader) => reader?._id);
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
207
|
+
/* Shared with every other HID screen — see `useHidReaderSelection`. The
|
|
208
|
+
resolver refuses a remembered reader that is not this site's, so a site
|
|
209
|
+
switch or a deleted reader falls back to the first rather than querying
|
|
210
|
+
an id the site does not own. */
|
|
211
|
+
selectedReaderId.value = resolveForSite(props.site, readers.value);
|
|
209
212
|
}
|
|
210
213
|
|
|
211
214
|
async function loadProfile() {
|
|
@@ -263,6 +266,12 @@ watch(
|
|
|
263
266
|
},
|
|
264
267
|
{ immediate: true },
|
|
265
268
|
);
|
|
269
|
+
|
|
270
|
+
/* Publish every change, including the seed above: a screen that had to fall
|
|
271
|
+
back to the first reader should leave the others agreeing with it. */
|
|
272
|
+
watch(selectedReaderId, (value) => {
|
|
273
|
+
if (value) selectHidReader(props.site, value);
|
|
274
|
+
});
|
|
266
275
|
</script>
|
|
267
276
|
|
|
268
277
|
<style scoped>
|
|
@@ -208,6 +208,7 @@ const {
|
|
|
208
208
|
} = useHidAmico();
|
|
209
209
|
const readers = ref<HidReader[]>([]);
|
|
210
210
|
const users = ref<HidReaderUser[]>([]);
|
|
211
|
+
const { selectHidReader, resolveForSite } = useHidReaderSelection();
|
|
211
212
|
const selectedReaderId = ref("");
|
|
212
213
|
const search = ref("");
|
|
213
214
|
const userType = ref<"all" | "user" | "visitor">("all");
|
|
@@ -270,7 +271,11 @@ async function loadReaders() {
|
|
|
270
271
|
readers.value = (Array.isArray(items) ? items : [])
|
|
271
272
|
.map(toReader)
|
|
272
273
|
.filter((reader): reader is HidReader => reader !== null);
|
|
273
|
-
|
|
274
|
+
/* Shared with every other HID screen — see `useHidReaderSelection`. The
|
|
275
|
+
resolver refuses a remembered reader that is not this site's, so a site
|
|
276
|
+
switch or a deleted reader falls back to the first rather than querying
|
|
277
|
+
an id the site does not own. */
|
|
278
|
+
selectedReaderId.value = resolveForSite(props.site, readers.value);
|
|
274
279
|
} catch (error: unknown) {
|
|
275
280
|
readers.value = [];
|
|
276
281
|
showToast(getErrorMessage(error), "error");
|
|
@@ -541,6 +546,12 @@ function toNumber(value: unknown, fallback: number) {
|
|
|
541
546
|
const number = Number(value);
|
|
542
547
|
return Number.isFinite(number) ? number : fallback;
|
|
543
548
|
}
|
|
549
|
+
|
|
550
|
+
/* Publish every change, including the seed above: a screen that had to fall
|
|
551
|
+
back to the first reader should leave the others agreeing with it. */
|
|
552
|
+
watch(selectedReaderId, (value) => {
|
|
553
|
+
if (value) selectHidReader(props.site, value);
|
|
554
|
+
});
|
|
544
555
|
</script>
|
|
545
556
|
|
|
546
557
|
<style scoped>
|
|
@@ -750,6 +750,7 @@ type HidIdentityPayload = Record<string, unknown> & {
|
|
|
750
750
|
const readers = ref<HidReader[]>([]);
|
|
751
751
|
const users = ref<HidUser[]>([]);
|
|
752
752
|
const administratorUserIds = ref<Set<number>>(new Set());
|
|
753
|
+
const { selectHidReader, resolveForSite } = useHidReaderSelection();
|
|
753
754
|
const selectedReaderId = ref("");
|
|
754
755
|
const search = ref("");
|
|
755
756
|
const status = ref("");
|
|
@@ -1136,9 +1137,11 @@ async function loadReaders() {
|
|
|
1136
1137
|
readers.value = (Array.isArray(items) ? items : [])
|
|
1137
1138
|
.map(toHidReader)
|
|
1138
1139
|
.filter((reader): reader is HidReader => reader !== null);
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1140
|
+
/* Shared with every other HID screen — see `useHidReaderSelection`. The
|
|
1141
|
+
resolver refuses a remembered reader that is not this site's, so a site
|
|
1142
|
+
switch or a deleted reader falls back to the first rather than querying
|
|
1143
|
+
an id the site does not own. */
|
|
1144
|
+
selectedReaderId.value = resolveForSite(props.site, readers.value);
|
|
1142
1145
|
}
|
|
1143
1146
|
|
|
1144
1147
|
/**
|
|
@@ -2577,6 +2580,12 @@ function toHidCard(value: unknown): HidCard {
|
|
|
2577
2580
|
source: card.source === "reader" || card.source === "manual" || card.source === "device" ? card.source : undefined,
|
|
2578
2581
|
};
|
|
2579
2582
|
}
|
|
2583
|
+
|
|
2584
|
+
/* Publish every change, including the seed above: a screen that had to fall
|
|
2585
|
+
back to the first reader should leave the others agreeing with it. */
|
|
2586
|
+
watch(selectedReaderId, (value) => {
|
|
2587
|
+
if (value) selectHidReader(props.site, value);
|
|
2588
|
+
});
|
|
2580
2589
|
</script>
|
|
2581
2590
|
|
|
2582
2591
|
<style scoped>
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import {
|
|
2
|
+
EMPTY_HID_READER_CHOICE,
|
|
3
|
+
resolveHidReaderId,
|
|
4
|
+
type HidReaderChoice,
|
|
5
|
+
} from "../utils/hid-reader-selection";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* ONE HID READER CHOICE, SHARED BY EVERY HID SCREEN.
|
|
9
|
+
*
|
|
10
|
+
* Declared at MODULE scope on purpose. Each screen held its own `ref("")`, and
|
|
11
|
+
* because the HID screens are separate pages the ref was rebuilt on every
|
|
12
|
+
* navigation — HID Reader Users, HID Cards, Access Logs and HID QR Code each
|
|
13
|
+
* reset to the first reader no matter what had just been picked next door.
|
|
14
|
+
*
|
|
15
|
+
* A module-scoped ref is enough because moving between those pages is a ROUTE
|
|
16
|
+
* change, not a page load: the menu's items carry a `route` and
|
|
17
|
+
* `NavigationItem.vue` renders them through `:to`, so vue-router handles them
|
|
18
|
+
* and this module is never re-evaluated.
|
|
19
|
+
*
|
|
20
|
+
* Deliberately NOT persisted. `localStorage` would carry the choice through a
|
|
21
|
+
* hard refresh as well, which is a real but much smaller benefit than the
|
|
22
|
+
* navigation case, and it is worth adding only once somebody has felt the
|
|
23
|
+
* absence. See `utils/hid-reader-selection.ts` for the staleness rule that
|
|
24
|
+
* would have to hold either way.
|
|
25
|
+
*
|
|
26
|
+
* Intercom keeps its own reader and is not wired to this. Its question is which
|
|
27
|
+
* panel you are calling, not which door you are administering, and joining them
|
|
28
|
+
* would mean switching reader on Access Logs changed who you would dial.
|
|
29
|
+
*/
|
|
30
|
+
const choice = ref<HidReaderChoice>({ ...EMPTY_HID_READER_CHOICE });
|
|
31
|
+
|
|
32
|
+
export default function useHidReaderSelection() {
|
|
33
|
+
/** Remember a choice. The site travels with it; an id alone means nothing. */
|
|
34
|
+
function selectHidReader(siteId: string, readerId: string) {
|
|
35
|
+
choice.value = { siteId: String(siteId ?? ""), readerId: String(readerId ?? "") };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The reader this screen should show, given the readers it just loaded.
|
|
40
|
+
*
|
|
41
|
+
* Call it after the reader list arrives, and write the answer back with
|
|
42
|
+
* `selectHidReader` so the screens agree on what "current" means even when
|
|
43
|
+
* one of them had to fall back to the first reader.
|
|
44
|
+
*/
|
|
45
|
+
function resolveForSite(siteId: string, readers: readonly { _id?: unknown }[]) {
|
|
46
|
+
return resolveHidReaderId(siteId, readers, choice.value);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return { choice, selectHidReader, resolveForSite };
|
|
50
|
+
}
|
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.28.1-staging.
|
|
5
|
+
"version": "4.28.1-staging.358",
|
|
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.",
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WHICH HID READER THE OPERATOR IS WORKING ON — the one rule behind it.
|
|
3
|
+
*
|
|
4
|
+
* Every HID screen used to hold its own `ref("")` and default it to
|
|
5
|
+
* `readers[0]`, so picking HID 2 on HID Reader Users and clicking through to
|
|
6
|
+
* HID Cards put you back on HID 1. They are separate PAGES, so the component
|
|
7
|
+
* unmounted and the ref was rebuilt from scratch every time — there was no way
|
|
8
|
+
* to make a choice stick. "I am working on HID 2" is a mode, not a per-screen
|
|
9
|
+
* preference.
|
|
10
|
+
*
|
|
11
|
+
* Navigation between those pages is a route change rather than a page load
|
|
12
|
+
* (`NavigationItem.vue` renders the menu's `route` through `:to`), so the
|
|
13
|
+
* module-scoped ref in `useHidReaderSelection` survives it. This file holds the
|
|
14
|
+
* part worth testing: deciding whether a remembered choice may still be used.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export type HidReaderChoice = { siteId: string; readerId: string };
|
|
18
|
+
|
|
19
|
+
/** Anything with an id — the four screens all carry a different reader shape. */
|
|
20
|
+
type ReaderLike = { _id?: unknown };
|
|
21
|
+
|
|
22
|
+
export const EMPTY_HID_READER_CHOICE: HidReaderChoice = { siteId: "", readerId: "" };
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The reader a screen should show, given what this site actually has.
|
|
26
|
+
*
|
|
27
|
+
* A remembered id is honoured ONLY when it belongs to this site and is still in
|
|
28
|
+
* the list. That single condition covers every way it goes stale:
|
|
29
|
+
*
|
|
30
|
+
* - the operator switched site, so the id belongs to a site they have left
|
|
31
|
+
* - the reader was deleted or deactivated since they chose it
|
|
32
|
+
* - nothing has been chosen yet
|
|
33
|
+
*
|
|
34
|
+
* In all three the first reader is returned instead. The alternative — using
|
|
35
|
+
* the id anyway — sends requests for a reader the site does not own, which come
|
|
36
|
+
* back empty and read on screen as a reader with no users, no cards and no
|
|
37
|
+
* logs, rather than as the mistake it is.
|
|
38
|
+
*/
|
|
39
|
+
export function resolveHidReaderId(
|
|
40
|
+
siteId: string,
|
|
41
|
+
readers: readonly ReaderLike[] | null | undefined,
|
|
42
|
+
choice: HidReaderChoice = EMPTY_HID_READER_CHOICE,
|
|
43
|
+
): string {
|
|
44
|
+
const ids = (Array.isArray(readers) ? readers : [])
|
|
45
|
+
.map((reader) => String(reader?._id ?? ""))
|
|
46
|
+
.filter(Boolean);
|
|
47
|
+
|
|
48
|
+
if (choice.siteId === String(siteId ?? "") && ids.includes(choice.readerId)) {
|
|
49
|
+
return choice.readerId;
|
|
50
|
+
}
|
|
51
|
+
return ids[0] ?? "";
|
|
52
|
+
}
|