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,156 @@
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
+ :source="'create'"
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
+
95
+ const coreStore = useCoreStore();
96
+
97
+ const initalValues = computed(() => {
98
+ if (!route.query.values) {
99
+ return {};
100
+ }
101
+ return JSON.parse(decodeURIComponent(route.query.values));
102
+ });
103
+
104
+
105
+
106
+ async function onUpdateRecord(newRecord) {
107
+ console.log('newRecord', newRecord);
108
+ record.value = newRecord;
109
+ }
110
+
111
+ onMounted(async () => {
112
+ loading.value = true;
113
+ record.value = initalValues.value;
114
+ await coreStore.fetchResourceFull({
115
+ resourceId: route.params.resourceId
116
+ });
117
+ loading.value = false;
118
+ checkAcessByAllowedActions(coreStore.resourceOptions.allowedActions,'create');
119
+ });
120
+
121
+ async function saveRecord() {
122
+ console.log('saveRecord isValid', isValid.value);
123
+ if (!isValid.value) {
124
+ validating.value = true;
125
+ return;
126
+ } else {
127
+ validating.value = false;
128
+ }
129
+ saving.value = true;
130
+ const response = await callAdminForthApi({
131
+ method: 'POST',
132
+ path: `/create_record`,
133
+ body: {
134
+ resourceId: route.params.resourceId,
135
+ record: record.value,
136
+ },
137
+ });
138
+ if (response.error) {
139
+ showErrorTost(response.error);
140
+ }
141
+ saving.value = false;
142
+ if (route.query.returnTo) {
143
+ router.push(route.query.returnTo);
144
+ } else {
145
+ router.push({
146
+ name: 'resource-show',
147
+ params: {
148
+ resourceId: route.params.resourceId,
149
+ primaryKey: response.newRecordId
150
+ }
151
+ });
152
+ }
153
+ }
154
+
155
+
156
+ </script>
@@ -0,0 +1,157 @@
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-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"
16
+ >
17
+ Cancel
18
+ </button>
19
+
20
+ <button @click="saveRecord"
21
+ 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"
22
+ :disabled="saving || (validating && !isValid)"
23
+ >
24
+ <IconFloppyDiskSolid class="w-4 h-4" />
25
+ Save
26
+ </button>
27
+
28
+ </BreadcrumbsWithButtons>
29
+
30
+ <component
31
+ v-for="c in coreStore?.resourceOptions?.pageInjections?.edit?.afterBreadcrumbs || []"
32
+ :is="getCustomComponent(c)"
33
+ :meta="c.meta"
34
+ :record="coreStore.record"
35
+ :resource="coreStore.resource"
36
+ :adminUser="coreStore.adminUser"
37
+ />
38
+
39
+ <SingleSkeletLoader v-if="loading"></SingleSkeletLoader>
40
+
41
+ <ResourceForm
42
+ v-else
43
+ :record="editableRecord"
44
+ :resource="coreStore.resource"
45
+ :adminUser="coreStore.adminUser"
46
+ @update:record="onUpdateRecord"
47
+ @update:isValid="isValid = $event"
48
+ :validating="validating"
49
+ :source="'edit'"
50
+ >
51
+ </ResourceForm>
52
+
53
+ <component
54
+ v-for="c in coreStore?.resourceOptions?.pageInjections?.edit?.bottom || []"
55
+ :is="getCustomComponent(c)"
56
+ :meta="c.meta"
57
+ :record="coreStore.record"
58
+ :resource="coreStore.resource"
59
+ :adminUser="coreStore.adminUser"
60
+ />
61
+
62
+ </div>
63
+ </template>
64
+
65
+
66
+ <script setup>
67
+
68
+ import BreadcrumbsWithButtons from '@/components/BreadcrumbsWithButtons.vue';
69
+ import ResourceForm from '@/components/ResourceForm.vue';
70
+ import SingleSkeletLoader from '@/components/SingleSkeletLoader.vue';
71
+ import { useCoreStore } from '@/stores/core';
72
+ import { callAdminForthApi, getCustomComponent,checkAcessByAllowedActions } from '@/utils';
73
+ import { IconFloppyDiskSolid } from '@iconify-prerendered/vue-flowbite';
74
+ import { computed, onMounted, ref } from 'vue';
75
+ import { useRoute, useRouter } from 'vue-router';
76
+ import { showErrorTost } from '@/composables/useFrontendApi';
77
+
78
+ const coreStore = useCoreStore();
79
+
80
+ const isValid = ref(false);
81
+ const validating = ref(false);
82
+
83
+ const route = useRoute();
84
+ const router = useRouter();
85
+
86
+ const loading = ref(false);
87
+
88
+ const saving = ref(false);
89
+
90
+ const record = ref({});
91
+
92
+ async function onUpdateRecord(newRecord) {
93
+ record.value = newRecord;
94
+ }
95
+
96
+ const editableRecord = computed(() => {
97
+ const newRecord = { ...coreStore.record };
98
+ if (!coreStore.resource) {
99
+ return {};
100
+ }
101
+ coreStore.resource.columns.forEach(column => {
102
+ if (column.foreignResource) {
103
+ newRecord[column.name] = newRecord[column.name]?.pk
104
+ }
105
+ });
106
+ return newRecord;
107
+ })
108
+
109
+ onMounted(async () => {
110
+
111
+ loading.value = true;
112
+
113
+ await coreStore.fetchResourceFull({
114
+ resourceId: route.params.resourceId
115
+ });
116
+ await coreStore.fetchRecord({
117
+ resourceId: route.params.resourceId,
118
+ primaryKey: route.params.primaryKey,
119
+ });
120
+ checkAcessByAllowedActions(coreStore.resourceOptions.allowedActions,'edit');
121
+ loading.value = false;
122
+ });
123
+
124
+ async function saveRecord() {
125
+ if (!isValid.value) {
126
+ validating.value = true;
127
+ return;
128
+ } else {
129
+ validating.value = false;
130
+ }
131
+
132
+ saving.value = true;
133
+
134
+ const updates = {};
135
+ for (const key in record.value) {
136
+ if (record.value[key] !== coreStore.record[key]) {
137
+ updates[key] = record.value[key];
138
+ }
139
+ }
140
+
141
+ const resp = await callAdminForthApi({
142
+ method: 'POST',
143
+ path: `/update_record`,
144
+ body: {
145
+ resourceId: route.params.resourceId,
146
+ recordId: route.params.primaryKey,
147
+ record: updates,
148
+ },
149
+ });
150
+ if (resp.error) {
151
+ showErrorTost(resp.error);
152
+ }
153
+ saving.value = false;
154
+ router.push({ name: 'resource-show', params: { resourceId: route.params.resourceId, primaryKey: coreStore.record[coreStore.primaryKey] } });
155
+ }
156
+
157
+ </script>
@@ -0,0 +1,8 @@
1
+ <script setup lang="ts">
2
+ </script>
3
+
4
+ <template>
5
+ <main>
6
+ 123
7
+ </main>
8
+ </template>
@@ -0,0 +1,258 @@
1
+ <template>
2
+ <div class="relative">
3
+ <Teleport to="body">
4
+ <Filters
5
+ :columns="coreStore.resource?.columns"
6
+ :columnsMinMax="columnsMinMax" :show="filtersShow"
7
+ @hide="filtersShow = false"
8
+ />
9
+ </Teleport>
10
+
11
+ <component
12
+ v-for="c in coreStore?.resourceOptions?.pageInjections?.list?.beforeBreadcrumbs || []"
13
+ :is="getCustomComponent(c)"
14
+ :meta="c.meta"
15
+ :resource="coreStore.resource"
16
+ :adminUser="coreStore.adminUser"
17
+ />
18
+
19
+ <BreadcrumbsWithButtons>
20
+ <button
21
+ @click="()=>{checkboxes = []}"
22
+ v-if="checkboxes.length"
23
+ data-tooltip-target="tooltip-remove-all"
24
+ data-tooltip-placement="bottom"
25
+ class="flex gap-1 items-center py-1 px-3 me-2 text-sm font-medium 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-darkListTable dark:text-gray-400 dark:border-gray-600 dark:hover:text-white dark:hover:bg-gray-700 rounded-default"
26
+ >
27
+ <IconBanOutline class="w-5 h-5 "/>
28
+
29
+ <div id="tooltip-remove-all" role="tooltip"
30
+ class="absolute z-10 invisible inline-block px-3 py-2 text-sm font-medium text-white transition-opacity duration-300 bg-gray-900 rounded-lg shadow-sm opacity-0 tooltip dark:bg-gray-700">
31
+ Remove selection
32
+ <div class="tooltip-arrow" data-popper-arrow></div>
33
+ </div>
34
+ </button>
35
+
36
+ <button
37
+ v-if="checkboxes.length"
38
+ v-for="(action,i) in coreStore.resource?.options?.bulkActions"
39
+ :key="action.id"
40
+ @click="startBulkAction(action.id)"
41
+ class="flex gap-1 items-center py-1 px-3 text-sm font-medium text-gray-900 focus:outline-none bg-white rounded-default 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"
42
+ :class="{'bg-red-100 text-red-800 border-red-400 dark:bg-red-700 dark:text-red-400 dark:border-red-400':action.state==='danger', 'bg-green-100 text-green-800 border-green-400 dark:bg-green-700 dark:text-green-400 dark:border-green-400':action.state==='success',
43
+ 'bg-blue-100 text-blue-800 border-blue-400 dark:bg-blue-700 dark:text-blue-400 dark:border-blue-400':action.state==='active',
44
+ }"
45
+ >
46
+ <component
47
+ v-if="action.icon"
48
+ :is="getIcon(action.icon)"
49
+ class="w-5 h-5 text-gray-500 transition duration-75 dark:text-gray-400 group-hover:text-gray-900 dark:group-hover:text-white"></component>
50
+
51
+ {{ `${action.label} (${checkboxes.length})` }}
52
+ </button>
53
+
54
+ <RouterLink v-if="coreStore.resource?.options?.allowedActions?.create"
55
+ :to="{ name: 'resource-create', params: { resourceId: $route.params.resourceId } }"
56
+ class="flex items-center py-1 px-3 text-sm font-medium 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 rounded-default"
57
+ >
58
+ <IconPlusOutline class="w-4 h-4 me-2"/>
59
+ Create
60
+ </RouterLink>
61
+
62
+ <button
63
+ class="flex gap-1 items-center py-1 px-3 me-2 text-sm font-medium 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 rounded-default"
64
+ @click="()=>{filtersShow = !filtersShow}"
65
+ v-if="coreStore.resource?.options?.allowedActions?.filter"
66
+ >
67
+ <IconFilterOutline class="w-4 h-4 me-2"/>
68
+ Filter
69
+ <span
70
+ 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"
71
+ v-if="filtersStore.filters.length">
72
+ {{ filtersStore.filters.length }}
73
+ </span>
74
+ </button>
75
+ </BreadcrumbsWithButtons>
76
+
77
+ <component
78
+ v-for="c in coreStore?.resourceOptions?.pageInjections?.list?.afterBreadcrumbs || []"
79
+ :is="getCustomComponent(c)"
80
+ :meta="c.meta"
81
+ :resource="coreStore.resource"
82
+ :adminUser="coreStore.adminUser"
83
+ />
84
+
85
+ <ResourceListTable
86
+ :resource="coreStore.resource"
87
+ :rows="rows"
88
+ @update:page="page = $event"
89
+ @update:sort="sort = $event"
90
+ @update:checkboxes="checkboxes = $event"
91
+ @update:records="getList"
92
+ :sort="sort"
93
+ :pageSize="pageSize"
94
+ :totalRows="totalRows"
95
+ :checkboxes="checkboxes"
96
+ />
97
+
98
+ <component
99
+ v-for="c in coreStore?.resourceOptions?.pageInjections?.list?.bottom || []"
100
+ :is="getCustomComponent(c)"
101
+ :meta="c.meta"
102
+ :resource="coreStore.resource"
103
+ :adminUser="coreStore.adminUser"
104
+ />
105
+
106
+ </div>
107
+ </template>
108
+
109
+ <script setup>
110
+ import BreadcrumbsWithButtons from '@/components/BreadcrumbsWithButtons.vue';
111
+ import ResourceListTable from '@/components/ResourceListTable.vue';
112
+ import { useCoreStore } from '@/stores/core';
113
+ import { useModalStore } from '@/stores/modal';
114
+ import { useFiltersStore } from '@/stores/filters';
115
+ import { callAdminForthApi, getIcon } from '@/utils';
116
+ import { initFlowbite } from 'flowbite';
117
+ import { computed, onMounted, ref, watch } from 'vue';
118
+ import { useRoute } from 'vue-router';
119
+ import { showErrorTost } from '@/composables/useFrontendApi'
120
+
121
+ import ValueRenderer from '@/components/ValueRenderer.vue';
122
+ import { getCustomComponent } from '@/utils';
123
+
124
+
125
+ import {
126
+ IconBanOutline,
127
+ IconFilterOutline,
128
+ IconPlusOutline
129
+ } from '@iconify-prerendered/vue-flowbite';
130
+
131
+ import Filters from '@/components/Filters.vue';
132
+
133
+ const filtersShow = ref(false);
134
+
135
+ const coreStore = useCoreStore();
136
+ const filtersStore = useFiltersStore();
137
+
138
+ const route = useRoute();
139
+
140
+ const page = ref(1);
141
+ const columnsMinMax = ref({});
142
+ const sort = ref([]);
143
+
144
+ const rows = ref(null);
145
+ const totalRows = ref(0);
146
+ const checkboxes = ref([]);
147
+
148
+ const DEFAULT_PAGE_SIZE = 10;
149
+
150
+
151
+ const pageSize = computed(() => coreStore.resource?.options?.listPageSize || DEFAULT_PAGE_SIZE);
152
+
153
+
154
+ watch([page], async () => {
155
+ await getList();
156
+ });
157
+
158
+ watch(()=>filtersStore.filters, async () => {
159
+ page.value = 1;
160
+ checkboxes.value = [];
161
+
162
+ await getList();
163
+ }, {deep: true});
164
+
165
+ watch([sort], async () => {
166
+ await getList();
167
+ }, {deep: true});
168
+
169
+
170
+ async function getList() {
171
+ rows.value = null;
172
+ const data = await callAdminForthApi({
173
+ path: '/get_resource_data',
174
+ method: 'POST',
175
+ body: {
176
+ source: 'list',
177
+ resourceId: route.params.resourceId,
178
+ limit: pageSize.value,
179
+ offset: (page.value - 1) * pageSize.value,
180
+ filters: filtersStore.filters,
181
+ sort: sort.value,
182
+ }
183
+ });
184
+ if (data.error) {
185
+ showErrorTost(data.error);
186
+ rows.value = [];
187
+ totalRows.value = 0;
188
+ return;
189
+ }
190
+ rows.value = data.data?.map(row => {
191
+ row._primaryKeyValue = row[coreStore.resource.columns.find(c => c.primaryKey).name];
192
+ return row;
193
+ });
194
+ totalRows.value = data.total;
195
+ }
196
+
197
+ async function startBulkAction(actionId) {
198
+ const data = await callAdminForthApi({
199
+ path: '/start_bulk_action',
200
+ method: 'POST',
201
+ body: {
202
+ resourceId: route.params.resourceId,
203
+ actionId: actionId,
204
+ recordIds: checkboxes.value
205
+
206
+ }
207
+ });
208
+ if (data?.ok) {
209
+ checkboxes.value = [];
210
+ await getList();
211
+ }
212
+ if (data?.error) {
213
+ showErrorTost(data.error);
214
+ }
215
+ }
216
+
217
+
218
+
219
+ async function init() {
220
+
221
+ await coreStore.fetchResourceFull({
222
+ resourceId: route.params.resourceId
223
+ });
224
+
225
+ if (coreStore.resource.options?.defaultSort) {
226
+ sort.value = [{
227
+ field: coreStore.resource.options.defaultSort.columnName,
228
+ direction: coreStore.resource.options.defaultSort.direction
229
+ }];
230
+ } else {
231
+ sort.value = [];
232
+ }
233
+
234
+ await getList();
235
+ columnsMinMax.value = await callAdminForthApi({
236
+ path: '/get_min_max_for_columns',
237
+ method: 'POST',
238
+ body: {
239
+ resourceId: route.params.resourceId
240
+ }
241
+ });
242
+ }
243
+
244
+ onMounted(async () => {
245
+ initFlowbite();
246
+
247
+ await init();
248
+
249
+ });
250
+
251
+ // on route param change
252
+ watch(() => route.params.resourceId, async () => {
253
+ filtersStore.setFilters([]);
254
+ checkboxes.value = [];
255
+ await init();
256
+ });
257
+
258
+ </script>