fantasia-archive/src/components/dialogs/ProjectCloseCheck.vue

128 lines
3.2 KiB
Vue
Raw Normal View History

2021-02-26 14:50:46 +13:00
<template>
<q-dialog
v-model="dialogModel"
@hide="triggerDialogClose"
>
<q-card dark>
2021-02-26 14:50:46 +13:00
<q-card-section class="row justify-center">
<h6 class="text-center q-my-sm">You have unsaved documents opened!</h6>
</q-card-section>
<q-card-section class="row justify-center q-mx-lg">
All unsaved data will be lost upon closing the app unless the documents are saved first.
</q-card-section>
<q-card-section class="row q-mx-lg">
<div class="q-mb-md text-bold">Affected documents:</div>
<q-list class="projectCloseDalogList">
2021-02-26 14:50:46 +13:00
<q-item
v-for=" doc in openedDocs"
:key="doc._id"
clickable
v-ripple
active
2021-03-04 13:27:07 +13:00
class="noHigh"
2021-02-26 14:50:46 +13:00
active-class="bg-primary-1 text-primary"
v-close-popup
:to="doc.url">
<q-item-section avatar>
<q-icon color="white" :name="doc.icon" />
2021-02-26 14:50:46 +13:00
</q-item-section>
<q-item-section class="text-primary">{{retrieveFieldValue(doc,'name')}}</q-item-section>
</q-item>
</q-list>
</q-card-section>
<q-card-actions align="around" class="q-mx-xl q-mt-lg q-mb-md">
<q-btn
flat
2021-03-04 13:27:07 +13:00
label="Cancel"
color="accent"
v-close-popup />
<q-btn
outline
2021-02-26 14:50:46 +13:00
:label="exitLabelText"
2021-03-04 13:27:07 +13:00
color="secondary"
2021-02-26 14:50:46 +13:00
v-close-popup
@click="checkModeAction" />
</q-card-actions>
</q-card>
</q-dialog>
</template>
<script lang="ts">
import { Component, Watch, Prop } from "vue-property-decorator"
import DialogBase from "src/components/dialogs/_DialogBase"
import { I_OpenedDocument } from "src/interfaces/I_OpenedDocument"
import { remote } from "electron"
@Component({
components: { }
})
export default class ProjectCloseCheck extends DialogBase {
@Prop() readonly dialogMode!: "appClose" | "projectClose"
get exitLabelText () {
if (this.dialogMode === "appClose") {
return "Exit app without saving"
}
if (this.dialogMode === "projectClose") {
return "Close project without saving"
}
}
@Watch("dialogTrigger")
openDialog (val: string|false) {
if (val) {
if (this.SGET_getDialogsState) {
return
}
this.SSET_setDialogState(true)
this.checkForDocumentsWithEdits()
}
}
openedDocs: I_OpenedDocument[]= []
checkForDocumentsWithEdits () {
this.openedDocs = this.SGET_allOpenedDocuments.docs.filter(doc => doc.hasEdits)
if (this.openedDocs.length > 0) {
this.dialogModel = true
}
else {
this.checkModeAction()
}
}
checkModeAction () {
if (this.dialogMode === "appClose") {
this.closeApp()
}
if (this.dialogMode === "projectClose") {
this.SSET_resetDocuments()
this.triggerDialogClose()
this.$router.push({ path: "/" }).catch((e: {name: string}) => {
if (e && e.name !== "NavigationDuplicated") {
console.log(e)
}
})
}
}
closeApp () {
remote.getCurrentWindow().destroy()
}
}
</script>
<style lang="scss">
.projectCloseDalogList {
width: 100%;
}
2021-02-26 14:50:46 +13:00
</style>