@frigear-nu/dashboard 0.0.0-stage → 0.0.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.
Files changed (67) hide show
  1. package/README.md +4 -2
  2. package/dist/module.d.mts +81 -0
  3. package/dist/module.json +12 -0
  4. package/dist/module.mjs +128 -0
  5. package/dist/runtime/access.d.ts +1 -0
  6. package/dist/runtime/access.js +12 -0
  7. package/dist/runtime/app/components/ActionCard.d.vue.ts +19 -0
  8. package/dist/runtime/app/components/ActionCard.vue +54 -0
  9. package/dist/runtime/app/components/ActionCard.vue.d.ts +19 -0
  10. package/dist/runtime/app/components/ChartCard.d.vue.ts +28 -0
  11. package/dist/runtime/app/components/ChartCard.vue +53 -0
  12. package/dist/runtime/app/components/ChartCard.vue.d.ts +28 -0
  13. package/dist/runtime/app/components/Dashboard.d.vue.ts +27 -0
  14. package/dist/runtime/app/components/Dashboard.vue +156 -0
  15. package/dist/runtime/app/components/Dashboard.vue.d.ts +27 -0
  16. package/dist/runtime/app/components/DashboardGrid.d.vue.ts +15 -0
  17. package/dist/runtime/app/components/DashboardGrid.vue +9 -0
  18. package/dist/runtime/app/components/DashboardGrid.vue.d.ts +15 -0
  19. package/dist/runtime/app/components/DashboardItem.d.vue.ts +26 -0
  20. package/dist/runtime/app/components/DashboardItem.vue +153 -0
  21. package/dist/runtime/app/components/DashboardItem.vue.d.ts +26 -0
  22. package/dist/runtime/app/components/EmptyCard.d.vue.ts +18 -0
  23. package/dist/runtime/app/components/EmptyCard.vue +25 -0
  24. package/dist/runtime/app/components/EmptyCard.vue.d.ts +18 -0
  25. package/dist/runtime/app/composables/useDashboard.d.ts +46 -0
  26. package/dist/runtime/app/composables/useDashboard.js +59 -0
  27. package/dist/runtime/app/composables/useDashboardItem.d.ts +34 -0
  28. package/dist/runtime/app/composables/useDashboardItem.js +28 -0
  29. package/dist/runtime/app/composables/useDashboardLayout.d.ts +24 -0
  30. package/dist/runtime/app/composables/useDashboardLayout.js +67 -0
  31. package/dist/runtime/app/composables/useDashboardPlatform.d.ts +10 -0
  32. package/dist/runtime/app/composables/useDashboardPlatform.js +17 -0
  33. package/dist/runtime/app/composables/useSavedDashboardLayouts.d.ts +20 -0
  34. package/dist/runtime/app/composables/useSavedDashboardLayouts.js +35 -0
  35. package/dist/runtime/app/pages/home.d.vue.ts +3 -0
  36. package/dist/runtime/app/pages/home.vue +16 -0
  37. package/dist/runtime/app/pages/home.vue.d.ts +3 -0
  38. package/dist/runtime/app/utils/components.d.ts +8 -0
  39. package/dist/runtime/app/utils/components.js +19 -0
  40. package/dist/runtime/app/utils/span.d.ts +1 -0
  41. package/dist/runtime/app/utils/span.js +10 -0
  42. package/dist/runtime/i18n/lang/da.json +49 -0
  43. package/dist/runtime/i18n/lang/en.json +49 -0
  44. package/dist/runtime/preferences.d.ts +37 -0
  45. package/dist/runtime/preferences.js +25 -0
  46. package/dist/runtime/server/layouts.d.ts +9 -0
  47. package/dist/runtime/server/layouts.js +25 -0
  48. package/dist/runtime/server/routes/me/layouts.get.d.ts +2 -0
  49. package/dist/runtime/server/routes/me/layouts.get.js +6 -0
  50. package/dist/runtime/server/routes/me/layouts.patch.d.ts +2 -0
  51. package/dist/runtime/server/routes/me/layouts.patch.js +10 -0
  52. package/dist/runtime/shared/home-tab.d.ts +31 -0
  53. package/dist/runtime/shared/home-tab.js +21 -0
  54. package/dist/runtime/shared/layout.d.ts +62 -0
  55. package/dist/runtime/shared/layout.js +110 -0
  56. package/dist/runtime/shared/registry.d.ts +11 -0
  57. package/dist/runtime/shared/registry.js +15 -0
  58. package/dist/runtime/shared/stored-layouts.d.ts +12 -0
  59. package/dist/runtime/shared/stored-layouts.js +16 -0
  60. package/dist/runtime/utils/api.d.ts +11 -0
  61. package/dist/runtime/utils/api.js +11 -0
  62. package/dist/runtime/utils/dashboard.d.ts +22 -0
  63. package/dist/runtime/utils/dashboard.js +32 -0
  64. package/dist/runtime/utils/index.d.ts +4 -0
  65. package/dist/runtime/utils/index.js +18 -0
  66. package/dist/types.d.mts +3 -0
  67. package/package.json +110 -3
