@7365admin1/layer-common 4.35.1-staging.381 → 4.35.1-staging.382

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.
@@ -317,7 +317,7 @@
317
317
  cols="12"
318
318
  sm="6"
319
319
  md="4"
320
- lg="3"
320
+ :lg="kpiColLg"
321
321
  class="d-flex"
322
322
  >
323
323
  <!--
@@ -1107,14 +1107,19 @@
1107
1107
  {{ widget.description }}
1108
1108
  </div>
1109
1109
  </div>
1110
+ <!--
1111
+ `app-switch` is the platform toggle (primitives.css): blue
1112
+ track + white knob right when ON, grey knob left when OFF, in
1113
+ both themes. The old blue-grey colour drew ON as near-black on the
1114
+ dark card and grey on the light one - on and off looked alike.
1115
+ -->
1110
1116
  <v-switch
1111
1117
  v-model="draftVisibleWidgetKeys"
1112
1118
  :value="widget.key"
1113
- color="blue-grey-darken-4"
1114
- inset
1119
+ class="app-switch flex-grow-0"
1115
1120
  hide-details
1116
1121
  density="compact"
1117
- aria-label="Toggle dashboard widget"
1122
+ :aria-label="`Show ${widget.title}`"
1118
1123
  />
1119
1124
  </div>
1120
1125
  </v-card>
@@ -1136,7 +1141,7 @@
1136
1141
  </v-btn>
1137
1142
  <v-btn
1138
1143
  variant="flat"
1139
- color="blue-grey-darken-4"
1144
+ color="primary"
1140
1145
  class="text-none font-weight-bold px-6"
1141
1146
  style="min-width: 110px"
1142
1147
  @click="submitCustomize"
@@ -1227,6 +1232,12 @@ import type { CookieOptions } from "#app";
1227
1232
  // `plugins/vuetify.ts`), and a bare call resolved to nothing when driven.
1228
1233
  import { buildWorkOrderStatus } from "../utils/dashboard";
1229
1234
  import { permissionsDenied } from "../utils/module-routes";
1235
+ import { grantsPermission } from "../utils/permission-spellings";
1236
+ import {
1237
+ hiddenDashboardWidgets,
1238
+ saveHiddenDashboardWidgets,
1239
+ type TDashboardWidgetPrefs,
1240
+ } from "../utils/dashboard-widget-prefs";
1230
1241
 
1231
1242
  // ─── Types ────────────────────────────────────────────────────────────────────
1232
1243
 
@@ -1482,21 +1493,20 @@ function canViewWidget(key: string) {
1482
1493
  return false;
1483
1494
  }
1484
1495
 
1485
- if (permissions.includes("*")) return true;
1496
+ // The estate rule (`grantsPermission`): a saved role with an EMPTY list, or
1497
+ // `*`, means everything. core seeds default roles with `permissions: []`, so
1498
+ // an exact `includes` test showed those accounts an empty dashboard while
1499
+ // every menu in the app let them in. `grantsPermission` also accepts every
1500
+ // shipped spelling of a grant (`work-orders:` / `workOrder:` / ...).
1501
+ if (!permissions.length || permissions.includes("*")) return true;
1486
1502
 
1487
1503
  if (bySchedule) {
1488
1504
  return hasSchedulePermission(permissions, "see-all-schedules");
1489
1505
  }
1490
1506
 
1491
- if (isPropertyMode.value && modulePermissions) {
1492
- return modulePermissions.some((permission) =>
1493
- permissions.includes(permission)
1494
- );
1495
- }
1496
-
1497
1507
  if (modulePermissions) {
1498
1508
  return modulePermissions.some((permission) =>
1499
- permissions.includes(permission)
1509
+ grantsPermission(permissions, permission)
1500
1510
  );
1501
1511
  }
1502
1512
 
@@ -2049,33 +2059,28 @@ const securityDefaultWidgetKeys = [
2049
2059
  ];
2050
2060
 
