adminforth 1.3.54-next.9 → 1.3.55-next.2

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 (224) hide show
  1. package/dist/auth.d.ts +31 -0
  2. package/dist/auth.d.ts.map +1 -0
  3. package/dist/auth.js +42 -56
  4. package/dist/auth.js.map +1 -0
  5. package/dist/basePlugin.d.ts +18 -0
  6. package/dist/basePlugin.d.ts.map +1 -0
  7. package/dist/basePlugin.js +1 -0
  8. package/dist/basePlugin.js.map +1 -0
  9. package/dist/dataConnectors/baseConnector.d.ts +94 -0
  10. package/dist/dataConnectors/baseConnector.d.ts.map +1 -0
  11. package/dist/dataConnectors/baseConnector.js +108 -122
  12. package/dist/dataConnectors/baseConnector.js.map +1 -0
  13. package/dist/dataConnectors/clickhouse.d.ts +92 -0
  14. package/dist/dataConnectors/clickhouse.d.ts.map +1 -0
  15. package/dist/dataConnectors/clickhouse.js +132 -149
  16. package/dist/dataConnectors/clickhouse.js.map +1 -0
  17. package/dist/dataConnectors/mongo.d.ts +93 -0
  18. package/dist/dataConnectors/mongo.d.ts.map +1 -0
  19. package/dist/dataConnectors/mongo.js +75 -101
  20. package/dist/dataConnectors/mongo.js.map +1 -0
  21. package/dist/dataConnectors/postgres.d.ts +71 -0
  22. package/dist/dataConnectors/postgres.d.ts.map +1 -0
  23. package/dist/dataConnectors/postgres.js +124 -143
  24. package/dist/dataConnectors/postgres.js.map +1 -0
  25. package/dist/dataConnectors/sqlite.d.ts +67 -0
  26. package/dist/dataConnectors/sqlite.d.ts.map +1 -0
  27. package/dist/dataConnectors/sqlite.js +113 -130
  28. package/dist/dataConnectors/sqlite.js.map +1 -0
  29. package/dist/index.d.ts +92 -0
  30. package/dist/index.d.ts.map +1 -0
  31. package/dist/index.js +197 -217
  32. package/dist/index.js.map +1 -0
  33. package/dist/modules/codeInjector.d.ts +35 -0
  34. package/dist/modules/codeInjector.d.ts.map +1 -0
  35. package/dist/modules/codeInjector.js +480 -486
  36. package/dist/modules/codeInjector.js.map +1 -0
  37. package/dist/modules/configValidator.d.ts +12 -0
  38. package/dist/modules/configValidator.d.ts.map +1 -0
  39. package/dist/modules/configValidator.js +31 -22
  40. package/dist/modules/configValidator.js.map +1 -0
  41. package/dist/modules/operationalResource.d.ts +17 -0
  42. package/dist/modules/operationalResource.d.ts.map +1 -0
  43. package/dist/modules/operationalResource.js +50 -70
  44. package/dist/modules/operationalResource.js.map +1 -0
  45. package/dist/modules/restApi.d.ts +10 -0
  46. package/dist/modules/restApi.d.ts.map +1 -0
  47. package/dist/modules/restApi.js +104 -116
  48. package/dist/modules/restApi.js.map +1 -0
  49. package/dist/modules/styleGenerator.d.ts +9 -0
  50. package/dist/modules/styleGenerator.d.ts.map +1 -0
  51. package/dist/modules/styleGenerator.js +1 -0
  52. package/dist/modules/styleGenerator.js.map +1 -0
  53. package/dist/modules/styles.d.ts +96 -0
  54. package/dist/modules/styles.d.ts.map +1 -0
  55. package/dist/modules/styles.js +1 -0
  56. package/dist/modules/styles.js.map +1 -0
  57. package/dist/modules/utils.d.ts +39 -0
  58. package/dist/modules/utils.d.ts.map +1 -0
  59. package/dist/modules/utils.js +1 -0
  60. package/dist/modules/utils.js.map +1 -0
  61. package/dist/plugins/audit-log/types.d.ts +35 -0
  62. package/dist/plugins/audit-log/types.d.ts.map +1 -0
  63. package/dist/plugins/audit-log/types.js +2 -0
  64. package/dist/plugins/audit-log/types.js.map +1 -0
  65. package/dist/plugins/chat-gpt/types.d.ts +82 -0
  66. package/dist/plugins/chat-gpt/types.d.ts.map +1 -0
  67. package/dist/plugins/chat-gpt/types.js +2 -0
  68. package/dist/plugins/chat-gpt/types.js.map +1 -0
  69. package/dist/plugins/email-password-reset/types.d.ts +28 -0
  70. package/dist/plugins/email-password-reset/types.d.ts.map +1 -0
  71. package/dist/plugins/email-password-reset/types.js +2 -0
  72. package/dist/plugins/email-password-reset/types.js.map +1 -0
  73. package/dist/plugins/foreign-inline-list/types.d.ts +19 -0
  74. package/dist/plugins/foreign-inline-list/types.d.ts.map +1 -0
  75. package/dist/plugins/foreign-inline-list/types.js +2 -0
  76. package/dist/plugins/foreign-inline-list/types.js.map +1 -0
  77. package/dist/plugins/import-export/types.d.ts +3 -0
  78. package/dist/plugins/import-export/types.d.ts.map +1 -0
  79. package/dist/plugins/import-export/types.js +2 -0
  80. package/dist/plugins/import-export/types.js.map +1 -0
  81. package/dist/plugins/rich-editor/custom/async-queue.d.ts +8 -0
  82. package/dist/plugins/rich-editor/custom/async-queue.d.ts.map +1 -0
  83. package/dist/plugins/rich-editor/custom/async-queue.js +29 -0
  84. package/dist/plugins/rich-editor/custom/async-queue.js.map +1 -0
  85. package/dist/plugins/rich-editor/dist/custom/async-queue.d.ts +8 -0
  86. package/dist/plugins/rich-editor/dist/custom/async-queue.d.ts.map +1 -0
  87. package/dist/plugins/rich-editor/dist/custom/async-queue.js +29 -0
  88. package/dist/plugins/rich-editor/dist/custom/async-queue.js.map +1 -0
  89. package/dist/plugins/rich-editor/types.d.ts +153 -0
  90. package/dist/plugins/rich-editor/types.d.ts.map +1 -0
  91. package/dist/plugins/rich-editor/types.js +16 -0
  92. package/dist/plugins/rich-editor/types.js.map +1 -0
  93. package/dist/plugins/two-factors-auth/types.d.ts +18 -0
  94. package/dist/plugins/two-factors-auth/types.d.ts.map +1 -0
  95. package/dist/plugins/two-factors-auth/types.js +2 -0
  96. package/dist/plugins/two-factors-auth/types.js.map +1 -0
  97. package/dist/plugins/upload/types.d.ts +132 -0
  98. package/dist/plugins/upload/types.d.ts.map +1 -0
  99. package/dist/plugins/upload/types.js +2 -0
  100. package/dist/plugins/upload/types.js.map +1 -0
  101. package/dist/servers/express.d.ts +18 -0
  102. package/dist/servers/express.d.ts.map +1 -0
  103. package/dist/servers/express.js +30 -42
  104. package/dist/servers/express.js.map +1 -0
  105. package/dist/spa/index.html +2 -2
  106. package/dist/spa/package-lock.json +87 -1
  107. package/dist/spa/package.json +4 -1
  108. package/dist/spa/src/App.vue +154 -50
  109. package/dist/spa/src/components/AcceptModal.vue +1 -1
  110. package/dist/spa/src/components/Breadcrumbs.vue +1 -1
  111. package/dist/spa/src/components/CustomDatePicker.vue +1 -1
  112. package/dist/spa/src/components/CustomDateRangePicker.vue +1 -1
  113. package/dist/spa/src/components/CustomRangePicker.vue +9 -5
  114. package/dist/spa/src/components/Dropdown.vue +4 -4
  115. package/dist/spa/src/components/Filters.vue +2 -2
  116. package/dist/spa/src/components/MenuLink.vue +3 -0
  117. package/dist/spa/src/components/ResourceForm.vue +67 -36
  118. package/dist/spa/src/components/ResourceListTable.vue +216 -144
  119. package/dist/spa/src/components/SkeleteLoader.vue +4 -4
  120. package/dist/spa/src/components/Toast.vue +3 -2
  121. package/dist/spa/src/components/ValueRenderer.vue +81 -6
  122. package/dist/spa/src/composables/useFrontendApi.ts +1 -1
  123. package/dist/spa/src/composables/useStores.ts +18 -14
  124. package/dist/spa/src/index.scss +4 -0
  125. package/{spa → dist/spa}/src/renderers/CompactUUID.vue +4 -4
  126. package/{spa → dist/spa}/src/renderers/CountryFlag.vue +2 -2
  127. package/dist/spa/src/router/index.ts +4 -8
  128. package/dist/spa/src/spa_types/core.ts +2 -0
  129. package/dist/spa/src/stores/core.ts +6 -2
  130. package/dist/spa/src/stores/filters.ts +15 -10
  131. package/dist/spa/src/stores/toast.ts +22 -6
  132. package/dist/spa/src/types/AdminForthConfig.ts +340 -55
  133. package/dist/spa/src/types/FrontendAPI.ts +52 -30
  134. package/dist/spa/src/utils.ts +59 -2
  135. package/dist/spa/src/views/CreateView.vue +15 -4
  136. package/dist/spa/src/views/EditView.vue +20 -7
  137. package/dist/spa/src/views/ListView.vue +132 -38
  138. package/dist/spa/src/views/LoginView.vue +50 -18
  139. package/dist/spa/src/views/ShowView.vue +25 -15
  140. package/dist/types/AdminForthConfig.d.ts +1619 -0
  141. package/dist/types/AdminForthConfig.d.ts.map +1 -0
  142. package/dist/types/AdminForthConfig.js +1 -0
  143. package/dist/types/AdminForthConfig.js.map +1 -0
  144. package/{types/FrontendAPI.ts → dist/types/FrontendAPI.d.ts} +27 -52
  145. package/dist/types/FrontendAPI.d.ts.map +1 -0
  146. package/dist/types/FrontendAPI.js +1 -0
  147. package/dist/types/FrontendAPI.js.map +1 -0
  148. package/package.json +16 -6
  149. package/auth.ts +0 -140
  150. package/basePlugin.ts +0 -70
  151. package/dataConnectors/baseConnector.ts +0 -216
  152. package/dataConnectors/clickhouse.ts +0 -338
  153. package/dataConnectors/mongo.ts +0 -202
  154. package/dataConnectors/postgres.ts +0 -306
  155. package/dataConnectors/sqlite.ts +0 -254
  156. package/index.ts +0 -428
  157. package/modules/codeInjector.ts +0 -736
  158. package/modules/configValidator.ts +0 -571
  159. package/modules/operationalResource.ts +0 -98
  160. package/modules/restApi.ts +0 -718
  161. package/modules/styleGenerator.ts +0 -55
  162. package/modules/styles.ts +0 -126
  163. package/modules/utils.ts +0 -472
  164. package/servers/express.ts +0 -259
  165. package/spa/.eslintrc.cjs +0 -14
  166. package/spa/README.md +0 -39
  167. package/spa/env.d.ts +0 -1
  168. package/spa/index.html +0 -23
  169. package/spa/package-lock.json +0 -4602
  170. package/spa/package.json +0 -51
  171. package/spa/postcss.config.js +0 -6
  172. package/spa/public/assets/favicon.png +0 -0
  173. package/spa/src/App.vue +0 -418
  174. package/spa/src/assets/base.css +0 -2
  175. package/spa/src/assets/logo.svg +0 -19
  176. package/spa/src/components/AcceptModal.vue +0 -45
  177. package/spa/src/components/Breadcrumbs.vue +0 -41
  178. package/spa/src/components/BreadcrumbsWithButtons.vue +0 -26
  179. package/spa/src/components/CustomDatePicker.vue +0 -176
  180. package/spa/src/components/CustomDateRangePicker.vue +0 -218
  181. package/spa/src/components/CustomRangePicker.vue +0 -156
  182. package/spa/src/components/Dropdown.vue +0 -168
  183. package/spa/src/components/Filters.vue +0 -222
  184. package/spa/src/components/HelloWorld.vue +0 -17
  185. package/spa/src/components/MenuLink.vue +0 -27
  186. package/spa/src/components/ResourceForm.vue +0 -290
  187. package/spa/src/components/ResourceListTable.vue +0 -466
  188. package/spa/src/components/SingleSkeletLoader.vue +0 -13
  189. package/spa/src/components/SkeleteLoader.vue +0 -23
  190. package/spa/src/components/Toast.vue +0 -78
  191. package/spa/src/components/ValueRenderer.vue +0 -114
  192. package/spa/src/components/icons/IconCalendar.vue +0 -5
  193. package/spa/src/components/icons/IconCommunity.vue +0 -7
  194. package/spa/src/components/icons/IconDocumentation.vue +0 -7
  195. package/spa/src/components/icons/IconEcosystem.vue +0 -7
  196. package/spa/src/components/icons/IconSupport.vue +0 -7
  197. package/spa/src/components/icons/IconTime.vue +0 -5
  198. package/spa/src/components/icons/IconTooling.vue +0 -19
  199. package/spa/src/composables/useFrontendApi.ts +0 -26
  200. package/spa/src/composables/useStores.ts +0 -131
  201. package/spa/src/index.scss +0 -31
  202. package/spa/src/main.ts +0 -18
  203. package/spa/src/router/index.ts +0 -59
  204. package/spa/src/spa_types/core.ts +0 -53
  205. package/spa/src/stores/core.ts +0 -148
  206. package/spa/src/stores/filters.ts +0 -27
  207. package/spa/src/stores/modal.ts +0 -48
  208. package/spa/src/stores/toast.ts +0 -31
  209. package/spa/src/stores/user.ts +0 -72
  210. package/spa/src/utils.ts +0 -160
  211. package/spa/src/views/CreateView.vue +0 -167
  212. package/spa/src/views/EditView.vue +0 -170
  213. package/spa/src/views/ListView.vue +0 -352
  214. package/spa/src/views/LoginView.vue +0 -192
  215. package/spa/src/views/ResourceParent.vue +0 -17
  216. package/spa/src/views/ShowView.vue +0 -186
  217. package/spa/tailwind.config.js +0 -17
  218. package/spa/tsconfig.app.json +0 -14
  219. package/spa/tsconfig.json +0 -11
  220. package/spa/tsconfig.node.json +0 -19
  221. package/spa/vite.config.ts +0 -56
  222. package/tsconfig.json +0 -112
  223. package/types/AdminForthConfig.ts +0 -1762
  224. /package/{spa → dist/spa}/src/components/ThreeDotsMenu.vue +0 -0
