adminforth 2.27.0-next.8 → 2.27.0-test.1

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 (52) hide show
  1. package/commands/callTsProxy.js +10 -5
  2. package/commands/proxy.ts +18 -10
  3. package/dist/commands/proxy.js +14 -10
  4. package/dist/commands/proxy.js.map +1 -1
  5. package/dist/dataConnectors/baseConnector.d.ts.map +1 -1
  6. package/dist/dataConnectors/baseConnector.js +8 -1
  7. package/dist/dataConnectors/baseConnector.js.map +1 -1
  8. package/dist/dataConnectors/clickhouse.js +1 -1
  9. package/dist/dataConnectors/clickhouse.js.map +1 -1
  10. package/dist/dataConnectors/mysql.js +1 -1
  11. package/dist/dataConnectors/mysql.js.map +1 -1
  12. package/dist/dataConnectors/sqlite.d.ts.map +1 -1
  13. package/dist/dataConnectors/sqlite.js +2 -0
  14. package/dist/dataConnectors/sqlite.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 +77 -4
  20. package/dist/modules/restApi.js.map +1 -1
  21. package/dist/modules/styles.js +1 -1
  22. package/dist/spa/package-lock.json +41 -0
  23. package/dist/spa/package.json +3 -0
  24. package/dist/spa/pnpm-lock.yaml +38 -0
  25. package/dist/spa/src/afcl/Select.vue +5 -1
  26. package/dist/spa/src/components/CallActionWrapper.vue +1 -1
  27. package/dist/spa/src/components/ColumnValueInput.vue +16 -3
  28. package/dist/spa/src/components/ColumnValueInputWrapper.vue +25 -2
  29. package/dist/spa/src/components/Filters.vue +23 -2
  30. package/dist/spa/src/components/GroupsTable.vue +9 -6
  31. package/dist/spa/src/components/ResourceForm.vue +100 -6
  32. package/dist/spa/src/components/ResourceListTable.vue +15 -2
  33. package/dist/spa/src/components/ShowTable.vue +1 -1
  34. package/dist/spa/src/components/ThreeDotsMenu.vue +20 -3
  35. package/dist/spa/src/types/Back.ts +16 -1
  36. package/dist/spa/src/types/Common.ts +19 -4
  37. package/dist/spa/src/utils/createEditUtils.ts +65 -0
  38. package/dist/spa/src/utils/index.ts +2 -1
  39. package/dist/spa/src/utils/utils.ts +38 -5
  40. package/dist/spa/src/utils.ts +2 -1
  41. package/dist/spa/src/views/CreateView.vue +22 -49
  42. package/dist/spa/src/views/EditView.vue +20 -38
  43. package/dist/spa/src/views/ListView.vue +9 -2
  44. package/dist/spa/src/views/ShowView.vue +62 -12
  45. package/dist/spa/tsconfig.app.json +1 -0
  46. package/dist/types/Back.d.ts +16 -1
  47. package/dist/types/Back.d.ts.map +1 -1
  48. package/dist/types/Back.js.map +1 -1
  49. package/dist/types/Common.d.ts +24 -4
  50. package/dist/types/Common.d.ts.map +1 -1
  51. package/dist/types/Common.js.map +1 -1
  52. package/package.json +4 -3
@@ -53,23 +53,46 @@
53
53
  @update:inValidity="$emit('update:inValidity', { name: column.name, value: $event })"
54
54
  @update:emptiness="$emit('update:emptiness', { name: column.name, value: $event })"
55
55
  />
56
+ <div v-if="columnsWithErrors[column.name] && validatingMode && !isValidating" class="af-invalid-field-message mt-1 text-xs text-lightInputErrorColor dark:text-darkInputErrorColor">{{ columnsWithErrors[column.name] }}</div>
57
+ <Spinner v-if="shouldWeShowSpinner" class="w-4 mt-1"/>
58
+ <div v-if="column.editingNote && column.editingNote[mode]" class="mt-1 text-xs text-lightFormFieldTextColor dark:text-darkFormFieldTextColor">{{ column.editingNote[mode] }}</div>
56
59
  </template>
57
60
 
58
61
  <script setup lang="ts">
59
62
  import { IconPlusOutline } from '@iconify-prerendered/vue-flowbite';
