|
10 | 10 | :adminUser="coreStore.adminUser" |
11 | 11 | /> |
12 | 12 | <BreadcrumbsWithButtons> |
| 13 | + <template v-if="coreStore.resource?.options?.actions"> |
| 14 | + <button |
| 15 | + v-for="action in coreStore.resource.options.actions.filter(a => a.showIn?.showButton)" |
| 16 | + :key="action.id" |
| 17 | + @click="startCustomAction(action.id)" |
| 18 | + :disabled="actionLoadingStates[action.id]" |
| 19 | + class="flex 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-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" |
| 20 | + > |
| 21 | + <component |
| 22 | + v-if="action.icon" |
| 23 | + :is="getIcon(action.icon)" |
| 24 | + class="w-4 h-4 me-2 text-lightPrimary dark:text-darkPrimary" |
| 25 | + /> |
| 26 | + {{ action.name }} |
| 27 | + </button> |
| 28 | + </template> |
13 | 29 | <RouterLink v-if="coreStore.resource?.options?.allowedActions?.create" |
14 | 30 | :to="{ name: 'resource-create', params: { resourceId: $route.params.resourceId } }" |
15 | 31 | 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-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 rounded-default" |
|
34 | 50 |
|
35 | 51 | <ThreeDotsMenu |
36 | 52 | :threeDotsDropdownItems="coreStore.resourceOptions?.pageInjections?.show?.threeDotsDropdownItems" |
| 53 | + :customActions="customActions" |
37 | 54 | ></ThreeDotsMenu> |
38 | 55 | </BreadcrumbsWithButtons> |
39 | 56 |
|
@@ -121,13 +138,20 @@ import ThreeDotsMenu from '@/components/ThreeDotsMenu.vue'; |
121 | 138 | import ShowTable from '@/components/ShowTable.vue'; |
122 | 139 | import adminforth from "@/adminforth"; |
123 | 140 | import { useI18n } from 'vue-i18n'; |
| 141 | +import { getIcon } from '@/utils'; |
124 | 142 |
|
125 | 143 | const route = useRoute(); |
126 | 144 | const router = useRouter(); |
127 | 145 | const loading = ref(true); |
128 | 146 | const { t } = useI18n(); |
129 | 147 | const coreStore = useCoreStore(); |
130 | 148 |
|
| 149 | +const actionLoadingStates = ref({}); |
| 150 | +
|
| 151 | +const customActions = computed(() => { |
| 152 | + return coreStore.resource?.options?.actions?.filter(a => a.showIn?.showThreeDotsMenu) || []; |
| 153 | +}); |
| 154 | +
|
131 | 155 | onMounted(async () => { |
132 | 156 | loading.value = true; |
133 | 157 | await coreStore.fetchResourceFull({ |
@@ -206,4 +230,39 @@ async function deleteRecord(row) { |
206 | 230 | |
207 | 231 | } |
208 | 232 |
|
| 233 | +async function startCustomAction(actionId) { |
| 234 | + actionLoadingStates.value[actionId] = true; |
| 235 | +
|
| 236 | + const data = await callAdminForthApi({ |
| 237 | + path: '/start_custom_action', |
| 238 | + method: 'POST', |
| 239 | + body: { |
| 240 | + resourceId: route.params.resourceId, |
| 241 | + actionId: actionId, |
| 242 | + recordId: route.params.primaryKey |
| 243 | + } |
| 244 | + }); |
| 245 | + |
| 246 | + actionLoadingStates.value[actionId] = false; |
| 247 | + |
| 248 | + if (data?.ok) { |
| 249 | + await coreStore.fetchRecord({ |
| 250 | + resourceId: route.params.resourceId, |
| 251 | + primaryKey: route.params.primaryKey, |
| 252 | + source: 'show', |
| 253 | + }); |
| 254 | +
|
| 255 | + if (data.successMessage) { |
| 256 | + adminforth.alert({ |
| 257 | + message: data.successMessage, |
| 258 | + variant: 'success' |
| 259 | + }); |
| 260 | + } |
| 261 | + } |
| 262 | + |
| 263 | + if (data?.error) { |
| 264 | + showErrorTost(data.error); |
| 265 | + } |
| 266 | +} |
| 267 | +
|
209 | 268 | </script> |
0 commit comments