adminforth 1.2.87 → 1.2.89

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/modules/restApi.js +9 -0
  2. package/dist/spa/.vscode/extensions.json +6 -0
  3. package/dist/spa/index.html +4 -4
  4. package/dist/spa/package-lock.json +6 -421
  5. package/dist/spa/package.json +2 -10
  6. package/dist/spa/public/favicon.ico +0 -0
  7. package/dist/spa/spa/.eslintrc.cjs +14 -0
  8. package/dist/spa/spa/.vscode/extensions.json +6 -0
  9. package/dist/spa/spa/README.md +39 -0
  10. package/dist/spa/spa/env.d.ts +1 -0
  11. package/dist/spa/spa/index.html +23 -0
  12. package/dist/spa/spa/package-lock.json +4573 -0
  13. package/dist/spa/spa/package.json +49 -0
  14. package/dist/spa/spa/postcss.config.js +6 -0
  15. package/dist/spa/spa/public/favicon.ico +0 -0
  16. package/dist/spa/spa/src/App.vue +314 -0
  17. package/dist/spa/spa/src/assets/base.css +0 -0
  18. package/dist/spa/spa/src/assets/logo.svg +19 -0
  19. package/dist/spa/spa/src/components/AcceptModal.vue +45 -0
  20. package/dist/spa/spa/src/components/Breadcrumbs.vue +40 -0
  21. package/dist/spa/spa/src/components/BreadcrumbsWithButtons.vue +26 -0
  22. package/dist/spa/spa/src/components/CustomDatePicker.vue +174 -0
  23. package/dist/spa/spa/src/components/CustomDateRangePicker.vue +218 -0
  24. package/dist/spa/spa/src/components/Dropdown.vue +168 -0
  25. package/dist/spa/spa/src/components/Filters.vue +222 -0
  26. package/dist/spa/spa/src/components/HelloWorld.vue +17 -0
  27. package/dist/spa/spa/src/components/MenuLink.vue +24 -0
  28. package/dist/spa/spa/src/components/ResourceForm.vue +289 -0
  29. package/dist/spa/{src → spa/src}/components/ResourceListTable.vue +3 -6
  30. package/dist/spa/spa/src/components/SingleSkeletLoader.vue +13 -0
  31. package/dist/spa/{src → spa/src}/components/Toast.vue +3 -9
  32. package/dist/spa/spa/src/components/ValueRenderer.vue +66 -0
  33. package/dist/spa/spa/src/components/icons/IconCalendar.vue +5 -0
  34. package/dist/spa/spa/src/components/icons/IconCommunity.vue +7 -0
  35. package/dist/spa/spa/src/components/icons/IconDocumentation.vue +7 -0
  36. package/dist/spa/spa/src/components/icons/IconEcosystem.vue +7 -0
  37. package/dist/spa/spa/src/components/icons/IconSupport.vue +7 -0
  38. package/dist/spa/spa/src/components/icons/IconTime.vue +5 -0
  39. package/dist/spa/spa/src/components/icons/IconTooling.vue +19 -0
  40. package/dist/spa/spa/src/index.scss +27 -0
  41. package/dist/spa/spa/src/main.ts +18 -0
  42. package/dist/spa/spa/src/router/index.ts +63 -0
  43. package/dist/spa/spa/src/stores/core.ts +144 -0
  44. package/dist/spa/spa/src/stores/modal.ts +48 -0
  45. package/dist/spa/spa/src/utils.ts +103 -0
  46. package/dist/spa/spa/src/views/CreateView.vue +156 -0
  47. package/dist/spa/spa/src/views/EditView.vue +157 -0
  48. package/dist/spa/spa/src/views/HomeView.vue +8 -0
  49. package/dist/spa/spa/src/views/ListView.vue +258 -0
  50. package/dist/spa/spa/src/views/LoginView.vue +143 -0
  51. package/dist/spa/spa/src/views/ResourceParent.vue +17 -0
  52. package/dist/spa/spa/src/views/ShowView.vue +184 -0
  53. package/dist/spa/spa/tailwind.config.js +17 -0
  54. package/dist/spa/spa/tsconfig.app.json +14 -0
  55. package/dist/spa/spa/tsconfig.json +11 -0
  56. package/dist/spa/spa/tsconfig.node.json +19 -0
  57. package/dist/spa/spa/vite.config.ts +56 -0
  58. package/dist/spa/src/App.vue +94 -236
  59. package/dist/spa/src/assets/base.css +0 -2
  60. package/dist/spa/src/assets/logo.svg +1 -19
  61. package/dist/spa/src/components/AcceptModal.vue +10 -3
  62. package/dist/spa/src/components/Breadcrumbs.vue +2 -3
  63. package/dist/spa/src/components/BreadcrumbsWithButtons.vue +1 -1
  64. package/dist/spa/src/components/CustomDatePicker.vue +10 -25
  65. package/dist/spa/src/components/CustomDateRangePicker.vue +5 -14
  66. package/dist/spa/src/components/Dropdown.vue +5 -19
  67. package/dist/spa/src/components/Filters.vue +38 -103
  68. package/dist/spa/src/components/MenuLink.vue +3 -3
  69. package/dist/spa/src/components/ResourceForm.vue +116 -205
  70. package/dist/spa/src/components/ValueRenderer.vue +8 -30
  71. package/dist/spa/src/index.scss +1 -2
  72. package/dist/spa/src/main.ts +2 -2
  73. package/dist/spa/src/router/index.ts +19 -29
  74. package/dist/spa/src/stores/core.ts +59 -65
  75. package/dist/spa/src/stores/modal.ts +3 -13
  76. package/dist/spa/src/utils.ts +10 -69
  77. package/dist/spa/src/views/CreateView.vue +16 -69
  78. package/dist/spa/src/views/EditView.vue +14 -68
  79. package/dist/spa/src/views/HomeView.vue +8 -0
  80. package/dist/spa/src/views/ListView.vue +371 -100
  81. package/dist/spa/src/views/LoginView.vue +29 -67
  82. package/dist/spa/src/views/ResourceParent.vue +2 -1
  83. package/dist/spa/src/views/ShowView.vue +25 -116
  84. package/dist/spa/tailwind.config.js +3 -8
  85. package/dist/spa/vite.config.ts +0 -13
  86. package/dist/types.js +30 -0
  87. package/modules/restApi.ts +14 -1
  88. package/package.json +1 -1
  89. package/spa/src/components/MenuLink.vue +3 -0
  90. package/types/AdminForthConfig.ts +6 -0
  91. package/dist/spa/src/types/AdminForthConfig.ts +0 -1477
  92. package/dist/spa/src/types/FrontendAPI.ts +0 -121
  93. /package/dist/spa/{public → spa/public}/assets/favicon.png +0 -0
  94. /package/dist/spa/{src → spa/src}/components/CustomRangePicker.vue +0 -0
  95. /package/dist/spa/{src → spa/src}/components/SkeleteLoader.vue +0 -0
  96. /package/dist/spa/{src → spa/src}/composables/useFrontendApi.ts +0 -0
  97. /package/dist/spa/{src → spa/src}/composables/useStores.ts +0 -0
  98. /package/dist/spa/{src → spa/src}/spa_types/core.ts +0 -0
  99. /package/dist/spa/{src → spa/src}/stores/filters.ts +0 -0
  100. /package/dist/spa/{src → spa/src}/stores/toast.ts +0 -0
  101. /package/dist/spa/{src → spa/src}/stores/user.ts +0 -0
