@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.
Files changed (51) hide show
  1. package/README.md +1 -1
  2. package/dist/module.json +1 -1
  3. package/dist/runtime/components/MongocampAggregationBuilder.d.vue.ts +6 -0
  4. package/dist/runtime/components/MongocampAggregationBuilder.vue +390 -0
  5. package/dist/runtime/components/MongocampAggregationBuilder.vue.d.ts +6 -0
  6. package/dist/runtime/components/MongocampBulkDelete.d.vue.ts +11 -1
  7. package/dist/runtime/components/MongocampBulkDelete.vue +1 -0
  8. package/dist/runtime/components/MongocampBulkDelete.vue.d.ts +11 -1
  9. package/dist/runtime/components/MongocampBulkEdit.d.vue.ts +29 -0
  10. package/dist/runtime/components/MongocampBulkEdit.vue +138 -0
  11. package/dist/runtime/components/MongocampBulkEdit.vue.d.ts +29 -0
  12. package/dist/runtime/components/MongocampCollectionData.vue +100 -1
  13. package/dist/runtime/components/MongocampCollectionInfos.vue +162 -0
  14. package/dist/runtime/components/MongocampFilterBuilder.d.vue.ts +1 -0
  15. package/dist/runtime/components/MongocampFilterBuilder.vue +33 -2
  16. package/dist/runtime/components/MongocampFilterBuilder.vue.d.ts +1 -0
  17. package/dist/runtime/components/MongocampImport.d.vue.ts +10 -0
  18. package/dist/runtime/components/MongocampImport.vue +479 -0
  19. package/dist/runtime/components/MongocampImport.vue.d.ts +10 -0
  20. package/dist/runtime/components/MongocampRoleGrants.vue +25 -0
  21. package/dist/runtime/components/MongocampRoles.vue +74 -0
  22. package/dist/runtime/composables/useMongocampAggregation.d.ts +28 -0
  23. package/dist/runtime/composables/useMongocampAggregation.js +99 -0
  24. package/dist/runtime/composables/useMongocampBulkDelete.d.ts +1 -1
  25. package/dist/runtime/composables/useMongocampImport.d.ts +14 -0
  26. package/dist/runtime/composables/useMongocampImport.js +25 -0
  27. package/dist/runtime/locales/de.json +147 -2
  28. package/dist/runtime/locales/en.json +147 -2
  29. package/dist/runtime/utils/aggregationErrors.d.ts +10 -0
  30. package/dist/runtime/utils/aggregationErrors.js +17 -0
  31. package/dist/runtime/utils/aggregationPipeline.d.ts +42 -0
  32. package/dist/runtime/utils/aggregationPipeline.js +118 -0
  33. package/dist/runtime/utils/aggregationResult.d.ts +5 -0
  34. package/dist/runtime/utils/aggregationResult.js +17 -0
  35. package/dist/runtime/utils/analyzeSamples.d.ts +27 -0
  36. package/dist/runtime/utils/analyzeSamples.js +92 -0
  37. package/dist/runtime/utils/batchInsert.d.ts +22 -0
  38. package/dist/runtime/utils/batchInsert.js +24 -0
  39. package/dist/runtime/utils/bulkDelete.d.ts +6 -1
  40. package/dist/runtime/utils/bulkDelete.js +28 -4
  41. package/dist/runtime/utils/bulkEdit.d.ts +27 -0
  42. package/dist/runtime/utils/bulkEdit.js +45 -0
  43. package/dist/runtime/utils/filterSuggestions.d.ts +8 -0
  44. package/dist/runtime/utils/filterSuggestions.js +15 -0
  45. package/dist/runtime/utils/importPipeline.d.ts +21 -0
  46. package/dist/runtime/utils/importPipeline.js +52 -0
  47. package/dist/runtime/utils/importRows.d.ts +36 -0
  48. package/dist/runtime/utils/importRows.js +228 -0
  49. package/dist/runtime/utils/objectId.d.ts +1 -0
  50. package/dist/runtime/utils/objectId.js +4 -0
  51. package/package.json +2 -2
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. 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`.
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`, `MongocampBulkEdit`, `MongocampImport`, `MongocampAggregationBuilder`, `MongocampErrorAlert` and `MongocampEmptyState`.
56
56
 
