@7365admin1/layer-common 4.20.0 → 4.21.1

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,17 @@
1
1
  # @iservice365/layer-common
2
2
 
3
+ ## 4.21.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 5f54311: CCTV wall: full screen now gives the wall the whole screen (the capabilities panel is not drawn while it is on, so the picture is no longer squeezed into 68% of the height), and a player that reports its first frame and then goes quiet is shown as "Not confirmed" instead of "The picture stopped arriving" — the relay reports only the first decoded frame, so the old rule called every working camera dead after 12 seconds.
8
+
9
+ ## 4.21.0
10
+
11
+ ### Minor Changes
12
+
13
+ - a26bc2e: Notification bell on by default in the shared top bar, for every signed-in web app: unread count, the latest notifications, mark one or all as read, an in-page pop-up for new ones (checked every 30 s and when the tab regains focus), optional desktop notifications, and a link to Notification settings. The list shows everything addressed to the person (it was site-scoped, which disagreed with the badge).
14
+
3
15
  ## 4.20.0
4
16
 
5
17
  ### Minor Changes
@@ -1199,11 +1211,11 @@
1199
1211
  `utils/console-tier.ts` + `composables/useConsoleTier.ts` mirror the server's
1200
1212
  own rule from two endpoints the console already calls, unprojected:
1201
1213
 
1202
- GET /api/members/user/:user/app/admin the Seven365 staff membership
1203
- GET /api/roles/id/:role that membership's role document
1214
+ GET /api/members/user/:user/app/admin the Seven365 staff membership
1215
+ GET /api/roles/id/:role that membership's role document
1204
1216
 
1205
- owner = member.type === "admin" && role.type === "admin" && role.default === true
1206
- staff = member.type === "admin" && role.type === "admin"
1217
+ owner = member.type === "admin" && role.type === "admin" && role.default === true
1218
+ staff = member.type === "admin" && role.type === "admin"
1207
1219
 
1208
1220
  `role.default` is the marker because it is the only property of a platform
1209
1221
  staff role no API caller can set - `role.controller.ts` validates create and
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <div ref="root" class="vms">
2
+ <div ref="root" class="vms" :class="{ 'vms--full': isFullscreen }">
3
3
  <!-- ------------------------------------------------------------ toolbar -->
4
4
  <div class="vms__bar">
5
5
  <button
@@ -43,10 +43,10 @@
43
43
  <button
44
44
  type="button"
45
45
  class="vms__tool"
46
- title="Fill the screen with the wall"
46
+ :title="isFullscreen ? 'Leave full screen' : 'Fill the screen with the wall — the panel below is hidden while it is on'"
47
47
  @click="toggleFullscreen"
48
48
  >
49
- Full screen
49
+ {{ isFullscreen ? "Leave full screen" : "Full screen" }}
50
50
  </button>
51
51
  </div>
52
52
 
@@ -780,17 +780,38 @@ onMounted(() => {
780
780
  setOnline();
781
781
  window.addEventListener("online", setOnline);
782
782
  window.addEventListener("offline", setOnline);
783
+ document.addEventListener("fullscreenchange", onFullscreenChange);
784
+ // Safari fires its own event name.
785
+ document.addEventListener("webkitfullscreenchange", onFullscreenChange);
783
786
  });
784
787
 
785
788
  onBeforeUnmount(() => {
786
789
  window.removeEventListener("online", setOnline);
787
790
  window.removeEventListener("offline", setOnline);
791
+ document.removeEventListener("fullscreenchange", onFullscreenChange);
792
+ document.removeEventListener("webkitfullscreenchange", onFullscreenChange);
788
793
  });
789
794
 
790
795
  /* ------------------------------------------------------------- fullscreen */
791
796
 
792
797
  const root = ref<HTMLElement | null>(null);
793
798
 
