@sfxcode/nuxt-ui-mongocamp 1.5.2 → 1.5.4
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 +4 -1
- package/dist/runtime/components/MongocampCollectionData.vue +21 -9
- package/dist/runtime/components/MongocampCollectionData.vue.d.ts +4 -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 +10 -3
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { computed, onMounted, ref, resolveComponent, watch } from "vue";
|
|
3
|
+
import { useI18n, useMongocampAdminGate, useMongocampAutoRefresh, useMongocampPaths, useMongocampProxyMode, useMongocampRoles, useMongocampStorage, useMongocampSystem } from "#imports";
|
|
4
|
+
import { useNuxtApp } from "#app";
|
|
5
|
+
import { connectionUsage, formatCount, formatUptime } from "../utils/serverInfo";
|
|
6
|
+
import { outcomeOfError, serverHealth } from "../utils/serverStatus";
|
|
7
|
+
const props = defineProps({
|
|
8
|
+
collapsed: { type: Boolean, required: false, default: false },
|
|
9
|
+
autoRefresh: { type: Number, required: false, default: 30 },
|
|
10
|
+
detailsPath: { type: String, required: false }
|
|
11
|
+
});
|
|
12
|
+
const { t } = useI18n();
|
|
13
|
+
const paths = useMongocampPaths();
|
|
14
|
+
const { $mongocampVersion } = useNuxtApp();
|
|
15
|
+
const { getStats, getServerInfo } = useMongocampSystem();
|
|
16
|
+
const { canSeeAdmin } = useMongocampRoles();
|
|
17
|
+
const { blocked } = useMongocampAdminGate();
|
|
18
|
+
const state = useMongocampStorage();
|
|
19
|
+
const isProxyMode = useMongocampProxyMode();
|
|
20
|
+
const server = computed(() => $mongocampVersion.value);
|
|
21
|
+
const mongoDbVersion = ref();
|
|
22
|
+
const connections = ref();
|
|
23
|
+
const uptimeSeconds = ref();
|
|
24
|
+
const outcome = ref({ info: "skipped", stats: "skipped" });
|
|
25
|
+
const canAskInfo = computed(() => isProxyMode || !!state.value?.profile);
|
|
26
|
+
const canAskStats = computed(() => canAskInfo.value && !blocked.value);
|
|
27
|
+
async function refresh() {
|
|
28
|
+
const [info, stats] = await Promise.allSettled([
|
|
29
|
+
canAskInfo.value ? getServerInfo() : Promise.reject(new Error("skipped")),
|
|
30
|
+
canAskStats.value ? getStats() : Promise.reject(new Error("skipped"))
|
|
31
|
+
]);
|
|
32
|
+
mongoDbVersion.value = info.status === "fulfilled" ? info.value.mongoDbVersion || void 0 : void 0;
|
|
33
|
+
const current = stats.status === "fulfilled" ? stats.value.connections?.current : void 0;
|
|
34
|
+
const available = stats.status === "fulfilled" ? stats.value.connections?.available : void 0;
|
|
35
|
+
connections.value = typeof current === "number" && typeof available === "number" ? { current, available } : void 0;
|
|
36
|
+
const uptime = stats.status === "fulfilled" ? stats.value.uptimeSeconds : void 0;
|
|
37
|
+
uptimeSeconds.value = typeof uptime === "number" ? uptime : void 0;
|
|
38
|
+
outcome.value = {
|
|
39
|
+
info: !canAskInfo.value ? "skipped" : info.status === "fulfilled" ? "ok" : outcomeOfError(info.reason),
|
|
40
|
+
stats: !canAskStats.value ? "skipped" : stats.status === "fulfilled" ? "ok" : outcomeOfError(stats.reason)
|
|
41
|
+
};
|
|
42
|
+
if (health.value === "down" && canAskInfo.value) throw info.status === "rejected" ? info.reason : new Error("server unreachable");
|
|
43
|
+
}
|
|
44
|
+
const health = computed(() => serverHealth({ ...outcome.value, hasConnections: !!connections.value, versionKnown: !!server.value }));
|
|
45
|
+
const healthLabel = computed(() => t(`nuxtUiMongocamp.serverStatus.${health.value}`));
|
|
46
|
+
const dotClass = computed(() => ({ ok: "bg-success", partial: "bg-warning", down: "bg-error" })[health.value]);
|
|
47
|
+
const usage = computed(() => connections.value ? connectionUsage(connections.value.current, connections.value.available) : null);
|
|
48
|
+
const versions = computed(() => [
|
|
49
|
+
server.value?.version ? `MongoCamp ${server.value.version}` : void 0,
|
|
50
|
+
mongoDbVersion.value ? `MongoDB ${mongoDbVersion.value}` : void 0
|
|
51
|
+
].filter((entry) => Boolean(entry)));
|
|
52
|
+
const linkTarget = computed(() => canSeeAdmin.value ? props.detailsPath ?? paths.server : "");
|
|
53
|
+
const NuxtLink = resolveComponent("NuxtLink");
|
|
54
|
+
const auto = useMongocampAutoRefresh(refresh, { intervalMs: () => props.autoRefresh * 1e3 });
|
|
55
|
+
function syncAutoRefresh() {
|
|
56
|
+
auto.stop();
|
|
57
|
+
if (props.autoRefresh > 0) auto.start();
|
|
58
|
+
}
|
|
59
|
+
const quietRefresh = () => refresh().catch(() => {
|
|
60
|
+
});
|
|
61
|
+
onMounted(() => {
|
|
62
|
+
quietRefresh();
|
|
63
|
+
syncAutoRefresh();
|
|
64
|
+
});
|
|
65
|
+
watch(() => props.autoRefresh, syncAutoRefresh);
|
|
66
|
+
watch(canAskInfo, quietRefresh);
|
|
67
|
+
defineExpose({ refresh: quietRefresh });
|
|
68
|
+
</script>
|
|
69
|
+
|
|
70
|
+
<template>
|
|
71
|
+
<UTooltip
|
|
72
|
+
v-if="collapsed"
|
|
73
|
+
:text="healthLabel"
|
|
74
|
+
>
|
|
75
|
+
<div
|
|
76
|
+
class="flex justify-center py-1.5"
|
|
77
|
+
role="status"
|
|
78
|
+
:aria-label="healthLabel"
|
|
79
|
+
data-test="server-status"
|
|
80
|
+
:data-health="health"
|
|
81
|
+
>
|
|
82
|
+
<span
|
|
83
|
+
class="size-2.5 rounded-full"
|
|
84
|
+
:class="dotClass"
|
|
85
|
+
/>
|
|
86
|
+
</div>
|
|
87
|
+
</UTooltip>
|
|
88
|
+
|
|
89
|
+
<component
|
|
90
|
+
:is="linkTarget ? NuxtLink : 'div'"
|
|
91
|
+
v-else
|
|
92
|
+
:to="linkTarget || void 0"
|
|
93
|
+
class="flex flex-col gap-1.5 rounded-md text-xs"
|
|
94
|
+
:class="linkTarget ? 'hover:bg-elevated' : ''"
|
|
95
|
+
:aria-label="linkTarget ? t('nuxtUiMongocamp.serverStatus.details') : void 0"
|
|
96
|
+
data-test="server-status"
|
|
97
|
+
:data-health="health"
|
|
98
|
+
>
|
|
99
|
+
<div
|
|
100
|
+
class="flex items-center gap-2"
|
|
101
|
+
role="status"
|
|
102
|
+
>
|
|
103
|
+
<span
|
|
104
|
+
class="size-2 shrink-0 rounded-full"
|
|
105
|
+
:class="dotClass"
|
|
106
|
+
aria-hidden="true"
|
|
107
|
+
/>
|
|
108
|
+
<span class="truncate font-medium text-highlighted">{{ health === "down" ? healthLabel : server?.name ?? healthLabel }}</span>
|
|
109
|
+
<span class="sr-only">{{ healthLabel }}</span>
|
|
110
|
+
</div>
|
|
111
|
+
|
|
112
|
+
<div
|
|
113
|
+
v-for="entry in versions"
|
|
114
|
+
:key="entry"
|
|
115
|
+
class="truncate text-muted"
|
|
116
|
+
>
|
|
117
|
+
{{ entry }}
|
|
118
|
+
</div>
|
|
119
|
+
|
|
120
|
+
<template v-if="connections && usage !== null">
|
|
121
|
+
<div class="mt-1 flex items-baseline justify-between gap-2 text-muted">
|
|
122
|
+
<span>{{ t("nuxtUiMongocamp.serverStatus.connections") }}</span>
|
|
123
|
+
<span class="tabular-nums text-default">{{ formatCount(connections.current) }}</span>
|
|
124
|
+
</div>
|
|
125
|
+
<div
|
|
126
|
+
class="h-1 overflow-hidden rounded-full bg-accented"
|
|
127
|
+
role="meter"
|
|
128
|
+
:aria-label="t('nuxtUiMongocamp.serverStatus.connections')"
|
|
129
|
+
aria-valuemin="0"
|
|
130
|
+
aria-valuemax="100"
|
|
131
|
+
:aria-valuenow="usage"
|
|
132
|
+
>
|
|
133
|
+
<div
|
|
134
|
+
class="h-full rounded-full bg-primary"
|
|
135
|
+
:style="{ width: `${Math.max(usage, 2)}%` }"
|
|
136
|
+
/>
|
|
137
|
+
</div>
|
|
138
|
+
</template>
|
|
139
|
+
|
|
140
|
+
<div
|
|
141
|
+
v-if="uptimeSeconds !== void 0"
|
|
142
|
+
class="text-dimmed"
|
|
143
|
+
>
|
|
144
|
+
{{ t("nuxtUiMongocamp.serverStatus.uptime", { time: formatUptime(uptimeSeconds) }) }}
|
|
145
|
+
</div>
|
|
146
|
+
</component>
|
|
147
|
+
</template>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
type __VLS_Props = {
|
|
2
|
+
collapsed?: boolean;
|
|
3
|
+
autoRefresh?: number;
|
|
4
|
+
detailsPath?: string;
|
|
5
|
+
};
|
|
6
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {
|
|
7
|
+
refresh: () => Promise<void>;
|
|
8
|
+
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
|
|
9
|
+
collapsed: boolean;
|
|
10
|
+
autoRefresh: number;
|
|
11
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
12
|
+
declare const _default: typeof __VLS_export;
|
|
13
|
+
export default _default;
|
|
@@ -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
|
}
|