@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
|
@@ -1,7 +1,9 @@
|
|
|
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
|
+
import { runBulkDelete } from "../utils/bulkDelete";
|
|
6
|
+
import { createSelectColumn } from "../utils/createSelectColumn";
|
|
5
7
|
const props = defineProps({
|
|
6
8
|
grantsPath: { type: String, required: false }
|
|
7
9
|
});
|
|
@@ -15,11 +17,17 @@ let filterTimer;
|
|
|
15
17
|
const isAddModalOpen = ref(false);
|
|
16
18
|
const isEditModalOpen = ref(false);
|
|
17
19
|
const isDeleteModalOpen = ref(false);
|
|
20
|
+
const isCloneModalOpen = ref(false);
|
|
18
21
|
const roleToDelete = ref("");
|
|
19
22
|
const errorMessage = ref("");
|
|
20
23
|
const newRole = ref({ name: "", isAdmin: false });
|
|
21
24
|
const editRole = ref({ roleName: "", isAdmin: false });
|
|
22
25
|
const editGrants = ref([]);
|
|
26
|
+
const cloneSource = ref("");
|
|
27
|
+
const cloneRole = ref({ name: "", isAdmin: false });
|
|
28
|
+
const cloneGrants = ref([]);
|
|
29
|
+
const cloneError = ref("");
|
|
30
|
+
const cloning = ref(false);
|
|
23
31
|
const addRoleSchema = reactive([
|
|
24
32
|
{
|
|
25
33
|
$formkit: "nuxtUIInput",
|
|
@@ -40,10 +48,49 @@ const editRoleSchema = reactive([
|
|
|
40
48
|
label: t("nuxtUiMongocamp.roles.adminRole")
|
|
41
49
|
}
|
|
42
50
|
]);
|
|
51
|
+
const cloneRoleSchema = reactive([
|
|
52
|
+
{
|
|
53
|
+
$formkit: "nuxtUIInput",
|
|
54
|
+
name: "name",
|
|
55
|
+
label: t("nuxtUiMongocamp.roles.roleName"),
|
|
56
|
+
validation: "required|length:2"
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
$formkit: "nuxtUISwitch",
|
|
60
|
+
name: "isAdmin",
|
|
61
|
+
label: t("nuxtUiMongocamp.roles.adminRole")
|
|
62
|
+
}
|
|
63
|
+
]);
|
|
64
|
+
const loadError = ref(null);
|
|
65
|
+
const { describeError } = useMongocampError();
|
|
66
|
+
const rowSelection = ref({});
|
|
67
|
+
const selectedRoleNames = computed(() => Object.keys(rowSelection.value).filter((name) => rowSelection.value[name]));
|
|
68
|
+
const bulkDeleting = ref(false);
|
|
69
|
+
const bulkError = ref("");
|
|
70
|
+
async function handleBulkDelete() {
|
|
71
|
+
bulkDeleting.value = true;
|
|
72
|
+
bulkError.value = "";
|
|
73
|
+
const names = [...selectedRoleNames.value];
|
|
74
|
+
try {
|
|
75
|
+
const { failed } = await runBulkDelete(names, (name) => deleteRole(name));
|
|
76
|
+
await fetchRoles();
|
|
77
|
+
if (failed.length > 0) {
|
|
78
|
+
rowSelection.value = Object.fromEntries(failed.map((f) => [f.item, true]));
|
|
79
|
+
bulkError.value = t("nuxtUiMongocamp.bulk.partialFailure", { failed: failed.length, total: names.length, reason: describeError(failed[0].error).message });
|
|
80
|
+
}
|
|
81
|
+
} finally {
|
|
82
|
+
bulkDeleting.value = false;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
43
85
|
async function fetchRoles() {
|
|
44
86
|
loading.value = true;
|
|
87
|
+
loadError.value = null;
|
|
88
|
+
rowSelection.value = {};
|
|
45
89
|
try {
|
|
46
90
|
roles.value = await listRoles(filterText.value);
|
|
91
|
+
} catch (e) {
|
|
92
|
+
loadError.value = e;
|
|
93
|
+
roles.value = [];
|
|
47
94
|
} finally {
|
|
48
95
|
loading.value = false;
|
|
49
96
|
}
|
|
@@ -78,18 +125,50 @@ async function handleEditRole() {
|
|
|
78
125
|
errorMessage.value = e instanceof Error ? e.message : t("nuxtUiMongocamp.roles.errorEditRole");
|
|
79
126
|
}
|
|
80
127
|
}
|
|
128
|
+
function openClone(role) {
|
|
129
|
+
cloneSource.value = role.name;
|
|
130
|
+
cloneRole.value = { name: "", isAdmin: role.isAdmin };
|
|
131
|
+
cloneGrants.value = (role.collectionGrants ?? []).map((g) => ({ ...g }));
|
|
132
|
+
cloneError.value = "";
|
|
133
|
+
isCloneModalOpen.value = true;
|
|
134
|
+
}
|
|
135
|
+
async function handleCloneRole() {
|
|
136
|
+
cloning.value = true;
|
|
137
|
+
cloneError.value = "";
|
|
138
|
+
try {
|
|
139
|
+
await addRole(cloneRole.value.name, cloneRole.value.isAdmin, cloneGrants.value);
|
|
140
|
+
isCloneModalOpen.value = false;
|
|
141
|
+
await fetchRoles();
|
|
142
|
+
} catch (e) {
|
|
143
|
+
cloneError.value = describeError(e, "nuxtUiMongocamp.roles.errorClone").message;
|
|
144
|
+
} finally {
|
|
145
|
+
cloning.value = false;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
const deleteError = ref("");
|
|
149
|
+
const deleting = ref(false);
|
|
81
150
|
function confirmDelete(roleName) {
|
|
82
151
|
roleToDelete.value = roleName;
|
|
152
|
+
deleteError.value = "";
|
|
83
153
|
isDeleteModalOpen.value = true;
|
|
84
154
|
}
|
|
85
155
|
async function handleDeleteRole() {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
156
|
+
deleting.value = true;
|
|
157
|
+
deleteError.value = "";
|
|
158
|
+
try {
|
|
159
|
+
await deleteRole(roleToDelete.value);
|
|
160
|
+
isDeleteModalOpen.value = false;
|
|
161
|
+
await fetchRoles();
|
|
162
|
+
} catch (e) {
|
|
163
|
+
deleteError.value = describeError(e, "nuxtUiMongocamp.roles.errorDelete").message;
|
|
164
|
+
} finally {
|
|
165
|
+
deleting.value = false;
|
|
166
|
+
}
|
|
89
167
|
}
|
|
90
168
|
const UBadge = resolveComponent("UBadge");
|
|
91
169
|
const UButton = resolveComponent("UButton");
|
|
92
170
|
const UTooltip = resolveComponent("UTooltip");
|
|
171
|
+
const UCheckbox = resolveComponent("UCheckbox");
|
|
93
172
|
function withTooltip(text, node) {
|
|
94
173
|
return h(UTooltip, { text }, { default: () => node });
|
|
95
174
|
}
|
|
@@ -104,7 +183,8 @@ function sortHeader(column, label) {
|
|
|
104
183
|
onClick: () => column.toggleSorting(isSorted === "asc")
|
|
105
184
|
});
|
|
106
185
|
}
|
|
107
|
-
const columns = [
|
|
186
|
+
const columns = computed(() => [
|
|
187
|
+
createSelectColumn(UCheckbox, { selectAll: t("nuxtUiMongocamp.bulk.selectAll"), selectRow: t("nuxtUiMongocamp.bulk.selectRow") }),
|
|
108
188
|
{
|
|
109
189
|
accessorKey: "name",
|
|
110
190
|
header: ({ column }) => sortHeader(column, t("nuxtUiMongocamp.roles.columnRole"))
|
|
@@ -146,6 +226,14 @@ const columns = [
|
|
|
146
226
|
"aria-label": t("nuxtUiMongocamp.roles.editRoleTooltip"),
|
|
147
227
|
"onClick": () => openEdit(row.original)
|
|
148
228
|
})),
|
|
229
|
+
withTooltip(t("nuxtUiMongocamp.roles.cloneRoleTooltip"), h(UButton, {
|
|
230
|
+
"icon": "i-lucide-copy",
|
|
231
|
+
"color": "neutral",
|
|
232
|
+
"variant": "ghost",
|
|
233
|
+
"size": "sm",
|
|
234
|
+
"aria-label": t("nuxtUiMongocamp.roles.cloneRoleTooltip"),
|
|
235
|
+
"onClick": () => openClone(row.original)
|
|
236
|
+
})),
|
|
149
237
|
withTooltip(t("nuxtUiMongocamp.roles.deleteRoleTooltip"), h(UButton, {
|
|
150
238
|
"icon": "i-lucide-trash-2",
|
|
151
239
|
"color": "error",
|
|
@@ -156,7 +244,7 @@ const columns = [
|
|
|
156
244
|
}))
|
|
157
245
|
])
|
|
158
246
|
}
|
|
159
|
-
];
|
|
247
|
+
]);
|
|
160
248
|
fetchRoles();
|
|
161
249
|
</script>
|
|
162
250
|
|
|
@@ -193,12 +281,32 @@ fetchRoles();
|
|
|
193
281
|
</div>
|
|
194
282
|
</div>
|
|
195
283
|
|
|
284
|
+
<MongocampErrorAlert
|
|
285
|
+
:error="loadError"
|
|
286
|
+
@retry="fetchRoles"
|
|
287
|
+
/>
|
|
288
|
+
|
|
289
|
+
<MongocampBulkDelete
|
|
290
|
+
:selected="selectedRoleNames"
|
|
291
|
+
:deleting="bulkDeleting"
|
|
292
|
+
:error="bulkError"
|
|
293
|
+
@open="bulkError = ''"
|
|
294
|
+
@clear="rowSelection = {}"
|
|
295
|
+
@confirm="handleBulkDelete"
|
|
296
|
+
/>
|
|
297
|
+
|
|
196
298
|
<UTable
|
|
197
299
|
v-model:sorting="sorting"
|
|
300
|
+
v-model:row-selection="rowSelection"
|
|
301
|
+
:get-row-id="(row) => row.name"
|
|
198
302
|
:data="roles"
|
|
199
303
|
:columns="columns"
|
|
200
304
|
:loading="loading"
|
|
201
|
-
|
|
305
|
+
>
|
|
306
|
+
<template #empty>
|
|
307
|
+
<MongocampEmptyState :title="t('nuxtUiMongocamp.empty.roles')" />
|
|
308
|
+
</template>
|
|
309
|
+
</UTable>
|
|
202
310
|
|
|
203
311
|
<!-- Add Role Modal -->
|
|
204
312
|
<UModal
|
|
@@ -244,6 +352,33 @@ fetchRoles();
|
|
|
244
352
|
</template>
|
|
245
353
|
</UModal>
|
|
246
354
|
|
|
355
|
+
<!-- Clone Role Modal -->
|
|
356
|
+
<UModal
|
|
357
|
+
v-model:open="isCloneModalOpen"
|
|
358
|
+
:title="t('nuxtUiMongocamp.roles.cloneRoleTitle', { roleName: cloneSource })"
|
|
359
|
+
>
|
|
360
|
+
<template #body>
|
|
361
|
+
<p class="mb-3 text-sm text-dimmed">
|
|
362
|
+
{{ t("nuxtUiMongocamp.roles.cloneRoleHint", { count: cloneGrants.length }) }}
|
|
363
|
+
</p>
|
|
364
|
+
<FUDataEdit
|
|
365
|
+
:data="cloneRole"
|
|
366
|
+
:schema="cloneRoleSchema"
|
|
367
|
+
:submit-label="t('nuxtUiMongocamp.roles.cloneRole')"
|
|
368
|
+
submit-icon="i-lucide-copy"
|
|
369
|
+
@data-saved="handleCloneRole"
|
|
370
|
+
/>
|
|
371
|
+
<UAlert
|
|
372
|
+
v-if="cloneError"
|
|
373
|
+
class="mt-3"
|
|
374
|
+
color="error"
|
|
375
|
+
variant="subtle"
|
|
376
|
+
icon="i-lucide-circle-alert"
|
|
377
|
+
:description="cloneError"
|
|
378
|
+
/>
|
|
379
|
+
</template>
|
|
380
|
+
</UModal>
|
|
381
|
+
|
|
247
382
|
<!-- Delete Confirmation Modal -->
|
|
248
383
|
<UModal
|
|
249
384
|
v-model:open="isDeleteModalOpen"
|
|
@@ -252,17 +387,27 @@ fetchRoles();
|
|
|
252
387
|
>
|
|
253
388
|
<template #body>
|
|
254
389
|
<p>{{ t("nuxtUiMongocamp.roles.confirmDelete", { roleName: roleToDelete }) }}</p>
|
|
390
|
+
<UAlert
|
|
391
|
+
v-if="deleteError"
|
|
392
|
+
class="mt-3"
|
|
393
|
+
color="error"
|
|
394
|
+
variant="subtle"
|
|
395
|
+
icon="i-lucide-circle-alert"
|
|
396
|
+
:description="deleteError"
|
|
397
|
+
/>
|
|
255
398
|
</template>
|
|
256
399
|
<template #footer>
|
|
257
400
|
<UButton
|
|
258
401
|
:label="t('nuxtUiMongocamp.common.cancel')"
|
|
259
402
|
color="neutral"
|
|
260
403
|
variant="ghost"
|
|
404
|
+
:disabled="deleting"
|
|
261
405
|
@click="isDeleteModalOpen = false"
|
|
262
406
|
/>
|
|
263
407
|
<UButton
|
|
264
408
|
:label="t('nuxtUiMongocamp.common.delete')"
|
|
265
409
|
color="error"
|
|
410
|
+
:loading="deleting"
|
|
266
411
|
@click="handleDeleteRole"
|
|
267
412
|
/>
|
|
268
413
|
</template>
|
|
@@ -1,7 +1,9 @@
|
|
|
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, useMongocampStorage } from "#imports";
|
|
4
4
|
import useMongocampAdmin from "../composables/useMongocampAdmin";
|
|
5
|
+
import { runBulkDelete } from "../utils/bulkDelete";
|
|
6
|
+
import { createSelectColumn } from "../utils/createSelectColumn";
|
|
5
7
|
const { t } = useI18n();
|
|
6
8
|
const { listUsers, addUser, deleteUser, updateUserRoles, updateUserPassword, listRoles } = useMongocampAdmin();
|
|
7
9
|
const users = ref([]);
|
|
@@ -75,10 +77,44 @@ const editUserSchema = reactive([
|
|
|
75
77
|
transferRightHeaderText: t("nuxtUiMongocamp.users.assigned")
|
|
76
78
|
}
|
|
77
79
|
]);
|
|
80
|
+
const loadError = ref(null);
|
|
81
|
+
const { describeError } = useMongocampError();
|
|
82
|
+
const storage = useMongocampStorage();
|
|
83
|
+
const rowSelection = ref({});
|
|
84
|
+
const selectedUserIds = computed(() => Object.keys(rowSelection.value).filter((id) => rowSelection.value[id]));
|
|
85
|
+
const bulkDeleting = ref(false);
|
|
86
|
+
const bulkError = ref("");
|
|
87
|
+
function isSelf(userId) {
|
|
88
|
+
const me = storage.value?.profile.user;
|
|
89
|
+
return !!me && userId === me;
|
|
90
|
+
}
|
|
91
|
+
function canSelectUser(row) {
|
|
92
|
+
return !isSelf(row.original.user);
|
|
93
|
+
}
|
|
94
|
+
async function handleBulkDelete() {
|
|
95
|
+
bulkDeleting.value = true;
|
|
96
|
+
bulkError.value = "";
|
|
97
|
+
const ids = [...selectedUserIds.value];
|
|
98
|
+
try {
|
|
99
|
+
const { failed } = await runBulkDelete(ids, (id) => deleteUser(id));
|
|
100
|
+
await fetchUsers();
|
|
101
|
+
if (failed.length > 0) {
|
|
102
|
+
rowSelection.value = Object.fromEntries(failed.map((f) => [f.item, true]));
|
|
103
|
+
bulkError.value = t("nuxtUiMongocamp.bulk.partialFailure", { failed: failed.length, total: ids.length, reason: describeError(failed[0].error).message });
|
|
104
|
+
}
|
|
105
|
+
} finally {
|
|
106
|
+
bulkDeleting.value = false;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
78
109
|
async function fetchUsers() {
|
|
79
110
|
loading.value = true;
|
|
111
|
+
loadError.value = null;
|
|
112
|
+
rowSelection.value = {};
|
|
80
113
|
try {
|
|
81
114
|
users.value = await listUsers(filterText.value);
|
|
115
|
+
} catch (e) {
|
|
116
|
+
loadError.value = e;
|
|
117
|
+
users.value = [];
|
|
82
118
|
} finally {
|
|
83
119
|
loading.value = false;
|
|
84
120
|
}
|
|
@@ -127,18 +163,30 @@ async function handleEditUser() {
|
|
|
127
163
|
errorMessage.value = e instanceof Error ? e.message : t("nuxtUiMongocamp.users.errorEditUser");
|
|
128
164
|
}
|
|
129
165
|
}
|
|
166
|
+
const deleteError = ref("");
|
|
167
|
+
const deleting = ref(false);
|
|
130
168
|
function confirmDelete(userId) {
|
|
131
169
|
userToDelete.value = userId;
|
|
170
|
+
deleteError.value = "";
|
|
132
171
|
isDeleteModalOpen.value = true;
|
|
133
172
|
}
|
|
134
173
|
async function handleDeleteUser() {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
174
|
+
deleting.value = true;
|
|
175
|
+
deleteError.value = "";
|
|
176
|
+
try {
|
|
177
|
+
await deleteUser(userToDelete.value);
|
|
178
|
+
isDeleteModalOpen.value = false;
|
|
179
|
+
await fetchUsers();
|
|
180
|
+
} catch (e) {
|
|
181
|
+
deleteError.value = describeError(e, "nuxtUiMongocamp.users.errorDelete").message;
|
|
182
|
+
} finally {
|
|
183
|
+
deleting.value = false;
|
|
184
|
+
}
|
|
138
185
|
}
|
|
139
186
|
const UBadge = resolveComponent("UBadge");
|
|
140
187
|
const UButton = resolveComponent("UButton");
|
|
141
188
|
const UTooltip = resolveComponent("UTooltip");
|
|
189
|
+
const UCheckbox = resolveComponent("UCheckbox");
|
|
142
190
|
function withTooltip(text, node) {
|
|
143
191
|
return h(UTooltip, { text }, { default: () => node });
|
|
144
192
|
}
|
|
@@ -153,7 +201,27 @@ function sortHeader(column, label) {
|
|
|
153
201
|
onClick: () => column.toggleSorting(isSorted === "asc")
|
|
154
202
|
});
|
|
155
203
|
}
|
|
156
|
-
|
|
204
|
+
function deleteButton(userId) {
|
|
205
|
+
const button = (disabled) => h(UButton, {
|
|
206
|
+
"icon": "i-lucide-trash-2",
|
|
207
|
+
"color": "error",
|
|
208
|
+
"variant": "ghost",
|
|
209
|
+
"size": "sm",
|
|
210
|
+
"aria-label": t("nuxtUiMongocamp.users.deleteUserTooltip"),
|
|
211
|
+
disabled,
|
|
212
|
+
"onClick": () => confirmDelete(userId)
|
|
213
|
+
});
|
|
214
|
+
if (isSelf(userId)) {
|
|
215
|
+
return h("span", { class: "inline-flex", title: t("nuxtUiMongocamp.bulk.cannotSelectSelf") }, [button(true)]);
|
|
216
|
+
}
|
|
217
|
+
return withTooltip(t("nuxtUiMongocamp.users.deleteUserTooltip"), button(false));
|
|
218
|
+
}
|
|
219
|
+
const columns = computed(() => [
|
|
220
|
+
createSelectColumn(UCheckbox, {
|
|
221
|
+
selectAll: t("nuxtUiMongocamp.bulk.selectAll"),
|
|
222
|
+
selectRow: t("nuxtUiMongocamp.bulk.selectRow"),
|
|
223
|
+
unselectable: t("nuxtUiMongocamp.bulk.cannotSelectSelf")
|
|
224
|
+
}),
|
|
157
225
|
{
|
|
158
226
|
accessorKey: "user",
|
|
159
227
|
header: ({ column }) => sortHeader(column, t("nuxtUiMongocamp.users.columnUser"))
|
|
@@ -193,17 +261,10 @@ const columns = [
|
|
|
193
261
|
"aria-label": t("nuxtUiMongocamp.users.editUserTooltip"),
|
|
194
262
|
"onClick": () => openEdit(row.original)
|
|
195
263
|
})),
|
|
196
|
-
|
|
197
|
-
"icon": "i-lucide-trash-2",
|
|
198
|
-
"color": "error",
|
|
199
|
-
"variant": "ghost",
|
|
200
|
-
"size": "sm",
|
|
201
|
-
"aria-label": t("nuxtUiMongocamp.users.deleteUserTooltip"),
|
|
202
|
-
"onClick": () => confirmDelete(row.original.user)
|
|
203
|
-
}))
|
|
264
|
+
deleteButton(row.original.user)
|
|
204
265
|
])
|
|
205
266
|
}
|
|
206
|
-
];
|
|
267
|
+
]);
|
|
207
268
|
fetchUsers();
|
|
208
269
|
fetchRoles();
|
|
209
270
|
</script>
|
|
@@ -241,12 +302,33 @@ fetchRoles();
|
|
|
241
302
|
</div>
|
|
242
303
|
</div>
|
|
243
304
|
|
|
305
|
+
<MongocampErrorAlert
|
|
306
|
+
:error="loadError"
|
|
307
|
+
@retry="fetchUsers"
|
|
308
|
+
/>
|
|
309
|
+
|
|
310
|
+
<MongocampBulkDelete
|
|
311
|
+
:selected="selectedUserIds"
|
|
312
|
+
:deleting="bulkDeleting"
|
|
313
|
+
:error="bulkError"
|
|
314
|
+
@open="bulkError = ''"
|
|
315
|
+
@clear="rowSelection = {}"
|
|
316
|
+
@confirm="handleBulkDelete"
|
|
317
|
+
/>
|
|
318
|
+
|
|
244
319
|
<UTable
|
|
245
320
|
v-model:sorting="sorting"
|
|
321
|
+
v-model:row-selection="rowSelection"
|
|
322
|
+
:get-row-id="(row) => row.user"
|
|
323
|
+
:row-selection-options="{ enableRowSelection: canSelectUser }"
|
|
246
324
|
:data="users"
|
|
247
325
|
:columns="columns"
|
|
248
326
|
:loading="loading"
|
|
249
|
-
|
|
327
|
+
>
|
|
328
|
+
<template #empty>
|
|
329
|
+
<MongocampEmptyState :title="t('nuxtUiMongocamp.empty.users')" />
|
|
330
|
+
</template>
|
|
331
|
+
</UTable>
|
|
250
332
|
|
|
251
333
|
<!-- Add User Modal -->
|
|
252
334
|
<UModal
|
|
@@ -300,17 +382,27 @@ fetchRoles();
|
|
|
300
382
|
>
|
|
301
383
|
<template #body>
|
|
302
384
|
<p>{{ t("nuxtUiMongocamp.users.confirmDelete", { userId: userToDelete }) }}</p>
|
|
385
|
+
<UAlert
|
|
386
|
+
v-if="deleteError"
|
|
387
|
+
class="mt-3"
|
|
388
|
+
color="error"
|
|
389
|
+
variant="subtle"
|
|
390
|
+
icon="i-lucide-circle-alert"
|
|
391
|
+
:description="deleteError"
|
|
392
|
+
/>
|
|
303
393
|
</template>
|
|
304
394
|
<template #footer>
|
|
305
395
|
<UButton
|
|
306
396
|
:label="t('nuxtUiMongocamp.common.cancel')"
|
|
307
397
|
color="neutral"
|
|
308
398
|
variant="ghost"
|
|
399
|
+
:disabled="deleting"
|
|
309
400
|
@click="isDeleteModalOpen = false"
|
|
310
401
|
/>
|
|
311
402
|
<UButton
|
|
312
403
|
:label="t('nuxtUiMongocamp.common.delete')"
|
|
313
404
|
color="error"
|
|
405
|
+
:loading="deleting"
|
|
314
406
|
@click="handleDeleteUser"
|
|
315
407
|
/>
|
|
316
408
|
</template>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type MongocampErrorKind = 'network' | 'unauthorized' | 'forbidden' | 'other';
|
|
2
|
+
export interface DescribedError {
|
|
3
|
+
kind: MongocampErrorKind;
|
|
4
|
+
message: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function useMongocampError(): {
|
|
7
|
+
describeError: (error: unknown, fallbackKey?: string) => DescribedError;
|
|
8
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useI18n } from "#imports";
|
|
2
|
+
export function useMongocampError() {
|
|
3
|
+
const { t } = useI18n();
|
|
4
|
+
function describeError(error, fallbackKey) {
|
|
5
|
+
const name = error?.name;
|
|
6
|
+
const status = error?.response?.status;
|
|
7
|
+
if (name === "FetchError") {
|
|
8
|
+
return { kind: "network", message: t("nuxtUiMongocamp.errors.network") };
|
|
9
|
+
}
|
|
10
|
+
if (status === 401) {
|
|
11
|
+
return { kind: "unauthorized", message: t("nuxtUiMongocamp.errors.unauthorized") };
|
|
12
|
+
}
|
|
13
|
+
if (status === 403) {
|
|
14
|
+
return { kind: "forbidden", message: t("nuxtUiMongocamp.errors.forbidden") };
|
|
15
|
+
}
|
|
16
|
+
const message = error instanceof Error && error.message ? error.message : t(fallbackKey ?? "nuxtUiMongocamp.errors.generic");
|
|
17
|
+
return { kind: "other", message };
|
|
18
|
+
}
|
|
19
|
+
return { describeError };
|
|
20
|
+
}
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
+
import { isIsoDateTimeString } from "../utils/isoDate.js";
|
|
1
2
|
function isPlainObject(value) {
|
|
2
3
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3
4
|
}
|
|
4
5
|
const NUMBER_WRAPPER_KEYS = ["$numberInt", "$numberLong", "$numberDouble", "$numberDecimal"];
|
|
5
|
-
const ISO_DATE_TIME_REGEX = /^\d{4}-\d{2}-\d{2}(?:[T ]\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:?\d{2})?)?$/;
|
|
6
|
-
function isIsoDateTimeString(value) {
|
|
7
|
-
return ISO_DATE_TIME_REGEX.test(value) && !Number.isNaN(Date.parse(value));
|
|
8
|
-
}
|
|
9
6
|
function unwrapDateTime(raw) {
|
|
10
7
|
const inner = raw.$date;
|
|
11
8
|
if (typeof inner === "string" || typeof inner === "number") return new Date(inner).toISOString();
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { buildCondition, buildFilterQuery, conditionValueText, countActiveConditions, operatorLabelKey, operatorsFor, toFilterFieldType, valueCountFor } from '../utils/filterBuilder.js';
|
|
2
|
+
export type { FilterCondition, FilterFieldType, FilterGroup, FilterOperator } from '../utils/filterBuilder.js';
|
|
3
|
+
export declare function useMongocampFilterBuilder(): {
|
|
4
|
+
operatorsFor: typeof operatorsFor;
|
|
5
|
+
valueCountFor: typeof valueCountFor;
|
|
6
|
+
toFilterFieldType: typeof toFilterFieldType;
|
|
7
|
+
operatorLabelKey: typeof operatorLabelKey;
|
|
8
|
+
conditionValueText: typeof conditionValueText;
|
|
9
|
+
buildCondition: typeof buildCondition;
|
|
10
|
+
buildFilterQuery: typeof buildFilterQuery;
|
|
11
|
+
countActiveConditions: typeof countActiveConditions;
|
|
12
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import {
|
|
2
|
+
buildCondition,
|
|
3
|
+
buildFilterQuery,
|
|
4
|
+
conditionValueText,
|
|
5
|
+
countActiveConditions,
|
|
6
|
+
operatorLabelKey,
|
|
7
|
+
operatorsFor,
|
|
8
|
+
toFilterFieldType,
|
|
9
|
+
valueCountFor
|
|
10
|
+
} from "../utils/filterBuilder.js";
|
|
11
|
+
export function useMongocampFilterBuilder() {
|
|
12
|
+
return { operatorsFor, valueCountFor, toFilterFieldType, operatorLabelKey, conditionValueText, buildCondition, buildFilterQuery, countActiveConditions };
|
|
13
|
+
}
|
|
@@ -1,14 +1,28 @@
|
|
|
1
1
|
/** Scalar value accepted by all query helpers. `null` and `undefined` produce an empty (no-op) expression. */
|
|
2
2
|
export type QueryValue = string | number | boolean | null | undefined;
|
|
3
|
+
/**
|
|
4
|
+
* What kind of values a field holds, when you know it. It only selects a shorter query for
|
|
5
|
+
* `exists`/`notExists`: `text` → `field:*`, `number` and `date` → a closed range over every possible value.
|
|
6
|
+
*/
|
|
7
|
+
export type ExistsFieldType = 'text' | 'number' | 'date';
|
|
3
8
|
export interface MongocampQueryHelper {
|
|
4
|
-
/**
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Matches documents where the field has a value. Without `type` this ORs a text wildcard with a
|
|
11
|
+
* full-range number and a full-range date clause, so it works for any of those types.
|
|
12
|
+
*
|
|
13
|
+
* MongoCamp 1.5 does not understand `_exists_:field` (it matches nothing), and `field:*` only matches text,
|
|
14
|
+
* which is why this is not just a wildcard.
|
|
15
|
+
*/
|
|
16
|
+
exists: (fieldName: string, type?: ExistsFieldType) => string;
|
|
17
|
+
/**
|
|
18
|
+
* Matches documents where the field is absent: every `exists` clause negated and ANDed (negating the
|
|
19
|
+
* whole group is silently ignored by the server).
|
|
20
|
+
*/
|
|
21
|
+
notExists: (fieldName: string, type?: ExistsFieldType) => string;
|
|
8
22
|
/** Alias for `notExists`. */
|
|
9
|
-
isEmpty: (fieldName: string) => string;
|
|
23
|
+
isEmpty: (fieldName: string, type?: ExistsFieldType) => string;
|
|
10
24
|
/** Alias for `exists`. */
|
|
11
|
-
isNotEmpty: (fieldName: string) => string;
|
|
25
|
+
isNotEmpty: (fieldName: string, type?: ExistsFieldType) => string;
|
|
12
26
|
/**
|
|
13
27
|
* `field:"value"` — exact match.
|
|
14
28
|
* Returns `''` when value is `null`, `undefined`, or an empty string.
|
|
@@ -21,12 +35,20 @@ export interface MongocampQueryHelper {
|
|
|
21
35
|
notEquals: (fieldName: string, value: QueryValue) => string;
|
|
22
36
|
/**
|
|
23
37
|
* `field:[from TO to]` — inclusive range.
|
|
24
|
-
*
|
|
38
|
+
*
|
|
39
|
+
* Pass `null` (or `'*'`) for an open end. MongoCamp 1.5 rejects `[x TO *]`, so the open end is replaced by
|
|
40
|
+
* the far bound of the other bound's type: the 64-bit integer limits for numbers, year 0001 / 9999 for
|
|
41
|
+
* dates. Both ends open means "has a value" and returns `exists(field)`. An open end next to a *text*
|
|
42
|
+
* bound can't be expressed and still becomes `*`, which the server rejects.
|
|
43
|
+
*
|
|
44
|
+
* A date without a time is widened to the whole UTC day (`T00:00:00Z` as lower, `T23:59:59.999Z` as
|
|
45
|
+
* upper bound) — the server matches nothing for a bare date. Characters that would break out of the
|
|
46
|
+
* range (brackets, quotes, whitespace…) in a bound are escaped.
|
|
25
47
|
*/
|
|
26
48
|
inRange: (fieldName: string, from: QueryValue, to: QueryValue) => string;
|
|
27
49
|
/**
|
|
28
|
-
* `-field:[from TO to]` — excluded range.
|
|
29
|
-
*
|
|
50
|
+
* `-field:[from TO to]` — excluded range. Open ends behave as in `inRange`; with both open it is
|
|
51
|
+
* `notExists(field)`.
|
|
30
52
|
*/
|
|
31
53
|
notInRange: (fieldName: string, from: QueryValue, to: QueryValue) => string;
|
|
32
54
|
/** Alias for `inRange`. */
|
|
@@ -81,19 +103,4 @@ export interface MongocampQueryHelper {
|
|
|
81
103
|
*/
|
|
82
104
|
or: (...queryParts: (string | null | undefined)[]) => string;
|
|
83
105
|
}
|
|
84
|
-
/**
|
|
85
|
-
* High-level Lucene query helpers for MongoCamp collection filters.
|
|
86
|
-
*
|
|
87
|
-
* All helpers return a Lucene expression string. A return value of `''` means "no filter"
|
|
88
|
-
* and is safe to pass directly to `and`/`or` — they filter it out automatically.
|
|
89
|
-
*
|
|
90
|
-
* @example
|
|
91
|
-
* const h = useMongocampQuery()
|
|
92
|
-
* h.and(
|
|
93
|
-
* h.or(h.like('name', 'alice'), h.like('email', 'alice')),
|
|
94
|
-
* h.inClause('role', ['admin', 'user']),
|
|
95
|
-
* h.between('createdAt', '2024-01-01', null),
|
|
96
|
-
* )
|
|
97
|
-
* // => '((name:*alice* OR email:*alice*) AND role:("admin" OR "user") AND createdAt:[2024-01-01 TO *])'
|
|
98
|
-
*/
|
|
99
106
|
export declare function useMongocampQuery(): MongocampQueryHelper;
|