adminforth 1.5.9-next.0 → 1.5.9-next.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/dist/spa/src/App.vue +6 -5
- package/dist/spa/src/adminforth.ts +159 -2
- package/dist/spa/src/components/ResourceListTable.vue +2 -1
- package/dist/spa/src/composables/useFrontendApi.ts +5 -3
- package/dist/spa/src/stores/core.ts +2 -1
- package/dist/spa/src/types/FrontendAPI.ts +32 -6
- package/dist/spa/src/utils.ts +1 -1
- package/dist/spa/src/views/ListView.vue +7 -6
- package/dist/types/FrontendAPI.d.ts +29 -6
- package/dist/types/FrontendAPI.d.ts.map +1 -1
- package/dist/types/FrontendAPI.js.map +1 -1
- package/package.json +1 -1
- package/dist/spa/src/composables/useStores.ts +0 -133
package/dist/spa/src/App.vue
CHANGED
|
@@ -250,17 +250,18 @@ import { createHead } from 'unhead'
|
|
|
250
250
|
import { loadFile } from '@/utils';
|
|
251
251
|
import Toast from './components/Toast.vue';
|
|
252
252
|
import {useToastStore} from '@/stores/toast';
|
|
253
|
-
import { FrontendAPI } from '@/composables/useStores';
|
|
254
253
|
import { getCustomComponent } from '@/utils';
|
|
255
254
|
import type { AdminForthConfigMenuItem, AnnouncementBadgeResponse } from './types/Common';
|
|
256
255
|
import { Tooltip } from '@/afcl';
|
|
256
|
+
import { initFrontedAPI } from '@/adminforth';
|
|
257
|
+
import adminforth from '@/adminforth';
|
|
257
258
|
|
|
258
259
|
|
|
259
260
|
const coreStore = useCoreStore();
|
|
260
261
|
const toastStore = useToastStore();
|
|
261
262
|
const userStore = useUserStore();
|
|
262
|
-
|
|
263
|
-
|
|
263
|
+
|
|
264
|
+
initFrontedAPI()
|
|
264
265
|
|
|
265
266
|
createHead()
|
|
266
267
|
const sideBarOpen = ref(false);
|
|
@@ -371,7 +372,7 @@ watch(dropdownUserButton, (dropdownUserButton) => {
|
|
|
371
372
|
document.querySelector('#dropdown-user') as HTMLElement,
|
|
372
373
|
document.querySelector('[data-dropdown-toggle="dropdown-user"]') as HTMLElement,
|
|
373
374
|
);
|
|
374
|
-
|
|
375
|
+
adminforth.closeUserMenuDropdown = () => {
|
|
375
376
|
dd.hide();
|
|
376
377
|
}
|
|
377
378
|
}
|
|
@@ -396,7 +397,7 @@ onMounted(async () => {
|
|
|
396
397
|
await initRouter();
|
|
397
398
|
handleCustomLayout();
|
|
398
399
|
|
|
399
|
-
|
|
400
|
+
adminforth.menu.refreshMenuBadges = async () => {
|
|
400
401
|
await coreStore.fetchMenuBadges();
|
|
401
402
|
}
|
|
402
403
|
})
|
|
@@ -1,3 +1,160 @@
|
|
|
1
|
-
import type { FrontendAPIInterface } from "./types/FrontendAPI";
|
|
1
|
+
import type { FilterParams, FrontendAPIInterface } from "./types/FrontendAPI";
|
|
2
|
+
import type { FrontendAPIInterface, ConfirmParams, AlertParams, } from '@/types/FrontendAPI';
|
|
3
|
+
import type { AdminForthFilterOperators, AdminForthResourceColumn } from '@/types/Common';
|
|
4
|
+
import { useToastStore } from '@/stores/toast';
|
|
5
|
+
import { useModalStore } from '@/stores/modal';
|
|
6
|
+
import { useCoreStore } from '@/stores/core';
|
|
7
|
+
import { useFiltersStore } from '@/stores/filters';
|
|
8
|
+
import router from '@/router'
|
|
2
9
|
|
|
3
|
-
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
declare global {
|
|
13
|
+
interface Window {
|
|
14
|
+
adminforth: FrontendAPIInterface;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
class FrontendAPI implements FrontendAPIInterface {
|
|
19
|
+
public toastStore:any
|
|
20
|
+
public modalStore:any
|
|
21
|
+
public filtersStore:any
|
|
22
|
+
public coreStore:any
|
|
23
|
+
|
|
24
|
+
public list: {
|
|
25
|
+
refresh(): Promise<{ error? : string }>;
|
|
26
|
+
silentRefresh(): Promise<{ error? : string }>;
|
|
27
|
+
silentRefreshRow(): Promise<{ error? : string }>;
|
|
28
|
+
closeThreeDotsDropdown(): Promise<{ error? : string }>;
|
|
29
|
+
closeUserMenuDropdown: () => void;
|
|
30
|
+
setFilter: (filter: FilterParams) => void;
|
|
31
|
+
updateFilter: (filter: FilterParams) => void;
|
|
32
|
+
clearFilters: () => void;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public menu: {
|
|
36
|
+
refreshMenuBadges: () => void;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
closeUserMenuDropdown(): void {
|
|
40
|
+
console.log('closeUserMenuDropdown')
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
constructor() {
|
|
45
|
+
|
|
46
|
+
this.menu = {
|
|
47
|
+
refreshMenuBadges: () => {
|
|
48
|
+
console.log('refreshMenuBadges')
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
this.list = {
|
|
53
|
+
refresh: async () => {
|
|
54
|
+
console.log('refresh');
|
|
55
|
+
return { error: 'Not implemented' }
|
|
56
|
+
},
|
|
57
|
+
silentRefresh: async () => {
|
|
58
|
+
console.log('silentRefresh')
|
|
59
|
+
return { error: 'Not implemented' }
|
|
60
|
+
},
|
|
61
|
+
silentRefreshRow: async () => {
|
|
62
|
+
console.log('silentRefreshRow')
|
|
63
|
+
return { error: 'Not implemented' }
|
|
64
|
+
},
|
|
65
|
+
closeThreeDotsDropdown: async () => {
|
|
66
|
+
console.log('closeThreeDotsDropdown')
|
|
67
|
+
return { error: 'Not implemented' }
|
|
68
|
+
},
|
|
69
|
+
closeUserMenuDropdown: () => {
|
|
70
|
+
console.log('closeUserMenuDropdown')
|
|
71
|
+
},
|
|
72
|
+
setFilter: this.setListFilter.bind(this),
|
|
73
|
+
updateFilter: this.updateListFilter.bind(this),
|
|
74
|
+
clearFilters: this.clearListFilters.bind(this),
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
confirm(params: ConfirmParams): Promise<void> {
|
|
79
|
+
return new Promise((resolve, reject) => {
|
|
80
|
+
this.modalStore.setModalContent({
|
|
81
|
+
content: params.message,
|
|
82
|
+
acceptText: params.yes || 'Yes',
|
|
83
|
+
cancelText: params.no || 'Cancel'
|
|
84
|
+
})
|
|
85
|
+
this.modalStore.onAcceptFunction = resolve
|
|
86
|
+
this.modalStore.onCancelFunction = reject
|
|
87
|
+
this.modalStore.togleModal()
|
|
88
|
+
})
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
alert(params: AlertParams): void {
|
|
92
|
+
this.toastStore.addToast({
|
|
93
|
+
message: params.message,
|
|
94
|
+
messageHtml: params.messageHtml,
|
|
95
|
+
variant: params.variant,
|
|
96
|
+
timeout: params.timeout
|
|
97
|
+
})
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
listFilterValidation(filter: FilterParams): boolean {
|
|
101
|
+
if(router.currentRoute.value.meta.type !== 'list'){
|
|
102
|
+
throw new Error(`Cannot use ${this.setListFilter.name} filter on a list page`)
|
|
103
|
+
} else {
|
|
104
|
+
console.log(this.coreStore.resourceColumnsWithFilters,'core store')
|
|
105
|
+
const filterField = this.coreStore.resourceColumnsWithFilters.find((col: AdminForthResourceColumn) => col.name === filter.field)
|
|
106
|
+
if(!filterField){
|
|
107
|
+
throw new Error(`Field ${filter.field} is not available for filtering`)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
}
|
|
111
|
+
return true
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
setListFilter(filter: FilterParams): void {
|
|
115
|
+
if(this.listFilterValidation(filter)){
|
|
116
|
+
if(this.filtersStore.filters.some((f) => {return f.field === filter.field && f.operator === filter.operator})){
|
|
117
|
+
throw new Error(`Filter ${filter.field} with operator ${filter.operator} already exists`)
|
|
118
|
+
} else {
|
|
119
|
+
this.filtersStore.setFilter(filter)
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
clearListFilters(): void {
|
|
125
|
+
this.filtersStore.clearFilters()
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
updateListFilter(filter: FilterParams): void {
|
|
129
|
+
if(this.listFilterValidation(filter)){
|
|
130
|
+
const index = this.filtersStore.filters.findIndex((f: FilterParams) => f.field === filter.field)
|
|
131
|
+
if(index === -1) {
|
|
132
|
+
this.filtersStore.setFilter(filter)
|
|
133
|
+
} else {
|
|
134
|
+
const filters = [...this.filtersStore.filters];
|
|
135
|
+
if (filter.value === undefined) {
|
|
136
|
+
filters.splice(index, 1);
|
|
137
|
+
} else {
|
|
138
|
+
filters[index] = filter;
|
|
139
|
+
}
|
|
140
|
+
this.filtersStore.setFilters(filters);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const frontendAPI: FrontendAPIInterface = new FrontendAPI();
|
|
148
|
+
window.adminforth = frontendAPI;
|
|
149
|
+
|
|
150
|
+
export function initFrontedAPI() {
|
|
151
|
+
// force init
|
|
152
|
+
const api: FrontendAPI = frontendAPI as FrontendAPI;
|
|
153
|
+
api.toastStore = useToastStore();
|
|
154
|
+
api.modalStore = useModalStore();
|
|
155
|
+
api.coreStore = useCoreStore();
|
|
156
|
+
api.filtersStore = useFiltersStore();
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
export default frontendAPI;
|
|
@@ -290,6 +290,7 @@ import {
|
|
|
290
290
|
import router from '@/router';
|
|
291
291
|
import { Tooltip } from '@/afcl';
|
|
292
292
|
import type { AdminForthResourceCommon } from '@/types/Common';
|
|
293
|
+
import adminforth from '@/adminforth';
|
|
293
294
|
|
|
294
295
|
const coreStore = useCoreStore();
|
|
295
296
|
|
|
@@ -458,7 +459,7 @@ async function onClick(e,row) {
|
|
|
458
459
|
}
|
|
459
460
|
|
|
460
461
|
async function deleteRecord(row) {
|
|
461
|
-
const data = await
|
|
462
|
+
const data = await adminforth.confirm({
|
|
462
463
|
message: 'Are you sure you want to delete this item?',
|
|
463
464
|
yes: 'Delete',
|
|
464
465
|
no: 'Cancel',
|
|
@@ -1,15 +1,17 @@
|
|
|
1
|
+
import adminforth from '@/adminforth';
|
|
2
|
+
|
|
1
3
|
export function showSuccesTost(message: string) {
|
|
2
|
-
|
|
4
|
+
adminforth.alert({ message, variant: 'success' });
|
|
3
5
|
return message;
|
|
4
6
|
}
|
|
5
7
|
|
|
6
8
|
export function showWarningTost(message: string) {
|
|
7
|
-
|
|
9
|
+
adminforth.alert({ message, variant: 'warning' });
|
|
8
10
|
return message;
|
|
9
11
|
}
|
|
10
12
|
|
|
11
13
|
export function showErrorTost(message: string, timeout?: number) {
|
|
12
|
-
|
|
14
|
+
adminforth.alert({ message, variant: 'danger', timeout: timeout || 30});
|
|
13
15
|
return message;
|
|
14
16
|
}
|
|
15
17
|
|
|
@@ -2,6 +2,7 @@ import { ref, computed } from 'vue'
|
|
|
2
2
|
import { defineStore } from 'pinia'
|
|
3
3
|
import { callAdminForthApi } from '@/utils';
|
|
4
4
|
import websocket from '@/websocket';
|
|
5
|
+
import adminforth from '@/adminforth';
|
|
5
6
|
|
|
6
7
|
import type { AdminForthResourceCommon, AdminForthResourceColumnCommon, GetBaseConfigResponse, ResourceVeryShort, AdminUser, UserData, AdminForthConfigMenuItem, AdminForthConfigForFrontend } from '@/types/Common';
|
|
7
8
|
import type { Ref } from 'vue'
|
|
@@ -151,7 +152,7 @@ export const useCoreStore = defineStore('core', () => {
|
|
|
151
152
|
});
|
|
152
153
|
|
|
153
154
|
if (respData.error) {
|
|
154
|
-
|
|
155
|
+
adminforth.alert({
|
|
155
156
|
message: respData.error,
|
|
156
157
|
variant: 'danger',
|
|
157
158
|
timeout: 30,
|
|
@@ -1,4 +1,22 @@
|
|
|
1
|
+
import type { AdminForthFilterOperators } from "./Common.js";
|
|
2
|
+
|
|
1
3
|
|
|
4
|
+
|
|
5
|
+
export type FilterParams = {
|
|
6
|
+
/**
|
|
7
|
+
* Field of resource to filter
|
|
8
|
+
*/
|
|
9
|
+
field: string;
|
|
10
|
+
/**
|
|
11
|
+
* Operator of filter
|
|
12
|
+
*/
|
|
13
|
+
operator: AdminForthFilterOperators;
|
|
14
|
+
/**
|
|
15
|
+
* Value of filter
|
|
16
|
+
*/
|
|
17
|
+
value: string | number | boolean ;
|
|
18
|
+
}
|
|
19
|
+
|
|
2
20
|
export interface FrontendAPIInterface {
|
|
3
21
|
|
|
4
22
|
/**
|
|
@@ -9,7 +27,9 @@ export interface FrontendAPIInterface {
|
|
|
9
27
|
* Example:
|
|
10
28
|
*
|
|
11
29
|
* ```ts
|
|
12
|
-
*
|
|
30
|
+
* import adminforth from '@/adminforth'
|
|
31
|
+
*
|
|
32
|
+
* const isConfirmed = await adminforth.confirm({message: 'Are you sure?', yes: 'Yes', no: 'No'})
|
|
13
33
|
* if (isConfirmed) {
|
|
14
34
|
* your code...
|
|
15
35
|
* }
|
|
@@ -28,7 +48,9 @@ export interface FrontendAPIInterface {
|
|
|
28
48
|
* Example:
|
|
29
49
|
*
|
|
30
50
|
* ```ts
|
|
31
|
-
*
|
|
51
|
+
* import adminforth from '@/adminforth'
|
|
52
|
+
*
|
|
53
|
+
* adminforth.alert({message: 'Hello', variant: 'success'})
|
|
32
54
|
* ```
|
|
33
55
|
*
|
|
34
56
|
* @param params - The parameters of the alert
|
|
@@ -69,12 +91,14 @@ export interface FrontendAPIInterface {
|
|
|
69
91
|
* Example:
|
|
70
92
|
*
|
|
71
93
|
* ```ts
|
|
72
|
-
*
|
|
94
|
+
* import adminforth from '@/adminforth'
|
|
95
|
+
*
|
|
96
|
+
* adminforth.list.setFilter({field: 'name', operator: 'ilike', value: 'john'})
|
|
73
97
|
* ```
|
|
74
98
|
*
|
|
75
99
|
* @param filter - The filter to set
|
|
76
100
|
*/
|
|
77
|
-
setFilter(filter:
|
|
101
|
+
setFilter(filter: FilterParams): void;
|
|
78
102
|
|
|
79
103
|
/**
|
|
80
104
|
* Update a filter in the list
|
|
@@ -82,12 +106,14 @@ export interface FrontendAPIInterface {
|
|
|
82
106
|
* Example:
|
|
83
107
|
*
|
|
84
108
|
* ```ts
|
|
85
|
-
*
|
|
109
|
+
* import adminforth from '@/adminforth';
|
|
110
|
+
*
|
|
111
|
+
* adminforth.list.updateFilter({field: 'name', operator: 'ilike', value: 'john'})
|
|
86
112
|
* ```
|
|
87
113
|
*
|
|
88
114
|
* @param filter - The filter to update
|
|
89
115
|
*/
|
|
90
|
-
updateFilter(filter:
|
|
116
|
+
updateFilter(filter: FilterParams): void;
|
|
91
117
|
|
|
92
118
|
/**
|
|
93
119
|
* Clear all filters from the list
|
package/dist/spa/src/utils.ts
CHANGED
|
@@ -118,7 +118,7 @@ export function initThreeDotsDropdown() {
|
|
|
118
118
|
threeDotsDropdown,
|
|
119
119
|
document.querySelector('[data-dropdown-toggle="listThreeDotsDropdown"]') as HTMLElement,
|
|
120
120
|
);
|
|
121
|
-
|
|
121
|
+
adminforth.list.closeThreeDotsDropdown = () => {
|
|
122
122
|
dd.hide();
|
|
123
123
|
}
|
|
124
124
|
}
|
|
@@ -147,6 +147,7 @@ import {
|
|
|
147
147
|
} from '@iconify-prerendered/vue-flowbite';
|
|
148
148
|
|
|
149
149
|
import Filters from '@/components/Filters.vue';
|
|
150
|
+
import adminforth from '@/adminforth';
|
|
150
151
|
|
|
151
152
|
const filtersShow = ref(false);
|
|
152
153
|
|
|
@@ -262,7 +263,7 @@ async function refreshExistingList(pk?: any) {
|
|
|
262
263
|
async function startBulkAction(actionId) {
|
|
263
264
|
const action = coreStore.resource.options.bulkActions.find(a => a.id === actionId);
|
|
264
265
|
if (action.confirm) {
|
|
265
|
-
const confirmed = await
|
|
266
|
+
const confirmed = await adminforth.confirm({
|
|
266
267
|
message: action.confirm,
|
|
267
268
|
});
|
|
268
269
|
if (!confirmed) {
|
|
@@ -287,7 +288,7 @@ async function startBulkAction(actionId) {
|
|
|
287
288
|
await getList();
|
|
288
289
|
|
|
289
290
|
if (data.successMessage) {
|
|
290
|
-
|
|
291
|
+
adminforth.alert({
|
|
291
292
|
message: data.successMessage,
|
|
292
293
|
variant: 'success'
|
|
293
294
|
});
|
|
@@ -367,7 +368,7 @@ async function init() {
|
|
|
367
368
|
}
|
|
368
369
|
if (coreStore.resource!.options?.listRowsAutoRefreshSeconds) {
|
|
369
370
|
listAutorefresher = setInterval(async () => {
|
|
370
|
-
await
|
|
371
|
+
await adminforth.list.silentRefresh();
|
|
371
372
|
}, coreStore.resource!.options.listRowsAutoRefreshSeconds * 1000);
|
|
372
373
|
}
|
|
373
374
|
}
|
|
@@ -377,15 +378,15 @@ watch([page, sort, () => filtersStore.filters], async () => {
|
|
|
377
378
|
await getList();
|
|
378
379
|
}, { deep: true });
|
|
379
380
|
|
|
380
|
-
|
|
381
|
+
adminforth.list.refresh = async () => {
|
|
381
382
|
return await getList();
|
|
382
383
|
}
|
|
383
384
|
|
|
384
|
-
|
|
385
|
+
adminforth.list.silentRefresh = async () => {
|
|
385
386
|
return await refreshExistingList();
|
|
386
387
|
}
|
|
387
388
|
|
|
388
|
-
|
|
389
|
+
adminforth.list.silentRefreshRow = async (pk: any) => {
|
|
389
390
|
return await refreshExistingList(pk);
|
|
390
391
|
}
|
|
391
392
|
|
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
import type { AdminForthFilterOperators } from "./Common.js";
|
|
2
|
+
export type FilterParams = {
|
|
3
|
+
/**
|
|
4
|
+
* Field of resource to filter
|
|
5
|
+
*/
|
|
6
|
+
field: string;
|
|
7
|
+
/**
|
|
8
|
+
* Operator of filter
|
|
9
|
+
*/
|
|
10
|
+
operator: AdminForthFilterOperators;
|
|
11
|
+
/**
|
|
12
|
+
* Value of filter
|
|
13
|
+
*/
|
|
14
|
+
value: string | number | boolean;
|
|
15
|
+
};
|
|
1
16
|
export interface FrontendAPIInterface {
|
|
2
17
|
/**
|
|
3
18
|
* Show a confirmation dialog
|
|
@@ -7,7 +22,9 @@ export interface FrontendAPIInterface {
|
|
|
7
22
|
* Example:
|
|
8
23
|
*
|
|
9
24
|
* ```ts
|
|
10
|
-
*
|
|
25
|
+
* import adminforth from '@/adminforth'
|
|
26
|
+
*
|
|
27
|
+
* const isConfirmed = await adminforth.confirm({message: 'Are you sure?', yes: 'Yes', no: 'No'})
|
|
11
28
|
* if (isConfirmed) {
|
|
12
29
|
* your code...
|
|
13
30
|
* }
|
|
@@ -25,7 +42,9 @@ export interface FrontendAPIInterface {
|
|
|
25
42
|
* Example:
|
|
26
43
|
*
|
|
27
44
|
* ```ts
|
|
28
|
-
*
|
|
45
|
+
* import adminforth from '@/adminforth'
|
|
46
|
+
*
|
|
47
|
+
* adminforth.alert({message: 'Hello', variant: 'success'})
|
|
29
48
|
* ```
|
|
30
49
|
*
|
|
31
50
|
* @param params - The parameters of the alert
|
|
@@ -64,24 +83,28 @@ export interface FrontendAPIInterface {
|
|
|
64
83
|
* Example:
|
|
65
84
|
*
|
|
66
85
|
* ```ts
|
|
67
|
-
*
|
|
86
|
+
* import adminforth from '@/adminforth'
|
|
87
|
+
*
|
|
88
|
+
* adminforth.list.setFilter({field: 'name', operator: 'ilike', value: 'john'})
|
|
68
89
|
* ```
|
|
69
90
|
*
|
|
70
91
|
* @param filter - The filter to set
|
|
71
92
|
*/
|
|
72
|
-
setFilter(filter:
|
|
93
|
+
setFilter(filter: FilterParams): void;
|
|
73
94
|
/**
|
|
74
95
|
* Update a filter in the list
|
|
75
96
|
*
|
|
76
97
|
* Example:
|
|
77
98
|
*
|
|
78
99
|
* ```ts
|
|
79
|
-
*
|
|
100
|
+
* import adminforth from '@/adminforth';
|
|
101
|
+
*
|
|
102
|
+
* adminforth.list.updateFilter({field: 'name', operator: 'ilike', value: 'john'})
|
|
80
103
|
* ```
|
|
81
104
|
*
|
|
82
105
|
* @param filter - The filter to update
|
|
83
106
|
*/
|
|
84
|
-
updateFilter(filter:
|
|
107
|
+
updateFilter(filter: FilterParams): void;
|
|
85
108
|
/**
|
|
86
109
|
* Clear all filters from the list
|
|
87
110
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FrontendAPI.d.ts","sourceRoot":"","sources":["../../types/FrontendAPI.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"FrontendAPI.d.ts","sourceRoot":"","sources":["../../types/FrontendAPI.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAI7D,MAAM,MAAM,YAAY,GAAG;IACvB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,QAAQ,EAAE,yBAAyB,CAAC;IACpC;;OAEG;IACH,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAE;CACrC,CAAA;AAED,MAAM,WAAW,oBAAoB;IAEjC;;;;;;;;;;;;;;;;;;OAkBG;IACH,OAAO,CAAC,MAAM,EAAC,aAAa,GAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAE9C;;;;;;;;;;;;;;OAcG;IACH,KAAK,CAAC,MAAM,EAAC,WAAW,GAAG,IAAI,CAAC;IAGhC,IAAI,EAAE;QAEF;;WAEG;QACH,OAAO,IAAI,OAAO,CAAC;YAAE,KAAK,CAAC,EAAG,MAAM,CAAA;SAAE,CAAC,CAAC;QAExC;;;;WAIG;QACH,aAAa,IAAI,OAAO,CAAC;YAAE,KAAK,CAAC,EAAG,MAAM,CAAA;SAAE,CAAC,CAAC;QAE9C;;WAEG;QACH,gBAAgB,CAAE,EAAE,EAAE,GAAG,GAAG,OAAO,CAAC;YAAE,KAAK,CAAC,EAAG,MAAM,CAAA;SAAE,CAAC,CAAC;QAEzD;;WAEG;QACH,sBAAsB,IAAI,IAAI,CAAC;QAG/B;;;;;;;;;;;;;;WAcG;QACH,SAAS,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI,CAAC;QAEtC;;;;;;;;;;;;WAYG;QACH,YAAY,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI,CAAC;QAEzC;;WAEG;QACH,YAAY,IAAI,IAAI,CAAC;KACxB,CAAA;IAED,IAAI,EAAE;QACF;;WAEG;QACH,iBAAiB,IAAI,IAAI,CAAC;KAC7B,CAAA;IAED;;OAEG;IACH,qBAAqB,IAAI,IAAI,CAAC;CACjC;AAED,MAAM,MAAM,aAAa,GAAG;IACxB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;CAEf,CAAA;AAED,MAAM,MAAM,WAAW,GAAG;IACtB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,OAAO,CAAC,EAAE,YAAY,GAAG,MAAM,OAAO,YAAY,CAAC;IAEnD;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC;CAElC,CAAA;AAID,oBAAY,YAAY;IACpB,MAAM,WAAW;IACjB,OAAO,YAAY;IACnB,OAAO,YAAY;IACnB,IAAI,SAAS;CACd"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FrontendAPI.js","sourceRoot":"","sources":["../../types/FrontendAPI.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"FrontendAPI.js","sourceRoot":"","sources":["../../types/FrontendAPI.ts"],"names":[],"mappings":"AAkLA,MAAM,CAAN,IAAY,YAKT;AALH,WAAY,YAAY;IACpB,iCAAiB,CAAA;IACjB,mCAAmB,CAAA;IACnB,mCAAmB,CAAA;IACnB,6BAAa,CAAA;AACf,CAAC,EALS,YAAY,KAAZ,YAAY,QAKrB"}
|
package/package.json
CHANGED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import type { FrontendAPIInterface, ConfirmParams, AlertParams, } from '@/types/FrontendAPI';
|
|
2
|
-
import type { AdminForthFilterOperators, AdminForthResourceColumn } from '@/types/Common';
|
|
3
|
-
import { useToastStore } from '../stores/toast';
|
|
4
|
-
import { useModalStore } from '../stores/modal';
|
|
5
|
-
import { useCoreStore } from '@/stores/core';
|
|
6
|
-
import { useFiltersStore } from '@/stores/filters';
|
|
7
|
-
import router from '@/router'
|
|
8
|
-
|
|
9
|
-
type FilterParams = {
|
|
10
|
-
/**
|
|
11
|
-
* Field of resource to filter
|
|
12
|
-
*/
|
|
13
|
-
field: string;
|
|
14
|
-
/**
|
|
15
|
-
* Operator of filter
|
|
16
|
-
*/
|
|
17
|
-
operator: AdminForthFilterOperators;
|
|
18
|
-
/**
|
|
19
|
-
* Value of filter
|
|
20
|
-
*/
|
|
21
|
-
value: string | number | boolean ;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
declare global {
|
|
25
|
-
interface Window {
|
|
26
|
-
adminforth: FrontendAPIInterface;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export class FrontendAPI {
|
|
31
|
-
private toastStore:any
|
|
32
|
-
private modalStore:any
|
|
33
|
-
private filtersStore:any
|
|
34
|
-
private coreStore:any
|
|
35
|
-
init() {
|
|
36
|
-
if (window.adminforth) {
|
|
37
|
-
throw new Error('adminforth already initialized');
|
|
38
|
-
}
|
|
39
|
-
this.toastStore = useToastStore();
|
|
40
|
-
this.modalStore = useModalStore();
|
|
41
|
-
|
|
42
|
-
window.adminforth = {
|
|
43
|
-
confirm: this.confirm.bind(this),
|
|
44
|
-
alert: this.alert.bind(this),
|
|
45
|
-
|
|
46
|
-
list: {
|
|
47
|
-
refresh: () => {/* will be redefined in list*/},
|
|
48
|
-
closeThreeDotsDropdown: () => {/* will be redefined in list*/},
|
|
49
|
-
closeUserMenuDropdown: () => {/* will be redefined in list*/},
|
|
50
|
-
setFilter: () => this.setListFilter.bind(this),
|
|
51
|
-
updateFilter: () => this.updateListFilter.bind(this),
|
|
52
|
-
clearFilters: () => this.clearListFilters.bind(this),
|
|
53
|
-
},
|
|
54
|
-
menu: {
|
|
55
|
-
refreshMenuBadges: () => {/* will be redefined */}
|
|
56
|
-
},
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
confirm(params: ConfirmParams): Promise<void> {
|
|
61
|
-
return new Promise((resolve, reject) => {
|
|
62
|
-
this.modalStore.setModalContent({
|
|
63
|
-
content: params.message,
|
|
64
|
-
acceptText: params.yes || 'Yes',
|
|
65
|
-
cancelText: params.no || 'Cancel'
|
|
66
|
-
})
|
|
67
|
-
this.modalStore.onAcceptFunction = resolve
|
|
68
|
-
this.modalStore.onCancelFunction = reject
|
|
69
|
-
this.modalStore.togleModal()
|
|
70
|
-
})
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
alert(params: AlertParams): void {
|
|
74
|
-
this.toastStore.addToast({
|
|
75
|
-
message: params.message,
|
|
76
|
-
messageHtml: params.messageHtml,
|
|
77
|
-
variant: params.variant,
|
|
78
|
-
timeout: params.timeout
|
|
79
|
-
})
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
listFilterValidation(filter: FilterParams): boolean {
|
|
83
|
-
if(router.currentRoute.value.meta.type !== 'list'){
|
|
84
|
-
throw new Error(`Cannot use ${this.setListFilter.name} filter on a list page`)
|
|
85
|
-
} else {
|
|
86
|
-
if(!this.coreStore) this.coreStore = useCoreStore()
|
|
87
|
-
console.log(this.coreStore.resourceColumnsWithFilters,'core store')
|
|
88
|
-
const filterField = this.coreStore.resourceColumnsWithFilters.find((col: AdminForthResourceColumn) => col.name === filter.field)
|
|
89
|
-
if(!filterField){
|
|
90
|
-
throw new Error(`Field ${filter.field} is not available for filtering`)
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
return true
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
setListFilter(filter: FilterParams): void {
|
|
98
|
-
if(this.listFilterValidation(filter)){
|
|
99
|
-
this.filtersStore = useFiltersStore()
|
|
100
|
-
if(this.filtersStore.filters.some((f) => {return f.field === filter.field && f.operator === filter.operator})){
|
|
101
|
-
throw new Error(`Filter ${filter.field} with operator ${filter.operator} already exists`)
|
|
102
|
-
} else {
|
|
103
|
-
this.filtersStore.setFilter(filter)
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
clearListFilters(): void {
|
|
109
|
-
this.filtersStore = useFiltersStore()
|
|
110
|
-
this.filtersStore.clearFilters()
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
updateListFilter(filter: FilterParams): void {
|
|
114
|
-
if(this.listFilterValidation(filter)){
|
|
115
|
-
this.filtersStore = useFiltersStore()
|
|
116
|
-
const index = this.filtersStore.filters.findIndex((f: FilterParams) => f.field === filter.field)
|
|
117
|
-
if(index === -1) {
|
|
118
|
-
this.filtersStore.setFilter(filter)
|
|
119
|
-
} else {
|
|
120
|
-
const filters = [...this.filtersStore.filters];
|
|
121
|
-
if (filter.value === undefined) {
|
|
122
|
-
filters.splice(index, 1);
|
|
123
|
-
} else {
|
|
124
|
-
filters[index] = filter;
|
|
125
|
-
}
|
|
126
|
-
this.filtersStore.setFilters(filters);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|