|
1 | 1 | <script setup lang="ts"> |
2 | 2 | import Calendar from 'primevue/calendar'; |
3 | 3 | import Button from 'primevue/button'; |
4 | | - import { computed, ComputedRef, Ref, ref } from 'vue'; |
| 4 | + import { computed, ComputedRef, onBeforeMount, onBeforeUnmount, Ref, ref } from 'vue'; |
5 | 5 | import { DropdownOption } from '../../models/Common'; |
6 | 6 | import { ComponentFactory, Observation, Participant } from '@gs'; |
7 | 7 | import { AxiosError, AxiosResponse } from 'axios'; |
|
18 | 18 | import MultiSelect from 'primevue/multiselect'; |
19 | 19 | import { DownloadDataFilter } from '../../models/DataDownloadModel'; |
20 | 20 | import ProgressSpinner from 'primevue/progressspinner'; |
| 21 | + import { useDialog } from 'primevue/usedialog'; |
| 22 | + import ConfirmationDialog from '../dialog/ConfirmationDialog.vue'; |
| 23 | + import { onBeforeRouteLeave, useRouter } from 'vue-router'; |
| 24 | +
|
| 25 | + const dialog = useDialog(); |
| 26 | + const router = useRouter(); |
| 27 | + const pendingRoute = ref<any>(null); |
21 | 28 |
|
22 | 29 | const { t } = useI18n(); |
23 | 30 | const { componentsApi } = useComponentsApi(); |
|
166 | 173 | .then((response: any) => response.data) |
167 | 174 | .then((rs) => (factories = rs)) |
168 | 175 | .then(loadData); |
| 176 | +
|
| 177 | + function interceptPageNavigation(): void { |
| 178 | + dialog.open(ConfirmationDialog, { |
| 179 | + data: { |
| 180 | + message: t('monitoringData.dialog.msg.downloadStudyData'), |
| 181 | + cancelBtn: t('monitoringData.dialog.waitForDownload'), |
| 182 | + approveBtn: t('monitoringData.dialog.navigatePage') |
| 183 | + }, |
| 184 | + props: { |
| 185 | + header: t('monitoringData.dialog.header.downloadStudyData'), |
| 186 | + style: { |
| 187 | + width: '50vw', |
| 188 | + }, |
| 189 | + breakpoints: { |
| 190 | + '960px': '75vw', |
| 191 | + '640px': '90vw', |
| 192 | + }, |
| 193 | + modal: true, |
| 194 | + draggable: false, |
| 195 | + }, |
| 196 | + onClose: (options) =>{ |
| 197 | + if (options?.data) { |
| 198 | + if (pendingRoute.value) { |
| 199 | + isDownloadDataLoading.value = false |
| 200 | + router.push(pendingRoute.value) |
| 201 | + pendingRoute.value = null |
| 202 | + } |
| 203 | + } else { |
| 204 | + pendingRoute.value = null |
| 205 | + } |
| 206 | + } |
| 207 | + }) |
| 208 | + } |
| 209 | +
|
| 210 | + onBeforeRouteLeave((to, from, next) => { |
| 211 | + if (isDownloadDataLoading.value) { |
| 212 | + pendingRoute.value = to |
| 213 | + interceptPageNavigation() |
| 214 | + // preventNavigation |
| 215 | + next(false) |
| 216 | + } else { |
| 217 | + // navigate |
| 218 | + next() |
| 219 | + } |
| 220 | + }) |
| 221 | +
|
| 222 | + onBeforeMount(() => { |
| 223 | + window.addEventListener('beforeunload', (e) => { |
| 224 | + if (isDownloadDataLoading.value) e.preventDefault() } |
| 225 | + ) |
| 226 | + }) |
| 227 | + onBeforeUnmount(() => { |
| 228 | + window.removeEventListener('beforeunload', (e) => { |
| 229 | + if (isDownloadDataLoading.value) e.preventDefault() } |
| 230 | + ) |
| 231 | + }) |
169 | 232 | </script> |
170 | 233 |
|
171 | 234 | <template> |
|
278 | 341 |
|
279 | 342 | <style scoped lang="postcss"> |
280 | 343 | :deep(.p-progress-spinner-circle) { |
281 | | - stroke: currentColor!important; /* nimmt dann die text-red-600 aus Tailwind */ |
| 344 | + stroke: currentColor!important; |
282 | 345 | } |
283 | 346 | </style> |
0 commit comments