@sfxcode/nuxt-ui-mongocamp 1.1.3 → 1.2.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 +31 -9
- package/dist/module.d.mts +22 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +41 -5
- package/dist/runtime/components/MongocampAccount.vue +21 -20
- package/dist/runtime/components/MongocampBucketFiles.d.vue.ts +6 -0
- package/dist/runtime/components/MongocampBucketFiles.vue +364 -0
- package/dist/runtime/components/MongocampBucketFiles.vue.d.ts +6 -0
- package/dist/runtime/components/MongocampCollectionData.vue +36 -35
- package/dist/runtime/components/MongocampCollectionInfos.vue +37 -36
- package/dist/runtime/components/MongocampCollections.d.vue.ts +1 -0
- package/dist/runtime/components/MongocampCollections.vue +38 -28
- package/dist/runtime/components/MongocampCollections.vue.d.ts +1 -0
- package/dist/runtime/components/MongocampDatabases.vue +13 -12
- package/dist/runtime/components/MongocampJobs.vue +43 -45
- package/dist/runtime/components/MongocampLogin.d.vue.ts +4 -1
- package/dist/runtime/components/MongocampLogin.vue +13 -9
- package/dist/runtime/components/MongocampLogin.vue.d.ts +4 -1
- package/dist/runtime/components/MongocampRoleGrants.vue +30 -28
- package/dist/runtime/components/MongocampRoles.vue +30 -31
- package/dist/runtime/components/MongocampUsers.vue +35 -36
- package/dist/runtime/components/MongocampVersion.vue +3 -1
- package/dist/runtime/composables/useMongocampAccount.js +6 -5
- package/dist/runtime/composables/useMongocampAdmin.js +2 -2
- package/dist/runtime/composables/useMongocampBucket.d.ts +20 -1
- package/dist/runtime/composables/useMongocampBucket.js +62 -13
- package/dist/runtime/composables/useMongocampClientApi.d.ts +13 -0
- package/dist/runtime/composables/useMongocampClientApi.js +8 -0
- package/dist/runtime/composables/useMongocampIndex.js +2 -2
- package/dist/runtime/composables/useMongocampJobs.js +2 -2
- package/dist/runtime/composables/useMongocampProxyApi.d.ts +13 -0
- package/dist/runtime/composables/useMongocampProxyApi.js +9 -0
- package/dist/runtime/composables/useMongocampRoles.d.ts +2 -0
- package/dist/runtime/composables/useMongocampRoles.js +4 -2
- package/dist/runtime/composables/useMongocampSystem.js +2 -2
- package/dist/runtime/locales/de.json +265 -0
- package/dist/runtime/locales/en.json +265 -0
- package/dist/runtime/plugin.js +8 -8
- package/dist/runtime/server/handlers/mongocampProxy.d.ts +2 -0
- package/dist/runtime/server/handlers/mongocampProxy.js +45 -0
- package/dist/runtime/utils/createProxyMongocampApis.d.ts +15 -0
- package/dist/runtime/utils/createProxyMongocampApis.js +28 -0
- package/package.json +13 -6
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { h, reactive, ref, resolveComponent, watch } from "vue";
|
|
3
|
+
import { useI18n } from "#imports";
|
|
4
|
+
import useMongocampCollection from "../composables/useMongocampCollection";
|
|
5
|
+
import { useMongocampBucket } from "../composables/useMongocampBucket";
|
|
6
|
+
import { useMongocampQuery } from "../composables/useMongocampQuery";
|
|
7
|
+
const props = defineProps({
|
|
8
|
+
bucketName: { type: String, required: true }
|
|
9
|
+
});
|
|
10
|
+
const { t } = useI18n();
|
|
11
|
+
const { pagination, total } = useMongocampCollection();
|
|
12
|
+
const {
|
|
13
|
+
listFiles,
|
|
14
|
+
deleteFile,
|
|
15
|
+
updateFileInformation,
|
|
16
|
+
downloadFile,
|
|
17
|
+
downloadingFileIds,
|
|
18
|
+
uploadFile,
|
|
19
|
+
uploading,
|
|
20
|
+
fileActionInFlight
|
|
21
|
+
} = useMongocampBucket();
|
|
22
|
+
const { like } = useMongocampQuery();
|
|
23
|
+
const fileInputRef = ref(null);
|
|
24
|
+
function openFilePicker() {
|
|
25
|
+
fileInputRef.value?.click();
|
|
26
|
+
}
|
|
27
|
+
async function handleFileSelected(event) {
|
|
28
|
+
const input = event.target;
|
|
29
|
+
const file = input.files?.[0];
|
|
30
|
+
input.value = "";
|
|
31
|
+
if (!file) return;
|
|
32
|
+
const success = await uploadFile(props.bucketName, file);
|
|
33
|
+
if (success) await fetchFiles();
|
|
34
|
+
}
|
|
35
|
+
const UButton = resolveComponent("UButton");
|
|
36
|
+
const UTooltip = resolveComponent("UTooltip");
|
|
37
|
+
function withTooltip(text, node) {
|
|
38
|
+
return h(UTooltip, { text }, { default: () => node });
|
|
39
|
+
}
|
|
40
|
+
function sortHeader(column, label) {
|
|
41
|
+
const isSorted = column.getIsSorted();
|
|
42
|
+
return h(UButton, {
|
|
43
|
+
color: "neutral",
|
|
44
|
+
variant: "ghost",
|
|
45
|
+
label,
|
|
46
|
+
icon: isSorted === "asc" ? "i-lucide-arrow-up-narrow-wide" : isSorted === "desc" ? "i-lucide-arrow-down-wide-narrow" : "i-lucide-arrow-up-down",
|
|
47
|
+
class: "-mx-2.5",
|
|
48
|
+
onClick: () => column.toggleSorting(isSorted === "asc")
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
function sortingToMongoSort(s) {
|
|
52
|
+
return s.map((col) => col.desc ? `-${col.id}` : col.id);
|
|
53
|
+
}
|
|
54
|
+
const BYTE_UNITS = ["B", "KB", "MB", "GB", "TB"];
|
|
55
|
+
function formatBytes(length) {
|
|
56
|
+
if (!length) return "0 B";
|
|
57
|
+
const exponent = Math.min(Math.floor(Math.log(length) / Math.log(1024)), BYTE_UNITS.length - 1);
|
|
58
|
+
const value = length / 1024 ** exponent;
|
|
59
|
+
return `${exponent === 0 ? value : value.toFixed(1)} ${BYTE_UNITS[exponent]}`;
|
|
60
|
+
}
|
|
61
|
+
function formatDate(value) {
|
|
62
|
+
try {
|
|
63
|
+
return new Date(value).toLocaleString();
|
|
64
|
+
} catch {
|
|
65
|
+
return String(value);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const detailOpen = ref(false);
|
|
69
|
+
const detailContent = ref("");
|
|
70
|
+
function openMetadataDetail(metadata) {
|
|
71
|
+
detailContent.value = JSON.stringify(metadata, null, 2);
|
|
72
|
+
detailOpen.value = true;
|
|
73
|
+
}
|
|
74
|
+
function makeMetadataCell() {
|
|
75
|
+
return ({ row }) => {
|
|
76
|
+
const metadata = row.original.metadata ?? {};
|
|
77
|
+
const keys = Object.keys(metadata);
|
|
78
|
+
if (keys.length === 0) return h("span", { class: "text-dimmed" }, "\u2014");
|
|
79
|
+
return withTooltip(t("nuxtUiMongocamp.bucketFiles.viewMetadataTooltip"), h(UButton, {
|
|
80
|
+
"icon": "i-lucide-braces",
|
|
81
|
+
"color": "neutral",
|
|
82
|
+
"variant": "ghost",
|
|
83
|
+
"size": "xs",
|
|
84
|
+
"label": keys.length === 1 ? t("nuxtUiMongocamp.bucketFiles.keyCount") : t("nuxtUiMongocamp.bucketFiles.keysCount", { count: keys.length }),
|
|
85
|
+
"aria-label": t("nuxtUiMongocamp.bucketFiles.viewMetadataTooltip"),
|
|
86
|
+
"onClick": () => openMetadataDetail(metadata)
|
|
87
|
+
}));
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
const isRenameModalOpen = ref(false);
|
|
91
|
+
const fileToRename = ref(void 0);
|
|
92
|
+
const renameData = ref({ filename: "", metadata: [] });
|
|
93
|
+
const renameSchema = reactive([
|
|
94
|
+
{
|
|
95
|
+
$formkit: "nuxtUIInput",
|
|
96
|
+
name: "filename",
|
|
97
|
+
label: t("nuxtUiMongocamp.bucketFiles.filename"),
|
|
98
|
+
validation: "required"
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
$formkit: "nuxtUIRepeater",
|
|
102
|
+
name: "metadata",
|
|
103
|
+
label: t("nuxtUiMongocamp.bucketFiles.columnMetadata"),
|
|
104
|
+
children: [
|
|
105
|
+
{ $formkit: "nuxtUIInput", name: "key", label: t("nuxtUiMongocamp.bucketFiles.metadataKey") },
|
|
106
|
+
{ $formkit: "nuxtUIInput", name: "value", label: t("nuxtUiMongocamp.bucketFiles.metadataValue") }
|
|
107
|
+
]
|
|
108
|
+
}
|
|
109
|
+
]);
|
|
110
|
+
function openRename(file) {
|
|
111
|
+
fileToRename.value = file;
|
|
112
|
+
renameData.value = {
|
|
113
|
+
filename: file.filename,
|
|
114
|
+
metadata: Object.entries(file.metadata ?? {}).map(([key, value]) => ({ key, value }))
|
|
115
|
+
};
|
|
116
|
+
isRenameModalOpen.value = true;
|
|
117
|
+
}
|
|
118
|
+
async function handleRenameSave() {
|
|
119
|
+
if (!fileToRename.value) return;
|
|
120
|
+
const metadata = {};
|
|
121
|
+
for (const entry of renameData.value.metadata) {
|
|
122
|
+
if (entry.key) metadata[entry.key] = entry.value;
|
|
123
|
+
}
|
|
124
|
+
const success = await updateFileInformation(props.bucketName, fileToRename.value.id, {
|
|
125
|
+
filename: renameData.value.filename,
|
|
126
|
+
metadata
|
|
127
|
+
});
|
|
128
|
+
if (success) {
|
|
129
|
+
isRenameModalOpen.value = false;
|
|
130
|
+
await fetchFiles();
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
const isDeleteModalOpen = ref(false);
|
|
134
|
+
const fileToDelete = ref(void 0);
|
|
135
|
+
function confirmDeleteFile(file) {
|
|
136
|
+
fileToDelete.value = file;
|
|
137
|
+
isDeleteModalOpen.value = true;
|
|
138
|
+
}
|
|
139
|
+
async function handleDeleteFile() {
|
|
140
|
+
if (!fileToDelete.value) return;
|
|
141
|
+
const success = await deleteFile(props.bucketName, fileToDelete.value.id);
|
|
142
|
+
if (success) {
|
|
143
|
+
isDeleteModalOpen.value = false;
|
|
144
|
+
await fetchFiles();
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
function makeActionsColumn() {
|
|
148
|
+
return {
|
|
149
|
+
id: "actions",
|
|
150
|
+
header: "",
|
|
151
|
+
cell: ({ row }) => {
|
|
152
|
+
const file = row.original;
|
|
153
|
+
return h("div", { class: "flex gap-1 justify-end" }, [
|
|
154
|
+
withTooltip(t("nuxtUiMongocamp.bucketFiles.downloadFileTooltip"), h(UButton, {
|
|
155
|
+
"icon": "i-lucide-download",
|
|
156
|
+
"color": "neutral",
|
|
157
|
+
"variant": "ghost",
|
|
158
|
+
"size": "sm",
|
|
159
|
+
"aria-label": t("nuxtUiMongocamp.bucketFiles.downloadFileTooltip"),
|
|
160
|
+
"loading": downloadingFileIds.value.has(file.id),
|
|
161
|
+
"onClick": () => downloadFile(props.bucketName, file.id)
|
|
162
|
+
})),
|
|
163
|
+
withTooltip(t("nuxtUiMongocamp.bucketFiles.renameTooltip"), h(UButton, {
|
|
164
|
+
"icon": "i-lucide-pencil",
|
|
165
|
+
"color": "neutral",
|
|
166
|
+
"variant": "ghost",
|
|
167
|
+
"size": "sm",
|
|
168
|
+
"aria-label": t("nuxtUiMongocamp.bucketFiles.renameTooltip"),
|
|
169
|
+
"loading": fileActionInFlight.value.has(file.id),
|
|
170
|
+
"onClick": () => openRename(file)
|
|
171
|
+
})),
|
|
172
|
+
withTooltip(t("nuxtUiMongocamp.bucketFiles.deleteFileTooltip"), h(UButton, {
|
|
173
|
+
"icon": "i-lucide-trash-2",
|
|
174
|
+
"color": "error",
|
|
175
|
+
"variant": "ghost",
|
|
176
|
+
"size": "sm",
|
|
177
|
+
"aria-label": t("nuxtUiMongocamp.bucketFiles.deleteFileTooltip"),
|
|
178
|
+
"loading": fileActionInFlight.value.has(file.id),
|
|
179
|
+
"onClick": () => confirmDeleteFile(file)
|
|
180
|
+
}))
|
|
181
|
+
]);
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
const columns = ref([
|
|
186
|
+
{
|
|
187
|
+
accessorKey: "filename",
|
|
188
|
+
header: ({ column }) => sortHeader(column, t("nuxtUiMongocamp.bucketFiles.columnFilename")),
|
|
189
|
+
cell: ({ row }) => h("span", row.original.filename)
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
accessorKey: "length",
|
|
193
|
+
header: ({ column }) => sortHeader(column, t("nuxtUiMongocamp.bucketFiles.columnSize")),
|
|
194
|
+
cell: ({ row }) => h("span", formatBytes(row.original.length))
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
accessorKey: "uploadDate",
|
|
198
|
+
header: ({ column }) => sortHeader(column, t("nuxtUiMongocamp.bucketFiles.columnUploaded")),
|
|
199
|
+
cell: ({ row }) => h("span", formatDate(row.original.uploadDate))
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
id: "metadata",
|
|
203
|
+
header: t("nuxtUiMongocamp.bucketFiles.columnMetadata"),
|
|
204
|
+
cell: makeMetadataCell()
|
|
205
|
+
},
|
|
206
|
+
makeActionsColumn()
|
|
207
|
+
]);
|
|
208
|
+
const files = ref([]);
|
|
209
|
+
const loading = ref(false);
|
|
210
|
+
const filterText = ref("");
|
|
211
|
+
const sorting = ref([]);
|
|
212
|
+
const isInitializing = ref(false);
|
|
213
|
+
let filterTimer;
|
|
214
|
+
function buildLuceneFilter(term) {
|
|
215
|
+
const trimmed = term.trim();
|
|
216
|
+
return trimmed ? like("filename", trimmed) : void 0;
|
|
217
|
+
}
|
|
218
|
+
function onFilterInput() {
|
|
219
|
+
clearTimeout(filterTimer);
|
|
220
|
+
filterTimer = setTimeout(() => {
|
|
221
|
+
pagination.value.pageIndex = 1;
|
|
222
|
+
fetchFiles();
|
|
223
|
+
}, 300);
|
|
224
|
+
}
|
|
225
|
+
watch(sorting, () => {
|
|
226
|
+
if (isInitializing.value) return;
|
|
227
|
+
pagination.value.pageIndex = 1;
|
|
228
|
+
fetchFiles();
|
|
229
|
+
});
|
|
230
|
+
async function fetchFiles() {
|
|
231
|
+
loading.value = true;
|
|
232
|
+
try {
|
|
233
|
+
const result = await listFiles(props.bucketName, {
|
|
234
|
+
rowsPerPage: pagination.value.pageSize,
|
|
235
|
+
page: pagination.value.pageIndex,
|
|
236
|
+
sort: sorting.value.length ? sortingToMongoSort(sorting.value).join(",") : void 0,
|
|
237
|
+
filter: buildLuceneFilter(filterText.value)
|
|
238
|
+
});
|
|
239
|
+
total.value = result.total;
|
|
240
|
+
files.value = result.files;
|
|
241
|
+
} finally {
|
|
242
|
+
loading.value = false;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
async function init() {
|
|
246
|
+
isInitializing.value = true;
|
|
247
|
+
sorting.value = [];
|
|
248
|
+
pagination.value.pageIndex = 1;
|
|
249
|
+
filterText.value = "";
|
|
250
|
+
files.value = [];
|
|
251
|
+
await fetchFiles();
|
|
252
|
+
isInitializing.value = false;
|
|
253
|
+
}
|
|
254
|
+
watch(() => props.bucketName, init, { immediate: true });
|
|
255
|
+
</script>
|
|
256
|
+
|
|
257
|
+
<template>
|
|
258
|
+
<div class="flex flex-col gap-4">
|
|
259
|
+
<div class="flex items-center justify-between gap-4">
|
|
260
|
+
<UInput
|
|
261
|
+
v-model="filterText"
|
|
262
|
+
icon="i-lucide-search"
|
|
263
|
+
:placeholder="t('nuxtUiMongocamp.bucketFiles.filterPlaceholder')"
|
|
264
|
+
size="sm"
|
|
265
|
+
class="flex-1 max-w-xs"
|
|
266
|
+
@input="onFilterInput"
|
|
267
|
+
/>
|
|
268
|
+
<div class="flex items-center gap-2">
|
|
269
|
+
<span class="text-sm text-gray-500 dark:text-gray-400 shrink-0">
|
|
270
|
+
{{ t("nuxtUiMongocamp.bucketFiles.filesCount", { count: total }) }}
|
|
271
|
+
</span>
|
|
272
|
+
<UTooltip :text="t('nuxtUiMongocamp.bucketFiles.uploadFileTooltip')">
|
|
273
|
+
<UButton
|
|
274
|
+
icon="i-lucide-upload"
|
|
275
|
+
color="primary"
|
|
276
|
+
variant="ghost"
|
|
277
|
+
size="sm"
|
|
278
|
+
:loading="uploading"
|
|
279
|
+
:aria-label="t('nuxtUiMongocamp.bucketFiles.uploadFileTooltip')"
|
|
280
|
+
@click="openFilePicker"
|
|
281
|
+
/>
|
|
282
|
+
</UTooltip>
|
|
283
|
+
<input
|
|
284
|
+
ref="fileInputRef"
|
|
285
|
+
type="file"
|
|
286
|
+
class="hidden"
|
|
287
|
+
@change="handleFileSelected"
|
|
288
|
+
>
|
|
289
|
+
<UTooltip :text="t('nuxtUiMongocamp.bucketFiles.reloadTooltip')">
|
|
290
|
+
<UButton
|
|
291
|
+
icon="i-lucide-refresh-cw"
|
|
292
|
+
color="neutral"
|
|
293
|
+
variant="ghost"
|
|
294
|
+
:loading="loading"
|
|
295
|
+
:aria-label="t('nuxtUiMongocamp.bucketFiles.reloadTooltip')"
|
|
296
|
+
@click="init"
|
|
297
|
+
/>
|
|
298
|
+
</UTooltip>
|
|
299
|
+
<UPagination
|
|
300
|
+
v-model:page="pagination.pageIndex"
|
|
301
|
+
:total="total"
|
|
302
|
+
:items-per-page="pagination.pageSize"
|
|
303
|
+
@update:page="fetchFiles"
|
|
304
|
+
/>
|
|
305
|
+
</div>
|
|
306
|
+
</div>
|
|
307
|
+
<UTable
|
|
308
|
+
v-model:sorting="sorting"
|
|
309
|
+
:sorting-options="{ manualSorting: true }"
|
|
310
|
+
:data="files"
|
|
311
|
+
:columns="columns"
|
|
312
|
+
:loading="loading"
|
|
313
|
+
/>
|
|
314
|
+
|
|
315
|
+
<UModal
|
|
316
|
+
v-model:open="detailOpen"
|
|
317
|
+
:title="t('nuxtUiMongocamp.bucketFiles.metadataTitle')"
|
|
318
|
+
>
|
|
319
|
+
<template #body>
|
|
320
|
+
<pre class="text-xs overflow-auto max-h-[60vh] whitespace-pre-wrap break-all">{{ detailContent }}</pre>
|
|
321
|
+
</template>
|
|
322
|
+
</UModal>
|
|
323
|
+
|
|
324
|
+
<UModal
|
|
325
|
+
v-model:open="isRenameModalOpen"
|
|
326
|
+
:title="t('nuxtUiMongocamp.bucketFiles.renameTitle')"
|
|
327
|
+
:ui="{ footer: 'justify-end' }"
|
|
328
|
+
>
|
|
329
|
+
<template #body>
|
|
330
|
+
<FUDataEdit
|
|
331
|
+
:data="renameData"
|
|
332
|
+
:schema="renameSchema"
|
|
333
|
+
:submit-label="t('nuxtUiMongocamp.common.save')"
|
|
334
|
+
submit-icon="i-lucide-save"
|
|
335
|
+
@data-saved="handleRenameSave"
|
|
336
|
+
/>
|
|
337
|
+
</template>
|
|
338
|
+
</UModal>
|
|
339
|
+
|
|
340
|
+
<UModal
|
|
341
|
+
v-model:open="isDeleteModalOpen"
|
|
342
|
+
:title="t('nuxtUiMongocamp.bucketFiles.deleteFileTitle')"
|
|
343
|
+
:ui="{ footer: 'justify-end' }"
|
|
344
|
+
>
|
|
345
|
+
<template #body>
|
|
346
|
+
<p>{{ t("nuxtUiMongocamp.bucketFiles.confirmDeleteFile") }}</p>
|
|
347
|
+
</template>
|
|
348
|
+
<template #footer>
|
|
349
|
+
<UButton
|
|
350
|
+
:label="t('nuxtUiMongocamp.common.cancel')"
|
|
351
|
+
color="neutral"
|
|
352
|
+
variant="ghost"
|
|
353
|
+
@click="isDeleteModalOpen = false"
|
|
354
|
+
/>
|
|
355
|
+
<UButton
|
|
356
|
+
:label="t('nuxtUiMongocamp.common.delete')"
|
|
357
|
+
color="error"
|
|
358
|
+
icon="i-lucide-trash-2"
|
|
359
|
+
@click="handleDeleteFile"
|
|
360
|
+
/>
|
|
361
|
+
</template>
|
|
362
|
+
</UModal>
|
|
363
|
+
</div>
|
|
364
|
+
</template>
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
type __VLS_Props = {
|
|
2
|
+
bucketName: string;
|
|
3
|
+
};
|
|
4
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
5
|
+
declare const _default: typeof __VLS_export;
|
|
6
|
+
export default _default;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script setup>
|
|
2
2
|
import { h, ref, resolveComponent, watch } from "vue";
|
|
3
|
-
import {
|
|
3
|
+
import { useI18n, useMongocampClientApi } from "#imports";
|
|
4
4
|
import useMongocampCollection from "../composables/useMongocampCollection";
|
|
5
5
|
import { useMongocampBucket } from "../composables/useMongocampBucket";
|
|
6
6
|
import { unwrapExtendedJson, wrapExtendedJson } from "../composables/useMongocampExtendedJson";
|
|
@@ -9,7 +9,8 @@ import { useMongocampQuery } from "../composables/useMongocampQuery";
|
|
|
9
9
|
const props = defineProps({
|
|
10
10
|
collectionName: { type: String, required: true }
|
|
11
11
|
});
|
|
12
|
-
const {
|
|
12
|
+
const { t } = useI18n();
|
|
13
|
+
const { documentApi } = useMongocampClientApi();
|
|
13
14
|
const { pagination, total } = useMongocampCollection();
|
|
14
15
|
const { isBucketCollection, fileIdForRow, downloadingFileIds, uploading, downloadFile, uploadFile } = useMongocampBucket();
|
|
15
16
|
const { ensureMetaData } = useMongocampDocument();
|
|
@@ -94,7 +95,7 @@ async function handleSave() {
|
|
|
94
95
|
try {
|
|
95
96
|
payload = JSON.parse(editJson.value);
|
|
96
97
|
} catch {
|
|
97
|
-
editError.value = "
|
|
98
|
+
editError.value = t("nuxtUiMongocamp.collectionData.invalidJson");
|
|
98
99
|
return;
|
|
99
100
|
}
|
|
100
101
|
}
|
|
@@ -111,7 +112,7 @@ async function handleSave() {
|
|
|
111
112
|
isEditModalOpen.value = false;
|
|
112
113
|
await fetchDocuments();
|
|
113
114
|
} catch (e) {
|
|
114
|
-
editError.value = e instanceof Error ? e.message : "
|
|
115
|
+
editError.value = e instanceof Error ? e.message : t("nuxtUiMongocamp.collectionData.errorSave");
|
|
115
116
|
}
|
|
116
117
|
}
|
|
117
118
|
async function handleDelete() {
|
|
@@ -122,7 +123,7 @@ async function handleDelete() {
|
|
|
122
123
|
isDeleteModalOpen.value = false;
|
|
123
124
|
await fetchDocuments();
|
|
124
125
|
} catch (e) {
|
|
125
|
-
deleteError.value = e instanceof Error ? e.message : "
|
|
126
|
+
deleteError.value = e instanceof Error ? e.message : t("nuxtUiMongocamp.collectionData.errorDelete");
|
|
126
127
|
}
|
|
127
128
|
}
|
|
128
129
|
function makeActionsColumn() {
|
|
@@ -134,32 +135,32 @@ function makeActionsColumn() {
|
|
|
134
135
|
if (isBucketCollection(props.collectionName)) {
|
|
135
136
|
const fileId = fileIdForRow(props.collectionName, row.original);
|
|
136
137
|
if (fileId) {
|
|
137
|
-
buttons.push(withTooltip("
|
|
138
|
+
buttons.push(withTooltip(t("nuxtUiMongocamp.collectionData.downloadFileTooltip"), h(UButton, {
|
|
138
139
|
"icon": "i-lucide-download",
|
|
139
140
|
"color": "neutral",
|
|
140
141
|
"variant": "ghost",
|
|
141
142
|
"size": "sm",
|
|
142
|
-
"aria-label": "
|
|
143
|
+
"aria-label": t("nuxtUiMongocamp.collectionData.downloadFileTooltip"),
|
|
143
144
|
"loading": downloadingFileIds.value.has(fileId),
|
|
144
145
|
"onClick": () => downloadFile(props.collectionName, fileId)
|
|
145
146
|
})));
|
|
146
147
|
}
|
|
147
148
|
}
|
|
148
149
|
buttons.push(
|
|
149
|
-
withTooltip("
|
|
150
|
+
withTooltip(t("nuxtUiMongocamp.collectionData.editDocumentTooltip"), h(UButton, {
|
|
150
151
|
"icon": "i-lucide-pencil",
|
|
151
152
|
"color": "neutral",
|
|
152
153
|
"variant": "ghost",
|
|
153
154
|
"size": "sm",
|
|
154
|
-
"aria-label": "
|
|
155
|
+
"aria-label": t("nuxtUiMongocamp.collectionData.editDocumentTooltip"),
|
|
155
156
|
"onClick": () => openEdit(row.original)
|
|
156
157
|
})),
|
|
157
|
-
withTooltip("
|
|
158
|
+
withTooltip(t("nuxtUiMongocamp.collectionData.deleteDocumentTooltip"), h(UButton, {
|
|
158
159
|
"icon": "i-lucide-trash-2",
|
|
159
160
|
"color": "error",
|
|
160
161
|
"variant": "ghost",
|
|
161
162
|
"size": "sm",
|
|
162
|
-
"aria-label": "
|
|
163
|
+
"aria-label": t("nuxtUiMongocamp.collectionData.deleteDocumentTooltip"),
|
|
163
164
|
"onClick": () => confirmDelete(row.original)
|
|
164
165
|
}))
|
|
165
166
|
);
|
|
@@ -193,9 +194,9 @@ function openDetail(value) {
|
|
|
193
194
|
detailOpen.value = true;
|
|
194
195
|
}
|
|
195
196
|
function buildLuceneFilter(term) {
|
|
196
|
-
const
|
|
197
|
-
if (!
|
|
198
|
-
return or(...filterableColumns.value.map((col) => like(col,
|
|
197
|
+
const trimmed = term.trim();
|
|
198
|
+
if (!trimmed || filterableColumns.value.length === 0) return void 0;
|
|
199
|
+
return or(...filterableColumns.value.map((col) => like(col, trimmed))) || void 0;
|
|
199
200
|
}
|
|
200
201
|
function onFilterInput() {
|
|
201
202
|
clearTimeout(filterTimer);
|
|
@@ -268,26 +269,26 @@ function makeCell(key, type) {
|
|
|
268
269
|
const rows = [];
|
|
269
270
|
if (obj.created) {
|
|
270
271
|
rows.push(h("div", [
|
|
271
|
-
h("span", { class: "text-dimmed" }, "
|
|
272
|
+
h("span", { class: "text-dimmed" }, t("nuxtUiMongocamp.collectionData.createdByPrefix")),
|
|
272
273
|
h("span", toDateDisplay(obj.created))
|
|
273
274
|
]));
|
|
274
275
|
}
|
|
275
276
|
if (obj.updated && obj.updated !== obj.created) {
|
|
276
277
|
rows.push(h("div", [
|
|
277
|
-
h("span", { class: "text-dimmed" }, "
|
|
278
|
+
h("span", { class: "text-dimmed" }, t("nuxtUiMongocamp.collectionData.updatedByPrefix")),
|
|
278
279
|
h("span", toDateDisplay(obj.updated))
|
|
279
280
|
]));
|
|
280
281
|
}
|
|
281
282
|
if (obj.createdBy) {
|
|
282
283
|
rows.push(h("div", [
|
|
283
|
-
h("span", { class: "text-dimmed" }, "
|
|
284
|
+
h("span", { class: "text-dimmed" }, t("nuxtUiMongocamp.collectionData.byPrefix")),
|
|
284
285
|
h("span", String(obj.createdBy))
|
|
285
286
|
]));
|
|
286
287
|
}
|
|
287
288
|
return h("div", { class: "flex flex-col gap-0.5 text-xs py-1" }, rows);
|
|
288
289
|
}
|
|
289
290
|
}
|
|
290
|
-
const viewLabel = Array.isArray(raw) ? "
|
|
291
|
+
const viewLabel = Array.isArray(raw) ? t("nuxtUiMongocamp.collectionData.viewArray") : t("nuxtUiMongocamp.collectionData.viewObject");
|
|
291
292
|
return withTooltip(viewLabel, h(UButton, {
|
|
292
293
|
"icon": Array.isArray(raw) ? "i-lucide-list" : "i-lucide-braces",
|
|
293
294
|
"color": "neutral",
|
|
@@ -355,7 +356,7 @@ watch(() => props.collectionName, init, { immediate: true });
|
|
|
355
356
|
<UInput
|
|
356
357
|
v-model="filterText"
|
|
357
358
|
icon="i-lucide-search"
|
|
358
|
-
placeholder="
|
|
359
|
+
:placeholder="t('nuxtUiMongocamp.collectionData.filterPlaceholder')"
|
|
359
360
|
size="sm"
|
|
360
361
|
class="flex-1 max-w-xs"
|
|
361
362
|
:disabled="filterableColumns.length === 0"
|
|
@@ -363,11 +364,11 @@ watch(() => props.collectionName, init, { immediate: true });
|
|
|
363
364
|
/>
|
|
364
365
|
<div class="flex items-center gap-2">
|
|
365
366
|
<span class="text-sm text-gray-500 dark:text-gray-400 shrink-0">
|
|
366
|
-
{{ total }}
|
|
367
|
+
{{ t("nuxtUiMongocamp.collectionData.documentsCount", { count: total }) }}
|
|
367
368
|
</span>
|
|
368
369
|
<UTooltip
|
|
369
370
|
v-if="isBucketCollection(collectionName)"
|
|
370
|
-
text="
|
|
371
|
+
:text="t('nuxtUiMongocamp.collectionData.uploadFileTooltip')"
|
|
371
372
|
>
|
|
372
373
|
<UButton
|
|
373
374
|
icon="i-lucide-upload"
|
|
@@ -375,20 +376,20 @@ watch(() => props.collectionName, init, { immediate: true });
|
|
|
375
376
|
variant="ghost"
|
|
376
377
|
size="sm"
|
|
377
378
|
:loading="uploading"
|
|
378
|
-
aria-label="
|
|
379
|
+
:aria-label="t('nuxtUiMongocamp.collectionData.uploadFileTooltip')"
|
|
379
380
|
@click="openFilePicker"
|
|
380
381
|
/>
|
|
381
382
|
</UTooltip>
|
|
382
383
|
<UTooltip
|
|
383
384
|
v-else
|
|
384
|
-
text="
|
|
385
|
+
:text="t('nuxtUiMongocamp.collectionData.insertDocumentTooltip')"
|
|
385
386
|
>
|
|
386
387
|
<UButton
|
|
387
388
|
icon="i-lucide-plus"
|
|
388
389
|
color="primary"
|
|
389
390
|
variant="ghost"
|
|
390
391
|
size="sm"
|
|
391
|
-
aria-label="
|
|
392
|
+
:aria-label="t('nuxtUiMongocamp.collectionData.insertDocumentTooltip')"
|
|
392
393
|
@click="openInsert"
|
|
393
394
|
/>
|
|
394
395
|
</UTooltip>
|
|
@@ -398,13 +399,13 @@ watch(() => props.collectionName, init, { immediate: true });
|
|
|
398
399
|
class="hidden"
|
|
399
400
|
@change="handleFileSelected"
|
|
400
401
|
>
|
|
401
|
-
<UTooltip text="
|
|
402
|
+
<UTooltip :text="t('nuxtUiMongocamp.collectionData.reloadTooltip')">
|
|
402
403
|
<UButton
|
|
403
404
|
icon="i-lucide-refresh-cw"
|
|
404
405
|
color="neutral"
|
|
405
406
|
variant="ghost"
|
|
406
407
|
:loading="loading"
|
|
407
|
-
aria-label="
|
|
408
|
+
:aria-label="t('nuxtUiMongocamp.collectionData.reloadTooltip')"
|
|
408
409
|
@click="init"
|
|
409
410
|
/>
|
|
410
411
|
</UTooltip>
|
|
@@ -426,7 +427,7 @@ watch(() => props.collectionName, init, { immediate: true });
|
|
|
426
427
|
|
|
427
428
|
<UModal
|
|
428
429
|
v-model:open="detailOpen"
|
|
429
|
-
title="
|
|
430
|
+
:title="t('nuxtUiMongocamp.collectionData.detailsTitle')"
|
|
430
431
|
>
|
|
431
432
|
<template #body>
|
|
432
433
|
<pre class="text-xs overflow-auto max-h-[60vh] whitespace-pre-wrap break-all">{{ detailContent }}</pre>
|
|
@@ -435,7 +436,7 @@ watch(() => props.collectionName, init, { immediate: true });
|
|
|
435
436
|
|
|
436
437
|
<UModal
|
|
437
438
|
v-model:open="isEditModalOpen"
|
|
438
|
-
:title="editMode === 'insert' ? '
|
|
439
|
+
:title="editMode === 'insert' ? t('nuxtUiMongocamp.collectionData.insertDocumentTitle') : t('nuxtUiMongocamp.collectionData.editDocumentTitle')"
|
|
439
440
|
:ui="{ footer: 'justify-end' }"
|
|
440
441
|
>
|
|
441
442
|
<template #body>
|
|
@@ -443,7 +444,7 @@ watch(() => props.collectionName, init, { immediate: true });
|
|
|
443
444
|
v-if="editSamples.length > 0"
|
|
444
445
|
v-model="editFormData"
|
|
445
446
|
:data="editSamples"
|
|
446
|
-
:submit-label="editMode === 'insert' ? '
|
|
447
|
+
:submit-label="editMode === 'insert' ? t('nuxtUiMongocamp.collectionData.insert') : t('nuxtUiMongocamp.common.save')"
|
|
447
448
|
:submit-icon="editMode === 'insert' ? 'i-lucide-plus' : 'i-lucide-save'"
|
|
448
449
|
@data-saved="handleSave"
|
|
449
450
|
/>
|
|
@@ -465,13 +466,13 @@ watch(() => props.collectionName, init, { immediate: true });
|
|
|
465
466
|
#footer
|
|
466
467
|
>
|
|
467
468
|
<UButton
|
|
468
|
-
label="
|
|
469
|
+
:label="t('nuxtUiMongocamp.common.cancel')"
|
|
469
470
|
color="neutral"
|
|
470
471
|
variant="ghost"
|
|
471
472
|
@click="isEditModalOpen = false"
|
|
472
473
|
/>
|
|
473
474
|
<UButton
|
|
474
|
-
:label="editMode === 'insert' ? '
|
|
475
|
+
:label="editMode === 'insert' ? t('nuxtUiMongocamp.collectionData.insert') : t('nuxtUiMongocamp.common.save')"
|
|
475
476
|
:icon="editMode === 'insert' ? 'i-lucide-plus' : 'i-lucide-save'"
|
|
476
477
|
@click="handleSave"
|
|
477
478
|
/>
|
|
@@ -480,11 +481,11 @@ watch(() => props.collectionName, init, { immediate: true });
|
|
|
480
481
|
|
|
481
482
|
<UModal
|
|
482
483
|
v-model:open="isDeleteModalOpen"
|
|
483
|
-
title="
|
|
484
|
+
:title="t('nuxtUiMongocamp.collectionData.deleteDocumentTitle')"
|
|
484
485
|
:ui="{ footer: 'justify-end' }"
|
|
485
486
|
>
|
|
486
487
|
<template #body>
|
|
487
|
-
<p>
|
|
488
|
+
<p>{{ t("nuxtUiMongocamp.collectionData.confirmDeleteDocument") }}</p>
|
|
488
489
|
<p
|
|
489
490
|
v-if="deleteError"
|
|
490
491
|
class="mt-2 text-sm text-error-500"
|
|
@@ -494,13 +495,13 @@ watch(() => props.collectionName, init, { immediate: true });
|
|
|
494
495
|
</template>
|
|
495
496
|
<template #footer>
|
|
496
497
|
<UButton
|
|
497
|
-
label="
|
|
498
|
+
:label="t('nuxtUiMongocamp.common.cancel')"
|
|
498
499
|
color="neutral"
|
|
499
500
|
variant="ghost"
|
|
500
501
|
@click="isDeleteModalOpen = false"
|
|
501
502
|
/>
|
|
502
503
|
<UButton
|
|
503
|
-
label="
|
|
504
|
+
:label="t('nuxtUiMongocamp.common.delete')"
|
|
504
505
|
color="error"
|
|
505
506
|
icon="i-lucide-trash-2"
|
|
506
507
|
@click="handleDelete"
|