60
63
  import ColumnValueInput from "./ColumnValueInput.vue";
61
- import { ref, nextTick } from 'vue';
64
+ import { ref, watch, nextTick } from 'vue';
65
+ import { Spinner } from '@/afcl';
62
66
 
63
67
  const props = defineProps<{
64
68
  source: 'create' | 'edit',
65
69
  column: any,
66
70
  currentValues: any,
67
- mode: string,
71
+ mode: 'create' | 'edit',
68
72
  columnOptions: any,
69
73
  unmasked: any,
70
74
  setCurrentValue: Function,
71
75
  readonly?: boolean,
76
+ columnsWithErrors: Record<string, string>,
77
+ isValidating: boolean,
78
+ validatingMode: boolean,
72
79
  }>();
80
+
81
+ const shouldWeShowSpinner = ref(false);
82
+
83
+
84
+ watch(() => props.currentValues[props.column.name], async (newVal) => {
85
+ await nextTick();
86
+ if (props.isValidating) {
87
+ shouldWeShowSpinner.value = true;
88
+ }
89
+ });
90
+
91
+ watch(() => [props.isValidating], () => {
92
+ if (!props.isValidating) {
93
+ shouldWeShowSpinner.value = false;
94
+ }
95
+ });
73
96
 
74
97
  const emit = defineEmits(['update:unmasked', 'update:inValidity', 'update:emptiness', 'focus-last-input']);
75
98
 
@@ -123,9 +123,9 @@
123
123
  :min="getFilterMinValue(c.name)"
124
124
  :max="getFilterMaxValue(c.name)"
125
125
  :valueStart="getFilterItem({ column: c, operator: 'gte' })"
126
- @update:valueStart="onFilterInput[c.name]({ column: c, operator: 'gte', value: ($event !== '' && $event !== null) ? (c.type === 'decimal' ? String($event) : $event) : undefined })"
126
+ @update:valueStart="(val) => rangeChangeHandler((val !== '' && val !== null) ? (c.type === 'decimal' ? String(val) : val) : undefined, c, 'gte')"
127
127
  :valueEnd="getFilterItem({ column: c, operator: 'lte' })"
128
- @update:valueEnd="onFilterInput[c.name]({ column: c, operator: 'lte', value: ($event !== '' && $event !== null) ? (c.type === 'decimal' ? String($event) : $event) : undefined })"
128
+ @update:valueEnd="(val) => rangeChangeHandler((val !== '' && val !== null) ? (c.type === 'decimal' ? String(val) : val) : undefined, c, 'lte')"
129
129
  />
130
130
 
131
131
  <div v-else-if="['integer', 'decimal', 'float'].includes(c.type)" class="flex gap-2">
@@ -275,6 +275,27 @@ const onFilterInput = computed(() => {
275
275
  }, {});
276
276
  });
277
277
 
