adminforth 1.2.95 → 1.2.98

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 (101) hide show
  1. package/dist/index.js +2 -1
  2. package/dist/modules/restApi.js +27 -29
  3. package/dist/spa/index.html +4 -4
  4. package/dist/spa/package-lock.json +421 -6
  5. package/dist/spa/package.json +10 -2
  6. package/dist/spa/src/App.vue +236 -94
  7. package/dist/spa/src/assets/base.css +2 -0
  8. package/dist/spa/src/assets/logo.svg +19 -1
  9. package/dist/spa/src/components/AcceptModal.vue +3 -10
  10. package/dist/spa/src/components/Breadcrumbs.vue +3 -2
  11. package/dist/spa/src/components/BreadcrumbsWithButtons.vue +1 -1
  12. package/dist/spa/src/components/CustomDatePicker.vue +25 -10
  13. package/dist/spa/src/components/CustomDateRangePicker.vue +14 -5
  14. package/dist/spa/src/components/Dropdown.vue +19 -5
  15. package/dist/spa/src/components/Filters.vue +103 -38
  16. package/dist/spa/src/components/MenuLink.vue +3 -3
  17. package/dist/spa/src/components/ResourceForm.vue +205 -116
  18. package/dist/spa/{spa/src → src}/components/ResourceListTable.vue +6 -3
  19. package/dist/spa/{spa/src → src}/components/Toast.vue +9 -3
  20. package/dist/spa/src/components/ValueRenderer.vue +30 -8
  21. package/dist/spa/src/index.scss +2 -1
  22. package/dist/spa/src/main.ts +2 -2
  23. package/dist/spa/src/router/index.ts +29 -19
  24. package/dist/spa/src/stores/core.ts +65 -59
  25. package/dist/spa/src/stores/modal.ts +13 -3
  26. package/dist/spa/src/types/AdminForthConfig.ts +1477 -0
  27. package/dist/spa/src/types/FrontendAPI.ts +121 -0
  28. package/dist/spa/src/utils.ts +69 -10
  29. package/dist/spa/src/views/CreateView.vue +69 -16
  30. package/dist/spa/src/views/EditView.vue +68 -14
  31. package/dist/spa/src/views/ListView.vue +100 -371
  32. package/dist/spa/src/views/LoginView.vue +67 -29
  33. package/dist/spa/src/views/ResourceParent.vue +1 -2
  34. package/dist/spa/src/views/ShowView.vue +116 -25
  35. package/dist/spa/tailwind.config.js +8 -3
  36. package/dist/spa/vite.config.ts +13 -0
  37. package/index.ts +2 -1
  38. package/modules/restApi.ts +31 -31
  39. package/package.json +1 -1
  40. package/dist/spa/.vscode/extensions.json +0 -6
  41. package/dist/spa/public/favicon.ico +0 -0
  42. package/dist/spa/spa/.eslintrc.cjs +0 -14
  43. package/dist/spa/spa/.vscode/extensions.json +0 -6
  44. package/dist/spa/spa/README.md +0 -39
  45. package/dist/spa/spa/env.d.ts +0 -1
  46. package/dist/spa/spa/index.html +0 -23
  47. package/dist/spa/spa/package-lock.json +0 -4573
  48. package/dist/spa/spa/package.json +0 -49
  49. package/dist/spa/spa/postcss.config.js +0 -6
  50. package/dist/spa/spa/public/favicon.ico +0 -0
  51. package/dist/spa/spa/src/App.vue +0 -314
  52. package/dist/spa/spa/src/assets/base.css +0 -0
  53. package/dist/spa/spa/src/assets/logo.svg +0 -19
  54. package/dist/spa/spa/src/components/AcceptModal.vue +0 -45
  55. package/dist/spa/spa/src/components/Breadcrumbs.vue +0 -40
  56. package/dist/spa/spa/src/components/BreadcrumbsWithButtons.vue +0 -26
  57. package/dist/spa/spa/src/components/CustomDatePicker.vue +0 -174
  58. package/dist/spa/spa/src/components/CustomDateRangePicker.vue +0 -218
  59. package/dist/spa/spa/src/components/Dropdown.vue +0 -168
  60. package/dist/spa/spa/src/components/Filters.vue +0 -222
  61. package/dist/spa/spa/src/components/HelloWorld.vue +0 -17
  62. package/dist/spa/spa/src/components/MenuLink.vue +0 -24
  63. package/dist/spa/spa/src/components/ResourceForm.vue +0 -289
  64. package/dist/spa/spa/src/components/SingleSkeletLoader.vue +0 -13
  65. package/dist/spa/spa/src/components/ValueRenderer.vue +0 -66
  66. package/dist/spa/spa/src/components/icons/IconCalendar.vue +0 -5
  67. package/dist/spa/spa/src/components/icons/IconCommunity.vue +0 -7
  68. package/dist/spa/spa/src/components/icons/IconDocumentation.vue +0 -7
  69. package/dist/spa/spa/src/components/icons/IconEcosystem.vue +0 -7
  70. package/dist/spa/spa/src/components/icons/IconSupport.vue +0 -7
  71. package/dist/spa/spa/src/components/icons/IconTime.vue +0 -5
  72. package/dist/spa/spa/src/components/icons/IconTooling.vue +0 -19
  73. package/dist/spa/spa/src/index.scss +0 -27
  74. package/dist/spa/spa/src/main.ts +0 -18
  75. package/dist/spa/spa/src/router/index.ts +0 -63
  76. package/dist/spa/spa/src/stores/core.ts +0 -144
  77. package/dist/spa/spa/src/stores/modal.ts +0 -48
  78. package/dist/spa/spa/src/utils.ts +0 -103
  79. package/dist/spa/spa/src/views/CreateView.vue +0 -156
  80. package/dist/spa/spa/src/views/EditView.vue +0 -157
  81. package/dist/spa/spa/src/views/HomeView.vue +0 -8
  82. package/dist/spa/spa/src/views/ListView.vue +0 -258
  83. package/dist/spa/spa/src/views/LoginView.vue +0 -143
  84. package/dist/spa/spa/src/views/ResourceParent.vue +0 -17
  85. package/dist/spa/spa/src/views/ShowView.vue +0 -184
  86. package/dist/spa/spa/tailwind.config.js +0 -17
  87. package/dist/spa/spa/tsconfig.app.json +0 -14
  88. package/dist/spa/spa/tsconfig.json +0 -11
  89. package/dist/spa/spa/tsconfig.node.json +0 -19
  90. package/dist/spa/spa/vite.config.ts +0 -56
  91. package/dist/spa/src/views/HomeView.vue +0 -8
  92. package/dist/types.js +0 -30
  93. /package/dist/spa/{spa/public → public}/assets/favicon.png +0 -0
  94. /package/dist/spa/{spa/src → src}/components/CustomRangePicker.vue +0 -0
  95. /package/dist/spa/{spa/src → src}/components/SkeleteLoader.vue +0 -0
  96. /package/dist/spa/{spa/src → src}/composables/useFrontendApi.ts +0 -0
  97. /package/dist/spa/{spa/src → src}/composables/useStores.ts +0 -0
  98. /package/dist/spa/{spa/src → src}/spa_types/core.ts +0 -0
  99. /package/dist/spa/{spa/src → src}/stores/filters.ts +0 -0
  100. /package/dist/spa/{spa/src → src}/stores/toast.ts +0 -0
  101. /package/dist/spa/{spa/src → src}/stores/user.ts +0 -0
