adminforth 1.1.32 → 1.1.33

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.
Files changed (98) hide show
  1. package/dist/index.js +9 -0
  2. package/dist/modules/codeInjector.js +19 -7
  3. package/dist/modules/styles.js +2 -2
  4. package/dist/spa/index.html +2 -2
  5. package/dist/spa/package-lock.json +17 -4
  6. package/dist/spa/package.json +2 -1
  7. package/dist/spa/src/App.vue +125 -45
  8. package/dist/spa/src/assets/logo.svg +19 -1
  9. package/dist/spa/src/components/AcceptModal.vue +2 -9
  10. package/dist/spa/src/components/BreadcrumbsWithButtons.vue +1 -1
  11. package/dist/spa/src/components/CustomDatePicker.vue +16 -3
  12. package/dist/spa/src/components/CustomDateRangePicker.vue +11 -2
  13. package/dist/spa/src/components/Dropdown.vue +6 -1
  14. package/dist/spa/src/components/Filters.vue +40 -19
  15. package/dist/spa/src/components/ResourceForm.vue +26 -24
  16. package/dist/spa/src/components/ValueRenderer.vue +14 -8
  17. package/dist/spa/src/main.ts +1 -1
  18. package/dist/spa/src/router/index.ts +30 -20
  19. package/dist/spa/src/stores/core.ts +48 -31
  20. package/dist/spa/src/stores/modal.ts +13 -3
  21. package/dist/spa/src/utils.ts +62 -7
  22. package/dist/spa/src/views/CreateView.vue +67 -15
  23. package/dist/spa/src/views/EditView.vue +45 -11
  24. package/dist/spa/src/views/ListView.vue +82 -366
  25. package/dist/spa/src/views/LoginView.vue +16 -4
  26. package/dist/spa/src/views/ShowView.vue +105 -21
  27. package/dist/spa/tailwind.config.js +1 -1
  28. package/dist/spa/vite.config.ts +6 -0
  29. package/index.ts +11 -0
  30. package/modules/codeInjector.ts +19 -1
  31. package/modules/styles.ts +2 -2
  32. package/package.json +1 -1
  33. package/spa/index.html +1 -1
  34. package/spa/src/App.vue +2 -3
  35. package/types/AdminForthConfig.ts +15 -0
  36. package/dist/plugins/AccessControl/index.js +0 -66
  37. package/dist/plugins/AccessControl/types.js +0 -1
  38. package/dist/spa/public/favicon.ico +0 -0
  39. package/dist/spa/spa/.eslintrc.cjs +0 -14
  40. package/dist/spa/spa/.vscode/extensions.json +0 -6
  41. package/dist/spa/spa/README.md +0 -39
  42. package/dist/spa/spa/env.d.ts +0 -1
  43. package/dist/spa/spa/index.html +0 -23
  44. package/dist/spa/spa/package-lock.json +0 -4359
  45. package/dist/spa/spa/package.json +0 -47
  46. package/dist/spa/spa/postcss.config.js +0 -6
  47. package/dist/spa/spa/public/favicon.ico +0 -0
  48. package/dist/spa/spa/src/App.vue +0 -272
  49. package/dist/spa/spa/src/assets/base.css +0 -0
  50. package/dist/spa/spa/src/assets/logo.svg +0 -19
  51. package/dist/spa/spa/src/components/AcceptModal.vue +0 -45
  52. package/dist/spa/spa/src/components/Breadcrumbs.vue +0 -40
  53. package/dist/spa/spa/src/components/BreadcrumbsWithButtons.vue +0 -26
  54. package/dist/spa/spa/src/components/CustomDatePicker.vue +0 -174
  55. package/dist/spa/spa/src/components/CustomDateRangePicker.vue +0 -218
  56. package/dist/spa/spa/src/components/CustomRangePicker.vue +0 -148
  57. package/dist/spa/spa/src/components/Dropdown.vue +0 -168
  58. package/dist/spa/spa/src/components/Filters.vue +0 -211
  59. package/dist/spa/spa/src/components/HelloWorld.vue +0 -17
  60. package/dist/spa/spa/src/components/MenuLink.vue +0 -24
  61. package/dist/spa/spa/src/components/ResourceForm.vue +0 -265
  62. package/dist/spa/spa/src/components/SingleSkeletLoader.vue +0 -13
  63. package/dist/spa/spa/src/components/ValueRenderer.vue +0 -60
  64. package/dist/spa/spa/src/components/icons/IconCalendar.vue +0 -5
  65. package/dist/spa/spa/src/components/icons/IconCommunity.vue +0 -7
  66. package/dist/spa/spa/src/components/icons/IconDocumentation.vue +0 -7
  67. package/dist/spa/spa/src/components/icons/IconEcosystem.vue +0 -7
  68. package/dist/spa/spa/src/components/icons/IconSupport.vue +0 -7
  69. package/dist/spa/spa/src/components/icons/IconTime.vue +0 -5
  70. package/dist/spa/spa/src/components/icons/IconTooling.vue +0 -19
  71. package/dist/spa/spa/src/index.scss +0 -26
  72. package/dist/spa/spa/src/main.ts +0 -18
  73. package/dist/spa/spa/src/router/index.ts +0 -64
  74. package/dist/spa/spa/src/stores/core.ts +0 -144
  75. package/dist/spa/spa/src/stores/modal.ts +0 -48
  76. package/dist/spa/spa/src/utils.ts +0 -101
  77. package/dist/spa/spa/src/views/CreateView.vue +0 -163
  78. package/dist/spa/spa/src/views/EditView.vue +0 -165
  79. package/dist/spa/spa/src/views/ListView.vue +0 -257
  80. package/dist/spa/spa/src/views/LoginView.vue +0 -134
  81. package/dist/spa/spa/src/views/ResourceParent.vue +0 -18
  82. package/dist/spa/spa/src/views/ShowView.vue +0 -188
  83. package/dist/spa/spa/tailwind.config.js +0 -15
  84. package/dist/spa/spa/tsconfig.app.json +0 -14
  85. package/dist/spa/spa/tsconfig.json +0 -11
  86. package/dist/spa/spa/tsconfig.node.json +0 -19
  87. package/dist/spa/spa/vite.config.ts +0 -49
  88. package/dist/types.js +0 -30
  89. /package/dist/spa/{spa/public → public/assets}/favicon.png +0 -0
  90. /package/dist/spa/{spa/src → src}/components/ResourceListTable.vue +0 -0
  91. /package/dist/spa/{spa/src → src}/components/Toast.vue +0 -0
  92. /package/dist/spa/{spa/src → src}/composables/useFrontendApi.ts +0 -0
  93. /package/dist/spa/{spa/src → src}/composables/useStores.ts +0 -0
  94. /package/dist/spa/{spa/src → src}/spa_types/core.ts +0 -0
  95. /package/dist/spa/{spa/src → src}/stores/filters.ts +0 -0
  96. /package/dist/spa/{spa/src → src}/stores/toast.ts +0 -0
  97. /package/dist/spa/{spa/src → src}/stores/user.ts +0 -0
  98. /package/spa/public/{favicon.png → assets/favicon.png} +0 -0