package/README.md CHANGED
@@ -1,3 +1,5 @@
1
- # Temporary Holding Version
1
+ # @frigear-nu/dashboard
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Customisable dashboards: modules add items to a named dashboard with `extendDashboard` (on top of `@frigear-nu/widget`), pages render them with `<Dashboard>` or their own layout from `useDashboard`, and each user reorders, hides and collapses items (saved as a `@frigear-nu/preferences` preference when installed). With `@frigear-nu/mobile` it adds a Home tab.
4
+
5
+ See the [documentation](../../apps/docs/content/3.modules/7.interface/6.dashboard.md) for usage.
@@ -0,0 +1,81 @@
1
+ import * as _nuxt_schema from '@nuxt/schema';
2
+ import { WidgetDefinition } from '@frigear-nu/widget/utils';
3
+
4
+ /** Where the app runs: `mobile` inside the Capacitor shell of `@frigear-nu/mobile`, `web` everywhere else. */
5
+ type DashboardPlatform = 'web' | 'mobile';
6
+ /** A serialisable condition: every key that is set must hold. */
7
+ interface DashboardItemCondition {
8
+ /** The item ships only when this Nuxt module is installed (decided at build time). */
9
+ module?: string;
10
+ /** The item shows only on this platform. */
11
+ platform?: DashboardPlatform;
12
+ }
13
+ /**
14
+ * An item of a named dashboard: a widget (`@frigear-nu/widget`) plus a title and where it shows. Everything except
15
+ * `component` must be serialisable, it is written into the build.
16
+ */
17
+ type DashboardItem = WidgetDefinition & {
18
+ /** Plain fallback title. */
19
+ title?: string;
20
+ /** i18n key of the title, translated at render time when `@nuxtjs/i18n` has it. */
21
+ titleKey?: string;
22
+ /** The platforms the item shows on. Default: both. */
23
+ platforms?: DashboardPlatform[];
24
+ when?: DashboardItemCondition;
25
+ };
26
+ /** What `#dashboard/registry` keeps of an item, next to the widget registry. */
27
+ interface DashboardRegistryEntry {
28
+ id: string;
29
+ title?: string;
30
+ titleKey?: string;
31
+ platforms?: DashboardPlatform[];
32
+ when?: DashboardItemCondition;
33
+ }
34
+ /** One user's layout of one dashboard. Ids that no longer exist are ignored. */
35
+ interface DashboardLayout {
36
+ /** Item ids in the user's order. Items missing from it keep their registered place. */
37
+ order: string[];
38
+ hidden: string[];
39
+ collapsed: string[];
40
+ /** Per-item settings, by item id (`useDashboardItem().settings`). */
41
+ settings?: Record<string, Record<string, unknown>>;
42
+ }
43
+ /** What `GET` and `PATCH /api/dashboard/me/layouts` answer: the caller's layouts by dashboard name. */
44
+ interface DashboardLayoutsDto {
45
+ layouts: Record<string, DashboardLayout>;
46
+ }
47
+ /** The Home tab of `@frigear-nu/mobile`. */
48
+ interface DashboardHomeTabOptions {
49
+ /** The dashboard the tab renders. Default `crew.home`. */
50
+ dashboard?: string;
51
+ /** The page path of the tab. Default `/crew`. */
52
+ path?: string;
53
+ /** Tab label. Default `Home` (translated through `dashboard.home.label`). */
54
+ label?: string;
55
+ /** Nuxt UI icon of the web tab bar. Default `i-lucide-house`. */
56
+ icon?: string;
57
+ }
58
+ interface ModuleOptions {
59
+ /**
60
+ * With `@frigear-nu/mobile`: a Home tab and a page at `path` rendering `<Dashboard :name>`. `false` turns it off.
61
+ * Without mobile nothing is registered: a web app places `<Dashboard>` on a page itself.
62
+ */
63
+ homeTab?: DashboardHomeTabOptions | false;
64
+ }
65
+ interface DashboardPublicConfig {
66
+ /** The dashboard the Home tab page renders, `''` without one. */
67
+ home: string;
68
+ }
69
+
70
+ declare module 'nuxt/schema' {
71
+ interface NuxtConfig {
72
+ dashboard?: ModuleOptions;
73
+ }
74
+ interface PublicRuntimeConfig {
75
+ dashboard: DashboardPublicConfig;
76
+ }
77
+ }
78
+ declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
79
+
80
+ export { _default as default };
81
+ export type { DashboardHomeTabOptions, DashboardItem, DashboardItemCondition, DashboardLayout, DashboardLayoutsDto, DashboardPlatform, DashboardPublicConfig, DashboardRegistryEntry, ModuleOptions };
@@ -0,0 +1,12 @@
1
+ {
2
+ "name": "@frigear-nu/dashboard",
3
+ "configKey": "dashboard",
4
+ "compatibility": {
5
+ "nuxt": ">=4.0.0"
6
+ },
7
+ "version": "0.0.0",
8
+ "builder": {
9
+ "@nuxt/module-builder": "1.0.4",
10
+ "unbuild": "unknown"
11
+ }
12
+ }
@@ -0,0 +1,128 @@
1
+ import { defineNuxtModule, createResolver, addImports, addComponent, hasNuxtModule, addTypeTemplate, useLogger } from '@nuxt/kit';
2
+ import { registerModule, inlineModuleRuntime, registerLocales, registerTailwindSource, addOptionalImports, defineVirtualRegistry, addModuleRoutes, addModulePages } from '@frigear-nu/module-kit/utils';
3
+ import { getDashboardItems } from '../dist/runtime/utils/dashboard.js';
4
+ import { dashboardRegistryTemplate, resolveDashboardRegistry, dashboardOfArea, isModuleConditionMet } from '../dist/runtime/shared/registry.js';
5
+ import { resolveHomeTab } from '../dist/runtime/shared/home-tab.js';
6
+
7
+ const MODULE_NAME = "@frigear-nu/dashboard";
8
+ const module$1 = defineNuxtModule({
9
+ meta: { name: MODULE_NAME, configKey: "dashboard", compatibility: { nuxt: ">=4.0.0" } },
10
+ defaults: {
11
+ homeTab: { dashboard: "crew.home", path: "/crew" }
12
+ },
13
+ moduleDependencies: {
14
+ "@frigear-nu/module-kit": { version: ">=0.0.0" },
15
+ // Items are widgets of the area `dashboard.<name>`, filtered by `widgets:filter`.
16
+ "@frigear-nu/widget": { version: ">=0.0.0" },
17
+ // `StatCard`, `ListCard`, `surfaceClass`, `useConfirmDialog` (and Nuxt UI through it).
18
+ "@frigear-nu/ui": { version: ">=0.0.0" },
19
+ // Soft: the per-user layout is stored as a `managed` preference when installed (read and written through
20
+ // `/api/dashboard/me/layouts`), else kept for the session.
21
+ "@frigear-nu/preferences": { version: ">=0.0.0", optional: true },
22
+ // Soft: the Home tab and the `mobile` platform.
23
+ "@frigear-nu/mobile": { version: ">=0.0.0", optional: true },
24
+ // Soft: whether someone is signed in, so a layout is only saved for a user; with Preferences, the `authorize` of
25
+ // the layout routes and their `dashboard:layouts` permission.
26
+ "@frigear-nu/auth": { version: ">=0.0.0", optional: true }
27
+ },
28
+ async setup(options, nuxt) {
29
+ registerModule(MODULE_NAME, nuxt);
30
+ const resolver = createResolver(import.meta.url);
31
+ inlineModuleRuntime(nuxt, resolver);
32
+ registerLocales(nuxt, resolver.resolve("./runtime/i18n/lang"));
33
+ registerTailwindSource(nuxt, resolver.resolve("./runtime/app"));
34
+ addImports([
35
+ { name: "useDashboard", from: resolver.resolve("./runtime/app/composables/useDashboard") },
36
+ { name: "useDashboardItem", from: resolver.resolve("./runtime/app/composables/useDashboardItem") },
37
+ { name: "useDashboardLayout", from: resolver.resolve("./runtime/app/composables/useDashboardLayout") },
38
+ { name: "useDashboardPlatform", from: resolver.resolve("./runtime/app/composables/useDashboardPlatform") },
39
+ { name: "dashboardSpanClass", from: resolver.resolve("./runtime/app/utils/span") },
40
+ { name: "useSavedDashboardLayouts", from: resolver.resolve("./runtime/app/composables/useSavedDashboardLayouts") }
41
+ ]);
42
+ for (const name of ["Dashboard", "DashboardGrid", "DashboardItem", "ChartCard", "ActionCard", "EmptyCard"]) {
43
+ addComponent({ name, filePath: resolver.resolve(`./runtime/app/components/${name}.vue`) });
44
+ }
45
+ const resolveAuthMode = await import('@frigear-nu/auth/mode').then((mod) => mod.resolveAuthMode, () => void 0);
46
+ const persistable = () => hasNuxtModule("@frigear-nu/preferences", nuxt) && hasNuxtModule("@frigear-nu/auth", nuxt) && resolveAuthMode?.(nuxt) === "server";
47
+ addOptionalImports(nuxt, "#dashboard/optional", [
48
+ {
49
+ name: "useSavedDashboardLayouts",
50
+ available: persistable,
51
+ fallback: "undefined",
52
+ fallbackType: `undefined | typeof import(${JSON.stringify(resolver.resolve("./runtime/app/composables/useSavedDashboardLayouts"))}).useSavedDashboardLayouts`
53
+ },
54
+ {
55
+ name: "useUserSession",
56
+ available: () => hasNuxtModule("@frigear-nu/auth", nuxt),
57
+ fallback: "undefined",
58
+ fallbackType: `undefined | (() => { loggedIn: import('vue').Ref<boolean> | import('vue').ComputedRef<boolean>, user: import('vue').Ref<{ id?: string | number } | null | undefined> })`
59
+ },
60
+ {
61
+ name: "useCapacitor",
62
+ available: () => hasNuxtModule("@frigear-nu/mobile", nuxt),
63
+ fallback: "undefined",
64
+ fallbackType: `undefined | (() => { isNative: boolean })`
65
+ }
66
+ ]);
67
+ const hasModule = (name) => hasNuxtModule(name, nuxt);
68
+ defineVirtualRegistry(nuxt, {
69
+ filename: "dashboard/registry.mjs",
70
+ alias: "#dashboard/registry",
71
+ collect: () => resolveDashboardRegistry(getDashboardItems(nuxt), hasModule),
72
+ contents: dashboardRegistryTemplate
73
+ });
74
+ pruneWidgetsByCondition(nuxt, hasModule);
75
+ addTypeTemplate({
76
+ filename: "types/dashboard-registry.d.ts",
77
+ getContents: () => `declare module '#dashboard/registry' {
78
+ import type { DashboardRegistryEntry } from ${JSON.stringify(resolver.resolve("./types"))}
79
+ export const dashboards: Record<string, Record<string, DashboardRegistryEntry>>
80
+ }
81
+ `
82
+ });
83
+ if (hasNuxtModule("@frigear-nu/preferences", nuxt)) {
84
+ const { addUserPreferences } = await import('@frigear-nu/preferences/utils');
85
+ addUserPreferences(nuxt, { path: resolver.resolve("./runtime/preferences") });
86
+ const [{ registerAccess }, { dashboardAccess }] = await Promise.all([
87
+ import('@frigear-nu/auth/utils'),
88
+ import('../dist/runtime/access.js')
89
+ ]);
90
+ registerAccess(nuxt, dashboardAccess);
91
+ addModuleRoutes(resolver, [
92
+ { method: "get", path: "me/layouts", file: "me/layouts.get" },
93
+ { method: "patch", path: "me/layouts", file: "me/layouts.patch" }
94
+ ], { base: "/api/dashboard" });
95
+ }
96
+ const home = resolveHomeTab(options.homeTab, { mobile: hasNuxtModule("@frigear-nu/mobile", nuxt) });
97
+ const publicConfig = nuxt.options.runtimeConfig.public;
98
+ publicConfig.dashboard = { home: home?.dashboard ?? "", ...publicConfig.dashboard };
99
+ if (home) {
100
+ addModulePages(MODULE_NAME, resolver, [{ name: "dashboard-home", path: home.path, file: "./runtime/app/pages/home.vue" }]);
101
+ const { extendMobileTabs } = await import('@frigear-nu/mobile/utils');
102
+ extendMobileTabs(nuxt, home.tab);
103
+ }
104
+ }
105
+ });
106
+ function pruneWidgetsByCondition(nuxt, hasModule) {
107
+ const logger = useLogger("dashboard");
108
+ const hooks = nuxt.hooks;
109
+ hooks.hook("widgets:resolved", (areas) => {
110
+ const dashboards = getDashboardItems(nuxt);
111
+ for (const [area, widgets] of Object.entries(areas)) {
112
+ const name = dashboardOfArea(area);
113
+ if (name === void 0) continue;
114
+ const entries = new Map((dashboards[name] ?? []).map((entry) => [entry.id, entry]));
115
+ const unregistered = widgets.filter((widget) => !entries.has(widget.id)).map((widget) => widget.id);
116
+ if (unregistered.length && !nuxt.options._prepare) {
117
+ logger.warn(`Widgets ${unregistered.map((id) => `"${id}"`).join(", ")} are in the area "${area}" but were not added with \`extendDashboard\`, so dashboard "${name}" does not show them. Use \`extendDashboard(nuxt, '${name}', ...)\` instead of \`extendWidgets\`.`);
118
+ }
119
+ const kept = widgets.filter((widget) => {
120
+ const entry = entries.get(widget.id);
121
+ return !entry || isModuleConditionMet(entry, hasModule);
122
+ });
123
+ widgets.splice(0, widgets.length, ...kept);
124
+ }
125
+ });
126
+ }
127
+
128
+ export { module$1 as default };
@@ -0,0 +1 @@
1
+ export declare const dashboardAccess: import("@frigear-nu/auth/access").Access<"dashboard", "layouts", never, never>;
@@ -0,0 +1,12 @@
1
+ import { defineAccess } from "@frigear-nu/auth/access";
2
+ export const dashboardAccess = defineAccess("dashboard", {
3
+ permissions: {
4
+ // Self-service: every signed-in user holds it, and may delegate it to an API token or an OAuth access token. The
5
+ // routes only ever act on the caller (`/api/dashboard/me/...`), so no policy is needed.
6
+ layouts: {
7
+ label: "Your dashboard layouts",
8
+ description: "See and change the order, hidden and collapsed items of your dashboards.",
9
+ implicit: true
10
+ }
11
+ }
12
+ });
@@ -0,0 +1,19 @@
1
+ /**
2
+ * A call to action: title, description, a tinted icon and one primary button that links to `to` or emits `action`.
3
+ * Name the object in `actionLabel` ("Apply for a shift", not "Apply").
4
+ */
5
+ type __VLS_Props = {
6
+ title: string;
7
+ description?: string;
8
+ icon?: string;
9
+ actionLabel: string;
10
+ to?: string;
11
+ loading?: boolean;
12
+ };
13
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
14
+ action: () => any;
15
+ }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
16
+ onAction?: (() => any) | undefined;
17
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
18
+ declare const _default: typeof __VLS_export;
19
+ export default _default;
@@ -0,0 +1,54 @@
1
+ <script setup>
2
+ import { surfaceClass } from "#imports";
3
+ defineProps({
4
+ title: { type: String, required: true },
5
+ description: { type: String, required: false },
6
+ icon: { type: String, required: false },
7
+ actionLabel: { type: String, required: true },
8
+ to: { type: String, required: false },
9
+ loading: { type: Boolean, required: false }
10
+ });
11
+ const emit = defineEmits(["action"]);
12
+ </script>
13
+
14
+ <template>
15
+ <section :class="[surfaceClass, 'flex h-full flex-col gap-3 p-4']">
16
+ <div class="flex items-start gap-3">
17
+ <span
18
+ v-if="icon"
19
+ class="bg-primary/10 ring-primary/25 text-primary flex shrink-0 items-center justify-center rounded-full p-2.5 ring ring-inset"
20
+ >
21
+ <UIcon
22
+ :name="icon"
23
+ class="size-5"
24
+ />
25
+ </span>
26
+ <div class="flex min-w-0 flex-1 flex-col gap-1">
27
+ <h2 class="text-highlighted text-sm font-semibold">
28
+ {{ title }}
29
+ </h2>
30
+ <div
31
+ v-if="loading"
32
+ class="space-y-2"
33
+ >
34
+ <USkeleton class="h-4 w-3/4" />
35
+ </div>
36
+ <p
37
+ v-else-if="description"
38
+ class="text-muted text-sm"
39
+ >
40
+ {{ description }}
41
+ </p>
42
+ </div>
43
+ </div>
44
+ <div class="mt-auto">
45
+ <UButton
46
+ :to="to"
47
+ :label="actionLabel"
48
+ :disabled="loading"
49
+ trailing-icon="i-lucide-arrow-right"
50
+ @click="emit('action')"
51
+ />
52
+ </div>
53
+ </section>
54
+ </template>
@@ -0,0 +1,19 @@
1
+ /**
2
+ * A call to action: title, description, a tinted icon and one primary button that links to `to` or emits `action`.
3
+ * Name the object in `actionLabel` ("Apply for a shift", not "Apply").
4
+ */
5
+ type __VLS_Props = {
6
+ title: string;
7
+ description?: string;
8
+ icon?: string;
9
+ actionLabel: string;
10
+ to?: string;
11
+ loading?: boolean;
12
+ };
13
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
14
+ action: () => any;
15
+ }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
16
+ onAction?: (() => any) | undefined;
17
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
18
+ declare const _default: typeof __VLS_export;
19
+ export default _default;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * A frame for a chart: title, optional description and `#actions`, a skeleton while `loading`, `empty` when `isEmpty`.
3
+ * The chart itself goes in the default slot (no chart library is bundled).
4
+ */
5
+ type __VLS_Props = {
6
+ title: string;
7
+ description?: string;
8
+ loading?: boolean;
9
+ isEmpty?: boolean;
10
+ empty?: string;
11
+ };
12
+ declare const __VLS_template: () => {
13
+ __VLS_Slots: {
14
+ actions?: (props: {}) => any;
15
+ } & {
16
+ default?: (props: {}) => any;
17
+ };
18
+ };
19
+ type __VLS_Slots = ReturnType<typeof __VLS_template>['__VLS_Slots'];
20
+ declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
21
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
22
+ declare const _default: typeof __VLS_export;
23
+ export default _default;
24
+ type __VLS_WithSlots<T, S> = T & {
25
+ new (): {
26
+ $slots: S;
27
+ };
28
+ };
@@ -0,0 +1,53 @@
1
+ <script setup>
2
+ import { surfaceClass } from "#imports";
3
+ defineProps({
4
+ title: { type: String, required: true },
5
+ description: { type: String, required: false },
6
+ loading: { type: Boolean, required: false },
7
+ isEmpty: { type: Boolean, required: false },
8
+ empty: { type: String, required: false }
9
+ });
10
+ </script>
11
+
12
+ <template>
13
+ <section :class="[surfaceClass, 'flex h-full flex-col']">
14
+ <div class="border-default flex items-center justify-between gap-3 border-b px-4 py-3">
15
+ <div class="min-w-0">
16
+ <h2 class="text-highlighted text-sm font-semibold">
17
+ {{ title }}
18
+ </h2>
19
+ <p
20
+ v-if="description"
21
+ class="text-muted text-xs"
22
+ >
23
+ {{ description }}
24
+ </p>
25
+ </div>
26
+ <div
27
+ v-if="$slots.actions"
28
+ class="flex items-center gap-2"
29
+ >
30
+ <slot name="actions" />
31
+ </div>
32
+ </div>
33
+ <div class="flex-1 p-4">
34
+ <div
35
+ v-if="loading"
36
+ class="flex h-40 items-end gap-2"
37
+ >
38
+ <USkeleton class="h-1/3 flex-1" />
39
+ <USkeleton class="h-2/3 flex-1" />
40
+ <USkeleton class="h-1/2 flex-1" />
41
+ <USkeleton class="h-full flex-1" />
42
+ <USkeleton class="h-3/5 flex-1" />
43
+ </div>
44
+ <p
45
+ v-else-if="isEmpty"
46
+ class="text-muted py-6 text-center text-sm"
47
+ >
48
+ {{ empty }}
49
+ </p>
50
+ <slot v-else />
51
+ </div>
52
+ </section>
53
+ </template>
@@ -0,0 +1,28 @@
1
+ /**
2
+ * A frame for a chart: title, optional description and `#actions`, a skeleton while `loading`, `empty` when `isEmpty`.
3
+ * The chart itself goes in the default slot (no chart library is bundled).
4
+ */
5
+ type __VLS_Props = {
6
+ title: string;
7
+ description?: string;
8
+ loading?: boolean;
9
+ isEmpty?: boolean;
10
+ empty?: string;
11
+ };
12
+ declare const __VLS_template: () => {
13
+ __VLS_Slots: {
14
+ actions?: (props: {}) => any;
15
+ } & {
16
+ default?: (props: {}) => any;
17
+ };
18
+ };
19
+ type __VLS_Slots = ReturnType<typeof __VLS_template>['__VLS_Slots'];
20
+ declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
21
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
22
+ declare const _default: typeof __VLS_export;
23
+ export default _default;
24
+ type __VLS_WithSlots<T, S> = T & {
25
+ new (): {
26
+ $slots: S;
27
+ };
28
+ };
@@ -0,0 +1,27 @@
1
+ /**
2
+ * A named dashboard in the default grid: every item the viewer may see on this platform, in their order. With
3
+ * `editable` (default) the viewer can move, hide and show items and reset the layout. Each item receives its static
4
+ * `props`, then every entry of `context` as a prop.
5
+ */
6
+ type __VLS_Props = {
7
+ name: string;
8
+ context?: Record<string, unknown>;
9
+ editable?: boolean;
10
+ };
11
+ declare const __VLS_template: () => {
12
+ __VLS_Slots: {
13
+ empty?: (props: {}) => any;
14
+ };
15
+ };
16
+ type __VLS_Slots = ReturnType<typeof __VLS_template>['__VLS_Slots'];
17
+ declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
18
+ editable: boolean;
19
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
20
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
21
+ declare const _default: typeof __VLS_export;
22
+ export default _default;
23
+ type __VLS_WithSlots<T, S> = T & {
24
+ new (): {
25
+ $slots: S;
26
+ };
27
+ };
@@ -0,0 +1,156 @@
1
+ <script setup>
2
+ import { ref } from "vue";
3
+ import { surfaceClass, useConfirmDialog, useModuleT } from "#imports";
4
+ import { useDashboard } from "../composables/useDashboard";
5
+ const props = defineProps({
6
+ name: { type: String, required: true },
7
+ context: { type: Object, required: false },
8
+ editable: { type: Boolean, required: false, default: true }
9
+ });
10
+ const t = useModuleT("dashboard");
11
+ const confirm = useConfirmDialog();
12
+ const { items, hidden, status, error, persisted, saving, move, hide, show, reset, refresh } = await useDashboard(props.name, () => props.context);
13
+ const editing = ref(false);
14
+ async function resetLayout() {
15
+ const ok = await confirm({
16
+ title: t("reset.title", "Reset layout?"),
17
+ description: t("reset.description", "Restores the default order and shows every hidden item. Collapsed items open again."),
18
+ confirmText: t("reset.confirm", "Reset layout"),
19
+ destructive: true
20
+ });
21
+ if (!ok) return;
22
+ await reset();
23
+ editing.value = false;
24
+ }
25
+ </script>
26
+
27
+ <template>
28
+ <div
29
+ class="flex flex-col gap-4"
30
+ :data-dashboard="name"
31
+ >
32
+ <div
33
+ v-if="editable && (items.length || hidden.length)"
34
+ class="flex flex-wrap items-center justify-end gap-2"
35
+ >
36
+ <template v-if="editing">
37
+ <p
38
+ v-if="!persisted"
39
+ class="text-muted me-auto text-sm"
40
+ data-dashboard-session-only
41
+ >
42
+ {{ t("edit.sessionOnly", "Changes last until you reload the page.") }}
43
+ </p>
44
+ <UButton
45
+ color="neutral"
46
+ variant="outline"
47
+ icon="i-lucide-rotate-ccw"
48
+ :label="t('reset.button', 'Reset layout')"
49
+ :disabled="saving"
50
+ @click="resetLayout"
51
+ />
52
+ <UButton
53
+ icon="i-lucide-check"
54
+ :label="t('edit.done', 'Done')"
55
+ @click="editing = false"
56
+ />
57
+ </template>
58
+ <UButton
59
+ v-else
60
+ color="neutral"
61
+ variant="ghost"
62
+ icon="i-lucide-layout-dashboard"
63
+ :label="t('edit.start', 'Customise dashboard')"
64
+ @click="editing = true"
65
+ />
66
+ </div>
67
+
68
+ <DashboardGrid
69
+ v-if="status === 'pending' && !items.length"
70
+ data-dashboard-pending
71
+ >
72
+ <div
73
+ v-for="index in 4"
74
+ :key="index"
75
+ :class="[surfaceClass, 'space-y-3 p-4']"
76
+ >
77
+ <USkeleton class="h-4 w-1/3" />
78
+ <USkeleton class="h-5 w-2/3" />
79
+ </div>
80
+ </DashboardGrid>
81
+
82
+ <UAlert
83
+ v-else-if="error"
84
+ color="error"
85
+ variant="subtle"
86
+ icon="i-lucide-circle-alert"
87
+ :title="t('error', 'The dashboard could not be loaded.')"
88
+ :actions="[{ label: t('retry', 'Try again'), color: 'neutral', variant: 'outline', icon: 'i-lucide-rotate-cw', onClick: () => refresh() }]"
89
+ />
90
+
91
+ <DashboardGrid v-else-if="items.length">
92
+ <DashboardItem
93
+ v-for="(item, index) in items"
94
+ :key="item.id"
95
+ :item="item"
96
+ :context="context"
97
+ :editing="editing"
98
+ :disabled="saving"
99
+ :first="index === 0"
100
+ :last="index === items.length - 1"
101
+ @move-up="move(item.id, index - 1)"
102
+ @move-down="move(item.id, index + 1)"
103
+ @hide="hide(item.id)"
104
+ />
105
+ </DashboardGrid>
106
+
107
+ <slot
108
+ v-else-if="!hidden.length"
109
+ name="empty"
110
+ >
111
+ <UEmpty
112
+ icon="i-lucide-layout-dashboard"
113
+ :title="t('empty.title', 'Nothing here yet')"
114
+ :description="t('empty.description', 'Items appear here when the modules that add them are installed.')"
115
+ variant="naked"
116
+ />
117
+ </slot>
118
+
119
+ <EmptyCard
120
+ v-else-if="!editing"
121
+ icon="i-lucide-eye-off"
122
+ :title="t('allHidden.title', 'Every item is hidden')"
123
+ :description="t('allHidden.description', 'Show the items you want to see again.')"
124
+ :action-label="t('edit.start', 'Customise dashboard')"
125
+ @action="editing = true"
126
+ />
127
+
128
+ <section
129
+ v-if="editing && hidden.length"
130
+ :class="[surfaceClass, 'flex flex-col']"
131
+ data-dashboard-hidden
132
+ >
133
+ <h2 class="border-default text-highlighted border-b px-4 py-3 text-sm font-semibold">
134
+ {{ t("hidden.title", "Hidden items") }}
135
+ </h2>
136
+ <ul class="divide-default divide-y">
137
+ <li
138
+ v-for="item in hidden"
139
+ :key="item.id"
140
+ class="flex items-center justify-between gap-3 px-4 py-2.5 text-sm"
141
+ >
142
+ <span class="truncate">{{ item.title ?? item.id }}</span>
143
+ <UButton
144
+ size="xs"
145
+ color="neutral"
146
+ variant="outline"
147
+ icon="i-lucide-eye"
148
+ :disabled="saving"
149
+ :label="t('hidden.show', 'Show {title}', { title: item.title ?? item.id })"
150
+ @click="show(item.id)"
151
+ />
152
+ </li>
153
+ </ul>
154
+ </section>
155
+ </div>
156
+ </template>
@@ -0,0 +1,27 @@
1
+ /**
2
+ * A named dashboard in the default grid: every item the viewer may see on this platform, in their order. With
3
+ * `editable` (default) the viewer can move, hide and show items and reset the layout. Each item receives its static
4
+ * `props`, then every entry of `context` as a prop.
5
+ */
6
+ type __VLS_Props = {
7
+ name: string;
8
+ context?: Record<string, unknown>;
9
+ editable?: boolean;
10
+ };
11
+ declare const __VLS_template: () => {
12
+ __VLS_Slots: {
13
+ empty?: (props: {}) => any;
14
+ };
15
+ };
16
+ type __VLS_Slots = ReturnType<typeof __VLS_template>['__VLS_Slots'];
17
+ declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
18
+ editable: boolean;
19
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
20
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
21
+ declare const _default: typeof __VLS_export;
22
+ export default _default;
23
+ type __VLS_WithSlots<T, S> = T & {
24
+ new (): {
25
+ $slots: S;
26
+ };
27
+ };