adminforth 1.3.21 → 1.3.22
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/dist/modules/configValidator.js +2 -1
- package/dist/modules/restApi.js +2 -3
- package/modules/configValidator.ts +4 -2
- package/modules/restApi.ts +2 -3
- package/package.json +1 -1
- package/spa/src/composables/useFrontendApi.ts +1 -1
- package/spa/src/composables/useStores.ts +5 -1
- package/spa/src/stores/core.ts +1 -1
- package/spa/src/stores/toast.ts +22 -6
- package/spa/src/views/CreateView.vue +4 -0
- package/spa/src/views/ListView.vue +18 -0
- package/types/AdminForthConfig.ts +5 -1
|
@@ -251,6 +251,7 @@ export default class ConfigValidator {
|
|
|
251
251
|
label: `Delete checked`,
|
|
252
252
|
state: 'danger',
|
|
253
253
|
icon: 'flowbite:trash-bin-outline',
|
|
254
|
+
confirm: 'Are you sure you want to delete selected items?',
|
|
254
255
|
allowed: (_b) => __awaiter(this, [_b], void 0, function* ({ resource, adminUser, allowedActions }) { return allowedActions.delete; }),
|
|
255
256
|
action: (_c) => __awaiter(this, [_c], void 0, function* ({ selectedIds, adminUser }) {
|
|
256
257
|
const connector = this.adminforth.connectors[res.dataSource];
|
|
@@ -286,7 +287,7 @@ export default class ConfigValidator {
|
|
|
286
287
|
if (error) {
|
|
287
288
|
return { error, ok: false };
|
|
288
289
|
}
|
|
289
|
-
return { ok: true };
|
|
290
|
+
return { ok: true, successMessage: `${selectedIds.length} item${selectedIds.length > 1 ? 's' : ''} deleted` };
|
|
290
291
|
})
|
|
291
292
|
});
|
|
292
293
|
}
|
package/dist/modules/restApi.js
CHANGED
|
@@ -43,7 +43,7 @@ export default class AdminForthRestAPI {
|
|
|
43
43
|
path: '/login',
|
|
44
44
|
handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, response }) {
|
|
45
45
|
var _b, _c, _d, _e;
|
|
46
|
-
const INVALID_MESSAGE = 'Invalid
|
|
46
|
+
const INVALID_MESSAGE = 'Invalid Username or Password';
|
|
47
47
|
const { username, password } = body;
|
|
48
48
|
let adminUser;
|
|
49
49
|
let toReturn = { ok: true, allowedLogin: true };
|
|
@@ -71,9 +71,8 @@ export default class AdminForthRestAPI {
|
|
|
71
71
|
offset: 0,
|
|
72
72
|
sort: [],
|
|
73
73
|
})).data) === null || _b === void 0 ? void 0 : _b[0];
|
|
74
|
-
console.log('userRecord', userRecord, this.adminforth.config.auth.usernameField, username);
|
|
75
74
|
if (!userRecord) {
|
|
76
|
-
return { error:
|
|
75
|
+
return { error: INVALID_MESSAGE };
|
|
77
76
|
}
|
|
78
77
|
const passwordHash = userRecord[this.adminforth.config.auth.passwordHashField];
|
|
79
78
|
const valid = yield AdminForthAuth.verifyPassword(password, passwordHash);
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
AdminForthResourcePages, AllowedActionsEnum,
|
|
7
7
|
type AdminForthComponentDeclarationFull,
|
|
8
8
|
type AfterSaveFunction,
|
|
9
|
+
AdminForthBulkAction,
|
|
9
10
|
} from "../types/AdminForthConfig.js";
|
|
10
11
|
|
|
11
12
|
import fs from 'fs';
|
|
@@ -260,7 +261,7 @@ export default class ConfigValidator implements IConfigValidator {
|
|
|
260
261
|
|
|
261
262
|
|
|
262
263
|
//check if resource has bulkActions
|
|
263
|
-
let bulkActions = res?.options?.bulkActions || [];
|
|
264
|
+
let bulkActions: AdminForthBulkAction[] = res?.options?.bulkActions || [];
|
|
264
265
|
|
|
265
266
|
if (!Array.isArray(bulkActions)) {
|
|
266
267
|
errors.push(`Resource "${res.resourceId}" bulkActions must be an array`);
|
|
@@ -272,6 +273,7 @@ export default class ConfigValidator implements IConfigValidator {
|
|
|
272
273
|
label: `Delete checked`,
|
|
273
274
|
state: 'danger',
|
|
274
275
|
icon: 'flowbite:trash-bin-outline',
|
|
276
|
+
confirm: 'Are you sure you want to delete selected items?',
|
|
275
277
|
allowed: async ({ resource, adminUser, allowedActions }) => { return allowedActions.delete },
|
|
276
278
|
action: async ({ selectedIds, adminUser }) => {
|
|
277
279
|
const connector = this.adminforth.connectors[res.dataSource];
|
|
@@ -324,7 +326,7 @@ export default class ConfigValidator implements IConfigValidator {
|
|
|
324
326
|
if (error) {
|
|
325
327
|
return { error, ok: false };
|
|
326
328
|
}
|
|
327
|
-
return { ok: true };
|
|
329
|
+
return { ok: true, successMessage: `${selectedIds.length} item${selectedIds.length > 1 ? 's' : ''} deleted` };
|
|
328
330
|
}
|
|
329
331
|
});
|
|
330
332
|
}
|
package/modules/restApi.ts
CHANGED
|
@@ -62,7 +62,7 @@ export default class AdminForthRestAPI {
|
|
|
62
62
|
path: '/login',
|
|
63
63
|
handler: async ({ body, response }) => {
|
|
64
64
|
|
|
65
|
-
const INVALID_MESSAGE = 'Invalid
|
|
65
|
+
const INVALID_MESSAGE = 'Invalid Username or Password';
|
|
66
66
|
const { username, password } = body;
|
|
67
67
|
let adminUser: AdminUser;
|
|
68
68
|
let toReturn: { ok: boolean, redirectTo?: string, allowedLogin:boolean } = { ok: true, allowedLogin:true};
|
|
@@ -95,10 +95,9 @@ export default class AdminForthRestAPI {
|
|
|
95
95
|
})
|
|
96
96
|
).data?.[0];
|
|
97
97
|
|
|
98
|
-
console.log('userRecord', userRecord, this.adminforth.config.auth.usernameField, username);
|
|
99
98
|
|
|
100
99
|
if (!userRecord) {
|
|
101
|
-
return { error:
|
|
100
|
+
return { error: INVALID_MESSAGE };
|
|
102
101
|
}
|
|
103
102
|
|
|
104
103
|
const passwordHash = userRecord[this.adminforth.config.auth.passwordHashField];
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@ export function showWarningTost(message: string) {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export function showErrorTost(message: string, timeout?: number) {
|
|
12
|
-
window.adminforth.alert({ message, variant: 'danger', timeout: timeout ||
|
|
12
|
+
window.adminforth.alert({ message, variant: 'danger', timeout: timeout || 30});
|
|
13
13
|
return message;
|
|
14
14
|
}
|
|
15
15
|
|
|
@@ -57,7 +57,11 @@ export class FrontendAPI implements FrontendAPIInterface {
|
|
|
57
57
|
|
|
58
58
|
confirm(params: ConfirmParams): Promise<void> {
|
|
59
59
|
return new Promise((resolve, reject) => {
|
|
60
|
-
this.modalStore.setModalContent({
|
|
60
|
+
this.modalStore.setModalContent({
|
|
61
|
+
content: params.message,
|
|
62
|
+
acceptText: params.yes || 'Yes',
|
|
63
|
+
cancelText: params.no || 'Cancel'
|
|
64
|
+
})
|
|
61
65
|
this.modalStore.onAcceptFunction = resolve
|
|
62
66
|
this.modalStore.onCancelFunction = reject
|
|
63
67
|
this.modalStore.togleModal()
|
package/spa/src/stores/core.ts
CHANGED
package/spa/src/stores/toast.ts
CHANGED
|
@@ -1,14 +1,30 @@
|
|
|
1
|
-
import { ref,
|
|
1
|
+
import { ref, watch, type Ref } from 'vue'
|
|
2
2
|
import { defineStore } from 'pinia'
|
|
3
|
-
import { callAdminForthApi } from '@/utils';
|
|
4
3
|
import { v1 as uuid } from 'uuid';
|
|
4
|
+
import { useRoute } from 'vue-router';
|
|
5
|
+
|
|
6
|
+
|
|
5
7
|
|
|
6
8
|
export const useToastStore = defineStore('toast', () => {
|
|
7
|
-
const toasts = ref([]);
|
|
8
|
-
const
|
|
9
|
-
|
|
9
|
+
const toasts: Ref<any[]> = ref([]);
|
|
10
|
+
const route = useRoute();
|
|
11
|
+
|
|
12
|
+
watch(route, () => {
|
|
13
|
+
console.log('route changed 121');
|
|
14
|
+
// on route change clear all toasts older then 5 seconds
|
|
15
|
+
const now = +new Date();
|
|
16
|
+
toasts.value = toasts.value.filter((t) => now - t.createdAt < 5000);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const addToast = (toast: { message: string; variant: string }) => {
|
|
20
|
+
const toastId = uuid();
|
|
21
|
+
toasts.value.push({
|
|
22
|
+
...toast,
|
|
23
|
+
id: toastId,
|
|
24
|
+
createdAt: +new Date(),
|
|
25
|
+
});
|
|
10
26
|
};
|
|
11
|
-
const removeToast = (toast) => {
|
|
27
|
+
const removeToast = (toast: { id: string }) => {
|
|
12
28
|
toasts.value = toasts.value.filter((t) => t.id !== toast.id);
|
|
13
29
|
};
|
|
14
30
|
return { toasts, addToast, removeToast };
|
|
@@ -179,6 +179,16 @@ async function getList() {
|
|
|
179
179
|
}
|
|
180
180
|
|
|
181
181
|
async function startBulkAction(actionId) {
|
|
182
|
+
const action = coreStore.resource.options.bulkActions.find(a => a.id === actionId);
|
|
183
|
+
if (action.confirm) {
|
|
184
|
+
const confirmed = await window.adminforth.confirm({
|
|
185
|
+
message: action.confirm,
|
|
186
|
+
});
|
|
187
|
+
if (!confirmed) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
182
192
|
const data = await callAdminForthApi({
|
|
183
193
|
path: '/start_bulk_action',
|
|
184
194
|
method: 'POST',
|
|
@@ -192,6 +202,14 @@ async function startBulkAction(actionId) {
|
|
|
192
202
|
if (data?.ok) {
|
|
193
203
|
checkboxes.value = [];
|
|
194
204
|
await getList();
|
|
205
|
+
|
|
206
|
+
if (data.successMessage) {
|
|
207
|
+
window.adminforth.alert({
|
|
208
|
+
message: data.successMessage,
|
|
209
|
+
variant: 'success'
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
|
|
195
213
|
}
|
|
196
214
|
if (data?.error) {
|
|
197
215
|
showErrorTost(data.error);
|
|
@@ -744,13 +744,17 @@ export type AdminForthBulkAction = {
|
|
|
744
744
|
* Callback which will be called on backend when user clicks on action button.
|
|
745
745
|
* It should return Promise which will be resolved when action is done.
|
|
746
746
|
*/
|
|
747
|
-
action: ({ resource, selectedIds, adminUser }: { resource: AdminForthResource, selectedIds: Array<any>, adminUser: AdminUser }) => Promise<{ ok: boolean, error?: string }>,
|
|
747
|
+
action: ({ resource, selectedIds, adminUser }: { resource: AdminForthResource, selectedIds: Array<any>, adminUser: AdminUser }) => Promise<{ ok: boolean, error?: string, successMessage?: string }>,
|
|
748
748
|
|
|
749
749
|
/**
|
|
750
750
|
* Confirmation message which will be displayed to user before action is executed.
|
|
751
751
|
*/
|
|
752
752
|
confirm?: string,
|
|
753
753
|
|
|
754
|
+
/**
|
|
755
|
+
* Success message which will be displayed to user after action is executed.
|
|
756
|
+
*/
|
|
757
|
+
successMessage?: string,
|
|
754
758
|
/**
|
|
755
759
|
* Allowed callback called to check whether action is allowed for user.
|
|
756
760
|
* 1. It called first time when user goes to list view. If callback returns false, action button will be hidden on list view.
|