@@ -1,96 +1,105 @@
1
1
  import { ref, computed } from 'vue'
2
2
  import { defineStore } from 'pinia'
3
3
  import { callAdminForthApi } from '@/utils';
4
- import router from '@/router';
5
-
6
- async function findHomepage(menu) {
7
- for (const item of menu) {
8
- if (item.homepage) {
9
- return item;
10
- }
11
- if (item.children) {
12
- const res = findHomepage(item.children);
13
- if (res) {
14
- return res;
15
- }
16
- }
17
- }
18
- return null;
19
- }
4
+ import type { AdminForthResource, AdminForthResourceColumn } from '@/types/AdminForthConfig';
5
+ import type { Ref } from 'vue'
20
6
 
21
7
  export const useCoreStore = defineStore('core', () => {
22
- const resourceById = ref([]);
8
+ const resourceById: Ref<Object> = ref({});
23
9
  const menu = ref([]);
24
10
  const config = ref({});
25
- const record = ref({});
26
- const resourceColumns = ref(null);
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);
27
22
  const resourceColumnsError = ref('');
28
23
  const resourceColumnsId = ref(null);
29
- const user = ref(null);
24
+ const adminUser = ref(null);
30
25
 
31
26
  async function fetchMenuAndResource() {
32
27
  const resp = await callAdminForthApi({
33
28
  path: '/get_base_config',
34
29
  method: 'GET',
35
30
  });
31
+ if(!resp){
32
+ return
33
+ }
36
34
  menu.value = resp.menu;
37
- resourceById.value = resp.resources.reduce((acc, resource) => {
35
+ resourceById.value = resp.resources.reduce((acc: Object, resource: AdminForthResource) => {
38
36
  acc[resource.resourceId] = resource;
39
37
  return acc;
40
38
  }, {});
41
39
  config.value = resp.config;
42
- user.value = resp.user;
43
-
44
- // find homepage:true in menu recuresively
45
- if (import.meta.env.DEV){
46
- return
47
- } else {
48
- const homepage = await findHomepage(menu.value);
49
- if (homepage) {
50
- if (homepage.resourceId) {
51
- // redirect to homepage
52
- router.push({ name: 'resource-list', params: { resourceId: homepage.resourceId } });
53
- } else {
54
- // redirect to path
55
- router.push(homepage.path);
56
- }
57
- }
58
- }
40
+ adminUser.value = resp.user;
41
+ console.log('🌍 AdminForth v', resp.version);
59
42
  }
60
43
 
61
44
  async function fetchRecord({ resourceId, primaryKey }) {
62
45
  record.value = null;
46
+
47
+ if (!resource.value) {
48
+ throw new Error('Columns not fetched yet');
49
+ }
63
50
 
64
- record.value = await callAdminForthApi({
65
- path: '/get_record',
51
+ const respData = await callAdminForthApi({
52
+ path: '/get_resource_data',
66
53
  method: 'POST',
67
54
  body: {
55
+ source: 'show',
68
56
  resourceId: resourceId,
69
- primaryKey: primaryKey,
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
70
67
  }
71
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
+
72
81
  }
73
82
 
74
- async function fetchColumns({ resourceId }) {
75
- if (resourceColumnsId.value === resourceId && resourceColumns.value) {
83
+ async function fetchResourceFull({ resourceId }: { resourceId: string }) {
84
+ if (resourceColumnsId.value === resourceId && resource.value) {
76
85
  // already fetched
77
86
  return;
78
87
  }
79
88
  resourceColumnsId.value = resourceId;
80
- resourceColumns.value = null;
81
89
  resourceColumnsError.value = '';
82
90
  const res = await callAdminForthApi({
83
- path: '/get_resource_columns',
91
+ path: '/get_resource',
84
92
  method: 'POST',
85
93
  body: {
86
94
  resourceId,
87
95
  }
88
- }
89
- );
96
+ });
90
97
  if (res.error) {
91
98
  resourceColumnsError.value = res.error;
92
99
  } else {
93
- resourceColumns.value = res.resource.columns;
100
+ resourceById.value[resourceId] = res.resource;
101
+ resource.value = res.resource;
102
+ resourceOptions.value = res.resource.options;
94
103
  }
95
104
  }
96
105
 
@@ -102,21 +111,16 @@ export const useCoreStore = defineStore('core', () => {
102
111
  config.value = {...config.value, ...res};
103
112
  }
104
113
 
105
- async function logout() {
106
- await callAdminForthApi({
107
- path: '/logout',
108
- method: 'POST',
109
- });
110
- }
114
+
111
115
 
112
116
  const username = computed(() => {
113
117
  const usernameField = config.value.usernameField;
114
- return user.value && user.value[usernameField];
118
+ return adminUser.value && adminUser.value[usernameField];
115
119
  });
116
120
 
117
121
  const userFullname = computed(() => {
118
122
  const userFullnameField = config.value.userFullnameField;
119
- return user.value && user.value[userFullnameField];
123
+ return adminUser.value && adminUser.value[userFullnameField];
120
124
  })
121
125
 
122
126
 
@@ -130,9 +134,11 @@ export const useCoreStore = defineStore('core', () => {
130
134
  fetchMenuAndResource,
131
135
  fetchRecord,
132
136
  record,
133
- resourceColumns,
134
- fetchColumns,
137
+ fetchResourceFull,
135
138
  resourceColumnsError,
136
- logout
139
+ resourceOptions,
140
+ resource,
141
+ adminUser,
142
+ resourceColumnsWithFilters
137
143
  }
138
144
  })
@@ -1,6 +1,12 @@
1
1
  import { ref } from 'vue'
2
2
  import { defineStore } from 'pinia'
3
- import { callAdminForthApi } from '@/utils';
3
+
4
+ type ModalContentType = {
5
+ title?: string;
6
+ content?: string;
7
+ acceptText?: string;
8
+ cancelText?: string;
9
+ }
4
10
 
5
11
 
6
12
  export const useModalStore = defineStore('modal', () => {
@@ -12,13 +18,17 @@ export const useModalStore = defineStore('modal', () => {
12
18
  });
13
19
  const isOpened = ref(false);
14
20
  const onAcceptFunction: any = ref(()=>{});
21
+ const onCancelFunction: any = ref(()=>{});
15
22
  function togleModal() {
16
23
  isOpened.value = !isOpened.value;
17
24
  }
18
25
  function setOnAcceptFunction(func: Function) {
19
26
  onAcceptFunction.value = func;
20
27
  }
21
- function setModalContent(content: string) {
28
+ function setOnCancelFunction(func: Function) {
29
+ onCancelFunction.value = func;
30
+ }
31
+ function setModalContent(content: ModalContentType) {
22
32
  modalContent.value = content;
23
33
  }
24
34
  function resetmodalState() {
@@ -33,6 +43,6 @@ export const useModalStore = defineStore('modal', () => {
33
43
 
34
44
  }
35
45
 
36
- return {isOpened, setModalContent, togleModal,modalContent, setOnAcceptFunction, onAcceptFunction,resetmodalState}
46
+ return {isOpened, setModalContent,onCancelFunction, togleModal,modalContent, setOnAcceptFunction, onAcceptFunction,resetmodalState,setOnCancelFunction}
37
47
 
38
48
  })