2051
2061
  /**
2052
- * THE CUSTOMISE CHOICE, REMEMBERED.
2062
+ * THE CUSTOMISE CHOICE, REMEMBERED - per signed-in user, per app.
2053
2063
  *
2054
- * Hiding a widget worked and then forgot: nothing was written anywhere, so a
2055
- * reload brought every panel back and the dialog was decoration.
2064
+ * A cookie on the layer's own `cookieConfig` (the parent-domain cookie `theme`
2065
+ * and `landing-page` already use; localStorage would be per-hostname and there
2066
+ * is no preferences API on the server). What is stored and why it is keyed by
2067
+ * user and app is in `utils/dashboard-widget-prefs.ts`.
2056
2068
  *
2057
- * A COOKIE, and specifically the layer's own `cookieConfig` - the same
2058
- * mechanism `sid`, `user`, `landing-page` and the light/dark preference already
2059
- * travel on (see `composables/useThemePreference.ts` for the full reasoning).
2060
- * localStorage would be per-origin, and this is one component shipped into
2061
- * seven applications on seven hostnames. No new storage mechanism, and no
2062
- * invented endpoint - there is no save API on the server for this.
2063
- *
2064
- * One cookie per dashboard MODE, because the three modes have different widget
2065
- * sets and a security member's choice must not decide what a hygiene member
2066
- * sees.
2069
+ * The earlier `dashboard-widgets-<mode>` cookies are not read: they belonged
2070
+ * to whoever last used the browser, and to five apps at once.
2067
2071
  */