@@ -1,27 +0,0 @@
1
- import { ref, type Ref } from 'vue';
2
- import { defineStore } from 'pinia';
3
-
4
- export const useFiltersStore = defineStore('filters', () => {
5
- const filters: Ref<any[]> = ref([]);
6
- const sort: Ref<any> = ref({});
7
-
8
- const setSort = (s: any) => {
9
- sort.value = s;
10
- }
11
- const getSort = () => {
12
- return sort.value;
13
- }
14
- const setFilter = (filter: any) => {
15
- filters.value.push(filter);
16
- }
17
- const setFilters = (f: any) => {
18
- filters.value = f;
19
- }
20
- const getFilters = () => {
21
- return filters.value;
22
- }
23
- const clearFilters = () => {
24
- filters.value = [];
25
- }
26
- return {setFilter, getFilters, clearFilters, filters, setFilters, setSort, getSort}
27
- })
@@ -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,31 +0,0 @@
1
- import { ref, watch, type Ref } from 'vue'
2
- import { defineStore } from 'pinia'
3
- import { v1 as uuid } from 'uuid';
4
- import { useRoute } from 'vue-router';
5
-
6
-
7
-
8
- export const useToastStore = defineStore('toast', () => {
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
- });
26
- };
27
- const removeToast = (toast: { id: string }) => {
28
- toasts.value = toasts.value.filter((t) => t.id !== toast.id);
29
- };
30
- return { toasts, addToast, removeToast };
31
- });
@@ -1,72 +0,0 @@
1
- import { ref } from 'vue';
2
- import { defineStore } from 'pinia';
3
- import { callAdminForthApi } from '@/utils';
4
- import { initFlowbite } from 'flowbite'
5
- import { useRouter } from 'vue-router';
6
- import { useCoreStore } from './core';
7
- import router from '@/router';
8
-
9
-
10
-
11
- export const useUserStore = defineStore('user', () => {
12
- const isAuthorized = ref(false);
13
-
14
- function authorize() {
15
- isAuthorized.value = true;
16
- localStorage.setItem('isAuthorized', 'true');
17
- }
18
-
19
- function unauthorize() {
20
- isAuthorized.value = false;
21
- localStorage.setItem('isAuthorized', 'false');
22
- }
23
-
24
- async function finishLogin() {
25
- const coreStore = useCoreStore();
26
- authorize(); // TODO not sure we need this approach with localStorage
27
- await router.push('/');
28
- await router.isReady();
29
- await coreStore.fetchMenuAndResource();
30
- setTimeout(() => {
31
- initFlowbite();
32
- });
33
- }
34
-
35
- async function logout() {
36
- await callAdminForthApi({
37
- path: '/logout',
38
- method: 'POST',
39
- });
40
- unauthorize();
41
- }
42
-
43
- // async function checkAuth( skipApiCall = false){
44
- // console.log('checkAuth', isAuthorized.value, skipApiCall)
45
- // if(isAuthorized.value) {
46
- // return true}
47
- // else {
48
- // if(skipApiCall) return false;
49
- // const resp = await callAdminForthApi({
50
- // path: '/check_auth',
51
- // method: 'POST',
52
- // });
53
- // if (resp.status !== 401) {
54
- // authorize();
55
- // return true;
56
- // }
57
- // else {
58
- // unauthorize();
59
- // return false;}
60
- // }
61
-
62
- // }
63
-
64
- return {
65
- isAuthorized,
66
- authorize,
67
- unauthorize,
68
- logout,
69
- finishLogin
70
- }
71
-
72
- });
package/spa/src/utils.ts DELETED
@@ -1,160 +0,0 @@
1
- import { onMounted, ref, resolveComponent } from 'vue';
2
- import type { CoreConfig } from './spa_types/core';
3
- import type { ValidationObject } from './types/AdminForthConfig';
4
-
5
-
6
- import router from "./router";
7
- import { useCoreStore } from './stores/core';
8
- import { useUserStore } from './stores/user';
9
- import { Dropdown } from 'flowbite';
10
-
11
-
12
- export async function callApi({path, method, body=undefined}: {
13
- path: string, method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'
14
- body?: any
15
- }): Promise<any> {
16
- const options = {
17
- method,
18
- headers: {
19
- 'Content-Type': 'application/json',
20
- },
21
- body: JSON.stringify(body),
22
- };
23
- const fullPath = `${import.meta.env.VITE_ADMINFORTH_PUBLIC_PATH || ''}${path}`;
24
- const r = await fetch(fullPath, options);
25
- if (r.status == 401 ) {
26
- useUserStore().unauthorize();
27
- router.push({ name: 'login' });
28
- return null;
29
- }
30
- return await r.json();
31
- }
32
-
33
- export async function callAdminForthApi({ path, method, body=undefined }: {
34
- path: string,
35
- method: 'GET' | 'POST' | 'PUT' | 'DELETE',
36
- body?: any
37
- }) {
38
- try {
39
- return callApi({path: `/adminapi/v1${path}`, method, body} );
40
- } catch (e) {
41
- console.error('error', e);
42
- return { error: `Unexpected error: ${e}` };
43
- }
44
- }
45
-
46
- export function getCustomComponent({ file, meta }: { file: string, meta: any }) {
47
- const name = file.replace(/@/g, '').replace(/\./g, '').replace(/\//g, '');
48
- return resolveComponent(name);
49
- }
50
-
51
- export function getIcon(icon: string) {
52
- // icon format is "feather:icon-name". We need to get IconName in pascal case
53
- if (!icon.includes(':')) {
54
- throw new Error('Icon name should be in format "icon-set:icon-name"');
55
- }
56
- const [iconSet, iconName] = icon.split(':');
57
- const compName = 'Icon' + iconName.split('-').map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join('');
58
- return resolveComponent(compName);
59
- }
60
-
61
- export const loadFile = (file: string) => {
62
- if (file.startsWith('http')) {
63
- return file;
64
- }
65
- let path;
66
- let baseUrl = '';
67
- if (file.startsWith('@/')) {
68
- path = file.replace('@/', '');
69
- baseUrl = new URL(`./${path}`, import.meta.url).href;
70
- } else if (file.startsWith('@@/')) {
71
- path = file.replace('@@/', '');
72
- baseUrl = new URL(`./custom/${path}`, import.meta.url).href;
73
- } else {
74
- baseUrl = new URL(`./${file}`, import.meta.url).href;
75
- }
76
- return baseUrl;
77
- }
78
-
79
- export function checkEmptyValues(value: any, viewType: 'show' | 'list' ) {
80
- const config: CoreConfig | {} = useCoreStore().config;
81
- let emptyFieldPlaceholder = '';
82
- if (config.emptyFieldPlaceholder) {
83
- if(typeof config.emptyFieldPlaceholder === 'string') {
84
- emptyFieldPlaceholder = config.emptyFieldPlaceholder;
85
- } else {
86
- emptyFieldPlaceholder = config.emptyFieldPlaceholder?.[viewType] || '';
87
- }
88
- if (value === null || value === undefined || value === '') {
89
- return emptyFieldPlaceholder;
90
- }
91
- }
92
- return value;
93
- }
94
-
95
- export function checkAcessByAllowedActions(allowedActions:any, action:any ) {
96
- if (!allowedActions) {
97
- console.warn('allowedActions not set');
98
- return;
99
- }
100
- if(allowedActions[action] === false) {
101
- console.warn(`Action ${action} is not allowed`);
102
- router.back();
103
- }
104
- }
105
-
106
- export function initThreeDotsDropdown() {
107
- const threeDotsDropdown: HTMLElement | null = document.querySelector('#listThreeDotsDropdown');
108
- if (threeDotsDropdown) {
109
- // this resource has three dots dropdown
110
- const dd = new Dropdown(
111
- threeDotsDropdown,
112
- document.querySelector('[data-dropdown-toggle="listThreeDotsDropdown"]') as HTMLElement,
113
- );
114
- window.adminforth.list.closeThreeDotsDropdown = () => {
115
- dd.hide();
116
- }
117
- }
118
- }
119
-
120
- export function applyRegexValidation(value: any, validation: ValidationObject[] | undefined) {
121
-
122
- if ( validation?.length ) {
123
- const validationArray = validation;
124
- for (let i = 0; i < validationArray.length; i++) {
125
- if (validationArray[i].regExp) {
126
- let flags = '';
127
- if (validationArray[i].caseSensitive) {
128
- flags += 'i';
129
- }
130
- if (validationArray[i].multiline) {
131
- flags += 'm';
132
- }
133
- if (validationArray[i].global) {
134
- flags += 'g';
135
- }
136
-
137
- const regExp = new RegExp(validationArray[i].regExp, flags);
138
- if (value === undefined || value === null) {
139
- value = '';
140
- }
141
- let valueS = `${value}`;
142
-
143
- if (!regExp.test(valueS)) {
144
- return validationArray[i].message;
145
- }
146
- }
147
- }
148
- }
149
- }
150
-
151
- export function currentQuery() {
152
- return router.currentRoute.value.query;
153
- }
154
-
155
- export function setQuery(query: any) {
156
- const currentQuery = { ...router.currentRoute.value.query, ...query };
157
- router.replace({
158
- query: currentQuery,
159
- });
160
- }
@@ -1,167 +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-lightPrimary 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
22
- @click="saveRecord"
23
- 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"
24
- :disabled="saving || (validating && !isValid)"
25
- >
26
- <svg v-if="saving" x
27
- 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>
28
-
29
- <IconFloppyDiskSolid v-else class="w-4 h-4 mr-1" />
30
- Save
31
- </button>
32
-
33
- <ThreeDotsMenu
34
- :threeDotsDropdownItems="coreStore.resourceOptions?.pageInjections?.create?.threeDotsDropdownItems"
35
- ></ThreeDotsMenu>
36
-
37
- </BreadcrumbsWithButtons>
38
-
39
- <component
40
- v-for="c in coreStore?.resourceOptions?.pageInjections?.create?.afterBreadcrumbs || []"
41
- :is="getCustomComponent(c)"
42
- :meta="c.meta"
43
- :record="coreStore.record"
44
- :resource="coreStore.resource"
45
- :adminUser="coreStore.adminUser"
46
- />
47
-
48
- <SingleSkeletLoader v-if="loading"></SingleSkeletLoader>
49
-
50
-
51
- <ResourceForm
52
- v-else
53
- :record="record"
54
- :resource="coreStore.resource"
55
- @update:record="onUpdateRecord"
56
- @update:isValid="isValid = $event"
57
- :validating="validating"
58
- :source="'create'"
59
- >
60
- </ResourceForm>
61
-
62
- <component
63
- v-for="c in coreStore?.resourceOptions?.pageInjections?.create?.bottom || []"
64
- :is="getCustomComponent(c)"
65
- :meta="c.meta"
66
- :record="coreStore.record"
67
- :resource="coreStore.resource"
68
- :adminUser="coreStore.adminUser"
69
- />
70
-
71
- </div>
72
- </template>
73
-
74
-
75
- <script setup>
76
-
77
- import BreadcrumbsWithButtons from '@/components/BreadcrumbsWithButtons.vue';
78
- import ResourceForm from '@/components/ResourceForm.vue';
79
- import SingleSkeletLoader from '@/components/SingleSkeletLoader.vue';
80
- import { useCoreStore } from '@/stores/core';
81
- import { callAdminForthApi, getCustomComponent,checkAcessByAllowedActions, initThreeDotsDropdown } from '@/utils';
82
- import { IconFloppyDiskSolid } from '@iconify-prerendered/vue-flowbite';
83
- import { onMounted, ref, watch } from 'vue';
84
- import { useRoute, useRouter } from 'vue-router';
85
- import { computed } from 'vue';
86
- import { showErrorTost } from '@/composables/useFrontendApi';
87
- import ThreeDotsMenu from '@/components/ThreeDotsMenu.vue';
88
-
89
-
90
- const isValid = ref(false);
91
- const validating = ref(false);
92
-
93
- const loading = ref(false);
94
- const saving = ref(false);
95
-
96
- const route = useRoute();
97
- const router = useRouter();
98
-
99
- const record = ref({});
100
-
101
- const coreStore = useCoreStore();
102
-
103
- const initalValues = computed(() => {
104
- if (!route.query.values) {
105
- return {};
106
- }
107
- return JSON.parse(decodeURIComponent(route.query.values));
108
- });
109
-
110
-
111
-
112
- async function onUpdateRecord(newRecord) {
113
- console.log('newRecord', newRecord);
114
- record.value = newRecord;
115
- }
116
-
117
- onMounted(async () => {
118
- loading.value = true;
119
- record.value = initalValues.value;
120
- await coreStore.fetchResourceFull({
121
- resourceId: route.params.resourceId
122
- });
123
- loading.value = false;
124
- checkAcessByAllowedActions(coreStore.resourceOptions.allowedActions,'create');
125
- initThreeDotsDropdown();
126
- });
127
-
128
- async function saveRecord() {
129
- console.log('saveRecord isValid', isValid.value);
130
- if (!isValid.value) {
131
- validating.value = true;
132
- return;
133
- } else {
134
- validating.value = false;
135
- }
136
- saving.value = true;
137
- const response = await callAdminForthApi({
138
- method: 'POST',
139
- path: `/create_record`,
140
- body: {
141
- resourceId: route.params.resourceId,
142
- record: record.value,
143
- },
144
- });
145
- if (response.error) {
146
- showErrorTost(response.error);
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
- window.adminforth.alert({
160
- message: 'Record created successfully',
161
- variant: 'success'
162
- });
163
- }
164
- }
165
-
166
-
167
- </script>
@@ -1,170 +0,0 @@
1
- <template>
2
- <div class="relative">
3
- <component
4
- v-for="c in coreStore?.resourceOptions?.pageInjections?.edit?.beforeBreadcrumbs || []"
5
- :is="getCustomComponent(c)"
6
- :meta="c.meta"
7
- :record="editableRecord"
8
- :resource="coreStore.resource"
9
- :adminUser="coreStore.adminUser"
10
- />
11
-
12
- <BreadcrumbsWithButtons>
13
- <!-- save and cancle -->
14
- <button @click="$router.back()"
15
- class="flex items-center py-1 px-3 me-2 text-sm font-medium text-gray-900 rounded-default focus:outline-none bg-white rounded border border-gray-300 hover:bg-gray-100 hover:text-lightPrimary 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"
16
- >
17
- Cancel
18
- </button>
19
-
20
- <button
21
- @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
- <IconFloppyDiskSolid class="w-4 h-4" />
26
- Save
27
- </button>
28
-
29
- <ThreeDotsMenu
30
- :threeDotsDropdownItems="coreStore.resourceOptions?.pageInjections?.edit?.threeDotsDropdownItems"
31
- ></ThreeDotsMenu>
32
-
33
- </BreadcrumbsWithButtons>
34
-
35
- <component
36
- v-for="c in coreStore?.resourceOptions?.pageInjections?.edit?.afterBreadcrumbs || []"
37
- :is="getCustomComponent(c)"
38
- :meta="c.meta"
39
- :record="coreStore.record"
40
- :resource="coreStore.resource"
41
- :adminUser="coreStore.adminUser"
42
- />
43
-
44
- <SingleSkeletLoader v-if="loading"></SingleSkeletLoader>
45
-
46
- <ResourceForm
47
- v-else
48
- :record="editableRecord"
49
- :resource="coreStore.resource"
50
- :adminUser="coreStore.adminUser"
51
- @update:record="onUpdateRecord"
52
- @update:isValid="isValid = $event"
53
- :validating="validating"
54
- :source="'edit'"
55
- >
56
- </ResourceForm>
57
-
58
- <component
59
- v-for="c in coreStore?.resourceOptions?.pageInjections?.edit?.bottom || []"
60
- :is="getCustomComponent(c)"
61
- :meta="c.meta"
62
- :record="coreStore.record"
63
- :resource="coreStore.resource"
64
- :adminUser="coreStore.adminUser"
65
- />
66
-
67
- </div>
68
- </template>
69
-
70
-
71
- <script setup>
72
-
73
- import BreadcrumbsWithButtons from '@/components/BreadcrumbsWithButtons.vue';
74
- import ResourceForm from '@/components/ResourceForm.vue';
75
- import SingleSkeletLoader from '@/components/SingleSkeletLoader.vue';
76
- import { useCoreStore } from '@/stores/core';
77
- import { callAdminForthApi, getCustomComponent,checkAcessByAllowedActions, initThreeDotsDropdown } from '@/utils';
78
- import { IconFloppyDiskSolid } from '@iconify-prerendered/vue-flowbite';
79
- import { computed, onMounted, ref } from 'vue';
80
- import { useRoute, useRouter } from 'vue-router';
81
- import { showErrorTost } from '@/composables/useFrontendApi';
82
- import ThreeDotsMenu from '@/components/ThreeDotsMenu.vue';
83
-
84
-
85
- const coreStore = useCoreStore();
86
-
87
- const isValid = ref(false);
88
- const validating = ref(false);
89
-
90
- const route = useRoute();
91
- const router = useRouter();
92
-
93
- const loading = ref(false);
94
-
95
- const saving = ref(false);
96
-
97
- const record = ref({});
98
-
99
- async function onUpdateRecord(newRecord) {
100
- record.value = newRecord;
101
- }
102
-
103
- const editableRecord = computed(() => {
104
- const newRecord = { ...coreStore.record };
105
- if (!coreStore.resource) {
106
- return {};
107
- }
108
- coreStore.resource.columns.forEach(column => {
109
- if (column.foreignResource) {
110
- newRecord[column.name] = newRecord[column.name]?.pk
111
- }
112
- });
113
- return newRecord;
114
- })
115
-
116
- onMounted(async () => {
117
- loading.value = true;
118
-
119
- await coreStore.fetchResourceFull({
120
- resourceId: route.params.resourceId
121
- });
122
- initThreeDotsDropdown();
123
-
124
- await coreStore.fetchRecord({
125
- resourceId: route.params.resourceId,
126
- primaryKey: route.params.primaryKey,
127
- });
128
- checkAcessByAllowedActions(coreStore.resourceOptions.allowedActions,'edit');
129
- loading.value = false;
130
- });
131
-
132
- async function saveRecord() {
133
- if (!isValid.value) {
134
- validating.value = true;
135
- return;
136
- } else {
137
- validating.value = false;
138
- }
139
-
140
- saving.value = true;
141
- const updates = {};
142
- for (const key in record.value) {
143
- if (record.value[key] !== coreStore.record[key]) {
144
- updates[key] = record.value[key];
145
- }
146
- }
147
-
148
- const resp = await callAdminForthApi({
149
- method: 'POST',
150
- path: `/update_record`,
151
- body: {
152
- resourceId: route.params.resourceId,
153
- recordId: route.params.primaryKey,
154
- record: updates,
155
- },
156
- });
157
- if (resp.error) {
158
- showErrorTost(resp.error);
159
- } else {
160
- window.adminforth.alert({
161
- message: 'Record updated successfully',
162
- variant: 'success',
163
- timeout: 400000
164
- });
165
- }
166
- saving.value = false;
167
- router.push({ name: 'resource-show', params: { resourceId: route.params.resourceId, primaryKey: coreStore.record[coreStore.primaryKey] } });
168
- }
169
-
170
- </script>