@sfxcode/nuxt-ui-mongocamp 1.2.6 → 1.3.0
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/MongocampAccount.vue +10 -0
- package/dist/runtime/components/MongocampBucketFiles.vue +18 -3
- package/dist/runtime/components/MongocampBulkDelete.d.vue.ts +16 -0
- package/dist/runtime/components/MongocampBulkDelete.vue +96 -0
- package/dist/runtime/components/MongocampBulkDelete.vue.d.ts +16 -0
- package/dist/runtime/components/MongocampCollectionData.vue +258 -11
- package/dist/runtime/components/MongocampCollectionInfos.vue +11 -5
- package/dist/runtime/components/MongocampCollections.vue +18 -4
- package/dist/runtime/components/MongocampDashboard.d.vue.ts +25 -0
- package/dist/runtime/components/MongocampDashboard.vue +111 -0
- package/dist/runtime/components/MongocampDashboard.vue.d.ts +25 -0
- package/dist/runtime/components/MongocampDatabases.vue +16 -24
- package/dist/runtime/components/MongocampEmptyState.d.vue.ts +18 -0
- package/dist/runtime/components/MongocampEmptyState.vue +28 -0
- package/dist/runtime/components/MongocampEmptyState.vue.d.ts +18 -0
- package/dist/runtime/components/MongocampErrorAlert.d.vue.ts +15 -0
- package/dist/runtime/components/MongocampErrorAlert.vue +53 -0
- package/dist/runtime/components/MongocampErrorAlert.vue.d.ts +15 -0
- package/dist/runtime/components/MongocampFilterBuilder.d.vue.ts +20 -0
- package/dist/runtime/components/MongocampFilterBuilder.vue +201 -0
- package/dist/runtime/components/MongocampFilterBuilder.vue.d.ts +20 -0
- package/dist/runtime/components/MongocampJobs.vue +44 -8
- package/dist/runtime/components/MongocampLogin.vue +3 -2
- package/dist/runtime/components/MongocampRoleGrants.vue +70 -38
- package/dist/runtime/components/MongocampRoles.vue +79 -8
- package/dist/runtime/components/MongocampUsers.vue +108 -16
- package/dist/runtime/composables/useMongocampBulkDelete.d.ts +5 -0
- package/dist/runtime/composables/useMongocampBulkDelete.js +4 -0
- package/dist/runtime/composables/useMongocampError.d.ts +8 -0
- package/dist/runtime/composables/useMongocampError.js +20 -0
- package/dist/runtime/composables/useMongocampExport.d.ts +5 -0
- package/dist/runtime/composables/useMongocampExport.js +4 -0
- package/dist/runtime/composables/useMongocampExtendedJson.js +1 -4
- package/dist/runtime/composables/useMongocampFilterBuilder.d.ts +12 -0
- package/dist/runtime/composables/useMongocampFilterBuilder.js +13 -0
- package/dist/runtime/composables/useMongocampQuery.d.ts +31 -24
- package/dist/runtime/composables/useMongocampQuery.js +60 -16
- package/dist/runtime/locales/de.json +97 -7
- package/dist/runtime/locales/en.json +97 -7
- package/dist/runtime/utils/bulkDelete.d.ts +8 -0
- package/dist/runtime/utils/bulkDelete.js +23 -0
- package/dist/runtime/utils/createSelectColumn.d.ts +7 -0
- package/dist/runtime/utils/createSelectColumn.js +19 -0
- package/dist/runtime/utils/escapeFieldName.d.ts +5 -0
- package/dist/runtime/utils/escapeFieldName.js +3 -0
- package/dist/runtime/utils/exportRows.d.ts +2 -0
- package/dist/runtime/utils/exportRows.js +18 -0
- package/dist/runtime/utils/filterBuilder.d.ts +31 -0
- package/dist/runtime/utils/filterBuilder.js +120 -0
- package/dist/runtime/utils/isoDate.d.ts +1 -0
- package/dist/runtime/utils/isoDate.js +4 -0
- package/package.json +18 -18
package/README.md
CHANGED
|
@@ -52,7 +52,7 @@ The `mongocamp` key is forwarded to `@sfxcode/nuxt-mongocamp-server`. Set `MONGO
|
|
|
52
52
|
|
|
53
53
|
## Components
|
|
54
54
|
|
|
55
|
-
All components are auto-imported.
|
|
55
|
+
All components are auto-imported. The sections below cover the main ones; the [component reference](https://sfxcode.github.io/nuxt-ui-mongocamp/components/) lists every component, including `MongocampDashboard` (admin landing page), `MongocampJobs`, `MongocampAccount`, `MongocampDatabases`, `MongocampBucketFiles`, and the building blocks `MongocampFilterBuilder`, `MongocampBulkDelete`, `MongocampErrorAlert` and `MongocampEmptyState`.
|
|
56
56
|
|
|
57
57
|
### `<MongocampLogin />`
|
|
58
58
|
|
package/dist/module.json
CHANGED
|
@@ -7,10 +7,14 @@ const toast = useToast();
|
|
|
7
7
|
const UBadge = resolveComponent("UBadge");
|
|
8
8
|
const profile = ref(null);
|
|
9
9
|
const loading = ref(false);
|
|
10
|
+
const loadError = ref(null);
|
|
10
11
|
async function loadProfile() {
|
|
11
12
|
loading.value = true;
|
|
13
|
+
loadError.value = null;
|
|
12
14
|
try {
|
|
13
15
|
profile.value = await fetchProfile();
|
|
16
|
+
} catch (e) {
|
|
17
|
+
loadError.value = e;
|
|
14
18
|
} finally {
|
|
15
19
|
loading.value = false;
|
|
16
20
|
}
|
|
@@ -61,6 +65,12 @@ loadProfile();
|
|
|
61
65
|
class="h-32 w-full"
|
|
62
66
|
/>
|
|
63
67
|
|
|
68
|
+
<MongocampErrorAlert
|
|
69
|
+
v-else-if="loadError"
|
|
70
|
+
:error="loadError"
|
|
71
|
+
@retry="loadProfile"
|
|
72
|
+
/>
|
|
73
|
+
|
|
64
74
|
<UCard v-else-if="profile">
|
|
65
75
|
<template #header>
|
|
66
76
|
<span class="font-semibold">{{ t("nuxtUiMongocamp.account.heading") }}</span>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script setup>
|
|
2
|
-
import { h, reactive, ref, resolveComponent, watch } from "vue";
|
|
2
|
+
import { computed, h, reactive, ref, resolveComponent, watch } from "vue";
|
|
3
3
|
import { useI18n } from "#imports";
|
|
4
4
|
import useMongocampCollection from "../composables/useMongocampCollection";
|
|
5
5
|
import { useMongocampBucket } from "../composables/useMongocampBucket";
|
|
@@ -182,7 +182,7 @@ function makeActionsColumn() {
|
|
|
182
182
|
}
|
|
183
183
|
};
|
|
184
184
|
}
|
|
185
|
-
const columns =
|
|
185
|
+
const columns = computed(() => [
|
|
186
186
|
{
|
|
187
187
|
accessorKey: "filename",
|
|
188
188
|
header: ({ column }) => sortHeader(column, t("nuxtUiMongocamp.bucketFiles.columnFilename")),
|
|
@@ -227,8 +227,10 @@ watch(sorting, () => {
|
|
|
227
227
|
pagination.value.pageIndex = 1;
|
|
228
228
|
fetchFiles();
|
|
229
229
|
});
|
|
230
|
+
const loadError = ref(null);
|
|
230
231
|
async function fetchFiles() {
|
|
231
232
|
loading.value = true;
|
|
233
|
+
loadError.value = null;
|
|
232
234
|
try {
|
|
233
235
|
const result = await listFiles(props.bucketName, {
|
|
234
236
|
rowsPerPage: pagination.value.pageSize,
|
|
@@ -238,6 +240,10 @@ async function fetchFiles() {
|
|
|
238
240
|
});
|
|
239
241
|
total.value = result.total;
|
|
240
242
|
files.value = result.files;
|
|
243
|
+
} catch (e) {
|
|
244
|
+
loadError.value = e;
|
|
245
|
+
files.value = [];
|
|
246
|
+
total.value = 0;
|
|
241
247
|
} finally {
|
|
242
248
|
loading.value = false;
|
|
243
249
|
}
|
|
@@ -304,13 +310,22 @@ watch(() => props.bucketName, init, { immediate: true });
|
|
|
304
310
|
/>
|
|
305
311
|
</div>
|
|
306
312
|
</div>
|
|
313
|
+
<MongocampErrorAlert
|
|
314
|
+
:error="loadError"
|
|
315
|
+
@retry="fetchFiles"
|
|
316
|
+
/>
|
|
317
|
+
|
|
307
318
|
<UTable
|
|
308
319
|
v-model:sorting="sorting"
|
|
309
320
|
:sorting-options="{ manualSorting: true }"
|
|
310
321
|
:data="files"
|
|
311
322
|
:columns="columns"
|
|
312
323
|
:loading="loading"
|
|
313
|
-
|
|
324
|
+
>
|
|
325
|
+
<template #empty>
|
|
326
|
+
<MongocampEmptyState :title="t('nuxtUiMongocamp.empty.files')" />
|
|
327
|
+
</template>
|
|
328
|
+
</UTable>
|
|
314
329
|
|
|
315
330
|
<UModal
|
|
316
331
|
v-model:open="detailOpen"
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
type __VLS_Props = {
|
|
2
|
+
selected: string[];
|
|
3
|
+
deleting?: boolean;
|
|
4
|
+
error?: string;
|
|
5
|
+
};
|
|
6
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
7
|
+
open: () => any;
|
|
8
|
+
clear: () => any;
|
|
9
|
+
confirm: () => any;
|
|
10
|
+
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
11
|
+
onOpen?: (() => any) | undefined;
|
|
12
|
+
onClear?: (() => any) | undefined;
|
|
13
|
+
onConfirm?: (() => any) | undefined;
|
|
14
|
+
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
15
|
+
declare const _default: typeof __VLS_export;
|
|
16
|
+
export default _default;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { computed, ref, watch } from "vue";
|
|
3
|
+
import { useI18n } from "#imports";
|
|
4
|
+
const PREVIEW_LIMIT = 5;
|
|
5
|
+
const props = defineProps({
|
|
6
|
+
selected: { type: Array, required: true },
|
|
7
|
+
deleting: { type: Boolean, required: false },
|
|
8
|
+
error: { type: String, required: false }
|
|
9
|
+
});
|
|
10
|
+
const emit = defineEmits(["confirm", "clear", "open"]);
|
|
11
|
+
const { t } = useI18n();
|
|
12
|
+
const isOpen = ref(false);
|
|
13
|
+
function openModal() {
|
|
14
|
+
emit("open");
|
|
15
|
+
isOpen.value = true;
|
|
16
|
+
}
|
|
17
|
+
const preview = computed(() => props.selected.slice(0, PREVIEW_LIMIT));
|
|
18
|
+
const hiddenCount = computed(() => Math.max(0, props.selected.length - PREVIEW_LIMIT));
|
|
19
|
+
watch(() => props.deleting, (now, before) => {
|
|
20
|
+
if (before && !now && !props.error) isOpen.value = false;
|
|
21
|
+
});
|
|
22
|
+
</script>
|
|
23
|
+
|
|
24
|
+
<template>
|
|
25
|
+
<div
|
|
26
|
+
v-if="selected.length > 0"
|
|
27
|
+
class="flex items-center gap-3 rounded-md border border-default bg-elevated/50 px-3 py-2"
|
|
28
|
+
>
|
|
29
|
+
<span class="text-sm font-medium">
|
|
30
|
+
{{ t("nuxtUiMongocamp.bulk.selectedCount", { count: selected.length }) }}
|
|
31
|
+
</span>
|
|
32
|
+
<UButton
|
|
33
|
+
icon="i-lucide-trash-2"
|
|
34
|
+
color="error"
|
|
35
|
+
variant="subtle"
|
|
36
|
+
size="sm"
|
|
37
|
+
:label="t('nuxtUiMongocamp.bulk.deleteSelected')"
|
|
38
|
+
@click="openModal"
|
|
39
|
+
/>
|
|
40
|
+
<UButton
|
|
41
|
+
color="neutral"
|
|
42
|
+
variant="ghost"
|
|
43
|
+
size="sm"
|
|
44
|
+
:label="t('nuxtUiMongocamp.bulk.clearSelection')"
|
|
45
|
+
@click="emit('clear')"
|
|
46
|
+
/>
|
|
47
|
+
</div>
|
|
48
|
+
|
|
49
|
+
<UModal
|
|
50
|
+
v-model:open="isOpen"
|
|
51
|
+
:title="t('nuxtUiMongocamp.bulk.deleteTitle', { count: selected.length }, selected.length)"
|
|
52
|
+
:ui="{ footer: 'justify-end' }"
|
|
53
|
+
>
|
|
54
|
+
<template #body>
|
|
55
|
+
<p>{{ t("nuxtUiMongocamp.bulk.deleteDescription") }}</p>
|
|
56
|
+
<ul class="mt-3 list-disc pl-5 text-sm">
|
|
57
|
+
<li
|
|
58
|
+
v-for="name in preview"
|
|
59
|
+
:key="name"
|
|
60
|
+
class="break-all"
|
|
61
|
+
>
|
|
62
|
+
{{ name }}
|
|
63
|
+
</li>
|
|
64
|
+
</ul>
|
|
65
|
+
<p
|
|
66
|
+
v-if="hiddenCount > 0"
|
|
67
|
+
class="mt-1 pl-5 text-sm text-dimmed"
|
|
68
|
+
>
|
|
69
|
+
{{ t("nuxtUiMongocamp.bulk.moreItems", { count: hiddenCount }) }}
|
|
70
|
+
</p>
|
|
71
|
+
<UAlert
|
|
72
|
+
v-if="error"
|
|
73
|
+
class="mt-3"
|
|
74
|
+
color="error"
|
|
75
|
+
variant="subtle"
|
|
76
|
+
icon="i-lucide-circle-alert"
|
|
77
|
+
:description="error"
|
|
78
|
+
/>
|
|
79
|
+
</template>
|
|
80
|
+
<template #footer>
|
|
81
|
+
<UButton
|
|
82
|
+
:label="t('nuxtUiMongocamp.common.cancel')"
|
|
83
|
+
color="neutral"
|
|
84
|
+
variant="ghost"
|
|
85
|
+
:disabled="deleting"
|
|
86
|
+
@click="isOpen = false"
|
|
87
|
+
/>
|
|
88
|
+
<UButton
|
|
89
|
+
:label="t('nuxtUiMongocamp.bulk.confirmDelete', { count: selected.length })"
|
|
90
|
+
color="error"
|
|
91
|
+
:loading="deleting"
|
|
92
|
+
@click="emit('confirm')"
|
|
93
|
+
/>
|
|
94
|
+
</template>
|
|
95
|
+
</UModal>
|
|
96
|
+
</template>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
type __VLS_Props = {
|
|
2
|
+
selected: string[];
|
|
3
|
+
deleting?: boolean;
|
|
4
|
+
error?: string;
|
|
5
|
+
};
|
|
6
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
7
|
+
open: () => any;
|
|
8
|
+
clear: () => any;
|
|
9
|
+
confirm: () => any;
|
|
10
|
+
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
11
|
+
onOpen?: (() => any) | undefined;
|
|
12
|
+
onClear?: (() => any) | undefined;
|
|
13
|
+
onConfirm?: (() => any) | undefined;
|
|
14
|
+
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
15
|
+
declare const _default: typeof __VLS_export;
|
|
16
|
+
export default _default;
|
|
@@ -1,9 +1,22 @@
|
|
|
1
1
|
<script setup>
|
|
2
|
-
import { h, ref, resolveComponent, watch } from "vue";
|
|
3
|
-
import { useI18n, useMongocampClientApi } from "#imports";
|
|
2
|
+
import { computed, h, ref, resolveComponent, watch } from "vue";
|
|
3
|
+
import { useI18n, useMongocampClientApi, useMongocampError, useMongocampSchema } from "#imports";
|
|
4
4
|
import useMongocampCollection from "../composables/useMongocampCollection";
|
|
5
5
|
import { useMongocampBucket } from "../composables/useMongocampBucket";
|
|
6
6
|
import { unwrapExtendedJson, wrapExtendedJson } from "../composables/useMongocampExtendedJson";
|
|
7
|
+
import { isIsoDateTimeString } from "../utils/isoDate";
|
|
8
|
+
import { downloadTextFile, rowsToCsv } from "../utils/exportRows";
|
|
9
|
+
import { runBulkDelete } from "../utils/bulkDelete";
|
|
10
|
+
import { createSelectColumn } from "../utils/createSelectColumn";
|
|
11
|
+
import {
|
|
12
|
+
buildCondition,
|
|
13
|
+
buildFilterQuery,
|
|
14
|
+
conditionValueText,
|
|
15
|
+
countActiveConditions,
|
|
16
|
+
operatorLabelKey,
|
|
17
|
+
operatorsFor,
|
|
18
|
+
toFilterFieldType
|
|
19
|
+
} from "../utils/filterBuilder";
|
|
7
20
|
import useMongocampDocument from "../composables/useMongocampDocument";
|
|
8
21
|
import { useMongocampQuery } from "../composables/useMongocampQuery";
|
|
9
22
|
const props = defineProps({
|
|
@@ -14,7 +27,8 @@ const { documentApi } = useMongocampClientApi();
|
|
|
14
27
|
const { pagination, total } = useMongocampCollection();
|
|
15
28
|
const { isBucketCollection, fileIdForRow, downloadingFileIds, uploading, downloadFile, uploadFile } = useMongocampBucket();
|
|
16
29
|
const { ensureMetaData } = useMongocampDocument();
|
|
17
|
-
const { like, or } = useMongocampQuery();
|
|
30
|
+
const { and, like, or } = useMongocampQuery();
|
|
31
|
+
const { schemaFromSamples } = useMongocampSchema();
|
|
18
32
|
const fileInputRef = ref(null);
|
|
19
33
|
function openFilePicker() {
|
|
20
34
|
fileInputRef.value?.click();
|
|
@@ -29,6 +43,7 @@ async function handleFileSelected(event) {
|
|
|
29
43
|
}
|
|
30
44
|
const UButton = resolveComponent("UButton");
|
|
31
45
|
const UTooltip = resolveComponent("UTooltip");
|
|
46
|
+
const UCheckbox = resolveComponent("UCheckbox");
|
|
32
47
|
function withTooltip(text, node) {
|
|
33
48
|
return h(UTooltip, { text }, { default: () => node });
|
|
34
49
|
}
|
|
@@ -184,7 +199,23 @@ const documents = ref([]);
|
|
|
184
199
|
const loading = ref(false);
|
|
185
200
|
const filterText = ref("");
|
|
186
201
|
const filterableColumns = ref([]);
|
|
202
|
+
const emptyFilterGroup = () => ({ match: "all", conditions: [] });
|
|
203
|
+
const filtersOpen = ref(false);
|
|
204
|
+
const filterDraft = ref(emptyFilterGroup());
|
|
205
|
+
const appliedFilterGroup = ref(emptyFilterGroup());
|
|
206
|
+
const appliedFilterQuery = ref("");
|
|
207
|
+
const filterFields = ref([]);
|
|
208
|
+
const filterFieldTypes = computed(() => Object.fromEntries(filterFields.value.map((f) => [f.key, f.type])));
|
|
209
|
+
const activeFilterCount = computed(() => countActiveConditions(appliedFilterGroup.value, filterFieldTypes.value));
|
|
210
|
+
const filterChips = computed(
|
|
211
|
+
() => appliedFilterGroup.value.conditions.filter((c) => buildCondition(c, filterFieldTypes.value[c.field] ?? "string") !== "").map((c) => ({
|
|
212
|
+
id: c.id,
|
|
213
|
+
label: [c.field, t(operatorLabelKey(c.operator, filterFieldTypes.value[c.field] ?? "string")), conditionValueText(c)].filter(Boolean).join(" ")
|
|
214
|
+
}))
|
|
215
|
+
);
|
|
187
216
|
const sorting = ref([]);
|
|
217
|
+
const columnVisibility = ref({});
|
|
218
|
+
const PAGE_SIZES = [10, 20, 50, 100];
|
|
188
219
|
const isInitializing = ref(false);
|
|
189
220
|
const detailOpen = ref(false);
|
|
190
221
|
const detailContent = ref("");
|
|
@@ -195,8 +226,8 @@ function openDetail(value) {
|
|
|
195
226
|
}
|
|
196
227
|
function buildLuceneFilter(term) {
|
|
197
228
|
const trimmed = term.trim();
|
|
198
|
-
|
|
199
|
-
return
|
|
229
|
+
const quick = trimmed && filterableColumns.value.length > 0 ? or(...filterableColumns.value.map((col) => like(col, trimmed))) : "";
|
|
230
|
+
return and(quick, appliedFilterQuery.value) || void 0;
|
|
200
231
|
}
|
|
201
232
|
function onFilterInput() {
|
|
202
233
|
clearTimeout(filterTimer);
|
|
@@ -248,6 +279,7 @@ function isMetaData(value) {
|
|
|
248
279
|
return "created" in obj || "updated" in obj;
|
|
249
280
|
}
|
|
250
281
|
const CELL_TEXT_MAX_LENGTH = 60;
|
|
282
|
+
const TIMESTAMP_PREFIX = /^\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}/;
|
|
251
283
|
function truncateText(value, maxLength = CELL_TEXT_MAX_LENGTH) {
|
|
252
284
|
return value.length > maxLength ? `${value.slice(0, maxLength)}...` : value;
|
|
253
285
|
}
|
|
@@ -298,20 +330,52 @@ function makeCell(key, type) {
|
|
|
298
330
|
"onClick": () => openDetail(raw)
|
|
299
331
|
}));
|
|
300
332
|
}
|
|
333
|
+
if (typeof raw === "string" && TIMESTAMP_PREFIX.test(raw) && isIsoDateTimeString(raw)) {
|
|
334
|
+
return h("span", toDateDisplay(raw));
|
|
335
|
+
}
|
|
301
336
|
const text = String(raw);
|
|
302
337
|
const truncated = truncateText(text);
|
|
303
338
|
return h("span", { title: truncated !== text ? text : void 0 }, truncated);
|
|
304
339
|
};
|
|
305
340
|
}
|
|
341
|
+
const loadError = ref(null);
|
|
342
|
+
const filterRejected = ref(false);
|
|
343
|
+
const { describeError } = useMongocampError();
|
|
344
|
+
const rowSelection = ref({});
|
|
345
|
+
const selectedDocIds = computed(() => Object.keys(rowSelection.value).filter((id) => rowSelection.value[id]));
|
|
346
|
+
const bulkDeleting = ref(false);
|
|
347
|
+
const bulkError = ref("");
|
|
348
|
+
function rowId(row, index) {
|
|
349
|
+
return getDocId(row) ?? String(index);
|
|
350
|
+
}
|
|
351
|
+
async function handleBulkDelete() {
|
|
352
|
+
bulkDeleting.value = true;
|
|
353
|
+
bulkError.value = "";
|
|
354
|
+
const ids = [...selectedDocIds.value];
|
|
355
|
+
try {
|
|
356
|
+
const { failed } = await runBulkDelete(ids, (documentId) => documentApi._delete({ collectionName: props.collectionName, documentId }));
|
|
357
|
+
await fetchDocuments();
|
|
358
|
+
if (failed.length > 0) {
|
|
359
|
+
rowSelection.value = Object.fromEntries(failed.map((f) => [f.item, true]));
|
|
360
|
+
bulkError.value = t("nuxtUiMongocamp.bulk.partialFailure", { failed: failed.length, total: ids.length, reason: describeError(failed[0].error).message });
|
|
361
|
+
}
|
|
362
|
+
} finally {
|
|
363
|
+
bulkDeleting.value = false;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
306
366
|
async function fetchDocuments() {
|
|
307
367
|
loading.value = true;
|
|
368
|
+
loadError.value = null;
|
|
369
|
+
rowSelection.value = {};
|
|
370
|
+
filterRejected.value = false;
|
|
371
|
+
const filter = buildLuceneFilter(filterText.value);
|
|
308
372
|
try {
|
|
309
373
|
const res = await documentApi.listDocumentsRaw({
|
|
310
374
|
collectionName: props.collectionName,
|
|
311
375
|
rowsPerPage: pagination.value.pageSize,
|
|
312
376
|
page: pagination.value.pageIndex,
|
|
313
377
|
sort: sorting.value.length ? sortingToMongoSort(sorting.value) : void 0,
|
|
314
|
-
filter
|
|
378
|
+
filter
|
|
315
379
|
});
|
|
316
380
|
total.value = +(res.raw.headers.get("x-pagination-count-rows") ?? 0);
|
|
317
381
|
const rows = await res.value();
|
|
@@ -324,24 +388,102 @@ async function fetchDocuments() {
|
|
|
324
388
|
...keys.filter((k) => k !== "_id" && k !== "metaData").sort(),
|
|
325
389
|
...keys.filter((k) => k === "metaData")
|
|
326
390
|
];
|
|
327
|
-
columns.value = orderedKeys.map((key) => ({
|
|
391
|
+
columns.value = orderedKeys.map((key, index) => ({
|
|
328
392
|
accessorKey: key,
|
|
329
393
|
header: ({ column }) => sortHeader(column, key),
|
|
330
|
-
cell: makeCell(key, "string")
|
|
394
|
+
cell: makeCell(key, "string"),
|
|
395
|
+
// keep the first column (usually _id) pinned so rows stay identifiable when the table scrolls sideways
|
|
396
|
+
...index === 0 ? { meta: { class: { th: "sticky left-0 z-10 bg-default", td: "sticky left-0 z-10 bg-default" } } } : {}
|
|
331
397
|
}));
|
|
332
398
|
filterableColumns.value = orderedKeys.filter((k) => k !== "_id" && k !== "metaData" && typeof firstRow[k] === "string");
|
|
399
|
+
filterFields.value = schemaFromSamples(rows).filter((c) => c.columnKey !== "_id").map((c) => ({ key: c.columnKey, type: toFilterFieldType(c.columnType) })).filter((f) => operatorsFor(f.type).length > 0);
|
|
400
|
+
if (!isBucketCollection(props.collectionName)) {
|
|
401
|
+
columns.value.unshift(createSelectColumn(UCheckbox, { selectAll: t("nuxtUiMongocamp.bulk.selectAll"), selectRow: t("nuxtUiMongocamp.bulk.selectRow") }));
|
|
402
|
+
}
|
|
333
403
|
columns.value.push(makeActionsColumn());
|
|
334
404
|
}
|
|
405
|
+
} catch (e) {
|
|
406
|
+
loadError.value = e;
|
|
407
|
+
documents.value = [];
|
|
408
|
+
total.value = 0;
|
|
409
|
+
if (filter && describeError(e).kind !== "unauthorized") filterRejected.value = await loadsWithoutFilter();
|
|
335
410
|
} finally {
|
|
336
411
|
loading.value = false;
|
|
337
412
|
}
|
|
338
413
|
}
|
|
414
|
+
async function loadsWithoutFilter() {
|
|
415
|
+
try {
|
|
416
|
+
await documentApi.listDocumentsRaw({ collectionName: props.collectionName, rowsPerPage: 1, page: 1 });
|
|
417
|
+
return true;
|
|
418
|
+
} catch {
|
|
419
|
+
return false;
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
function clearAllFilters() {
|
|
423
|
+
filterText.value = "";
|
|
424
|
+
filterDraft.value = emptyFilterGroup();
|
|
425
|
+
onFilterApply("");
|
|
426
|
+
}
|
|
427
|
+
function onFilterApply(query) {
|
|
428
|
+
appliedFilterGroup.value = { match: filterDraft.value.match, conditions: filterDraft.value.conditions.map((c) => ({ ...c })) };
|
|
429
|
+
appliedFilterQuery.value = query;
|
|
430
|
+
pagination.value.pageIndex = 1;
|
|
431
|
+
fetchDocuments();
|
|
432
|
+
}
|
|
433
|
+
function removeFilterChip(id) {
|
|
434
|
+
filterDraft.value = { ...filterDraft.value, conditions: filterDraft.value.conditions.filter((c) => c.id !== id) };
|
|
435
|
+
appliedFilterGroup.value = { ...appliedFilterGroup.value, conditions: appliedFilterGroup.value.conditions.filter((c) => c.id !== id) };
|
|
436
|
+
appliedFilterQuery.value = buildFilterQuery(appliedFilterGroup.value, filterFieldTypes.value);
|
|
437
|
+
pagination.value.pageIndex = 1;
|
|
438
|
+
fetchDocuments();
|
|
439
|
+
}
|
|
440
|
+
function clearFilterChips() {
|
|
441
|
+
filterDraft.value = emptyFilterGroup();
|
|
442
|
+
onFilterApply("");
|
|
443
|
+
}
|
|
444
|
+
function onPageSizeChange() {
|
|
445
|
+
pagination.value.pageIndex = 1;
|
|
446
|
+
fetchDocuments();
|
|
447
|
+
}
|
|
448
|
+
const dataColumnKeys = computed(
|
|
449
|
+
() => columns.value.flatMap((column) => "accessorKey" in column && typeof column.accessorKey === "string" ? [column.accessorKey] : [])
|
|
450
|
+
);
|
|
451
|
+
const columnMenuItems = computed(
|
|
452
|
+
() => dataColumnKeys.value.map((key) => ({
|
|
453
|
+
label: key,
|
|
454
|
+
type: "checkbox",
|
|
455
|
+
checked: columnVisibility.value[key] !== false,
|
|
456
|
+
onUpdateChecked: (checked) => {
|
|
457
|
+
columnVisibility.value = { ...columnVisibility.value, [key]: checked };
|
|
458
|
+
},
|
|
459
|
+
onSelect: (e) => e.preventDefault()
|
|
460
|
+
}))
|
|
461
|
+
);
|
|
462
|
+
function exportPage(format) {
|
|
463
|
+
const rows = documents.value.map((row) => unwrapExtendedJson(row));
|
|
464
|
+
if (format === "json") {
|
|
465
|
+
downloadTextFile(`${props.collectionName}.json`, JSON.stringify(rows, null, 2), "application/json");
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
const keys = dataColumnKeys.value.filter((key) => columnVisibility.value[key] !== false);
|
|
469
|
+
downloadTextFile(`${props.collectionName}.csv`, rowsToCsv(rows, keys), "text/csv");
|
|
470
|
+
}
|
|
471
|
+
const exportMenuItems = computed(() => [
|
|
472
|
+
{ label: t("nuxtUiMongocamp.collectionData.exportJson"), icon: "i-lucide-file-json", onSelect: () => exportPage("json") },
|
|
473
|
+
{ label: t("nuxtUiMongocamp.collectionData.exportCsv"), icon: "i-lucide-file-spreadsheet", onSelect: () => exportPage("csv") }
|
|
474
|
+
]);
|
|
339
475
|
async function init() {
|
|
340
476
|
isInitializing.value = true;
|
|
341
477
|
sorting.value = [];
|
|
342
478
|
pagination.value.pageIndex = 1;
|
|
343
479
|
filterText.value = "";
|
|
344
480
|
filterableColumns.value = [];
|
|
481
|
+
filterFields.value = [];
|
|
482
|
+
filterDraft.value = emptyFilterGroup();
|
|
483
|
+
appliedFilterGroup.value = emptyFilterGroup();
|
|
484
|
+
appliedFilterQuery.value = "";
|
|
485
|
+
filtersOpen.value = false;
|
|
486
|
+
columnVisibility.value = {};
|
|
345
487
|
columns.value = [];
|
|
346
488
|
documents.value = [];
|
|
347
489
|
await fetchDocuments();
|
|
@@ -352,7 +494,7 @@ watch(() => props.collectionName, init, { immediate: true });
|
|
|
352
494
|
|
|
353
495
|
<template>
|
|
354
496
|
<div class="flex flex-col gap-4">
|
|
355
|
-
<div class="flex items-center justify-between gap-4">
|
|
497
|
+
<div class="flex flex-wrap items-center justify-between gap-4">
|
|
356
498
|
<UInput
|
|
357
499
|
v-model="filterText"
|
|
358
500
|
icon="i-lucide-search"
|
|
@@ -362,7 +504,7 @@ watch(() => props.collectionName, init, { immediate: true });
|
|
|
362
504
|
:disabled="filterableColumns.length === 0"
|
|
363
505
|
@input="onFilterInput"
|
|
364
506
|
/>
|
|
365
|
-
<div class="flex items-center gap-2">
|
|
507
|
+
<div class="flex flex-wrap items-center gap-2">
|
|
366
508
|
<span class="text-sm text-gray-500 dark:text-gray-400 shrink-0">
|
|
367
509
|
{{ t("nuxtUiMongocamp.collectionData.documentsCount", { count: total }) }}
|
|
368
510
|
</span>
|
|
@@ -409,6 +551,50 @@ watch(() => props.collectionName, init, { immediate: true });
|
|
|
409
551
|
@click="init"
|
|
410
552
|
/>
|
|
411
553
|
</UTooltip>
|
|
554
|
+
<UChip
|
|
555
|
+
:text="activeFilterCount"
|
|
556
|
+
:show="activeFilterCount > 0"
|
|
557
|
+
size="sm"
|
|
558
|
+
>
|
|
559
|
+
<UButton
|
|
560
|
+
icon="i-lucide-list-filter"
|
|
561
|
+
color="neutral"
|
|
562
|
+
:variant="filtersOpen ? 'subtle' : 'ghost'"
|
|
563
|
+
size="sm"
|
|
564
|
+
:disabled="filterFields.length === 0"
|
|
565
|
+
:aria-pressed="filtersOpen"
|
|
566
|
+
:aria-label="t('nuxtUiMongocamp.collectionData.filtersTooltip')"
|
|
567
|
+
@click="filtersOpen = !filtersOpen"
|
|
568
|
+
/>
|
|
569
|
+
</UChip>
|
|
570
|
+
<UDropdownMenu :items="columnMenuItems">
|
|
571
|
+
<UButton
|
|
572
|
+
icon="i-lucide-columns-3"
|
|
573
|
+
color="neutral"
|
|
574
|
+
variant="ghost"
|
|
575
|
+
size="sm"
|
|
576
|
+
:disabled="dataColumnKeys.length === 0"
|
|
577
|
+
:aria-label="t('nuxtUiMongocamp.collectionData.columnsTooltip')"
|
|
578
|
+
/>
|
|
579
|
+
</UDropdownMenu>
|
|
580
|
+
<UDropdownMenu :items="exportMenuItems">
|
|
581
|
+
<UButton
|
|
582
|
+
icon="i-lucide-download"
|
|
583
|
+
color="neutral"
|
|
584
|
+
variant="ghost"
|
|
585
|
+
size="sm"
|
|
586
|
+
:disabled="documents.length === 0"
|
|
587
|
+
:aria-label="t('nuxtUiMongocamp.collectionData.exportTooltip')"
|
|
588
|
+
/>
|
|
589
|
+
</UDropdownMenu>
|
|
590
|
+
<USelect
|
|
591
|
+
v-model="pagination.pageSize"
|
|
592
|
+
:items="PAGE_SIZES"
|
|
593
|
+
size="sm"
|
|
594
|
+
class="w-20"
|
|
595
|
+
:aria-label="t('nuxtUiMongocamp.collectionData.pageSizeLabel')"
|
|
596
|
+
@update:model-value="onPageSizeChange"
|
|
597
|
+
/>
|
|
412
598
|
<UPagination
|
|
413
599
|
v-model:page="pagination.pageIndex"
|
|
414
600
|
:total="total"
|
|
@@ -417,13 +603,74 @@ watch(() => props.collectionName, init, { immediate: true });
|
|
|
417
603
|
/>
|
|
418
604
|
</div>
|
|
419
605
|
</div>
|
|
606
|
+
<MongocampFilterBuilder
|
|
607
|
+
v-if="filtersOpen"
|
|
608
|
+
v-model="filterDraft"
|
|
609
|
+
:fields="filterFields"
|
|
610
|
+
@apply="onFilterApply"
|
|
611
|
+
/>
|
|
612
|
+
|
|
613
|
+
<div
|
|
614
|
+
v-if="filterChips.length > 0"
|
|
615
|
+
class="flex flex-wrap items-center gap-2"
|
|
616
|
+
>
|
|
617
|
+
<UBadge
|
|
618
|
+
v-for="chip in filterChips"
|
|
619
|
+
:key="chip.id"
|
|
620
|
+
color="neutral"
|
|
621
|
+
variant="subtle"
|
|
622
|
+
class="gap-1"
|
|
623
|
+
>
|
|
624
|
+
{{ chip.label }}
|
|
625
|
+
<UButton
|
|
626
|
+
icon="i-lucide-x"
|
|
627
|
+
color="neutral"
|
|
628
|
+
variant="link"
|
|
629
|
+
size="xs"
|
|
630
|
+
class="p-0"
|
|
631
|
+
:aria-label="t('nuxtUiMongocamp.collectionData.removeFilter', { filter: chip.label })"
|
|
632
|
+
@click="removeFilterChip(chip.id)"
|
|
633
|
+
/>
|
|
634
|
+
</UBadge>
|
|
635
|
+
<UButton
|
|
636
|
+
color="neutral"
|
|
637
|
+
variant="link"
|
|
638
|
+
size="xs"
|
|
639
|
+
:label="t('nuxtUiMongocamp.collectionData.clearFilters')"
|
|
640
|
+
@click="clearFilterChips"
|
|
641
|
+
/>
|
|
642
|
+
</div>
|
|
643
|
+
|
|
644
|
+
<MongocampErrorAlert
|
|
645
|
+
:error="loadError"
|
|
646
|
+
:filter-rejected="filterRejected"
|
|
647
|
+
@retry="fetchDocuments"
|
|
648
|
+
@clear-filters="clearAllFilters"
|
|
649
|
+
/>
|
|
650
|
+
|
|
651
|
+
<MongocampBulkDelete
|
|
652
|
+
:selected="selectedDocIds"
|
|
653
|
+
:deleting="bulkDeleting"
|
|
654
|
+
:error="bulkError"
|
|
655
|
+
@open="bulkError = ''"
|
|
656
|
+
@clear="rowSelection = {}"
|
|
657
|
+
@confirm="handleBulkDelete"
|
|
658
|
+
/>
|
|
659
|
+
|
|
420
660
|
<UTable
|
|
421
661
|
v-model:sorting="sorting"
|
|
662
|
+
v-model:column-visibility="columnVisibility"
|
|
663
|
+
v-model:row-selection="rowSelection"
|
|
664
|
+
:get-row-id="rowId"
|
|
422
665
|
:sorting-options="{ manualSorting: true }"
|
|
423
666
|
:data="documents"
|
|
424
667
|
:columns="columns"
|
|
425
668
|
:loading="loading"
|
|
426
|
-
|
|
669
|
+
>
|
|
670
|
+
<template #empty>
|
|
671
|
+
<MongocampEmptyState :title="t('nuxtUiMongocamp.empty.documents')" />
|
|
672
|
+
</template>
|
|
673
|
+
</UTable>
|
|
427
674
|
|
|
428
675
|
<UModal
|
|
429
676
|
v-model:open="detailOpen"
|
|
@@ -64,7 +64,7 @@ async function copySchemaAsTs() {
|
|
|
64
64
|
await navigator.clipboard.writeText(tsInterface.value);
|
|
65
65
|
toast.add({ title: t("nuxtUiMongocamp.collectionInfos.copiedTitle"), description: t("nuxtUiMongocamp.collectionInfos.copiedDescription"), color: "success" });
|
|
66
66
|
}
|
|
67
|
-
const schemaTableColumns = [
|
|
67
|
+
const schemaTableColumns = computed(() => [
|
|
68
68
|
{
|
|
69
69
|
accessorKey: "field",
|
|
70
70
|
header: t("nuxtUiMongocamp.collectionInfos.columnField")
|
|
@@ -83,7 +83,7 @@ const schemaTableColumns = [
|
|
|
83
83
|
header: t("nuxtUiMongocamp.collectionInfos.columnInAllSamples"),
|
|
84
84
|
cell: ({ row }) => row.original.required ? h(UIcon, { name: "i-lucide-check", class: "size-4 text-success" }) : h("span", { class: "text-dimmed" }, "\u2014")
|
|
85
85
|
}
|
|
86
|
-
];
|
|
86
|
+
]);
|
|
87
87
|
const indexRows = computed(
|
|
88
88
|
() => indexes.value.map((idx) => ({
|
|
89
89
|
name: idx.name,
|
|
@@ -181,7 +181,7 @@ const INDEX_FLAG_BADGES = [
|
|
|
181
181
|
{ key: "text", label: "text", color: "info" },
|
|
182
182
|
{ key: "expire", label: "expire", color: "secondary" }
|
|
183
183
|
];
|
|
184
|
-
const indexTableColumns = [
|
|
184
|
+
const indexTableColumns = computed(() => [
|
|
185
185
|
{
|
|
186
186
|
accessorKey: "name",
|
|
187
187
|
header: t("nuxtUiMongocamp.collectionInfos.columnIndex")
|
|
@@ -194,7 +194,13 @@ const indexTableColumns = [
|
|
|
194
194
|
{
|
|
195
195
|
id: "flags",
|
|
196
196
|
header: t("nuxtUiMongocamp.collectionInfos.columnType"),
|
|
197
|
-
cell: ({ row }) =>
|
|
197
|
+
cell: ({ row }) => {
|
|
198
|
+
const badges = INDEX_FLAG_BADGES.filter((flag) => row.original[flag.key]).map((flag) => h(UBadge, { label: flag.label, color: flag.color, variant: "subtle", size: "sm" }));
|
|
199
|
+
if (badges.length === 0) {
|
|
200
|
+
badges.push(h(UBadge, { label: t("nuxtUiMongocamp.collectionInfos.typeStandard"), color: "neutral", variant: "subtle", size: "sm" }));
|
|
201
|
+
}
|
|
202
|
+
return h("div", { class: "flex gap-1" }, badges);
|
|
203
|
+
}
|
|
198
204
|
},
|
|
199
205
|
{
|
|
200
206
|
accessorKey: "sizeKb",
|
|
@@ -214,7 +220,7 @@ const indexTableColumns = [
|
|
|
214
220
|
}))
|
|
215
221
|
])
|
|
216
222
|
}
|
|
217
|
-
];
|
|
223
|
+
]);
|
|
218
224
|
</script>
|
|
219
225
|
|
|
220
226
|
<template>
|