@sfxcode/nuxt-ui-mongocamp 1.5.2 → 1.5.3
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/dist/module.d.mts +9 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +1 -0
- package/dist/runtime/components/MongocampCollectionData.d.vue.ts +0 -1
- package/dist/runtime/components/MongocampCollectionData.vue +4 -3
- package/dist/runtime/components/MongocampCollectionData.vue.d.ts +0 -1
- package/dist/runtime/components/MongocampCollections.vue +7 -4
- package/dist/runtime/components/MongocampCommandPalette.d.vue.ts +0 -7
- package/dist/runtime/components/MongocampCommandPalette.vue +16 -15
- package/dist/runtime/components/MongocampCommandPalette.vue.d.ts +0 -7
- package/dist/runtime/components/MongocampDashboard.d.vue.ts +0 -3
- package/dist/runtime/components/MongocampDashboard.vue +8 -7
- package/dist/runtime/components/MongocampDashboard.vue.d.ts +0 -3
- package/dist/runtime/components/MongocampPermissionMatrix.d.vue.ts +0 -1
- package/dist/runtime/components/MongocampPermissionMatrix.vue +4 -3
- package/dist/runtime/components/MongocampPermissionMatrix.vue.d.ts +0 -1
- package/dist/runtime/components/MongocampRoles.vue +3 -2
- package/dist/runtime/components/MongocampServerOverview.d.vue.ts +0 -3
- package/dist/runtime/components/MongocampServerOverview.vue +8 -7
- package/dist/runtime/components/MongocampServerOverview.vue.d.ts +0 -3
- package/dist/runtime/components/MongocampServerStatus.d.vue.ts +13 -0
- package/dist/runtime/components/MongocampServerStatus.vue +147 -0
- package/dist/runtime/components/MongocampServerStatus.vue.d.ts +13 -0
- package/dist/runtime/components/MongocampUserAccess.d.vue.ts +27 -0
- package/dist/runtime/components/MongocampUserAccess.vue +168 -0
- package/dist/runtime/components/MongocampUserAccess.vue.d.ts +27 -0
- package/dist/runtime/components/MongocampVersion.vue +3 -3
- package/dist/runtime/composables/useMongocampAdminGate.js +2 -3
- package/dist/runtime/composables/useMongocampBreadcrumbs.d.ts +12 -0
- package/dist/runtime/composables/useMongocampBreadcrumbs.js +13 -0
- package/dist/runtime/composables/useMongocampCollectionNames.d.ts +21 -0
- package/dist/runtime/composables/useMongocampCollectionNames.js +46 -0
- package/dist/runtime/composables/useMongocampNavigation.d.ts +32 -0
- package/dist/runtime/composables/useMongocampNavigation.js +15 -0
- package/dist/runtime/composables/useMongocampPaths.d.ts +6 -0
- package/dist/runtime/composables/useMongocampPaths.js +6 -0
- package/dist/runtime/composables/useMongocampPermissions.js +2 -3
- package/dist/runtime/composables/useMongocampProxyMode.d.ts +5 -0
- package/dist/runtime/composables/useMongocampProxyMode.js +4 -0
- package/dist/runtime/composables/useMongocampRoles.d.ts +3 -0
- package/dist/runtime/composables/useMongocampRoles.js +5 -1
- package/dist/runtime/composables/useMongocampSession.js +2 -3
- package/dist/runtime/locales/de.json +42 -0
- package/dist/runtime/locales/en.json +42 -0
- package/dist/runtime/publicUtils.d.ts +4 -0
- package/dist/runtime/publicUtils.js +4 -0
- package/dist/runtime/utils/collectionNames.d.ts +13 -0
- package/dist/runtime/utils/collectionNames.js +14 -0
- package/dist/runtime/utils/collectionProtection.d.ts +2 -0
- package/dist/runtime/utils/collectionProtection.js +3 -0
- package/dist/runtime/utils/navigation.d.ts +39 -0
- package/dist/runtime/utils/navigation.js +65 -0
- package/dist/runtime/utils/paths.d.ts +32 -0
- package/dist/runtime/utils/paths.js +24 -0
- package/dist/runtime/utils/serverStatus.d.ts +20 -0
- package/dist/runtime/utils/serverStatus.js +11 -0
- package/package.json +8 -1
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
type __VLS_Props = {
|
|
2
|
+
hideHeading?: boolean;
|
|
3
|
+
hideRefresh?: boolean;
|
|
4
|
+
hideStats?: boolean;
|
|
5
|
+
};
|
|
6
|
+
declare function refresh(): Promise<void>;
|
|
7
|
+
declare const __VLS_template: () => {
|
|
8
|
+
__VLS_Slots: {
|
|
9
|
+
toolbar?: (props: {}) => any;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
type __VLS_Slots = ReturnType<typeof __VLS_template>['__VLS_Slots'];
|
|
13
|
+
declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {
|
|
14
|
+
refresh: typeof refresh;
|
|
15
|
+
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
|
|
16
|
+
hideRefresh: boolean;
|
|
17
|
+
hideHeading: boolean;
|
|
18
|
+
hideStats: 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,168 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { computed, ref } from "vue";
|
|
3
|
+
import { useI18n, useMongocampClientApi, useMongocampStorage } from "#imports";
|
|
4
|
+
defineProps({
|
|
5
|
+
hideHeading: { type: Boolean, required: false, default: false },
|
|
6
|
+
hideRefresh: { type: Boolean, required: false, default: false },
|
|
7
|
+
hideStats: { type: Boolean, required: false, default: false }
|
|
8
|
+
});
|
|
9
|
+
const FLAGS = ["read", "write", "administrate"];
|
|
10
|
+
const { t } = useI18n();
|
|
11
|
+
const { authApi } = useMongocampClientApi();
|
|
12
|
+
const state = useMongocampStorage();
|
|
13
|
+
const isAdmin = computed(() => state.value?.profile?.isAdmin === true);
|
|
14
|
+
const access = ref([]);
|
|
15
|
+
const loading = ref(false);
|
|
16
|
+
const loadError = ref(null);
|
|
17
|
+
async function refresh() {
|
|
18
|
+
if (isAdmin.value) return;
|
|
19
|
+
loading.value = true;
|
|
20
|
+
loadError.value = null;
|
|
21
|
+
try {
|
|
22
|
+
const rows = await authApi.userPermissions({}, { signal: AbortSignal.timeout(15e3) });
|
|
23
|
+
access.value = rows.filter((row) => !row.name.startsWith("mc_")).map((row) => ({ name: row.name, read: row.read === true, write: row.write === true, administrate: row.administrate === true })).sort((a, b) => a.name.localeCompare(b.name));
|
|
24
|
+
} catch (e) {
|
|
25
|
+
loadError.value = e;
|
|
26
|
+
access.value = [];
|
|
27
|
+
} finally {
|
|
28
|
+
loading.value = false;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const stats = computed(() => [
|
|
32
|
+
{ key: "collections", label: t("nuxtUiMongocamp.userAccess.collections"), icon: "i-lucide-database", value: access.value.length },
|
|
33
|
+
{ key: "read", label: t("nuxtUiMongocamp.userAccess.canRead"), icon: "i-lucide-eye", value: access.value.filter((r) => r.read).length },
|
|
34
|
+
{ key: "write", label: t("nuxtUiMongocamp.userAccess.canWrite"), icon: "i-lucide-pencil", value: access.value.filter((r) => r.write).length },
|
|
35
|
+
{ key: "administrate", label: t("nuxtUiMongocamp.userAccess.canAdministrate"), icon: "i-lucide-shield-check", value: access.value.filter((r) => r.administrate).length }
|
|
36
|
+
]);
|
|
37
|
+
defineExpose({ refresh });
|
|
38
|
+
refresh();
|
|
39
|
+
</script>
|
|
40
|
+
|
|
41
|
+
<template>
|
|
42
|
+
<div class="flex flex-col gap-6">
|
|
43
|
+
<div
|
|
44
|
+
v-if="!hideHeading || !hideRefresh || $slots.toolbar"
|
|
45
|
+
class="flex items-center justify-between gap-2"
|
|
46
|
+
>
|
|
47
|
+
<h2
|
|
48
|
+
v-if="!hideHeading"
|
|
49
|
+
class="text-lg font-semibold"
|
|
50
|
+
>
|
|
51
|
+
{{ t("nuxtUiMongocamp.userAccess.heading") }}
|
|
52
|
+
</h2>
|
|
53
|
+
<div class="ml-auto flex items-center gap-2">
|
|
54
|
+
<UTooltip
|
|
55
|
+
v-if="!isAdmin && !hideRefresh"
|
|
56
|
+
:text="t('nuxtUiMongocamp.common.refresh')"
|
|
57
|
+
>
|
|
58
|
+
<UButton
|
|
59
|
+
icon="i-lucide-refresh-cw"
|
|
60
|
+
color="neutral"
|
|
61
|
+
variant="ghost"
|
|
62
|
+
:loading="loading"
|
|
63
|
+
:aria-label="t('nuxtUiMongocamp.common.refresh')"
|
|
64
|
+
@click="refresh"
|
|
65
|
+
/>
|
|
66
|
+
</UTooltip>
|
|
67
|
+
<slot name="toolbar" />
|
|
68
|
+
</div>
|
|
69
|
+
</div>
|
|
70
|
+
|
|
71
|
+
<UAlert
|
|
72
|
+
v-if="isAdmin"
|
|
73
|
+
color="info"
|
|
74
|
+
variant="subtle"
|
|
75
|
+
icon="i-lucide-shield-check"
|
|
76
|
+
:title="t('nuxtUiMongocamp.userAccess.adminTitle')"
|
|
77
|
+
:description="t('nuxtUiMongocamp.userAccess.adminDescription')"
|
|
78
|
+
data-test="admin-access"
|
|
79
|
+
/>
|
|
80
|
+
|
|
81
|
+
<template v-else>
|
|
82
|
+
<div
|
|
83
|
+
v-if="!hideStats"
|
|
84
|
+
class="grid grid-cols-2 gap-4 lg:grid-cols-4"
|
|
85
|
+
>
|
|
86
|
+
<UCard
|
|
87
|
+
v-for="stat in stats"
|
|
88
|
+
:key="stat.key"
|
|
89
|
+
:data-test="`access-stat-${stat.key}`"
|
|
90
|
+
>
|
|
91
|
+
<div class="flex items-center gap-3">
|
|
92
|
+
<UIcon
|
|
93
|
+
:name="stat.icon"
|
|
94
|
+
class="size-6 text-primary"
|
|
95
|
+
/>
|
|
96
|
+
<div>
|
|
97
|
+
<div class="text-2xl font-semibold tabular-nums">
|
|
98
|
+
{{ loading || loadError ? "\u2026" : stat.value }}
|
|
99
|
+
</div>
|
|
100
|
+
<div class="text-sm text-muted">
|
|
101
|
+
{{ stat.label }}
|
|
102
|
+
</div>
|
|
103
|
+
</div>
|
|
104
|
+
</div>
|
|
105
|
+
</UCard>
|
|
106
|
+
</div>
|
|
107
|
+
|
|
108
|
+
<MongocampErrorAlert
|
|
109
|
+
:error="loadError"
|
|
110
|
+
@retry="refresh"
|
|
111
|
+
/>
|
|
112
|
+
<MongocampEmptyState
|
|
113
|
+
v-if="!loadError && !loading && !access.length"
|
|
114
|
+
icon="i-lucide-lock"
|
|
115
|
+
:title="t('nuxtUiMongocamp.userAccess.emptyTitle')"
|
|
116
|
+
:description="t('nuxtUiMongocamp.userAccess.emptyDescription')"
|
|
117
|
+
/>
|
|
118
|
+
<table
|
|
119
|
+
v-else-if="access.length"
|
|
120
|
+
class="w-full text-sm"
|
|
121
|
+
>
|
|
122
|
+
<thead>
|
|
123
|
+
<tr class="text-left text-muted">
|
|
124
|
+
<th
|
|
125
|
+
scope="col"
|
|
126
|
+
class="py-2 font-medium"
|
|
127
|
+
>
|
|
128
|
+
{{ t("nuxtUiMongocamp.userAccess.collection") }}
|
|
129
|
+
</th>
|
|
130
|
+
<th
|
|
131
|
+
v-for="flag in FLAGS"
|
|
132
|
+
:key="flag"
|
|
133
|
+
scope="col"
|
|
134
|
+
class="py-2 font-medium"
|
|
135
|
+
>
|
|
136
|
+
{{ t(`nuxtUiMongocamp.userAccess.${flag}`) }}
|
|
137
|
+
</th>
|
|
138
|
+
</tr>
|
|
139
|
+
</thead>
|
|
140
|
+
<tbody>
|
|
141
|
+
<tr
|
|
142
|
+
v-for="row in access"
|
|
143
|
+
:key="row.name"
|
|
144
|
+
class="border-t border-default"
|
|
145
|
+
>
|
|
146
|
+
<th
|
|
147
|
+
scope="row"
|
|
148
|
+
class="py-2 text-left font-mono font-normal"
|
|
149
|
+
>
|
|
150
|
+
{{ row.name }}
|
|
151
|
+
</th>
|
|
152
|
+
<td
|
|
153
|
+
v-for="flag in FLAGS"
|
|
154
|
+
:key="flag"
|
|
155
|
+
class="py-2"
|
|
156
|
+
>
|
|
157
|
+
<UBadge
|
|
158
|
+
:label="row[flag] ? t('nuxtUiMongocamp.common.yes') : t('nuxtUiMongocamp.common.no')"
|
|
159
|
+
:color="row[flag] ? 'success' : 'neutral'"
|
|
160
|
+
variant="subtle"
|
|
161
|
+
/>
|
|
162
|
+
</td>
|
|
163
|
+
</tr>
|
|
164
|
+
</tbody>
|
|
165
|
+
</table>
|
|
166
|
+
</template>
|
|
167
|
+
</div>
|
|
168
|
+
</template>
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
type __VLS_Props = {
|
|
2
|
+
hideHeading?: boolean;
|
|
3
|
+
hideRefresh?: boolean;
|
|
4
|
+
hideStats?: boolean;
|
|
5
|
+
};
|
|
6
|
+
declare function refresh(): Promise<void>;
|
|
7
|
+
declare const __VLS_template: () => {
|
|
8
|
+
__VLS_Slots: {
|
|
9
|
+
toolbar?: (props: {}) => any;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
type __VLS_Slots = ReturnType<typeof __VLS_template>['__VLS_Slots'];
|
|
13
|
+
declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {
|
|
14
|
+
refresh: typeof refresh;
|
|
15
|
+
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
|
|
16
|
+
hideRefresh: boolean;
|
|
17
|
+
hideHeading: boolean;
|
|
18
|
+
hideStats: 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
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script setup>
|
|
2
2
|
import { computed, ref, watch } from "vue";
|
|
3
|
-
import { useI18n, useMongocampStorage, useMongocampSystem } from "#imports";
|
|
4
|
-
import { useNuxtApp
|
|
3
|
+
import { useI18n, useMongocampProxyMode, useMongocampStorage, useMongocampSystem } from "#imports";
|
|
4
|
+
import { useNuxtApp } from "#app";
|
|
5
5
|
const props = defineProps({
|
|
6
6
|
hideDatabase: { type: Boolean, required: false, default: false }
|
|
7
7
|
});
|
|
@@ -9,7 +9,7 @@ const { t } = useI18n();
|
|
|
9
9
|
const { $mongocampVersion } = useNuxtApp();
|
|
10
10
|
const { getServerInfo } = useMongocampSystem();
|
|
11
11
|
const state = useMongocampStorage();
|
|
12
|
-
const isProxyMode =
|
|
12
|
+
const isProxyMode = useMongocampProxyMode();
|
|
13
13
|
const version = computed(() => $mongocampVersion.value);
|
|
14
14
|
const mongoDbVersion = ref(null);
|
|
15
15
|
const canAsk = computed(() => !props.hideDatabase && (isProxyMode || !!state.value?.profile));
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { useRuntimeConfig } from "#app";
|
|
2
1
|
import { useI18n, useMongocampStorage } from "#imports";
|
|
3
2
|
import { computed } from "vue";
|
|
3
|
+
import { useMongocampProxyMode } from "./useMongocampProxyMode.js";
|
|
4
4
|
export function useMongocampAdminGate() {
|
|
5
|
-
const config = useRuntimeConfig();
|
|
6
5
|
const state = useMongocampStorage();
|
|
7
6
|
const { t } = useI18n();
|
|
8
|
-
const isProxyMode =
|
|
7
|
+
const isProxyMode = useMongocampProxyMode();
|
|
9
8
|
const blocked = computed(() => !isProxyMode && state.value?.profile?.isAdmin === false);
|
|
10
9
|
const message = computed(() => t("nuxtUiMongocamp.common.adminOnly"));
|
|
11
10
|
return { blocked, message };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface MongocampBreadcrumbItem {
|
|
2
|
+
label: string;
|
|
3
|
+
/** Absent on the last item — the current page. */
|
|
4
|
+
to?: string;
|
|
5
|
+
icon?: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* The breadcrumb of the current route among the module's pages (module option `paths`): Home › Collections ›
|
|
9
|
+
* test_customer › Data. Section names follow the locale; a collection, bucket or role name is shown as it is in the URL.
|
|
10
|
+
* A route outside every configured page is just Home. The items fit `UBreadcrumb`'s `items`.
|
|
11
|
+
*/
|
|
12
|
+
export declare function useMongocampBreadcrumbs(): import("vue").ComputedRef<MongocampBreadcrumbItem[]>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { useI18n, useMongocampPaths, useRoute } from "#imports";
|
|
2
|
+
import { computed } from "vue";
|
|
3
|
+
import { buildBreadcrumbs } from "../utils/navigation.js";
|
|
4
|
+
export function useMongocampBreadcrumbs() {
|
|
5
|
+
const { t } = useI18n();
|
|
6
|
+
const paths = useMongocampPaths();
|
|
7
|
+
const route = useRoute();
|
|
8
|
+
return computed(() => buildBreadcrumbs(route.path, paths).map((part) => ({
|
|
9
|
+
label: part.labelKey ? t(part.labelKey) : part.text ?? "",
|
|
10
|
+
...part.to ? { to: part.to } : {},
|
|
11
|
+
...part.icon ? { icon: part.icon } : {}
|
|
12
|
+
})));
|
|
13
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export type CollectionNamesStatus = 'idle' | 'loading' | 'ready' | 'failed';
|
|
2
|
+
/**
|
|
3
|
+
* The collection names of the server, **loaded once and shared** by everything that shows them (a sidebar, a panel, a
|
|
4
|
+
* switcher) — a `useState` cache per signed-in user, instead of one `listCollections` request per component. `load()` asks
|
|
5
|
+
* only when nothing is loaded yet, `refresh()` always; neither throws (`status` becomes `failed`, the last list stays).
|
|
6
|
+
* `collections` / `buckets` / `system` are the same list split the usual way (`utils/collectionNames.ts`).
|
|
7
|
+
*
|
|
8
|
+
* `MongocampCollections` writes every list it loads into this cache (`set`), so after a create / drop / rename / copy done
|
|
9
|
+
* there the shared list is current without another request. Code that changes collections elsewhere calls `refresh()`.
|
|
10
|
+
*/
|
|
11
|
+
export declare function useMongocampCollectionNames(): {
|
|
12
|
+
names: import("vue").ComputedRef<string[]>;
|
|
13
|
+
collections: import("vue").ComputedRef<string[]>;
|
|
14
|
+
buckets: import("vue").ComputedRef<string[]>;
|
|
15
|
+
system: import("vue").ComputedRef<string[]>;
|
|
16
|
+
status: import("vue").ComputedRef<CollectionNamesStatus>;
|
|
17
|
+
load: (force?: boolean) => Promise<void>;
|
|
18
|
+
refresh: () => Promise<void>;
|
|
19
|
+
set: (loaded: readonly string[]) => void;
|
|
20
|
+
invalidate: () => void;
|
|
21
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { useMongocampClientApi, useMongocampStorage, useState } from "#imports";
|
|
2
|
+
import { computed } from "vue";
|
|
3
|
+
import { groupCollectionNames } from "../utils/collectionNames.js";
|
|
4
|
+
const REQUEST_TIMEOUT_MS = 15e3;
|
|
5
|
+
let inFlight;
|
|
6
|
+
export function useMongocampCollectionNames() {
|
|
7
|
+
const { collectionApi } = useMongocampClientApi();
|
|
8
|
+
const storage = useMongocampStorage();
|
|
9
|
+
const cache = useState("mongocamp-collection-names", () => ({ user: "", status: "idle", names: [] }));
|
|
10
|
+
const currentUser = () => storage.value?.profile?.user ?? "";
|
|
11
|
+
const own = () => cache.value.user === currentUser();
|
|
12
|
+
const names = computed(() => own() ? cache.value.names : []);
|
|
13
|
+
const status = computed(() => own() ? cache.value.status : "idle");
|
|
14
|
+
const groups = computed(() => groupCollectionNames(names.value));
|
|
15
|
+
const collections = computed(() => groups.value.collections);
|
|
16
|
+
const buckets = computed(() => groups.value.buckets);
|
|
17
|
+
const system = computed(() => groups.value.system);
|
|
18
|
+
async function load(force = false) {
|
|
19
|
+
const user = currentUser();
|
|
20
|
+
if (inFlight?.user === user) return inFlight.run;
|
|
21
|
+
if (!force && own() && cache.value.status === "ready") return;
|
|
22
|
+
const previous = own() ? cache.value.names : [];
|
|
23
|
+
cache.value = { user, status: "loading", names: previous };
|
|
24
|
+
const flight = { user, run: Promise.resolve() };
|
|
25
|
+
inFlight = flight;
|
|
26
|
+
flight.run = (async () => {
|
|
27
|
+
try {
|
|
28
|
+
const loaded = await collectionApi.listCollections({ signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS) });
|
|
29
|
+
if (currentUser() === user) cache.value = { user, status: "ready", names: [...loaded] };
|
|
30
|
+
} catch {
|
|
31
|
+
if (currentUser() === user) cache.value = { user, status: "failed", names: previous };
|
|
32
|
+
} finally {
|
|
33
|
+
if (inFlight === flight) inFlight = void 0;
|
|
34
|
+
}
|
|
35
|
+
})();
|
|
36
|
+
return flight.run;
|
|
37
|
+
}
|
|
38
|
+
const refresh = () => load(true);
|
|
39
|
+
function set(loaded) {
|
|
40
|
+
cache.value = { user: currentUser(), status: "ready", names: [...loaded] };
|
|
41
|
+
}
|
|
42
|
+
function invalidate() {
|
|
43
|
+
cache.value = { user: currentUser(), status: "idle", names: [] };
|
|
44
|
+
}
|
|
45
|
+
return { names, collections, buckets, system, status, load, refresh, set, invalidate };
|
|
46
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { NavigationGroup } from '../utils/navigation.js';
|
|
2
|
+
import type { MongocampPaths } from '../utils/paths.js';
|
|
3
|
+
export interface MongocampNavigationItem {
|
|
4
|
+
/** Stable id of the page — its key in the module's `paths` option. */
|
|
5
|
+
key: keyof MongocampPaths;
|
|
6
|
+
label: string;
|
|
7
|
+
icon: string;
|
|
8
|
+
to: string;
|
|
9
|
+
exact?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface MongocampNavigationGroup {
|
|
12
|
+
key: NavigationGroup['key'];
|
|
13
|
+
label?: string;
|
|
14
|
+
items: MongocampNavigationItem[];
|
|
15
|
+
}
|
|
16
|
+
type MenuRow = MongocampNavigationItem | {
|
|
17
|
+
type: 'label';
|
|
18
|
+
label: string;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* The module's pages as role-aware navigation data, from the module option `paths`: Home and Account for everyone (no
|
|
22
|
+
* Account in server proxy mode), the admin pages in three groups (data, access, server) for whoever may see them
|
|
23
|
+
* (`canSeeAdmin`). Labels follow the current locale.
|
|
24
|
+
*
|
|
25
|
+
* `groups` is the plain structure; `menu` is the same in the shape `UNavigationMenu`'s `items` takes (one array per group,
|
|
26
|
+
* a `{ type: 'label' }` row first where the group has a label). Add your own pages by spreading either.
|
|
27
|
+
*/
|
|
28
|
+
export declare function useMongocampNavigation(): {
|
|
29
|
+
groups: import("vue").ComputedRef<MongocampNavigationGroup[]>;
|
|
30
|
+
menu: import("vue").ComputedRef<MenuRow[][]>;
|
|
31
|
+
};
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useI18n, useMongocampPaths, useMongocampRoles } from "#imports";
|
|
2
|
+
import { computed } from "vue";
|
|
3
|
+
import { buildNavigation } from "../utils/navigation.js";
|
|
4
|
+
export function useMongocampNavigation() {
|
|
5
|
+
const { t } = useI18n();
|
|
6
|
+
const paths = useMongocampPaths();
|
|
7
|
+
const { canSeeAdmin, isProxyMode } = useMongocampRoles();
|
|
8
|
+
const groups = computed(() => buildNavigation(paths, { canSeeAdmin: canSeeAdmin.value, isProxyMode }).map((group) => ({
|
|
9
|
+
key: group.key,
|
|
10
|
+
...group.labelKey ? { label: t(group.labelKey) } : {},
|
|
11
|
+
items: group.items.map(({ labelKey, ...item }) => ({ ...item, label: t(labelKey) }))
|
|
12
|
+
})));
|
|
13
|
+
const menu = computed(() => groups.value.map((group) => [...group.label ? [{ type: "label", label: group.label }] : [], ...group.items]));
|
|
14
|
+
return { groups, menu };
|
|
15
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { MongocampPaths } from '../utils/paths.js';
|
|
2
|
+
/**
|
|
3
|
+
* The base routes of the app's MongoCamp pages (module option `paths`, defaults `/secured/admin/...`). Every `*Path` prop of
|
|
4
|
+
* the components falls back to these, so an app with other routes sets them once. Use it for your own links as well.
|
|
5
|
+
*/
|
|
6
|
+
export declare function useMongocampPaths(): MongocampPaths;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { useRuntimeConfig } from "#app";
|
|
2
1
|
import { useMongocampClientApi, useMongocampStorage, useState } from "#imports";
|
|
3
2
|
import { permissionFromGrants } from "../utils/grantMatching.js";
|
|
3
|
+
import { useMongocampProxyMode } from "./useMongocampProxyMode.js";
|
|
4
4
|
const REQUEST_TIMEOUT_MS = 15e3;
|
|
5
5
|
export function useMongocampPermissions() {
|
|
6
|
-
const config = useRuntimeConfig();
|
|
7
6
|
const state = useMongocampStorage();
|
|
8
7
|
const cache = useState("mongocamp-permissions", () => ({ user: "", byName: {} }));
|
|
9
|
-
const isProxyMode =
|
|
8
|
+
const isProxyMode = useMongocampProxyMode();
|
|
10
9
|
const currentUser = () => state.value?.profile?.user ?? "";
|
|
11
10
|
const key = (name) => name.trim().toLowerCase();
|
|
12
11
|
function fromServer(collectionName) {
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `true` when the module runs in server proxy mode (module option `useServerProxy`): there is no login and no profile, the
|
|
3
|
+
* server-side api key decides what is allowed. A plain boolean — the option is fixed at build time.
|
|
4
|
+
*/
|
|
5
|
+
export declare function useMongocampProxyMode(): boolean;
|
|
@@ -2,6 +2,9 @@ export declare function useMongocampRoles(): {
|
|
|
2
2
|
isLoggedIn: import("vue").ComputedRef<boolean>;
|
|
3
3
|
isAdmin: import("vue").ComputedRef<boolean>;
|
|
4
4
|
isManager: import("vue").ComputedRef<boolean>;
|
|
5
|
+
isProxyMode: boolean;
|
|
6
|
+
canSeeAdmin: import("vue").ComputedRef<boolean>;
|
|
7
|
+
canSeeManagement: import("vue").ComputedRef<boolean>;
|
|
5
8
|
notAllowedPath: string;
|
|
6
9
|
logoutRedirectPath: string;
|
|
7
10
|
logoutPath: string;
|
|
@@ -2,6 +2,7 @@ import { useRuntimeConfig } from "#app";
|
|
|
2
2
|
import { minimatch } from "minimatch";
|
|
3
3
|
import { useMongocampAuth, useMongocampStorage } from "#imports";
|
|
4
4
|
import { computed } from "vue";
|
|
5
|
+
import { useMongocampProxyMode } from "./useMongocampProxyMode.js";
|
|
5
6
|
export function useMongocampRoles() {
|
|
6
7
|
const config = useRuntimeConfig();
|
|
7
8
|
const { isLoggedIn } = useMongocampAuth();
|
|
@@ -20,6 +21,9 @@ export function useMongocampRoles() {
|
|
|
20
21
|
return allowedRoles.some((role) => roles.value.includes(role));
|
|
21
22
|
}
|
|
22
23
|
const isManager = computed(() => isAdmin.value || matchesAnyRole(managerRoles));
|
|
24
|
+
const isProxyMode = useMongocampProxyMode();
|
|
25
|
+
const canSeeAdmin = computed(() => isProxyMode || isAdmin.value);
|
|
26
|
+
const canSeeManagement = computed(() => isProxyMode || isManager.value);
|
|
23
27
|
function matchesAnyPattern(route, patterns) {
|
|
24
28
|
return patterns.some((pattern) => minimatch(route, pattern) || minimatch(`${route}/`, pattern));
|
|
25
29
|
}
|
|
@@ -36,5 +40,5 @@ export function useMongocampRoles() {
|
|
|
36
40
|
}
|
|
37
41
|
return true;
|
|
38
42
|
}
|
|
39
|
-
return { isLoggedIn, isAdmin, isManager, notAllowedPath, logoutRedirectPath, logoutPath, loginPath, isAllowedPathForRoute };
|
|
43
|
+
return { isLoggedIn, isAdmin, isManager, isProxyMode, canSeeAdmin, canSeeManagement, notAllowedPath, logoutRedirectPath, logoutPath, loginPath, isAllowedPathForRoute };
|
|
40
44
|
}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { useRuntimeConfig } from "#app";
|
|
2
1
|
import { useMongocampAuth, useMongocampClientApi, useMongocampStorage } from "#imports";
|
|
3
2
|
import { tokenExpiryState } from "../utils/jwtExpiry.js";
|
|
3
|
+
import { useMongocampProxyMode } from "./useMongocampProxyMode.js";
|
|
4
4
|
const VERIFY_TIMEOUT_MS = 15e3;
|
|
5
5
|
export function useMongocampSession() {
|
|
6
|
-
const config = useRuntimeConfig();
|
|
7
6
|
const { logout } = useMongocampAuth();
|
|
8
7
|
const storage = useMongocampStorage();
|
|
9
8
|
const { authApi } = useMongocampClientApi();
|
|
10
|
-
const isProxyMode =
|
|
9
|
+
const isProxyMode = useMongocampProxyMode();
|
|
11
10
|
function checkExpiry() {
|
|
12
11
|
if (isProxyMode) return "unknown";
|
|
13
12
|
const token = storage.value?.token;
|
|
@@ -1072,6 +1072,48 @@
|
|
|
1072
1072
|
"ariaDescription": "{count} Werte der angezeigten Ergebnisseite",
|
|
1073
1073
|
"cut": "Nur die ersten {max} Zeilen dieser Seite werden dargestellt.",
|
|
1074
1074
|
"skipped": "{count} Zeilen ohne Zahl wurden ausgelassen."
|
|
1075
|
+
},
|
|
1076
|
+
"navigation": {
|
|
1077
|
+
"home": "Start",
|
|
1078
|
+
"account": "Konto",
|
|
1079
|
+
"collections": "Collections",
|
|
1080
|
+
"buckets": "Buckets",
|
|
1081
|
+
"databases": "Datenbanken",
|
|
1082
|
+
"jobs": "Jobs",
|
|
1083
|
+
"users": "Benutzer",
|
|
1084
|
+
"roles": "Rollen",
|
|
1085
|
+
"permissions": "Berechtigungen",
|
|
1086
|
+
"overview": "Übersicht",
|
|
1087
|
+
"server": "Server",
|
|
1088
|
+
"settings": "Einstellungen",
|
|
1089
|
+
"data": "Daten",
|
|
1090
|
+
"aggregate": "Aggregation",
|
|
1091
|
+
"groupData": "Daten",
|
|
1092
|
+
"groupAccess": "Zugriff",
|
|
1093
|
+
"groupServer": "Server"
|
|
1094
|
+
},
|
|
1095
|
+
"serverStatus": {
|
|
1096
|
+
"ok": "Server erreichbar",
|
|
1097
|
+
"partial": "Server erreichbar, einige Angaben fehlen",
|
|
1098
|
+
"down": "Server nicht erreichbar",
|
|
1099
|
+
"connections": "Verbindungen",
|
|
1100
|
+
"uptime": "Läuft seit {time}",
|
|
1101
|
+
"details": "Details zum Serverstatus"
|
|
1102
|
+
},
|
|
1103
|
+
"userAccess": {
|
|
1104
|
+
"heading": "Ihr Zugriff",
|
|
1105
|
+
"collections": "Collections",
|
|
1106
|
+
"canRead": "Lesbar",
|
|
1107
|
+
"canWrite": "Schreibbar",
|
|
1108
|
+
"canAdministrate": "Verwaltbar",
|
|
1109
|
+
"collection": "Collection",
|
|
1110
|
+
"read": "Lesen",
|
|
1111
|
+
"write": "Schreiben",
|
|
1112
|
+
"administrate": "Verwalten",
|
|
1113
|
+
"emptyTitle": "Noch keine Collections",
|
|
1114
|
+
"emptyDescription": "Ihnen wurde noch keine Collection freigegeben. Bitten Sie einen Administrator um Zugriff.",
|
|
1115
|
+
"adminTitle": "Sie sind Administrator",
|
|
1116
|
+
"adminDescription": "Administratoren dürfen jede Collection lesen, schreiben und verwalten."
|
|
1075
1117
|
}
|
|
1076
1118
|
}
|
|
1077
1119
|
}
|
|
@@ -1072,6 +1072,48 @@
|
|
|
1072
1072
|
"ariaDescription": "{count} values from the shown page of the result",
|
|
1073
1073
|
"cut": "Only the first {max} rows of this page are charted.",
|
|
1074
1074
|
"skipped": "{count} rows without a number were left out."
|
|
1075
|
+
},
|
|
1076
|
+
"navigation": {
|
|
1077
|
+
"home": "Home",
|
|
1078
|
+
"account": "Account",
|
|
1079
|
+
"collections": "Collections",
|
|
1080
|
+
"buckets": "Buckets",
|
|
1081
|
+
"databases": "Databases",
|
|
1082
|
+
"jobs": "Jobs",
|
|
1083
|
+
"users": "Users",
|
|
1084
|
+
"roles": "Roles",
|
|
1085
|
+
"permissions": "Permissions",
|
|
1086
|
+
"overview": "Overview",
|
|
1087
|
+
"server": "Server",
|
|
1088
|
+
"settings": "Settings",
|
|
1089
|
+
"data": "Data",
|
|
1090
|
+
"aggregate": "Aggregate",
|
|
1091
|
+
"groupData": "Data",
|
|
1092
|
+
"groupAccess": "Access",
|
|
1093
|
+
"groupServer": "Server"
|
|
1094
|
+
},
|
|
1095
|
+
"serverStatus": {
|
|
1096
|
+
"ok": "Server reachable",
|
|
1097
|
+
"partial": "Server reachable, some details unavailable",
|
|
1098
|
+
"down": "Server not reachable",
|
|
1099
|
+
"connections": "Connections",
|
|
1100
|
+
"uptime": "Up {time}",
|
|
1101
|
+
"details": "Server status details"
|
|
1102
|
+
},
|
|
1103
|
+
"userAccess": {
|
|
1104
|
+
"heading": "Your access",
|
|
1105
|
+
"collections": "Collections",
|
|
1106
|
+
"canRead": "Can read",
|
|
1107
|
+
"canWrite": "Can write",
|
|
1108
|
+
"canAdministrate": "Can administrate",
|
|
1109
|
+
"collection": "Collection",
|
|
1110
|
+
"read": "Read",
|
|
1111
|
+
"write": "Write",
|
|
1112
|
+
"administrate": "Administrate",
|
|
1113
|
+
"emptyTitle": "No collections yet",
|
|
1114
|
+
"emptyDescription": "No collection has been granted to you. Ask an administrator for access.",
|
|
1115
|
+
"adminTitle": "You are an administrator",
|
|
1116
|
+
"adminDescription": "Administrators may read, write and administrate every collection."
|
|
1075
1117
|
}
|
|
1076
1118
|
}
|
|
1077
1119
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { formatBytes } from './utils/formatBytes.js';
|
|
2
|
+
export { connectionUsage, formatCount, formatUptime } from './utils/serverInfo.js';
|
|
3
|
+
export { groupCollectionNames } from './utils/collectionNames.js';
|
|
4
|
+
export { bucketNameOf, isBucketMemberCollection, isProtectedCollection } from './utils/collectionProtection.js';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { formatBytes } from "./utils/formatBytes.js";
|
|
2
|
+
export { connectionUsage, formatCount, formatUptime } from "./utils/serverInfo.js";
|
|
3
|
+
export { groupCollectionNames } from "./utils/collectionNames.js";
|
|
4
|
+
export { bucketNameOf, isBucketMemberCollection, isProtectedCollection } from "./utils/collectionProtection.js";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface CollectionNameGroups {
|
|
2
|
+
/** Ordinary collections: not MongoCamp's own, not half of a GridFS bucket. */
|
|
3
|
+
collections: string[];
|
|
4
|
+
/** GridFS bucket names (`images` for `images.files` / `images.chunks`), each once. */
|
|
5
|
+
buckets: string[];
|
|
6
|
+
/** MongoCamp's own `mc_*` collections. */
|
|
7
|
+
system: string[];
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Splits a collection list the way every navigation shows it. Each group is sorted and free of duplicates; a `mc_*` name is
|
|
11
|
+
* always `system`, also when it looks like a bucket half. A bucket is listed when either of its halves is present.
|
|
12
|
+
*/
|
|
13
|
+
export declare function groupCollectionNames(names: readonly string[]): CollectionNameGroups;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { bucketNameOf, isBucketMemberCollection } from "./collectionProtection.js";
|
|
2
|
+
export function groupCollectionNames(names) {
|
|
3
|
+
const collections = /* @__PURE__ */ new Set();
|
|
4
|
+
const buckets = /* @__PURE__ */ new Set();
|
|
5
|
+
const system = /* @__PURE__ */ new Set();
|
|
6
|
+
for (const name of names) {
|
|
7
|
+
if (typeof name !== "string" || !name) continue;
|
|
8
|
+
if (name.startsWith("mc_")) system.add(name);
|
|
9
|
+
else if (isBucketMemberCollection(name)) buckets.add(bucketNameOf(name));
|
|
10
|
+
else collections.add(name);
|
|
11
|
+
}
|
|
12
|
+
const sorted = (set) => [...set].sort((a, b) => a.localeCompare(b));
|
|
13
|
+
return { collections: sorted(collections), buckets: sorted(buckets), system: sorted(system) };
|
|
14
|
+
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export declare const BUCKET_COLLECTION_SUFFIX: RegExp;
|
|
2
2
|
export declare function isBucketMemberCollection(collectionName: string): boolean;
|
|
3
|
+
/** `fs` for `fs.files` / `fs.chunks`; `null` for a collection that is not half of a GridFS bucket. */
|
|
4
|
+
export declare function bucketNameOf(collectionName: string): string | null;
|
|
3
5
|
export declare function isProtectedCollection(collectionName: string): boolean;
|