adminforth 2.27.0-next.5 → 2.27.0-next.51

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 (82) hide show
  1. package/commands/callTsProxy.js +10 -5
  2. package/commands/createApp/templates/api.ts.hbs +28 -9
  3. package/commands/createApp/templates/package.json.hbs +2 -1
  4. package/commands/proxy.ts +18 -10
  5. package/dist/commands/proxy.js +14 -10
  6. package/dist/commands/proxy.js.map +1 -1
  7. package/dist/dataConnectors/clickhouse.d.ts +5 -2
  8. package/dist/dataConnectors/clickhouse.d.ts.map +1 -1
  9. package/dist/dataConnectors/clickhouse.js +73 -9
  10. package/dist/dataConnectors/clickhouse.js.map +1 -1
  11. package/dist/index.d.ts +4 -1
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +17 -0
  14. package/dist/index.js.map +1 -1
  15. package/dist/modules/configValidator.d.ts.map +1 -1
  16. package/dist/modules/configValidator.js +16 -9
  17. package/dist/modules/configValidator.js.map +1 -1
  18. package/dist/modules/restApi.d.ts.map +1 -1
  19. package/dist/modules/restApi.js +515 -9
  20. package/dist/modules/restApi.js.map +1 -1
  21. package/dist/modules/styles.js +1 -1
  22. package/dist/modules/utils.d.ts +1 -1
  23. package/dist/modules/utils.d.ts.map +1 -1
  24. package/dist/modules/utils.js +3 -5
  25. package/dist/modules/utils.js.map +1 -1
  26. package/dist/servers/express.d.ts +13 -7
  27. package/dist/servers/express.d.ts.map +1 -1
  28. package/dist/servers/express.js +141 -1
  29. package/dist/servers/express.js.map +1 -1
  30. package/dist/servers/openapi.d.ts +25 -0
  31. package/dist/servers/openapi.d.ts.map +1 -0
  32. package/dist/servers/openapi.js +126 -0
  33. package/dist/servers/openapi.js.map +1 -0
  34. package/dist/spa/package-lock.json +41 -0
  35. package/dist/spa/package.json +4 -0
  36. package/dist/spa/pnpm-lock.yaml +38 -0
  37. package/dist/spa/src/App.vue +77 -76
  38. package/dist/spa/src/afcl/Button.vue +2 -3
  39. package/dist/spa/src/afcl/Dialog.vue +1 -1
  40. package/dist/spa/src/afcl/Input.vue +1 -1
  41. package/dist/spa/src/afcl/Select.vue +8 -2
  42. package/dist/spa/src/afcl/Skeleton.vue +5 -0
  43. package/dist/spa/src/afcl/Spinner.vue +1 -1
  44. package/dist/spa/src/components/CallActionWrapper.vue +1 -1
  45. package/dist/spa/src/components/ColumnValueInput.vue +16 -3
  46. package/dist/spa/src/components/ColumnValueInputWrapper.vue +25 -2
  47. package/dist/spa/src/components/CustomRangePicker.vue +16 -14
  48. package/dist/spa/src/components/Filters.vue +95 -63
  49. package/dist/spa/src/components/GroupsTable.vue +9 -6
  50. package/dist/spa/src/components/MenuLink.vue +2 -2
  51. package/dist/spa/src/components/ResourceForm.vue +101 -7
  52. package/dist/spa/src/components/ResourceListTable.vue +14 -8
  53. package/dist/spa/src/components/ShowTable.vue +1 -1
  54. package/dist/spa/src/components/Sidebar.vue +29 -8
  55. package/dist/spa/src/components/ThreeDotsMenu.vue +25 -10
  56. package/dist/spa/src/components/ValueRenderer.vue +1 -0
  57. package/dist/spa/src/spa_types/core.ts +32 -0
  58. package/dist/spa/src/stores/filters.ts +16 -12
  59. package/dist/spa/src/types/Back.ts +137 -26
  60. package/dist/spa/src/types/Common.ts +24 -5
  61. package/dist/spa/src/types/adapters/CompletionAdapter.ts +27 -5
  62. package/dist/spa/src/types/adapters/index.ts +2 -2
  63. package/dist/spa/src/utils/createEditUtils.ts +65 -0
  64. package/dist/spa/src/utils/index.ts +2 -1
  65. package/dist/spa/src/utils/utils.ts +42 -7
  66. package/dist/spa/src/utils.ts +2 -1
  67. package/dist/spa/src/views/CreateEditSkeleton.vue +78 -0
  68. package/dist/spa/src/views/CreateView.vue +24 -50
  69. package/dist/spa/src/views/EditView.vue +23 -40
  70. package/dist/spa/src/views/ListView.vue +22 -32
  71. package/dist/spa/src/views/ShowView.vue +66 -24
  72. package/dist/types/Back.d.ts +140 -32
  73. package/dist/types/Back.d.ts.map +1 -1
  74. package/dist/types/Back.js.map +1 -1
  75. package/dist/types/Common.d.ts +31 -5
  76. package/dist/types/Common.d.ts.map +1 -1
  77. package/dist/types/Common.js.map +1 -1
  78. package/dist/types/adapters/CompletionAdapter.d.ts +18 -3
  79. package/dist/types/adapters/CompletionAdapter.d.ts.map +1 -1
  80. package/dist/types/adapters/index.d.ts +1 -1
  81. package/dist/types/adapters/index.d.ts.map +1 -1
  82. package/package.json +11 -6