57
57
  ### `<MongocampLogin />`
58
58
 
package/dist/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=3.16.0"
6
6
  },
7
- "version": "1.3.0",
7
+ "version": "1.3.2",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.3",
10
10
  "unbuild": "3.6.1"
@@ -0,0 +1,6 @@
1
+ type __VLS_Props = {
2
+ collectionName: 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;
@@ -0,0 +1,390 @@
1
+ <script setup>
2
+ import { computed, h, ref, watch } from "vue";
3
+ import { useI18n } from "#imports";
4
+ import { useMongocampAggregation } from "../composables/useMongocampAggregation";
5
+ import {
6
+ VISUAL_STAGE_TYPES,
7
+ buildPipeline,
8
+ findForbidden,
9
+ parsePipeline,
10
+ pipelineToText,
11
+ toVisualStages,
12
+ validateStages
13
+ } from "../utils/aggregationPipeline";
14
+ import { formatCell, resultColumns } from "../utils/aggregationResult";
15
+ import { downloadTextFile, rowsToCsv } from "../utils/exportRows";
16
+ const props = defineProps({
17
+ collectionName: { type: String, required: true }
18
+ });
19
+ const PAGE_SIZES = [10, 20, 50, 100];
20
+ const JSON_PLACEHOLDER = '[ { "$match": { } }, { "$limit": 10 } ]';
21
+ const DEFAULT_TEXT = {
22
+ $match: "{}",
23
+ $group: '{ "_id": "$field", "count": { "$sum": 1 } }',
24
+ $sort: '{ "count": -1 }',
25
+ $project: "{}",
26
+ $limit: "10"
27
+ };
28
+ const { t } = useI18n();
29
+ const { runAggregation, describeAggregationError } = useMongocampAggregation();
30
+ let idCounter = 0;
31
+ function newId() {
32
+ return `stage-${idCounter++}`;
33
+ }
34
+ const mode = ref("visual");
35
+ const drafts = ref([{ id: newId(), type: "$match", text: DEFAULT_TEXT.$match }]);
36
+ const rawText = ref("[]");
37
+ const newStageType = ref("$group");
38
+ const modeError = ref("");
39
+ const rowsPerPage = ref(20);
40
+ const page = ref(1);
41
+ const running = ref(false);
42
+ const result = ref(null);
43
+ const runError = ref(null);
44
+ let lastPipeline = null;
45
+ let runCounter = 0;
46
+ const draftStates = computed(() => drafts.value.map((draft) => {
47
+ const stage = { id: draft.id, type: draft.type, value: void 0 };
48
+ if (draft.text.trim() === "") return { stage };
49
+ try {
50
+ stage.value = JSON.parse(draft.text);
51
+ } catch {
52
+ return { stage, error: t("nuxtUiMongocamp.aggregation.stageErrors.invalid-json") };
53
+ }
54
+ const issue = validateStages([stage])[0];
55
+ if (issue) return { stage, error: t(`nuxtUiMongocamp.aggregation.stageErrors.${issue.code}`) };
56
+ const forbidden = findForbidden(buildPipeline([stage]))[0];
57
+ if (forbidden) return { stage, error: t("nuxtUiMongocamp.aggregation.stageErrors.forbidden", { operator: forbidden.operator }) };
58
+ return { stage };
59
+ }));
60
+ function stageLabel(type) {
61
+ return t(`nuxtUiMongocamp.aggregation.stageTypes.${type}`);
62
+ }
63
+ const stageTypeItems = computed(() => VISUAL_STAGE_TYPES.map((type) => ({ label: stageLabel(type), value: type })));
64
+ function addStage() {
65
+ drafts.value = [...drafts.value, { id: newId(), type: newStageType.value, text: DEFAULT_TEXT[newStageType.value] }];
66
+ }
67
+ function removeStage(index) {
68
+ drafts.value = drafts.value.filter((_, i) => i !== index);
69
+ }
70
+ function moveStage(index, offset) {
71
+ const target = index + offset;
72
+ if (target < 0 || target >= drafts.value.length) return;
73
+ const next = [...drafts.value];
74
+ [next[index], next[target]] = [next[target], next[index]];
75
+ drafts.value = next;
76
+ }
77
+ function pipelineErrorText(error) {
78
+ const n = (error.stageIndex ?? 0) + 1;
79
+ return t(`nuxtUiMongocamp.aggregation.pipelineErrors.${error.code}`, { n, operator: error.operator ?? "" });
80
+ }
81
+ const pipelineState = computed(() => {
82
+ if (mode.value === "visual") {
83
+ if (draftStates.value.some((state) => state.error)) return { error: t("nuxtUiMongocamp.aggregation.fixStages") };
84
+ return { pipeline: buildPipeline(draftStates.value.map((state) => state.stage)) };
85
+ }
86
+ const parsed = parsePipeline(rawText.value);
87
+ return parsed.ok ? { pipeline: parsed.pipeline } : { error: pipelineErrorText(parsed.error) };
88
+ });
89
+ const canRun = computed(() => pipelineState.value.pipeline !== void 0 && !running.value);
90
+ function switchMode(next) {
91
+ modeError.value = "";
92
+ if (next === mode.value) return;
93
+ if (next === "json") {
94
+ if (draftStates.value.some((state) => state.error)) {
95
+ modeError.value = t("nuxtUiMongocamp.aggregation.fixStagesFirst");
96
+ return;
97
+ }
98
+ rawText.value = pipelineToText(buildPipeline(draftStates.value.map((state) => state.stage)));
99
+ mode.value = "json";
100
+ return;
101
+ }
102
+ const parsed = parsePipeline(rawText.value);
103
+ if (!parsed.ok) {
104
+ modeError.value = pipelineErrorText(parsed.error);
105
+ return;
106
+ }
107
+ const stages = toVisualStages(parsed.pipeline, () => newId());
108
+ if (!stages) {
109
+ modeError.value = t("nuxtUiMongocamp.aggregation.cannotShowVisually");
110
+ return;
111
+ }
112
+ drafts.value = stages.map((stage) => ({ id: stage.id, type: stage.type, text: JSON.stringify(stage.value, null, 2) }));
113
+ mode.value = "visual";
114
+ }
115
+ async function execute(pageNumber) {
116
+ if (!lastPipeline) return;
117
+ const run = ++runCounter;
118
+ running.value = true;
119
+ runError.value = null;
120
+ try {
121
+ const outcome = await runAggregation(props.collectionName, lastPipeline, { page: pageNumber, rowsPerPage: rowsPerPage.value });
122
+ if (run !== runCounter) return;
123
+ result.value = outcome;
124
+ page.value = outcome.page;
125
+ } catch (error) {
126
+ const described = await describeAggregationError(error);
127
+ if (run !== runCounter) return;
128
+ result.value = null;
129
+ runError.value = described;
130
+ } finally {
131
+ if (run === runCounter) running.value = false;
132
+ }
133
+ }
134
+ async function runPipeline() {
135
+ const pipeline = pipelineState.value.pipeline;
136
+ if (!pipeline || running.value) return;
137
+ lastPipeline = pipeline;
138
+ await execute(1);
139
+ }
140
+ function onPageChange(next) {
141
+ page.value = next;
142
+ void execute(next);
143
+ }
144
+ function onPageSizeChange(size) {
145
+ rowsPerPage.value = size;
146
+ void execute(1);
147
+ }
148
+ watch(() => props.collectionName, () => {
149
+ runCounter++;
150
+ lastPipeline = null;
151
+ result.value = null;
152
+ runError.value = null;
153
+ running.value = false;
154
+ page.value = 1;
155
+ });
156
+ const columnKeys = computed(() => resultColumns(result.value?.rows ?? []));
157
+ const tableColumns = computed(() => columnKeys.value.map((key) => ({
158
+ id: key,
159
+ header: key,
160
+ // keys can contain dots, which an accessorKey would read as a path
161
+ accessorFn: (row) => row[key],
162
+ cell: ({ getValue }) => {
163
+ const { text, full } = formatCell(getValue());
164
+ return h("span", { title: full === text ? void 0 : full, class: "font-mono text-xs" }, text);
165
+ }
166
+ })));
167
+ function exportPage(format) {
168
+ const rows = result.value?.rows ?? [];
169
+ if (format === "json") {
170
+ downloadTextFile(`${props.collectionName}-aggregation.json`, JSON.stringify(rows, null, 2), "application/json");
171
+ return;
172
+ }
173
+ downloadTextFile(`${props.collectionName}-aggregation.csv`, rowsToCsv(rows, columnKeys.value), "text/csv");
174
+ }
175
+ const exportMenuItems = computed(() => [
176
+ { label: t("nuxtUiMongocamp.aggregation.exportJson"), icon: "i-lucide-file-json", onSelect: () => exportPage("json") },
177
+ { label: t("nuxtUiMongocamp.aggregation.exportCsv"), icon: "i-lucide-file-spreadsheet", onSelect: () => exportPage("csv") }
178
+ ]);
179
+ </script>
180
+
181
+ <template>
182
+ <div class="flex flex-col gap-4">
183
+ <div class="flex flex-wrap items-center justify-between gap-2">
184
+ <div class="flex items-center gap-1">
185
+ <UButton
186
+ color="neutral"
187
+ size="sm"
188
+ :variant="mode === 'visual' ? 'subtle' : 'ghost'"
189
+ :aria-pressed="mode === 'visual'"
190
+ :label="t('nuxtUiMongocamp.aggregation.modeVisual')"
191
+ @click="switchMode('visual')"
192
+ />
193
+ <UButton
194
+ color="neutral"
195
+ size="sm"
196
+ :variant="mode === 'json' ? 'subtle' : 'ghost'"
197
+ :aria-pressed="mode === 'json'"
198
+ :label="t('nuxtUiMongocamp.aggregation.modeJson')"
199
+ @click="switchMode('json')"
200
+ />
201
+ </div>
202
+ <UButton
203
+ icon="i-lucide-play"
204
+ :label="t('nuxtUiMongocamp.aggregation.run')"
205
+ :loading="running"
206
+ :disabled="!canRun"
207
+ @click="runPipeline"
208
+ />
209
+ </div>
210
+
211
+ <UAlert
212
+ v-if="modeError"
213
+ color="warning"
214
+ variant="subtle"
215
+ icon="i-lucide-triangle-alert"
216
+ :description="modeError"
217
+ />
218
+
219
+ <div
220
+ v-if="mode === 'visual'"
221
+ class="flex flex-col gap-3"
222
+ >
223
+ <div
224
+ v-for="(draft, index) in drafts"
225
+ :key="draft.id"
226
+ class="flex flex-col gap-2 rounded-md border border-default p-3"
227
+ >
228
+ <div class="flex items-center justify-between gap-2">
229
+ <span class="text-sm font-medium">
230
+ {{ t("nuxtUiMongocamp.aggregation.stageTitle", { n: index + 1 }) }}
231
+ <code class="ml-1 font-mono text-xs">{{ draft.type }}</code>
232
+ </span>
233
+ <div class="flex items-center">
234
+ <UButton
235
+ icon="i-lucide-arrow-up"
236
+ color="neutral"
237
+ variant="ghost"
238
+ size="sm"
239
+ :disabled="index === 0"
240
+ :aria-label="t('nuxtUiMongocamp.aggregation.moveUp')"
241
+ @click="moveStage(index, -1)"
242
+ />
243
+ <UButton
244
+ icon="i-lucide-arrow-down"
245
+ color="neutral"
246
+ variant="ghost"
247
+ size="sm"
248
+ :disabled="index === drafts.length - 1"
249
+ :aria-label="t('nuxtUiMongocamp.aggregation.moveDown')"
250
+ @click="moveStage(index, 1)"
251
+ />
252
+ <UButton
253
+ icon="i-lucide-x"
254
+ color="neutral"
255
+ variant="ghost"
256
+ size="sm"
257
+ :aria-label="t('nuxtUiMongocamp.aggregation.removeStage')"
258
+ @click="removeStage(index)"
259
+ />
260
+ </div>
261
+ </div>
262
+ <UTextarea
263
+ v-model="draft.text"
264
+ :rows="draft.type === '$limit' ? 1 : 3"
265
+ :color="draftStates[index]?.error ? 'error' : void 0"
266
+ class="w-full font-mono"
267
+ :aria-label="t('nuxtUiMongocamp.aggregation.stageValue', { type: draft.type })"
268
+ />
269
+ <p
270
+ v-if="draftStates[index]?.error"
271
+ class="text-sm text-error"
272
+ >
273
+ {{ draftStates[index]?.error }}
274
+ </p>
275
+ </div>
276
+ <div class="flex flex-wrap items-center gap-2">
277
+ <USelect
278
+ v-model="newStageType"
279
+ :items="stageTypeItems"
280
+ size="sm"
281
+ class="w-72"
282
+ :aria-label="t('nuxtUiMongocamp.aggregation.newStageType')"
283
+ />
284
+ <UButton
285
+ icon="i-lucide-plus"
286
+ color="neutral"
287
+ variant="ghost"
288
+ size="sm"
289
+ :label="t('nuxtUiMongocamp.aggregation.addStage')"
290
+ @click="addStage"
291
+ />
292
+ </div>
293
+ </div>
294
+
295
+ <div
296
+ v-else
297
+ class="flex flex-col gap-2"
298
+ >
299
+ <UTextarea
300
+ v-model="rawText"
301
+ :rows="12"
302
+ :color="pipelineState.error ? 'error' : void 0"
303
+ class="w-full font-mono"
304
+ :placeholder="JSON_PLACEHOLDER"
305
+ :aria-label="t('nuxtUiMongocamp.aggregation.jsonLabel')"
306
+ />
307
+ <p
308
+ v-if="pipelineState.error"
309
+ class="text-sm text-error"
310
+ >
311
+ {{ pipelineState.error }}
312
+ </p>
313
+ </div>
314
+
315
+ <UAlert
316
+ v-if="runError"
317
+ color="error"
318
+ variant="subtle"
319
+ icon="i-lucide-circle-alert"
320
+ :title="t('nuxtUiMongocamp.aggregation.runFailedTitle')"
321
+ :description="runError.message"
322
+ >
323
+ <template #actions>
324
+ <UButton
325
+ v-if="runError.kind === 'unauthorized'"
326
+ :label="t('nuxtUiMongocamp.errors.loginAgain')"
327
+ to="/"
328
+ color="error"
329
+ variant="subtle"
330
+ icon="i-lucide-log-in"
331
+ />
332
+ <UButton
333
+ v-else-if="runError.kind !== 'forbidden'"
334
+ :label="t('nuxtUiMongocamp.common.retry')"
335
+ color="error"
336
+ variant="subtle"
337
+ icon="i-lucide-refresh-cw"
338
+ @click="execute(page)"
339
+ />
340
+ </template>
341
+ </UAlert>
342
+
343
+ <template v-if="result">
344
+ <div class="flex flex-wrap items-center justify-between gap-2">
345
+ <span class="text-sm text-dimmed">
346
+ {{ t("nuxtUiMongocamp.aggregation.resultsCount", { count: result.total }, result.total) }}
347
+ </span>
348
+ <div class="flex flex-wrap items-center gap-2">
349
+ <UDropdownMenu :items="exportMenuItems">
350
+ <UButton
351
+ icon="i-lucide-download"
352
+ color="neutral"
353
+ variant="ghost"
354
+ size="sm"
355
+ :disabled="result.rows.length === 0"
356
+ :aria-label="t('nuxtUiMongocamp.aggregation.exportTooltip')"
357
+ />
358
+ </UDropdownMenu>
359
+ <USelect
360
+ :model-value="rowsPerPage"
361
+ :items="PAGE_SIZES"
362
+ size="sm"
363
+ class="w-20"
364
+ :aria-label="t('nuxtUiMongocamp.aggregation.pageSize')"
365
+ @update:model-value="onPageSizeChange"
366
+ />
367
+ <UPagination
368
+ :page="page"
369
+ :total="result.total"
370
+ :items-per-page="rowsPerPage"
371
+ @update:page="onPageChange"
372
+ />
373
+ </div>
374
+ </div>
375
+
376
+ <UTable
377
+ :data="result.rows"
378
+ :columns="tableColumns"
379
+ :loading="running"
380
+ >
381
+ <template #empty>
382
+ <MongocampEmptyState :title="t('nuxtUiMongocamp.aggregation.noResults')" />
383
+ </template>
384
+ </UTable>
385
+ <p class="text-xs text-dimmed">
386
+ {{ t("nuxtUiMongocamp.aggregation.precisionNote") }}
387
+ </p>
388
+ </template>
389
+ </div>
390
+ </template>
@@ -0,0 +1,6 @@
1
+ type __VLS_Props = {
2
+ collectionName: 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;
@@ -3,7 +3,11 @@ type __VLS_Props = {
3
3
  deleting?: boolean;
4
4
  error?: string;
5
5
  };
6
- declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
6
+ declare var __VLS_8: {};
7
+ type __VLS_Slots = {} & {
8
+ actions?: (props: typeof __VLS_8) => any;
9
+ };
10
+ declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
7
11
  open: () => any;
8
12
  clear: () => any;
9
13
  confirm: () => any;
@@ -12,5 +16,11 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {
12
16
  onClear?: (() => any) | undefined;
13
17
  onConfirm?: (() => any) | undefined;
14
18
  }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
19
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
15
20
  declare const _default: typeof __VLS_export;
16
21
  export default _default;
22
+ type __VLS_WithSlots<T, S> = T & {
23
+ new (): {
24
+ $slots: S;
25
+ };
26
+ };
@@ -37,6 +37,7 @@ watch(() => props.deleting, (now, before) => {
37
37
  :label="t('nuxtUiMongocamp.bulk.deleteSelected')"
38
38
  @click="openModal"
39
39
  />
40
+ <slot name="actions" />
40
41
  <UButton
41
42
  color="neutral"
42
43
  variant="ghost"
@@ -3,7 +3,11 @@ type __VLS_Props = {
3
3
  deleting?: boolean;
4
4
  error?: string;
5
5
  };
6
- declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
6
+ declare var __VLS_8: {};
7
+ type __VLS_Slots = {} & {
8
+ actions?: (props: typeof __VLS_8) => any;
9
+ };
10
+ declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
7
11
  open: () => any;
8
12
  clear: () => any;
9
13
  confirm: () => any;
@@ -12,5 +16,11 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {
12
16
  onClear?: (() => any) | undefined;
13
17
  onConfirm?: (() => any) | undefined;
14
18
  }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
19
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
15
20
  declare const _default: typeof __VLS_export;
16
21
  export default _default;
22
+ type __VLS_WithSlots<T, S> = T & {
23
+ new (): {
24
+ $slots: S;
25
+ };
26
+ };
@@ -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;
@@ -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;