adminforth 2.22.0-next.39 → 2.22.0-next.40
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.
|
@@ -5,13 +5,13 @@ import router from "../router";
|
|
|
5
5
|
import { useCoreStore } from '../stores/core';
|
|
6
6
|
import { useUserStore } from '../stores/user';
|
|
7
7
|
import { Dropdown } from 'flowbite';
|
|
8
|
-
import adminforth from '../adminforth';
|
|
8
|
+
import adminforth, { useAdminforth } from '../adminforth';
|
|
9
9
|
import sanitizeHtml from 'sanitize-html'
|
|
10
10
|
import debounce from 'debounce';
|
|
11
11
|
import type { AdminForthResourceColumnInputCommon, Predicate } from '@/types/Common';
|
|
12
12
|
import { i18nInstance } from '../i18n'
|
|
13
13
|
import { useI18n } from 'vue-i18n';
|
|
14
|
-
|
|
14
|
+
import { onBeforeRouteLeave } from 'vue-router';
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
|
|
@@ -616,4 +616,55 @@ export function getTimeAgoString(date: Date): string {
|
|
|
616
616
|
const days = Math.floor(diffInSeconds / 86400);
|
|
617
617
|
return `${days} ${days === 1 ? 'day' : 'days'} ago`;
|
|
618
618
|
}
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
export class leaveGuardActiveClass {
|
|
622
|
+
private active = false;
|
|
623
|
+
|
|
624
|
+
isActive() {
|
|
625
|
+
return this.active;
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
setActive(value: boolean) {
|
|
629
|
+
this.active = value;
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
export async function onBeforeRouteLeaveCreateEditViewGuard(initialValues: any, record: any, checkIfWeCanLeavePage: () => boolean, leaveGuardActive: leaveGuardActiveClass): Promise<boolean> {
|
|
634
|
+
|
|
635
|
+
const { confirm } = useAdminforth();
|
|
636
|
+
const { t } = useI18n();
|
|
637
|
+
|
|
638
|
+
onBeforeRouteLeave(async (to, from) => {
|
|
639
|
+
|
|
640
|
+
if (leaveGuardActive.isActive()) {
|
|
641
|
+
return false;
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
if (checkIfWeCanLeavePage()) {
|
|
645
|
+
return true;
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
leaveGuardActive.setActive(true);
|
|
649
|
+
|
|
650
|
+
try {
|
|
651
|
+
const { changedFields } = compareOldAndNewRecord(
|
|
652
|
+
initialValues.value,
|
|
653
|
+
record.value
|
|
654
|
+
);
|
|
655
|
+
|
|
656
|
+
const messageHtml =
|
|
657
|
+
generateMessageHtmlForRecordChange(changedFields, t);
|
|
658
|
+
|
|
659
|
+
const answer = await confirm({
|
|
660
|
+
messageHtml,
|
|
661
|
+
yes: t('Yes'),
|
|
662
|
+
no: t('No'),
|
|
663
|
+
});
|
|
664
|
+
|
|
665
|
+
return answer;
|
|
666
|
+
} finally {
|
|
667
|
+
leaveGuardActive.setActive(false);
|
|
668
|
+
}
|
|
669
|
+
});
|
|
619
670
|
}
|
|
@@ -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, compareOldAndNewRecord,
|
|
82
|
+
import { callAdminForthApi, getCustomComponent,checkAcessByAllowedActions, initThreeDotsDropdown, checkShowIf, compareOldAndNewRecord, onBeforeRouteLeaveCreateEditViewGuard, leaveGuardActiveClass, onBeforeRouteLeaveCreateEditView } 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';
|
|
@@ -137,17 +137,12 @@ onBeforeUnmount(() => {
|
|
|
137
137
|
window.removeEventListener('beforeunload', onBeforeUnload);
|
|
138
138
|
});
|
|
139
139
|
|
|
140
|
-
onBeforeRouteLeave(async (to, from, next) => {
|
|
141
|
-
if (!checkIfWeCanLeavePage()) {
|
|
142
|
-
const { changedFields } = compareOldAndNewRecord(initialValues.value, record.value);
|
|
143
|
-
|
|
144
|
-
const messageHtml = generateMessageHtmlForRecordChange(changedFields, t);
|
|
145
140
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
141
|
+
const leaveGuardActive = new leaveGuardActiveClass();
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
onBeforeRouteLeaveCreateEditViewGuard(initialValues, record, checkIfWeCanLeavePage, leaveGuardActive);
|
|
145
|
+
|
|
151
146
|
|
|
152
147
|
onBeforeMount(() => {
|
|
153
148
|
clearSaveInterceptors(route.params.resourceId as string);
|
|
@@ -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, compareOldAndNewRecord, generateMessageHtmlForRecordChange } from '@/utils';
|
|
77
|
+
import { callAdminForthApi, getCustomComponent,checkAcessByAllowedActions, initThreeDotsDropdown, compareOldAndNewRecord, generateMessageHtmlForRecordChange, leaveGuardActiveClass, onBeforeRouteLeaveCreateEditViewGuard } 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';
|
|
@@ -122,17 +122,8 @@ onBeforeUnmount(() => {
|
|
|
122
122
|
window.removeEventListener('beforeunload', onBeforeUnload);
|
|
123
123
|
});
|
|
124
124
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
const { changedFields } = compareOldAndNewRecord(initialRecord.value, record.value);
|
|
128
|
-
|
|
129
|
-
const messageHtml = generateMessageHtmlForRecordChange(changedFields, t);
|
|
130
|
-
|
|
131
|
-
const answer = await confirm({ messageHtml: messageHtml, yes: t('Yes'), no: t('No') });
|
|
132
|
-
if (!answer) return next(false);
|
|
133
|
-
}
|
|
134
|
-
next();
|
|
135
|
-
});
|
|
125
|
+
const leaveGuardActive = new leaveGuardActiveClass();
|
|
126
|
+
onBeforeRouteLeaveCreateEditViewGuard(initialRecord, record, checkIfWeCanLeavePage, leaveGuardActive);
|
|
136
127
|
|
|
137
128
|
const resourceFormRef = ref<InstanceType<typeof ResourceForm> | null>(null);
|
|
138
129
|
|