@@ -0,0 +1,66 @@
1
+ <template>
2
+ <div>
3
+ <span @click="(e)=>{e.stopPropagation()}" v-if="column.foreignResource">
4
+ <RouterLink v-if="record[column.name]" class="font-medium text-blue-600 dark:text-blue-500 hover:brightness-110"
5
+ :to="{ name: 'resource-show', params: { resourceId: column.foreignResource.resourceId, primaryKey: record[column.name].pk } }">
6
+ {{ record[column.name].label }}
7
+ </RouterLink>
8
+ <div v-else>
9
+ <span class="text-gray-400">-</span>
10
+ </div>
11
+ </span>
12
+
13
+ <span v-else-if="column.type === 'boolean'">
14
+ <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>
15
+ <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>
16
+ </span>
17
+ <span v-else-if="column.enum">
18
+ {{ checkEmptyValues(column.enum.find(e => e.value === record[column.name])?.label,route.meta.type) }}
19
+ </span>
20
+ <span v-else-if="column.type === 'datetime'" class="whitespace-nowrap">
21
+ {{ checkEmptyValues(formatDate(record[column.name]),route.meta.type) }}
22
+ </span>
23
+ <span v-else-if="column.type === 'richtext'">
24
+ <div v-html="protectAgainstXSS(record[column.name])"></div>
25
+ </span>
26
+ <span v-else>
27
+ {{ checkEmptyValues(record[column.name],route.meta.type) }}
28
+ </span>
29
+ </div>
30
+ </template>
31
+
32
+
33
+ <script setup>
34
+
35
+ import dayjs from 'dayjs';
36
+ import utc from 'dayjs/plugin/utc';
37
+ import timezone from 'dayjs/plugin/timezone';
38
+ import {checkEmptyValues} from '@/utils';
39
+ import { useRoute, useRouter } from 'vue-router';
40
+ import sanitizeHtml from 'sanitize-html';
41
+
42
+
43
+ import { useCoreStore } from '@/stores/core';
44
+
45
+ const coreStore = useCoreStore();
46
+ const route = useRoute();
47
+
48
+
49
+ dayjs.extend(utc);
50
+ dayjs.extend(timezone);
51
+
52
+ const props = defineProps({
53
+ column: Object,
54
+ record: Object
55
+ });
56
+
57
+ function protectAgainstXSS(value) {
58
+ return sanitizeHtml(value);
59
+ }
60
+
61
+
62
+ function formatDate(date) {
63
+ if (!date) return '';
64
+ return dayjs.utc(date).local().format(coreStore.config?.datesFormat || 'YYYY-MM-DD HH:mm:ss');
65
+ }
66
+ </script>
@@ -0,0 +1,5 @@
1
+ <template>
2
+ <svg aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 20">
3
+ <path d="M20 4a2 2 0 0 0-2-2h-2V1a1 1 0 0 0-2 0v1h-3V1a1 1 0 0 0-2 0v1H6V1a1 1 0 0 0-2 0v1H2a2 2 0 0 0-2 2v2h20V4ZM0 18a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V8H0v10Zm5-8h10a1 1 0 0 1 0 2H5a1 1 0 0 1 0-2Z"/>
4
+ </svg>
5
+ </template>
@@ -0,0 +1,7 @@
1
+ <template>
2
+ <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor">
3
+ <path
4
+ d="M15 4a1 1 0 1 0 0 2V4zm0 11v-1a1 1 0 0 0-1 1h1zm0 4l-.707.707A1 1 0 0 0 16 19h-1zm-4-4l.707-.707A1 1 0 0 0 11 14v1zm-4.707-1.293a1 1 0 0 0-1.414 1.414l1.414-1.414zm-.707.707l-.707-.707.707.707zM9 11v-1a1 1 0 0 0-.707.293L9 11zm-4 0h1a1 1 0 0 0-1-1v1zm0 4H4a1 1 0 0 0 1.707.707L5 15zm10-9h2V4h-2v2zm2 0a1 1 0 0 1 1 1h2a3 3 0 0 0-3-3v2zm1 1v6h2V7h-2zm0 6a1 1 0 0 1-1 1v2a3 3 0 0 0 3-3h-2zm-1 1h-2v2h2v-2zm-3 1v4h2v-4h-2zm1.707 3.293l-4-4-1.414 1.414 4 4 1.414-1.414zM11 14H7v2h4v-2zm-4 0c-.276 0-.525-.111-.707-.293l-1.414 1.414C5.42 15.663 6.172 16 7 16v-2zm-.707 1.121l3.414-3.414-1.414-1.414-3.414 3.414 1.414 1.414zM9 12h4v-2H9v2zm4 0a3 3 0 0 0 3-3h-2a1 1 0 0 1-1 1v2zm3-3V3h-2v6h2zm0-6a3 3 0 0 0-3-3v2a1 1 0 0 1 1 1h2zm-3-3H3v2h10V0zM3 0a3 3 0 0 0-3 3h2a1 1 0 0 1 1-1V0zM0 3v6h2V3H0zm0 6a3 3 0 0 0 3 3v-2a1 1 0 0 1-1-1H0zm3 3h2v-2H3v2zm1-1v4h2v-4H4zm1.707 4.707l.586-.586-1.414-1.414-.586.586 1.414 1.414z"
5
+ />
6
+ </svg>
7
+ </template>
@@ -0,0 +1,7 @@
1
+ <template>
2
+ <svg xmlns="http://www.w3.org/2000/svg" width="20" height="17" fill="currentColor">
3
+ <path
4
+ d="M11 2.253a1 1 0 1 0-2 0h2zm-2 13a1 1 0 1 0 2 0H9zm.447-12.167a1 1 0 1 0 1.107-1.666L9.447 3.086zM1 2.253L.447 1.42A1 1 0 0 0 0 2.253h1zm0 13H0a1 1 0 0 0 1.553.833L1 15.253zm8.447.833a1 1 0 1 0 1.107-1.666l-1.107 1.666zm0-14.666a1 1 0 1 0 1.107 1.666L9.447 1.42zM19 2.253h1a1 1 0 0 0-.447-.833L19 2.253zm0 13l-.553.833A1 1 0 0 0 20 15.253h-1zm-9.553-.833a1 1 0 1 0 1.107 1.666L9.447 14.42zM9 2.253v13h2v-13H9zm1.553-.833C9.203.523 7.42 0 5.5 0v2c1.572 0 2.961.431 3.947 1.086l1.107-1.666zM5.5 0C3.58 0 1.797.523.447 1.42l1.107 1.666C2.539 2.431 3.928 2 5.5 2V0zM0 2.253v13h2v-13H0zm1.553 13.833C2.539 15.431 3.928 15 5.5 15v-2c-1.92 0-3.703.523-5.053 1.42l1.107 1.666zM5.5 15c1.572 0 2.961.431 3.947 1.086l1.107-1.666C9.203 13.523 7.42 13 5.5 13v2zm5.053-11.914C11.539 2.431 12.928 2 14.5 2V0c-1.92 0-3.703.523-5.053 1.42l1.107 1.666zM14.5 2c1.573 0 2.961.431 3.947 1.086l1.107-1.666C18.203.523 16.421 0 14.5 0v2zm3.5.253v13h2v-13h-2zm1.553 12.167C18.203 13.523 16.421 13 14.5 13v2c1.573 0 2.961.431 3.947 1.086l1.107-1.666zM14.5 13c-1.92 0-3.703.523-5.053 1.42l1.107 1.666C11.539 15.431 12.928 15 14.5 15v-2z"
5
+ />
6
+ </svg>
7
+ </template>
@@ -0,0 +1,7 @@
1
+ <template>
2
+ <svg xmlns="http://www.w3.org/2000/svg" width="18" height="20" fill="currentColor">
3
+ <path
4
+ d="M11.447 8.894a1 1 0 1 0-.894-1.789l.894 1.789zm-2.894-.789a1 1 0 1 0 .894 1.789l-.894-1.789zm0 1.789a1 1 0 1 0 .894-1.789l-.894 1.789zM7.447 7.106a1 1 0 1 0-.894 1.789l.894-1.789zM10 9a1 1 0 1 0-2 0h2zm-2 2.5a1 1 0 1 0 2 0H8zm9.447-5.606a1 1 0 1 0-.894-1.789l.894 1.789zm-2.894-.789a1 1 0 1 0 .894 1.789l-.894-1.789zm2 .789a1 1 0 1 0 .894-1.789l-.894 1.789zm-1.106-2.789a1 1 0 1 0-.894 1.789l.894-1.789zM18 5a1 1 0 1 0-2 0h2zm-2 2.5a1 1 0 1 0 2 0h-2zm-5.447-4.606a1 1 0 1 0 .894-1.789l-.894 1.789zM9 1l.447-.894a1 1 0 0 0-.894 0L9 1zm-2.447.106a1 1 0 1 0 .894 1.789l-.894-1.789zm-6 3a1 1 0 1 0 .894 1.789L.553 4.106zm2.894.789a1 1 0 1 0-.894-1.789l.894 1.789zm-2-.789a1 1 0 1 0-.894 1.789l.894-1.789zm1.106 2.789a1 1 0 1 0 .894-1.789l-.894 1.789zM2 5a1 1 0 1 0-2 0h2zM0 7.5a1 1 0 1 0 2 0H0zm8.553 12.394a1 1 0 1 0 .894-1.789l-.894 1.789zm-1.106-2.789a1 1 0 1 0-.894 1.789l.894-1.789zm1.106 1a1 1 0 1 0 .894 1.789l-.894-1.789zm2.894.789a1 1 0 1 0-.894-1.789l.894 1.789zM8 19a1 1 0 1 0 2 0H8zm2-2.5a1 1 0 1 0-2 0h2zm-7.447.394a1 1 0 1 0 .894-1.789l-.894 1.789zM1 15H0a1 1 0 0 0 .553.894L1 15zm1-2.5a1 1 0 1 0-2 0h2zm12.553 2.606a1 1 0 1 0 .894 1.789l-.894-1.789zM17 15l.447.894A1 1 0 0 0 18 15h-1zm1-2.5a1 1 0 1 0-2 0h2zm-7.447-5.394l-2 1 .894 1.789 2-1-.894-1.789zm-1.106 1l-2-1-.894 1.789 2 1 .894-1.789zM8 9v2.5h2V9H8zm8.553-4.894l-2 1 .894 1.789 2-1-.894-1.789zm.894 0l-2-1-.894 1.789 2 1 .894-1.789zM16 5v2.5h2V5h-2zm-4.553-3.894l-2-1-.894 1.789 2 1 .894-1.789zm-2.894-1l-2 1 .894 1.789 2-1L8.553.106zM1.447 5.894l2-1-.894-1.789-2 1 .894 1.789zm-.894 0l2 1 .894-1.789-2-1-.894 1.789zM0 5v2.5h2V5H0zm9.447 13.106l-2-1-.894 1.789 2 1 .894-1.789zm0 1.789l2-1-.894-1.789-2 1 .894 1.789zM10 19v-2.5H8V19h2zm-6.553-3.894l-2-1-.894 1.789 2 1 .894-1.789zM2 15v-2.5H0V15h2zm13.447 1.894l2-1-.894-1.789-2 1 .894 1.789zM18 15v-2.5h-2V15h2z"
5
+ />
6
+ </svg>
7
+ </template>
@@ -0,0 +1,7 @@
1
+ <template>
2
+ <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor">
3
+ <path
4
+ d="M10 3.22l-.61-.6a5.5 5.5 0 0 0-7.666.105 5.5 5.5 0 0 0-.114 7.665L10 18.78l8.39-8.4a5.5 5.5 0 0 0-.114-7.665 5.5 5.5 0 0 0-7.666-.105l-.61.61z"
5
+ />
6
+ </svg>
7
+ </template>
@@ -0,0 +1,5 @@
1
+ <template>
2
+ <svg aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 24 24">
3
+ <path fill-rule="evenodd" d="M2 12C2 6.477 6.477 2 12 2s10 4.477 10 10-4.477 10-10 10S2 17.523 2 12Zm11-4a1 1 0 1 0-2 0v4a1 1 0 0 0 .293.707l3 3a1 1 0 0 0 1.414-1.414L13 11.586V8Z" clip-rule="evenodd"></path>
4
+ </svg>
5
+ </template>
@@ -0,0 +1,19 @@
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>
@@ -0,0 +1,27 @@
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
+ // }
27
+
@@ -0,0 +1,18 @@
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
+ export 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')
@@ -0,0 +1,63 @@
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
+ if(localStorage.getItem('isAuthorized') === 'true'){
16
+ next({name: 'home'})
17
+ } else {
18
+ next()
19
+ }
20
+ }
21
+ },
22
+ {
23
+ path: '/resource/:resourceId',
24
+ component: ResourceParent,
25
+ name: 'resource',
26
+ children: [
27
+ {
28
+ path: '',
29
+ component: () => import('@/views/ListView.vue'),
30
+ name: 'resource-list',
31
+ meta: { title: 'list',type: 'list' }
32
+ },
33
+ {
34
+ path: 'show/:primaryKey',
35
+ component: () => import('@/views/ShowView.vue'),
36
+ name: 'resource-show',
37
+ meta: { title: 'show', type: 'show'}
38
+
39
+ },
40
+ {
41
+ path: 'edit/:primaryKey',
42
+ component: () => import('@/views/EditView.vue'),
43
+ name: 'resource-edit',
44
+ meta: { title: 'edit', type: 'edit'}
45
+ },
46
+ {
47
+ path: 'create',
48
+ component: () => import('@/views/CreateView.vue'),
49
+ name: 'resource-create',
50
+ meta: { title: 'create', type: 'create'}
51
+
52
+ },
53
+ ]
54
+ },
55
+ /* IMPORTANT:ADMINFORTH ROUTES */
56
+ ]
57
+ })
58
+
59
+
60
+
61
+
62
+
63
+ export default router
@@ -0,0 +1,144 @@
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
+ })
@@ -0,0 +1,48 @@
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
+ })
@@ -0,0 +1,103 @@
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
+ path: string, method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'
11
+ body?: any
12
+ }): Promise<any> {
13
+ const options = {
14
+ method,
15
+ headers: {
16
+ 'Content-Type': 'application/json',
17
+ },
18
+ body: JSON.stringify(body),
19
+ };
20
+ const fullPath = `${import.meta.env.VITE_ADMINFORTH_PUBLIC_PATH || ''}${path}`;
21
+ const r = await fetch(fullPath, options);
22
+ if (r.status == 401 ) {
23
+ useUserStore().unauthorize();
24
+ router.push({ name: 'login' });
25
+ return null;
26
+ }
27
+ return await r.json();
28
+ }
29
+
30
+ export async function callAdminForthApi({ path, method, body=undefined }: {
31
+ path: string,
32
+ method: 'GET' | 'POST' | 'PUT' | 'DELETE',
33
+ body?: any
34
+ }) {
35
+ try {
36
+ return callApi({path: `/adminapi/v1${path}`, method, body} );
37
+ } catch (e) {
38
+ console.error('error', e);
39
+ return { error: `Unexpected error: ${e}` };
40
+ }
41
+ }
42
+
43
+ export function getCustomComponent({ file, meta }: { file: string, meta: any }) {
44
+ const name = file.replace(/@/g, '').replace(/\./g, '').replace(/\//g, '');
45
+ return resolveComponent(name);
46
+ }
47
+
48
+ export function getIcon(icon: string) {
49
+ // icon format is "feather:icon-name". We need to get IconName in pascal case
50
+ if (!icon.includes(':')) {
51
+ throw new Error('Icon name should be in format "icon-set:icon-name"');
52
+ }
53
+ const [iconSet, iconName] = icon.split(':');
54
+ const compName = 'Icon' + iconName.split('-').map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join('');
55
+ return resolveComponent(compName);
56
+ }
57
+
58
+ export const loadFile = (file: string) => {
59
+ if (file.startsWith('http')) {
60
+ return file;
61
+ }
62
+ let path;
63
+ let baseUrl = '';
64
+ if (file.startsWith('@/')) {
65
+ path = file.replace('@/', '');
66
+ baseUrl = new URL(`./${path}`, import.meta.url).href;
67
+ } else if (file.startsWith('@@/')) {
68
+ path = file.replace('@@/', '');
69
+ baseUrl = new URL(`./custom/${path}`, import.meta.url).href;
70
+ } else {
71
+ baseUrl = new URL(`./${file}`, import.meta.url).href;
72
+ }
73
+ return baseUrl;
74
+ }
75
+
76
+ export function checkEmptyValues(value: any, viewType: 'show' | 'list' ) {
77
+ const config: CoreConfig | {} = useCoreStore().config;
78
+ let emptyFieldPlaceholder = '';
79
+ if (config.emptyFieldPlaceholder) {
80
+ if(typeof config.emptyFieldPlaceholder === 'string') {
81
+ emptyFieldPlaceholder = config.emptyFieldPlaceholder;
82
+ } else {
83
+ emptyFieldPlaceholder = config.emptyFieldPlaceholder?.[viewType] || '';
84
+ }
85
+ if (value === null || value === undefined || value === '') {
86
+ return emptyFieldPlaceholder;
87
+ }
88
+ }
89
+ return value;
90
+ }
91
+
92
+ export function checkAcessByAllowedActions(allowedActions:any, action:any ) {
93
+ if (!allowedActions) {
94
+ console.warn('allowedActions not set');
95
+ return;
96
+ }
97
+ if(allowedActions[action] === false) {
98
+ console.warn(`Action ${action} is not allowed`);
99
+ router.back();
100
+ }
101
+ }
102
+
103
+