@sfxcode/nuxt-ui-mongocamp 1.3.0 → 1.3.2
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.json +1 -1
- 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.vue +100 -1
- package/dist/runtime/components/MongocampCollectionInfos.vue +162 -0
- 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/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/MongocampRoleGrants.vue +25 -0
- package/dist/runtime/components/MongocampRoles.vue +74 -0
- package/dist/runtime/composables/useMongocampAggregation.d.ts +28 -0
- package/dist/runtime/composables/useMongocampAggregation.js +99 -0
- 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/locales/de.json +147 -2
- package/dist/runtime/locales/en.json +147 -2
- 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/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/objectId.d.ts +1 -0
- package/dist/runtime/utils/objectId.js +4 -0
- package/package.json +2 -2
|
@@ -0,0 +1,479 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { computed, ref, watch } from "vue";
|
|
3
|
+
import { useI18n, useMongocampError } from "#imports";
|
|
4
|
+
import { useMongocampImport } from "../composables/useMongocampImport";
|
|
5
|
+
import { DEFAULT_IMPORT_LIMITS } from "../utils/importRows";
|
|
6
|
+
import { detectImportFormat, prepareImport } from "../utils/importPipeline";
|
|
7
|
+
const props = defineProps({
|
|
8
|
+
collectionName: { type: String, required: true }
|
|
9
|
+
});
|
|
10
|
+
const emit = defineEmits(["imported"]);
|
|
11
|
+
const PREVIEW_ROWS = 5;
|
|
12
|
+
const ERROR_LIMIT = 10;
|
|
13
|
+
const { t } = useI18n();
|
|
14
|
+
const { describeError } = useMongocampError();
|
|
15
|
+
const { importRows } = useMongocampImport();
|
|
16
|
+
const isOpen = ref(false);
|
|
17
|
+
const step = ref("select");
|
|
18
|
+
const fileInputRef = ref(null);
|
|
19
|
+
const readError = ref("");
|
|
20
|
+
const fileName = ref("");
|
|
21
|
+
const fileText = ref("");
|
|
22
|
+
const format = ref("json");
|
|
23
|
+
const delimiter = ref(",");
|
|
24
|
+
const userColumnTypes = ref(null);
|
|
25
|
+
const emptyAsText = ref(false);
|
|
26
|
+
const stampMetadata = ref(true);
|
|
27
|
+
const progress = ref({ done: 0, total: 0 });
|
|
28
|
+
const attemptRows = ref([]);
|
|
29
|
+
const attemptSources = ref([]);
|
|
30
|
+
const failures = ref([]);
|
|
31
|
+
const totalInserted = ref(0);
|
|
32
|
+
const skipped = ref(0);
|
|
33
|
+
let controller = null;
|
|
34
|
+
const prepared = computed(() => {
|
|
35
|
+
if (!fileText.value) return null;
|
|
36
|
+
return prepareImport({
|
|
37
|
+
format: format.value,
|
|
38
|
+
text: fileText.value,
|
|
39
|
+
delimiter: delimiter.value,
|
|
40
|
+
columnTypes: format.value === "csv" ? userColumnTypes.value ?? void 0 : void 0,
|
|
41
|
+
emptyCells: emptyAsText.value ? "empty-string" : "omit"
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
const columnTypes = computed(() => userColumnTypes.value ?? prepared.value?.columnTypes ?? {});
|
|
45
|
+
const formatItems = computed(() => [
|
|
46
|
+
{ label: t("nuxtUiMongocamp.import.formatJson"), value: "json" },
|
|
47
|
+
{ label: t("nuxtUiMongocamp.import.formatCsv"), value: "csv" }
|
|
48
|
+
]);
|
|
49
|
+
const delimiterItems = computed(() => [
|
|
50
|
+
{ label: t("nuxtUiMongocamp.import.delimiterComma"), value: "," },
|
|
51
|
+
{ label: t("nuxtUiMongocamp.import.delimiterSemicolon"), value: ";" },
|
|
52
|
+
{ label: t("nuxtUiMongocamp.import.delimiterTab"), value: " " }
|
|
53
|
+
]);
|
|
54
|
+
const typeItems = computed(() => [
|
|
55
|
+
{ label: t("nuxtUiMongocamp.import.typeString"), value: "string" },
|
|
56
|
+
{ label: t("nuxtUiMongocamp.import.typeNumber"), value: "number" },
|
|
57
|
+
{ label: t("nuxtUiMongocamp.import.typeBoolean"), value: "boolean" },
|
|
58
|
+
{ label: t("nuxtUiMongocamp.import.typeDate"), value: "date-time" },
|
|
59
|
+
{ label: t("nuxtUiMongocamp.import.typeJson"), value: "json" }
|
|
60
|
+
]);
|
|
61
|
+
const readyCount = computed(() => prepared.value?.rows.length ?? 0);
|
|
62
|
+
const rowErrors = computed(() => (prepared.value?.errors ?? []).filter((e) => e.rowIndex >= 0 && e.code !== "too-many-rows"));
|
|
63
|
+
const fileErrors = computed(() => (prepared.value?.errors ?? []).filter((e) => e.rowIndex < 0 && e.code !== "too-many-rows"));
|
|
64
|
+
const visibleErrors = computed(() => [...rowErrors.value].sort((a, b) => a.rowIndex - b.rowIndex).slice(0, ERROR_LIMIT));
|
|
65
|
+
const hiddenErrorCount = computed(() => Math.max(0, rowErrors.value.length - ERROR_LIMIT));
|
|
66
|
+
const previewColumns = computed(() => (prepared.value?.columns ?? []).map((column) => ({
|
|
67
|
+
id: column,
|
|
68
|
+
header: column,
|
|
69
|
+
accessorFn: (row) => row[column]
|
|
70
|
+
})));
|
|
71
|
+
const previewRows = computed(() => (prepared.value?.rows ?? []).slice(0, PREVIEW_ROWS).map((row) => {
|
|
72
|
+
const shown = {};
|
|
73
|
+
for (const [key, value] of Object.entries(row)) shown[key] = typeof value === "object" && value !== null ? JSON.stringify(value) : String(value);
|
|
74
|
+
return shown;
|
|
75
|
+
}));
|
|
76
|
+
function errorText(error) {
|
|
77
|
+
const message = t(`nuxtUiMongocamp.import.error.${error.code}`);
|
|
78
|
+
if (error.rowIndex < 0) return message;
|
|
79
|
+
const where = error.column ? t("nuxtUiMongocamp.import.errorRowColumn", { row: error.rowIndex + 1, column: error.column }) : t("nuxtUiMongocamp.import.errorRow", { row: error.rowIndex + 1 });
|
|
80
|
+
return `${where}: ${message}`;
|
|
81
|
+
}
|
|
82
|
+
function resetState() {
|
|
83
|
+
controller?.abort();
|
|
84
|
+
controller = null;
|
|
85
|
+
step.value = "select";
|
|
86
|
+
readError.value = "";
|
|
87
|
+
fileName.value = "";
|
|
88
|
+
fileText.value = "";
|
|
89
|
+
format.value = "json";
|
|
90
|
+
delimiter.value = ",";
|
|
91
|
+
userColumnTypes.value = null;
|
|
92
|
+
emptyAsText.value = false;
|
|
93
|
+
stampMetadata.value = true;
|
|
94
|
+
progress.value = { done: 0, total: 0 };
|
|
95
|
+
attemptRows.value = [];
|
|
96
|
+
attemptSources.value = [];
|
|
97
|
+
failures.value = [];
|
|
98
|
+
totalInserted.value = 0;
|
|
99
|
+
skipped.value = 0;
|
|
100
|
+
}
|
|
101
|
+
function openModal() {
|
|
102
|
+
isOpen.value = true;
|
|
103
|
+
}
|
|
104
|
+
watch(isOpen, (open) => {
|
|
105
|
+
if (!open) resetState();
|
|
106
|
+
});
|
|
107
|
+
function openFilePicker() {
|
|
108
|
+
fileInputRef.value?.click();
|
|
109
|
+
}
|
|
110
|
+
async function handleFileSelected(event) {
|
|
111
|
+
const input = event.target;
|
|
112
|
+
const file = input.files?.[0];
|
|
113
|
+
input.value = "";
|
|
114
|
+
if (!file) return;
|
|
115
|
+
readError.value = "";
|
|
116
|
+
try {
|
|
117
|
+
const text = await file.text();
|
|
118
|
+
fileName.value = file.name;
|
|
119
|
+
fileText.value = text;
|
|
120
|
+
format.value = detectImportFormat(file.name, text);
|
|
121
|
+
delimiter.value = file.name.toLowerCase().endsWith(".tsv") ? " " : ",";
|
|
122
|
+
userColumnTypes.value = null;
|
|
123
|
+
step.value = "preview";
|
|
124
|
+
} catch {
|
|
125
|
+
readError.value = t("nuxtUiMongocamp.import.readError");
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
function backToSelect() {
|
|
129
|
+
fileName.value = "";
|
|
130
|
+
fileText.value = "";
|
|
131
|
+
userColumnTypes.value = null;
|
|
132
|
+
step.value = "select";
|
|
133
|
+
}
|
|
134
|
+
function onFormatChange(value) {
|
|
135
|
+
format.value = value;
|
|
136
|
+
userColumnTypes.value = null;
|
|
137
|
+
}
|
|
138
|
+
function onDelimiterChange(value) {
|
|
139
|
+
delimiter.value = value;
|
|
140
|
+
userColumnTypes.value = null;
|
|
141
|
+
}
|
|
142
|
+
function setColumnType(column, type) {
|
|
143
|
+
userColumnTypes.value = { ...columnTypes.value, [column]: type };
|
|
144
|
+
}
|
|
145
|
+
async function failureReason(error) {
|
|
146
|
+
const response = error?.response;
|
|
147
|
+
if (response) {
|
|
148
|
+
try {
|
|
149
|
+
const body = await response.clone().json();
|
|
150
|
+
if (typeof body?.msg === "string" && body.msg) return body.msg;
|
|
151
|
+
} catch {
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return describeError(error).message;
|
|
155
|
+
}
|
|
156
|
+
async function runImport(rows, sources) {
|
|
157
|
+
attemptRows.value = rows;
|
|
158
|
+
attemptSources.value = sources;
|
|
159
|
+
progress.value = { done: 0, total: rows.length };
|
|
160
|
+
failures.value = [];
|
|
161
|
+
skipped.value = 0;
|
|
162
|
+
step.value = "importing";
|
|
163
|
+
const run = new AbortController();
|
|
164
|
+
controller = run;
|
|
165
|
+
const result = await importRows(props.collectionName, rows, {
|
|
166
|
+
signal: run.signal,
|
|
167
|
+
stampMetadata: stampMetadata.value,
|
|
168
|
+
onProgress: (p) => {
|
|
169
|
+
progress.value = p;
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
if (controller === run) controller = null;
|
|
173
|
+
if (!isOpen.value) return;
|
|
174
|
+
totalInserted.value += result.inserted;
|
|
175
|
+
skipped.value = result.skipped;
|
|
176
|
+
failures.value = await Promise.all(result.failedBatches.map(async (batch) => ({
|
|
177
|
+
start: batch.start,
|
|
178
|
+
count: batch.count,
|
|
179
|
+
from: sources[batch.start] + 1,
|
|
180
|
+
to: sources[batch.start + batch.count - 1] + 1,
|
|
181
|
+
reason: await failureReason(batch.error),
|
|
182
|
+
mayBePartial: batch.mayBePartial
|
|
183
|
+
})));
|
|
184
|
+
step.value = "done";
|
|
185
|
+
if (result.inserted > 0) emit("imported", result.inserted);
|
|
186
|
+
}
|
|
187
|
+
async function startImport() {
|
|
188
|
+
if (!prepared.value || prepared.value.rows.length === 0) return;
|
|
189
|
+
await runImport(prepared.value.rows, prepared.value.sourceIndexes);
|
|
190
|
+
}
|
|
191
|
+
async function retryFailed() {
|
|
192
|
+
const rows = [];
|
|
193
|
+
const sources = [];
|
|
194
|
+
for (const range of failures.value) {
|
|
195
|
+
rows.push(...attemptRows.value.slice(range.start, range.start + range.count));
|
|
196
|
+
sources.push(...attemptSources.value.slice(range.start, range.start + range.count));
|
|
197
|
+
}
|
|
198
|
+
if (rows.length > 0) await runImport(rows, sources);
|
|
199
|
+
}
|
|
200
|
+
function stopImport() {
|
|
201
|
+
controller?.abort();
|
|
202
|
+
}
|
|
203
|
+
const anyMayBePartial = computed(() => failures.value.some((f) => f.mayBePartial));
|
|
204
|
+
const progressPercent = computed(() => progress.value.total === 0 ? 0 : Math.round(progress.value.done / progress.value.total * 100));
|
|
205
|
+
const limitsText = computed(() => ({ maxRows: DEFAULT_IMPORT_LIMITS.maxRows, maxMb: DEFAULT_IMPORT_LIMITS.maxBytes / (1024 * 1024) }));
|
|
206
|
+
</script>
|
|
207
|
+
|
|
208
|
+
<template>
|
|
209
|
+
<UTooltip :text="t('nuxtUiMongocamp.import.trigger')">
|
|
210
|
+
<UButton
|
|
211
|
+
icon="i-lucide-file-up"
|
|
212
|
+
color="neutral"
|
|
213
|
+
variant="ghost"
|
|
214
|
+
size="sm"
|
|
215
|
+
:aria-label="t('nuxtUiMongocamp.import.trigger')"
|
|
216
|
+
@click="openModal"
|
|
217
|
+
/>
|
|
218
|
+
</UTooltip>
|
|
219
|
+
|
|
220
|
+
<UModal
|
|
221
|
+
v-model:open="isOpen"
|
|
222
|
+
:title="t('nuxtUiMongocamp.import.title')"
|
|
223
|
+
:dismissible="step !== 'importing'"
|
|
224
|
+
:ui="{ footer: 'justify-end', content: 'sm:max-w-3xl' }"
|
|
225
|
+
>
|
|
226
|
+
<template #body>
|
|
227
|
+
<div
|
|
228
|
+
v-if="step === 'select'"
|
|
229
|
+
class="flex flex-col items-start gap-3"
|
|
230
|
+
>
|
|
231
|
+
<p class="font-medium">
|
|
232
|
+
{{ t("nuxtUiMongocamp.import.chooseFile") }}
|
|
233
|
+
</p>
|
|
234
|
+
<p class="text-sm text-dimmed">
|
|
235
|
+
{{ t("nuxtUiMongocamp.import.hint", limitsText) }}
|
|
236
|
+
</p>
|
|
237
|
+
<input
|
|
238
|
+
ref="fileInputRef"
|
|
239
|
+
type="file"
|
|
240
|
+
class="hidden"
|
|
241
|
+
accept=".json,.csv,.tsv,.txt,application/json,text/csv"
|
|
242
|
+
data-testid="import-file-input"
|
|
243
|
+
@change="handleFileSelected"
|
|
244
|
+
>
|
|
245
|
+
<UButton
|
|
246
|
+
icon="i-lucide-folder-open"
|
|
247
|
+
:label="t('nuxtUiMongocamp.import.chooseButton')"
|
|
248
|
+
@click="openFilePicker"
|
|
249
|
+
/>
|
|
250
|
+
<UAlert
|
|
251
|
+
v-if="readError"
|
|
252
|
+
color="error"
|
|
253
|
+
variant="subtle"
|
|
254
|
+
icon="i-lucide-circle-alert"
|
|
255
|
+
:description="readError"
|
|
256
|
+
/>
|
|
257
|
+
</div>
|
|
258
|
+
|
|
259
|
+
<div
|
|
260
|
+
v-else-if="step === 'preview' && prepared"
|
|
261
|
+
class="flex flex-col gap-4"
|
|
262
|
+
>
|
|
263
|
+
<div class="flex flex-wrap items-end gap-3">
|
|
264
|
+
<span class="text-sm font-medium break-all">{{ fileName }}</span>
|
|
265
|
+
<USelect
|
|
266
|
+
:model-value="format"
|
|
267
|
+
:items="formatItems"
|
|
268
|
+
size="sm"
|
|
269
|
+
class="w-28"
|
|
270
|
+
:aria-label="t('nuxtUiMongocamp.import.format')"
|
|
271
|
+
@update:model-value="onFormatChange"
|
|
272
|
+
/>
|
|
273
|
+
<USelect
|
|
274
|
+
v-if="format === 'csv'"
|
|
275
|
+
:model-value="delimiter"
|
|
276
|
+
:items="delimiterItems"
|
|
277
|
+
size="sm"
|
|
278
|
+
class="w-40"
|
|
279
|
+
:aria-label="t('nuxtUiMongocamp.import.delimiter')"
|
|
280
|
+
@update:model-value="onDelimiterChange"
|
|
281
|
+
/>
|
|
282
|
+
</div>
|
|
283
|
+
|
|
284
|
+
<UAlert
|
|
285
|
+
v-for="error in fileErrors"
|
|
286
|
+
:key="error.code"
|
|
287
|
+
color="error"
|
|
288
|
+
variant="subtle"
|
|
289
|
+
icon="i-lucide-circle-alert"
|
|
290
|
+
:description="errorText(error)"
|
|
291
|
+
/>
|
|
292
|
+
|
|
293
|
+
<template v-if="fileErrors.length === 0">
|
|
294
|
+
<p class="text-sm font-medium">
|
|
295
|
+
{{ t("nuxtUiMongocamp.import.summary", { ready: readyCount, total: prepared.sourceRowCount }) }}
|
|
296
|
+
</p>
|
|
297
|
+
<UAlert
|
|
298
|
+
v-if="prepared.truncated"
|
|
299
|
+
color="warning"
|
|
300
|
+
variant="subtle"
|
|
301
|
+
icon="i-lucide-triangle-alert"
|
|
302
|
+
:description="t('nuxtUiMongocamp.import.truncated', { maxRows: limitsText.maxRows })"
|
|
303
|
+
/>
|
|
304
|
+
|
|
305
|
+
<div
|
|
306
|
+
v-if="format === 'csv' && prepared.columns.length > 0"
|
|
307
|
+
class="flex flex-col gap-2"
|
|
308
|
+
>
|
|
309
|
+
<p class="text-sm font-medium">
|
|
310
|
+
{{ t("nuxtUiMongocamp.import.columnTypes") }}
|
|
311
|
+
</p>
|
|
312
|
+
<div class="grid grid-cols-1 gap-2 sm:grid-cols-2">
|
|
313
|
+
<div
|
|
314
|
+
v-for="column in prepared.columns"
|
|
315
|
+
:key="column"
|
|
316
|
+
class="flex items-center gap-2"
|
|
317
|
+
>
|
|
318
|
+
<span class="w-32 truncate text-sm">{{ column }}</span>
|
|
319
|
+
<USelect
|
|
320
|
+
:model-value="columnTypes[column]"
|
|
321
|
+
:items="typeItems"
|
|
322
|
+
size="sm"
|
|
323
|
+
class="w-32"
|
|
324
|
+
:aria-label="column"
|
|
325
|
+
@update:model-value="setColumnType(column, $event)"
|
|
326
|
+
/>
|
|
327
|
+
</div>
|
|
328
|
+
</div>
|
|
329
|
+
<USwitch
|
|
330
|
+
v-model="emptyAsText"
|
|
331
|
+
:label="t('nuxtUiMongocamp.import.emptyAsText')"
|
|
332
|
+
/>
|
|
333
|
+
</div>
|
|
334
|
+
|
|
335
|
+
<UAlert
|
|
336
|
+
v-if="rowErrors.length > 0"
|
|
337
|
+
color="warning"
|
|
338
|
+
variant="subtle"
|
|
339
|
+
icon="i-lucide-triangle-alert"
|
|
340
|
+
:title="t('nuxtUiMongocamp.import.problems', { count: rowErrors.length }, rowErrors.length)"
|
|
341
|
+
>
|
|
342
|
+
<template #description>
|
|
343
|
+
<ul class="list-disc pl-5 text-sm">
|
|
344
|
+
<li
|
|
345
|
+
v-for="error in visibleErrors"
|
|
346
|
+
:key="`${error.rowIndex}-${error.column ?? ''}-${error.code}`"
|
|
347
|
+
>
|
|
348
|
+
{{ errorText(error) }}
|
|
349
|
+
</li>
|
|
350
|
+
</ul>
|
|
351
|
+
<p
|
|
352
|
+
v-if="hiddenErrorCount > 0"
|
|
353
|
+
class="mt-1 text-sm"
|
|
354
|
+
>
|
|
355
|
+
{{ t("nuxtUiMongocamp.import.moreErrors", { count: hiddenErrorCount }) }}
|
|
356
|
+
</p>
|
|
357
|
+
</template>
|
|
358
|
+
</UAlert>
|
|
359
|
+
|
|
360
|
+
<div v-if="previewRows.length > 0">
|
|
361
|
+
<p class="mb-1 text-sm font-medium">
|
|
362
|
+
{{ t("nuxtUiMongocamp.import.previewTitle", { count: previewRows.length }) }}
|
|
363
|
+
</p>
|
|
364
|
+
<UTable
|
|
365
|
+
:data="previewRows"
|
|
366
|
+
:columns="previewColumns"
|
|
367
|
+
class="max-h-64"
|
|
368
|
+
/>
|
|
369
|
+
</div>
|
|
370
|
+
|
|
371
|
+
<USwitch
|
|
372
|
+
v-model="stampMetadata"
|
|
373
|
+
:label="t('nuxtUiMongocamp.import.stampMetadata')"
|
|
374
|
+
/>
|
|
375
|
+
</template>
|
|
376
|
+
</div>
|
|
377
|
+
|
|
378
|
+
<div
|
|
379
|
+
v-else-if="step === 'importing'"
|
|
380
|
+
class="flex flex-col gap-3"
|
|
381
|
+
>
|
|
382
|
+
<p class="text-sm">
|
|
383
|
+
{{ t("nuxtUiMongocamp.import.importing", progress) }}
|
|
384
|
+
</p>
|
|
385
|
+
<UProgress
|
|
386
|
+
:model-value="progressPercent"
|
|
387
|
+
:aria-label="t('nuxtUiMongocamp.import.importing', progress)"
|
|
388
|
+
/>
|
|
389
|
+
</div>
|
|
390
|
+
|
|
391
|
+
<div
|
|
392
|
+
v-else-if="step === 'done'"
|
|
393
|
+
class="flex flex-col gap-3"
|
|
394
|
+
>
|
|
395
|
+
<UAlert
|
|
396
|
+
:color="totalInserted > 0 ? 'success' : 'neutral'"
|
|
397
|
+
variant="subtle"
|
|
398
|
+
:icon="totalInserted > 0 ? 'i-lucide-circle-check' : 'i-lucide-info'"
|
|
399
|
+
:title="t('nuxtUiMongocamp.import.result', { count: totalInserted }, totalInserted)"
|
|
400
|
+
/>
|
|
401
|
+
<UAlert
|
|
402
|
+
v-if="skipped > 0"
|
|
403
|
+
color="warning"
|
|
404
|
+
variant="subtle"
|
|
405
|
+
icon="i-lucide-triangle-alert"
|
|
406
|
+
:description="t('nuxtUiMongocamp.import.aborted', { count: skipped })"
|
|
407
|
+
/>
|
|
408
|
+
<UAlert
|
|
409
|
+
v-if="failures.length > 0"
|
|
410
|
+
color="error"
|
|
411
|
+
variant="subtle"
|
|
412
|
+
icon="i-lucide-circle-alert"
|
|
413
|
+
>
|
|
414
|
+
<template #description>
|
|
415
|
+
<ul class="list-disc pl-5 text-sm">
|
|
416
|
+
<li
|
|
417
|
+
v-for="failure in failures"
|
|
418
|
+
:key="failure.start"
|
|
419
|
+
>
|
|
420
|
+
{{ t("nuxtUiMongocamp.import.failedBatch", { from: failure.from, to: failure.to, reason: failure.reason }) }}
|
|
421
|
+
</li>
|
|
422
|
+
</ul>
|
|
423
|
+
<p
|
|
424
|
+
v-if="anyMayBePartial"
|
|
425
|
+
class="mt-2 text-sm"
|
|
426
|
+
>
|
|
427
|
+
{{ t("nuxtUiMongocamp.import.maybePartial") }}
|
|
428
|
+
</p>
|
|
429
|
+
</template>
|
|
430
|
+
</UAlert>
|
|
431
|
+
</div>
|
|
432
|
+
</template>
|
|
433
|
+
|
|
434
|
+
<template #footer>
|
|
435
|
+
<template v-if="step === 'preview'">
|
|
436
|
+
<UButton
|
|
437
|
+
:label="t('nuxtUiMongocamp.import.back')"
|
|
438
|
+
color="neutral"
|
|
439
|
+
variant="ghost"
|
|
440
|
+
@click="backToSelect"
|
|
441
|
+
/>
|
|
442
|
+
<UButton
|
|
443
|
+
:label="t('nuxtUiMongocamp.import.importButton', { count: readyCount }, readyCount)"
|
|
444
|
+
:disabled="readyCount === 0"
|
|
445
|
+
@click="startImport"
|
|
446
|
+
/>
|
|
447
|
+
</template>
|
|
448
|
+
<template v-else-if="step === 'importing'">
|
|
449
|
+
<UButton
|
|
450
|
+
:label="t('nuxtUiMongocamp.import.stop')"
|
|
451
|
+
color="neutral"
|
|
452
|
+
variant="subtle"
|
|
453
|
+
@click="stopImport"
|
|
454
|
+
/>
|
|
455
|
+
</template>
|
|
456
|
+
<template v-else-if="step === 'done'">
|
|
457
|
+
<UButton
|
|
458
|
+
v-if="failures.length > 0"
|
|
459
|
+
:label="t('nuxtUiMongocamp.import.retryFailed')"
|
|
460
|
+
color="neutral"
|
|
461
|
+
variant="subtle"
|
|
462
|
+
@click="retryFailed"
|
|
463
|
+
/>
|
|
464
|
+
<UButton
|
|
465
|
+
:label="t('nuxtUiMongocamp.import.close')"
|
|
466
|
+
@click="isOpen = false"
|
|
467
|
+
/>
|
|
468
|
+
</template>
|
|
469
|
+
<template v-else>
|
|
470
|
+
<UButton
|
|
471
|
+
:label="t('nuxtUiMongocamp.common.cancel')"
|
|
472
|
+
color="neutral"
|
|
473
|
+
variant="ghost"
|
|
474
|
+
@click="isOpen = false"
|
|
475
|
+
/>
|
|
476
|
+
</template>
|
|
477
|
+
</template>
|
|
478
|
+
</UModal>
|
|
479
|
+
</template>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type __VLS_Props = {
|
|
2
|
+
collectionName: string;
|
|
3
|
+
};
|
|
4
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
5
|
+
imported: (count: number) => any;
|
|
6
|
+
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
7
|
+
onImported?: ((count: number) => any) | undefined;
|
|
8
|
+
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
9
|
+
declare const _default: typeof __VLS_export;
|
|
10
|
+
export default _default;
|
|
@@ -126,6 +126,21 @@ async function handleEditGrant() {
|
|
|
126
126
|
async function removeGrant(index) {
|
|
127
127
|
await saveGrants(grants.value.filter((_, i) => i !== index));
|
|
128
128
|
}
|
|
129
|
+
const missingReadCollections = computed(() => {
|
|
130
|
+
const grantedNames = new Set(grants.value.map((g) => g.name));
|
|
131
|
+
return allCollections.value.filter((c) => !c.startsWith("mc_") && !grantedNames.has(c));
|
|
132
|
+
});
|
|
133
|
+
async function addAllReadGrants() {
|
|
134
|
+
const added = missingReadCollections.value.map((name) => ({
|
|
135
|
+
name,
|
|
136
|
+
read: true,
|
|
137
|
+
write: false,
|
|
138
|
+
administrate: false,
|
|
139
|
+
grantType: "COLLECTION"
|
|
140
|
+
}));
|
|
141
|
+
if (!added.length) return;
|
|
142
|
+
await saveGrants([...grants.value, ...added]);
|
|
143
|
+
}
|
|
129
144
|
function openAdd() {
|
|
130
145
|
const grantedNames = new Set(grants.value.map((g) => g.name));
|
|
131
146
|
addGrantSchema[0].options = allCollections.value.filter((c) => !grantedNames.has(c));
|
|
@@ -226,6 +241,16 @@ fetchCollections();
|
|
|
226
241
|
@click="fetchRole"
|
|
227
242
|
/>
|
|
228
243
|
</UTooltip>
|
|
244
|
+
<UTooltip :text="t('nuxtUiMongocamp.roleGrants.addAllReadTooltip')">
|
|
245
|
+
<UButton
|
|
246
|
+
icon="i-lucide-eye"
|
|
247
|
+
color="neutral"
|
|
248
|
+
variant="outline"
|
|
249
|
+
:label="t('nuxtUiMongocamp.roleGrants.addAllRead')"
|
|
250
|
+
:disabled="saving || loading || !missingReadCollections.length"
|
|
251
|
+
@click="addAllReadGrants"
|
|
252
|
+
/>
|
|
253
|
+
</UTooltip>
|
|
229
254
|
<UButton
|
|
230
255
|
icon="i-lucide-plus"
|
|
231
256
|
:label="t('nuxtUiMongocamp.roleGrants.addGrant')"
|
|
@@ -17,11 +17,17 @@ let filterTimer;
|
|
|
17
17
|
const isAddModalOpen = ref(false);
|
|
18
18
|
const isEditModalOpen = ref(false);
|
|
19
19
|
const isDeleteModalOpen = ref(false);
|
|
20
|
+
const isCloneModalOpen = ref(false);
|
|
20
21
|
const roleToDelete = ref("");
|
|
21
22
|
const errorMessage = ref("");
|
|
22
23
|
const newRole = ref({ name: "", isAdmin: false });
|
|
23
24
|
const editRole = ref({ roleName: "", isAdmin: false });
|
|
24
25
|
const editGrants = ref([]);
|
|
26
|
+
const cloneSource = ref("");
|
|
27
|
+
const cloneRole = ref({ name: "", isAdmin: false });
|
|
28
|
+
const cloneGrants = ref([]);
|
|
29
|
+
const cloneError = ref("");
|
|
30
|
+
const cloning = ref(false);
|
|
25
31
|
const addRoleSchema = reactive([
|
|
26
32
|
{
|
|
27
33
|
$formkit: "nuxtUIInput",
|
|
@@ -42,6 +48,19 @@ const editRoleSchema = reactive([
|
|
|
42
48
|
label: t("nuxtUiMongocamp.roles.adminRole")
|
|
43
49
|
}
|
|
44
50
|
]);
|
|
51
|
+
const cloneRoleSchema = reactive([
|
|
52
|
+
{
|
|
53
|
+
$formkit: "nuxtUIInput",
|
|
54
|
+
name: "name",
|
|
55
|
+
label: t("nuxtUiMongocamp.roles.roleName"),
|
|
56
|
+
validation: "required|length:2"
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
$formkit: "nuxtUISwitch",
|
|
60
|
+
name: "isAdmin",
|
|
61
|
+
label: t("nuxtUiMongocamp.roles.adminRole")
|
|
62
|
+
}
|
|
63
|
+
]);
|
|
45
64
|
const loadError = ref(null);
|
|
46
65
|
const { describeError } = useMongocampError();
|
|
47
66
|
const rowSelection = ref({});
|
|
@@ -106,6 +125,26 @@ async function handleEditRole() {
|
|
|
106
125
|
errorMessage.value = e instanceof Error ? e.message : t("nuxtUiMongocamp.roles.errorEditRole");
|
|
107
126
|
}
|
|
108
127
|
}
|
|
128
|
+
function openClone(role) {
|
|
129
|
+
cloneSource.value = role.name;
|
|
130
|
+
cloneRole.value = { name: "", isAdmin: role.isAdmin };
|
|
131
|
+
cloneGrants.value = (role.collectionGrants ?? []).map((g) => ({ ...g }));
|
|
132
|
+
cloneError.value = "";
|
|
133
|
+
isCloneModalOpen.value = true;
|
|
134
|
+
}
|
|
135
|
+
async function handleCloneRole() {
|
|
136
|
+
cloning.value = true;
|
|
137
|
+
cloneError.value = "";
|
|
138
|
+
try {
|
|
139
|
+
await addRole(cloneRole.value.name, cloneRole.value.isAdmin, cloneGrants.value);
|
|
140
|
+
isCloneModalOpen.value = false;
|
|
141
|
+
await fetchRoles();
|
|
142
|
+
} catch (e) {
|
|
143
|
+
cloneError.value = describeError(e, "nuxtUiMongocamp.roles.errorClone").message;
|
|
144
|
+
} finally {
|
|
145
|
+
cloning.value = false;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
109
148
|
const deleteError = ref("");
|
|
110
149
|
const deleting = ref(false);
|
|
111
150
|
function confirmDelete(roleName) {
|
|
@@ -187,6 +226,14 @@ const columns = computed(() => [
|
|
|
187
226
|
"aria-label": t("nuxtUiMongocamp.roles.editRoleTooltip"),
|
|
188
227
|
"onClick": () => openEdit(row.original)
|
|
189
228
|
})),
|
|
229
|
+
withTooltip(t("nuxtUiMongocamp.roles.cloneRoleTooltip"), h(UButton, {
|
|
230
|
+
"icon": "i-lucide-copy",
|
|
231
|
+
"color": "neutral",
|
|
232
|
+
"variant": "ghost",
|
|
233
|
+
"size": "sm",
|
|
234
|
+
"aria-label": t("nuxtUiMongocamp.roles.cloneRoleTooltip"),
|
|
235
|
+
"onClick": () => openClone(row.original)
|
|
236
|
+
})),
|
|
190
237
|
withTooltip(t("nuxtUiMongocamp.roles.deleteRoleTooltip"), h(UButton, {
|
|
191
238
|
"icon": "i-lucide-trash-2",
|
|
192
239
|
"color": "error",
|
|
@@ -305,6 +352,33 @@ fetchRoles();
|
|
|
305
352
|
</template>
|
|
306
353
|
</UModal>
|
|
307
354
|
|
|
355
|
+
<!-- Clone Role Modal -->
|
|
356
|
+
<UModal
|
|
357
|
+
v-model:open="isCloneModalOpen"
|
|
358
|
+
:title="t('nuxtUiMongocamp.roles.cloneRoleTitle', { roleName: cloneSource })"
|
|
359
|
+
>
|
|
360
|
+
<template #body>
|
|
361
|
+
<p class="mb-3 text-sm text-dimmed">
|
|
362
|
+
{{ t("nuxtUiMongocamp.roles.cloneRoleHint", { count: cloneGrants.length }) }}
|
|
363
|
+
</p>
|
|
364
|
+
<FUDataEdit
|
|
365
|
+
:data="cloneRole"
|
|
366
|
+
:schema="cloneRoleSchema"
|
|
367
|
+
:submit-label="t('nuxtUiMongocamp.roles.cloneRole')"
|
|
368
|
+
submit-icon="i-lucide-copy"
|
|
369
|
+
@data-saved="handleCloneRole"
|
|
370
|
+
/>
|
|
371
|
+
<UAlert
|
|
372
|
+
v-if="cloneError"
|
|
373
|
+
class="mt-3"
|
|
374
|
+
color="error"
|
|
375
|
+
variant="subtle"
|
|
376
|
+
icon="i-lucide-circle-alert"
|
|
377
|
+
:description="cloneError"
|
|
378
|
+
/>
|
|
379
|
+
</template>
|
|
380
|
+
</UModal>
|
|
381
|
+
|
|
308
382
|
<!-- Delete Confirmation Modal -->
|
|
309
383
|
<UModal
|
|
310
384
|
v-model:open="isDeleteModalOpen"
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { RequestStage } from '../utils/aggregationPipeline.js';
|
|
2
|
+
export interface AggregationPaging {
|
|
3
|
+
page?: number;
|
|
4
|
+
rowsPerPage?: number;
|
|
5
|
+
}
|
|
6
|
+
export interface AggregationResult {
|
|
7
|
+
rows: Record<string, unknown>[];
|
|
8
|
+
total: number;
|
|
9
|
+
pages: number;
|
|
10
|
+
page: number;
|
|
11
|
+
}
|
|
12
|
+
export type DistinctValue = string | number | boolean;
|
|
13
|
+
export interface DistinctResult {
|
|
14
|
+
values: DistinctValue[];
|
|
15
|
+
total: number;
|
|
16
|
+
truncated: boolean;
|
|
17
|
+
}
|
|
18
|
+
export type AggregationErrorKind = 'forbidden' | 'retryable' | 'mongo' | 'network' | 'unauthorized' | 'forbidden-access' | 'other';
|
|
19
|
+
export interface DescribedAggregationError {
|
|
20
|
+
kind: AggregationErrorKind;
|
|
21
|
+
message: string;
|
|
22
|
+
}
|
|
23
|
+
export declare function useMongocampAggregation(): {
|
|
24
|
+
runAggregation: (collectionName: string, pipeline: RequestStage[], paging?: AggregationPaging) => Promise<AggregationResult>;
|
|
25
|
+
listDistinct: (collectionName: string, field: string, limit?: number) => Promise<DistinctResult>;
|
|
26
|
+
sampleDocuments: (collectionName: string, size?: number) => Promise<AggregationResult>;
|
|
27
|
+
describeAggregationError: (error: unknown) => Promise<DescribedAggregationError>;
|
|
28
|
+
};
|