@@ -1,8 +1,8 @@
1
1
  export type { EmailAdapter } from './EmailAdapter.js';
2
- export type { CompletionAdapter } from './CompletionAdapter.js';
2
+ export type { CompletionAdapter, CompletionStreamEvent } from './CompletionAdapter.js';
3
3
  export type { ImageGenerationAdapter } from './ImageGenerationAdapter.js';
4
4
  export type { KeyValueAdapter } from './KeyValueAdapter.js';
5
5
  export type { ImageVisionAdapter } from './ImageVisionAdapter.js';
6
6
  export type { OAuth2Adapter } from './OAuth2Adapter.js';
7
7
  export type { StorageAdapter } from './StorageAdapter.js';
8
- export type { CaptchaAdapter } from './CaptchaAdapter.js';
8
+ export type { CaptchaAdapter } from './CaptchaAdapter.js';
@@ -0,0 +1,65 @@
1
+ import type { AdminForthResourceColumn } from '@/types/Back';
2
+ import { useAdminforth } from '@/adminforth';
3
+ import { type Ref, nextTick } from 'vue';
4
+
5
+ export function scrollToInvalidField(resourceFormRef: any, t: (key: string) => string) {
6
+ const { alert } = useAdminforth();
7
+ let columnsWithErrors: {column: AdminForthResourceColumn, error: string}[] = [];
8
+ for (const column of resourceFormRef.value?.editableColumns || []) {
9
+ if (resourceFormRef.value?.columnsWithErrors[column.name]) {
10
+ columnsWithErrors.push({
11
+ column,
12
+ error: resourceFormRef.value?.columnsWithErrors[column.name]
13
+ });
14
+ }
15
+ }
16
+ 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>';
17
+ alert({
18
+ messageHtml: errorMessage,
19
+ variant: 'danger'
20
+ });
21
+ const firstInvalidElement = document.querySelector('.af-invalid-field-message');
22
+ if (firstInvalidElement) {
23
+ firstInvalidElement.scrollIntoView({ behavior: 'smooth', block: 'center' });
24
+ }
25
+ }
26
+
27
+ export async function saveRecordPreparations(
28
+ viewMode: 'create' | 'edit',
29
+ validatingMode: Ref<boolean>,
30
+ resourceFormRef: Ref<any>,
31
+ isValid: Ref<boolean>,
32
+ t: (key: string) => string,
33
+ saving: Ref<boolean>,
34
+ runSaveInterceptors: any,
35
+ record: Ref<Record<string, any>>,
36
+ coreStore: any,
37
+ route: any
38
+ ) {
39
+ validatingMode.value = true;
40
+ await nextTick();
41
+ //wait for response for the user validation function if it exists
42
+ while (1) {
43
+ if (resourceFormRef.value?.isValidating) {
44
+ await new Promise(resolve => setTimeout(resolve, 100));
45
+ } else {
46
+ break;
47
+ }
48
+ }
49
+ if (!isValid.value) {
50
+ await nextTick();
51
+ scrollToInvalidField(resourceFormRef, t);
52
+ return;
53
+ } else {
54
+ validatingMode.value = false;
55
+ }
56
+
57
+ saving.value = true;
58
+ const interceptorsResult = await runSaveInterceptors({
59
+ action: viewMode,
60
+ values: record.value,
61
+ resource: coreStore.resource,
62
+ resourceId: route.params.resourceId as string,
63
+ });
64
+ return interceptorsResult;
65
+ }
@@ -1,2 +1,3 @@
1
1
  export * from './utils';
