Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data download component: Show dialog for unsaved changes #919

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 30 additions & 6 deletions src/components/timeseries/TimeSeriesComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,20 @@
</KeepAlive>
</v-window-item>
</v-window>
<v-dialog v-model="confirmationDialog" persistent max-width="500">
<v-card prepend-icon="mdi-content-save" title="Unsaved Changes">
<v-card-text>
You have unsaved changes. Are you sure you want to leave?
</v-card-text>
<v-card-actions>
<v-spacer />
<v-btn varint="flat" @click="onConfirmationCancel"> Cancel </v-btn>
<v-btn color="error" variant="flat" @click="onConfirmationLeave">
Leave
</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
</template>

<script setup lang="ts">
Expand All @@ -67,6 +81,7 @@ import { useSystemTimeStore } from '@/stores/systemTime'
import type { TimeSeriesEvent } from '@deltares/fews-pi-requests'
import { useDisplay } from 'vuetify'
import { onBeforeRouteUpdate, onBeforeRouteLeave } from 'vue-router'
import { until } from '@vueuse/core'

interface Props {
config?: DisplayConfig
Expand Down Expand Up @@ -108,6 +123,7 @@ const props = withDefaults(defineProps<Props>(), {
const store = useSystemTimeStore()
const lastUpdated = ref<Date>(new Date())
const isEditing = ref(false)
const confirmationDialog = ref(false)
const { xs } = useDisplay()

const options = computed<UseTimeSeriesOptions>(() => {
Expand Down Expand Up @@ -188,21 +204,29 @@ onUnmounted(() => {

onBeforeRouteLeave(confirmUnsavedChanges)
onBeforeRouteUpdate(confirmUnsavedChanges)
function confirmUnsavedChanges() {
async function confirmUnsavedChanges() {
if (isEditing.value) {
// For multiple simultaneous leaves set to false since confirm dialog is async
isEditing.value = false

const answer = window.confirm(
'You have unsaved changes. Are you sure you want to leave?',
)
confirmationDialog.value = true
await until(confirmationDialog).toBe(false)

if (!answer) {
isEditing.value = true
if (isEditing.value) {
return false
}
}
}

function onConfirmationCancel() {
confirmationDialog.value = false
isEditing.value = true
}

function onConfirmationLeave() {
confirmationDialog.value = false
isEditing.value = false
}
</script>

<style scoped>
Expand Down
Loading