adminforth 2.27.0-next.1 → 2.27.0-next.10
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.
- package/dist/modules/restApi.d.ts.map +1 -1
- package/dist/modules/restApi.js +40 -2
- package/dist/modules/restApi.js.map +1 -1
- package/dist/spa/package-lock.json +41 -0
- package/dist/spa/package.json +3 -0
- package/dist/spa/pnpm-lock.yaml +38 -0
- package/dist/spa/src/components/ColumnValueInputWrapper.vue +24 -1
- package/dist/spa/src/components/CustomRangePicker.vue +6 -0
- package/dist/spa/src/components/GroupsTable.vue +7 -4
- package/dist/spa/src/components/ResourceForm.vue +100 -6
- package/dist/spa/src/components/ResourceListTable.vue +21 -43
- package/dist/spa/src/components/ThreeDotsMenu.vue +47 -51
- package/dist/spa/src/types/Back.ts +3 -0
- package/dist/spa/src/types/Common.ts +18 -3
- package/dist/spa/src/types/adapters/StorageAdapter.ts +12 -0
- package/dist/spa/src/utils/createEditUtils.ts +65 -0
- package/dist/spa/src/utils/index.ts +2 -1
- package/dist/spa/src/utils/utils.ts +165 -4
- package/dist/spa/src/utils.ts +2 -1
- package/dist/spa/src/views/CreateView.vue +22 -49
- package/dist/spa/src/views/EditView.vue +20 -38
- package/dist/spa/src/views/ListView.vue +72 -13
- package/dist/spa/src/views/ShowView.vue +52 -46
- package/dist/types/Back.d.ts +3 -0
- package/dist/types/Back.d.ts.map +1 -1
- package/dist/types/Back.js.map +1 -1
- package/dist/types/Common.d.ts +23 -3
- package/dist/types/Common.d.ts.map +1 -1
- package/dist/types/Common.js.map +1 -1
- package/dist/types/adapters/StorageAdapter.d.ts +11 -0
- package/dist/types/adapters/StorageAdapter.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -101,11 +101,13 @@ export async function callAdminForthApi(
|
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
export function formatComponent(component: AdminForthComponentDeclaration): AdminForthComponentDeclarationFull {
|
|
104
|
+
export function formatComponent(component: AdminForthComponentDeclaration | undefined): AdminForthComponentDeclarationFull {
|
|
105
105
|
if (typeof component === 'string') {
|
|
106
106
|
return { file: component, meta: {} };
|
|
107
|
-
} else {
|
|
107
|
+
} else if (typeof component === 'object') {
|
|
108
108
|
return { file: component.file, meta: component.meta };
|
|
109
|
+
} else {
|
|
110
|
+
return { file: '', meta: {} };
|
|
109
111
|
}
|
|
110
112
|
}
|
|
111
113
|
|
|
@@ -191,7 +193,8 @@ export function applyRegexValidation(value: any, validation: ValidationObject[]
|
|
|
191
193
|
if ( validation?.length ) {
|
|
192
194
|
const validationArray = validation;
|
|
193
195
|
for (let i = 0; i < validationArray.length; i++) {
|
|
194
|
-
|
|
196
|
+
const regExpPattern = validationArray[i].regExp;
|
|
197
|
+
if (regExpPattern) {
|
|
195
198
|
let flags = '';
|
|
196
199
|
if (validationArray[i].caseSensitive) {
|
|
197
200
|
flags += 'i';
|
|
@@ -203,7 +206,7 @@ export function applyRegexValidation(value: any, validation: ValidationObject[]
|
|
|
203
206
|
flags += 'g';
|
|
204
207
|
}
|
|
205
208
|
|
|
206
|
-
const regExp = new RegExp(
|
|
209
|
+
const regExp = new RegExp(regExpPattern, flags);
|
|
207
210
|
if (value === undefined || value === null) {
|
|
208
211
|
value = '';
|
|
209
212
|
}
|
|
@@ -690,4 +693,162 @@ export async function onBeforeRouteLeaveCreateEditViewGuard(initialValues: any,
|
|
|
690
693
|
leaveGuardActive.setActive(false);
|
|
691
694
|
}
|
|
692
695
|
});
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
export async function executeCustomAction({
|
|
699
|
+
actionId,
|
|
700
|
+
resourceId,
|
|
701
|
+
recordId,
|
|
702
|
+
extra = {},
|
|
703
|
+
onSuccess,
|
|
704
|
+
onError,
|
|
705
|
+
setLoadingState,
|
|
706
|
+
}: {
|
|
707
|
+
actionId: string | number | undefined,
|
|
708
|
+
resourceId: string,
|
|
709
|
+
recordId: string | number,
|
|
710
|
+
extra?: Record<string, any>,
|
|
711
|
+
onSuccess?: (data: any) => Promise<void>,
|
|
712
|
+
onError?: (error: string) => void,
|
|
713
|
+
setLoadingState?: (loading: boolean) => void,
|
|
714
|
+
}): Promise<any> {
|
|
715
|
+
setLoadingState?.(true);
|
|
716
|
+
|
|
717
|
+
try {
|
|
718
|
+
const data = await callAdminForthApi({
|
|
719
|
+
path: '/start_custom_action',
|
|
720
|
+
method: 'POST',
|
|
721
|
+
body: {
|
|
722
|
+
resourceId,
|
|
723
|
+
actionId,
|
|
724
|
+
recordId,
|
|
725
|
+
extra: extra || {},
|
|
726
|
+
}
|
|
727
|
+
});
|
|
728
|
+
|
|
729
|
+
if (data?.redirectUrl) {
|
|
730
|
+
// Check if the URL should open in a new tab
|
|
731
|
+
if (data.redirectUrl.includes('target=_blank')) {
|
|
732
|
+
window.open(data.redirectUrl.replace('&target=_blank', '').replace('?target=_blank', ''), '_blank');
|
|
733
|
+
} else {
|
|
734
|
+
// Navigate within the app
|
|
735
|
+
if (data.redirectUrl.startsWith('http')) {
|
|
736
|
+
window.location.href = data.redirectUrl;
|
|
737
|
+
} else {
|
|
738
|
+
router.push(data.redirectUrl);
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
return data;
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
if (data?.ok) {
|
|
745
|
+
if (onSuccess) {
|
|
746
|
+
await onSuccess(data);
|
|
747
|
+
}
|
|
748
|
+
return data;
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
if (data?.error) {
|
|
752
|
+
if (onError) {
|
|
753
|
+
onError(data.error);
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
return data;
|
|
758
|
+
} finally {
|
|
759
|
+
setLoadingState?.(false);
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
export async function executeCustomBulkAction({
|
|
764
|
+
actionId,
|
|
765
|
+
resourceId,
|
|
766
|
+
recordIds,
|
|
767
|
+
extra = {},
|
|
768
|
+
onSuccess,
|
|
769
|
+
onError,
|
|
770
|
+
setLoadingState,
|
|
771
|
+
confirmMessage,
|
|
772
|
+
}: {
|
|
773
|
+
actionId: string | number | undefined,
|
|
774
|
+
resourceId: string,
|
|
775
|
+
recordIds: (string | number)[],
|
|
776
|
+
extra?: Record<string, any>,
|
|
777
|
+
onSuccess?: (results: any[]) => Promise<void>,
|
|
778
|
+
onError?: (error: string) => void,
|
|
779
|
+
setLoadingState?: (loading: boolean) => void,
|
|
780
|
+
confirmMessage?: string,
|
|
781
|
+
}): Promise<any> {
|
|
782
|
+
if (!recordIds || recordIds.length === 0) {
|
|
783
|
+
if (onError) {
|
|
784
|
+
onError('No records selected');
|
|
785
|
+
}
|
|
786
|
+
return { error: 'No records selected' };
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
if (confirmMessage) {
|
|
790
|
+
const { confirm } = useAdminforth();
|
|
791
|
+
const confirmed = await confirm({
|
|
792
|
+
message: confirmMessage,
|
|
793
|
+
});
|
|
794
|
+
if (!confirmed) {
|
|
795
|
+
return { cancelled: true };
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
setLoadingState?.(true);
|
|
800
|
+
|
|
801
|
+
try {
|
|
802
|
+
// Execute action for all records in parallel using Promise.all
|
|
803
|
+
const results = await Promise.all(
|
|
804
|
+
recordIds.map(recordId =>
|
|
805
|
+
callAdminForthApi({
|
|
806
|
+
path: '/start_custom_action',
|
|
807
|
+
method: 'POST',
|
|
808
|
+
body: {
|
|
809
|
+
resourceId,
|
|
810
|
+
actionId,
|
|
811
|
+
recordId,
|
|
812
|
+
extra: extra || {},
|
|
813
|
+
}
|
|
814
|
+
})
|
|
815
|
+
)
|
|
816
|
+
);
|
|
817
|
+
|
|
818
|
+
const lastResult = results[results.length - 1];
|
|
819
|
+
if (lastResult?.redirectUrl) {
|
|
820
|
+
if (lastResult.redirectUrl.includes('target=_blank')) {
|
|
821
|
+
window.open(lastResult.redirectUrl.replace('&target=_blank', '').replace('?target=_blank', ''), '_blank');
|
|
822
|
+
} else {
|
|
823
|
+
if (lastResult.redirectUrl.startsWith('http')) {
|
|
824
|
+
window.location.href = lastResult.redirectUrl;
|
|
825
|
+
} else {
|
|
826
|
+
router.push(lastResult.redirectUrl);
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
return lastResult;
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
const allSucceeded = results.every(r => r?.ok);
|
|
833
|
+
const hasErrors = results.some(r => r?.error);
|
|
834
|
+
|
|
835
|
+
if (allSucceeded) {
|
|
836
|
+
if (onSuccess) {
|
|
837
|
+
await onSuccess(results);
|
|
838
|
+
}
|
|
839
|
+
return { ok: true, results };
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
if (hasErrors) {
|
|
843
|
+
const errorMessages = results.filter(r => r?.error).map(r => r.error).join(', ');
|
|
844
|
+
if (onError) {
|
|
845
|
+
onError(errorMessages);
|
|
846
|
+
}
|
|
847
|
+
return { error: errorMessages, results };
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
return { results };
|
|
851
|
+
} finally {
|
|
852
|
+
setLoadingState?.(false);
|
|
853
|
+
}
|
|
693
854
|
}
|
package/dist/spa/src/utils.ts
CHANGED
|
@@ -20,11 +20,9 @@
|
|
|
20
20
|
<button
|
|
21
21
|
@click="() => saveRecord()"
|
|
22
22
|
class="af-save-button h-[34px] af-button-shadow flex items-center py-1 px-3 text-sm font-medium rounded-default text-lightCreateViewSaveButtonText focus:outline-none bg-lightCreateViewButtonBackground rounded border border-lightCreateViewButtonBorder hover:bg-lightCreateViewButtonBackgroundHover hover:text-lightCreateViewSaveButtonTextHover focus:z-10 focus:ring-4 focus:ring-lightCreateViewButtonFocusRing dark:focus:ring-darkCreateViewButtonFocusRing dark:bg-darkCreateViewButtonBackground dark:text-darkCreateViewSaveButtonText dark:border-darkCreateViewButtonBorder dark:hover:text-darkCreateViewSaveButtonTextHover dark:hover:bg-darkCreateViewButtonBackgroundHover disabled:opacity-50 gap-1"
|
|
23
|
-
:disabled="saving || (
|
|
23
|
+
:disabled="saving || (validatingMode && !isValid) || resourceFormRef?.isValidating"
|
|
24
24
|
>
|
|
25
|
-
<
|
|
26
|
-
aria-hidden="true" class="w-4 h-4 mr-1 text-gray-200 animate-spin dark:text-gray-600 fill-lightCreateViewSaveButtonText" 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
|
-
|
|
25
|
+
<Spinner v-if="saving || resourceFormRef?.isValidating" class="w-4 h-4" />
|
|
28
26
|
<IconFloppyDiskSolid v-else class="w-4 h-4" />
|
|
29
27
|
{{ $t('Save') }}
|
|
30
28
|
</button>
|
|
@@ -54,7 +52,7 @@
|
|
|
54
52
|
:resource="coreStore.resource!"
|
|
55
53
|
@update:record="onUpdateRecord"
|
|
56
54
|
@update:isValid="isValid = $event"
|
|
57
|
-
:
|
|
55
|
+
:validatingMode="validatingMode"
|
|
58
56
|
:source="'create'"
|
|
59
57
|
:readonlyColumns="readonlyColumns"
|
|
60
58
|
>
|
|
@@ -81,18 +79,18 @@ import SingleSkeletLoader from '@/components/SingleSkeletLoader.vue';
|
|
|
81
79
|
import { useCoreStore } from '@/stores/core';
|
|
82
80
|
import { callAdminForthApi, getCustomComponent,checkAcessByAllowedActions, initThreeDotsDropdown, checkShowIf, compareOldAndNewRecord, onBeforeRouteLeaveCreateEditViewGuard, leaveGuardActiveClass, formatComponent } from '@/utils';
|
|
83
81
|
import { IconFloppyDiskSolid } from '@iconify-prerendered/vue-flowbite';
|
|
84
|
-
import { onMounted, onBeforeMount, onBeforeUnmount, ref
|
|
85
|
-
import { useRoute, useRouter
|
|
86
|
-
import { computed } from 'vue';
|
|
82
|
+
import { onMounted, onBeforeMount, onBeforeUnmount, ref } from 'vue';
|
|
83
|
+
import { useRoute, useRouter } from 'vue-router';
|
|
87
84
|
import { showErrorTost } from '@/composables/useFrontendApi';
|
|
88
85
|
import ThreeDotsMenu from '@/components/ThreeDotsMenu.vue';
|
|
89
86
|
import { useAdminforth } from '@/adminforth';
|
|
90
87
|
import { useI18n } from 'vue-i18n';
|
|
91
88
|
import { type AdminForthComponentDeclaration, type AdminForthComponentDeclarationFull } from '@/types/Common.js';
|
|
92
|
-
import
|
|
89
|
+
import { saveRecordPreparations } from '@/utils';
|
|
90
|
+
import { Spinner } from '@/afcl'
|
|
93
91
|
|
|
94
92
|
const isValid = ref(false);
|
|
95
|
-
const
|
|
93
|
+
const validatingMode = ref(false);
|
|
96
94
|
|
|
97
95
|
const loading = ref(true);
|
|
98
96
|
const saving = ref(false);
|
|
@@ -195,28 +193,22 @@ onMounted(async () => {
|
|
|
195
193
|
});
|
|
196
194
|
|
|
197
195
|
async function saveRecord() {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
196
|
+
const interceptorsResult = await saveRecordPreparations(
|
|
197
|
+
'create',
|
|
198
|
+
validatingMode,
|
|
199
|
+
resourceFormRef,
|
|
200
|
+
isValid,
|
|
201
|
+
t,
|
|
202
|
+
saving,
|
|
203
|
+
runSaveInterceptors,
|
|
204
|
+
record,
|
|
205
|
+
coreStore,
|
|
206
|
+
route
|
|
207
|
+
);
|
|
208
|
+
|
|
206
209
|
const requiredColumns = coreStore.resource?.columns.filter(c => c.required?.create === true) || [];
|
|
207
210
|
const requiredColumnsToSkip = requiredColumns.filter(c => checkShowIf(c, record.value, coreStore.resource?.columns || []) === false);
|
|
208
|
-
|
|
209
|
-
const interceptorsResult = await runSaveInterceptors({
|
|
210
|
-
action: 'create',
|
|
211
|
-
values: record.value,
|
|
212
|
-
resource: coreStore.resource,
|
|
213
|
-
resourceId: route.params.resourceId as string,
|
|
214
|
-
});
|
|
215
|
-
if (!interceptorsResult.ok) {
|
|
216
|
-
saving.value = false;
|
|
217
|
-
if (interceptorsResult.error) showErrorTost(interceptorsResult.error);
|
|
218
|
-
return;
|
|
219
|
-
}
|
|
211
|
+
|
|
220
212
|
const interceptorConfirmationResult = (interceptorsResult.extra as Record<string, any>)?.confirmationResult;
|
|
221
213
|
const response = await callAdminForthApi({
|
|
222
214
|
method: 'POST',
|
|
@@ -254,23 +246,4 @@ async function saveRecord() {
|
|
|
254
246
|
saving.value = false;
|
|
255
247
|
}
|
|
256
248
|
|
|
257
|
-
function scrollToInvalidField() {
|
|
258
|
-
let columnsWithErrors: {column: AdminForthResourceColumn, error: string}[] = [];
|
|
259
|
-
for (const column of resourceFormRef.value?.editableColumns || []) {
|
|
260
|
-
const error = resourceFormRef.value?.columnError(column);
|
|
261
|
-
if (error) {
|
|
262
|
-
columnsWithErrors.push({column, error});
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
const errorMessage = t('Failed to save. Please fix errors for the following fields:') + '<ul class="mt-2 list-disc list-inside">' + columnsWithErrors.map(c => `<li><strong>${c.column.label || c.column.name}</strong>: ${c.error}</li>`).join('') + '</ul>';
|
|
266
|
-
alert({
|
|
267
|
-
messageHtml: errorMessage,
|
|
268
|
-
variant: 'danger'
|
|
269
|
-
});
|
|
270
|
-
const firstInvalidElement = document.querySelector('.af-invalid-field-message');
|
|
271
|
-
if (firstInvalidElement) {
|
|
272
|
-
firstInvalidElement.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
|
|
276
249
|
</script>
|
|
@@ -19,9 +19,10 @@
|
|
|
19
19
|
<button
|
|
20
20
|
@click="() => saveRecord()"
|
|
21
21
|
class="flex items-center h-[34px] af-button-shadow py-1 px-3 text-sm font-medium rounded-default text-lightEditViewSaveButtonText focus:outline-none bg-lightEditViewButtonBackground rounded border border-lightEditViewButtonBorder hover:bg-lightEditViewButtonBackgroundHover hover:text-lightEditViewSaveButtonTextHover focus:z-10 focus:ring-4 focus:ring-lightEditViewButtonFocusRing dark:focus:ring-darkEditViewButtonFocusRing dark:bg-darkEditViewButtonBackground dark:text-darkEditViewSaveButtonText dark:border-darkEditViewButtonBorder dark:hover:text-darkEditViewSaveButtonTextHover dark:hover:bg-darkEditViewButtonBackgroundHover disabled:opacity-50 gap-1"
|
|
22
|
-
:disabled="saving || (
|
|
22
|
+
:disabled="saving || (validatingMode && !isValid) || resourceFormRef?.isValidating"
|
|
23
23
|
>
|
|
24
|
-
<
|
|
24
|
+
<Spinner v-if="saving || resourceFormRef?.isValidating" class="w-4 h-4" />
|
|
25
|
+
<IconFloppyDiskSolid v-else class="w-4 h-4" />
|
|
25
26
|
{{ $t('Save') }}
|
|
26
27
|
</button>
|
|
27
28
|
|
|
@@ -50,7 +51,7 @@
|
|
|
50
51
|
:adminUser="coreStore.adminUser"
|
|
51
52
|
@update:record="onUpdateRecord"
|
|
52
53
|
@update:isValid="isValid = $event"
|
|
53
|
-
:
|
|
54
|
+
:validatingMode="validatingMode"
|
|
54
55
|
:source="'edit'"
|
|
55
56
|
>
|
|
56
57
|
</ResourceForm>
|
|
@@ -85,13 +86,15 @@ import { useI18n } from 'vue-i18n';
|
|
|
85
86
|
import { formatComponent } from '@/utils';
|
|
86
87
|
import { type AdminForthComponentDeclaration, type AdminForthComponentDeclarationFull } from '@/types/Common.js';
|
|
87
88
|
import type { AdminForthResourceColumn } from '@/types/Back';
|
|
89
|
+
import { scrollToInvalidField, saveRecordPreparations } from '@/utils';
|
|
90
|
+
import { Spinner } from '@/afcl'
|
|
88
91
|
|
|
89
92
|
const { t } = useI18n();
|
|
90
93
|
const coreStore = useCoreStore();
|
|
91
94
|
const { clearSaveInterceptors, runSaveInterceptors, alert, confirm } = useAdminforth();
|
|
92
95
|
|
|
93
96
|
const isValid = ref(false);
|
|
94
|
-
const
|
|
97
|
+
const validatingMode = ref(false);
|
|
95
98
|
|
|
96
99
|
const route = useRoute();
|
|
97
100
|
const router = useRouter();
|
|
@@ -180,22 +183,20 @@ onMounted(async () => {
|
|
|
180
183
|
});
|
|
181
184
|
|
|
182
185
|
async function saveRecord() {
|
|
183
|
-
if (!isValid.value) {
|
|
184
|
-
validating.value = true;
|
|
185
|
-
await nextTick();
|
|
186
|
-
scrollToInvalidField();
|
|
187
|
-
return;
|
|
188
|
-
} else {
|
|
189
|
-
validating.value = false;
|
|
190
|
-
}
|
|
191
186
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
187
|
+
const interceptorsResult = await saveRecordPreparations(
|
|
188
|
+
'edit',
|
|
189
|
+
validatingMode,
|
|
190
|
+
resourceFormRef,
|
|
191
|
+
isValid,
|
|
192
|
+
t,
|
|
193
|
+
saving,
|
|
194
|
+
runSaveInterceptors,
|
|
195
|
+
record,
|
|
196
|
+
coreStore,
|
|
197
|
+
route
|
|
198
|
+
);
|
|
199
|
+
|
|
199
200
|
if (!interceptorsResult.ok) {
|
|
200
201
|
saving.value = false;
|
|
201
202
|
if (interceptorsResult.error) showErrorTost(interceptorsResult.error);
|
|
@@ -256,23 +257,4 @@ async function saveRecord() {
|
|
|
256
257
|
saving.value = false;
|
|
257
258
|
}
|
|
258
259
|
|
|
259
|
-
function scrollToInvalidField() {
|
|
260
|
-
let columnsWithErrors: {column: AdminForthResourceColumn, error: string}[] = [];
|
|
261
|
-
for (const column of resourceFormRef.value?.editableColumns || []) {
|
|
262
|
-
const error = resourceFormRef.value?.columnError(column);
|
|
263
|
-
if (error) {
|
|
264
|
-
columnsWithErrors.push({column, error});
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
const errorMessage = t('Failed to save. Please fix errors for the following fields:') + '<ul class="mt-2 list-disc list-inside">' + columnsWithErrors.map(c => `<li><strong>${c.column.label || c.column.name}</strong>: ${c.error}</li>`).join('') + '</ul>';
|
|
268
|
-
alert({
|
|
269
|
-
messageHtml: errorMessage,
|
|
270
|
-
variant: 'danger'
|
|
271
|
-
});
|
|
272
|
-
const firstInvalidElement = document.querySelector('.af-invalid-field-message');
|
|
273
|
-
if (firstInvalidElement) {
|
|
274
|
-
firstInvalidElement.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
|
|
278
260
|
</script>
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
</Tooltip>
|
|
49
49
|
</button>
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
<div
|
|
52
52
|
v-if="checkboxes.length"
|
|
53
53
|
v-for="(action,i) in coreStore.resource?.options?.bulkActions"
|
|
54
54
|
>
|
|
@@ -91,6 +91,41 @@
|
|
|
91
91
|
</div>
|
|
92
92
|
</button>
|
|
93
93
|
</div>
|
|
94
|
+
<div
|
|
95
|
+
v-if="checkboxes.length"
|
|
96
|
+
v-for="(action,i) in coreStore.resource?.options?.actions?.filter(a => a.showIn?.bulkButton)"
|
|
97
|
+
>
|
|
98
|
+
<button
|
|
99
|
+
:key="action.id"
|
|
100
|
+
@click="startCustomBulkActionInner(action.id!)"
|
|
101
|
+
class="flex gap-1 items-center py-1 px-3 text-sm font-medium text-lightListViewButtonText
|
|
102
|
+
focus:outline-none bg-lightListViewButtonBackground rounded-default border h-[34px]
|
|
103
|
+
border-lightListViewButtonBorder hover:bg-lightListViewButtonBackgroundHover
|
|
104
|
+
hover:text-lightListViewButtonTextHover focus:z-10 focus:ring-4 af-button-shadow
|
|
105
|
+
focus:ring-lightListViewButtonFocusRing dark:focus:ring-darkListViewButtonFocusRing
|
|
106
|
+
dark:bg-darkListViewButtonBackground dark:text-darkListViewButtonText dark:border-darkListViewButtonBorder
|
|
107
|
+
dark:hover:text-darkListViewButtonTextHover dark:hover:bg-darkListViewButtonBackgroundHover"
|
|
108
|
+
>
|
|
109
|
+
<component
|
|
110
|
+
v-if="action.icon && !customActionLoadingStates[action.id!]"
|
|
111
|
+
:is="getIcon(action.icon)"
|
|
112
|
+
class="w-5 h-5 transition duration-75 group-hover:text-gray-900 dark:group-hover:text-white"></component>
|
|
113
|
+
<div v-if="customActionLoadingStates[action.id!]">
|
|
114
|
+
<svg
|
|
115
|
+
aria-hidden="true"
|
|
116
|
+
class="w-5 h-5 animate-spin text-gray-200 dark:text-gray-500 fill-gray-500 dark:fill-gray-300"
|
|
117
|
+
viewBox="0 0 100 101"
|
|
118
|
+
fill="none"
|
|
119
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
120
|
+
>
|
|
121
|
+
<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"/>
|
|
122
|
+
<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"/>
|
|
123
|
+
</svg>
|
|
124
|
+
<span class="sr-only">Loading...</span>
|
|
125
|
+
</div>
|
|
126
|
+
{{ `${action.name} (${checkboxes.length})` }}
|
|
127
|
+
</button>
|
|
128
|
+
</div>
|
|
94
129
|
|
|
95
130
|
<RouterLink v-if="coreStore.resource?.options?.allowedActions?.create"
|
|
96
131
|
:to="{ name: 'resource-create', params: { resourceId: $route.params.resourceId } }"
|
|
@@ -199,7 +234,7 @@ import BreadcrumbsWithButtons from '@/components/BreadcrumbsWithButtons.vue';
|
|
|
199
234
|
import ResourceListTable from '@/components/ResourceListTable.vue';
|
|
200
235
|
import { useCoreStore } from '@/stores/core';
|
|
201
236
|
import { useFiltersStore } from '@/stores/filters';
|
|
202
|
-
import { callAdminForthApi, currentQuery, getIcon, setQuery, formatComponent } from '@/utils';
|
|
237
|
+
import { callAdminForthApi, currentQuery, getIcon, setQuery, formatComponent, executeCustomBulkAction } from '@/utils';
|
|
203
238
|
import { computed, onMounted, onUnmounted, ref, watch, type Ref } from 'vue';
|
|
204
239
|
import { useRoute } from 'vue-router';
|
|
205
240
|
import { getCustomComponent, initThreeDotsDropdown, getList, startBulkAction } from '@/utils';
|
|
@@ -218,7 +253,7 @@ import Filters from '@/components/Filters.vue';
|
|
|
218
253
|
import { useAdminforth } from '@/adminforth';
|
|
219
254
|
|
|
220
255
|
const filtersShow = ref(false);
|
|
221
|
-
const { list } = useAdminforth();
|
|
256
|
+
const { list, alert } = useAdminforth();
|
|
222
257
|
const coreStore = useCoreStore();
|
|
223
258
|
const filtersStore = useFiltersStore();
|
|
224
259
|
|
|
@@ -237,6 +272,7 @@ const rows: Ref<any[]|null> = ref(null);
|
|
|
237
272
|
const totalRows = ref(0);
|
|
238
273
|
const checkboxes = ref([]);
|
|
239
274
|
const bulkActionLoadingStates = ref<{[key: string]: boolean}>({});
|
|
275
|
+
const customActionLoadingStates = ref<{[key: string]: boolean}>({});
|
|
240
276
|
|
|
241
277
|
const DEFAULT_PAGE_SIZE = 10;
|
|
242
278
|
|
|
@@ -306,6 +342,38 @@ async function startBulkActionInner(actionId: string) {
|
|
|
306
342
|
await startBulkAction(actionId, coreStore.resource!, checkboxes, bulkActionLoadingStates, getListInner);
|
|
307
343
|
}
|
|
308
344
|
|
|
345
|
+
async function startCustomBulkActionInner(actionId: string | number) {
|
|
346
|
+
const action = coreStore.resource?.options?.actions?.find(a => a.id === actionId);
|
|
347
|
+
|
|
348
|
+
await executeCustomBulkAction({
|
|
349
|
+
actionId,
|
|
350
|
+
resourceId: route.params.resourceId as string,
|
|
351
|
+
recordIds: checkboxes.value,
|
|
352
|
+
confirmMessage: action?.bulkConfirmationMessage,
|
|
353
|
+
setLoadingState: (loading: boolean) => {
|
|
354
|
+
customActionLoadingStates.value[actionId] = loading;
|
|
355
|
+
},
|
|
356
|
+
onSuccess: async (results: any[]) => {
|
|
357
|
+
checkboxes.value = [];
|
|
358
|
+
await getListInner();
|
|
359
|
+
|
|
360
|
+
const successResults = results.filter(r => r?.successMessage);
|
|
361
|
+
if (successResults.length > 0) {
|
|
362
|
+
alert({
|
|
363
|
+
message: action?.bulkSuccessMessage || `${successResults.length} out of ${results.length} items processed successfully`,
|
|
364
|
+
variant: 'success'
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
},
|
|
368
|
+
onError: (error: string) => {
|
|
369
|
+
alert({
|
|
370
|
+
message: error,
|
|
371
|
+
variant: 'danger'
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
|
|
309
377
|
async function getListInner() {
|
|
310
378
|
rows.value = null; // to show loading state
|
|
311
379
|
const result = await getList(coreStore.resource!, isPageLoaded.value, page.value, pageSize.value, sort.value, checkboxes, filtersStore.filters);
|
|
@@ -474,16 +542,7 @@ watch([sort], async () => {
|
|
|
474
542
|
|
|
475
543
|
|
|
476
544
|
.af-button-shadow {
|
|
477
|
-
|
|
478
|
-
&::after {
|
|
479
|
-
content: '';
|
|
480
|
-
position: absolute;
|
|
481
|
-
left: 0;
|
|
482
|
-
right: 0;
|
|
483
|
-
height: 100%;
|
|
484
|
-
box-shadow: -0px 6px 6px rgb(0, 0, 0, 0.1);
|
|
485
|
-
border-radius: inherit;
|
|
486
|
-
}
|
|
545
|
+
box-shadow: -0px 6px 6px rgb(0, 0, 0, 0.1);
|
|
487
546
|
}
|
|
488
547
|
|
|
489
548
|
|
|
@@ -25,10 +25,23 @@
|
|
|
25
25
|
class="flex items-center af-button-shadow h-[34px] 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"
|
|
26
26
|
>
|
|
27
27
|
<component
|
|
28
|
-
v-if="action.icon"
|
|
28
|
+
v-if="action.icon && !actionLoadingStates[action.id!]"
|
|
29
29
|
:is="getIcon(action.icon)"
|
|
30
30
|
class="w-4 h-4 me-2 text-lightPrimary dark:text-darkPrimary"
|
|
31
31
|
/>
|
|
32
|
+
<div v-if="actionLoadingStates[action.id!]" class="me-2">
|
|
33
|
+
<svg
|
|
34
|
+
aria-hidden="true"
|
|
35
|
+
class="w-4 h-4 animate-spin text-gray-200 dark:text-gray-500 fill-gray-500 dark:fill-gray-300"
|
|
36
|
+
viewBox="0 0 100 101"
|
|
37
|
+
fill="none"
|
|
38
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
39
|
+
>
|
|
40
|
+
<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"/>
|
|
41
|
+
<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"/>
|
|
42
|
+
</svg>
|
|
43
|
+
<span class="sr-only">Loading...</span>
|
|
44
|
+
</div>
|
|
32
45
|
{{ action.name }}
|
|
33
46
|
</button>
|
|
34
47
|
</component>
|
|
@@ -137,7 +150,7 @@
|
|
|
137
150
|
import BreadcrumbsWithButtons from '@/components/BreadcrumbsWithButtons.vue';
|
|
138
151
|
|
|
139
152
|
import { useCoreStore } from '@/stores/core';
|
|
140
|
-
import { getCustomComponent, checkAcessByAllowedActions, initThreeDotsDropdown, formatComponent } from '@/utils';
|
|
153
|
+
import { getCustomComponent, checkAcessByAllowedActions, initThreeDotsDropdown, formatComponent, executeCustomAction } from '@/utils';
|
|
141
154
|
import { IconPenSolid, IconTrashBinSolid, IconPlusOutline } from '@iconify-prerendered/vue-flowbite';
|
|
142
155
|
import { onMounted, ref, computed } from 'vue';
|
|
143
156
|
import { useRoute,useRouter } from 'vue-router';
|
|
@@ -246,54 +259,47 @@ async function deleteRecord() {
|
|
|
246
259
|
}
|
|
247
260
|
|
|
248
261
|
async function startCustomAction(actionId: string, extra?: any) {
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
window.location.href = data.redirectUrl;
|
|
272
|
-
} else {
|
|
273
|
-
router.push(data.redirectUrl);
|
|
262
|
+
await executeCustomAction({
|
|
263
|
+
actionId,
|
|
264
|
+
resourceId: route.params.resourceId as string,
|
|
265
|
+
recordId: route.params.primaryKey as string,
|
|
266
|
+
extra,
|
|
267
|
+
setLoadingState: (loading: boolean) => {
|
|
268
|
+
actionLoadingStates.value[actionId] = loading;
|
|
269
|
+
},
|
|
270
|
+
onSuccess: async (data: any) => {
|
|
271
|
+
if (data?.redirectUrl) {
|
|
272
|
+
// Check if the URL should open in a new tab
|
|
273
|
+
if (data.redirectUrl.includes('target=_blank')) {
|
|
274
|
+
window.open(data.redirectUrl.replace('&target=_blank', '').replace('?target=_blank', ''), '_blank');
|
|
275
|
+
} else {
|
|
276
|
+
// Navigate within the app
|
|
277
|
+
if (data.redirectUrl.startsWith('http')) {
|
|
278
|
+
window.location.href = data.redirectUrl;
|
|
279
|
+
} else {
|
|
280
|
+
router.push(data.redirectUrl);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
return;
|
|
274
284
|
}
|
|
275
|
-
}
|
|
276
|
-
return;
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
if (data?.ok) {
|
|
280
|
-
await coreStore.fetchRecord({
|
|
281
|
-
resourceId: route.params.resourceId as string,
|
|
282
|
-
primaryKey: route.params.primaryKey as string,
|
|
283
|
-
source: 'show',
|
|
284
|
-
});
|
|
285
285
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
286
|
+
await coreStore.fetchRecord({
|
|
287
|
+
resourceId: route.params.resourceId as string,
|
|
288
|
+
primaryKey: route.params.primaryKey as string,
|
|
289
|
+
source: 'show',
|
|
290
290
|
});
|
|
291
|
+
|
|
292
|
+
if (data.successMessage) {
|
|
293
|
+
alert({
|
|
294
|
+
message: data.successMessage,
|
|
295
|
+
variant: 'success'
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
},
|
|
299
|
+
onError: (error: string) => {
|
|
300
|
+
showErrorTost(error);
|
|
291
301
|
}
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
if (data?.error) {
|
|
295
|
-
showErrorTost(data.error);
|
|
296
|
-
}
|
|
302
|
+
});
|
|
297
303
|
}
|
|
298
304
|
|
|
299
305
|
show.refresh = () => {
|