278
+ // rangeState is used for cutom range picker, because if we change two values very quickly
279
+ // in filters writes only the last one, because of debounce
280
+ const rangeState = reactive({});
281
+
282
+ const updateRange = (column) => {
283
+ debounce(() => {
284
+ const { gte, lte } = rangeState[column.name];
285
+
286
+ setFilterItem({ column, operator: 'gte', value: gte });
287
+ setFilterItem({ column, operator: 'lte', value: lte });
288
+ }, column?.filterOptions?.debounceTimeMs || 10)();
289
+ }
290
+
291
+ function rangeChangeHandler(value, column, operator) {
292
+ if (!rangeState[column.name]) {
293
+ rangeState[column.name] = { gte: null, lte: null };
294
+ }
295
+ rangeState[column.name][operator] = value;
296
+ updateRange(column);
297
+ }
298
+
278
299
  const onSearchInput = computed(() => {
279
300
  return createSearchInputHandlers(
280
301
  props.columns,
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <div class="rounded-lg shadow-resourseFormShadow dark:shadow-darkResourseFormShadow dark:shadow-2xl">
2
+ <div class="rounded-lg shadow-resourseFormShadow dark:shadow-darkResourseFormShadow dark:shadow-2xl border dark:border-darkFormBorder">
3
3
  <div v-if="group.groupName && !group.noTitle" class="text-md font-semibold px-6 py-3 flex flex-1 items-center dark:border-darkFormBorder text-lightListTableHeadingText bg-lightFormHeading dark:bg-darkFormHeading dark:text-darkListTableHeadingText rounded-t-lg">
4
4
  {{ group.groupName }}
5
5
  </div>
@@ -30,7 +30,7 @@
30
30
  <Tooltip v-if="column.required[mode]">
31
31
 
32
32
  <IconExclamationCircleSolid v-if="column.required[mode]" class="w-4 h-4"
33
- :class="(columnError(column) && validating) ? 'text-lightInputErrorColor dark:text-darkInputErrorColor' : 'text-lightRequiredIconColor dark:text-darkRequiredIconColor'"
33
+ :class="(columnsWithErrors[column.name] && validatingMode && !isValidating) ? 'text-lightInputErrorColor dark:text-darkInputErrorColor' : 'text-lightRequiredIconColor dark:text-darkRequiredIconColor'"
34
34
  />
35
35
 
36
36
  <template #tooltip>
@@ -56,9 +56,10 @@
56
56
  @update:inValidity="customComponentsInValidity[$event.name] = $event.value"
57
57
  @update:emptiness="customComponentsEmptiness[$event.name] = $event.value"
58
58
  :readonly="readonlyColumns?.includes(column.name)"
59
+ :columnsWithErrors="columnsWithErrors"
60
+ :isValidating="isValidating"
61
+ :validatingMode="validatingMode"
59
62
  />
60
- <div v-if="columnError(column) && validating" class="af-invalid-field-message mt-1 text-xs text-lightInputErrorColor dark:text-darkInputErrorColor">{{ columnError(column) }}</div>
61
- <div v-if="column.editingNote && column.editingNote[mode]" class="mt-1 text-xs text-lightFormFieldTextColor dark:text-darkFormFieldTextColor">{{ column.editingNote[mode] }}</div>
62
63
  </td>
63
64
  </tr>
64
65
  </tbody>
@@ -79,14 +80,16 @@
79
80
  const props = defineProps<{
80
81
  source: 'create' | 'edit',
81
82
  group: any,
82
- mode: string,
83
- validating: boolean,
83
+ mode: 'create' | 'edit',
84
+ validatingMode: boolean,
84
85
  currentValues: any,
85
86
  unmasked: any,
86
87
  columnError: (column: any) => string,
87
88
  setCurrentValue: (columnName: string, value: any) => void,
88
89
  columnOptions: any,
89
90
  readonlyColumns?: string[],
91
+ columnsWithErrors: Record<string, string>,
92
+ isValidating: boolean
90
93
  }>();
91
94
 
92
95
  const customComponentsInValidity: Ref<Record<string, boolean>> = ref({});
@@ -13,11 +13,13 @@
13
13
  :mode="mode"
14
14
  :unmasked="unmasked"
15
15
  :columnOptions="columnOptions"
16
- :validating="validating"
16
+ :validatingMode="validatingMode"
17
17
  :columnError="columnError"
18
18
  :setCurrentValue="setCurrentValue"
19
19
  @update:customComponentsInValidity="(data) => customComponentsInValidity = { ...customComponentsInValidity, ...data }"
20
20
  @update:customComponentsEmptiness="(data) => customComponentsEmptiness = { ...customComponentsEmptiness, ...data }"
21
+ :columnsWithErrors="columnsWithErrors"
22
+ :isValidating="isValidating"
21
23
  />
22
24
  </div>
23
25
  <div v-else class="flex flex-col gap-4">
@@ -31,11 +33,13 @@
31
33
  :mode="mode"
32
34
  :unmasked="unmasked"
33
35
  :columnOptions="columnOptions"
34
- :validating="validating"
36
+ :validatingMode="validatingMode"
35
37
  :columnError="columnError"
36
38
  :setCurrentValue="setCurrentValue"
37
39
  @update:customComponentsInValidity="(data) => customComponentsInValidity = { ...customComponentsInValidity, ...data }"
38
40
  @update:customComponentsEmptiness="(data) => customComponentsEmptiness = { ...customComponentsEmptiness, ...data }"
41
+ :columnsWithErrors="columnsWithErrors"
42
+ :isValidating="isValidating"
39
43
  />
40
44
  </template>
41
45
  <div v-if="otherColumns?.length || 0 > 0">
@@ -48,11 +52,13 @@
48
52
  :mode="mode"
49
53
  :unmasked="unmasked"
50
54
  :columnOptions="columnOptions"
51
- :validating="validating"
55
+ :validatingMode="validatingMode"
52
56
  :columnError="columnError"
53
57
  :setCurrentValue="setCurrentValue"
54
58
  @update:customComponentsInValidity="(data) => customComponentsInValidity = { ...customComponentsInValidity, ...data }"
55
59
  @update:customComponentsEmptiness="(data) => customComponentsEmptiness = { ...customComponentsEmptiness, ...data }"
60
+ :columnsWithErrors="columnsWithErrors"
61
+ :isValidating="isValidating"
56
62
  />
57
63
  </div>
58
64
  </div>
@@ -71,16 +77,20 @@ import { useCoreStore } from "@/stores/core";
71
77
  import GroupsTable from '@/components/GroupsTable.vue';
72
78
  import { useI18n } from 'vue-i18n';
73
79
  import { type AdminForthResourceColumnCommon, type AdminForthResourceCommon } from '@/types/Common';
80
+ import { Mutex } from 'async-mutex';
81
+ import debounce from 'lodash.debounce';
74
82
 
75
83
  const { t } = useI18n();
76
84
 
85
+ const mutex = new Mutex();
86
+
77
87
  const coreStore = useCoreStore();
78
88
  const router = useRouter();
79
89
  const route = useRoute();
80
90
  const props = defineProps<{
81
91
  resource: AdminForthResourceCommon,
82
92
  record: any,
83
- validating: boolean,
93
+ validatingMode: boolean,
84
94
  source: 'create' | 'edit',
85
95
  readonlyColumns?: string[],
86
96
  }>();
@@ -99,6 +109,11 @@ const columnOptions = ref<Record<string, any[]>>({});
99
109
  const columnLoadingState = reactive<Record<string, { loading: boolean; hasMore: boolean }>>({});
100
110
  const columnOffsets = reactive<Record<string, number>>({});
101
111
  const columnEmptyResultsCount = reactive<Record<string, number>>({});
112
+ const columnsWithErrors = ref<Record<string, string>>({});
113
+ const isValidating = ref(false);
114
+ const blockSettingIsValidating = ref(false);
115
+ const isValid = ref(true);
116
+ const doesUserHaveCustomValidation = computed(() => props.resource.columns.some(column => column.validation && column.validation.some((val) => val.validator)));
102
117
 
103
118
  const columnError = (column: AdminForthResourceColumnCommon) => {
104
119
  const val = computed(() => {
@@ -329,10 +344,48 @@ const editableColumns = computed(() => {
329
344
  return props.resource?.columns?.filter(column => column.showIn?.[mode.value] && (currentValues.value ? checkShowIf(column, currentValues.value, props.resource.columns) : true));
330
345
  });
331
346
 
332
- const isValid = computed(() => {
333
- return editableColumns.value?.every(column => !columnError(column));
347
+ function checkIfColumnHasError(column: AdminForthResourceColumnCommon) {
348
+ const error = columnError(column);
349
+ if (error) {
350
+ columnsWithErrors.value[column.name] = error;
351
+ } else {
352
+ delete columnsWithErrors.value[column.name];
353
+ }
354
+ }
355
+
356
+ const checkIfAnyColumnHasErrors = () => {
357
+ return Object.keys(columnsWithErrors.value).length > 0 ? false : true;
358
+ }
359
+
360
+ const debouncedValidation = debounce(async (columns: AdminForthResourceColumnCommon[]) => {
361
+ await mutex.runExclusive(async () => {
362
+ await validateUsingUserValidationFunction(columns);
363
+ });
364
+ setIsValidatingValue(false);
365
+ isValid.value = checkIfAnyColumnHasErrors();
366
+ }, 500);
367
+
368
+ watch(() => [editableColumns.value, props.validatingMode], async () => {
369
+ setIsValidatingValue(true);
370
+
371
+ editableColumns.value?.forEach(column => {
372
+ checkIfColumnHasError(column);
373
+ });
374
+
375
+ if (props.validatingMode && doesUserHaveCustomValidation.value) {
376
+ debouncedValidation(editableColumns.value);
377
+ } else {
378
+ setIsValidatingValue(false);
379
+ isValid.value = checkIfAnyColumnHasErrors();
380
+ }
334
381
  });
335
382
 
383
+ const setIsValidatingValue = (value: boolean) => {
384
+ if (!blockSettingIsValidating.value) {
385
+ isValidating.value = value;
386
+ }
387
+ }
388
+
336
389
 
337
390
  const groups = computed(() => {
338
391
  let fieldGroupType;
@@ -381,9 +434,50 @@ watch(() => isValid.value, (value) => {
381
434
  emit('update:isValid', value);
382
435
  });
383
436
 
437
+ async function validateUsingUserValidationFunction(editableColumnsInner: AdminForthResourceColumnCommon[]): Promise<void> {
438
+ if (doesUserHaveCustomValidation.value) {
439
+ try {
440
+ blockSettingIsValidating.value = true;
441
+ const res = await callAdminForthApi({
442
+ method: 'POST',
443
+ path: '/validate_columns',
444
+ body: {
445
+ resourceId: props.resource.resourceId,
446
+ editableColumns: editableColumnsInner.map(col => {return {name: col.name, value: currentValues.value?.[col.name]} }),
447
+ record: currentValues.value,
448
+ }
449
+ })
450
+ if (res.validationResults && Object.keys(res.validationResults).length > 0) {
451
+ for (const [columnName, validationResult] of Object.entries(res.validationResults) as [string, any][]) {
452
+ if (!validationResult.isValid) {
453
+ columnsWithErrors.value[columnName] = validationResult.message || 'Invalid value';
454
+ } else {
455
+ delete columnsWithErrors.value[columnName];
456
+ }
457
+ }
458
+ const columnsToProcess = editableColumns.value.filter(col => res.validationResults[col.name] === undefined);
459
+ columnsToProcess.forEach(column => {
460
+ checkIfColumnHasError(column);
461
+ });
462
+ } else {
463
+ editableColumnsInner.forEach(column => {
464
+ checkIfColumnHasError(column);
465
+ });
466
+ }
467
+ blockSettingIsValidating.value = false;
468
+ } catch (e) {
469
+ console.error('Error during custom validation', e);
470
+ blockSettingIsValidating.value = false;
471
+ }
472
+ }
473
+ }
474
+
384
475
  defineExpose({
385
476
  columnError,
386
477
  editableColumns,
478
+ columnsWithErrors,
479
+ isValidating,
480
+ validateUsingUserValidationFunction
387
481
  })
388
482
 
389
483
  </script>
@@ -211,12 +211,25 @@
211
211
  <button
212
212
  type="button"
213
213
  class="border border-gray-300 dark:border-gray-700 dark:border-opacity-0 border-opacity-0 hover:border-opacity-100 dark:hover:border-opacity-100 rounded-md hover:bg-gray-100 dark:hover:bg-gray-800 cursor-pointer"
214
+ :disabled="!!actionLoadingStates[`${action.id}_${row._primaryKeyValue}`]"
214
215
  >
215
216
  <component
216
- v-if="action.icon"
217
+ v-if="action.icon && !actionLoadingStates[`${action.id}_${row._primaryKeyValue}`]"
217
218
  :is="getIcon(action.icon)"
218
219
  class="w-6 h-6 text-lightPrimary dark:text-darkPrimary"
219
220
  />
221
+ <svg
222
+ v-if="actionLoadingStates[`${action.id}_${row._primaryKeyValue}`]"
223
+ aria-hidden="true"
224
+ class="w-6 h-6 p-1 animate-spin text-gray-200 dark:text-gray-500 fill-gray-500 dark:fill-gray-300"
225
+ viewBox="0 0 100 101"
226
+ fill="none"
227
+ xmlns="http://www.w3.org/2000/svg"
228
+ >
229
+ <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"/>
230
+ <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"/>
231
+ </svg>
232
+ <span v-if="actionLoadingStates[`${action.id}_${row._primaryKeyValue}`]" class="sr-only">Loading...</span>
220
233
  </button>
221
234
  </component>
222
235
 
@@ -613,7 +626,7 @@ async function startCustomAction(actionId: string | number, row: any, extraData:
613
626
  recordId: row._primaryKeyValue,
614
627
  extra: extraData,
615
628
  setLoadingState: (loading: boolean) => {
616
- actionLoadingStates.value[actionId] = loading;
629
+ actionLoadingStates.value[`${actionId}_${row._primaryKeyValue}`] = loading;
617
630
  },
618
631
  onSuccess: async (data: any) => {
619
632
  emits('update:records', true);
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <div class="overflow-x-auto shadow-resourseFormShadow dark:shadow-darkResourseFormShadow"
2
+ <div class="overflow-x-auto shadow-resourseFormShadow dark:shadow-darkResourseFormShadow border dark:border-gray-700"
3
3
  :class="{'rounded-default' : isRounded}"
4
4
  >
5
5
  <div v-if="groupName && !noTitle" class="text-md font-semibold px-6 py-3 flex flex-1 items-center text-lightShowTableHeadingText bg-lightShowTableHeadingBackground dark:bg-darkShowTableHeadingBackground dark:text-darkShowTableHeadingText rounded-t-lg">
@@ -51,12 +51,25 @@
51
51
  @callAction="(payload? : Object) => handleActionClick(action, payload)"
52
52
  >
53
53
  <a @click.prevent class="block">
54
- <div class="flex items-center gap-2">
54
+ <div class="flex items-center gap-2 px-4 py-2 hover:text-lightThreeDotsMenuBodyTextHover hover:bg-lightThreeDotsMenuBodyBackgroundHover dark:hover:bg-darkThreeDotsMenuBodyBackgroundHover dark:hover:text-darkThreeDotsMenuBodyTextHover">
55
55
  <component
56
- v-if="action.icon"
56
+ v-if="action.icon && !actionLoadingStates[action.id!]"
57
57
  :is="getIcon(action.icon)"
58
58
  class="w-4 h-4 text-lightPrimary dark:text-darkPrimary"
59
59
  />
60
+ <div v-if="actionLoadingStates[action.id!]">
61
+ <svg
62
+ aria-hidden="true"
63
+ class="w-4 h-4 animate-spin text-gray-200 dark:text-gray-500 fill-gray-500 dark:fill-gray-300"
64
+ viewBox="0 0 100 101"
65
+ fill="none"
66
+ xmlns="http://www.w3.org/2000/svg"
67
+ >
68
+ <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"/>
69
+ <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"/>
70
+ </svg>
71
+ <span class="sr-only">Loading...</span>
72
+ </div>
60
73
  {{ action.name }}
61
74
  </div>
62
75
  </a>
@@ -104,6 +117,7 @@ const coreStore = useCoreStore();
104
117
  const router = useRouter();
105
118
  const threeDotsDropdownItemsRefs = ref<Array<ComponentPublicInstance | null>>([]);
106
119
  const showDropdown = ref(false);
120
+ const actionLoadingStates = ref<Record<string, boolean>>({});
107
121
  const dropdownRef = ref<HTMLElement | null>(null);
108
122
  const buttonTriggerRef = ref<HTMLElement | null>(null);
109
123
 
@@ -135,6 +149,9 @@ async function handleActionClick(action: AdminForthActionInput, payload: any) {
135
149
  resourceId: route.params.resourceId as string,
136
150
  recordId: route.params.primaryKey as string,
137
151
  extra: payload || {},
152
+ setLoadingState: (loading: boolean) => {
153
+ actionLoadingStates.value[action.id!] = loading;
154
+ },
138
155
  onSuccess: async (data: any) => {
139
156
  await coreStore.fetchRecord({
140
157
  resourceId: route.params.resourceId as string,
@@ -195,7 +212,7 @@ onUnmounted(() => {
195
212
  </script>
196
213
 
197
214
  <style lang="scss" scoped>
198
- .wrapper > * {
215
+ .wrapper {
199
216
  @apply px-4 py-2
200
217
  hover:text-lightThreeDotsMenuBodyTextHover hover:bg-lightThreeDotsMenuBodyBackgroundHover
201
218
  dark:hover:bg-darkThreeDotsMenuBodyBackgroundHover dark:hover:text-darkThreeDotsMenuBodyTextHover
@@ -1305,6 +1305,19 @@ export interface AdminForthActionInput {
1305
1305
  standardAllowedActions: AllowedActions;
1306
1306
  }) => boolean;
1307
1307
  url?: string;
1308
+ bulkHandler?: (params: {
1309
+ adminforth: IAdminForth;
1310
+ resource: AdminForthResource;
1311
+ recordIds: (string | number)[];
1312
+ adminUser: AdminUser;
1313
+ response: IAdminForthHttpResponse;
1314
+ extra?: HttpExtra;
1315
+ tr: ITranslateFunction;
1316
+ }) => Promise<{
1317
+ ok: boolean;
1318
+ error?: string;
1319
+ successMessage?: string;
1320
+ }>;
1308
1321
  action?: (params: {
1309
1322
  adminforth: IAdminForth;
1310
1323
  resource: AdminForthResource;
@@ -1312,7 +1325,7 @@ export interface AdminForthActionInput {
1312
1325
  adminUser: AdminUser;
1313
1326
  response: IAdminForthHttpResponse;
1314
1327
  extra?: HttpExtra;
1315
- tr: Function;
1328
+ tr: ITranslateFunction;
1316
1329
  }) => Promise<{
1317
1330
  ok: boolean;
1318
1331
  error?: string;
@@ -1837,6 +1850,8 @@ export interface ResourceOptionsInput extends Omit<NonNullable<AdminForthResourc
1837
1850
  /**
1838
1851
  * Custom bulk actions list. Bulk actions available in list view when user selects multiple records by
1839
1852
  * using checkboxes.
1853
+ * @deprecated Since 2.26.5. Will be removed in 3.0.0. Use `actions` instead.
1854
+
1840
1855
  */
1841
1856
  bulkActions?: Array<AdminForthBulkAction>,
1842
1857
 
@@ -303,7 +303,7 @@ export interface AdminForthComponentDeclarationFull {
303
303
  [key: string]: any,
304
304
  }
305
305
  }
306
- import { type AdminForthActionInput, type AdminForthResource } from './Back.js'
306
+ import { type IAdminForth, type AdminForthActionInput, type AdminForthResource } from './Back.js'
307
307
  export { type AdminForthActionInput } from './Back.js'
308
308
 
309
309
  export type AdminForthComponentDeclaration = AdminForthComponentDeclarationFull | string;
@@ -314,8 +314,9 @@ export type FieldGroup = {
314
314
  noTitle?: boolean;
315
315
  };
316
316
 
317
- export interface AdminForthActionFront extends Omit<AdminForthActionInput, 'id'> {
317
+ export interface AdminForthActionFront extends Omit<AdminForthActionInput, 'id' | 'bulkHandler' | 'action' | 'allowed'> {
318
318
  id: string;
319
+ hasBulkHandler?: boolean;
319
320
  }
320
321
 
321
322
  export interface AdminForthBulkActionFront extends Omit<AdminForthBulkActionCommon, 'id'> {
@@ -610,14 +611,14 @@ export type ValidationObject = {
610
611
  * ```
611
612
  *
612
613
  */
613
- regExp: string,
614
+ regExp?: string,
614
615
 
615
616
  /**
616
617
  * Error message shown to user if validation fails
617
618
  *
618
619
  * Example: "Invalid email format"
619
620
  */
620
- message: string,
621
+ message?: string,
621
622
 
622
623
  /**
623
624
  * Whether to check case sensitivity (i flag)
@@ -633,6 +634,20 @@ export type ValidationObject = {
633
634
  * Whether to check global strings (g flag)
634
635
  */
635
636
  global?: boolean
637
+
638
+ /**
639
+ * Custom validator function.
640
+ *
641
+ * Example:
642
+ *
643
+ * ```ts
644
+ * validator: async (value) => {
645
+ * // custom validation logic
646
+ * return { isValid: true, message: 'Validation passed' }; // or { isValid: false, message: 'Validation failed' }
647
+ * }
648
+ * ```
649
+ */
650
+ validator?: (value: any, record: any, adminForth: IAdminForth) => {isValid: boolean, message?: string} | Promise<{isValid: boolean, message?: string}> | boolean,
636
651
  }
637
652
 
638
653
 
@@ -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';