@frigear-nu/dashboard 0.0.0-stage → 0.0.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/README.md +4 -2
- package/dist/module.d.mts +104 -0
- package/dist/module.json +12 -0
- package/dist/module.mjs +175 -0
- package/dist/runtime/access.d.ts +1 -0
- package/dist/runtime/access.js +12 -0
- package/dist/runtime/app/components/ActionCard.d.vue.ts +19 -0
- package/dist/runtime/app/components/ActionCard.vue +54 -0
- package/dist/runtime/app/components/ActionCard.vue.d.ts +19 -0
- package/dist/runtime/app/components/ChartCard.d.vue.ts +28 -0
- package/dist/runtime/app/components/ChartCard.vue +53 -0
- package/dist/runtime/app/components/ChartCard.vue.d.ts +28 -0
- package/dist/runtime/app/components/Dashboard.d.vue.ts +27 -0
- package/dist/runtime/app/components/Dashboard.vue +156 -0
- package/dist/runtime/app/components/Dashboard.vue.d.ts +27 -0
- package/dist/runtime/app/components/DashboardGrid.d.vue.ts +15 -0
- package/dist/runtime/app/components/DashboardGrid.vue +11 -0
- package/dist/runtime/app/components/DashboardGrid.vue.d.ts +15 -0
- package/dist/runtime/app/components/DashboardItem.d.vue.ts +26 -0
- package/dist/runtime/app/components/DashboardItem.vue +175 -0
- package/dist/runtime/app/components/DashboardItem.vue.d.ts +26 -0
- package/dist/runtime/app/components/EmptyCard.d.vue.ts +18 -0
- package/dist/runtime/app/components/EmptyCard.vue +25 -0
- package/dist/runtime/app/components/EmptyCard.vue.d.ts +18 -0
- package/dist/runtime/app/composables/useDashboard.d.ts +46 -0
- package/dist/runtime/app/composables/useDashboard.js +59 -0
- package/dist/runtime/app/composables/useDashboardItem.d.ts +39 -0
- package/dist/runtime/app/composables/useDashboardItem.js +29 -0
- package/dist/runtime/app/composables/useDashboardLayout.d.ts +24 -0
- package/dist/runtime/app/composables/useDashboardLayout.js +67 -0
- package/dist/runtime/app/composables/useDashboardNav.d.ts +23 -0
- package/dist/runtime/app/composables/useDashboardNav.js +16 -0
- package/dist/runtime/app/composables/useDashboardPlatform.d.ts +10 -0
- package/dist/runtime/app/composables/useDashboardPlatform.js +17 -0
- package/dist/runtime/app/composables/useSavedDashboardLayouts.d.ts +20 -0
- package/dist/runtime/app/composables/useSavedDashboardLayouts.js +35 -0
- package/dist/runtime/app/layouts/dashboard.d.vue.ts +15 -0
- package/dist/runtime/app/layouts/dashboard.vue +32 -0
- package/dist/runtime/app/layouts/dashboard.vue.d.ts +15 -0
- package/dist/runtime/app/pages/home.d.vue.ts +3 -0
- package/dist/runtime/app/pages/home.vue +16 -0
- package/dist/runtime/app/pages/home.vue.d.ts +3 -0
- package/dist/runtime/app/pages/hub.d.vue.ts +3 -0
- package/dist/runtime/app/pages/hub.vue +63 -0
- package/dist/runtime/app/pages/hub.vue.d.ts +3 -0
- package/dist/runtime/app/utils/components.d.ts +8 -0
- package/dist/runtime/app/utils/components.js +19 -0
- package/dist/runtime/app/utils/span.d.ts +1 -0
- package/dist/runtime/app/utils/span.js +10 -0
- package/dist/runtime/i18n/lang/da.json +71 -0
- package/dist/runtime/i18n/lang/en.json +71 -0
- package/dist/runtime/menus.d.ts +2 -0
- package/dist/runtime/menus.js +26 -0
- package/dist/runtime/preferences.d.ts +37 -0
- package/dist/runtime/preferences.js +25 -0
- package/dist/runtime/server/layouts.d.ts +9 -0
- package/dist/runtime/server/layouts.js +25 -0
- package/dist/runtime/server/routes/me/layouts.get.d.ts +2 -0
- package/dist/runtime/server/routes/me/layouts.get.js +6 -0
- package/dist/runtime/server/routes/me/layouts.patch.d.ts +2 -0
- package/dist/runtime/server/routes/me/layouts.patch.js +10 -0
- package/dist/runtime/shared/home-tab.d.ts +31 -0
- package/dist/runtime/shared/home-tab.js +21 -0
- package/dist/runtime/shared/hub.d.ts +18 -0
- package/dist/runtime/shared/hub.js +8 -0
- package/dist/runtime/shared/layout.d.ts +62 -0
- package/dist/runtime/shared/layout.js +110 -0
- package/dist/runtime/shared/registry.d.ts +11 -0
- package/dist/runtime/shared/registry.js +15 -0
- package/dist/runtime/shared/stored-layouts.d.ts +12 -0
- package/dist/runtime/shared/stored-layouts.js +16 -0
- package/dist/runtime/utils/api.d.ts +11 -0
- package/dist/runtime/utils/api.js +11 -0
- package/dist/runtime/utils/dashboard.d.ts +22 -0
- package/dist/runtime/utils/dashboard.js +32 -0
- package/dist/runtime/utils/hub.d.ts +8 -0
- package/dist/runtime/utils/hub.js +5 -0
- package/dist/runtime/utils/index.d.ts +5 -0
- package/dist/runtime/utils/index.js +19 -0
- package/dist/types.d.mts +3 -0
- package/package.json +116 -3
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
declare const __VLS_template: () => {
|
|
2
|
+
__VLS_Slots: {
|
|
3
|
+
default?: (props: {}) => any;
|
|
4
|
+
};
|
|
5
|
+
};
|
|
6
|
+
type __VLS_Slots = ReturnType<typeof __VLS_template>['__VLS_Slots'];
|
|
7
|
+
declare const __VLS_base: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
8
|
+
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
9
|
+
declare const _default: typeof __VLS_export;
|
|
10
|
+
export default _default;
|
|
11
|
+
type __VLS_WithSlots<T, S> = T & {
|
|
12
|
+
new (): {
|
|
13
|
+
$slots: S;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
declare const __VLS_template: () => {
|
|
2
|
+
__VLS_Slots: {
|
|
3
|
+
default?: (props: {}) => any;
|
|
4
|
+
};
|
|
5
|
+
};
|
|
6
|
+
type __VLS_Slots = ReturnType<typeof __VLS_template>['__VLS_Slots'];
|
|
7
|
+
declare const __VLS_base: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
8
|
+
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
9
|
+
declare const _default: typeof __VLS_export;
|
|
10
|
+
export default _default;
|
|
11
|
+
type __VLS_WithSlots<T, S> = T & {
|
|
12
|
+
new (): {
|
|
13
|
+
$slots: S;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { DashboardEntry } from '../composables/useDashboard.js';
|
|
2
|
+
/**
|
|
3
|
+
* The frame of one dashboard item: its title with a collapse toggle, the item's component, a skeleton while the item
|
|
4
|
+
* reports `loading`, an error with a retry, and nothing while it reports `empty` or renders nothing at all (a `v-if` on
|
|
5
|
+
* its root, as widgets shared with other widget areas do). Provides `useDashboardItem()` to the component. In `editing` mode it shows the buttons to move and hide the item (the dashboard handles the events).
|
|
6
|
+
*/
|
|
7
|
+
type __VLS_Props = {
|
|
8
|
+
item: DashboardEntry;
|
|
9
|
+
context?: Record<string, unknown>;
|
|
10
|
+
editing?: boolean;
|
|
11
|
+
/** Disables the edit buttons, while a layout change is being saved. */
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
first?: boolean;
|
|
14
|
+
last?: boolean;
|
|
15
|
+
};
|
|
16
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
17
|
+
hide: () => any;
|
|
18
|
+
moveUp: () => any;
|
|
19
|
+
moveDown: () => any;
|
|
20
|
+
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
21
|
+
onHide?: (() => any) | undefined;
|
|
22
|
+
onMoveUp?: (() => any) | undefined;
|
|
23
|
+
onMoveDown?: (() => any) | undefined;
|
|
24
|
+
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
25
|
+
declare const _default: typeof __VLS_export;
|
|
26
|
+
export default _default;
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { computed, onBeforeUnmount, onErrorCaptured, provide, ref, watch } from "vue";
|
|
3
|
+
import { errorMessage, surfaceClass, useModuleT } from "#imports";
|
|
4
|
+
import { dashboardItemKey } from "../composables/useDashboardItem";
|
|
5
|
+
import { useDashboardLayout } from "../composables/useDashboardLayout";
|
|
6
|
+
import { setItemSettings, toggleCollapsed } from "../../shared/layout";
|
|
7
|
+
import { getDashboardComponent } from "../utils/components";
|
|
8
|
+
import { dashboardSpanClass } from "../utils/span";
|
|
9
|
+
const props = defineProps({
|
|
10
|
+
item: { type: Object, required: true },
|
|
11
|
+
context: { type: Object, required: false },
|
|
12
|
+
editing: { type: Boolean, required: false },
|
|
13
|
+
disabled: { type: Boolean, required: false },
|
|
14
|
+
first: { type: Boolean, required: false },
|
|
15
|
+
last: { type: Boolean, required: false }
|
|
16
|
+
});
|
|
17
|
+
const emit = defineEmits(["moveUp", "moveDown", "hide"]);
|
|
18
|
+
const t = useModuleT("dashboard");
|
|
19
|
+
const { layout, saving, update } = useDashboardLayout(props.item.dashboard);
|
|
20
|
+
const component = computed(() => getDashboardComponent(props.item.dashboard, props.item.id));
|
|
21
|
+
const label = computed(() => props.item.title ?? props.item.id);
|
|
22
|
+
const loading = ref(false);
|
|
23
|
+
const error = ref(null);
|
|
24
|
+
const empty = ref(false);
|
|
25
|
+
const renderKey = ref(0);
|
|
26
|
+
let refreshHandler;
|
|
27
|
+
const collapsed = computed(() => layout.value.collapsed.includes(props.item.id));
|
|
28
|
+
const itemContext = {
|
|
29
|
+
dashboard: props.item.dashboard,
|
|
30
|
+
id: props.item.id,
|
|
31
|
+
loading,
|
|
32
|
+
error,
|
|
33
|
+
empty,
|
|
34
|
+
collapsed,
|
|
35
|
+
settings: computed(() => layout.value.settings?.[props.item.id] ?? {}),
|
|
36
|
+
setSettings: (value) => update((current) => setItemSettings(current, props.item.id, value)),
|
|
37
|
+
async refresh() {
|
|
38
|
+
error.value = null;
|
|
39
|
+
if (refreshHandler) await refreshHandler();
|
|
40
|
+
else renderKey.value++;
|
|
41
|
+
},
|
|
42
|
+
onRefresh(handler) {
|
|
43
|
+
refreshHandler = handler;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
provide(dashboardItemKey, itemContext);
|
|
47
|
+
onErrorCaptured((cause) => {
|
|
48
|
+
error.value = cause;
|
|
49
|
+
return false;
|
|
50
|
+
});
|
|
51
|
+
const toggle = () => update((current) => toggleCollapsed(current, props.item.id));
|
|
52
|
+
const blank = ref(false);
|
|
53
|
+
const content = ref(null);
|
|
54
|
+
let observer;
|
|
55
|
+
const check = () => {
|
|
56
|
+
if (content.value) blank.value = content.value.childElementCount === 0 && !content.value.textContent?.trim();
|
|
57
|
+
};
|
|
58
|
+
watch(content, (element) => {
|
|
59
|
+
observer?.disconnect();
|
|
60
|
+
if (!element || typeof MutationObserver === "undefined") return;
|
|
61
|
+
check();
|
|
62
|
+
observer = new MutationObserver(check);
|
|
63
|
+
observer.observe(element, { childList: true, subtree: true, characterData: true });
|
|
64
|
+
}, { flush: "post" });
|
|
65
|
+
onBeforeUnmount(() => observer?.disconnect());
|
|
66
|
+
const visible = computed(() => props.editing || !!error.value || !empty.value && (loading.value || !blank.value));
|
|
67
|
+
</script>
|
|
68
|
+
|
|
69
|
+
<template>
|
|
70
|
+
<!-- An item with nothing to show (`empty`, or nothing rendered) stays mounted, so it can come back, but takes no place in
|
|
71
|
+
the grid. -->
|
|
72
|
+
<div
|
|
73
|
+
v-show="visible"
|
|
74
|
+
:class="['flex min-w-0 flex-col gap-2', dashboardSpanClass(item.span)]"
|
|
75
|
+
:data-dashboard-item="item.id"
|
|
76
|
+
>
|
|
77
|
+
<div
|
|
78
|
+
v-if="item.title || editing"
|
|
79
|
+
class="flex min-h-7 items-center justify-between gap-2"
|
|
80
|
+
>
|
|
81
|
+
<button
|
|
82
|
+
v-if="item.title"
|
|
83
|
+
type="button"
|
|
84
|
+
class="text-highlighted flex min-w-0 items-center gap-1 text-sm font-semibold"
|
|
85
|
+
:aria-expanded="!collapsed"
|
|
86
|
+
:disabled="saving"
|
|
87
|
+
:aria-label="collapsed ? t('item.expand', 'Expand {title}', { title: label }) : t('item.collapse', 'Collapse {title}', { title: label })"
|
|
88
|
+
@click="toggle"
|
|
89
|
+
>
|
|
90
|
+
<UIcon
|
|
91
|
+
:name="collapsed ? 'i-lucide-chevron-right' : 'i-lucide-chevron-down'"
|
|
92
|
+
class="text-muted size-4 shrink-0"
|
|
93
|
+
/>
|
|
94
|
+
<span class="truncate">{{ item.title }}</span>
|
|
95
|
+
</button>
|
|
96
|
+
<span v-else />
|
|
97
|
+
<div
|
|
98
|
+
v-if="editing"
|
|
99
|
+
class="flex shrink-0 items-center gap-1"
|
|
100
|
+
>
|
|
101
|
+
<UButton
|
|
102
|
+
icon="i-lucide-arrow-up"
|
|
103
|
+
size="xs"
|
|
104
|
+
color="neutral"
|
|
105
|
+
variant="ghost"
|
|
106
|
+
:disabled="first || disabled"
|
|
107
|
+
:aria-label="t('item.moveUp', 'Move {title} up', { title: label })"
|
|
108
|
+
@click="emit('moveUp')"
|
|
109
|
+
/>
|
|
110
|
+
<UButton
|
|
111
|
+
icon="i-lucide-arrow-down"
|
|
112
|
+
size="xs"
|
|
113
|
+
color="neutral"
|
|
114
|
+
variant="ghost"
|
|
115
|
+
:disabled="last || disabled"
|
|
116
|
+
:aria-label="t('item.moveDown', 'Move {title} down', { title: label })"
|
|
117
|
+
@click="emit('moveDown')"
|
|
118
|
+
/>
|
|
119
|
+
<UButton
|
|
120
|
+
icon="i-lucide-eye-off"
|
|
121
|
+
size="xs"
|
|
122
|
+
color="neutral"
|
|
123
|
+
variant="ghost"
|
|
124
|
+
:disabled="disabled"
|
|
125
|
+
:aria-label="t('item.hide', 'Hide {title}', { title: label })"
|
|
126
|
+
@click="emit('hide')"
|
|
127
|
+
/>
|
|
128
|
+
</div>
|
|
129
|
+
</div>
|
|
130
|
+
|
|
131
|
+
<template v-if="!collapsed">
|
|
132
|
+
<div
|
|
133
|
+
v-if="error"
|
|
134
|
+
:class="[surfaceClass, 'flex flex-col items-start gap-2 p-4']"
|
|
135
|
+
role="alert"
|
|
136
|
+
>
|
|
137
|
+
<p class="text-highlighted text-sm font-medium">
|
|
138
|
+
{{ t("item.error", "{title} could not be loaded.", { title: label }) }}
|
|
139
|
+
</p>
|
|
140
|
+
<p class="text-muted text-xs">
|
|
141
|
+
{{ errorMessage(error, t("item.errorHint", "Something went wrong. Try again in a moment.")) }}
|
|
142
|
+
</p>
|
|
143
|
+
<UButton
|
|
144
|
+
size="xs"
|
|
145
|
+
color="neutral"
|
|
146
|
+
variant="outline"
|
|
147
|
+
icon="i-lucide-rotate-cw"
|
|
148
|
+
:label="t('item.retry', 'Try again')"
|
|
149
|
+
@click="itemContext.refresh()"
|
|
150
|
+
/>
|
|
151
|
+
</div>
|
|
152
|
+
<div
|
|
153
|
+
v-if="!error && loading"
|
|
154
|
+
:class="[surfaceClass, 'space-y-3 p-4']"
|
|
155
|
+
data-dashboard-skeleton
|
|
156
|
+
>
|
|
157
|
+
<USkeleton class="h-4 w-1/3" />
|
|
158
|
+
<USkeleton class="h-5 w-2/3" />
|
|
159
|
+
<USkeleton class="h-4 w-1/2" />
|
|
160
|
+
</div>
|
|
161
|
+
<!-- Grows to the row's height, and so does the component's root, so cards in a row line up. -->
|
|
162
|
+
<div
|
|
163
|
+
v-show="!error && !loading"
|
|
164
|
+
ref="content"
|
|
165
|
+
class="flex min-h-0 flex-1 flex-col *:flex-1"
|
|
166
|
+
>
|
|
167
|
+
<component
|
|
168
|
+
:is="component"
|
|
169
|
+
:key="renderKey"
|
|
170
|
+
v-bind="{ ...item.props, ...context }"
|
|
171
|
+
/>
|
|
172
|
+
</div>
|
|
173
|
+
</template>
|
|
174
|
+
</div>
|
|
175
|
+
</template>
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { DashboardEntry } from '../composables/useDashboard.js';
|
|
2
|
+
/**
|
|
3
|
+
* The frame of one dashboard item: its title with a collapse toggle, the item's component, a skeleton while the item
|
|
4
|
+
* reports `loading`, an error with a retry, and nothing while it reports `empty` or renders nothing at all (a `v-if` on
|
|
5
|
+
* its root, as widgets shared with other widget areas do). Provides `useDashboardItem()` to the component. In `editing` mode it shows the buttons to move and hide the item (the dashboard handles the events).
|
|
6
|
+
*/
|
|
7
|
+
type __VLS_Props = {
|
|
8
|
+
item: DashboardEntry;
|
|
9
|
+
context?: Record<string, unknown>;
|
|
10
|
+
editing?: boolean;
|
|
11
|
+
/** Disables the edit buttons, while a layout change is being saved. */
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
first?: boolean;
|
|
14
|
+
last?: boolean;
|
|
15
|
+
};
|
|
16
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
17
|
+
hide: () => any;
|
|
18
|
+
moveUp: () => any;
|
|
19
|
+
moveDown: () => any;
|
|
20
|
+
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
21
|
+
onHide?: (() => any) | undefined;
|
|
22
|
+
onMoveUp?: (() => any) | undefined;
|
|
23
|
+
onMoveDown?: (() => any) | undefined;
|
|
24
|
+
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
25
|
+
declare const _default: typeof __VLS_export;
|
|
26
|
+
export default _default;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An empty state in a card (`UEmpty`) with exactly one action: a link to `to` or the `action` event. Without
|
|
3
|
+
* `actionLabel` it has none, for a state the viewer cannot change.
|
|
4
|
+
*/
|
|
5
|
+
type __VLS_Props = {
|
|
6
|
+
title: string;
|
|
7
|
+
description?: string;
|
|
8
|
+
icon?: string;
|
|
9
|
+
actionLabel?: string;
|
|
10
|
+
to?: string;
|
|
11
|
+
};
|
|
12
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
13
|
+
action: () => any;
|
|
14
|
+
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
15
|
+
onAction?: (() => any) | undefined;
|
|
16
|
+
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
17
|
+
declare const _default: typeof __VLS_export;
|
|
18
|
+
export default _default;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { computed } from "vue";
|
|
3
|
+
import { surfaceClass } from "#imports";
|
|
4
|
+
const props = defineProps({
|
|
5
|
+
title: { type: String, required: true },
|
|
6
|
+
description: { type: String, required: false },
|
|
7
|
+
icon: { type: String, required: false },
|
|
8
|
+
actionLabel: { type: String, required: false },
|
|
9
|
+
to: { type: String, required: false }
|
|
10
|
+
});
|
|
11
|
+
const emit = defineEmits(["action"]);
|
|
12
|
+
const actions = computed(() => props.actionLabel ? [{ label: props.actionLabel, to: props.to, color: "neutral", variant: "outline", onClick: () => emit("action") }] : void 0);
|
|
13
|
+
</script>
|
|
14
|
+
|
|
15
|
+
<template>
|
|
16
|
+
<div :class="[surfaceClass, 'h-full']">
|
|
17
|
+
<UEmpty
|
|
18
|
+
:icon="icon"
|
|
19
|
+
:title="title"
|
|
20
|
+
:description="description"
|
|
21
|
+
:actions="actions"
|
|
22
|
+
variant="naked"
|
|
23
|
+
/>
|
|
24
|
+
</div>
|
|
25
|
+
</template>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An empty state in a card (`UEmpty`) with exactly one action: a link to `to` or the `action` event. Without
|
|
3
|
+
* `actionLabel` it has none, for a state the viewer cannot change.
|
|
4
|
+
*/
|
|
5
|
+
type __VLS_Props = {
|
|
6
|
+
title: string;
|
|
7
|
+
description?: string;
|
|
8
|
+
icon?: string;
|
|
9
|
+
actionLabel?: string;
|
|
10
|
+
to?: string;
|
|
11
|
+
};
|
|
12
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
13
|
+
action: () => any;
|
|
14
|
+
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
15
|
+
onAction?: (() => any) | undefined;
|
|
16
|
+
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
17
|
+
declare const _default: typeof __VLS_export;
|
|
18
|
+
export default _default;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { type ComputedRef, type MaybeRefOrGetter, type Ref } from 'vue';
|
|
2
|
+
import { useWidgets } from '#imports';
|
|
3
|
+
import type { WidgetMeta } from '@frigear-nu/widget';
|
|
4
|
+
import type { DashboardLayout, DashboardPlatform, DashboardRegistryEntry } from '../../../types.js';
|
|
5
|
+
/** A resolved item: its widget data, its dashboard data and its title translated. */
|
|
6
|
+
export type DashboardEntry = WidgetMeta & Omit<DashboardRegistryEntry, 'id'> & {
|
|
7
|
+
/** The dashboard's name. */
|
|
8
|
+
dashboard: string;
|
|
9
|
+
/** Whether the user collapsed it. */
|
|
10
|
+
collapsed: boolean;
|
|
11
|
+
};
|
|
12
|
+
export interface UseDashboard {
|
|
13
|
+
/** The items to render: allowed for the viewer, on this platform, not hidden, in the user's order. */
|
|
14
|
+
items: ComputedRef<DashboardEntry[]>;
|
|
15
|
+
/** The items the user hid, in their order. */
|
|
16
|
+
hidden: ComputedRef<DashboardEntry[]>;
|
|
17
|
+
/** Ids of the collapsed items. */
|
|
18
|
+
collapsed: ComputedRef<string[]>;
|
|
19
|
+
/** The user's layout of this dashboard. */
|
|
20
|
+
layout: ComputedRef<DashboardLayout>;
|
|
21
|
+
/** Whether layout changes are saved for the user, not only kept for this session. */
|
|
22
|
+
persisted: ComputedRef<boolean>;
|
|
23
|
+
/** Whether a layout change is being saved: disable the edit buttons meanwhile. */
|
|
24
|
+
saving: Ref<boolean>;
|
|
25
|
+
platform: Ref<DashboardPlatform>;
|
|
26
|
+
/** Moves an item to `toIndex` among `items`. */
|
|
27
|
+
move: (id: string, toIndex: number) => Promise<void>;
|
|
28
|
+
hide: (id: string) => Promise<void>;
|
|
29
|
+
show: (id: string) => Promise<void>;
|
|
30
|
+
toggleCollapsed: (id: string) => Promise<void>;
|
|
31
|
+
/** Back to the registered default. */
|
|
32
|
+
reset: () => Promise<void>;
|
|
33
|
+
status: ReturnType<typeof useWidgets>['status'];
|
|
34
|
+
error: ReturnType<typeof useWidgets>['error'];
|
|
35
|
+
refresh: () => Promise<void>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* A dashboard's items, resolved for the current viewer: filtered by `permission` (the `widgets:filter` hook of
|
|
39
|
+
* `@frigear-nu/widget`), by platform, and laid out in the user's order without the hidden ones. Plus the edits of the
|
|
40
|
+
* layout. Await it on a page so the items render on the server.
|
|
41
|
+
*
|
|
42
|
+
* ```ts
|
|
43
|
+
* const { items, hidden, move, hide, show, reset } = await useDashboard('crew.home')
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare function useDashboard(name: string, context?: MaybeRefOrGetter<Record<string, unknown> | undefined>): UseDashboard & Promise<UseDashboard>;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { computed } from "vue";
|
|
2
|
+
import { useNuxtApp, useWidgets } from "#imports";
|
|
3
|
+
import { dashboards } from "#dashboard/registry";
|
|
4
|
+
import { applyLayout, filterByPlatform, hideItem, moveItem, resetLayout, showItem, toggleCollapsed } from "../../shared/layout.js";
|
|
5
|
+
import { dashboardArea } from "../../shared/registry.js";
|
|
6
|
+
import { getDashboardItemIds } from "../utils/components.js";
|
|
7
|
+
import { useDashboardLayout } from "./useDashboardLayout.js";
|
|
8
|
+
import { useDashboardPlatform } from "./useDashboardPlatform.js";
|
|
9
|
+
export function useDashboard(name, context) {
|
|
10
|
+
const nuxtApp = useNuxtApp();
|
|
11
|
+
const i18n = nuxtApp.$i18n;
|
|
12
|
+
const translate = (key, fallback) => {
|
|
13
|
+
if (!key || !i18n) return fallback;
|
|
14
|
+
const text = i18n.t(key);
|
|
15
|
+
return text && text !== key ? text : fallback;
|
|
16
|
+
};
|
|
17
|
+
const platform = useDashboardPlatform();
|
|
18
|
+
const registry = dashboards[name] ?? {};
|
|
19
|
+
const widgets = useWidgets(dashboardArea(name), context);
|
|
20
|
+
const { layout, persisted, ready, saving, update } = useDashboardLayout(name);
|
|
21
|
+
const available = computed(() => {
|
|
22
|
+
const collapsed = new Set(layout.value.collapsed);
|
|
23
|
+
const joined = (widgets.data.value ?? []).flatMap((widget) => {
|
|
24
|
+
const entry = registry[widget.id];
|
|
25
|
+
if (!entry) return [];
|
|
26
|
+
const { id: _id, ...extra } = entry;
|
|
27
|
+
return [{
|
|
28
|
+
...widget,
|
|
29
|
+
...extra,
|
|
30
|
+
title: translate(entry.titleKey, entry.title),
|
|
31
|
+
dashboard: name,
|
|
32
|
+
collapsed: collapsed.has(widget.id)
|
|
33
|
+
}];
|
|
34
|
+
});
|
|
35
|
+
return filterByPlatform(joined, platform.value);
|
|
36
|
+
});
|
|
37
|
+
const applied = computed(() => applyLayout(available.value, layout.value, getDashboardItemIds(name)));
|
|
38
|
+
const items = computed(() => applied.value.items);
|
|
39
|
+
const result = {
|
|
40
|
+
items,
|
|
41
|
+
hidden: computed(() => applied.value.hidden),
|
|
42
|
+
collapsed: computed(() => applied.value.collapsed),
|
|
43
|
+
layout,
|
|
44
|
+
persisted,
|
|
45
|
+
saving,
|
|
46
|
+
platform,
|
|
47
|
+
// Within the full order of every item, so items of the other platform (or another viewer) keep their place.
|
|
48
|
+
move: (id, toIndex) => update((current) => moveItem(current, getDashboardItemIds(name), items.value.map((item) => item.id), id, toIndex)),
|
|
49
|
+
hide: (id) => update((current) => hideItem(current, id)),
|
|
50
|
+
show: (id) => update((current) => showItem(current, id)),
|
|
51
|
+
toggleCollapsed: (id) => update((current) => toggleCollapsed(current, id)),
|
|
52
|
+
reset: () => update(() => resetLayout()),
|
|
53
|
+
status: widgets.status,
|
|
54
|
+
error: widgets.error,
|
|
55
|
+
refresh: () => widgets.refresh()
|
|
56
|
+
};
|
|
57
|
+
const promise = Promise.all([widgets, ready]).then(() => result);
|
|
58
|
+
return Object.assign(promise, result);
|
|
59
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type ComputedRef, type InjectionKey, type Ref } from 'vue';
|
|
2
|
+
export interface DashboardItemContext {
|
|
3
|
+
/** The dashboard's name. */
|
|
4
|
+
dashboard: string;
|
|
5
|
+
/** The item's id. */
|
|
6
|
+
id: string;
|
|
7
|
+
/** Set by the item while it loads: the frame shows a skeleton instead of an empty card. */
|
|
8
|
+
loading: Ref<boolean>;
|
|
9
|
+
/** Set by the item when its data failed: the frame shows the error with a retry button. */
|
|
10
|
+
error: Ref<unknown>;
|
|
11
|
+
/**
|
|
12
|
+
* Set by the item when it has nothing to show this viewer (no apps, no mailbox): the frame, title included, is left
|
|
13
|
+
* out of the grid until it has something, except while the user edits the layout.
|
|
14
|
+
*/
|
|
15
|
+
empty: Ref<boolean>;
|
|
16
|
+
/** Whether the user collapsed the item. A collapsed item is not rendered. */
|
|
17
|
+
collapsed: ComputedRef<boolean>;
|
|
18
|
+
/** The user's settings of this item (stored in their layout). */
|
|
19
|
+
settings: ComputedRef<Record<string, unknown>>;
|
|
20
|
+
/** Replaces the user's settings of this item; an empty object clears them. */
|
|
21
|
+
setSettings: (value: Record<string, unknown>) => Promise<void>;
|
|
22
|
+
/** Reloads the item: clears `error` and calls the handler registered with `onRefresh`. */
|
|
23
|
+
refresh: () => Promise<void>;
|
|
24
|
+
/** Registers what `refresh()` (and the retry button) calls, such as the `refresh` of the item's `useFetch`. */
|
|
25
|
+
onRefresh: (handler: () => unknown) => void;
|
|
26
|
+
}
|
|
27
|
+
export declare const dashboardItemKey: InjectionKey<DashboardItemContext>;
|
|
28
|
+
/**
|
|
29
|
+
* The context of the dashboard item being rendered: report `loading` and `error`, register a `refresh`, and read or
|
|
30
|
+
* change the user's `settings` of the item.
|
|
31
|
+
*
|
|
32
|
+
* ```ts
|
|
33
|
+
* const { loading, error, onRefresh } = useDashboardItem()
|
|
34
|
+
* const { data, status, error: fetchError, refresh } = await useFetch('/api/shifts/me/next')
|
|
35
|
+
* watchEffect(() => { loading.value = status.value === 'pending'; error.value = fetchError.value })
|
|
36
|
+
* onRefresh(refresh)
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare function useDashboardItem(): DashboardItemContext;
|