@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
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { computed, ref, watch } from "vue";
|
|
3
|
+
import { useI18n } from "#imports";
|
|
4
|
+
import { coerceRow } from "../utils/importRows";
|
|
5
|
+
const props = defineProps({
|
|
6
|
+
selected: { type: Number, required: true },
|
|
7
|
+
fields: { type: Array, required: true },
|
|
8
|
+
saving: { type: Boolean, required: false },
|
|
9
|
+
error: { type: String, required: false }
|
|
10
|
+
});
|
|
11
|
+
const emit = defineEmits(["apply"]);
|
|
12
|
+
const isOpen = defineModel("open", { type: Boolean, ...{ default: false } });
|
|
13
|
+
const { t } = useI18n();
|
|
14
|
+
const field = ref("");
|
|
15
|
+
const type = ref("string");
|
|
16
|
+
const text = ref("");
|
|
17
|
+
const booleanValue = ref("true");
|
|
18
|
+
watch(isOpen, (open) => {
|
|
19
|
+
if (!open) return;
|
|
20
|
+
field.value = props.fields[0]?.key ?? "";
|
|
21
|
+
type.value = props.fields[0]?.type ?? "string";
|
|
22
|
+
text.value = "";
|
|
23
|
+
booleanValue.value = "true";
|
|
24
|
+
});
|
|
25
|
+
const fieldItems = computed(() => props.fields.map((f) => ({ label: f.key, value: f.key })));
|
|
26
|
+
const typeItems = computed(() => [
|
|
27
|
+
{ label: t("nuxtUiMongocamp.import.typeString"), value: "string" },
|
|
28
|
+
{ label: t("nuxtUiMongocamp.import.typeNumber"), value: "number" },
|
|
29
|
+
{ label: t("nuxtUiMongocamp.import.typeBoolean"), value: "boolean" },
|
|
30
|
+
{ label: t("nuxtUiMongocamp.import.typeDate"), value: "date-time" },
|
|
31
|
+
{ label: t("nuxtUiMongocamp.import.typeJson"), value: "json" }
|
|
32
|
+
]);
|
|
33
|
+
const booleanItems = computed(() => [
|
|
34
|
+
{ label: t("nuxtUiMongocamp.bulk.editTrue"), value: "true" },
|
|
35
|
+
{ label: t("nuxtUiMongocamp.bulk.editFalse"), value: "false" }
|
|
36
|
+
]);
|
|
37
|
+
function onFieldChange(key) {
|
|
38
|
+
field.value = key;
|
|
39
|
+
type.value = props.fields.find((f) => f.key === key)?.type ?? "string";
|
|
40
|
+
text.value = "";
|
|
41
|
+
}
|
|
42
|
+
const parsed = computed(() => {
|
|
43
|
+
if (type.value === "boolean") return { value: booleanValue.value === "true" };
|
|
44
|
+
if (text.value.trim() === "" && type.value !== "string") return { error: t("nuxtUiMongocamp.bulk.editValueRequired") };
|
|
45
|
+
const { row, errors } = coerceRow({ value: text.value }, { value: type.value }, { emptyCells: "empty-string" });
|
|
46
|
+
if (errors.length > 0) return { error: t(`nuxtUiMongocamp.import.error.${errors[0].code}`) };
|
|
47
|
+
return { value: row.value };
|
|
48
|
+
});
|
|
49
|
+
const showTextError = computed(() => text.value !== "" && parsed.value.error !== void 0);
|
|
50
|
+
const canApply = computed(() => field.value !== "" && parsed.value.error === void 0 && !props.saving);
|
|
51
|
+
function apply() {
|
|
52
|
+
if (!canApply.value) return;
|
|
53
|
+
emit("apply", { field: field.value, value: parsed.value.value });
|
|
54
|
+
}
|
|
55
|
+
watch(() => props.saving, (now, before) => {
|
|
56
|
+
if (before && !now && !props.error) isOpen.value = false;
|
|
57
|
+
});
|
|
58
|
+
</script>
|
|
59
|
+
|
|
60
|
+
<template>
|
|
61
|
+
<UModal
|
|
62
|
+
v-model:open="isOpen"
|
|
63
|
+
:title="t('nuxtUiMongocamp.bulk.editTitle', { count: selected }, selected)"
|
|
64
|
+
:ui="{ footer: 'justify-end' }"
|
|
65
|
+
>
|
|
66
|
+
<template #body>
|
|
67
|
+
<div class="flex flex-col gap-3">
|
|
68
|
+
<p class="text-sm">
|
|
69
|
+
{{ t("nuxtUiMongocamp.bulk.editDescription") }}
|
|
70
|
+
</p>
|
|
71
|
+
<div class="flex flex-wrap items-end gap-3">
|
|
72
|
+
<USelect
|
|
73
|
+
:model-value="field"
|
|
74
|
+
:items="fieldItems"
|
|
75
|
+
class="w-48"
|
|
76
|
+
:aria-label="t('nuxtUiMongocamp.bulk.editField')"
|
|
77
|
+
@update:model-value="onFieldChange"
|
|
78
|
+
/>
|
|
79
|
+
<USelect
|
|
80
|
+
v-model="type"
|
|
81
|
+
:items="typeItems"
|
|
82
|
+
class="w-36"
|
|
83
|
+
:aria-label="t('nuxtUiMongocamp.bulk.editType')"
|
|
84
|
+
/>
|
|
85
|
+
<USelect
|
|
86
|
+
v-if="type === 'boolean'"
|
|
87
|
+
v-model="booleanValue"
|
|
88
|
+
:items="booleanItems"
|
|
89
|
+
class="w-28"
|
|
90
|
+
:aria-label="t('nuxtUiMongocamp.bulk.editValue')"
|
|
91
|
+
/>
|
|
92
|
+
<UInput
|
|
93
|
+
v-else
|
|
94
|
+
v-model="text"
|
|
95
|
+
class="w-56"
|
|
96
|
+
:color="showTextError ? 'error' : void 0"
|
|
97
|
+
:aria-label="t('nuxtUiMongocamp.bulk.editValue')"
|
|
98
|
+
@keydown.enter.prevent="apply"
|
|
99
|
+
/>
|
|
100
|
+
</div>
|
|
101
|
+
<p
|
|
102
|
+
v-if="showTextError"
|
|
103
|
+
class="text-sm text-error"
|
|
104
|
+
>
|
|
105
|
+
{{ parsed.error }}
|
|
106
|
+
</p>
|
|
107
|
+
<p
|
|
108
|
+
v-if="field"
|
|
109
|
+
class="text-sm text-dimmed"
|
|
110
|
+
>
|
|
111
|
+
{{ t("nuxtUiMongocamp.bulk.editSummary", { field, count: selected }, selected) }}
|
|
112
|
+
</p>
|
|
113
|
+
<UAlert
|
|
114
|
+
v-if="error"
|
|
115
|
+
color="error"
|
|
116
|
+
variant="subtle"
|
|
117
|
+
icon="i-lucide-circle-alert"
|
|
118
|
+
:description="error"
|
|
119
|
+
/>
|
|
120
|
+
</div>
|
|
121
|
+
</template>
|
|
122
|
+
<template #footer>
|
|
123
|
+
<UButton
|
|
124
|
+
:label="t('nuxtUiMongocamp.common.cancel')"
|
|
125
|
+
color="neutral"
|
|
126
|
+
variant="ghost"
|
|
127
|
+
:disabled="saving"
|
|
128
|
+
@click="isOpen = false"
|
|
129
|
+
/>
|
|
130
|
+
<UButton
|
|
131
|
+
:label="t('nuxtUiMongocamp.bulk.confirmEdit', { count: selected })"
|
|
132
|
+
:loading="saving"
|
|
133
|
+
:disabled="!canApply"
|
|
134
|
+
@click="apply"
|
|
135
|
+
/>
|
|
136
|
+
</template>
|
|
137
|
+
</UModal>
|
|
138
|
+
</template>
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ImportColumnType } from '../utils/importRows.js';
|
|
2
|
+
type __VLS_Props = {
|
|
3
|
+
selected: number;
|
|
4
|
+
fields: {
|
|
5
|
+
key: string;
|
|
6
|
+
type: ImportColumnType;
|
|
7
|
+
}[];
|
|
8
|
+
saving?: boolean;
|
|
9
|
+
error?: string;
|
|
10
|
+
};
|
|
11
|
+
type __VLS_ModelProps = {
|
|
12
|
+
'open'?: boolean;
|
|
13
|
+
};
|
|
14
|
+
type __VLS_PublicProps = __VLS_Props & __VLS_ModelProps;
|
|
15
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_PublicProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
16
|
+
"update:open": (value: boolean) => any;
|
|
17
|
+
apply: (edit: {
|
|
18
|
+
field: string;
|
|
19
|
+
value: unknown;
|
|
20
|
+
}) => any;
|
|
21
|
+
}, string, import("vue").PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
|
|
22
|
+
"onUpdate:open"?: ((value: boolean) => any) | undefined;
|
|
23
|
+
onApply?: ((edit: {
|
|
24
|
+
field: string;
|
|
25
|
+
value: unknown;
|
|
26
|
+
}) => any) | undefined;
|
|
27
|
+
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
28
|
+
declare const _default: typeof __VLS_export;
|
|
29
|
+
export default _default;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
type __VLS_Props = {
|
|
2
2
|
collectionName: string;
|
|
3
|
+
infoPath?: string;
|
|
3
4
|
};
|
|
4
|
-
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
|
|
5
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
|
|
6
|
+
infoPath: string;
|
|
7
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
5
8
|
declare const _default: typeof __VLS_export;
|
|
6
9
|
export default _default;
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
<script setup>
|
|
2
2
|
import { computed, h, ref, resolveComponent, watch } from "vue";
|
|
3
|
-
import { useI18n, useMongocampClientApi, useMongocampError, useMongocampSchema } from "#imports";
|
|
3
|
+
import { useI18n, useMongocampClientApi, useMongocampError, useMongocampRoles, useMongocampSchema, useToast } from "#imports";
|
|
4
4
|
import useMongocampCollection from "../composables/useMongocampCollection";
|
|
5
5
|
import { useMongocampBucket } from "../composables/useMongocampBucket";
|
|
6
|
+
import { useMongocampIndex } from "../composables/useMongocampIndex";
|
|
6
7
|
import { unwrapExtendedJson, wrapExtendedJson } from "../composables/useMongocampExtendedJson";
|
|
7
8
|
import { isIsoDateTimeString } from "../utils/isoDate";
|
|
9
|
+
import { parseServerError } from "../utils/aggregationErrors";
|
|
8
10
|
import { downloadTextFile, rowsToCsv } from "../utils/exportRows";
|
|
9
11
|
import { runBulkDelete } from "../utils/bulkDelete";
|
|
12
|
+
import { BulkMatchShortfall, BulkUnaddressableId, buildIdFilter, isEditableField, runBulkUpdate } from "../utils/bulkEdit";
|
|
13
|
+
import { isObjectIdHex } from "../utils/objectId";
|
|
10
14
|
import { createSelectColumn } from "../utils/createSelectColumn";
|
|
11
15
|
import {
|
|
12
16
|
buildCondition,
|
|
@@ -19,8 +23,10 @@ import {
|
|
|
19
23
|
} from "../utils/filterBuilder";
|
|
20
24
|
import useMongocampDocument from "../composables/useMongocampDocument";
|
|
21
25
|
import { useMongocampQuery } from "../composables/useMongocampQuery";
|
|
26
|
+
import { useMongocampAggregation } from "../composables/useMongocampAggregation";
|
|
22
27
|
const props = defineProps({
|
|
23
|
-
collectionName: { type: String, required: true }
|
|
28
|
+
collectionName: { type: String, required: true },
|
|
29
|
+
infoPath: { type: String, required: false, default: "/secured/admin/collections" }
|
|
24
30
|
});
|
|
25
31
|
const { t } = useI18n();
|
|
26
32
|
const { documentApi } = useMongocampClientApi();
|
|
@@ -29,6 +35,10 @@ const { isBucketCollection, fileIdForRow, downloadingFileIds, uploading, downloa
|
|
|
29
35
|
const { ensureMetaData } = useMongocampDocument();
|
|
30
36
|
const { and, like, or } = useMongocampQuery();
|
|
31
37
|
const { schemaFromSamples } = useMongocampSchema();
|
|
38
|
+
const { listDistinct } = useMongocampAggregation();
|
|
39
|
+
const { createIndexForField } = useMongocampIndex();
|
|
40
|
+
const { isManager } = useMongocampRoles();
|
|
41
|
+
const toast = useToast();
|
|
32
42
|
const fileInputRef = ref(null);
|
|
33
43
|
function openFilePicker() {
|
|
34
44
|
fileInputRef.value?.click();
|
|
@@ -43,6 +53,7 @@ async function handleFileSelected(event) {
|
|
|
43
53
|
}
|
|
44
54
|
const UButton = resolveComponent("UButton");
|
|
45
55
|
const UTooltip = resolveComponent("UTooltip");
|
|
56
|
+
const UDropdownMenu = resolveComponent("UDropdownMenu");
|
|
46
57
|
const UCheckbox = resolveComponent("UCheckbox");
|
|
47
58
|
function withTooltip(text, node) {
|
|
48
59
|
return h(UTooltip, { text }, { default: () => node });
|
|
@@ -194,6 +205,63 @@ function sortHeader(column, label) {
|
|
|
194
205
|
onClick: () => column.toggleSorting(isSorted === "asc")
|
|
195
206
|
});
|
|
196
207
|
}
|
|
208
|
+
const indexing = ref(/* @__PURE__ */ new Set());
|
|
209
|
+
function canIndexField(key) {
|
|
210
|
+
return isManager.value && !isBucketCollection(props.collectionName) && key !== "_id" && key !== "metaData";
|
|
211
|
+
}
|
|
212
|
+
async function indexFailureMessage(error) {
|
|
213
|
+
try {
|
|
214
|
+
const body = await error?.response?.clone().json();
|
|
215
|
+
if (typeof body?.msg === "string" && body.msg) {
|
|
216
|
+
const message = parseServerError(body.msg).message;
|
|
217
|
+
if (message) return message;
|
|
218
|
+
}
|
|
219
|
+
} catch {
|
|
220
|
+
}
|
|
221
|
+
return describeError(error).message;
|
|
222
|
+
}
|
|
223
|
+
async function indexField(key, ascending) {
|
|
224
|
+
if (indexing.value.has(key)) return;
|
|
225
|
+
indexing.value = new Set(indexing.value).add(key);
|
|
226
|
+
try {
|
|
227
|
+
const created = await createIndexForField(props.collectionName, key, ascending);
|
|
228
|
+
toast.add({
|
|
229
|
+
title: t("nuxtUiMongocamp.collectionData.indexCreatedTitle"),
|
|
230
|
+
description: t("nuxtUiMongocamp.collectionData.indexCreatedDescription", { name: created.name, collection: props.collectionName }),
|
|
231
|
+
color: "success",
|
|
232
|
+
actions: [{ label: t("nuxtUiMongocamp.collectionData.viewIndexes"), to: `${props.infoPath}/${props.collectionName}` }]
|
|
233
|
+
});
|
|
234
|
+
} catch (e) {
|
|
235
|
+
toast.add({ title: t("nuxtUiMongocamp.collectionData.indexFailedTitle", { field: key }), description: await indexFailureMessage(e), color: "error" });
|
|
236
|
+
} finally {
|
|
237
|
+
const next = new Set(indexing.value);
|
|
238
|
+
next.delete(key);
|
|
239
|
+
indexing.value = next;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
function columnHeader(column, key) {
|
|
243
|
+
const sort = sortHeader(column, key);
|
|
244
|
+
if (!canIndexField(key)) return sort;
|
|
245
|
+
const label = t("nuxtUiMongocamp.collectionData.indexFieldTooltip", { field: key });
|
|
246
|
+
return h("div", { class: "flex items-center gap-1" }, [
|
|
247
|
+
sort,
|
|
248
|
+
h(UDropdownMenu, {
|
|
249
|
+
items: [[
|
|
250
|
+
{ label: t("nuxtUiMongocamp.collectionData.indexAscending"), icon: "i-lucide-arrow-up-narrow-wide", onSelect: () => indexField(key, true) },
|
|
251
|
+
{ label: t("nuxtUiMongocamp.collectionData.indexDescending"), icon: "i-lucide-arrow-down-wide-narrow", onSelect: () => indexField(key, false) }
|
|
252
|
+
]]
|
|
253
|
+
}, {
|
|
254
|
+
default: () => h(UButton, {
|
|
255
|
+
"icon": "i-lucide-list-tree",
|
|
256
|
+
"color": "neutral",
|
|
257
|
+
"variant": "ghost",
|
|
258
|
+
"size": "xs",
|
|
259
|
+
"aria-label": label,
|
|
260
|
+
"loading": indexing.value.has(key)
|
|
261
|
+
})
|
|
262
|
+
})
|
|
263
|
+
]);
|
|
264
|
+
}
|
|
197
265
|
const columns = ref([]);
|
|
198
266
|
const documents = ref([]);
|
|
199
267
|
const loading = ref(false);
|
|
@@ -345,6 +413,13 @@ const rowSelection = ref({});
|
|
|
345
413
|
const selectedDocIds = computed(() => Object.keys(rowSelection.value).filter((id) => rowSelection.value[id]));
|
|
346
414
|
const bulkDeleting = ref(false);
|
|
347
415
|
const bulkError = ref("");
|
|
416
|
+
const bulkEditing = ref(false);
|
|
417
|
+
const bulkEditError = ref("");
|
|
418
|
+
const bulkEditOpen = ref(false);
|
|
419
|
+
function openBulkEdit() {
|
|
420
|
+
bulkEditError.value = "";
|
|
421
|
+
bulkEditOpen.value = true;
|
|
422
|
+
}
|
|
348
423
|
function rowId(row, index) {
|
|
349
424
|
return getDocId(row) ?? String(index);
|
|
350
425
|
}
|
|
@@ -353,7 +428,20 @@ async function handleBulkDelete() {
|
|
|
353
428
|
bulkError.value = "";
|
|
354
429
|
const ids = [...selectedDocIds.value];
|
|
355
430
|
try {
|
|
356
|
-
const { failed } = await runBulkDelete(
|
|
431
|
+
const { failed } = await runBulkDelete(
|
|
432
|
+
ids,
|
|
433
|
+
(documentId) => documentApi._delete({ collectionName: props.collectionName, documentId }),
|
|
434
|
+
void 0,
|
|
435
|
+
{
|
|
436
|
+
// one request per chunk for ids a filter can address; the rest (and any chunk that does not
|
|
437
|
+
// come back fully deleted) go one by one. The generated type says string values only.
|
|
438
|
+
canHandle: isObjectIdHex,
|
|
439
|
+
run: async (chunk) => (await documentApi.deleteMany({
|
|
440
|
+
collectionName: props.collectionName,
|
|
441
|
+
requestBody: buildIdFilter(chunk)
|
|
442
|
+
})).deletedCount
|
|
443
|
+
}
|
|
444
|
+
);
|
|
357
445
|
await fetchDocuments();
|
|
358
446
|
if (failed.length > 0) {
|
|
359
447
|
rowSelection.value = Object.fromEntries(failed.map((f) => [f.item, true]));
|
|
@@ -363,6 +451,38 @@ async function handleBulkDelete() {
|
|
|
363
451
|
bulkDeleting.value = false;
|
|
364
452
|
}
|
|
365
453
|
}
|
|
454
|
+
const editableFields = computed(
|
|
455
|
+
() => filterFields.value.filter((f) => f.key !== "metaData" && isEditableField(f.key)).map((f) => ({ key: f.key, type: f.type === "array" || f.type === "object" ? "json" : f.type }))
|
|
456
|
+
);
|
|
457
|
+
function bulkEditFailureReason(error) {
|
|
458
|
+
if (error instanceof BulkMatchShortfall) return t("nuxtUiMongocamp.bulk.editShortfall", { matched: error.matched, expected: error.expected });
|
|
459
|
+
if (error instanceof BulkUnaddressableId) return t("nuxtUiMongocamp.bulk.editUnaddressable");
|
|
460
|
+
return describeError(error).message;
|
|
461
|
+
}
|
|
462
|
+
async function handleBulkEdit(edit) {
|
|
463
|
+
bulkEditing.value = true;
|
|
464
|
+
bulkEditError.value = "";
|
|
465
|
+
const ids = [...selectedDocIds.value];
|
|
466
|
+
const document = { [edit.field]: edit.value };
|
|
467
|
+
try {
|
|
468
|
+
const { failed } = await runBulkUpdate(
|
|
469
|
+
ids,
|
|
470
|
+
(chunk) => documentApi.updateMany({
|
|
471
|
+
collectionName: props.collectionName,
|
|
472
|
+
updateRequest: { filter: buildIdFilter(chunk), document }
|
|
473
|
+
})
|
|
474
|
+
);
|
|
475
|
+
await fetchDocuments();
|
|
476
|
+
if (failed.length > 0) {
|
|
477
|
+
const onScreen = new Set(documents.value.map((row) => getDocId(row)));
|
|
478
|
+
const failedIds = failed.flatMap((f) => f.ids);
|
|
479
|
+
rowSelection.value = Object.fromEntries(failedIds.filter((id) => onScreen.has(id)).map((id) => [id, true]));
|
|
480
|
+
bulkEditError.value = t("nuxtUiMongocamp.bulk.editPartialFailure", { failed: failedIds.length, total: ids.length, reason: bulkEditFailureReason(failed[0].error) });
|
|
481
|
+
}
|
|
482
|
+
} finally {
|
|
483
|
+
bulkEditing.value = false;
|
|
484
|
+
}
|
|
485
|
+
}
|
|
366
486
|
async function fetchDocuments() {
|
|
367
487
|
loading.value = true;
|
|
368
488
|
loadError.value = null;
|
|
@@ -390,7 +510,7 @@ async function fetchDocuments() {
|
|
|
390
510
|
];
|
|
391
511
|
columns.value = orderedKeys.map((key, index) => ({
|
|
392
512
|
accessorKey: key,
|
|
393
|
-
header: ({ column }) =>
|
|
513
|
+
header: ({ column }) => columnHeader(column, key),
|
|
394
514
|
cell: makeCell(key, "string"),
|
|
395
515
|
// keep the first column (usually _id) pinned so rows stay identifiable when the table scrolls sideways
|
|
396
516
|
...index === 0 ? { meta: { class: { th: "sticky left-0 z-10 bg-default", td: "sticky left-0 z-10 bg-default" } } } : {}
|
|
@@ -472,7 +592,24 @@ const exportMenuItems = computed(() => [
|
|
|
472
592
|
{ label: t("nuxtUiMongocamp.collectionData.exportJson"), icon: "i-lucide-file-json", onSelect: () => exportPage("json") },
|
|
473
593
|
{ label: t("nuxtUiMongocamp.collectionData.exportCsv"), icon: "i-lucide-file-spreadsheet", onSelect: () => exportPage("csv") }
|
|
474
594
|
]);
|
|
595
|
+
const DISTINCT_SUGGESTION_LIMIT = 100;
|
|
596
|
+
let distinctCache = /* @__PURE__ */ new Map();
|
|
597
|
+
async function loadDistinctSuggestions(field) {
|
|
598
|
+
const cached = distinctCache.get(field);
|
|
599
|
+
if (cached) return cached;
|
|
600
|
+
const cache = distinctCache;
|
|
601
|
+
const collection = props.collectionName;
|
|
602
|
+
let suggestions = [];
|
|
603
|
+
try {
|
|
604
|
+
const { values, truncated } = await listDistinct(collection, field, DISTINCT_SUGGESTION_LIMIT);
|
|
605
|
+
if (!truncated) suggestions = [...new Set(values.map(String))].sort((a, b) => a.localeCompare(b));
|
|
606
|
+
} catch {
|
|
607
|
+
}
|
|
608
|
+
if (cache === distinctCache && collection === props.collectionName) cache.set(field, suggestions);
|
|
609
|
+
return suggestions;
|
|
610
|
+
}
|
|
475
611
|
async function init() {
|
|
612
|
+
distinctCache = /* @__PURE__ */ new Map();
|
|
476
613
|
isInitializing.value = true;
|
|
477
614
|
sorting.value = [];
|
|
478
615
|
pagination.value.pageIndex = 1;
|
|
@@ -541,6 +678,11 @@ watch(() => props.collectionName, init, { immediate: true });
|
|
|
541
678
|
class="hidden"
|
|
542
679
|
@change="handleFileSelected"
|
|
543
680
|
>
|
|
681
|
+
<MongocampImport
|
|
682
|
+
v-if="!isBucketCollection(collectionName)"
|
|
683
|
+
:collection-name="collectionName"
|
|
684
|
+
@imported="init"
|
|
685
|
+
/>
|
|
544
686
|
<UTooltip :text="t('nuxtUiMongocamp.collectionData.reloadTooltip')">
|
|
545
687
|
<UButton
|
|
546
688
|
icon="i-lucide-refresh-cw"
|
|
@@ -607,6 +749,7 @@ watch(() => props.collectionName, init, { immediate: true });
|
|
|
607
749
|
v-if="filtersOpen"
|
|
608
750
|
v-model="filterDraft"
|
|
609
751
|
:fields="filterFields"
|
|
752
|
+
:load-distinct="loadDistinctSuggestions"
|
|
610
753
|
@apply="onFilterApply"
|
|
611
754
|
/>
|
|
612
755
|
|
|
@@ -655,6 +798,26 @@ watch(() => props.collectionName, init, { immediate: true });
|
|
|
655
798
|
@open="bulkError = ''"
|
|
656
799
|
@clear="rowSelection = {}"
|
|
657
800
|
@confirm="handleBulkDelete"
|
|
801
|
+
>
|
|
802
|
+
<template #actions>
|
|
803
|
+
<UButton
|
|
804
|
+
v-if="editableFields.length > 0"
|
|
805
|
+
icon="i-lucide-pencil"
|
|
806
|
+
color="neutral"
|
|
807
|
+
variant="subtle"
|
|
808
|
+
size="sm"
|
|
809
|
+
:label="t('nuxtUiMongocamp.bulk.editSelected')"
|
|
810
|
+
@click="openBulkEdit"
|
|
811
|
+
/>
|
|
812
|
+
</template>
|
|
813
|
+
</MongocampBulkDelete>
|
|
814
|
+
<MongocampBulkEdit
|
|
815
|
+
v-model:open="bulkEditOpen"
|
|
816
|
+
:selected="selectedDocIds.length"
|
|
817
|
+
:fields="editableFields"
|
|
818
|
+
:saving="bulkEditing"
|
|
819
|
+
:error="bulkEditError"
|
|
820
|
+
@apply="handleBulkEdit"
|
|
658
821
|
/>
|
|
659
822
|
|
|
660
823
|
<UTable
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
type __VLS_Props = {
|
|
2
2
|
collectionName: string;
|
|
3
|
+
infoPath?: string;
|
|
3
4
|
};
|
|
4
|
-
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
|
|
5
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
|
|
6
|
+
infoPath: string;
|
|
7
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
5
8
|
declare const _default: typeof __VLS_export;
|
|
6
9
|
export default _default;
|