adminforth 1.0.83 → 1.0.86
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/index.js +34 -16
- package/dist/modules/codeInjector.js +19 -10
- package/dist/plugins/ForeignInlineListPlugin/index.js +3 -2
- package/dist/servers/express.js +0 -3
- package/dist/spa/spa/package-lock.json +13 -0
- package/dist/spa/spa/package.json +1 -0
- package/dist/spa/spa/src/App.vue +44 -19
- package/dist/spa/spa/src/components/AcceptModal.vue +2 -9
- package/dist/spa/spa/src/components/Toast.vue +65 -0
- package/dist/spa/spa/src/components/ValueRenderer.vue +8 -8
- package/dist/spa/spa/src/composables/useStores.ts +51 -0
- package/dist/spa/spa/src/stores/core.ts +5 -1
- package/dist/spa/spa/src/stores/modal.ts +13 -2
- package/dist/spa/spa/src/stores/toast.ts +15 -0
- package/dist/spa/spa/src/views/CreateView.vue +25 -2
- package/dist/spa/spa/src/views/EditView.vue +28 -3
- package/dist/spa/spa/src/views/ListView.vue +28 -5
- package/dist/spa/spa/src/views/ShowView.vue +33 -7
- package/dist/types/AdminForthConfig.js +54 -0
- package/dist/types/FrontendAPI.js +7 -0
- package/documentation/docs/Getting Started.md +374 -0
- package/documentation/docs/Glossary.md +37 -0
- package/documentation/docs/image.png +0 -0
- package/documentation/docusaurus.config.ts +4 -4
- package/documentation/static/CNAME +1 -0
- package/index.ts +50 -35
- package/modules/codeInjector.ts +15 -6
- package/package.json +1 -1
- package/plugins/ForeignInlineListPlugin/index.ts +3 -3
- package/servers/express.ts +4 -9
- package/spa/package-lock.json +13 -0
- package/spa/package.json +1 -0
- package/spa/src/App.vue +44 -19
- package/spa/src/components/AcceptModal.vue +2 -9
- package/spa/src/components/Toast.vue +65 -0
- package/spa/src/components/ValueRenderer.vue +8 -8
- package/spa/src/composables/useStores.ts +51 -0
- package/spa/src/stores/core.ts +5 -1
- package/spa/src/stores/modal.ts +13 -2
- package/spa/src/stores/toast.ts +15 -0
- package/spa/src/views/CreateView.vue +25 -2
- package/spa/src/views/EditView.vue +28 -3
- package/spa/src/views/ListView.vue +28 -5
- package/spa/src/views/ShowView.vue +33 -7
- package/types/AdminForthConfig.ts +469 -42
- package/types/FrontendAPI.ts +73 -0
- package/documentation/static/img/docusaurus-social-card.jpg +0 -0
- package/documentation/static/img/tail.png:Zone.Identifier +0 -0
package/servers/express.ts
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
|
|
2
2
|
import path from 'path';
|
|
3
|
-
import { fileURLToPath } from 'url';
|
|
4
3
|
import fs from 'fs';
|
|
5
4
|
import CodeInjector from '../modules/codeInjector.js';
|
|
6
|
-
import AdminForth from '../index.js';
|
|
7
5
|
import { Express } from 'express';
|
|
8
6
|
import fetch from 'node-fetch';
|
|
9
|
-
|
|
10
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
11
|
-
const __dirname = path.dirname(__filename);
|
|
12
|
-
|
|
7
|
+
import { AdminForthClass, ExpressHttpServer } from '../types/AdminForthConfig.js';
|
|
13
8
|
|
|
14
9
|
|
|
15
10
|
function replaceAtStart(string, substring) {
|
|
@@ -80,12 +75,12 @@ const respondNoServer = (title, explanation) => {
|
|
|
80
75
|
</body>
|
|
81
76
|
`;
|
|
82
77
|
}
|
|
83
|
-
class ExpressServer {
|
|
78
|
+
class ExpressServer implements ExpressHttpServer {
|
|
84
79
|
|
|
85
80
|
expressApp: Express;
|
|
86
|
-
adminforth:
|
|
81
|
+
adminforth: AdminForthClass;
|
|
87
82
|
|
|
88
|
-
constructor(adminforth) {
|
|
83
|
+
constructor(adminforth: AdminForthClass) {
|
|
89
84
|
this.adminforth = adminforth;
|
|
90
85
|
}
|
|
91
86
|
|
package/spa/package-lock.json
CHANGED
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
"flowbite-datepicker": "^1.2.6",
|
|
18
18
|
"pinia": "^2.1.7",
|
|
19
19
|
"unhead": "^1.9.12",
|
|
20
|
+
"uuid": "^10.0.0",
|
|
20
21
|
"vue": "^3.4.21",
|
|
21
22
|
"vue-router": "^4.3.0",
|
|
22
23
|
"vue-slider-component": "^4.1.0-beta.7"
|
|
@@ -4032,6 +4033,18 @@
|
|
|
4032
4033
|
"integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==",
|
|
4033
4034
|
"dev": true
|
|
4034
4035
|
},
|
|
4036
|
+
"node_modules/uuid": {
|
|
4037
|
+
"version": "10.0.0",
|
|
4038
|
+
"resolved": "https://registry.npmjs.org/uuid/-/uuid-10.0.0.tgz",
|
|
4039
|
+
"integrity": "sha512-8XkAphELsDnEGrDxUOHB3RGvXz6TeuYSGEZBOjtTtPm2lwhGBjLgOzLHB63IUWfBpNucQjND6d3AOudO+H3RWQ==",
|
|
4040
|
+
"funding": [
|
|
4041
|
+
"https://github.com/sponsors/broofa",
|
|
4042
|
+
"https://github.com/sponsors/ctavan"
|
|
4043
|
+
],
|
|
4044
|
+
"bin": {
|
|
4045
|
+
"uuid": "dist/bin/uuid"
|
|
4046
|
+
}
|
|
4047
|
+
},
|
|
4035
4048
|
"node_modules/vite": {
|
|
4036
4049
|
"version": "5.2.13",
|
|
4037
4050
|
"resolved": "https://registry.npmjs.org/vite/-/vite-5.2.13.tgz",
|
package/spa/package.json
CHANGED
package/spa/src/App.vue
CHANGED
|
@@ -123,15 +123,43 @@
|
|
|
123
123
|
</div>
|
|
124
124
|
</div>
|
|
125
125
|
<AcceptModal />
|
|
126
|
+
<div v-if="toastStore.toasts.length>0" class="fixed bottom-5 right-5 flex gap-1 flex-col-reverse">
|
|
127
|
+
<transition-group
|
|
128
|
+
name="fade"
|
|
129
|
+
tag="div"
|
|
130
|
+
class="flex flex-col-reverse gap-1"
|
|
131
|
+
>
|
|
132
|
+
<Toast :toast="t" @close="toastStore.removeToast(t)" v-for="(t,i) in toastStore.toasts" :key="`t-${t.id}`" ></Toast>
|
|
133
|
+
</transition-group>
|
|
134
|
+
</div>
|
|
126
135
|
|
|
127
136
|
<div v-if="sideBarOpen"
|
|
128
137
|
@click="sideBarOpen = false"
|
|
129
138
|
|
|
130
139
|
drawer-backdrop="" class="bg-gray-900/50 dark:bg-gray-900/80 fixed inset-0 z-30"></div>
|
|
131
140
|
|
|
141
|
+
|
|
142
|
+
|
|
132
143
|
</template>
|
|
133
144
|
|
|
134
|
-
<style scoped>
|
|
145
|
+
<style lang="scss" scoped>
|
|
146
|
+
|
|
147
|
+
.fade-leave-active {
|
|
148
|
+
@apply transition-opacity duration-500;
|
|
149
|
+
}
|
|
150
|
+
.fade-leave-to {
|
|
151
|
+
@apply opacity-0;
|
|
152
|
+
}
|
|
153
|
+
.fade-enter-active {
|
|
154
|
+
@apply transition-opacity duration-500;
|
|
155
|
+
}
|
|
156
|
+
.fade-enter-from {
|
|
157
|
+
@apply opacity-0;
|
|
158
|
+
}
|
|
159
|
+
.fade-enter-to {
|
|
160
|
+
@apply opacity-100;
|
|
161
|
+
}
|
|
162
|
+
|
|
135
163
|
</style>
|
|
136
164
|
|
|
137
165
|
<script setup lang="ts">
|
|
@@ -140,6 +168,7 @@ import { RouterLink, RouterView } from 'vue-router';
|
|
|
140
168
|
import { initFlowbite } from 'flowbite'
|
|
141
169
|
import './index.scss'
|
|
142
170
|
import { useCoreStore } from '@/stores/core';
|
|
171
|
+
import {useModalStore} from '@/stores/modal';
|
|
143
172
|
import { IconMoonSolid, IconSunSolid } from '@iconify-prerendered/vue-flowbite';
|
|
144
173
|
import AcceptModal from './components/AcceptModal.vue';
|
|
145
174
|
import MenuLink from './components/MenuLink.vue';
|
|
@@ -148,33 +177,22 @@ import { getIcon } from '@/utils';
|
|
|
148
177
|
import { useHead } from 'unhead'
|
|
149
178
|
import { createHead } from 'unhead'
|
|
150
179
|
import { loadFile } from './utils';
|
|
151
|
-
|
|
180
|
+
import Toast from './components/Toast.vue';
|
|
181
|
+
import {useToastStore} from '@/stores/toast';
|
|
182
|
+
import { FrontendAPI } from '@/composables/useStores'
|
|
152
183
|
// import { link } from 'fs';
|
|
153
184
|
const coreStore = useCoreStore();
|
|
154
|
-
|
|
155
|
-
|
|
185
|
+
const modalStore = useModalStore();
|
|
186
|
+
const toastStore = useToastStore();
|
|
187
|
+
const frontendApi = new FrontendAPI();
|
|
188
|
+
frontendApi.init();
|
|
156
189
|
const splitAtLast = (str: string, separator: string) => {
|
|
157
190
|
const index = str.lastIndexOf(separator);
|
|
158
191
|
return [str.slice(0, index), str.slice(index + 1)];
|
|
159
192
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
193
|
createHead()
|
|
164
|
-
|
|
165
|
-
|
|
166
194
|
const sideBarOpen = ref(false);
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
195
|
const route = useRoute();
|
|
171
|
-
watch(route, () => {
|
|
172
|
-
title.value = `${coreStore.config?.title || coreStore.config?.brandName || 'Adminforth'} | ${ Object.values(route.params)[0] || route.meta.title || ' '}`;
|
|
173
|
-
useHead({
|
|
174
|
-
title: title.value,
|
|
175
|
-
})
|
|
176
|
-
});
|
|
177
|
-
|
|
178
196
|
const router = useRouter();
|
|
179
197
|
const title = ref('');
|
|
180
198
|
//create a ref to store the opened menu items with ts type;
|
|
@@ -226,6 +244,13 @@ async function loadMenu() {
|
|
|
226
244
|
});
|
|
227
245
|
}
|
|
228
246
|
|
|
247
|
+
watch(route, () => {
|
|
248
|
+
title.value = `${coreStore.config?.title || coreStore.config?.brandName || 'Adminforth'} | ${ Object.values(route.params)[0] || route.meta.title || ' '}`;
|
|
249
|
+
useHead({
|
|
250
|
+
title: title.value,
|
|
251
|
+
})
|
|
252
|
+
});
|
|
253
|
+
|
|
229
254
|
// initialize components based on data attribute selectors
|
|
230
255
|
onMounted(async () => {
|
|
231
256
|
loadMenu(); // run this in async mode
|
|
@@ -3,13 +3,6 @@ import { ref,onMounted } from 'vue'
|
|
|
3
3
|
import { useModalStore } from '@/stores/modal';
|
|
4
4
|
|
|
5
5
|
const modalStore = useModalStore();
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
6
|
</script>
|
|
14
7
|
|
|
15
8
|
<template>
|
|
@@ -28,10 +21,10 @@ const modalStore = useModalStore();
|
|
|
28
21
|
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 11V6m0 8h.01M19 10a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z"/>
|
|
29
22
|
</svg>
|
|
30
23
|
<h3 class="mb-5 text-lg font-normal text-gray-500 dark:text-gray-400">{{ modalStore?.modalContent?.content }}</h3>
|
|
31
|
-
<button @click="()=>{modalStore.onAcceptFunction();modalStore.togleModal()}" type="button" class="text-white bg-red-600 hover:bg-red-800 focus:ring-4 focus:outline-none focus:ring-red-300 dark:focus:ring-red-800 font-medium rounded-lg text-sm inline-flex items-center px-5 py-2.5 text-center">
|
|
24
|
+
<button @click="()=>{ modalStore.onAcceptFunction(true);modalStore.togleModal()}" type="button" class="text-white bg-red-600 hover:bg-red-800 focus:ring-4 focus:outline-none focus:ring-red-300 dark:focus:ring-red-800 font-medium rounded-lg text-sm inline-flex items-center px-5 py-2.5 text-center">
|
|
32
25
|
{{ modalStore?.modalContent?.acceptText }}
|
|
33
26
|
</button>
|
|
34
|
-
<button @click="modalStore.togleModal" type="button" class="py-2.5 px-5 ms-3 text-sm font-medium text-gray-900 focus:outline-none bg-white rounded-lg border border-gray-200 hover:bg-gray-100 hover:text-blue-700 focus:z-10 focus:ring-4 focus:ring-gray-100 dark:focus:ring-gray-700 dark:bg-gray-800 dark:text-gray-400 dark:border-gray-600 dark:hover:text-white dark:hover:bg-gray-700">{{ modalStore?.modalContent?.cancelText }}</button>
|
|
27
|
+
<button @click="()=>{modalStore.onAcceptFunction(false);modalStore.togleModal()}" type="button" class="py-2.5 px-5 ms-3 text-sm font-medium text-gray-900 focus:outline-none bg-white rounded-lg border border-gray-200 hover:bg-gray-100 hover:text-blue-700 focus:z-10 focus:ring-4 focus:ring-gray-100 dark:focus:ring-gray-700 dark:bg-gray-800 dark:text-gray-400 dark:border-gray-600 dark:hover:text-white dark:hover:bg-gray-700">{{ modalStore?.modalContent?.cancelText }}</button>
|
|
35
28
|
</div>
|
|
36
29
|
</div>
|
|
37
30
|
</div>
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
<div id="toast-default" class="flex items-center w-full max-w-xs p-4 text-gray-500 bg-white rounded-lg shadow dark:text-gray-400 dark:bg-gray-800" role="alert">
|
|
5
|
+
<div v-if="toast.variant == 'info'" class="inline-flex items-center justify-center flex-shrink-0 w-8 h-8 text-blue-500 bg-blue-100 rounded-lg dark:bg-blue-800 dark:text-blue-200">
|
|
6
|
+
<svg class="w-4 h-4" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 18 20">
|
|
7
|
+
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15.147 15.085a7.159 7.159 0 0 1-6.189 3.307A6.713 6.713 0 0 1 3.1 15.444c-2.679-4.513.287-8.737.888-9.548A4.373 4.373 0 0 0 5 1.608c1.287.953 6.445 3.218 5.537 10.5 1.5-1.122 2.706-3.01 2.853-6.14 1.433 1.049 3.993 5.395 1.757 9.117Z"/>
|
|
8
|
+
</svg>
|
|
9
|
+
<span class="sr-only">Fire icon</span>
|
|
10
|
+
</div>
|
|
11
|
+
<div v-else-if="toast.variant == 'danger'" class="inline-flex items-center justify-center flex-shrink-0 w-8 h-8 text-red-500 bg-red-100 rounded-lg dark:bg-red-800 dark:text-red-200">
|
|
12
|
+
<svg class="w-5 h-5" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 20">
|
|
13
|
+
<path d="M10 .5a9.5 9.5 0 1 0 9.5 9.5A9.51 9.51 0 0 0 10 .5Zm3.707 11.793a1 1 0 1 1-1.414 1.414L10 11.414l-2.293 2.293a1 1 0 0 1-1.414-1.414L8.586 10 6.293 7.707a1 1 0 0 1 1.414-1.414L10 8.586l2.293-2.293a1 1 0 0 1 1.414 1.414L11.414 10l2.293 2.293Z"/>
|
|
14
|
+
</svg>
|
|
15
|
+
<span class="sr-only">Error icon</span>
|
|
16
|
+
</div>
|
|
17
|
+
<div v-else-if="toast.variant == 'warning'"class="inline-flex items-center justify-center flex-shrink-0 w-8 h-8 text-orange-500 bg-orange-100 rounded-lg dark:bg-orange-700 dark:text-orange-200">
|
|
18
|
+
<svg class="w-5 h-5" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 20">
|
|
19
|
+
<path d="M10 .5a9.5 9.5 0 1 0 9.5 9.5A9.51 9.51 0 0 0 10 .5ZM10 15a1 1 0 1 1 0-2 1 1 0 0 1 0 2Zm1-4a1 1 0 0 1-2 0V6a1 1 0 0 1 2 0v5Z"/>
|
|
20
|
+
</svg>
|
|
21
|
+
<span class="sr-only">Warning icon</span>
|
|
22
|
+
</div>
|
|
23
|
+
<div v-else class="inline-flex items-center justify-center flex-shrink-0 w-8 h-8 text-green-500 bg-green-100 rounded-lg dark:bg-green-800 dark:text-green-200">
|
|
24
|
+
<svg class="w-5 h-5" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 20">
|
|
25
|
+
<path d="M10 .5a9.5 9.5 0 1 0 9.5 9.5A9.51 9.51 0 0 0 10 .5Zm3.707 8.207-4 4a1 1 0 0 1-1.414 0l-2-2a1 1 0 0 1 1.414-1.414L9 10.586l3.293-3.293a1 1 0 0 1 1.414 1.414Z"/>
|
|
26
|
+
</svg>
|
|
27
|
+
<span class="sr-only">Check icon</span>
|
|
28
|
+
</div>
|
|
29
|
+
<div class="ms-3 text-sm font-normal">{{toast.message}}</div>
|
|
30
|
+
<button @click="closeToast" type="button" class="ms-auto -mx-1.5 -my-1.5 bg-white text-gray-400 hover:text-gray-900 rounded-lg focus:ring-2 focus:ring-gray-300 p-1.5 hover:bg-gray-100 inline-flex items-center justify-center h-8 w-8 dark:text-gray-500 dark:hover:text-white dark:bg-gray-800 dark:hover:bg-gray-700" >
|
|
31
|
+
<svg class="w-3 h-3" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 14 14">
|
|
32
|
+
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m1 1 6 6m0 0 6 6M7 7l6-6M7 7l-6 6"/>
|
|
33
|
+
</svg>
|
|
34
|
+
</button>
|
|
35
|
+
</div>
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
</template>
|
|
39
|
+
|
|
40
|
+
<script setup lang="ts">
|
|
41
|
+
import { onMounted } from 'vue';
|
|
42
|
+
import { useToastStore } from '@/stores/toast';
|
|
43
|
+
const toastStore = useToastStore();
|
|
44
|
+
const emit = defineEmits(['close']);
|
|
45
|
+
const props = defineProps<{
|
|
46
|
+
toast:{message: string;
|
|
47
|
+
variant: string;
|
|
48
|
+
id: string;
|
|
49
|
+
duration?: number;}
|
|
50
|
+
}>();
|
|
51
|
+
function closeToast() {
|
|
52
|
+
emit('close');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
onMounted(() => {
|
|
56
|
+
setTimeout(() => {
|
|
57
|
+
emit('close');
|
|
58
|
+
}, props.toast.duration || 5000 );
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
</script>
|
|
62
|
+
|
|
63
|
+
<style lang="scss" scoped>
|
|
64
|
+
|
|
65
|
+
</style>
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
<div>
|
|
3
3
|
|
|
4
4
|
<span v-if="column.foreignResource">
|
|
5
|
-
<RouterLink v-if="
|
|
6
|
-
:to="{ name: 'resource-show', params: { resourceId: column.foreignResource.resourceId, primaryKey:
|
|
7
|
-
{{
|
|
5
|
+
<RouterLink v-if="record[column.name]" class="font-medium text-blue-600 dark:text-blue-500 hover:brightness-110"
|
|
6
|
+
:to="{ name: 'resource-show', params: { resourceId: column.foreignResource.resourceId, primaryKey: record[column.name].pk } }">
|
|
7
|
+
{{ record[column.name].label }}
|
|
8
8
|
</RouterLink>
|
|
9
9
|
<div v-else>
|
|
10
10
|
<span class="text-gray-400">-</span>
|
|
@@ -12,18 +12,18 @@
|
|
|
12
12
|
</span>
|
|
13
13
|
|
|
14
14
|
<span v-else-if="column.type === 'boolean'">
|
|
15
|
-
<span v-if="
|
|
15
|
+
<span v-if="record[column.name]" class="bg-green-100 text-green-800 text-xs font-medium me-2 px-2.5 py-0.5 rounded dark:bg-gray-700 dark:text-green-400 border border-green-400">Yes</span>
|
|
16
16
|
<span v-else class="bg-red-100 text-red-800 text-xs font-medium me-2 px-2.5 py-0.5 rounded dark:bg-gray-700 dark:text-red-400 border border-red-400">No</span>
|
|
17
17
|
</span>
|
|
18
18
|
<span v-else-if="column.enum">
|
|
19
|
-
{{ checkEmptyValues(column.enum.find(e => e.value ===
|
|
19
|
+
{{ checkEmptyValues(column.enum.find(e => e.value === record[column.name])?.label,route.meta.type) }}
|
|
20
20
|
</span>
|
|
21
21
|
<span v-else-if="column.type === 'datetime'">
|
|
22
|
-
{{ checkEmptyValues(formatDate(
|
|
22
|
+
{{ checkEmptyValues(formatDate(record[column.name]),route.meta.type) }}
|
|
23
23
|
|
|
24
24
|
</span>
|
|
25
25
|
<span v-else>
|
|
26
|
-
{{ checkEmptyValues(
|
|
26
|
+
{{ checkEmptyValues(record[column.name],route.meta.type) }}
|
|
27
27
|
</span>
|
|
28
28
|
</div>
|
|
29
29
|
</template>
|
|
@@ -49,7 +49,7 @@ dayjs.extend(timezone);
|
|
|
49
49
|
|
|
50
50
|
const props = defineProps({
|
|
51
51
|
column: Object,
|
|
52
|
-
|
|
52
|
+
record: Object
|
|
53
53
|
});
|
|
54
54
|
|
|
55
55
|
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { FrontendAPIInterface, ConfirmParams, AlertParams } from '../types/FrontendAPI';
|
|
2
|
+
import { useToastStore } from '../stores/toast';
|
|
3
|
+
import { useModalStore } from '../stores/modal';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
declare global {
|
|
8
|
+
interface Window {
|
|
9
|
+
adminforth: {
|
|
10
|
+
confirm: (params: ConfirmParams) => Promise<void>;
|
|
11
|
+
alert: (params: AlertParams) => void;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export class FrontendAPI implements FrontendAPIInterface {
|
|
17
|
+
private toastStore:any
|
|
18
|
+
private modalStore:any
|
|
19
|
+
init() {
|
|
20
|
+
if (window.adminforth) {
|
|
21
|
+
throw new Error('adminforth already initialized');
|
|
22
|
+
}
|
|
23
|
+
this.toastStore = useToastStore();
|
|
24
|
+
this.modalStore = useModalStore();
|
|
25
|
+
console.log(this.toastStore, this.modalStore,'init of adminforth frontend api')
|
|
26
|
+
window.adminforth = {
|
|
27
|
+
confirm: this.confirm.bind(this),
|
|
28
|
+
alert: this.alert.bind(this)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
confirm(params: ConfirmParams): Promise<void> {
|
|
33
|
+
return new Promise((resolve, reject) => {
|
|
34
|
+
this.modalStore.setModalContent({ content: params.message, acceptText: params.yes, cancelText: params.no })
|
|
35
|
+
this.modalStore.onAcceptFunction = resolve
|
|
36
|
+
this.modalStore.onCancelFunction = reject
|
|
37
|
+
this.modalStore.togleModal()
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
alert(params: AlertParams): void {
|
|
42
|
+
this.toastStore.addToast({
|
|
43
|
+
message: params.message,
|
|
44
|
+
variant: params.variant
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
package/spa/src/stores/core.ts
CHANGED
|
@@ -8,6 +8,8 @@ export const useCoreStore = defineStore('core', () => {
|
|
|
8
8
|
const config = ref({});
|
|
9
9
|
const record = ref({});
|
|
10
10
|
const resourceColumns = ref(null);
|
|
11
|
+
const resource = ref(null);
|
|
12
|
+
|
|
11
13
|
const resourceOptions = ref(null);
|
|
12
14
|
const resourceColumnsError = ref('');
|
|
13
15
|
const resourceColumnsId = ref(null);
|
|
@@ -85,6 +87,7 @@ export const useCoreStore = defineStore('core', () => {
|
|
|
85
87
|
} else {
|
|
86
88
|
resourceColumns.value = res.resource.columns;
|
|
87
89
|
resourceById.value[resourceId] = res.resource;
|
|
90
|
+
resource.value = res.resource;
|
|
88
91
|
resourceOptions.value = res.resource.options;
|
|
89
92
|
}
|
|
90
93
|
}
|
|
@@ -129,6 +132,7 @@ export const useCoreStore = defineStore('core', () => {
|
|
|
129
132
|
fetchResourceFull,
|
|
130
133
|
resourceColumnsError,
|
|
131
134
|
resourceOptions,
|
|
132
|
-
logout
|
|
135
|
+
logout,
|
|
136
|
+
resource,
|
|
133
137
|
}
|
|
134
138
|
})
|
package/spa/src/stores/modal.ts
CHANGED
|
@@ -2,6 +2,13 @@ import { ref } from 'vue'
|
|
|
2
2
|
import { defineStore } from 'pinia'
|
|
3
3
|
import { callAdminForthApi } from '@/utils';
|
|
4
4
|
|
|
5
|
+
type ModalContentType = {
|
|
6
|
+
title?: string;
|
|
7
|
+
content?: string;
|
|
8
|
+
acceptText?: string;
|
|
9
|
+
cancelText?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
5
12
|
|
|
6
13
|
export const useModalStore = defineStore('modal', () => {
|
|
7
14
|
const modalContent = ref({
|
|
@@ -12,13 +19,17 @@ export const useModalStore = defineStore('modal', () => {
|
|
|
12
19
|
});
|
|
13
20
|
const isOpened = ref(false);
|
|
14
21
|
const onAcceptFunction: any = ref(()=>{});
|
|
22
|
+
const onCancelFunction: any = ref(()=>{});
|
|
15
23
|
function togleModal() {
|
|
16
24
|
isOpened.value = !isOpened.value;
|
|
17
25
|
}
|
|
18
26
|
function setOnAcceptFunction(func: Function) {
|
|
19
27
|
onAcceptFunction.value = func;
|
|
20
28
|
}
|
|
21
|
-
function
|
|
29
|
+
function setOnCancelFunction(func: Function) {
|
|
30
|
+
onCancelFunction.value = func;
|
|
31
|
+
}
|
|
32
|
+
function setModalContent(content: ModalContentType) {
|
|
22
33
|
modalContent.value = content;
|
|
23
34
|
}
|
|
24
35
|
function resetmodalState() {
|
|
@@ -33,6 +44,6 @@ export const useModalStore = defineStore('modal', () => {
|
|
|
33
44
|
|
|
34
45
|
}
|
|
35
46
|
|
|
36
|
-
return {isOpened, setModalContent, togleModal,modalContent, setOnAcceptFunction, onAcceptFunction,resetmodalState}
|
|
47
|
+
return {isOpened, setModalContent,onCancelFunction, togleModal,modalContent, setOnAcceptFunction, onAcceptFunction,resetmodalState,setOnCancelFunction}
|
|
37
48
|
|
|
38
49
|
})
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ref, computed } from 'vue'
|
|
2
|
+
import { defineStore } from 'pinia'
|
|
3
|
+
import { callAdminForthApi } from '@/utils';
|
|
4
|
+
import { v1 as uuid } from 'uuid';
|
|
5
|
+
|
|
6
|
+
export const useToastStore = defineStore('toast', () => {
|
|
7
|
+
const toasts = ref([]);
|
|
8
|
+
const addToast = (toast) => {
|
|
9
|
+
toasts.value.push({...toast, id: uuid()});
|
|
10
|
+
};
|
|
11
|
+
const removeToast = (toast) => {
|
|
12
|
+
toasts.value = toasts.value.filter((t) => t.id !== toast.id);
|
|
13
|
+
};
|
|
14
|
+
return { toasts, addToast, removeToast };
|
|
15
|
+
});
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div class="relative">
|
|
3
3
|
|
|
4
|
+
<component
|
|
5
|
+
v-for="c in coreStore?.resourceOptions?.pageInjections?.create?.beforeBreadcrumbs || []"
|
|
6
|
+
:is="getCustomComponent(c)"
|
|
7
|
+
:record="coreStore.record"
|
|
8
|
+
:resource="coreStore.resource"
|
|
9
|
+
:adminUser="coreStore.adminUser"
|
|
10
|
+
/>
|
|
11
|
+
|
|
4
12
|
<BreadcrumbsWithButtons>
|
|
5
13
|
<!-- save and cancle -->
|
|
6
14
|
<button @click="$router.back()"
|
|
@@ -22,6 +30,14 @@
|
|
|
22
30
|
|
|
23
31
|
</BreadcrumbsWithButtons>
|
|
24
32
|
|
|
33
|
+
<component
|
|
34
|
+
v-for="c in coreStore?.resourceOptions?.pageInjections?.create?.afterBreadcrumbs || []"
|
|
35
|
+
:is="getCustomComponent(c)"
|
|
36
|
+
:record="coreStore.record"
|
|
37
|
+
:resource="coreStore.resource"
|
|
38
|
+
:adminUser="coreStore.adminUser"
|
|
39
|
+
/>
|
|
40
|
+
|
|
25
41
|
<SingleSkeletLoader v-if="loading"></SingleSkeletLoader>
|
|
26
42
|
|
|
27
43
|
|
|
@@ -36,6 +52,13 @@
|
|
|
36
52
|
>
|
|
37
53
|
</ResourceForm>
|
|
38
54
|
|
|
55
|
+
<component
|
|
56
|
+
v-for="c in coreStore?.resourceOptions?.pageInjections?.create?.bottom || []"
|
|
57
|
+
:is="getCustomComponent(c)"
|
|
58
|
+
:record="coreStore.record"
|
|
59
|
+
:resource="coreStore.resource"
|
|
60
|
+
:adminUser="coreStore.adminUser"
|
|
61
|
+
/>
|
|
39
62
|
|
|
40
63
|
</div>
|
|
41
64
|
</template>
|
|
@@ -78,8 +101,8 @@ onMounted(async () => {
|
|
|
78
101
|
resourceId: route.params.resourceId
|
|
79
102
|
});
|
|
80
103
|
createComponentsPerColumn = coreStore.resourceColumns.reduce((acc, column) => {
|
|
81
|
-
if (column.
|
|
82
|
-
acc[column.name] = getCustomComponent(column.
|
|
104
|
+
if (column.components?.create) {
|
|
105
|
+
acc[column.name] = getCustomComponent(column.components.create);
|
|
83
106
|
}
|
|
84
107
|
return acc;
|
|
85
108
|
}, {});
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div class="relative">
|
|
3
|
+
<component
|
|
4
|
+
v-for="c in coreStore?.resourceOptions?.pageInjections?.edit?.beforeBreadcrumbs || []"
|
|
5
|
+
:is="getCustomComponent(c)"
|
|
6
|
+
:record="editableRecord"
|
|
7
|
+
:resource="coreStore.resource"
|
|
8
|
+
:adminUser="coreStore.adminUser"
|
|
9
|
+
/>
|
|
3
10
|
|
|
4
11
|
<BreadcrumbsWithButtons>
|
|
5
12
|
<!-- save and cancle -->
|
|
@@ -19,18 +26,36 @@
|
|
|
19
26
|
|
|
20
27
|
</BreadcrumbsWithButtons>
|
|
21
28
|
|
|
29
|
+
<component
|
|
30
|
+
v-for="c in coreStore?.resourceOptions?.pageInjections?.edit?.afterBreadcrumbs || []"
|
|
31
|
+
:is="getCustomComponent(c)"
|
|
32
|
+
:record="coreStore.record"
|
|
33
|
+
:resource="coreStore.resource"
|
|
34
|
+
:adminUser="coreStore.adminUser"
|
|
35
|
+
/>
|
|
36
|
+
|
|
22
37
|
<SingleSkeletLoader v-if="loading"></SingleSkeletLoader>
|
|
23
38
|
|
|
24
39
|
<ResourceForm
|
|
25
40
|
v-else
|
|
26
41
|
:record="editableRecord"
|
|
27
|
-
:
|
|
42
|
+
:resource="coreStore.resource"
|
|
43
|
+
:adminUser="coreStore.adminUser"
|
|
28
44
|
@update:record="onUpdateRecord"
|
|
29
45
|
@update:isValid="isValid = $event"
|
|
30
46
|
:validating="validating"
|
|
31
47
|
:customComponentsPerColumn="editComponentsPerColumn"
|
|
32
48
|
>
|
|
33
49
|
</ResourceForm>
|
|
50
|
+
|
|
51
|
+
<component
|
|
52
|
+
v-for="c in coreStore?.resourceOptions?.pageInjections?.edit?.bottom || []"
|
|
53
|
+
:is="getCustomComponent(c)"
|
|
54
|
+
:record="coreStore.record"
|
|
55
|
+
:resource="coreStore.resource"
|
|
56
|
+
:adminUser="coreStore.adminUser"
|
|
57
|
+
/>
|
|
58
|
+
|
|
34
59
|
</div>
|
|
35
60
|
</template>
|
|
36
61
|
|
|
@@ -92,8 +117,8 @@ onMounted(async () => {
|
|
|
92
117
|
checkAcessByAllowedActions(coreStore.resourceOptions.allowedActions,'edit');
|
|
93
118
|
|
|
94
119
|
editComponentsPerColumn = coreStore.resourceColumns.reduce((acc, column) => {
|
|
95
|
-
if (column.
|
|
96
|
-
acc[column.name] = getCustomComponent(column.
|
|
120
|
+
if (column.components?.edit) {
|
|
121
|
+
acc[column.name] = getCustomComponent(column.components.edit);
|
|
97
122
|
}
|
|
98
123
|
return acc;
|
|
99
124
|
}, {});
|
|
@@ -9,6 +9,13 @@
|
|
|
9
9
|
/>
|
|
10
10
|
</Teleport>
|
|
11
11
|
|
|
12
|
+
<component
|
|
13
|
+
v-for="c in coreStore?.resourceOptions?.pageInjections?.list?.beforeBreadcrumbs || []"
|
|
14
|
+
:is="getCustomComponent(c)"
|
|
15
|
+
:resource="coreStore.resource"
|
|
16
|
+
:adminUser="coreStore.adminUser"
|
|
17
|
+
/>
|
|
18
|
+
|
|
12
19
|
<BreadcrumbsWithButtons>
|
|
13
20
|
<button
|
|
14
21
|
@click="()=>{checkboxes = []}"
|
|
@@ -64,6 +71,13 @@
|
|
|
64
71
|
</button>
|
|
65
72
|
</BreadcrumbsWithButtons>
|
|
66
73
|
|
|
74
|
+
<component
|
|
75
|
+
v-for="c in coreStore?.resourceOptions?.pageInjections?.list?.afterBreadcrumbs || []"
|
|
76
|
+
:is="getCustomComponent(c)"
|
|
77
|
+
:resource="coreStore.resource"
|
|
78
|
+
:adminUser="coreStore.adminUser"
|
|
79
|
+
/>
|
|
80
|
+
|
|
67
81
|
<!-- table -->
|
|
68
82
|
<div class="relative overflow-x-auto shadow-list-table-shadow dark:shadow-black overflow-y-hidden rounded-default">
|
|
69
83
|
|
|
@@ -202,7 +216,9 @@
|
|
|
202
216
|
<component
|
|
203
217
|
:is="listComponentsPerColumn[c.name] || ValueRenderer"
|
|
204
218
|
:column="c"
|
|
205
|
-
:
|
|
219
|
+
:record="row"
|
|
220
|
+
:adminUser="coreStore.adminUser"
|
|
221
|
+
:resource="coreStore.resource"
|
|
206
222
|
/>
|
|
207
223
|
</td>
|
|
208
224
|
<td class=" items-center px-6 py-4">
|
|
@@ -260,8 +276,7 @@
|
|
|
260
276
|
</div>
|
|
261
277
|
<!-- pagination -->
|
|
262
278
|
<div class="flex flex-col items-center mt-4 xs:flex-row xs:justify-between xs:items-center"
|
|
263
|
-
v-if="rows && totalRows >= pageSize && totalRows > 0"
|
|
264
|
-
>
|
|
279
|
+
v-if="rows && totalRows >= pageSize && totalRows > 0">
|
|
265
280
|
<!-- Help text -->
|
|
266
281
|
<span class="text-sm text-gray-700 dark:text-gray-400">
|
|
267
282
|
Showing <span class="font-semibold text-gray-900 dark:text-white">
|
|
@@ -313,6 +328,14 @@
|
|
|
313
328
|
</button>
|
|
314
329
|
</div>
|
|
315
330
|
</div>
|
|
331
|
+
|
|
332
|
+
<component
|
|
333
|
+
v-for="c in coreStore?.resourceOptions?.pageInjections?.list?.bottom || []"
|
|
334
|
+
:is="getCustomComponent(c)"
|
|
335
|
+
:resource="coreStore.resource"
|
|
336
|
+
:adminUser="coreStore.adminUser"
|
|
337
|
+
/>
|
|
338
|
+
|
|
316
339
|
</div>
|
|
317
340
|
</template>
|
|
318
341
|
|
|
@@ -434,8 +457,8 @@ async function getList() {
|
|
|
434
457
|
}
|
|
435
458
|
});
|
|
436
459
|
listComponentsPerColumn = coreStore.resourceColumns.reduce((acc, column) => {
|
|
437
|
-
if (column.
|
|
438
|
-
acc[column.name] = getCustomComponent(column.
|
|
460
|
+
if (column.components?.list) {
|
|
461
|
+
acc[column.name] = getCustomComponent(column.components.list);
|
|
439
462
|
}
|
|
440
463
|
return acc;
|
|
441
464
|
}, {});
|