adminforth 2.26.4 → 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/commands/createApp/templates/package.json.hbs +1 -1
- package/dist/modules/restApi.d.ts +1 -0
- package/dist/modules/restApi.d.ts.map +1 -1
- package/dist/modules/restApi.js +65 -3
- package/dist/modules/restApi.js.map +1 -1
- package/dist/modules/styles.js +2 -2
- package/dist/modules/styles.js.map +1 -1
- package/dist/servers/express.d.ts.map +1 -1
- package/dist/servers/express.js +7 -1
- package/dist/servers/express.js.map +1 -1
- package/dist/spa/package-lock.json +85 -7
- package/dist/spa/package.json +4 -1
- package/dist/spa/pnpm-lock.yaml +339 -299
- package/dist/spa/src/App.vue +1 -1
- package/dist/spa/src/adminforth.ts +17 -29
- package/dist/spa/src/afcl/Input.vue +1 -1
- package/dist/spa/src/afcl/Modal.vue +12 -1
- package/dist/spa/src/afcl/Select.vue +4 -2
- package/dist/spa/src/afcl/Table.vue +27 -13
- package/dist/spa/src/components/AcceptModal.vue +2 -0
- package/dist/spa/src/components/ColumnValueInputWrapper.vue +35 -4
- package/dist/spa/src/components/CustomRangePicker.vue +22 -67
- package/dist/spa/src/components/GroupsTable.vue +7 -4
- package/dist/spa/src/components/ListActionsThreeDots.vue +9 -8
- package/dist/spa/src/components/RangePicker.vue +236 -0
- package/dist/spa/src/components/ResourceForm.vue +100 -6
- package/dist/spa/src/components/ResourceListTable.vue +45 -70
- package/dist/spa/src/components/Sidebar.vue +1 -1
- package/dist/spa/src/components/ThreeDotsMenu.vue +54 -57
- package/dist/spa/src/i18n.ts +1 -1
- package/dist/spa/src/stores/core.ts +4 -2
- package/dist/spa/src/types/Back.ts +10 -3
- package/dist/spa/src/types/Common.ts +43 -8
- package/dist/spa/src/types/FrontendAPI.ts +6 -1
- 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/listUtils.ts +8 -2
- package/dist/spa/src/utils/utils.ts +192 -12
- package/dist/spa/src/utils.ts +2 -1
- package/dist/spa/src/views/CreateView.vue +32 -59
- package/dist/spa/src/views/EditView.vue +30 -47
- package/dist/spa/src/views/ListView.vue +119 -18
- package/dist/spa/src/views/LoginView.vue +13 -13
- package/dist/spa/src/views/ShowView.vue +67 -61
- package/dist/spa/tsconfig.app.json +1 -1
- package/dist/types/Back.d.ts +7 -4
- package/dist/types/Back.d.ts.map +1 -1
- package/dist/types/Back.js.map +1 -1
- package/dist/types/Common.d.ts +43 -8
- package/dist/types/Common.d.ts.map +1 -1
- package/dist/types/Common.js.map +1 -1
- package/dist/types/FrontendAPI.d.ts +13 -1
- package/dist/types/FrontendAPI.d.ts.map +1 -1
- package/dist/types/FrontendAPI.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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { nextTick, onMounted, ref, resolveComponent } from 'vue';
|
|
2
2
|
import type { CoreConfig } from '../spa_types/core';
|
|
3
|
-
import type { ValidationObject } from '../types/Common.js';
|
|
3
|
+
import type { AdminForthComponentDeclaration, AdminForthComponentDeclarationFull, ValidationObject } from '../types/Common.js';
|
|
4
4
|
import router from "../router";
|
|
5
5
|
import { useCoreStore } from '../stores/core';
|
|
6
6
|
import { useUserStore } from '../stores/user';
|
|
@@ -19,11 +19,12 @@ const LS_LANG_KEY = `afLanguage`;
|
|
|
19
19
|
const MAX_CONSECUTIVE_EMPTY_RESULTS = 2;
|
|
20
20
|
const ITEMS_PER_PAGE_LIMIT = 100;
|
|
21
21
|
|
|
22
|
-
export async function callApi({path, method, body, headers, silentError = false}: {
|
|
22
|
+
export async function callApi({path, method, body, headers, silentError = false, abortSignal}: {
|
|
23
23
|
path: string, method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'
|
|
24
24
|
body?: any
|
|
25
25
|
headers?: Record<string, string>
|
|
26
26
|
silentError?: boolean
|
|
27
|
+
abortSignal?: AbortSignal
|
|
27
28
|
}): Promise<any> {
|
|
28
29
|
const t = i18nInstance?.global.t || ((s: string) => s)
|
|
29
30
|
const options = {
|
|
@@ -34,6 +35,7 @@ export async function callApi({path, method, body, headers, silentError = false}
|
|
|
34
35
|
...headers
|
|
35
36
|
},
|
|
36
37
|
body: JSON.stringify(body),
|
|
38
|
+
signal: abortSignal
|
|
37
39
|
};
|
|
38
40
|
const fullPath = `${import.meta.env.VITE_ADMINFORTH_PUBLIC_PATH || ''}${path}`;
|
|
39
41
|
try {
|
|
@@ -68,28 +70,47 @@ export async function callApi({path, method, body, headers, silentError = false}
|
|
|
68
70
|
return null;
|
|
69
71
|
}
|
|
70
72
|
|
|
71
|
-
if (!silentError) {
|
|
73
|
+
if (!silentError && !(e instanceof DOMException && e.name === 'AbortError')) {
|
|
72
74
|
adminforth.alert({variant:'danger', message: t('Something went wrong, please try again later'),})
|
|
73
75
|
}
|
|
74
76
|
console.error(`error in callApi ${path}`, e);
|
|
75
77
|
}
|
|
76
78
|
}
|
|
77
79
|
|
|
78
|
-
export async function callAdminForthApi(
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
80
|
+
export async function callAdminForthApi(
|
|
81
|
+
{
|
|
82
|
+
path,
|
|
83
|
+
method,
|
|
84
|
+
body=undefined,
|
|
85
|
+
headers=undefined,
|
|
86
|
+
silentError = false,
|
|
87
|
+
abortSignal = undefined
|
|
88
|
+
}: {
|
|
89
|
+
path: string,
|
|
90
|
+
method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH',
|
|
91
|
+
body?: any,
|
|
92
|
+
headers?: Record<string, string>,
|
|
93
|
+
silentError?: boolean,
|
|
94
|
+
abortSignal?: AbortSignal
|
|
84
95
|
}): Promise<any> {
|
|
85
96
|
try {
|
|
86
|
-
return callApi({path: `/adminapi/v1${path}`, method, body, headers, silentError} );
|
|
97
|
+
return callApi({path: `/adminapi/v1${path}`, method, body, headers, silentError, abortSignal} );
|
|
87
98
|
} catch (e) {
|
|
88
99
|
console.error('error', e);
|
|
89
100
|
return { error: `Unexpected error: ${e}` };
|
|
90
101
|
}
|
|
91
102
|
}
|
|
92
103
|
|
|
104
|
+
export function formatComponent(component: AdminForthComponentDeclaration | undefined): AdminForthComponentDeclarationFull {
|
|
105
|
+
if (typeof component === 'string') {
|
|
106
|
+
return { file: component, meta: {} };
|
|
107
|
+
} else if (typeof component === 'object') {
|
|
108
|
+
return { file: component.file, meta: component.meta };
|
|
109
|
+
} else {
|
|
110
|
+
return { file: '', meta: {} };
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
93
114
|
export function getCustomComponent({ file, meta }: { file: string, meta?: any }) {
|
|
94
115
|
const name = file.replace(/@/g, '').replace(/\./g, '').replace(/\//g, '');
|
|
95
116
|
return resolveComponent(name);
|
|
@@ -172,7 +193,8 @@ export function applyRegexValidation(value: any, validation: ValidationObject[]
|
|
|
172
193
|
if ( validation?.length ) {
|
|
173
194
|
const validationArray = validation;
|
|
174
195
|
for (let i = 0; i < validationArray.length; i++) {
|
|
175
|
-
|
|
196
|
+
const regExpPattern = validationArray[i].regExp;
|
|
197
|
+
if (regExpPattern) {
|
|
176
198
|
let flags = '';
|
|
177
199
|
if (validationArray[i].caseSensitive) {
|
|
178
200
|
flags += 'i';
|
|
@@ -184,7 +206,7 @@ export function applyRegexValidation(value: any, validation: ValidationObject[]
|
|
|
184
206
|
flags += 'g';
|
|
185
207
|
}
|
|
186
208
|
|
|
187
|
-
const regExp = new RegExp(
|
|
209
|
+
const regExp = new RegExp(regExpPattern, flags);
|
|
188
210
|
if (value === undefined || value === null) {
|
|
189
211
|
value = '';
|
|
190
212
|
}
|
|
@@ -671,4 +693,162 @@ export async function onBeforeRouteLeaveCreateEditViewGuard(initialValues: any,
|
|
|
671
693
|
leaveGuardActive.setActive(false);
|
|
672
694
|
}
|
|
673
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
|
+
}
|
|
674
854
|
}
|
package/dist/spa/src/utils.ts
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
<div class="relative w-full">
|
|
3
3
|
|
|
4
4
|
<component
|
|
5
|
-
v-for="c in coreStore?.resourceOptions?.pageInjections?.create?.beforeBreadcrumbs || []"
|
|
6
|
-
:is="getCustomComponent(c)"
|
|
5
|
+
v-for="c in coreStore?.resourceOptions?.pageInjections?.create?.beforeBreadcrumbs as AdminForthComponentDeclaration[] || []"
|
|
6
|
+
:is="getCustomComponent(formatComponent(c))"
|
|
7
7
|
:meta="(c as AdminForthComponentDeclarationFull).meta"
|
|
8
8
|
:record="coreStore.record"
|
|
9
9
|
:resource="coreStore.resource"
|
|
@@ -13,18 +13,16 @@
|
|
|
13
13
|
<BreadcrumbsWithButtons>
|
|
14
14
|
<!-- save and cancle -->
|
|
15
15
|
<button @click="() => {cancelButtonClicked = true; $router.back()}"
|
|
16
|
-
class="af-cancel-button flex items-center py-1 px-3 me-2 text-sm font-medium rounded-default text-lightCreateViewButtonText focus:outline-none bg-lightCreateViewButtonBackground rounded border border-lightCreateViewButtonBorder hover:bg-lightCreateViewButtonBackgroundHover hover:text-lightCreateViewButtonTextHover focus:z-10 focus:ring-4 focus:ring-lightCreateViewButtonFocusRing dark:focus:ring-darkCreateViewButtonFocusRing dark:bg-darkCreateViewButtonBackground dark:text-darkCreateViewButtonText dark:border-darkCreateViewButtonBorder dark:hover:text-darkCreateViewButtonTextHover dark:hover:bg-darkCreateViewButtonBackgroundHover"
|
|
16
|
+
class="af-cancel-button h-[34px] af-button-shadow flex items-center py-1 px-3 me-2 text-sm font-medium rounded-default text-lightCreateViewButtonText focus:outline-none bg-lightCreateViewButtonBackground rounded border border-lightCreateViewButtonBorder hover:bg-lightCreateViewButtonBackgroundHover hover:text-lightCreateViewButtonTextHover focus:z-10 focus:ring-4 focus:ring-lightCreateViewButtonFocusRing dark:focus:ring-darkCreateViewButtonFocusRing dark:bg-darkCreateViewButtonBackground dark:text-darkCreateViewButtonText dark:border-darkCreateViewButtonBorder dark:hover:text-darkCreateViewButtonTextHover dark:hover:bg-darkCreateViewButtonBackgroundHover"
|
|
17
17
|
>
|
|
18
18
|
{{ $t('Cancel') }}
|
|
19
19
|
</button>
|
|
20
20
|
<button
|
|
21
21
|
@click="() => saveRecord()"
|
|
22
|
-
class="af-save-button 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 || (
|
|
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 || (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>
|
|
@@ -36,8 +34,8 @@
|
|
|
36
34
|
</BreadcrumbsWithButtons>
|
|
37
35
|
|
|
38
36
|
<component
|
|
39
|
-
v-for="c in coreStore?.resourceOptions?.pageInjections?.create?.afterBreadcrumbs || []"
|
|
40
|
-
:is="getCustomComponent(c)"
|
|
37
|
+
v-for="c in coreStore?.resourceOptions?.pageInjections?.create?.afterBreadcrumbs as AdminForthComponentDeclaration[] || []"
|
|
38
|
+
:is="getCustomComponent(formatComponent(c))"
|
|
41
39
|
:meta="(c as AdminForthComponentDeclarationFull).meta"
|
|
42
40
|
:record="coreStore.record"
|
|
43
41
|
:resource="coreStore.resource"
|
|
@@ -54,15 +52,15 @@
|
|
|
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
|
>
|
|
61
59
|
</ResourceForm>
|
|
62
60
|
|
|
63
61
|
<component
|
|
64
|
-
v-for="c in coreStore?.resourceOptions?.pageInjections?.create?.bottom || []"
|
|
65
|
-
:is="getCustomComponent(c)"
|
|
62
|
+
v-for="c in coreStore?.resourceOptions?.pageInjections?.create?.bottom as AdminForthComponentDeclaration[] || []"
|
|
63
|
+
:is="getCustomComponent(formatComponent(c))"
|
|
66
64
|
:meta="(c as AdminForthComponentDeclarationFull).meta"
|
|
67
65
|
:record="coreStore.record"
|
|
68
66
|
:resource="coreStore.resource"
|
|
@@ -79,20 +77,20 @@ import BreadcrumbsWithButtons from '@/components/BreadcrumbsWithButtons.vue';
|
|
|
79
77
|
import ResourceForm from '@/components/ResourceForm.vue';
|
|
80
78
|
import SingleSkeletLoader from '@/components/SingleSkeletLoader.vue';
|
|
81
79
|
import { useCoreStore } from '@/stores/core';
|
|
82
|
-
import { callAdminForthApi, getCustomComponent,checkAcessByAllowedActions, initThreeDotsDropdown, checkShowIf, compareOldAndNewRecord, onBeforeRouteLeaveCreateEditViewGuard, leaveGuardActiveClass,
|
|
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
|
-
import { type AdminForthComponentDeclarationFull } from '@/types/Common.js';
|
|
92
|
-
import
|
|
88
|
+
import { type AdminForthComponentDeclaration, type AdminForthComponentDeclarationFull } from '@/types/Common.js';
|
|
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>
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div class="relative w-full">
|
|
3
3
|
<component
|
|
4
|
-
v-for="c in coreStore?.resourceOptions?.pageInjections?.edit?.beforeBreadcrumbs || []"
|
|
5
|
-
:is="getCustomComponent(c)"
|
|
4
|
+
v-for="c in coreStore?.resourceOptions?.pageInjections?.edit?.beforeBreadcrumbs as AdminForthComponentDeclaration[] || []"
|
|
5
|
+
:is="getCustomComponent(formatComponent(c))"
|
|
6
6
|
:meta="(c as AdminForthComponentDeclarationFull).meta"
|
|
7
7
|
:record="editableRecord"
|
|
8
8
|
:resource="coreStore.resource"
|
|
@@ -12,16 +12,17 @@
|
|
|
12
12
|
<BreadcrumbsWithButtons>
|
|
13
13
|
<!-- save and cancle -->
|
|
14
14
|
<button @click="() => {cancelButtonClicked = true; $router.back()}"
|
|
15
|
-
class="flex items-center py-1 px-3 me-2 text-sm font-medium text-lightEditViewButtonText rounded-default focus:outline-none bg-lightEditViewButtonBackground rounded border border-lightEditViewButtonBorder hover:bg-lightEditViewButtonBackgroundHover hover:text-lightEditViewButtonTextHover focus:z-10 focus:ring-4 focus:ring-lightEditViewButtonFocusRing dark:focus:ring-darkEditViewButtonFocusRing dark:bg-darkEditViewButtonBackground dark:text-darkEditViewButtonText dark:border-darkEditViewButtonBorder dark:hover:text-darkEditViewButtonTextHover dark:hover:bg-darkEditViewButtonBackgroundHover"
|
|
15
|
+
class="flex items-center h-[34px] af-button-shadow py-1 px-3 me-2 text-sm font-medium text-lightEditViewButtonText rounded-default focus:outline-none bg-lightEditViewButtonBackground rounded border border-lightEditViewButtonBorder hover:bg-lightEditViewButtonBackgroundHover hover:text-lightEditViewButtonTextHover focus:z-10 focus:ring-4 focus:ring-lightEditViewButtonFocusRing dark:focus:ring-darkEditViewButtonFocusRing dark:bg-darkEditViewButtonBackground dark:text-darkEditViewButtonText dark:border-darkEditViewButtonBorder dark:hover:text-darkEditViewButtonTextHover dark:hover:bg-darkEditViewButtonBackgroundHover"
|
|
16
16
|
>
|
|
17
17
|
{{ $t('Cancel') }}
|
|
18
18
|
</button>
|
|
19
19
|
<button
|
|
20
20
|
@click="() => saveRecord()"
|
|
21
|
-
class="flex items-center 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 || (
|
|
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 || (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
|
|
|
@@ -32,8 +33,8 @@
|
|
|
32
33
|
</BreadcrumbsWithButtons>
|
|
33
34
|
|
|
34
35
|
<component
|
|
35
|
-
v-for="c in coreStore?.resourceOptions?.pageInjections?.edit?.afterBreadcrumbs || []"
|
|
36
|
-
:is="getCustomComponent(c)"
|
|
36
|
+
v-for="c in coreStore?.resourceOptions?.pageInjections?.edit?.afterBreadcrumbs as AdminForthComponentDeclaration[] || []"
|
|
37
|
+
:is="getCustomComponent(formatComponent(c))"
|
|
37
38
|
:meta="(c as AdminForthComponentDeclarationFull).meta"
|
|
38
39
|
:record="coreStore.record"
|
|
39
40
|
:resource="coreStore.resource"
|
|
@@ -50,14 +51,14 @@
|
|
|
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>
|
|
57
58
|
|
|
58
59
|
<component
|
|
59
|
-
v-for="c in coreStore?.resourceOptions?.pageInjections?.edit?.bottom || []"
|
|
60
|
-
:is="getCustomComponent(c)"
|
|
60
|
+
v-for="c in coreStore?.resourceOptions?.pageInjections?.edit?.bottom as AdminForthComponentDeclaration[] || []"
|
|
61
|
+
:is="getCustomComponent(formatComponent(c))"
|
|
61
62
|
:meta="(c as AdminForthComponentDeclarationFull).meta"
|
|
62
63
|
:record="coreStore.record"
|
|
63
64
|
:resource="coreStore.resource"
|
|
@@ -82,15 +83,18 @@ import { showErrorTost } from '@/composables/useFrontendApi';
|
|
|
82
83
|
import ThreeDotsMenu from '@/components/ThreeDotsMenu.vue';
|
|
83
84
|
import { useAdminforth } from '@/adminforth';
|
|
84
85
|
import { useI18n } from 'vue-i18n';
|
|
85
|
-
import {
|
|
86
|
+
import { formatComponent } from '@/utils';
|
|
87
|
+
import { type AdminForthComponentDeclaration, type AdminForthComponentDeclarationFull } from '@/types/Common.js';
|
|
86
88
|
import type { AdminForthResourceColumn } from '@/types/Back';
|
|
89
|
+
import { scrollToInvalidField, saveRecordPreparations } from '@/utils';
|
|
90
|
+
import { Spinner } from '@/afcl'
|
|
87
91
|
|
|
88
92
|
const { t } = useI18n();
|
|
89
93
|
const coreStore = useCoreStore();
|
|
90
94
|
const { clearSaveInterceptors, runSaveInterceptors, alert, confirm } = useAdminforth();
|
|
91
95
|
|
|
92
96
|
const isValid = ref(false);
|
|
93
|
-
const
|
|
97
|
+
const validatingMode = ref(false);
|
|
94
98
|
|
|
95
99
|
const route = useRoute();
|
|
96
100
|
const router = useRouter();
|
|
@@ -179,22 +183,20 @@ onMounted(async () => {
|
|
|
179
183
|
});
|
|
180
184
|
|
|
181
185
|
async function saveRecord() {
|
|
182
|
-
if (!isValid.value) {
|
|
183
|
-
validating.value = true;
|
|
184
|
-
await nextTick();
|
|
185
|
-
scrollToInvalidField();
|
|
186
|
-
return;
|
|
187
|
-
} else {
|
|
188
|
-
validating.value = false;
|
|
189
|
-
}
|
|
190
186
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
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
|
+
|
|
198
200
|
if (!interceptorsResult.ok) {
|
|
199
201
|
saving.value = false;
|
|
200
202
|
if (interceptorsResult.error) showErrorTost(interceptorsResult.error);
|
|
@@ -255,23 +257,4 @@ async function saveRecord() {
|
|
|
255
257
|
saving.value = false;
|
|
256
258
|
}
|
|
257
259
|
|
|
258
|
-
function scrollToInvalidField() {
|
|
259
|
-
let columnsWithErrors: {column: AdminForthResourceColumn, error: string}[] = [];
|
|
260
|
-
for (const column of resourceFormRef.value?.editableColumns || []) {
|
|
261
|
-
const error = resourceFormRef.value?.columnError(column);
|
|
262
|
-
if (error) {
|
|
263
|
-
columnsWithErrors.push({column, error});
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
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>';
|
|
267
|
-
alert({
|
|
268
|
-
messageHtml: errorMessage,
|
|
269
|
-
variant: 'danger'
|
|
270
|
-
});
|
|
271
|
-
const firstInvalidElement = document.querySelector('.af-invalid-field-message');
|
|
272
|
-
if (firstInvalidElement) {
|
|
273
|
-
firstInvalidElement.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
|
|
277
260
|
</script>
|