2
- export * from './listUtils';
2
+ export * from './listUtils';
3
+ export * from './createEditUtils';
@@ -8,7 +8,7 @@ import { Dropdown } from 'flowbite';
8
8
  import adminforth, { useAdminforth } from '../adminforth';
9
9
  import sanitizeHtml from 'sanitize-html'
10
10
  import debounce from 'debounce';
11
- import type { AdminForthResourceColumnInputCommon, Predicate } from '@/types/Common';
11
+ import type { AdminForthActionFront, AdminForthResourceColumnInputCommon, AdminForthResourceCommon, Predicate } from '@/types/Common';
12
12
  import { i18nInstance } from '../i18n'
13
13
  import { useI18n } from 'vue-i18n';
14
14
  import { onBeforeRouteLeave } from 'vue-router';
@@ -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
- if (validationArray[i].regExp) {
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(validationArray[i].regExp, flags);
209
+ const regExp = new RegExp(regExpPattern, flags);
207
210
  if (value === undefined || value === null) {
208
211
  value = '';
209
212
  }
@@ -766,6 +769,7 @@ export async function executeCustomBulkAction({
766
769
  onError,
767
770
  setLoadingState,
768
771
  confirmMessage,
772
+ resource,
769
773
  }: {
770
774
  actionId: string | number | undefined,
771
775
  resourceId: string,
@@ -775,6 +779,7 @@ export async function executeCustomBulkAction({
775
779
  onError?: (error: string) => void,
776
780
  setLoadingState?: (loading: boolean) => void,
777
781
  confirmMessage?: string,
782
+ resource?: AdminForthResourceCommon,
778
783
  }): Promise<any> {
779
784
  if (!recordIds || recordIds.length === 0) {
780
785
  if (onError) {
@@ -796,7 +801,38 @@ export async function executeCustomBulkAction({
796
801
  setLoadingState?.(true);
797
802
 
798
803
  try {
799
- // Execute action for all records in parallel using Promise.all
804
+ const action = resource?.options?.actions?.find((a: any) => a.id === actionId) as AdminForthActionFront | undefined;
805
+
806
+ if (action?.hasBulkHandler && action?.showIn?.bulkButton) {
807
+ const result = await callAdminForthApi({
808
+ path: '/start_custom_bulk_action',
809
+ method: 'POST',
810
+ body: {
811
+ resourceId,
812
+ actionId,
813
+ recordIds,
814
+ extra: extra || {},
815
+ }
816
+ });
817
+
818
+ if (result?.ok) {
819
+ if (onSuccess) {
820
+ await onSuccess([result]);
821
+ }
822
+ return { ok: true, results: [result] };
823
+ }
824
+
825
+ if (result?.error) {
826
+ if (onError) {
827
+ onError(result.error);
828
+ }
829
+ return { error: result.error };
830
+ }
831
+
832
+ return result;
833
+ }
834
+
835
+ // Per-record parallel calls (legacy path)
800
836
  const results = await Promise.all(
801
837
  recordIds.map(recordId =>
802
838
  callAdminForthApi({
@@ -811,7 +847,6 @@ export async function executeCustomBulkAction({
811
847
  })
812
848
  )
813
849
  );
814
-
815
850
  const lastResult = results[results.length - 1];
816
851
  if (lastResult?.redirectUrl) {
817
852
  if (lastResult.redirectUrl.includes('target=_blank')) {
@@ -1,2 +1,3 @@
1
1
  export * from './utils/utils';
2
- export * from './utils/listUtils';
2
+ export * from './utils/listUtils';
3
+ export * from './utils/createEditUtils';
@@ -0,0 +1,78 @@
1
+ <template>
2
+ <div class="w-full mt-[36px]">
3
+ <div class="w-full border dark:border-darkFormBorder border-gray-200 rounded-lg overflow-hidden shadow-resourseFormShadow dark:shadow-darkResourseFormShadow bg-white dark:bg-darkForm">
4
+
5
+ <div class="flex px-6 items-center border-b border-gray-200 dark:border-darkFormBorder bg-lightFormHeading dark:bg-darkFormHeading" style="height: 40px;">
6
+ <div class="w-[208px] flex-shrink-0 pr-6 text-xs text-lightListTableHeadingText uppercase dark:text-darkListTableHeadingText font-bold">
7
+ {{ $t('Field') }}
8
+ </div>
9
+ <div class="flex-1 text-xs text-lightListTableHeadingText uppercase dark:text-darkListTableHeadingText font-bold">
10
+ {{ $t('Value') }}
11
+ </div>
12
+ </div>
13
+
14
+ <div v-for="i in 5" :key="i"
15
+ class="flex items-center bg-lightForm dark:bg-darkForm border-b border-gray-100 dark:border-darkFormBorder"
16
+ :style="{ height: i === 2 ? '95px' : '75px' }"
17
+ >
18
+ <div class="w-[208px] flex-shrink-0 px-6 flex items-center gap-1">
19
+ <Skeleton class="w-24 h-[10px]" />
20
+ </div>
21
+
22
+ <div class="flex-1 px-6">
23
+ <div v-if="i === 2">
24
+ <Skeleton type="input" class="h-[42px] w-[160px]" />
25
+ <Skeleton class="mt-1 h-[12px] w-20" />
26
+ </div>
27
+ <Skeleton type="input" v-else-if="i === 4 || i === 5" class="h-[42px] w-[160px]" />
28
+ <Skeleton v-else type="input" class="h-[42px] w-full" />
29
+ </div>
30
+ </div>
31
+
32
+ <div class="flex items-start bg-lightForm dark:bg-darkForm" style="height: 759px;">
33
+ <div class="w-[208px] flex-shrink-0 px-6 pt-7">
34
+ <Skeleton class="w-24 h-[10px]" />
35
+ </div>
36
+
37
+ <div class="flex-1 px-6 pt-4 h-full flex flex-col">
38
+ <div class="flex flex-wrap items-center gap-3 p-1.5 border border-gray-300 dark:border-gray-600 rounded-t-lg bg-gray-50 dark:bg-gray-800 w-full box-border h-[44px]">
39
+ <template v-for="btn in skeletonButtons" :key="btn.id">
40
+ <div class=" animate-pulse flex items-center justify-center h-8 px-1 text-gray-300 dark:text-gray-600">
41
+ <component :is="btn.icon" class="w-5 h-5" />
42
+ </div>
43
+ <div v-if="btn.sep" class="w-px h-4 bg-gray-300 dark:bg-gray-600 mx-1"></div>
44
+ </template>
45
+ </div>
46
+ <div class="flex-1 animate-pulse bg-white dark:bg-gray-950 border-x border-b border-gray-200 dark:border-gray-700 rounded-b-lg w-full shadow-inner"></div>
47
+ <div class="h-10"></div>
48
+ </div>
49
+ </div>
50
+ </div>
51
+ </div>
52
+ </template>
53
+
54
+ <script setup lang="ts">
55
+ import { markRaw } from 'vue';
56
+ import { IconExclamationCircleSolid } from '@iconify-prerendered/vue-flowbite';
57
+ import {
58
+ IconLinkOutline, IconCodeOutline, IconRectangleListOutline,
59
+ IconOrderedListOutline, IconLetterBoldOutline, IconLetterUnderlineOutline,
60
+ IconLetterItalicOutline, IconTextSlashOutline
61
+ } from '@iconify-prerendered/vue-flowbite';
62
+ import { IconH116Solid, IconH216Solid, IconH316Solid } from '@iconify-prerendered/vue-heroicons';
63
+ import { Skeleton } from '@/afcl';
64
+
65
+ const skeletonButtons = [
66
+ { id: 'bold', icon: markRaw(IconLetterBoldOutline), sep: false },
67
+ { id: 'italic', icon: markRaw(IconLetterItalicOutline), sep: false },
68
+ { id: 'underline', icon: markRaw(IconLetterUnderlineOutline), sep: false },
69
+ { id: 'strike', icon: markRaw(IconTextSlashOutline), sep: true },
70
+ { id: 'h1', icon: markRaw(IconH116Solid), sep: false },
71
+ { id: 'h2', icon: markRaw(IconH216Solid), sep: false },
72
+ { id: 'h3', icon: markRaw(IconH316Solid), sep: true },
73
+ { id: 'ul', icon: markRaw(IconRectangleListOutline), sep: false },
74
+ { id: 'ol', icon: markRaw(IconOrderedListOutline), sep: false },
75
+ { id: 'link', icon: markRaw(IconLinkOutline), sep: false },
76
+ { id: 'codeBlock', icon: markRaw(IconCodeOutline), sep: false },
77
+ ];
78
+ </script>
@@ -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 || (validating && !isValid)"
23
+ :disabled="saving || (validatingMode && !isValid) || resourceFormRef?.isValidating"
24
24
  >
25
- <svg v-if="saving"
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>
@@ -44,7 +42,7 @@
44
42
  :adminUser="coreStore.adminUser"
45
43
  />
46
44
 
47
- <SingleSkeletLoader v-if="loading"></SingleSkeletLoader>
45
+ <CreateEditSkeleton v-if="loading"></CreateEditSkeleton>
48
46
 
49
47
 
50
48
  <ResourceForm
@@ -54,7 +52,7 @@
54
52
  :resource="coreStore.resource!"
55
53
  @update:record="onUpdateRecord"
56
54
  @update:isValid="isValid = $event"
57
- :validating="validating"
55
+ :validatingMode="validatingMode"
58
56
  :source="'create'"
59
57
  :readonlyColumns="readonlyColumns"
60
58
  >
@@ -81,18 +79,19 @@ 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, watch, nextTick } from 'vue';
85
- import { useRoute, useRouter, onBeforeRouteLeave } from 'vue-router';
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 type { AdminForthResourceColumn } from '@/types/Back';
89
+ import { saveRecordPreparations } from '@/utils';
90
+ import { Spinner } from '@/afcl'
91
+ import CreateEditSkeleton from './CreateEditSkeleton.vue';
93
92
 
94
93
  const isValid = ref(false);
95
- const validating = ref(false);
94
+ const validatingMode = ref(false);
96
95
 
97
96
  const loading = ref(true);
98
97
  const saving = ref(false);
@@ -195,28 +194,22 @@ onMounted(async () => {
195
194
  });
196
195
 
197
196
  async function saveRecord() {
198
- if (!isValid.value) {
199
- validating.value = true;
200
- await nextTick();
201
- scrollToInvalidField();
202
- return;
203
- } else {
204
- validating.value = false;
205
- }
197
+ const interceptorsResult = await saveRecordPreparations(
198
+ 'create',
199
+ validatingMode,
200
+ resourceFormRef,
201
+ isValid,
202
+ t,
203
+ saving,
204
+ runSaveInterceptors,
205
+ record,
206
+ coreStore,
207
+ route
208
+ );
209
+
206
210
  const requiredColumns = coreStore.resource?.columns.filter(c => c.required?.create === true) || [];
207
211
  const requiredColumnsToSkip = requiredColumns.filter(c => checkShowIf(c, record.value, coreStore.resource?.columns || []) === false);
208
- saving.value = true;
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
- }
212
+
220
213
  const interceptorConfirmationResult = (interceptorsResult.extra as Record<string, any>)?.confirmationResult;
221
214
  const response = await callAdminForthApi({
222
215
  method: 'POST',
@@ -254,23 +247,4 @@ async function saveRecord() {
254
247
  saving.value = false;
255
248
  }
256
249
 
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
250
  </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 || (validating && !isValid)"
22
+ :disabled="saving || (validatingMode && !isValid) || resourceFormRef?.isValidating"
23
23
  >
24
- <IconFloppyDiskSolid class="w-4 h-4" />
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
 
@@ -40,7 +41,7 @@
40
41
  :adminUser="coreStore.adminUser"
41
42
  />
42
43
 
43
- <SingleSkeletLoader v-if="loading"></SingleSkeletLoader>
44
+ <CreateEditSkeleton v-if="loading"></CreateEditSkeleton>
44
45
 
45
46
  <ResourceForm
46
47
  v-else-if="coreStore.resource"
@@ -50,7 +51,7 @@
50
51
  :adminUser="coreStore.adminUser"
51
52
  @update:record="onUpdateRecord"
52
53
  @update:isValid="isValid = $event"
53
- :validating="validating"
54
+ :validatingMode="validatingMode"
54
55
  :source="'edit'"
55
56
  >
56
57
  </ResourceForm>
@@ -85,13 +86,16 @@ 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'
91
+ import CreateEditSkeleton from './CreateEditSkeleton.vue';
88
92
 
89
93
  const { t } = useI18n();
90
94
  const coreStore = useCoreStore();
91
95
  const { clearSaveInterceptors, runSaveInterceptors, alert, confirm } = useAdminforth();
92
96
 
93
97
  const isValid = ref(false);
94
- const validating = ref(false);
98
+ const validatingMode = ref(false);
95
99
 
96
100
  const route = useRoute();
97
101
  const router = useRouter();
@@ -144,7 +148,7 @@ const editableRecord = computed(() => {
144
148
  coreStore.resource.columns.forEach(column => {
145
149
  if (column.foreignResource) {
146
150
  if (column.isArray?.enabled) {
147
- newRecord[column.name] = newRecord[column.name]?.map((fr: { pk: any }) => fr.pk);
151
+ newRecord[column.name] = newRecord[column.name]?.map((fr: { pk: any }) => fr?.pk);
148
152
  } else {
149
153
  newRecord[column.name] = newRecord[column.name]?.pk;
150
154
  }
@@ -180,22 +184,20 @@ onMounted(async () => {
180
184
  });
181
185
 
182
186
  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
187
 
192
- saving.value = true;
193
- const interceptorsResult = await runSaveInterceptors({
194
- action: 'edit',
195
- values: record.value,
196
- resource: coreStore.resource,
197
- resourceId: route.params.resourceId as string,
198
- });
188
+ const interceptorsResult = await saveRecordPreparations(
189
+ 'edit',
190
+ validatingMode,
191
+ resourceFormRef,
192
+ isValid,
193
+ t,
194
+ saving,
195
+ runSaveInterceptors,
196
+ record,
197
+ coreStore,
198
+ route
199
+ );
200
+
199
201
  if (!interceptorsResult.ok) {
200
202
  saving.value = false;
201
203
  if (interceptorsResult.error) showErrorTost(interceptorsResult.error);
@@ -256,23 +258,4 @@ async function saveRecord() {
256
258
  saving.value = false;
257
259
  }
258
260
 
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
261
  </script>
@@ -2,10 +2,11 @@
2
2
  <div class="relative flex flex-col max-w-full w-full">
3
3
  <Teleport to="body">
4
4
  <Filters
5
- :columns="coreStore.resource?.columns"
5
+ :columns="coreStore.resource?.columns as AdminForthResourceColumnCommon[] || []"
6
6
  :columnsMinMax="columnsMinMax"
7
7
  :show="filtersShow"
8
8
  @hide="filtersShow = false"
9
+ :filtersStore="filtersStore"
9
10
  />
10
11
  </Teleport>
11
12
 
@@ -69,19 +70,10 @@
69
70
  v-if="action.icon && !bulkActionLoadingStates[action.id!]"
70
71
  :is="getIcon(action.icon)"
71
72
  class="w-5 h-5 transition duration-75 group-hover:text-gray-900 dark:group-hover:text-white"></component>
72
- <div v-if="bulkActionLoadingStates[action.id!]">
73
- <svg
74
- aria-hidden="true"
75
- class="w-5 h-5 animate-spin text-gray-200 dark:text-gray-500 fill-gray-500 dark:fill-gray-300"
76
- viewBox="0 0 100 101"
77
- fill="none"
78
- xmlns="http://www.w3.org/2000/svg"
79
- >
80
- <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"/>
81
- <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"/>
82
- </svg>
83
- <span class="sr-only">Loading...</span>
84
- </div>
73
+ <Spinner
74
+ v-if="bulkActionLoadingStates[action.id!]"
75
+ class="w-5 h-5 text-gray-200 dark:text-gray-500 fill-gray-500 dark:fill-gray-300"
76
+ />
85
77
  {{ `${action.label} (${checkboxes.length})` }}
86
78
  <div v-if="action.badge" class="text-white bg-gradient-to-r from-purple-500
87
79
  via-purple-600 to-purple-700 hover:bg-gradient-to-br focus:ring-4 focus:outline-none
@@ -98,25 +90,22 @@
98
90
  <button
99
91
  :key="action.id"
100
92
  @click="startCustomBulkActionInner(action.id!)"
101
- class="flex gap-1 items-center py-1 px-3 text-sm font-medium text-lightListViewButtonText focus:outline-none bg-lightListViewButtonBackground rounded-default border border-lightListViewButtonBorder hover:bg-lightListViewButtonBackgroundHover hover:text-lightListViewButtonTextHover focus:z-10 focus:ring-4 focus:ring-lightListViewButtonFocusRing dark:focus:ring-darkListViewButtonFocusRing dark:bg-darkListViewButtonBackground dark:text-darkListViewButtonText dark:border-darkListViewButtonBorder dark:hover:text-darkListViewButtonTextHover dark:hover:bg-darkListViewButtonBackgroundHover"
93
+ class="flex gap-1 items-center py-1 px-3 text-sm font-medium text-lightListViewButtonText
94
+ focus:outline-none bg-lightListViewButtonBackground rounded-default border h-[34px]
95
+ border-lightListViewButtonBorder hover:bg-lightListViewButtonBackgroundHover
96
+ hover:text-lightListViewButtonTextHover focus:z-10 focus:ring-4 af-button-shadow
97
+ focus:ring-lightListViewButtonFocusRing dark:focus:ring-darkListViewButtonFocusRing
98
+ dark:bg-darkListViewButtonBackground dark:text-darkListViewButtonText dark:border-darkListViewButtonBorder
99
+ dark:hover:text-darkListViewButtonTextHover dark:hover:bg-darkListViewButtonBackgroundHover"
102
100
  >
103
101
  <component
104
102
  v-if="action.icon && !customActionLoadingStates[action.id!]"
105
103
  :is="getIcon(action.icon)"
106
104
  class="w-5 h-5 transition duration-75 group-hover:text-gray-900 dark:group-hover:text-white"></component>
107
- <div v-if="customActionLoadingStates[action.id!]">
108
- <svg
109
- aria-hidden="true"
110
- class="w-5 h-5 animate-spin text-gray-200 dark:text-gray-500 fill-gray-500 dark:fill-gray-300"
111
- viewBox="0 0 100 101"
112
- fill="none"
113
- xmlns="http://www.w3.org/2000/svg"
114
- >
115
- <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"/>
116
- <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"/>
117
- </svg>
118
- <span class="sr-only">Loading...</span>
119
- </div>
105
+ <Spinner
106
+ v-if="customActionLoadingStates[action.id!]"
107
+ class="w-5 h-5 text-gray-200 dark:text-gray-500 fill-gray-500 dark:fill-gray-300"
108
+ />
120
109
  {{ `${action.name} (${checkboxes.length})` }}
121
110
  </button>
122
111
  </div>
@@ -233,8 +222,8 @@ import { computed, onMounted, onUnmounted, ref, watch, type Ref } from 'vue';
233
222
  import { useRoute } from 'vue-router';
234
223
  import { getCustomComponent, initThreeDotsDropdown, getList, startBulkAction } from '@/utils';
235
224
  import ThreeDotsMenu from '@/components/ThreeDotsMenu.vue';
236
- import { Tooltip } from '@/afcl'
237
- import type { AdminForthComponentDeclaration, AdminForthComponentDeclarationFull } from '@/types/Common';
225
+ import { Tooltip, Spinner } from '@/afcl'
226
+ import type { AdminForthComponentDeclaration, AdminForthComponentDeclarationFull, AdminForthFilterOperators, AdminForthResourceColumnCommon } from '@/types/Common';
238
227
 
239
228
 
240
229
  import {
@@ -344,6 +333,7 @@ async function startCustomBulkActionInner(actionId: string | number) {
344
333
  resourceId: route.params.resourceId as string,
345
334
  recordIds: checkboxes.value,
346
335
  confirmMessage: action?.bulkConfirmationMessage,
336
+ resource: coreStore.resource!,
347
337
  setLoadingState: (loading: boolean) => {
348
338
  customActionLoadingStates.value[actionId] = loading;
349
339
  },
@@ -354,7 +344,7 @@ async function startCustomBulkActionInner(actionId: string | number) {
354
344
  const successResults = results.filter(r => r?.successMessage);
355
345
  if (successResults.length > 0) {
356
346
  alert({
357
- message: action?.bulkSuccessMessage || `${successResults.length} out of ${results.length} items processed successfully`,
347
+ message: action?.bulkSuccessMessage ? action.bulkSuccessMessage : action?.hasBulkHandler ? successResults[0].successMessage : `${successResults.length} out of ${results.length} items processed successfully`,
358
348
  variant: 'success'
359
349
  });
360
350
  }
@@ -413,7 +403,7 @@ async function init() {
413
403
  const [_, field, operator] = k.split('__');
414
404
  return {
415
405
  field,
416
- operator,
406
+ operator: operator as AdminForthFilterOperators,
417
407
  value: JSON.parse((route.query[k] as string))
418
408
  }
419
409
  });