@@ -1,19 +0,0 @@
1
- <!-- This icon is from <https://github.com/Templarian/MaterialDesign>, distributed under Apache 2.0 (https://www.apache.org/licenses/LICENSE-2.0) license-->
2
- <template>
3
- <svg
4
- xmlns="http://www.w3.org/2000/svg"
5
- xmlns:xlink="http://www.w3.org/1999/xlink"
6
- aria-hidden="true"
7
- role="img"
8
- class="iconify iconify--mdi"
9
- width="24"
10
- height="24"
11
- preserveAspectRatio="xMidYMid meet"
12
- viewBox="0 0 24 24"
13
- >
14
- <path
15
- d="M20 18v-4h-3v1h-2v-1H9v1H7v-1H4v4h16M6.33 8l-1.74 4H7v-1h2v1h6v-1h2v1h2.41l-1.74-4H6.33M9 5v1h6V5H9m12.84 7.61c.1.22.16.48.16.8V18c0 .53-.21 1-.6 1.41c-.4.4-.85.59-1.4.59H4c-.55 0-1-.19-1.4-.59C2.21 19 2 18.53 2 18v-4.59c0-.32.06-.58.16-.8L4.5 7.22C4.84 6.41 5.45 6 6.33 6H7V5c0-.55.18-1 .57-1.41C7.96 3.2 8.44 3 9 3h6c.56 0 1.04.2 1.43.59c.39.41.57.86.57 1.41v1h.67c.88 0 1.49.41 1.83 1.22l2.34 5.39z"
16
- fill="currentColor"
17
- ></path>
18
- </svg>
19
- </template>
@@ -1,26 +0,0 @@
1
- @tailwind base;
2
- @tailwind components;
3
- @tailwind utilities;
4
-
5
-
6
- // @layer base {
7
- // /* width */
8
- // ::-webkit-scrollbar {
9
- // @apply w-2 p-2
10
- // }
11
-
12
- // /* Track */
13
- // ::-webkit-scrollbar-track {
14
- // @apply bg-inherit
15
- // }
16
-
17
- // /* Handle */
18
- // ::-webkit-scrollbar-thumb {
19
- // @apply bg-gray-200 dark:bg-gray-600 rounded-xl
20
- // }
21
-
22
- // /* Handle on hover */
23
- // ::-webkit-scrollbar-thumb:hover {
24
- // @apply bg-gray-700
25
- // }
26
- // }
@@ -1,18 +0,0 @@
1
- import { createApp } from 'vue'
2
- import { createPinia } from 'pinia'
3
- /* IMPORTANT:ADMINFORTH IMPORTS */
4
-
5
-
6
- import App from './App.vue'
7
- import router from './router'
8
-
9
- const app = createApp(App)
10
- /* IMPORTANT:ADMINFORTH COMPONENT REGISTRATIONS */
11
-
12
-
13
- app.use(createPinia())
14
- app.use(router)
15
-
16
- /* IMPORTANT:ADMINFORTH CUSTOM USES */
17
-
18
- app.mount('#app')
@@ -1,64 +0,0 @@
1
- import { createRouter, createWebHistory } from 'vue-router'
2
- import ResourceParent from '@/views/ResourceParent.vue'
3
- import { useUserStore } from '@/stores/user'
4
- /* IMPORTANT:ADMINFORTH ROUTES IMPORTS */
5
-
6
- const router = createRouter({
7
- history: createWebHistory(import.meta.env.BASE_URL),
8
- routes: [
9
- {
10
- path: '/login',
11
- name: 'login',
12
- component: () => import('@/views/LoginView.vue'),
13
- meta: { title: 'login' },
14
- beforeEnter: async (to, from, next) => {
15
- const userStore = useUserStore()
16
- if(localStorage.getItem('isAuthorized') === 'true'){
17
- next({name: 'home'})
18
- } else {
19
- next()
20
- }
21
- }
22
- },
23
- {
24
- path: '/resource/:resourceId',
25
- component: ResourceParent,
26
- name: 'resource',
27
- children: [
28
- {
29
- path: '',
30
- component: () => import('@/views/ListView.vue'),
31
- name: 'resource-list',
32
- meta: { title: 'list',type: 'list' }
33
- },
34
- {
35
- path: 'show/:primaryKey',
36
- component: () => import('@/views/ShowView.vue'),
37
- name: 'resource-show',
38
- meta: { title: 'show', type: 'show'}
39
-
40
- },
41
- {
42
- path: 'edit/:primaryKey',
43
- component: () => import('@/views/EditView.vue'),
44
- name: 'resource-edit',
45
- meta: { title: 'edit', type: 'edit'}
46
- },
47
- {
48
- path: 'create',
49
- component: () => import('@/views/CreateView.vue'),
50
- name: 'resource-create',
51
- meta: { title: 'create', type: 'create'}
52
-
53
- },
54
- ]
55
- },
56
- /* IMPORTANT:ADMINFORTH ROUTES */
57
- ]
58
- })
59
-
60
-
61
-
62
-
63
-
64
- export default router
@@ -1,144 +0,0 @@
1
- import { ref, computed } from 'vue'
2
- import { defineStore } from 'pinia'
3
- import { callAdminForthApi } from '@/utils';
4
- import type { AdminForthResource, AdminForthResourceColumn } from '@/types/AdminForthConfig';
5
- import type { Ref } from 'vue'
6
-
7
- export const useCoreStore = defineStore('core', () => {
8
- const resourceById: Ref<Object> = ref({});
9
- const menu = ref([]);
10
- const config = ref({});
11
- const record: Ref<any | null> = ref({});
12
- const resource: Ref<AdminForthResource | null> = ref(null);
13
-
14
- const resourceColumnsWithFilters = computed(() => {
15
- if (!resource.value) {
16
- return [];
17
- }
18
- return resource.value.columns.filter((col: AdminForthResourceColumn) => col.showIn?.includes('filter'));
19
- })
20
-
21
- const resourceOptions = ref(null);
22
- const resourceColumnsError = ref('');
23
- const resourceColumnsId = ref(null);
24
- const adminUser = ref(null);
25
-
26
- async function fetchMenuAndResource() {
27
- const resp = await callAdminForthApi({
28
- path: '/get_base_config',
29
- method: 'GET',
30
- });
31
- if(!resp){
32
- return
33
- }
34
- menu.value = resp.menu;
35
- resourceById.value = resp.resources.reduce((acc: Object, resource: AdminForthResource) => {
36
- acc[resource.resourceId] = resource;
37
- return acc;
38
- }, {});
39
- config.value = resp.config;
40
- adminUser.value = resp.user;
41
- console.log('🌍 AdminForth v', resp.version);
42
- }
43
-
44
- async function fetchRecord({ resourceId, primaryKey }) {
45
- record.value = null;
46
-
47
- if (!resource.value) {
48
- throw new Error('Columns not fetched yet');
49
- }
50
-
51
- const respData = await callAdminForthApi({
52
- path: '/get_resource_data',
53
- method: 'POST',
54
- body: {
55
- source: 'show',
56
- resourceId: resourceId,
57
- filters: [
58
- {
59
- field: resource.value.columns.find((col: AdminForthResourceColumn) => col.primaryKey).name,
60
- operator: 'eq',
61
- value: primaryKey
62
- }
63
- ],
64
- sort: [],
65
- limit: 1,
66
- offset: 0
67
- }
68
- });
69
-
70
- if (respData.error) {
71
- window.adminforth.alert({
72
- message: respData.error,
73
- variant: 'danger',
74
- timeout: 'unlimited'
75
- });
76
- record.value = {};
77
- } else {
78
- record.value = respData.data[0];
79
- }
80
-
81
- }
82
-
83
- async function fetchResourceFull({ resourceId }: { resourceId: string }) {
84
- if (resourceColumnsId.value === resourceId && resource.value) {
85
- // already fetched
86
- return;
87
- }
88
- resourceColumnsId.value = resourceId;
89
- resourceColumnsError.value = '';
90
- const res = await callAdminForthApi({
91
- path: '/get_resource',
92
- method: 'POST',
93
- body: {
94
- resourceId,
95
- }
96
- });
97
- if (res.error) {
98
- resourceColumnsError.value = res.error;
99
- } else {
100
- resourceById.value[resourceId] = res.resource;
101
- resource.value = res.resource;
102
- resourceOptions.value = res.resource.options;
103
- }
104
- }
105
-
106
- async function getPublicConfig() {
107
- const res = await callAdminForthApi({
108
- path: '/get_public_config',
109
- method: 'GET',
110
- });
111
- config.value = {...config.value, ...res};
112
- }
113
-
114
-
115
-
116
- const username = computed(() => {
117
- const usernameField = config.value.usernameField;
118
- return adminUser.value && adminUser.value[usernameField];
119
- });
120
-
121
- const userFullname = computed(() => {
122
- const userFullnameField = config.value.userFullnameField;
123
- return adminUser.value && adminUser.value[userFullnameField];
124
- })
125
-
126
-
127
- return {
128
- config,
129
- resourceById,
130
- menu,
131
- username,
132
- userFullname,
133
- getPublicConfig,
134
- fetchMenuAndResource,
135
- fetchRecord,
136
- record,
137
- fetchResourceFull,
138
- resourceColumnsError,
139
- resourceOptions,
140
- resource,
141
- adminUser,
142
- resourceColumnsWithFilters
143
- }
144
- })
@@ -1,48 +0,0 @@
1
- import { ref } from 'vue'
2
- import { defineStore } from 'pinia'
3
-
4
- type ModalContentType = {
5
- title?: string;
6
- content?: string;
7
- acceptText?: string;
8
- cancelText?: string;
9
- }
10
-
11
-
12
- export const useModalStore = defineStore('modal', () => {
13
- const modalContent = ref({
14
- title: 'title',
15
- content: 'content',
16
- acceptText: 'acceptText',
17
- cancelText: 'cancelText',
18
- });
19
- const isOpened = ref(false);
20
- const onAcceptFunction: any = ref(()=>{});
21
- const onCancelFunction: any = ref(()=>{});
22
- function togleModal() {
23
- isOpened.value = !isOpened.value;
24
- }
25
- function setOnAcceptFunction(func: Function) {
26
- onAcceptFunction.value = func;
27
- }
28
- function setOnCancelFunction(func: Function) {
29
- onCancelFunction.value = func;
30
- }
31
- function setModalContent(content: ModalContentType) {
32
- modalContent.value = content;
33
- }
34
- function resetmodalState() {
35
- isOpened.value = false;
36
- modalContent.value = {
37
- title: 'title',
38
- content: 'content',
39
- acceptText: 'acceptText',
40
- cancelText: 'cancelText',
41
- };
42
- setOnAcceptFunction(()=>{});
43
-
44
- }
45
-
46
- return {isOpened, setModalContent,onCancelFunction, togleModal,modalContent, setOnAcceptFunction, onAcceptFunction,resetmodalState,setOnCancelFunction}
47
-
48
- })
@@ -1,101 +0,0 @@
1
- import { onMounted, ref, resolveComponent } from 'vue';
2
- import type { CoreConfig } from './spa_types/core';
3
-
4
- import router from "./router";
5
- import { useRouter } from 'vue-router';
6
- import { useCoreStore } from './stores/core';
7
- import { useUserStore } from './stores/user';
8
-
9
- export async function callApi({path, method, body=undefined} ) {
10
- const options = {
11
- method,
12
- headers: {
13
- 'Content-Type': 'application/json',
14
- },
15
- body: JSON.stringify(body),
16
- };
17
- const fullPath = `${import.meta.env.VITE_ADMINFORTH_PUBLIC_PATH || ''}${path}`;
18
- const r = await fetch(fullPath, options);
19
- if (r.status == 401) {
20
- useUserStore().unauthorize();
21
- router.push({ name: 'login' });
22
- return null;
23
- }
24
- return await r.json();
25
- }
26
-
27
- export async function callAdminForthApi({ path, method, body=undefined }: {
28
- path: string,
29
- method: 'GET' | 'POST' | 'PUT' | 'DELETE',
30
- body?: any
31
- }) {
32
- try {
33
- return callApi({path: `/adminapi/v1${path}`, method, body} );
34
- } catch (e) {
35
- console.error('error', e);
36
- return { error: `Unexpected error: ${e}` };
37
- }
38
- }
39
-
40
- export function getCustomComponent({ file, meta }: { file: string, meta: any }) {
41
- const name = file.replace(/@/g, '').replace(/\./g, '').replace(/\//g, '');
42
- console.log('resolving name', name);
43
- return resolveComponent(name);
44
- }
45
-
46
- export function getIcon(icon: string) {
47
- // icon format is "feather:icon-name". We need to get IconName in pascal case
48
- if (!icon.includes(':')) {
49
- throw new Error('Icon name should be in format "icon-set:icon-name"');
50
- }
51
- const [iconSet, iconName] = icon.split(':');
52
- const compName = 'Icon' + iconName.split('-').map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join('');
53
- return resolveComponent(compName);
54
- }
55
-
56
- export const loadFile = (file: string) => {
57
- if (file.startsWith('http')) {
58
- return file;
59
- }
60
- let path;
61
- let baseUrl = '';
62
- if (file.startsWith('@/')) {
63
- path = file.replace('@/', '');
64
- baseUrl = new URL(`./${path}`, import.meta.url).href;
65
- } else if (file.startsWith('@@/')) {
66
- path = file.replace('@@/', '');
67
- baseUrl = new URL(`./custom/${path}`, import.meta.url).href;
68
- } else {
69
- baseUrl = new URL(`./${file}`, import.meta.url).href;
70
- }
71
- return baseUrl;
72
- }
73
-
74
- export function checkEmptyValues(value: any, viewType:'show' | 'list' ) {
75
- const config: CoreConfig | {} = useCoreStore().config;
76
- let emptyFieldPlaceholder = '';
77
- if (config.emptyFieldPlaceholder) {
78
- if(typeof config.emptyFieldPlaceholder === 'string') {
79
- emptyFieldPlaceholder = config.emptyFieldPlaceholder;
80
- } else {
81
- emptyFieldPlaceholder = config.emptyFieldPlaceholder?.[viewType] || '';
82
- }
83
- if (value === null || value === undefined || value === '') {
84
- return emptyFieldPlaceholder;
85
- }
86
- }
87
- return value;
88
- }
89
-
90
- export function checkAcessByAllowedActions(allowedActions:any, action:any ) {
91
- if (!allowedActions) {
92
- console.warn('allowedActions not set');
93
- return;
94
- }
95
- if(allowedActions[action] === false) {
96
- console.warn(`Action ${action} is not allowed`);
97
- router.back();
98
- }
99
- }
100
-
101
-
@@ -1,163 +0,0 @@
1
- <template>
2
- <div class="relative">
3
-
4
- <component
5
- v-for="c in coreStore?.resourceOptions?.pageInjections?.create?.beforeBreadcrumbs || []"
6
- :is="getCustomComponent(c)"
7
- :meta="c.meta"
8
- :record="coreStore.record"
9
- :resource="coreStore.resource"
10
- :adminUser="coreStore.adminUser"
11
- />
12
-
13
- <BreadcrumbsWithButtons>
14
- <!-- save and cancle -->
15
- <button @click="$router.back()"
16
- class="flex items-center py-1 px-3 me-2 text-sm font-medium rounded-default text-gray-900 focus:outline-none bg-white rounded border border-gray-300 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"
17
- >
18
- Cancel
19
- </button>
20
-
21
- <button @click="saveRecord"
22
- class="flex items-center py-1 px-3 text-sm font-medium rounded-default text-red-600 focus:outline-none bg-white rounded border border-gray-300 hover:bg-gray-100 hover:text-red-700 focus:z-10 focus:ring-4 focus:ring-gray-100 dark:focus:ring-gray-700 dark:bg-gray-800 dark:text-red-500 dark:border-gray-600 dark:hover:text-white dark:hover:bg-gray-700 disabled:opacity-50"
23
- :disabled="saving || (validating && !isValid)"
24
- >
25
- <svg v-if="saving" x
26
- aria-hidden="true" class="w-4 h-4 mr-1 text-gray-200 animate-spin dark:text-gray-600 fill-red-600" viewBox="0 0 100 101" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z" fill="currentColor"/><path d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z" fill="currentFill"/></svg>
27
-
28
- <IconFloppyDiskSolid v-else class="w-4 h-4 mr-1" />
29
- Save
30
- </button>
31
-
32
- </BreadcrumbsWithButtons>
33
-
34
- <component
35
- v-for="c in coreStore?.resourceOptions?.pageInjections?.create?.afterBreadcrumbs || []"
36
- :is="getCustomComponent(c)"
37
- :meta="c.meta"
38
- :record="coreStore.record"
39
- :resource="coreStore.resource"
40
- :adminUser="coreStore.adminUser"
41
- />
42
-
43
- <SingleSkeletLoader v-if="loading"></SingleSkeletLoader>
44
-
45
-
46
- <ResourceForm
47
- v-else
48
- :record="record"
49
- :resource="coreStore.resource"
50
- @update:record="onUpdateRecord"
51
- @update:isValid="isValid = $event"
52
- :validating="validating"
53
- :customComponentsPerColumn="createComponentsPerColumn"
54
- >
55
- </ResourceForm>
56
-
57
- <component
58
- v-for="c in coreStore?.resourceOptions?.pageInjections?.create?.bottom || []"
59
- :is="getCustomComponent(c)"
60
- :meta="c.meta"
61
- :record="coreStore.record"
62
- :resource="coreStore.resource"
63
- :adminUser="coreStore.adminUser"
64
- />
65
-
66
- </div>
67
- </template>
68
-
69
-
70
- <script setup>
71
-
72
- import BreadcrumbsWithButtons from '@/components/BreadcrumbsWithButtons.vue';
73
- import ResourceForm from '@/components/ResourceForm.vue';
74
- import SingleSkeletLoader from '@/components/SingleSkeletLoader.vue';
75
- import { useCoreStore } from '@/stores/core';
76
- import { callAdminForthApi, getCustomComponent,checkAcessByAllowedActions } from '@/utils';
77
- import { IconFloppyDiskSolid } from '@iconify-prerendered/vue-flowbite';
78
- import { onMounted, ref, watch } from 'vue';
79
- import { useRoute, useRouter } from 'vue-router';
80
- import { computed } from 'vue';
81
- import { showErrorTost } from '@/composables/useFrontendApi';
82
-
83
-
84
- const isValid = ref(false);
85
- const validating = ref(false);
86
-
87
- const loading = ref(false);
88
- const saving = ref(false);
89
-
90
- const route = useRoute();
91
- const router = useRouter();
92
-
93
- const record = ref({});
94
- let createComponentsPerColumn = {};
95
-
96
- const coreStore = useCoreStore();
97
-
98
- const initalValues = computed(() => {
99
- if (!route.query.values) {
100
- return {};
101
- }
102
- return JSON.parse(decodeURIComponent(route.query.values));
103
- });
104
-
105
-
106
-
107
- async function onUpdateRecord(newRecord) {
108
- console.log('newRecord', newRecord);
109
- record.value = newRecord;
110
- }
111
-
112
- onMounted(async () => {
113
- loading.value = true;
114
- record.value = initalValues.value;
115
- await coreStore.fetchResourceFull({
116
- resourceId: route.params.resourceId
117
- });
118
- createComponentsPerColumn = coreStore.resource.columns.reduce((acc, column) => {
119
- if (column.components?.create) {
120
- acc[column.name] = getCustomComponent(column.components.create);
121
- }
122
- return acc;
123
- }, {});
124
- loading.value = false;
125
- checkAcessByAllowedActions(coreStore.resourceOptions.allowedActions,'create');
126
- });
127
-
128
- async function saveRecord() {
129
- if (!isValid.value) {
130
- validating.value = true;
131
- return;
132
- } else {
133
- validating.value = false;
134
- }
135
- saving.value = true;
136
- const response = await callAdminForthApi({
137
- method: 'POST',
138
- path: `/create_record`,
139
- body: {
140
- resourceId: route.params.resourceId,
141
- record: record.value,
142
- },
143
- });
144
- if (response.error) {
145
- showErrorTost(response.error);
146
-
147
- }
148
- saving.value = false;
149
- if (route.query.returnTo) {
150
- router.push(route.query.returnTo);
151
- } else {
152
- router.push({
153
- name: 'resource-show',
154
- params: {
155
- resourceId: route.params.resourceId,
156
- primaryKey: response.newRecordId
157
- }
158
- });
159
- }
160
- }
161
-
162
-
163
- </script>