799
+ /**
800
+ * In full screen the wall takes the whole screen.
801
+ *
802
+ * It did not: `.vms__body` is 68vh whatever the window is, so the picture kept
803
+ * two thirds of the screen and the capabilities panel below took the rest —
804
+ * the owner's "it squeezes the CCTV view". While full screen is on, the body
805
+ * takes the space that is left and the panel is not drawn; the toolbar and the
806
+ * pager stay, so the layout and the page can still be changed.
807
+ */
808
+ const isFullscreen = ref(false);
809
+
810
+ function onFullscreenChange() {
811
+ const el = document.fullscreenElement;
812
+ isFullscreen.value = Boolean(el && root.value && (el === root.value || root.value.contains(el)));
813
+ }
814
+
794
815
  async function toggleFullscreen() {
795
816
  const el = root.value;
796
817
  if (!el) return;
@@ -913,6 +934,22 @@ async function toggleFullscreen() {
913
934
  height: 68vh;
914
935
  }
915
936
 
937
+ /* Full screen: the wall gets the screen, the capabilities panel stands down. */
938
+ .vms--full {
939
+ display: flex;
940
+ flex-direction: column;
941
+ height: 100vh;
942
+ }
943
+
944
+ .vms--full .vms__body {
945
+ flex: 1 1 auto;
946
+ height: auto;
947
+ }
948
+
949
+ .vms--full .vms__caps {
950
+ display: none;
951
+ }
952
+
916
953
  .vms__picker {
917
954
  width: 220px;
918
955
  flex: none;
@@ -157,6 +157,7 @@ import {
157
157
  liveSource,
158
158
  LIVE_CONNECT_TIMEOUT_MS,
159
159
  LIVE_FRAME_TIMEOUT_MS,
160
+ stateAfterFrameSilence,
160
161
  playerOrigin,
161
162
  playerSignal,
162
163
  tileView,
@@ -218,6 +219,8 @@ const frameEl = ref<HTMLIFrameElement | null>(null);
218
219
  const player = ref<TPlayerState>("loading");
219
220
  let timer: ReturnType<typeof setTimeout> | null = null;
220
221
  let frameTimer: ReturnType<typeof setTimeout> | null = null;
222
+ /** How many frame reports this address has produced — see `stateAfterFrameSilence`. */
223
+ let frameReports = 0;
221
224
 
222
225
  const view = computed(() =>
223
226
  tileView(props.camera, { online: props.online, player: player.value })
@@ -407,6 +410,7 @@ function onPlayerMessage(event: MessageEvent) {
407
410
 
408
411
  clearTimer();
409
412
  if (signal === "playing") {
413
+ frameReports += 1;
410
414
  player.value = "playing";
411
415
  // A picture that arrived once and stopped must not stay green. This is the
412
416
  // mobile app's "Live over a nine-second-old still" defect, and the clock is
@@ -435,7 +439,7 @@ function clearFrameTimer() {
435
439
  function restartFrameClock() {
436
440
  clearFrameTimer();
437
441
  frameTimer = setTimeout(() => {
438
- if (player.value === "playing") player.value = "stalled";
442
+ if (player.value === "playing") player.value = stateAfterFrameSilence(frameReports);
439
443
  }, LIVE_FRAME_TIMEOUT_MS);
440
444
  }
441
445
 
@@ -454,6 +458,7 @@ watch(
454
458
  (host) => {
455
459
  clearTimer();
456
460
  clearFrameTimer();
461
+ frameReports = 0;
457
462
  player.value = "loading";
458
463
  if (!host) return;
459
464
  timer = setTimeout(() => {
@@ -41,6 +41,11 @@
41
41
  @click="toggleTheme"
42
42
  />
43
43
 
44
+ <NotificationBell
45
+ v-if="props.showNotifications"
46
+ :site-id="routeSiteId"
47
+ />
48
+
44
49
  <v-menu offset="10px" :close-on-content-click="false">
45
50
  <template #activator="{ props }">
46
51
  <v-btn fab variant="text" icon v-bind="props" class="ms-2 me-1">
@@ -96,6 +101,17 @@ const props = defineProps({
96
101
  type: Boolean,
97
102
  default: false,
98
103
  },
104
+ /**
105
+ * Whether to show the notification bell.
106
+ *
107
+ * ON by default (owner requirement 2026-09-19: every type of account on the
108
+ * web is told about its notifications). An app can still pass `false` for a
109
+ * screen that should not have one.
110
+ */
111
+ showNotifications: {
112
+ type: Boolean,
113
+ default: true,
114
+ },
99
115
  });
100
116
 
101
117
  const menu = defineModel("menu", { type: Boolean });
@@ -128,6 +144,15 @@ const { currentUser } = useLocalAuth();
128
144
  */
129
145
  const { site } = useSite();
130
146
 
147
+ /**
148
+ * The site the user is currently inside, straight off the route. Empty outside
149
+ * a site, where the feed falls back to everything addressed to this user.
150
+ */
151
+ const routeSiteId = computed(() => {
152
+ const param = useRoute().params.site;
153
+ return typeof param === "string" ? param : "";
154
+ });
155
+
131
156
  /**
132
157
  * The shared `site` state is only populated by the screens that load a site
133
158
  * document, so on most screens - the dashboard included - the bar had no name
@@ -0,0 +1,478 @@
1
+ <template>
2
+ <div class="notif-bell">
3
+ <v-menu
4
+ v-model="open"
5
+ offset="10px"
6
+ :close-on-content-click="false"
7
+ location="bottom end"
8
+ >
9
+ <template #activator="{ props: activator }">
10
+ <v-btn
11
+ v-bind="activator"
12
+ variant="text"
13
+ size="36"
14
+ class="app-topbar-shell__icon-btn ms-2"
15
+ :aria-label="
16
+ unread > 0 ? `Notifications, ${unread} unread` : 'Notifications'
17
+ "
18
+ >
19
+ <v-badge
20
+ :model-value="unread > 0"
21
+ :content="badgeLabel"
22
+ color="error"
23
+ offset-x="-2"
24
+ offset-y="-2"
25
+ >
26
+ <v-icon icon="mdi-bell-outline" size="20" />
27
+ </v-badge>
28
+ </v-btn>
29
+ </template>
30
+
31
+ <v-card :width="440" elevation="0" class="notif-panel">
32
+ <div class="notif-panel__head">
33
+ <span>Notification</span>
34
+ <v-btn
35
+ v-if="unread > 0"
36
+ variant="text"
37
+ size="small"
38
+ class="text-none"
39
+ :loading="markingAll"
40
+ @click="readAll"
41
+ >
42
+ Mark all as read
43
+ </v-btn>
44
+ </div>
45
+
46
+ <div v-if="canAskDesktop" class="notif-panel__desktop">
47
+ <v-icon icon="mdi-monitor" size="18" />
48
+ <span>Get a pop-up on this computer when something new arrives.</span>
49
+ <v-btn variant="tonal" size="small" class="text-none" @click="askDesktop">
50
+ Turn on
51
+ </v-btn>
52
+ </div>
53
+
54
+ <div class="notif-panel__body">
55
+ <div v-if="loading" class="notif-panel__state">
56
+ <v-progress-circular indeterminate size="22" />
57
+ </div>
58
+
59
+ <p v-else-if="error" class="notif-panel__state text-error">
60
+ Notifications could not be loaded.
61
+ </p>
62
+
63
+ <p v-else-if="!items.length" class="notif-panel__state">
64
+ You have no notifications.
65
+ </p>
66
+
67
+ <template v-else>
68
+ <button
69
+ v-for="item in items"
70
+ :key="item._id"
71
+ type="button"
72
+ class="notif-card"
73
+ :class="{ 'notif-card--unread': !item.hasRead }"
74
+ @click="openNotification(item)"
75
+ >
76
+ <div class="notif-card__top">
77
+ <span class="notif-card__title" :class="titleClass(item)">
78
+ {{ item.title }}
79
+ </span>
80
+ <span class="notif-card__age">{{ timeAgo(item.createdAt) }}</span>
81
+ </div>
82
+
83
+ <div class="notif-card__bottom">
84
+ <v-icon size="18" class="notif-card__icon">
85
+ {{ iconFor(item) }}
86
+ </v-icon>
87
+ <span class="notif-card__body">{{ item.body }}</span>
88
+ <span
89
+ class="notif-card__dot"
90
+ :class="{ 'notif-card__dot--read': item.hasRead }"
91
+ />
92
+ </div>
93
+ </button>
94
+ </template>
95
+ </div>
96
+
97
+ <div class="notif-panel__foot">
98
+ <NuxtLink
99
+ :to="{ path: '/notification-settings' }"
100
+ class="notif-panel__settings"
101
+ @click="open = false"
102
+ >
103
+ <v-icon icon="mdi-cog-outline" size="16" /> Notification settings
104
+ </NuxtLink>
105
+ </div>
106
+ </v-card>
107
+ </v-menu>
108
+
109
+ <v-snackbar
110
+ v-model="toast.show"
111
+ location="top right"
112
+ :timeout="6000"
113
+ color="surface"
114
+ class="notif-toast"
115
+ >
116
+ <div class="d-flex align-center ga-3">
117
+ <v-icon icon="mdi-bell-ring-outline" color="primary" />
118
+ <div>
119
+ <div class="font-weight-bold">{{ toast.title }}</div>
120
+ <div v-if="toast.body" class="text-body-2">{{ toast.body }}</div>
121
+ </div>
122
+ </div>
123
+ <template #actions>
124
+ <v-btn variant="text" class="text-none" @click="viewFromToast">View</v-btn>
125
+ </template>
126
+ </v-snackbar>
127
+ </div>
128
+ </template>
129
+
130
+ <script setup lang="ts">
131
+ import {
132
+ badgeText,
133
+ newArrivals,
134
+ timeAgo,
135
+ type TInboxItem,
136
+ } from "../utils/notification-inbox";
137
+
138
+ /**
139
+ * The top-bar notification feed for the web, in every signed-in app.
140
+ *
141
+ * Owner requirement (2026-09-19): every type of account on the web gets the
142
+ * bell AND is told when something new arrives. So it is on by default in
143
+ * `Layout/Header.vue`, and it checks the unread count every 30 seconds and
144
+ * whenever the tab comes back into view — one small count query, not the list.
145
+ * When the count rises, the newest unread items are read and anything not seen
146
+ * before pops up in the page; if the person turned it on, as a desktop
147
+ * notification too (a browser only allows asking after a click, hence the
148
+ * "Turn on" button, never a prompt on load).
149
+ *
150
+ * The list shows everything addressed to the person, not only the current
151
+ * site: the unread count is never site-scoped, and most rows carry no site, so
152
+ * a site-scoped list disagreed with its own badge and was empty on site pages.
153
+ * `siteId` is still accepted so existing callers keep working.
154
+ */
155
+ const PAGE_SIZE = 10;
156
+ const POLL_MS = 30_000;
157
+
158
+ defineProps({
159
+ /** Accepted for existing callers; the feed is not narrowed by it (see above). */
160
+ siteId: {
161
+ type: String,
162
+ default: "",
163
+ },
164
+ });
165
+
166
+ const { getAll, getUnreadCount, markAsRead, markAllAsRead } = useNotification();
167
+ const { currentUser } = useLocalAuth();
168
+
169
+ const open = ref(false);
170
+ const loading = ref(false);
171
+ const error = ref(false);
172
+ const markingAll = ref(false);
173
+ const items = ref<Array<Record<string, any>>>([]);
174
+ const unread = ref(0);
175
+ const toast = reactive({ show: false, title: "", body: "" });
176
+
177
+ const userId = computed(() => String(currentUser.value?._id ?? ""));
178
+ const badgeLabel = computed(() => badgeText(unread.value));
179
+
180
+ const seen = new Set<string>();
181
+ let firstLook = true;
182
+ let timer: ReturnType<typeof setInterval> | null = null;
183
+
184
+ const desktopState = ref<NotificationPermission | "unsupported">("unsupported");
185
+ const canAskDesktop = computed(() => desktopState.value === "default");
186
+
187
+ /**
188
+ * Red for a document that has already lapsed, amber for one approaching it;
189
+ * everything else is plain. Matched on the title because the stored feed row
190
+ * carries no structured stage (see `document-expiry-reminder.util.ts`).
191
+ */
192
+ function titleClass(item: Record<string, any>) {
193
+ const title = String(item?.title ?? "");
194
+ if (/expired/i.test(title)) return "notif-card__title--urgent";
195
+ if (/expir/i.test(title)) return "notif-card__title--warn";
196
+ return "";
197
+ }
198
+
199
+ function iconFor(item: Record<string, any>) {
200
+ return /expir|document/i.test(`${item?.title ?? ""} ${item?.module ?? ""}`)
201
+ ? "mdi-file-document-outline"
202
+ : "mdi-bell-outline";
203
+ }
204
+
205
+ /** Tolerates the reply being paginated, wrapped once, or a bare array. */
206
+ function readRows(response: any): Array<Record<string, any>> {
207
+ const payload = response?.data ?? response;
208
+ const rows = payload?.items ?? payload?.data ?? payload;
209
+ return Array.isArray(rows) ? rows : [];
210
+ }
211
+
212
+ function readCount(response: any): number {
213
+ const payload = response?.data ?? response;
214
+ const value = payload?.unread ?? payload?.count ?? payload;
215
+ return Number.isFinite(Number(value)) ? Number(value) : 0;
216
+ }
217
+
218
+ async function refreshList() {
219
+ if (!userId.value) return;
220
+ loading.value = true;
221
+ error.value = false;
222
+ try {
223
+ items.value = readRows(await getAll({ page: 1, limit: PAGE_SIZE, user: userId.value }));
224
+ } catch {
225
+ error.value = true;
226
+ items.value = [];
227
+ } finally {
228
+ loading.value = false;
229
+ }
230
+ }
231
+
232
+ /** One check: the count, and — only if it rose — the newest unread, to announce what is new. */
233
+ async function check() {
234
+ if (!userId.value) return;
235
+ try {
236
+ const count = readCount(await getUnreadCount(userId.value));
237
+ const rose = count > unread.value;
238
+ unread.value = count;
239
+ if (!firstLook && !rose) return;
240
+ const latest = readRows(
241
+ await getAll({ page: 1, limit: PAGE_SIZE, hasRead: false, user: userId.value }),
242
+ ) as TInboxItem[];
243
+ const fresh = newArrivals(latest, seen, firstLook);
244
+ latest.forEach((i) => i?._id && seen.add(i._id));
245
+ firstLook = false;
246
+ if (fresh.length) announce(fresh);
247
+ if (open.value) await refreshList();
248
+ } catch {
249
+ // A failed check is retried on the next tick; the top bar never shows an error for it.
250
+ }
251
+ }
252
+
253
+ function announce(fresh: TInboxItem[]) {
254
+ const first = fresh[0];
255
+ toast.title = fresh.length > 1 ? `${fresh.length} new notifications` : first.title || "New notification";
256
+ toast.body = fresh.length > 1 ? first.title || "" : first.body || "";
257
+ toast.show = true;
258
+ if (desktopState.value === "granted" && document.visibilityState !== "visible") {
259
+ try {
260
+ const note = new Notification(toast.title, { body: toast.body, tag: `iservice365-${first._id}` });
261
+ note.onclick = () => {
262
+ window.focus();
263
+ open.value = true;
264
+ note.close();
265
+ };
266
+ } catch {
267
+ // Some browsers only allow notifications from a service worker; the in-page pop-up still shows.
268
+ }
269
+ }
270
+ }
271
+
272
+ async function openNotification(item: Record<string, any>) {
273
+ if (item.hasRead) return;
274
+ // Marked locally first: waiting on a round trip to move the dot reads as a dead control.
275
+ item.hasRead = true;
276
+ unread.value = Math.max(0, unread.value - 1);
277
+ try {
278
+ await markAsRead(String(item._id), userId.value);
279
+ } catch {
280
+ item.hasRead = false;
281
+ unread.value += 1;
282
+ }
283
+ }
284
+
285
+ async function readAll() {
286
+ markingAll.value = true;
287
+ try {
288
+ await markAllAsRead(userId.value);
289
+ items.value.forEach((i) => (i.hasRead = true));
290
+ unread.value = 0;
291
+ } catch {
292
+ // Left as it was; the next check shows the real state.
293
+ } finally {
294
+ markingAll.value = false;
295
+ }
296
+ }
297
+
298
+ async function askDesktop() {
299
+ try {
300
+ desktopState.value = await Notification.requestPermission();
301
+ } catch {
302
+ desktopState.value = "denied";
303
+ }
304
+ }
305
+
306
+ function viewFromToast() {
307
+ toast.show = false;
308
+ open.value = true;
309
+ }
310
+
311
+ function onVisible() {
312
+ if (document.visibilityState === "visible") check();
313
+ }
314
+
315
+ watch(open, (isOpen) => {
316
+ if (isOpen) refreshList();
317
+ });
318
+
319
+ watch(userId, (id) => {
320
+ if (id) check();
321
+ });
322
+
323
+ onMounted(() => {
324
+ if (typeof window !== "undefined" && "Notification" in window) {
325
+ desktopState.value = Notification.permission;
326
+ }
327
+ check();
328
+ timer = setInterval(check, POLL_MS);
329
+ document.addEventListener("visibilitychange", onVisible);
330
+ });
331
+
332
+ onBeforeUnmount(() => {
333
+ if (timer) clearInterval(timer);
334
+ document.removeEventListener("visibilitychange", onVisible);
335
+ });
336
+ </script>
337
+
338
+ <style scoped>
339
+ .notif-bell {
340
+ display: inline-flex;
341
+ align-items: center;
342
+ }
343
+
344
+ /* The header's 36px bordered icon button; its rule is scoped to Header.vue. */
345
+ .app-topbar-shell__icon-btn {
346
+ border: 1px solid var(--border);
347
+ border-radius: var(--r-inner);
348
+ }
349
+
350
+ .notif-panel {
351
+ border-radius: var(--r-menu);
352
+ background: var(--card);
353
+ overflow: hidden;
354
+ }
355
+
356
+ .notif-panel__head {
357
+ display: flex;
358
+ align-items: center;
359
+ justify-content: space-between;
360
+ padding: 14px 16px;
361
+ font-weight: 600;
362
+ border-bottom: 1px solid var(--border);
363
+ }
364
+
365
+ .notif-panel__desktop {
366
+ display: flex;
367
+ align-items: center;
368
+ gap: 8px;
369
+ padding: 10px 16px;
370
+ font-size: 12.5px;
371
+ background: var(--hover);
372
+ }
373
+
374
+ .notif-panel__body {
375
+ max-height: 420px;
376
+ overflow-y: auto;
377
+ padding: 12px;
378
+ display: flex;
379
+ flex-direction: column;
380
+ gap: 10px;
381
+ }
382
+
383
+ .notif-panel__state {
384
+ padding: 24px 8px;
385
+ text-align: center;
386
+ color: var(--muted);
387
+ margin: 0;
388
+ }
389
+
390
+ .notif-panel__foot {
391
+ padding: 10px 16px;
392
+ border-top: 1px solid var(--border);
393
+ }
394
+
395
+ .notif-panel__settings {
396
+ display: inline-flex;
397
+ align-items: center;
398
+ gap: 6px;
399
+ font-size: 12.5px;
400
+ color: var(--text2);
401
+ text-decoration: none;
402
+ }
403
+
404
+ .notif-card {
405
+ width: 100%;
406
+ text-align: left;
407
+ padding: 12px 14px;
408
+ border: 1px solid var(--border);
409
+ border-radius: var(--r-inner);
410
+ background: transparent;
411
+ cursor: pointer;
412
+ }
413
+
414
+ .notif-card:hover {
415
+ background: var(--hover);
416
+ }
417
+
418
+ .notif-card__top {
419
+ display: flex;
420
+ align-items: baseline;
421
+ justify-content: space-between;
422
+ gap: 12px;
423
+ }
424
+
425
+ .notif-card__title {
426
+ font-size: var(--fs-cell);
427
+ font-weight: 500;
428
+ }
429
+
430
+ .notif-card--unread .notif-card__title {
431
+ font-weight: 700;
432
+ }
433
+
434
+ .notif-card__title--warn {
435
+ color: var(--warn);
436
+ }
437
+
438
+ .notif-card__title--urgent {
439
+ color: var(--err);
440
+ }
441
+
442
+ .notif-card__age {
443
+ flex: 0 0 auto;
444
+ font-size: 12px;
445
+ color: var(--muted);
446
+ }
447
+
448
+ .notif-card__bottom {
449
+ display: flex;
450
+ align-items: center;
451
+ gap: 8px;
452
+ margin-top: 6px;
453
+ }
454
+
455
+ .notif-card__icon {
456
+ flex: 0 0 auto;
457
+ color: var(--text);
458
+ }
459
+
460
+ .notif-card__body {
461
+ flex: 1 1 auto;
462
+ font-size: var(--fs-cell);
463
+ }
464
+
465
+ /* Filled while unread, hollow grey once read - the design's two states. */
466
+ .notif-card__dot {
467
+ flex: 0 0 auto;
468
+ width: 10px;
469
+ height: 10px;
470
+ border-radius: 50%;
471
+ background: var(--info);
472
+ }
473
+
474
+ .notif-card__dot--read {
475
+ background: var(--muted);
476
+ opacity: 0.45;
477
+ }
478
+ </style>
@@ -0,0 +1,78 @@
1
+ /**
2
+ * The web client for the in-app notification feed.
3
+ *
4
+ * The feed itself is not new - it has been written to for a while and read by
5
+ * the MA mobile app. Nothing on the web ever read it, which is why this is the
6
+ * first composable for it.
7
+ *
8
+ * `appSlug` is deliberately never sent. The inbox query applies that filter only
9
+ * when it is given one, so omitting it returns the rows written for the web
10
+ * (which carry no slug) alongside anything else addressed to this user, while a
11
+ * mobile client asking for its own slug still sees only its own.
12
+ */
13
+ export default function useNotification() {
14
+ function getAll({
15
+ page = 1,
16
+ limit = 10,
17
+ siteId = "",
18
+ hasRead,
19
+ search = "",
20
+ user = "",
21
+ }: {
22
+ page?: number;
23
+ limit?: number;
24
+ siteId?: string;
25
+ hasRead?: boolean;
26
+ search?: string;
27
+ user?: string;
28
+ } = {}) {
29
+ const query: Record<string, any> = { page, limit, search };
30
+
31
+ // Sent only when set. The list schema rejects a malformed id rather than
32
+ // ignoring it, and `hasRead` false is a real filter that `||` would drop.
33
+ if (siteId) query.siteId = siteId;
34
+ if (user) query.user = user;
35
+ if (hasRead !== undefined) query.hasRead = hasRead;
36
+
37
+ return useNuxtApp().$api<Record<string, any>>("/api/notifications", {
38
+ method: "GET",
39
+ query,
40
+ });
41
+ }
42
+
43
+ function getUnreadCount(user: string) {
44
+ return useNuxtApp().$api<Record<string, any>>(
45
+ "/api/notifications/unread-count",
46
+ {
47
+ method: "GET",
48
+ query: { user },
49
+ },
50
+ );
51
+ }
52
+
53
+ function markAsRead(id: string, user: string) {
54
+ return useNuxtApp().$api<Record<string, any>>(
55
+ `/api/notifications/${id}/${user}/read`,
56
+ {
57
+ method: "PATCH",
58
+ },
59
+ );
60
+ }
61
+
62
+ function markAllAsRead(user: string) {
63
+ return useNuxtApp().$api<Record<string, any>>(
64
+ "/api/notifications/read-all",
65
+ {
66
+ method: "PATCH",
67
+ query: { user },
68
+ },
69
+ );
70
+ }
71
+
72
+ return {
73
+ getAll,
74
+ getUnreadCount,
75
+ markAsRead,
76
+ markAllAsRead,
77
+ };
78
+ }
@@ -42,13 +42,14 @@ export default function useSecurityPermission() {
42
42
  check: true,
43
43
  description: "Allows the user to add a new feedback to the system.",
44
44
  },
45
- "see-all-feedbacks": {
46
- check: true,
47
- description: "Allows the user to view the list of all feedbacks.",
48
- },
49
- // The spelling the great majority of live roles actually hold, and the
50
- // one the iSecure365 mobile app checks. Offered so an administrator can
51
- // reproduce an existing grant.
45
+ // ONE row for "see all feedbacks" (2026-09-17). The editor showed two -
46
+ // `see-all-feedbacks` and `see-all-feedback` - for the same right.
47
+ // Kept: `see-all-feedback`, the canonical spelling ~95 live roles hold and
48
+ // the iSecure365 app checks. Removed: the plural row. Roles that hold
49
+ // `feedbacks:see-all-feedbacks` (~8) are NOT un-granted: it stays in
50
+ // `LEGACY_PERMISSION_ALIASES`, so `hasPermission` still honours it and the
51
+ // edit dialog shows it ticked on this row (and unticking removes it).
52
+ // API-core and the mobile app accept both spellings too.
52
53
  "see-all-feedback": {
53
54
  check: true,
54
55
  description: "Allows the user to view the list of all feedbacks.",
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.20.0",
5
+ "version": "4.21.1",
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.",
@@ -613,6 +613,26 @@ export const LIVE_CONNECT_TIMEOUT_MS = 15_000;
613
613
  */
614
614
  export const LIVE_FRAME_TIMEOUT_MS = 12_000;
615
615
 
616
+ /**
617
+ * What silence after a frame report MEANS — and it depends on how many reports
618
+ * there have ever been.
619
+ *
620
+ * The relay reports the FIRST decoded frame and nothing after it (measured
621
+ * 2026-09-21 against the live relay: one `{event:"frame",state:"live"}` in 25
622
+ * seconds while the websocket carried 410 video frames). Treating that silence
623
+ * as a stall put "The picture stopped arriving" over four tiles that were
624
+ * playing perfectly — the same lie as a green badge over a frozen picture,
625
+ * pointed the other way.
626
+ *
627
+ * So: two or more reports mean the service does report frames, and silence
628
+ * after that is a real stall. A single report proves the picture STARTED and
629
+ * proves nothing about now, which is "Not confirmed" — the tile keeps showing
630
+ * the stream and says plainly that it cannot vouch for it.
631
+ */
632
+ export function stateAfterFrameSilence(frameReports: number): "stalled" | "page-up" {
633
+ return frameReports >= 2 ? "stalled" : "page-up";
634
+ }
635
+
616
636
  export type TTileState =
617
637
  | "live"
618
638
  | "unverified"
@@ -0,0 +1,47 @@
1
+ /**
2
+ * The web notification bell's decisions, kept free of Vue and Nuxt so they are
3
+ * unit-tested directly (`utils/notification-inbox.test.ts`).
4
+ */
5
+
6
+ export type TInboxItem = {
7
+ _id: string;
8
+ title?: string;
9
+ body?: string;
10
+ hasRead?: boolean;
11
+ createdAt?: string;
12
+ };
13
+
14
+ /**
15
+ * Which of the newest unread items have not been announced yet.
16
+ *
17
+ * The first look after sign-in announces nothing: a pop-up for every message
18
+ * that was already waiting is noise, and the badge already says how many there
19
+ * are. After that, anything unread whose id was not seen before is new.
20
+ */
21
+ export function newArrivals(items: TInboxItem[], seen: Set<string>, firstLook: boolean): TInboxItem[] {
22
+ const unread = items.filter((i) => i && i._id && !i.hasRead);
23
+ if (firstLook) return [];
24
+ return unread.filter((i) => !seen.has(i._id));
25
+ }
26
+
27
+ /** "just now", "5 min ago", "3 h ago", "2 days ago", then the date. */
28
+ export function timeAgo(value: string | undefined, now: Date = new Date()): string {
29
+ if (!value) return "";
30
+ const at = new Date(value);
31
+ if (Number.isNaN(at.getTime())) return "";
32
+ const seconds = Math.round((now.getTime() - at.getTime()) / 1000);
33
+ if (seconds < 60) return "just now";
34
+ const minutes = Math.round(seconds / 60);
35
+ if (minutes < 60) return `${minutes} min ago`;
36
+ const hours = Math.round(minutes / 60);
37
+ if (hours < 24) return `${hours} h ago`;
38
+ const days = Math.round(hours / 24);
39
+ if (days < 7) return `${days} day${days === 1 ? "" : "s"} ago`;
40
+ return at.toLocaleDateString("en-SG", { day: "2-digit", month: "short", year: "numeric" });
41
+ }
42
+
43
+ /** The badge text: nothing at 0, the number up to 99, then "99+". */
44
+ export function badgeText(unread: number): string {
45
+ if (!unread || unread < 0) return "";
46
+ return unread > 99 ? "99+" : String(unread);
47
+ }