2068
- const widgetPrefsCookie = useCookie<string[] | null>(
2069
- `dashboard-widgets-${
2070
- isPropertyMode.value
2071
- ? "property"
2072
- : isSecurityMode.value
2073
- ? "security"
2074
- : "service"
2075
- }`,
2076
- runtimeConfig.public.cookieConfig as CookieOptions<string[] | null> & {
2077
- readonly?: false;
2078
- }
2072
+ const cookieOptions = runtimeConfig.public.cookieConfig as CookieOptions<any> & {
2073
+ readonly?: false;
2074
+ };
2075
+ const widgetPrefsCookie = useCookie<TDashboardWidgetPrefs | null>(
2076
+ "dashboard-widgets",
2077
+ cookieOptions
2078
+ );
2079
+ // The `user` cookie holds the signed-in user's id (`useLocalAuth`).
2080
+ const widgetPrefsUser = String(useCookie("user", cookieOptions).value ?? "");
2081
+ const widgetPrefsApp = String(props.serviceType ?? "");
2082
+ const hiddenByUser = ref<string[]>(
2083
+ hiddenDashboardWidgets(widgetPrefsCookie.value, widgetPrefsUser, widgetPrefsApp)
2079
2084
  );
2080
2085
 
2081
2086
  const defaultVisibleWidgetKeys = computed(() => {
@@ -2096,26 +2101,10 @@ const defaultVisibleWidgetKeys = computed(() => {
2096
2101
  watch(
2097
2102
  defaultVisibleWidgetKeys,
2098
2103
  (keys) => {
2099
- const nextKeys = [...keys];
2100
- if (!visibleWidgetKeys.value.length) {
2101
- // A remembered choice wins on first paint, filtered against the keys this
2102
- // mode actually has so a stale cookie cannot resurrect a removed widget.
2103
- // `Array.isArray` rather than a length check: "the user hid everything"
2104
- // and "there is no cookie" are different answers.
2105
- const remembered = Array.isArray(widgetPrefsCookie.value)
2106
- ? widgetPrefsCookie.value.filter((k) => nextKeys.includes(k))
2107
- : null;
2108
- const initial = remembered ?? nextKeys;
2109
- visibleWidgetKeys.value = initial;
2110
- draftVisibleWidgetKeys.value = [...initial];
2111
- return;
2112
- }
2113
- visibleWidgetKeys.value = visibleWidgetKeys.value.filter((k) =>
2114
- nextKeys.includes(k)
2115
- );
2116
- draftVisibleWidgetKeys.value = draftVisibleWidgetKeys.value.filter((k) =>
2117
- nextKeys.includes(k)
2104
+ visibleWidgetKeys.value = keys.filter(
2105
+ (k) => !hiddenByUser.value.includes(k)
2118
2106
  );
2107
+ draftVisibleWidgetKeys.value = [...visibleWidgetKeys.value];
2119
2108
  },
2120
2109
  { immediate: true }
2121
2110
  );
@@ -2546,6 +2535,13 @@ const visibleKpiCards = computed(() =>
2546
2535
  kpiCards.value.filter((card) => isWidgetVisible(card.key))
2547
2536
  );
2548
2537
 
2538
+ // Four tiles fill a row at `lg`; hiding one in Customize left a hole where it
2539
+ // had been. Fewer tiles share the row instead.
2540
+ const kpiColLg = computed(() => {
2541
+ const shown = visibleKpiCards.value.length;
2542
+ return shown >= 4 || shown === 0 ? 3 : 12 / shown;
2543
+ });
2544
+
2549
2545
  /**
2550
2546
  * Nothing to draw, and which of the two reasons it is.
2551
2547
  *
@@ -3599,10 +3595,20 @@ function resetCustomizeDraft() {
3599
3595
  }
3600
3596
 
3601
3597
  function submitCustomize() {
3602
- visibleWidgetKeys.value = [...draftVisibleWidgetKeys.value];
3603
- // The write is the whole point - see `widgetPrefsCookie`. Saving on Submit
3604
- // rather than on every switch keeps Cancel meaning cancel.
3605
- widgetPrefsCookie.value = [...draftVisibleWidgetKeys.value];
3598
+ const hidden = defaultVisibleWidgetKeys.value.filter(
3599
+ (k) => !draftVisibleWidgetKeys.value.includes(k)
3600
+ );
3601
+ hiddenByUser.value = hidden;
3602
+ visibleWidgetKeys.value = defaultVisibleWidgetKeys.value.filter(
3603
+ (k) => !hidden.includes(k)
3604
+ );
3605
+ // The write is the whole point - see `widgetPrefsCookie`.
3606
+ widgetPrefsCookie.value = saveHiddenDashboardWidgets(
3607
+ widgetPrefsCookie.value,
3608
+ widgetPrefsUser,
3609
+ widgetPrefsApp,
3610
+ hidden
3611
+ );
3606
3612
  widgetSearch.value = "";
3607
3613
  customizeDialog.value = false;
3608
3614
  }
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.35.1-staging.381",
5
+ "version": "4.35.1-staging.382",
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,54 @@
1
+ /**
2
+ * The dashboard's Customize choice, as it is remembered in one cookie.
3
+ *
4
+ * WHOSE and WHICH APP. The old cookie was keyed only by dashboard mode, so the
5
+ * next person to sign in on the same browser inherited the last person's
6
+ * choice, and Hygiene, M&E, Pest, Landscape and Pool all shared ONE choice -
7
+ * hiding a panel in one hid it in the other four.
8
+ *
9
+ * HIDDEN, not shown. The old cookie listed the widgets to show, so any widget
10
+ * added after someone once pressed Submit stayed hidden for them forever.
11
+ * Remembering what was switched OFF lets a new widget appear by default.
12
+ *
13
+ * Still a cookie on the layer's `cookieConfig` (the same parent-domain cookie
14
+ * `theme` and `landing-page` use): there is no preferences API on the server.
15
+ * One cookie holds the signed-in user's choice for every app; a different user
16
+ * signing in starts from the defaults and replaces it on their first Submit.
17
+ */
18
+ export type TDashboardWidgetPrefs = {
19
+ user: string;
20
+ hidden: Record<string, string[]>;
21
+ };
22
+
23
+ function prefsFor(stored: unknown, user: string) {
24
+ if (!user || !stored || typeof stored !== "object") return null;
25
+ const prefs = stored as Partial<TDashboardWidgetPrefs>;
26
+ if (prefs.user !== user) return null;
27
+ if (!prefs.hidden || typeof prefs.hidden !== "object") return null;
28
+ return prefs.hidden;
29
+ }
30
+
31
+ /** The widgets this user switched off in this app. Empty = the defaults. */
32
+ export function hiddenDashboardWidgets(
33
+ stored: unknown,
34
+ user: string,
35
+ app: string,
36
+ ): string[] {
37
+ const list = prefsFor(stored, user)?.[app];
38
+ return Array.isArray(list)
39
+ ? list.filter((key): key is string => typeof key === "string")
40
+ : [];
41
+ }
42
+
43
+ /** The cookie value after this user saves `hidden` for this app. */
44
+ export function saveHiddenDashboardWidgets(
45
+ stored: unknown,
46
+ user: string,
47
+ app: string,
48
+ hidden: readonly string[],
49
+ ): TDashboardWidgetPrefs {
50
+ return {
51
+ user,
52
+ hidden: { ...(prefsFor(stored, user) ?? {}), [app]: [...hidden] },
53
+ };
54
+ }