adminforth 2.21.2-next.1 → 2.21.2-next.2

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.
@@ -13,6 +13,7 @@ import { i18nInstance } from '../i18n'
13
13
 
14
14
 
15
15
 
16
+
16
17
  const LS_LANG_KEY = `afLanguage`;
17
18
  const MAX_CONSECUTIVE_EMPTY_RESULTS = 2;
18
19
  const ITEMS_PER_PAGE_LIMIT = 100;
@@ -522,3 +523,42 @@ export function btoa_function(source: string): string {
522
523
  export function atob_function(source: string): string {
523
524
  return atob(source);
524
525
  }
526
+
527
+ export function compareOldAndNewRecord(oldRecord: Record<string, any>, newRecord: Record<string, any>): boolean {
528
+ const newKeys = Object.keys(newRecord);
529
+ const coreStore = useCoreStore();
530
+
531
+ for (const key of newKeys) {
532
+ if (oldRecord[key] !== newRecord[key]) {
533
+ if (
534
+ (
535
+ oldRecord[key] === undefined ||
536
+ oldRecord[key] === null ||
537
+ oldRecord[key] === '' ||
538
+ (Array.isArray(oldRecord[key]) && oldRecord[key].length === 0)
539
+ )
540
+ &&
541
+ (
542
+ newRecord[key] === undefined ||
543
+ newRecord[key] === null ||
544
+ newRecord[key] === '' ||
545
+ (Array.isArray(newRecord[key]) && newRecord[key].length === 0)
546
+ )
547
+ ) {
548
+ // console.log(`Value for key ${key} is considered equal (empty)`)
549
+ continue;
550
+ }
551
+
552
+ const column = coreStore.resource.columns.find((c) => c.name === key);
553
+ if (column?.foreignResource) {
554
+ if (newRecord[key] === oldRecord[key]?.pk) {
555
+ // console.log(`Value for key ${key} is considered equal (foreign key)`)
556
+ continue;
557
+ }
558
+ }
559
+ // console.log(`Value for key ${key} is different`, { oldValue: oldRecord[key], newValue: newRecord[key] });
560
+ return false;
561
+ }
562
+ }
563
+ return true;
564
+ }
@@ -79,7 +79,7 @@ import BreadcrumbsWithButtons from '@/components/BreadcrumbsWithButtons.vue';
79
79
  import ResourceForm from '@/components/ResourceForm.vue';
80
80
  import SingleSkeletLoader from '@/components/SingleSkeletLoader.vue';
81
81
  import { useCoreStore } from '@/stores/core';
82
- import { callAdminForthApi, getCustomComponent,checkAcessByAllowedActions, initThreeDotsDropdown, checkShowIf } from '@/utils';
82
+ import { callAdminForthApi, getCustomComponent,checkAcessByAllowedActions, initThreeDotsDropdown, checkShowIf, compareOldAndNewRecord } from '@/utils';
83
83
  import { IconFloppyDiskSolid } from '@iconify-prerendered/vue-flowbite';
84
84
  import { onMounted, onBeforeMount, onBeforeUnmount, ref, watch, nextTick } from 'vue';
85
85
  import { useRoute, useRouter, onBeforeRouteLeave } from 'vue-router';
@@ -121,7 +121,7 @@ async function onUpdateRecord(newRecord: any) {
121
121
  }
122
122
 
123
123
  function checkIfWeCanLeavePage() {
124
- return wasSaveSuccessful.value || cancelButtonClicked.value || JSON.stringify(record.value) === JSON.stringify(initialValues.value);
124
+ return wasSaveSuccessful.value || cancelButtonClicked.value || compareOldAndNewRecord(initialValues.value, record.value);
125
125
  }
126
126
 
127
127
  function onBeforeUnload(event: BeforeUnloadEvent) {
@@ -74,7 +74,7 @@ import BreadcrumbsWithButtons from '@/components/BreadcrumbsWithButtons.vue';
74
74
  import ResourceForm from '@/components/ResourceForm.vue';
75
75
  import SingleSkeletLoader from '@/components/SingleSkeletLoader.vue';
76
76
  import { useCoreStore } from '@/stores/core';
77
- import { callAdminForthApi, getCustomComponent,checkAcessByAllowedActions, initThreeDotsDropdown } from '@/utils';
77
+ import { callAdminForthApi, getCustomComponent,checkAcessByAllowedActions, initThreeDotsDropdown, compareOldAndNewRecord } from '@/utils';
78
78
  import { IconFloppyDiskSolid } from '@iconify-prerendered/vue-flowbite';
79
79
  import { computed, onMounted, onBeforeMount, ref, type Ref, nextTick, watch, onBeforeUnmount } from 'vue';
80
80
  import { useRoute, useRouter, onBeforeRouteLeave } from 'vue-router';
@@ -113,7 +113,7 @@ function onBeforeUnload(event: BeforeUnloadEvent) {
113
113
  }
114
114
 
115
115
  function checkIfWeCanLeavePage() {
116
- return wasSaveSuccessful.value || cancelButtonClicked.value || JSON.stringify(record.value) === JSON.stringify(initialRecord.value);
116
+ return wasSaveSuccessful.value || cancelButtonClicked.value || compareOldAndNewRecord(initialRecord.value, record.value);
117
117
  }
118
118
 
119
119
  window.addEventListener('beforeunload', onBeforeUnload);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adminforth",
3
- "version": "2.21.2-next.1",
3
+ "version": "2.21.2-next.2",
4
4
  "description": "OpenSource Vue3 powered forth-generation admin panel",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",