@sfxcode/nuxt-ui-mongocamp 1.3.1 → 1.3.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/README.md +1 -1
- package/dist/module.d.mts +12 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +18 -5
- package/dist/runtime/components/MongocampAggregationBuilder.d.vue.ts +6 -0
- package/dist/runtime/components/MongocampAggregationBuilder.vue +390 -0
- package/dist/runtime/components/MongocampAggregationBuilder.vue.d.ts +6 -0
- package/dist/runtime/components/MongocampBulkDelete.d.vue.ts +11 -1
- package/dist/runtime/components/MongocampBulkDelete.vue +1 -0
- package/dist/runtime/components/MongocampBulkDelete.vue.d.ts +11 -1
- package/dist/runtime/components/MongocampBulkEdit.d.vue.ts +29 -0
- package/dist/runtime/components/MongocampBulkEdit.vue +138 -0
- package/dist/runtime/components/MongocampBulkEdit.vue.d.ts +29 -0
- package/dist/runtime/components/MongocampCollectionData.d.vue.ts +4 -1
- package/dist/runtime/components/MongocampCollectionData.vue +167 -4
- package/dist/runtime/components/MongocampCollectionData.vue.d.ts +4 -1
- package/dist/runtime/components/MongocampCollectionInfos.vue +266 -8
- package/dist/runtime/components/MongocampCollections.d.vue.ts +8 -1
- package/dist/runtime/components/MongocampCollections.vue +84 -72
- package/dist/runtime/components/MongocampCollections.vue.d.ts +8 -1
- package/dist/runtime/components/MongocampConfirmByName.d.vue.ts +23 -0
- package/dist/runtime/components/MongocampConfirmByName.vue +92 -0
- package/dist/runtime/components/MongocampConfirmByName.vue.d.ts +23 -0
- package/dist/runtime/components/MongocampErrorAlert.vue +28 -5
- package/dist/runtime/components/MongocampFilterBuilder.d.vue.ts +1 -0
- package/dist/runtime/components/MongocampFilterBuilder.vue +33 -2
- package/dist/runtime/components/MongocampFilterBuilder.vue.d.ts +1 -0
- package/dist/runtime/components/MongocampGrantList.d.vue.ts +7 -0
- package/dist/runtime/components/MongocampGrantList.vue +38 -0
- package/dist/runtime/components/MongocampGrantList.vue.d.ts +7 -0
- package/dist/runtime/components/MongocampImport.d.vue.ts +10 -0
- package/dist/runtime/components/MongocampImport.vue +479 -0
- package/dist/runtime/components/MongocampImport.vue.d.ts +10 -0
- package/dist/runtime/components/MongocampRoles.vue +45 -0
- package/dist/runtime/components/MongocampSettings.d.vue.ts +3 -0
- package/dist/runtime/components/MongocampSettings.vue +179 -0
- package/dist/runtime/components/MongocampSettings.vue.d.ts +3 -0
- package/dist/runtime/components/MongocampUsers.vue +183 -3
- package/dist/runtime/composables/useMongocampAdmin.d.ts +7 -1
- package/dist/runtime/composables/useMongocampAdmin.js +24 -1
- package/dist/runtime/composables/useMongocampAggregation.d.ts +28 -0
- package/dist/runtime/composables/useMongocampAggregation.js +100 -0
- package/dist/runtime/composables/useMongocampBucket.js +1 -1
- package/dist/runtime/composables/useMongocampBulkDelete.d.ts +1 -1
- package/dist/runtime/composables/useMongocampImport.d.ts +14 -0
- package/dist/runtime/composables/useMongocampImport.js +25 -0
- package/dist/runtime/composables/useMongocampIndex.d.ts +1 -0
- package/dist/runtime/composables/useMongocampIndex.js +8 -1
- package/dist/runtime/composables/useMongocampRoles.d.ts +1 -0
- package/dist/runtime/composables/useMongocampRoles.js +3 -2
- package/dist/runtime/composables/useMongocampSession.d.ts +8 -0
- package/dist/runtime/composables/useMongocampSession.js +45 -0
- package/dist/runtime/composables/useMongocampSystem.d.ts +15 -3
- package/dist/runtime/composables/useMongocampSystem.js +19 -2
- package/dist/runtime/locales/de.json +200 -3
- package/dist/runtime/locales/en.json +200 -3
- package/dist/runtime/plugin.js +19 -0
- package/dist/runtime/utils/aggregationErrors.d.ts +10 -0
- package/dist/runtime/utils/aggregationErrors.js +17 -0
- package/dist/runtime/utils/aggregationPipeline.d.ts +42 -0
- package/dist/runtime/utils/aggregationPipeline.js +118 -0
- package/dist/runtime/utils/aggregationResult.d.ts +5 -0
- package/dist/runtime/utils/aggregationResult.js +17 -0
- package/dist/runtime/utils/analyzeSamples.d.ts +27 -0
- package/dist/runtime/utils/analyzeSamples.js +92 -0
- package/dist/runtime/utils/batchInsert.d.ts +22 -0
- package/dist/runtime/utils/batchInsert.js +24 -0
- package/dist/runtime/utils/bulkDelete.d.ts +6 -1
- package/dist/runtime/utils/bulkDelete.js +28 -4
- package/dist/runtime/utils/bulkEdit.d.ts +27 -0
- package/dist/runtime/utils/bulkEdit.js +45 -0
- package/dist/runtime/utils/collectionProtection.d.ts +3 -0
- package/dist/runtime/utils/collectionProtection.js +7 -0
- package/dist/runtime/utils/configRows.d.ts +11 -0
- package/dist/runtime/utils/configRows.js +53 -0
- package/dist/runtime/utils/failureKind.d.ts +3 -0
- package/dist/runtime/utils/failureKind.js +11 -0
- package/dist/runtime/utils/filterSuggestions.d.ts +8 -0
- package/dist/runtime/utils/filterSuggestions.js +15 -0
- package/dist/runtime/utils/importPipeline.d.ts +21 -0
- package/dist/runtime/utils/importPipeline.js +52 -0
- package/dist/runtime/utils/importRows.d.ts +36 -0
- package/dist/runtime/utils/importRows.js +228 -0
- package/dist/runtime/utils/jwtExpiry.d.ts +3 -0
- package/dist/runtime/utils/jwtExpiry.js +31 -0
- package/dist/runtime/utils/objectId.d.ts +1 -0
- package/dist/runtime/utils/objectId.js +4 -0
- package/dist/runtime/utils/serverProbe.d.ts +10 -0
- package/dist/runtime/utils/serverProbe.js +25 -0
- package/dist/runtime/utils/sessionGuard.d.ts +10 -0
- package/dist/runtime/utils/sessionGuard.js +10 -0
- package/dist/runtime/utils/throttled.d.ts +6 -0
- package/dist/runtime/utils/throttled.js +16 -0
- package/package.json +1 -1
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
<script setup>
|
|
2
2
|
import { computed, h, reactive, ref, resolveComponent, watch } from "vue";
|
|
3
3
|
import { useI18n, useMongocampClientApi, useMongocampIndex, useMongocampSchema, useToast } from "#imports";
|
|
4
|
+
import { useMongocampAggregation } from "../composables/useMongocampAggregation";
|
|
5
|
+
import useMongocampAdmin from "../composables/useMongocampAdmin";
|
|
6
|
+
import { analyzeSamples } from "../utils/analyzeSamples";
|
|
7
|
+
import { downloadTextFile } from "../utils/exportRows";
|
|
4
8
|
const props = defineProps({
|
|
5
9
|
collectionName: { type: String, required: true },
|
|
6
10
|
sampleSize: { type: Number, required: false, default: 500 }
|
|
@@ -9,6 +13,8 @@ const { t } = useI18n();
|
|
|
9
13
|
const { collectionApi, documentApi } = useMongocampClientApi();
|
|
10
14
|
const { schemaFromSamples, schemaToTsInterface } = useMongocampSchema();
|
|
11
15
|
const { listIndexes, createIndex, createUniqueIndex, createTextIndex, createExpiringIndex, deleteIndex } = useMongocampIndex();
|
|
16
|
+
const { sampleDocuments, describeAggregationError } = useMongocampAggregation();
|
|
17
|
+
const { getJsonSchema } = useMongocampAdmin();
|
|
12
18
|
const UBadge = resolveComponent("UBadge");
|
|
13
19
|
const UIcon = resolveComponent("UIcon");
|
|
14
20
|
const UButton = resolveComponent("UButton");
|
|
@@ -64,6 +70,44 @@ async function copySchemaAsTs() {
|
|
|
64
70
|
await navigator.clipboard.writeText(tsInterface.value);
|
|
65
71
|
toast.add({ title: t("nuxtUiMongocamp.collectionInfos.copiedTitle"), description: t("nuxtUiMongocamp.collectionInfos.copiedDescription"), color: "success" });
|
|
66
72
|
}
|
|
73
|
+
const isSchemaOpen = ref(false);
|
|
74
|
+
const schemaJson = ref("");
|
|
75
|
+
const schemaLoading = ref(false);
|
|
76
|
+
const schemaError = ref(null);
|
|
77
|
+
let schemaRun = 0;
|
|
78
|
+
async function loadJsonSchema() {
|
|
79
|
+
const run = ++schemaRun;
|
|
80
|
+
schemaLoading.value = true;
|
|
81
|
+
schemaError.value = null;
|
|
82
|
+
try {
|
|
83
|
+
const schema = await getJsonSchema(props.collectionName);
|
|
84
|
+
if (run !== schemaRun) return;
|
|
85
|
+
schemaJson.value = JSON.stringify(schema, null, 2);
|
|
86
|
+
} catch (e) {
|
|
87
|
+
if (run !== schemaRun) return;
|
|
88
|
+
schemaError.value = e;
|
|
89
|
+
} finally {
|
|
90
|
+
if (run === schemaRun) schemaLoading.value = false;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function openJsonSchema() {
|
|
94
|
+
isSchemaOpen.value = true;
|
|
95
|
+
if (!schemaJson.value) loadJsonSchema();
|
|
96
|
+
}
|
|
97
|
+
async function copyJsonSchema() {
|
|
98
|
+
await navigator.clipboard.writeText(schemaJson.value);
|
|
99
|
+
toast.add({ title: t("nuxtUiMongocamp.collectionInfos.copiedTitle"), description: t("nuxtUiMongocamp.collectionInfos.schemaCopiedDescription"), color: "success" });
|
|
100
|
+
}
|
|
101
|
+
function downloadJsonSchema() {
|
|
102
|
+
downloadTextFile(`${props.collectionName}.schema.json`, schemaJson.value, "application/json");
|
|
103
|
+
}
|
|
104
|
+
watch(() => props.collectionName, () => {
|
|
105
|
+
schemaRun++;
|
|
106
|
+
schemaJson.value = "";
|
|
107
|
+
schemaError.value = null;
|
|
108
|
+
schemaLoading.value = false;
|
|
109
|
+
isSchemaOpen.value = false;
|
|
110
|
+
});
|
|
67
111
|
const schemaTableColumns = computed(() => [
|
|
68
112
|
{
|
|
69
113
|
accessorKey: "field",
|
|
@@ -84,6 +128,76 @@ const schemaTableColumns = computed(() => [
|
|
|
84
128
|
cell: ({ row }) => row.original.required ? h(UIcon, { name: "i-lucide-check", class: "size-4 text-success" }) : h("span", { class: "text-dimmed" }, "\u2014")
|
|
85
129
|
}
|
|
86
130
|
]);
|
|
131
|
+
const STATS_SAMPLE_SIZES = [100, 500, 1e3];
|
|
132
|
+
const KIND_COLORS = {
|
|
133
|
+
string: "neutral",
|
|
134
|
+
number: "warning",
|
|
135
|
+
boolean: "success",
|
|
136
|
+
date: "info",
|
|
137
|
+
object: "secondary",
|
|
138
|
+
array: "primary",
|
|
139
|
+
null: "neutral"
|
|
140
|
+
};
|
|
141
|
+
const statsSampleSize = ref(500);
|
|
142
|
+
const statsLoading = ref(false);
|
|
143
|
+
const statsError = ref(null);
|
|
144
|
+
const statsAnalysis = ref(null);
|
|
145
|
+
let statsRun = 0;
|
|
146
|
+
async function analyzeFields() {
|
|
147
|
+
const run = ++statsRun;
|
|
148
|
+
statsLoading.value = true;
|
|
149
|
+
statsError.value = null;
|
|
150
|
+
try {
|
|
151
|
+
const { rows } = await sampleDocuments(props.collectionName, statsSampleSize.value);
|
|
152
|
+
if (run !== statsRun) return;
|
|
153
|
+
statsAnalysis.value = analyzeSamples(rows);
|
|
154
|
+
} catch (error) {
|
|
155
|
+
const described = await describeAggregationError(error);
|
|
156
|
+
if (run !== statsRun) return;
|
|
157
|
+
statsAnalysis.value = null;
|
|
158
|
+
statsError.value = described;
|
|
159
|
+
} finally {
|
|
160
|
+
if (run === statsRun) statsLoading.value = false;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
watch(() => props.collectionName, () => {
|
|
164
|
+
statsRun++;
|
|
165
|
+
statsAnalysis.value = null;
|
|
166
|
+
statsError.value = null;
|
|
167
|
+
statsLoading.value = false;
|
|
168
|
+
});
|
|
169
|
+
function percent(share) {
|
|
170
|
+
if (share >= 1) return "100%";
|
|
171
|
+
return share > 0 && share < 0.01 ? "<1%" : `${Math.round(share * 100)}%`;
|
|
172
|
+
}
|
|
173
|
+
const statsColumns = computed(() => [
|
|
174
|
+
{
|
|
175
|
+
accessorKey: "path",
|
|
176
|
+
header: t("nuxtUiMongocamp.collectionInfos.columnField")
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
id: "types",
|
|
180
|
+
header: t("nuxtUiMongocamp.collectionInfos.columnType"),
|
|
181
|
+
cell: ({ row }) => h("div", { class: "flex flex-wrap gap-1" }, row.original.types.map(
|
|
182
|
+
({ type, count }) => h(UBadge, {
|
|
183
|
+
label: row.original.types.length > 1 ? `${type} ${percent(count / row.original.present)}` : type,
|
|
184
|
+
color: KIND_COLORS[type] ?? "neutral",
|
|
185
|
+
variant: "subtle",
|
|
186
|
+
size: "sm"
|
|
187
|
+
})
|
|
188
|
+
))
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
id: "present",
|
|
192
|
+
header: t("nuxtUiMongocamp.collectionInfos.statsColumnPresent"),
|
|
193
|
+
cell: ({ row }) => h("span", { title: t("nuxtUiMongocamp.collectionInfos.statsPresentTitle", { present: row.original.present, sampled: statsAnalysis.value?.sampled ?? 0 }) }, percent(row.original.share))
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
id: "values",
|
|
197
|
+
header: t("nuxtUiMongocamp.collectionInfos.statsColumnValues"),
|
|
198
|
+
cell: ({ row }) => row.original.topValues ? h("span", { class: "text-xs" }, row.original.topValues.map((v) => `${v.value} (${v.count})`).join(", ")) : h("span", { class: "text-dimmed" }, "\u2014")
|
|
199
|
+
}
|
|
200
|
+
]);
|
|
87
201
|
const indexRows = computed(
|
|
88
202
|
() => indexes.value.map((idx) => ({
|
|
89
203
|
name: idx.name,
|
|
@@ -330,14 +444,24 @@ const indexTableColumns = computed(() => [
|
|
|
330
444
|
size="sm"
|
|
331
445
|
/>
|
|
332
446
|
</div>
|
|
333
|
-
<
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
447
|
+
<div class="flex items-center gap-1">
|
|
448
|
+
<UButton
|
|
449
|
+
icon="i-lucide-file-json"
|
|
450
|
+
:label="t('nuxtUiMongocamp.collectionInfos.jsonSchema')"
|
|
451
|
+
color="neutral"
|
|
452
|
+
variant="ghost"
|
|
453
|
+
size="sm"
|
|
454
|
+
@click="openJsonSchema"
|
|
455
|
+
/>
|
|
456
|
+
<UButton
|
|
457
|
+
icon="i-lucide-copy"
|
|
458
|
+
:label="t('nuxtUiMongocamp.collectionInfos.copyAsTs')"
|
|
459
|
+
color="neutral"
|
|
460
|
+
variant="ghost"
|
|
461
|
+
size="sm"
|
|
462
|
+
@click="copySchemaAsTs"
|
|
463
|
+
/>
|
|
464
|
+
</div>
|
|
341
465
|
</div>
|
|
342
466
|
</template>
|
|
343
467
|
<UTable
|
|
@@ -346,6 +470,95 @@ const indexTableColumns = computed(() => [
|
|
|
346
470
|
/>
|
|
347
471
|
</UCard>
|
|
348
472
|
|
|
473
|
+
<UCard v-if="info && !loading">
|
|
474
|
+
<template #header>
|
|
475
|
+
<div class="flex flex-wrap items-center justify-between gap-2">
|
|
476
|
+
<div class="flex items-center gap-2">
|
|
477
|
+
<UIcon
|
|
478
|
+
name="i-lucide-chart-no-axes-column"
|
|
479
|
+
class="size-4 text-(--ui-primary)"
|
|
480
|
+
/>
|
|
481
|
+
<span class="font-semibold">{{ t("nuxtUiMongocamp.collectionInfos.statsTitle") }}</span>
|
|
482
|
+
<UBadge
|
|
483
|
+
v-if="statsAnalysis"
|
|
484
|
+
:label="t('nuxtUiMongocamp.collectionInfos.statsSampled', { sampled: statsAnalysis.sampled, total: info.count })"
|
|
485
|
+
variant="subtle"
|
|
486
|
+
color="neutral"
|
|
487
|
+
size="sm"
|
|
488
|
+
/>
|
|
489
|
+
</div>
|
|
490
|
+
<div class="flex items-center gap-2">
|
|
491
|
+
<USelect
|
|
492
|
+
v-model="statsSampleSize"
|
|
493
|
+
:items="STATS_SAMPLE_SIZES"
|
|
494
|
+
size="sm"
|
|
495
|
+
class="w-24"
|
|
496
|
+
:aria-label="t('nuxtUiMongocamp.collectionInfos.statsSampleSize')"
|
|
497
|
+
/>
|
|
498
|
+
<UButton
|
|
499
|
+
icon="i-lucide-activity"
|
|
500
|
+
:label="t('nuxtUiMongocamp.collectionInfos.statsAnalyze')"
|
|
501
|
+
color="neutral"
|
|
502
|
+
variant="subtle"
|
|
503
|
+
size="sm"
|
|
504
|
+
:loading="statsLoading"
|
|
505
|
+
@click="analyzeFields"
|
|
506
|
+
/>
|
|
507
|
+
</div>
|
|
508
|
+
</div>
|
|
509
|
+
</template>
|
|
510
|
+
|
|
511
|
+
<p
|
|
512
|
+
v-if="!statsAnalysis && !statsError && !statsLoading"
|
|
513
|
+
class="text-sm text-dimmed"
|
|
514
|
+
>
|
|
515
|
+
{{ t("nuxtUiMongocamp.collectionInfos.statsHint") }}
|
|
516
|
+
</p>
|
|
517
|
+
<UAlert
|
|
518
|
+
v-if="statsError"
|
|
519
|
+
color="error"
|
|
520
|
+
variant="subtle"
|
|
521
|
+
icon="i-lucide-circle-alert"
|
|
522
|
+
:title="t('nuxtUiMongocamp.collectionInfos.statsFailed')"
|
|
523
|
+
:description="statsError.message"
|
|
524
|
+
>
|
|
525
|
+
<template #actions>
|
|
526
|
+
<UButton
|
|
527
|
+
v-if="statsError.kind === 'unauthorized'"
|
|
528
|
+
:label="t('nuxtUiMongocamp.errors.loginAgain')"
|
|
529
|
+
to="/"
|
|
530
|
+
color="error"
|
|
531
|
+
variant="subtle"
|
|
532
|
+
icon="i-lucide-log-in"
|
|
533
|
+
/>
|
|
534
|
+
<UButton
|
|
535
|
+
v-else
|
|
536
|
+
:label="t('nuxtUiMongocamp.common.retry')"
|
|
537
|
+
color="error"
|
|
538
|
+
variant="subtle"
|
|
539
|
+
icon="i-lucide-refresh-cw"
|
|
540
|
+
@click="analyzeFields"
|
|
541
|
+
/>
|
|
542
|
+
</template>
|
|
543
|
+
</UAlert>
|
|
544
|
+
<template v-if="statsAnalysis">
|
|
545
|
+
<p class="mb-2 text-xs text-dimmed">
|
|
546
|
+
{{ t("nuxtUiMongocamp.collectionInfos.statsNote") }}
|
|
547
|
+
<template v-if="statsAnalysis.truncated">
|
|
548
|
+
{{ t("nuxtUiMongocamp.collectionInfos.statsTruncated", { count: statsAnalysis.fields.length }) }}
|
|
549
|
+
</template>
|
|
550
|
+
</p>
|
|
551
|
+
<UTable
|
|
552
|
+
:data="statsAnalysis.fields"
|
|
553
|
+
:columns="statsColumns"
|
|
554
|
+
>
|
|
555
|
+
<template #empty>
|
|
556
|
+
<MongocampEmptyState :title="t('nuxtUiMongocamp.collectionInfos.statsEmpty')" />
|
|
557
|
+
</template>
|
|
558
|
+
</UTable>
|
|
559
|
+
</template>
|
|
560
|
+
</UCard>
|
|
561
|
+
|
|
349
562
|
<UModal
|
|
350
563
|
v-model:open="isCreateIndexModalOpen"
|
|
351
564
|
:title="t('nuxtUiMongocamp.collectionInfos.createIndexTitle')"
|
|
@@ -396,5 +609,50 @@ const indexTableColumns = computed(() => [
|
|
|
396
609
|
/>
|
|
397
610
|
</template>
|
|
398
611
|
</UModal>
|
|
612
|
+
|
|
613
|
+
<UModal
|
|
614
|
+
v-model:open="isSchemaOpen"
|
|
615
|
+
:title="t('nuxtUiMongocamp.collectionInfos.jsonSchemaTitle', { name: collectionName })"
|
|
616
|
+
:ui="{ content: 'sm:max-w-3xl', footer: 'justify-end' }"
|
|
617
|
+
>
|
|
618
|
+
<template #body>
|
|
619
|
+
<MongocampErrorAlert
|
|
620
|
+
:error="schemaError"
|
|
621
|
+
:title="t('nuxtUiMongocamp.collectionInfos.jsonSchemaFailedTitle')"
|
|
622
|
+
@retry="loadJsonSchema"
|
|
623
|
+
/>
|
|
624
|
+
<div
|
|
625
|
+
v-if="schemaLoading"
|
|
626
|
+
class="flex justify-center py-8"
|
|
627
|
+
>
|
|
628
|
+
<UIcon
|
|
629
|
+
name="i-lucide-loader-circle"
|
|
630
|
+
class="size-6 animate-spin text-dimmed"
|
|
631
|
+
/>
|
|
632
|
+
</div>
|
|
633
|
+
<pre
|
|
634
|
+
v-else-if="schemaJson"
|
|
635
|
+
class="max-h-[60vh] overflow-auto rounded-md bg-elevated p-3 text-xs"
|
|
636
|
+
tabindex="0"
|
|
637
|
+
:aria-label="t('nuxtUiMongocamp.collectionInfos.jsonSchema')"
|
|
638
|
+
>{{ schemaJson }}</pre>
|
|
639
|
+
</template>
|
|
640
|
+
<template #footer>
|
|
641
|
+
<UButton
|
|
642
|
+
icon="i-lucide-copy"
|
|
643
|
+
:label="t('nuxtUiMongocamp.common.copy')"
|
|
644
|
+
color="neutral"
|
|
645
|
+
variant="ghost"
|
|
646
|
+
:disabled="!schemaJson"
|
|
647
|
+
@click="copyJsonSchema"
|
|
648
|
+
/>
|
|
649
|
+
<UButton
|
|
650
|
+
icon="i-lucide-download"
|
|
651
|
+
:label="t('nuxtUiMongocamp.collectionInfos.downloadSchema')"
|
|
652
|
+
:disabled="!schemaJson"
|
|
653
|
+
@click="downloadJsonSchema"
|
|
654
|
+
/>
|
|
655
|
+
</template>
|
|
656
|
+
</UModal>
|
|
399
657
|
</div>
|
|
400
658
|
</template>
|
|
@@ -2,7 +2,14 @@ type __VLS_Props = {
|
|
|
2
2
|
infoPath?: string;
|
|
3
3
|
dataPath?: string;
|
|
4
4
|
bucketFilesPath?: string;
|
|
5
|
+
canManage?: boolean;
|
|
5
6
|
};
|
|
6
|
-
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
7
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
8
|
+
changed: () => any;
|
|
9
|
+
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
10
|
+
onChanged?: (() => any) | undefined;
|
|
11
|
+
}>, {
|
|
12
|
+
canManage: boolean;
|
|
13
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
7
14
|
declare const _default: typeof __VLS_export;
|
|
8
15
|
export default _default;
|
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
<script setup>
|
|
2
2
|
import { computed, h, ref, resolveComponent } from "vue";
|
|
3
|
-
import { useI18n, useMongocampClientApi, useMongocampBucket } from "#imports";
|
|
3
|
+
import { useI18n, useMongocampClientApi, useMongocampBucket, useMongocampRoles, useToast } from "#imports";
|
|
4
|
+
import useMongocampAdmin from "../composables/useMongocampAdmin";
|
|
5
|
+
import { isProtectedCollection } from "../utils/collectionProtection";
|
|
4
6
|
const props = defineProps({
|
|
5
7
|
infoPath: { type: String, required: false },
|
|
6
8
|
dataPath: { type: String, required: false },
|
|
7
|
-
bucketFilesPath: { type: String, required: false }
|
|
9
|
+
bucketFilesPath: { type: String, required: false },
|
|
10
|
+
canManage: { type: Boolean, required: false, default: true }
|
|
8
11
|
});
|
|
12
|
+
const emit = defineEmits(["changed"]);
|
|
9
13
|
const { t } = useI18n();
|
|
10
14
|
const { collectionApi } = useMongocampClientApi();
|
|
11
15
|
const { isBucketCollection, bucketNameFor, bucketActionInFlight, clearBucket, deleteBucket } = useMongocampBucket();
|
|
16
|
+
const { clearCollection, deleteCollection } = useMongocampAdmin();
|
|
17
|
+
const { isAdmin } = useMongocampRoles();
|
|
18
|
+
const toast = useToast();
|
|
19
|
+
const canClearOrDrop = computed(() => props.canManage && isAdmin.value);
|
|
12
20
|
const collections = ref([]);
|
|
13
21
|
const loading = ref(false);
|
|
14
22
|
const loadError = ref(null);
|
|
@@ -44,29 +52,49 @@ function withTooltip(text, node) {
|
|
|
44
52
|
}
|
|
45
53
|
const globalFilter = ref("");
|
|
46
54
|
const sorting = ref([]);
|
|
47
|
-
const
|
|
48
|
-
const
|
|
49
|
-
function
|
|
50
|
-
|
|
51
|
-
|
|
55
|
+
const pending = ref(null);
|
|
56
|
+
const isConfirmOpen = ref(false);
|
|
57
|
+
function askToConfirm(kind, name) {
|
|
58
|
+
pending.value = { kind, name };
|
|
59
|
+
isConfirmOpen.value = true;
|
|
52
60
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
const confirmTexts = computed(() => {
|
|
62
|
+
const name = pending.value?.name ?? "";
|
|
63
|
+
switch (pending.value?.kind) {
|
|
64
|
+
case "clear":
|
|
65
|
+
return { title: t("nuxtUiMongocamp.collections.clearTitle"), description: t("nuxtUiMongocamp.collections.confirmClear", { name }), label: t("nuxtUiMongocamp.collections.clearTitle"), color: "warning", icon: "i-lucide-eraser" };
|
|
66
|
+
case "drop":
|
|
67
|
+
return { title: t("nuxtUiMongocamp.collections.dropTitle"), description: t("nuxtUiMongocamp.collections.confirmDrop", { name }), label: t("nuxtUiMongocamp.collections.dropTitle"), color: "error", icon: "i-lucide-trash-2" };
|
|
68
|
+
case "clearBucket":
|
|
69
|
+
return { title: t("nuxtUiMongocamp.collections.clearBucketTitle"), description: t("nuxtUiMongocamp.collections.confirmClearBucket", { bucketName: name }), label: t("nuxtUiMongocamp.collections.clearBucketTitle"), color: "warning", icon: "i-lucide-eraser" };
|
|
70
|
+
default:
|
|
71
|
+
return { title: t("nuxtUiMongocamp.collections.deleteBucketTitle"), description: t("nuxtUiMongocamp.collections.confirmDeleteBucket", { bucketName: name }), label: t("nuxtUiMongocamp.collections.deleteBucketTitle"), color: "error", icon: "i-lucide-trash-2" };
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
async function runBucketAction(action, bucketName) {
|
|
75
|
+
if (!await action(bucketName)) throw new Error(t("nuxtUiMongocamp.collections.bucketActionFailed", { bucketName }));
|
|
64
76
|
}
|
|
65
|
-
async function
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
77
|
+
async function runPending() {
|
|
78
|
+
const action = pending.value;
|
|
79
|
+
if (!action) return;
|
|
80
|
+
switch (action.kind) {
|
|
81
|
+
case "clear":
|
|
82
|
+
await clearCollection(action.name);
|
|
83
|
+
toast.add({ title: t("nuxtUiMongocamp.collections.clearedTitle"), description: t("nuxtUiMongocamp.collections.clearedDescription", { name: action.name }), color: "success" });
|
|
84
|
+
break;
|
|
85
|
+
case "drop":
|
|
86
|
+
await deleteCollection(action.name);
|
|
87
|
+
toast.add({ title: t("nuxtUiMongocamp.collections.droppedTitle"), description: t("nuxtUiMongocamp.collections.droppedDescription", { name: action.name }), color: "success" });
|
|
88
|
+
break;
|
|
89
|
+
case "clearBucket":
|
|
90
|
+
await runBucketAction(clearBucket, action.name);
|
|
91
|
+
break;
|
|
92
|
+
case "deleteBucket":
|
|
93
|
+
await runBucketAction(deleteBucket, action.name);
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
await fetchCollections();
|
|
97
|
+
emit("changed");
|
|
70
98
|
}
|
|
71
99
|
function sortHeader(column, label) {
|
|
72
100
|
const isSorted = column.getIsSorted();
|
|
@@ -140,7 +168,7 @@ const columns = computed(() => [
|
|
|
140
168
|
"size": "sm",
|
|
141
169
|
"aria-label": t("nuxtUiMongocamp.collections.clearBucketTooltip"),
|
|
142
170
|
"loading": bucketActionInFlight.value.has(bucketName),
|
|
143
|
-
"onClick": () =>
|
|
171
|
+
"onClick": () => askToConfirm("clearBucket", bucketName)
|
|
144
172
|
})),
|
|
145
173
|
withTooltip(t("nuxtUiMongocamp.collections.deleteBucketTooltip"), h(UButton, {
|
|
146
174
|
"icon": "i-lucide-trash-2",
|
|
@@ -149,7 +177,27 @@ const columns = computed(() => [
|
|
|
149
177
|
"size": "sm",
|
|
150
178
|
"aria-label": t("nuxtUiMongocamp.collections.deleteBucketTooltip"),
|
|
151
179
|
"loading": bucketActionInFlight.value.has(bucketName),
|
|
152
|
-
"onClick": () =>
|
|
180
|
+
"onClick": () => askToConfirm("deleteBucket", bucketName)
|
|
181
|
+
}))
|
|
182
|
+
);
|
|
183
|
+
} else if (canClearOrDrop.value && !isProtectedCollection(row.original.name)) {
|
|
184
|
+
const name = row.original.name;
|
|
185
|
+
buttons.push(
|
|
186
|
+
withTooltip(t("nuxtUiMongocamp.collections.clearTooltip"), h(UButton, {
|
|
187
|
+
"icon": "i-lucide-eraser",
|
|
188
|
+
"color": "warning",
|
|
189
|
+
"variant": "ghost",
|
|
190
|
+
"size": "sm",
|
|
191
|
+
"aria-label": t("nuxtUiMongocamp.collections.clearTooltip"),
|
|
192
|
+
"onClick": () => askToConfirm("clear", name)
|
|
193
|
+
})),
|
|
194
|
+
withTooltip(t("nuxtUiMongocamp.collections.dropTooltip"), h(UButton, {
|
|
195
|
+
"icon": "i-lucide-trash-2",
|
|
196
|
+
"color": "error",
|
|
197
|
+
"variant": "ghost",
|
|
198
|
+
"size": "sm",
|
|
199
|
+
"aria-label": t("nuxtUiMongocamp.collections.dropTooltip"),
|
|
200
|
+
"onClick": () => askToConfirm("drop", name)
|
|
153
201
|
}))
|
|
154
202
|
);
|
|
155
203
|
}
|
|
@@ -204,52 +252,16 @@ fetchCollections();
|
|
|
204
252
|
</template>
|
|
205
253
|
</UTable>
|
|
206
254
|
|
|
207
|
-
<
|
|
208
|
-
v-
|
|
209
|
-
:
|
|
210
|
-
:
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
color="neutral"
|
|
219
|
-
variant="ghost"
|
|
220
|
-
@click="isClearBucketModalOpen = false"
|
|
221
|
-
/>
|
|
222
|
-
<UButton
|
|
223
|
-
:label="t('nuxtUiMongocamp.collections.clearBucketTitle')"
|
|
224
|
-
color="warning"
|
|
225
|
-
icon="i-lucide-eraser"
|
|
226
|
-
@click="handleClearBucket"
|
|
227
|
-
/>
|
|
228
|
-
</template>
|
|
229
|
-
</UModal>
|
|
230
|
-
|
|
231
|
-
<UModal
|
|
232
|
-
v-model:open="isDeleteBucketModalOpen"
|
|
233
|
-
:title="t('nuxtUiMongocamp.collections.deleteBucketTitle')"
|
|
234
|
-
:ui="{ footer: 'justify-end' }"
|
|
235
|
-
>
|
|
236
|
-
<template #body>
|
|
237
|
-
<p>{{ t("nuxtUiMongocamp.collections.confirmDeleteBucket", { bucketName: bucketToDelete }) }}</p>
|
|
238
|
-
</template>
|
|
239
|
-
<template #footer>
|
|
240
|
-
<UButton
|
|
241
|
-
:label="t('nuxtUiMongocamp.common.cancel')"
|
|
242
|
-
color="neutral"
|
|
243
|
-
variant="ghost"
|
|
244
|
-
@click="isDeleteBucketModalOpen = false"
|
|
245
|
-
/>
|
|
246
|
-
<UButton
|
|
247
|
-
:label="t('nuxtUiMongocamp.collections.deleteBucketTitle')"
|
|
248
|
-
color="error"
|
|
249
|
-
icon="i-lucide-trash-2"
|
|
250
|
-
@click="handleDeleteBucket"
|
|
251
|
-
/>
|
|
252
|
-
</template>
|
|
253
|
-
</UModal>
|
|
255
|
+
<MongocampConfirmByName
|
|
256
|
+
v-if="pending"
|
|
257
|
+
v-model:open="isConfirmOpen"
|
|
258
|
+
:name="pending.name"
|
|
259
|
+
:title="confirmTexts.title"
|
|
260
|
+
:description="confirmTexts.description"
|
|
261
|
+
:confirm-label="confirmTexts.label"
|
|
262
|
+
:confirm-color="confirmTexts.color"
|
|
263
|
+
:confirm-icon="confirmTexts.icon"
|
|
264
|
+
:on-confirm="runPending"
|
|
265
|
+
/>
|
|
254
266
|
</div>
|
|
255
267
|
</template>
|
|
@@ -2,7 +2,14 @@ type __VLS_Props = {
|
|
|
2
2
|
infoPath?: string;
|
|
3
3
|
dataPath?: string;
|
|
4
4
|
bucketFilesPath?: string;
|
|
5
|
+
canManage?: boolean;
|
|
5
6
|
};
|
|
6
|
-
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
7
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
8
|
+
changed: () => any;
|
|
9
|
+
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
10
|
+
onChanged?: (() => any) | undefined;
|
|
11
|
+
}>, {
|
|
12
|
+
canManage: boolean;
|
|
13
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
7
14
|
declare const _default: typeof __VLS_export;
|
|
8
15
|
export default _default;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
type __VLS_Props = {
|
|
2
|
+
name: string;
|
|
3
|
+
title: string;
|
|
4
|
+
description: string;
|
|
5
|
+
confirmLabel: string;
|
|
6
|
+
confirmColor?: 'error' | 'warning';
|
|
7
|
+
confirmIcon?: string;
|
|
8
|
+
onConfirm: () => Promise<void>;
|
|
9
|
+
};
|
|
10
|
+
type __VLS_ModelProps = {
|
|
11
|
+
'open'?: boolean;
|
|
12
|
+
};
|
|
13
|
+
type __VLS_PublicProps = __VLS_Props & __VLS_ModelProps;
|
|
14
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_PublicProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
15
|
+
"update:open": (value: boolean) => any;
|
|
16
|
+
}, string, import("vue").PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
|
|
17
|
+
"onUpdate:open"?: ((value: boolean) => any) | undefined;
|
|
18
|
+
}>, {
|
|
19
|
+
confirmColor: "error" | "warning";
|
|
20
|
+
confirmIcon: string;
|
|
21
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
22
|
+
declare const _default: typeof __VLS_export;
|
|
23
|
+
export default _default;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { computed, ref, watch } from "vue";
|
|
3
|
+
import { useI18n, useMongocampError } from "#imports";
|
|
4
|
+
const props = defineProps({
|
|
5
|
+
name: { type: String, required: true },
|
|
6
|
+
title: { type: String, required: true },
|
|
7
|
+
description: { type: String, required: true },
|
|
8
|
+
confirmLabel: { type: String, required: true },
|
|
9
|
+
confirmColor: { type: String, required: false, default: "error" },
|
|
10
|
+
confirmIcon: { type: String, required: false, default: "i-lucide-trash-2" },
|
|
11
|
+
onConfirm: { type: Function, required: true }
|
|
12
|
+
});
|
|
13
|
+
const open = defineModel("open", { type: Boolean, ...{ default: false } });
|
|
14
|
+
const { t } = useI18n();
|
|
15
|
+
const { describeError } = useMongocampError();
|
|
16
|
+
const typed = ref("");
|
|
17
|
+
const busy = ref(false);
|
|
18
|
+
const error = ref("");
|
|
19
|
+
const matches = computed(() => props.name !== "" && typed.value.trim() === props.name);
|
|
20
|
+
watch(open, (isOpen) => {
|
|
21
|
+
if (!isOpen) return;
|
|
22
|
+
typed.value = "";
|
|
23
|
+
error.value = "";
|
|
24
|
+
});
|
|
25
|
+
function close() {
|
|
26
|
+
open.value = false;
|
|
27
|
+
}
|
|
28
|
+
async function handleConfirm() {
|
|
29
|
+
if (!matches.value || busy.value) return;
|
|
30
|
+
busy.value = true;
|
|
31
|
+
error.value = "";
|
|
32
|
+
try {
|
|
33
|
+
await props.onConfirm();
|
|
34
|
+
close();
|
|
35
|
+
} catch (e) {
|
|
36
|
+
error.value = describeError(e).message;
|
|
37
|
+
} finally {
|
|
38
|
+
busy.value = false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
</script>
|
|
42
|
+
|
|
43
|
+
<template>
|
|
44
|
+
<UModal
|
|
45
|
+
v-model:open="open"
|
|
46
|
+
:title="title"
|
|
47
|
+
:dismissible="!busy"
|
|
48
|
+
:ui="{ footer: 'justify-end' }"
|
|
49
|
+
>
|
|
50
|
+
<template #body>
|
|
51
|
+
<p>{{ description }}</p>
|
|
52
|
+
<UFormField
|
|
53
|
+
class="mt-4"
|
|
54
|
+
:label="t('nuxtUiMongocamp.confirmByName.prompt', { name })"
|
|
55
|
+
>
|
|
56
|
+
<UInput
|
|
57
|
+
v-model="typed"
|
|
58
|
+
class="w-full"
|
|
59
|
+
autocomplete="off"
|
|
60
|
+
:disabled="busy"
|
|
61
|
+
:aria-label="t('nuxtUiMongocamp.confirmByName.prompt', { name })"
|
|
62
|
+
@keydown.enter.prevent="handleConfirm"
|
|
63
|
+
/>
|
|
64
|
+
</UFormField>
|
|
65
|
+
<UAlert
|
|
66
|
+
v-if="error"
|
|
67
|
+
class="mt-3"
|
|
68
|
+
color="error"
|
|
69
|
+
variant="subtle"
|
|
70
|
+
icon="i-lucide-circle-alert"
|
|
71
|
+
:description="error"
|
|
72
|
+
/>
|
|
73
|
+
</template>
|
|
74
|
+
<template #footer>
|
|
75
|
+
<UButton
|
|
76
|
+
:label="t('nuxtUiMongocamp.common.cancel')"
|
|
77
|
+
color="neutral"
|
|
78
|
+
variant="ghost"
|
|
79
|
+
:disabled="busy"
|
|
80
|
+
@click="close"
|
|
81
|
+
/>
|
|
82
|
+
<UButton
|
|
83
|
+
:label="confirmLabel"
|
|
84
|
+
:color="confirmColor"
|
|
85
|
+
:icon="confirmIcon"
|
|
86
|
+
:disabled="!matches"
|
|
87
|
+
:loading="busy"
|
|
88
|
+
@click="handleConfirm"
|
|
89
|
+
/>
|
|
90
|
+
</template>
|
|
91
|
+
</UModal>
|
|
92
|
+
</template>
|