@sfxcode/nuxt-ui-mongocamp 1.2.7 → 1.3.1
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 +95 -38
- package/dist/runtime/components/MongocampRoles.vue +153 -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 +104 -7
- package/dist/runtime/locales/en.json +104 -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 +14 -14
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { computed } from "vue";
|
|
3
|
+
import { useI18n } from "#imports";
|
|
4
|
+
import {
|
|
5
|
+
buildFilterQuery,
|
|
6
|
+
countActiveConditions,
|
|
7
|
+
operatorLabelKey,
|
|
8
|
+
operatorsFor,
|
|
9
|
+
valueCountFor
|
|
10
|
+
} from "../utils/filterBuilder";
|
|
11
|
+
const props = defineProps({
|
|
12
|
+
fields: { type: Array, required: true }
|
|
13
|
+
});
|
|
14
|
+
const model = defineModel({ type: Object, ...{ required: true } });
|
|
15
|
+
const emit = defineEmits(["apply"]);
|
|
16
|
+
const { t } = useI18n();
|
|
17
|
+
let idCounter = 0;
|
|
18
|
+
function newId() {
|
|
19
|
+
return `filter-${Date.now()}-${idCounter++}`;
|
|
20
|
+
}
|
|
21
|
+
const fieldTypes = computed(
|
|
22
|
+
() => Object.fromEntries(props.fields.map((f) => [f.key, f.type]))
|
|
23
|
+
);
|
|
24
|
+
const fieldItems = computed(() => props.fields.map((f) => ({ label: f.key, value: f.key })));
|
|
25
|
+
function typeOf(field) {
|
|
26
|
+
return fieldTypes.value[field] ?? "string";
|
|
27
|
+
}
|
|
28
|
+
function operatorItems(type) {
|
|
29
|
+
return operatorsFor(type).map((operator) => ({ label: t(operatorLabelKey(operator, type)), value: operator }));
|
|
30
|
+
}
|
|
31
|
+
const matchItems = computed(() => [
|
|
32
|
+
{ label: t("nuxtUiMongocamp.filterBuilder.matchAll"), value: "all" },
|
|
33
|
+
{ label: t("nuxtUiMongocamp.filterBuilder.matchAny"), value: "any" }
|
|
34
|
+
]);
|
|
35
|
+
const query = computed(() => buildFilterQuery(model.value, fieldTypes.value));
|
|
36
|
+
const ignoredCount = computed(() => model.value.conditions.length - countActiveConditions(model.value, fieldTypes.value));
|
|
37
|
+
function setConditions(conditions) {
|
|
38
|
+
model.value = { ...model.value, conditions };
|
|
39
|
+
}
|
|
40
|
+
function updateCondition(index, patch) {
|
|
41
|
+
setConditions(model.value.conditions.map((c, i) => i === index ? { ...c, ...patch } : c));
|
|
42
|
+
}
|
|
43
|
+
function addCondition() {
|
|
44
|
+
const field = props.fields[0];
|
|
45
|
+
if (!field) return;
|
|
46
|
+
setConditions([...model.value.conditions, { id: newId(), field: field.key, operator: operatorsFor(field.type)[0] }]);
|
|
47
|
+
}
|
|
48
|
+
function removeCondition(index) {
|
|
49
|
+
setConditions(model.value.conditions.filter((_, i) => i !== index));
|
|
50
|
+
}
|
|
51
|
+
function changeField(index, field) {
|
|
52
|
+
const operators = operatorsFor(typeOf(field));
|
|
53
|
+
const current = model.value.conditions[index];
|
|
54
|
+
updateCondition(index, {
|
|
55
|
+
field,
|
|
56
|
+
operator: operators.includes(current.operator) ? current.operator : operators[0],
|
|
57
|
+
value: "",
|
|
58
|
+
value2: ""
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
function setMatch(match) {
|
|
62
|
+
model.value = { ...model.value, match };
|
|
63
|
+
}
|
|
64
|
+
function apply() {
|
|
65
|
+
emit("apply", query.value);
|
|
66
|
+
}
|
|
67
|
+
function clearAll() {
|
|
68
|
+
setConditions([]);
|
|
69
|
+
emit("apply", "");
|
|
70
|
+
}
|
|
71
|
+
</script>
|
|
72
|
+
|
|
73
|
+
<template>
|
|
74
|
+
<div class="flex flex-col gap-3 rounded-md border border-default p-3">
|
|
75
|
+
<p
|
|
76
|
+
v-if="fields.length === 0"
|
|
77
|
+
class="text-sm text-dimmed"
|
|
78
|
+
>
|
|
79
|
+
{{ t("nuxtUiMongocamp.filterBuilder.noFields") }}
|
|
80
|
+
</p>
|
|
81
|
+
|
|
82
|
+
<template v-else>
|
|
83
|
+
<div
|
|
84
|
+
v-if="model.conditions.length > 1"
|
|
85
|
+
class="flex items-center gap-2 text-sm"
|
|
86
|
+
>
|
|
87
|
+
<span>{{ t("nuxtUiMongocamp.filterBuilder.matchLabel") }}</span>
|
|
88
|
+
<USelect
|
|
89
|
+
:model-value="model.match"
|
|
90
|
+
:items="matchItems"
|
|
91
|
+
size="sm"
|
|
92
|
+
class="w-44"
|
|
93
|
+
:aria-label="t('nuxtUiMongocamp.filterBuilder.matchLabel')"
|
|
94
|
+
@update:model-value="(value) => setMatch(value)"
|
|
95
|
+
/>
|
|
96
|
+
</div>
|
|
97
|
+
|
|
98
|
+
<p
|
|
99
|
+
v-if="model.conditions.length === 0"
|
|
100
|
+
class="text-sm text-dimmed"
|
|
101
|
+
>
|
|
102
|
+
{{ t("nuxtUiMongocamp.filterBuilder.noConditions") }}
|
|
103
|
+
</p>
|
|
104
|
+
|
|
105
|
+
<div
|
|
106
|
+
v-for="(condition, index) in model.conditions"
|
|
107
|
+
:key="condition.id"
|
|
108
|
+
class="flex flex-wrap items-center gap-2"
|
|
109
|
+
>
|
|
110
|
+
<USelect
|
|
111
|
+
:model-value="condition.field"
|
|
112
|
+
:items="fieldItems"
|
|
113
|
+
size="sm"
|
|
114
|
+
class="w-44"
|
|
115
|
+
:aria-label="t('nuxtUiMongocamp.filterBuilder.field')"
|
|
116
|
+
@update:model-value="(value) => changeField(index, value)"
|
|
117
|
+
/>
|
|
118
|
+
<USelect
|
|
119
|
+
:model-value="condition.operator"
|
|
120
|
+
:items="operatorItems(typeOf(condition.field))"
|
|
121
|
+
size="sm"
|
|
122
|
+
class="w-44"
|
|
123
|
+
:aria-label="t('nuxtUiMongocamp.filterBuilder.operator')"
|
|
124
|
+
@update:model-value="(value) => updateCondition(index, { operator: value })"
|
|
125
|
+
/>
|
|
126
|
+
<template v-if="valueCountFor(condition.operator) > 0">
|
|
127
|
+
<UInput
|
|
128
|
+
:model-value="condition.value ?? ''"
|
|
129
|
+
:type="typeOf(condition.field) === 'date-time' ? 'date' : 'text'"
|
|
130
|
+
:inputmode="typeOf(condition.field) === 'number' ? 'decimal' : void 0"
|
|
131
|
+
:placeholder="condition.operator === 'oneOf' ? t('nuxtUiMongocamp.filterBuilder.listPlaceholder') : void 0"
|
|
132
|
+
size="sm"
|
|
133
|
+
class="w-48"
|
|
134
|
+
:aria-label="t('nuxtUiMongocamp.filterBuilder.value')"
|
|
135
|
+
@update:model-value="(value) => updateCondition(index, { value: String(value ?? '') })"
|
|
136
|
+
/>
|
|
137
|
+
<template v-if="valueCountFor(condition.operator) === 2">
|
|
138
|
+
<span class="text-sm text-dimmed">{{ t("nuxtUiMongocamp.filterBuilder.and") }}</span>
|
|
139
|
+
<UInput
|
|
140
|
+
:model-value="condition.value2 ?? ''"
|
|
141
|
+
:type="typeOf(condition.field) === 'date-time' ? 'date' : 'text'"
|
|
142
|
+
:inputmode="typeOf(condition.field) === 'number' ? 'decimal' : void 0"
|
|
143
|
+
size="sm"
|
|
144
|
+
class="w-48"
|
|
145
|
+
:aria-label="t('nuxtUiMongocamp.filterBuilder.valueTo')"
|
|
146
|
+
@update:model-value="(value) => updateCondition(index, { value2: String(value ?? '') })"
|
|
147
|
+
/>
|
|
148
|
+
</template>
|
|
149
|
+
</template>
|
|
150
|
+
<UButton
|
|
151
|
+
icon="i-lucide-x"
|
|
152
|
+
color="neutral"
|
|
153
|
+
variant="ghost"
|
|
154
|
+
size="sm"
|
|
155
|
+
:aria-label="t('nuxtUiMongocamp.filterBuilder.remove')"
|
|
156
|
+
@click="removeCondition(index)"
|
|
157
|
+
/>
|
|
158
|
+
</div>
|
|
159
|
+
|
|
160
|
+
<p
|
|
161
|
+
v-if="ignoredCount > 0"
|
|
162
|
+
class="text-xs text-warning"
|
|
163
|
+
>
|
|
164
|
+
{{ t("nuxtUiMongocamp.filterBuilder.ignoredRows", { count: ignoredCount }, ignoredCount) }}
|
|
165
|
+
</p>
|
|
166
|
+
|
|
167
|
+
<div
|
|
168
|
+
v-if="query"
|
|
169
|
+
class="flex items-baseline gap-2 text-xs"
|
|
170
|
+
>
|
|
171
|
+
<span class="shrink-0 text-dimmed">{{ t("nuxtUiMongocamp.filterBuilder.query") }}</span>
|
|
172
|
+
<code class="break-all font-mono">{{ query }}</code>
|
|
173
|
+
</div>
|
|
174
|
+
|
|
175
|
+
<div class="flex flex-wrap items-center justify-between gap-2">
|
|
176
|
+
<UButton
|
|
177
|
+
icon="i-lucide-plus"
|
|
178
|
+
color="neutral"
|
|
179
|
+
variant="ghost"
|
|
180
|
+
size="sm"
|
|
181
|
+
:label="t('nuxtUiMongocamp.filterBuilder.addCondition')"
|
|
182
|
+
@click="addCondition"
|
|
183
|
+
/>
|
|
184
|
+
<div class="flex items-center gap-2">
|
|
185
|
+
<UButton
|
|
186
|
+
color="neutral"
|
|
187
|
+
variant="ghost"
|
|
188
|
+
size="sm"
|
|
189
|
+
:label="t('nuxtUiMongocamp.filterBuilder.clearAll')"
|
|
190
|
+
@click="clearAll"
|
|
191
|
+
/>
|
|
192
|
+
<UButton
|
|
193
|
+
size="sm"
|
|
194
|
+
:label="t('nuxtUiMongocamp.filterBuilder.apply')"
|
|
195
|
+
@click="apply"
|
|
196
|
+
/>
|
|
197
|
+
</div>
|
|
198
|
+
</div>
|
|
199
|
+
</template>
|
|
200
|
+
</div>
|
|
201
|
+
</template>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { FilterFieldType, FilterGroup } from '../utils/filterBuilder.js';
|
|
2
|
+
type __VLS_Props = {
|
|
3
|
+
fields: {
|
|
4
|
+
key: string;
|
|
5
|
+
type: FilterFieldType;
|
|
6
|
+
}[];
|
|
7
|
+
};
|
|
8
|
+
type __VLS_ModelProps = {
|
|
9
|
+
modelValue: FilterGroup;
|
|
10
|
+
};
|
|
11
|
+
type __VLS_PublicProps = __VLS_Props & __VLS_ModelProps;
|
|
12
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_PublicProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
13
|
+
"update:modelValue": (value: FilterGroup) => any;
|
|
14
|
+
apply: (query: string) => any;
|
|
15
|
+
}, string, import("vue").PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
|
|
16
|
+
"onUpdate:modelValue"?: ((value: FilterGroup) => any) | undefined;
|
|
17
|
+
onApply?: ((query: string) => any) | undefined;
|
|
18
|
+
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
19
|
+
declare const _default: typeof __VLS_export;
|
|
20
|
+
export default _default;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
<script setup>
|
|
2
|
-
import { h, reactive, ref, resolveComponent } from "vue";
|
|
3
|
-
import { useI18n, useMongocampJobs, useToast } from "#imports";
|
|
2
|
+
import { computed, h, reactive, ref, resolveComponent } from "vue";
|
|
3
|
+
import { useI18n, useMongocampError, useMongocampJobs, useToast } from "#imports";
|
|
4
4
|
const { t } = useI18n();
|
|
5
|
+
const { describeError } = useMongocampError();
|
|
5
6
|
const { listJobs, listPossibleJobs, registerJob, updateJob, executeJob, deleteJob } = useMongocampJobs();
|
|
6
7
|
const toast = useToast();
|
|
7
8
|
const jobs = ref([]);
|
|
@@ -15,10 +16,15 @@ const executingJobs = ref(/* @__PURE__ */ new Set());
|
|
|
15
16
|
function jobKey(group, name) {
|
|
16
17
|
return `${group}/${name}`;
|
|
17
18
|
}
|
|
19
|
+
const loadError = ref(null);
|
|
18
20
|
async function fetchJobs() {
|
|
19
21
|
loading.value = true;
|
|
22
|
+
loadError.value = null;
|
|
20
23
|
try {
|
|
21
24
|
jobs.value = await listJobs();
|
|
25
|
+
} catch (e) {
|
|
26
|
+
loadError.value = e;
|
|
27
|
+
jobs.value = [];
|
|
22
28
|
} finally {
|
|
23
29
|
loading.value = false;
|
|
24
30
|
}
|
|
@@ -146,14 +152,25 @@ async function handleEditJob() {
|
|
|
146
152
|
}
|
|
147
153
|
}
|
|
148
154
|
const jobToDelete = ref({ group: "", name: "" });
|
|
155
|
+
const deleteError = ref("");
|
|
156
|
+
const deleting = ref(false);
|
|
149
157
|
function confirmDelete(group, name) {
|
|
150
158
|
jobToDelete.value = { group, name };
|
|
159
|
+
deleteError.value = "";
|
|
151
160
|
isDeleteModalOpen.value = true;
|
|
152
161
|
}
|
|
153
162
|
async function handleDeleteJob() {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
163
|
+
deleting.value = true;
|
|
164
|
+
deleteError.value = "";
|
|
165
|
+
try {
|
|
166
|
+
await deleteJob(jobToDelete.value.group, jobToDelete.value.name);
|
|
167
|
+
isDeleteModalOpen.value = false;
|
|
168
|
+
await fetchJobs();
|
|
169
|
+
} catch (e) {
|
|
170
|
+
deleteError.value = describeError(e, "nuxtUiMongocamp.jobs.errorDelete").message;
|
|
171
|
+
} finally {
|
|
172
|
+
deleting.value = false;
|
|
173
|
+
}
|
|
157
174
|
}
|
|
158
175
|
async function handleExecuteJob(group, name) {
|
|
159
176
|
const key = jobKey(group, name);
|
|
@@ -187,7 +204,7 @@ function sortHeader(column, label) {
|
|
|
187
204
|
onClick: () => column.toggleSorting(isSorted === "asc")
|
|
188
205
|
});
|
|
189
206
|
}
|
|
190
|
-
const columns = [
|
|
207
|
+
const columns = computed(() => [
|
|
191
208
|
{
|
|
192
209
|
accessorKey: "name",
|
|
193
210
|
header: ({ column }) => sortHeader(column, t("nuxtUiMongocamp.jobs.columnName"))
|
|
@@ -244,7 +261,7 @@ const columns = [
|
|
|
244
261
|
]);
|
|
245
262
|
}
|
|
246
263
|
}
|
|
247
|
-
];
|
|
264
|
+
]);
|
|
248
265
|
fetchJobs();
|
|
249
266
|
</script>
|
|
250
267
|
|
|
@@ -273,12 +290,21 @@ fetchJobs();
|
|
|
273
290
|
</div>
|
|
274
291
|
</div>
|
|
275
292
|
|
|
293
|
+
<MongocampErrorAlert
|
|
294
|
+
:error="loadError"
|
|
295
|
+
@retry="fetchJobs"
|
|
296
|
+
/>
|
|
297
|
+
|
|
276
298
|
<UTable
|
|
277
299
|
v-model:sorting="sorting"
|
|
278
300
|
:data="jobs"
|
|
279
301
|
:columns="columns"
|
|
280
302
|
:loading="loading"
|
|
281
|
-
|
|
303
|
+
>
|
|
304
|
+
<template #empty>
|
|
305
|
+
<MongocampEmptyState :title="t('nuxtUiMongocamp.empty.jobs')" />
|
|
306
|
+
</template>
|
|
307
|
+
</UTable>
|
|
282
308
|
|
|
283
309
|
<!-- Add Job Modal -->
|
|
284
310
|
<UModal
|
|
@@ -332,18 +358,28 @@ fetchJobs();
|
|
|
332
358
|
>
|
|
333
359
|
<template #body>
|
|
334
360
|
<p>{{ t("nuxtUiMongocamp.jobs.confirmDelete", { name: jobToDelete.name }) }}</p>
|
|
361
|
+
<UAlert
|
|
362
|
+
v-if="deleteError"
|
|
363
|
+
class="mt-3"
|
|
364
|
+
color="error"
|
|
365
|
+
variant="subtle"
|
|
366
|
+
icon="i-lucide-circle-alert"
|
|
367
|
+
:description="deleteError"
|
|
368
|
+
/>
|
|
335
369
|
</template>
|
|
336
370
|
<template #footer>
|
|
337
371
|
<UButton
|
|
338
372
|
:label="t('nuxtUiMongocamp.common.cancel')"
|
|
339
373
|
color="neutral"
|
|
340
374
|
variant="ghost"
|
|
375
|
+
:disabled="deleting"
|
|
341
376
|
@click="isDeleteModalOpen = false"
|
|
342
377
|
/>
|
|
343
378
|
<UButton
|
|
344
379
|
:label="t('nuxtUiMongocamp.common.delete')"
|
|
345
380
|
color="error"
|
|
346
381
|
icon="i-lucide-trash-2"
|
|
382
|
+
:loading="deleting"
|
|
347
383
|
@click="handleDeleteJob"
|
|
348
384
|
/>
|
|
349
385
|
</template>
|
|
@@ -48,7 +48,7 @@ async function actionLogin() {
|
|
|
48
48
|
</script>
|
|
49
49
|
|
|
50
50
|
<template>
|
|
51
|
-
<div class="flex flex-col items-center justify-center gap-4 p-4 w-
|
|
51
|
+
<div class="flex flex-col items-center justify-center gap-4 p-4 w-full">
|
|
52
52
|
<UPageCard class="w-full max-w-md">
|
|
53
53
|
<FUDataEdit
|
|
54
54
|
:data="data"
|
|
@@ -58,7 +58,8 @@ async function actionLogin() {
|
|
|
58
58
|
/>
|
|
59
59
|
<div
|
|
60
60
|
v-if="errorMessage.length > 0"
|
|
61
|
-
|
|
61
|
+
role="alert"
|
|
62
|
+
class="mt-2 text-sm text-error font-medium"
|
|
62
63
|
>
|
|
63
64
|
{{ errorMessage }}
|
|
64
65
|
</div>
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
<script setup>
|
|
2
|
-
import { h, reactive, ref, resolveComponent } from "vue";
|
|
3
|
-
import { useI18n } from "#imports";
|
|
2
|
+
import { computed, h, reactive, ref, resolveComponent } from "vue";
|
|
3
|
+
import { useI18n, useMongocampError } from "#imports";
|
|
4
4
|
import useMongocampAdmin from "../composables/useMongocampAdmin";
|
|
5
5
|
const props = defineProps({
|
|
6
6
|
roleName: { type: String, required: true }
|
|
7
7
|
});
|
|
8
8
|
const { t } = useI18n();
|
|
9
|
+
const { describeError } = useMongocampError();
|
|
9
10
|
const { listRoles, updateRole, listCollections } = useMongocampAdmin();
|
|
10
11
|
const grants = ref([]);
|
|
11
12
|
const allCollections = ref([]);
|
|
@@ -13,7 +14,8 @@ const isAdmin = ref(false);
|
|
|
13
14
|
const loading = ref(false);
|
|
14
15
|
const isAddModalOpen = ref(false);
|
|
15
16
|
const isEditModalOpen = ref(false);
|
|
16
|
-
const
|
|
17
|
+
const saveError = ref("");
|
|
18
|
+
const saving = ref(false);
|
|
17
19
|
const editIndex = ref(-1);
|
|
18
20
|
const editGrantName = ref("");
|
|
19
21
|
const newGrant = ref({ collectionName: "", read: false, write: false, administrate: false });
|
|
@@ -60,8 +62,11 @@ const editGrantSchema = reactive([
|
|
|
60
62
|
label: t("nuxtUiMongocamp.roleGrants.administrate")
|
|
61
63
|
}
|
|
62
64
|
]);
|
|
65
|
+
const loadError = ref(null);
|
|
63
66
|
async function fetchRole() {
|
|
64
67
|
loading.value = true;
|
|
68
|
+
loadError.value = null;
|
|
69
|
+
saveError.value = "";
|
|
65
70
|
try {
|
|
66
71
|
const roles = await listRoles();
|
|
67
72
|
const role = roles.find((r) => r.name === props.roleName);
|
|
@@ -69,6 +74,9 @@ async function fetchRole() {
|
|
|
69
74
|
isAdmin.value = role.isAdmin;
|
|
70
75
|
grants.value = (role.collectionGrants ?? []).map((g) => ({ ...g }));
|
|
71
76
|
}
|
|
77
|
+
} catch (e) {
|
|
78
|
+
loadError.value = e;
|
|
79
|
+
grants.value = [];
|
|
72
80
|
} finally {
|
|
73
81
|
loading.value = false;
|
|
74
82
|
}
|
|
@@ -76,54 +84,68 @@ async function fetchRole() {
|
|
|
76
84
|
async function fetchCollections() {
|
|
77
85
|
allCollections.value = await listCollections();
|
|
78
86
|
}
|
|
79
|
-
async function saveGrants() {
|
|
80
|
-
|
|
87
|
+
async function saveGrants(next) {
|
|
88
|
+
if (saving.value) return false;
|
|
89
|
+
saving.value = true;
|
|
90
|
+
saveError.value = "";
|
|
81
91
|
try {
|
|
82
|
-
await updateRole(props.roleName, isAdmin.value,
|
|
83
|
-
await fetchRole();
|
|
92
|
+
await updateRole(props.roleName, isAdmin.value, next);
|
|
84
93
|
} catch (e) {
|
|
85
|
-
|
|
94
|
+
saveError.value = describeError(e, "nuxtUiMongocamp.roleGrants.errorSave").message;
|
|
95
|
+
return false;
|
|
96
|
+
} finally {
|
|
97
|
+
saving.value = false;
|
|
86
98
|
}
|
|
99
|
+
await fetchRole();
|
|
100
|
+
return true;
|
|
87
101
|
}
|
|
88
102
|
async function handleAddGrant() {
|
|
89
103
|
const raw = newGrant.value.collectionName;
|
|
90
104
|
const collectionName = typeof newGrant.value.collectionName === "object" ? raw.value ?? raw.label ?? "" : newGrant.value.collectionName;
|
|
91
|
-
grants.value
|
|
105
|
+
const next = [...grants.value, {
|
|
92
106
|
name: collectionName,
|
|
93
107
|
read: newGrant.value.read,
|
|
94
108
|
write: newGrant.value.write,
|
|
95
109
|
administrate: newGrant.value.administrate,
|
|
96
110
|
grantType: "COLLECTION"
|
|
97
|
-
}
|
|
98
|
-
await saveGrants();
|
|
99
|
-
isAddModalOpen.value = false;
|
|
111
|
+
}];
|
|
112
|
+
if (await saveGrants(next)) isAddModalOpen.value = false;
|
|
100
113
|
}
|
|
101
114
|
function openEdit(index) {
|
|
102
115
|
const grant = grants.value[index];
|
|
103
116
|
editIndex.value = index;
|
|
117
|
+
saveError.value = "";
|
|
104
118
|
editGrantName.value = grant.name;
|
|
105
119
|
editGrant.value = { read: grant.read, write: grant.write, administrate: grant.administrate };
|
|
106
120
|
isEditModalOpen.value = true;
|
|
107
121
|
}
|
|
108
122
|
async function handleEditGrant() {
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
...grant,
|
|
112
|
-
read: editGrant.value.read,
|
|
113
|
-
write: editGrant.value.write,
|
|
114
|
-
administrate: editGrant.value.administrate
|
|
115
|
-
};
|
|
116
|
-
await saveGrants();
|
|
117
|
-
isEditModalOpen.value = false;
|
|
123
|
+
const next = grants.value.map((grant, index) => index === editIndex.value ? { ...grant, read: editGrant.value.read, write: editGrant.value.write, administrate: editGrant.value.administrate } : grant);
|
|
124
|
+
if (await saveGrants(next)) isEditModalOpen.value = false;
|
|
118
125
|
}
|
|
119
126
|
async function removeGrant(index) {
|
|
120
|
-
grants.value.
|
|
121
|
-
|
|
127
|
+
await saveGrants(grants.value.filter((_, i) => i !== index));
|
|
128
|
+
}
|
|
129
|
+
const missingReadCollections = computed(() => {
|
|
130
|
+
const grantedNames = new Set(grants.value.map((g) => g.name));
|
|
131
|
+
return allCollections.value.filter((c) => !c.startsWith("mc_") && !grantedNames.has(c));
|
|
132
|
+
});
|
|
133
|
+
async function addAllReadGrants() {
|
|
134
|
+
const added = missingReadCollections.value.map((name) => ({
|
|
135
|
+
name,
|
|
136
|
+
read: true,
|
|
137
|
+
write: false,
|
|
138
|
+
administrate: false,
|
|
139
|
+
grantType: "COLLECTION"
|
|
140
|
+
}));
|
|
141
|
+
if (!added.length) return;
|
|
142
|
+
await saveGrants([...grants.value, ...added]);
|
|
122
143
|
}
|
|
123
144
|
function openAdd() {
|
|
124
145
|
const grantedNames = new Set(grants.value.map((g) => g.name));
|
|
125
146
|
addGrantSchema[0].options = allCollections.value.filter((c) => !grantedNames.has(c));
|
|
126
147
|
newGrant.value = { collectionName: "", read: false, write: false, administrate: false };
|
|
148
|
+
saveError.value = "";
|
|
127
149
|
isAddModalOpen.value = true;
|
|
128
150
|
}
|
|
129
151
|
const UBadge = resolveComponent("UBadge");
|
|
@@ -132,7 +154,7 @@ const UTooltip = resolveComponent("UTooltip");
|
|
|
132
154
|
function withTooltip(text, node) {
|
|
133
155
|
return h(UTooltip, { text }, { default: () => node });
|
|
134
156
|
}
|
|
135
|
-
const columns = [
|
|
157
|
+
const columns = computed(() => [
|
|
136
158
|
{
|
|
137
159
|
accessorKey: "name",
|
|
138
160
|
header: t("nuxtUiMongocamp.roleGrants.columnCollection")
|
|
@@ -183,6 +205,7 @@ const columns = [
|
|
|
183
205
|
"variant": "ghost",
|
|
184
206
|
"size": "sm",
|
|
185
207
|
"aria-label": t("nuxtUiMongocamp.roleGrants.editGrantTooltip"),
|
|
208
|
+
"disabled": saving.value,
|
|
186
209
|
"onClick": () => openEdit(row.index)
|
|
187
210
|
})),
|
|
188
211
|
withTooltip(t("nuxtUiMongocamp.roleGrants.removeGrantTooltip"), h(UButton, {
|
|
@@ -191,11 +214,12 @@ const columns = [
|
|
|
191
214
|
"variant": "ghost",
|
|
192
215
|
"size": "sm",
|
|
193
216
|
"aria-label": t("nuxtUiMongocamp.roleGrants.removeGrantTooltip"),
|
|
217
|
+
"disabled": saving.value,
|
|
194
218
|
"onClick": () => removeGrant(row.index)
|
|
195
219
|
}))
|
|
196
220
|
])
|
|
197
221
|
}
|
|
198
|
-
];
|
|
222
|
+
]);
|
|
199
223
|
fetchRole();
|
|
200
224
|
fetchCollections();
|
|
201
225
|
</script>
|
|
@@ -217,6 +241,16 @@ fetchCollections();
|
|
|
217
241
|
@click="fetchRole"
|
|
218
242
|
/>
|
|
219
243
|
</UTooltip>
|
|
244
|
+
<UTooltip :text="t('nuxtUiMongocamp.roleGrants.addAllReadTooltip')">
|
|
245
|
+
<UButton
|
|
246
|
+
icon="i-lucide-eye"
|
|
247
|
+
color="neutral"
|
|
248
|
+
variant="outline"
|
|
249
|
+
:label="t('nuxtUiMongocamp.roleGrants.addAllRead')"
|
|
250
|
+
:disabled="saving || loading || !missingReadCollections.length"
|
|
251
|
+
@click="addAllReadGrants"
|
|
252
|
+
/>
|
|
253
|
+
</UTooltip>
|
|
220
254
|
<UButton
|
|
221
255
|
icon="i-lucide-plus"
|
|
222
256
|
:label="t('nuxtUiMongocamp.roleGrants.addGrant')"
|
|
@@ -225,11 +259,30 @@ fetchCollections();
|
|
|
225
259
|
</div>
|
|
226
260
|
</div>
|
|
227
261
|
|
|
262
|
+
<MongocampErrorAlert
|
|
263
|
+
:error="loadError"
|
|
264
|
+
@retry="fetchRole"
|
|
265
|
+
/>
|
|
266
|
+
|
|
267
|
+
<!-- a refused remove has no dialog to show its reason in; add/edit show it inside their own dialog -->
|
|
268
|
+
<UAlert
|
|
269
|
+
v-if="saveError && !isAddModalOpen && !isEditModalOpen"
|
|
270
|
+
color="error"
|
|
271
|
+
variant="subtle"
|
|
272
|
+
icon="i-lucide-circle-alert"
|
|
273
|
+
:title="t('nuxtUiMongocamp.roleGrants.errorSave')"
|
|
274
|
+
:description="saveError"
|
|
275
|
+
/>
|
|
276
|
+
|
|
228
277
|
<UTable
|
|
229
278
|
:data="grants"
|
|
230
279
|
:columns="columns"
|
|
231
280
|
:loading="loading"
|
|
232
|
-
|
|
281
|
+
>
|
|
282
|
+
<template #empty>
|
|
283
|
+
<MongocampEmptyState :title="t('nuxtUiMongocamp.empty.grants')" />
|
|
284
|
+
</template>
|
|
285
|
+
</UTable>
|
|
233
286
|
|
|
234
287
|
<!-- Add Grant Modal -->
|
|
235
288
|
<UModal
|
|
@@ -244,12 +297,14 @@ fetchCollections();
|
|
|
244
297
|
submit-icon="i-lucide-plus"
|
|
245
298
|
@data-saved="handleAddGrant"
|
|
246
299
|
/>
|
|
247
|
-
<
|
|
248
|
-
v-if="
|
|
249
|
-
class="mt-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
300
|
+
<UAlert
|
|
301
|
+
v-if="saveError"
|
|
302
|
+
class="mt-3"
|
|
303
|
+
color="error"
|
|
304
|
+
variant="subtle"
|
|
305
|
+
icon="i-lucide-circle-alert"
|
|
306
|
+
:description="saveError"
|
|
307
|
+
/>
|
|
253
308
|
</template>
|
|
254
309
|
</UModal>
|
|
255
310
|
|
|
@@ -266,12 +321,14 @@ fetchCollections();
|
|
|
266
321
|
submit-icon="i-lucide-save"
|
|
267
322
|
@data-saved="handleEditGrant"
|
|
268
323
|
/>
|
|
269
|
-
<
|
|
270
|
-
v-if="
|
|
271
|
-
class="mt-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
324
|
+
<UAlert
|
|
325
|
+
v-if="saveError"
|
|
326
|
+
class="mt-3"
|
|
327
|
+
color="error"
|
|
328
|
+
variant="subtle"
|
|
329
|
+
icon="i-lucide-circle-alert"
|
|
330
|
+
:description="saveError"
|
|
331
|
+
/>
|
|
275
332
|
</template>
|
|
276
333
|
</UModal>
|
|
277
334
|
</div>
|