2021-02-26 14:50:46 +13:00
|
|
|
<template>
|
2021-03-06 08:54:03 +13:00
|
|
|
<q-dialog
|
|
|
|
v-model="dialogModel"
|
2021-05-09 02:05:13 +12:00
|
|
|
@before-hide="triggerDialogClose"
|
2021-03-06 08:54:03 +13:00
|
|
|
>
|
2021-05-15 11:35:18 +12:00
|
|
|
<q-card
|
|
|
|
class="documentCloseCheckDialog"
|
|
|
|
dark>
|
2021-03-06 08:54:03 +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>
|
2021-05-15 11:35:18 +12:00
|
|
|
<q-list class="projectCloseDialogList">
|
2021-03-06 08:54:03 +13:00
|
|
|
<q-item
|
2021-04-03 12:33:49 +13:00
|
|
|
v-for=" doc in openedDocsWithEdits"
|
2021-03-06 08:54:03 +13:00
|
|
|
:key="doc._id"
|
|
|
|
clickable
|
|
|
|
v-ripple
|
|
|
|
active
|
|
|
|
class="noHigh"
|
|
|
|
active-class="bg-primary-1 text-primary"
|
|
|
|
v-close-popup
|
|
|
|
:to="doc.url">
|
|
|
|
<q-item-section avatar>
|
|
|
|
<q-icon color="white" :name="doc.icon" />
|
|
|
|
</q-item-section>
|
|
|
|
|
|
|
|
<q-item-section class="text-primary">{{retrieveFieldValue(doc,'name')}}</q-item-section>
|
|
|
|
</q-item>
|
|
|
|
</q-list>
|
|
|
|
|
|
|
|
</q-card-section>
|
|
|
|
|
2021-05-15 11:35:18 +12:00
|
|
|
<q-card-actions align="right" class="q-mx-xl q-mt-lg q-mb-md">
|
2021-03-06 08:54:03 +13:00
|
|
|
<q-btn
|
|
|
|
flat
|
|
|
|
label="Cancel"
|
|
|
|
color="accent"
|
2021-05-15 11:35:18 +12:00
|
|
|
class="q-mx-sm"
|
2021-03-06 08:54:03 +13:00
|
|
|
v-close-popup />
|
2021-05-15 11:35:18 +12:00
|
|
|
<q-btn
|
|
|
|
outline
|
|
|
|
:label="saveAllLabelText"
|
|
|
|
color="primary"
|
|
|
|
class="q-mx-sm"
|
|
|
|
@click="determineMassSaveAction" />
|
2021-03-06 08:54:03 +13:00
|
|
|
<q-btn
|
|
|
|
outline
|
|
|
|
:label="exitLabelText"
|
|
|
|
color="secondary"
|
2021-05-15 11:35:18 +12:00
|
|
|
class="q-mx-sm"
|
2021-03-06 08:54:03 +13:00
|
|
|
v-close-popup
|
2021-04-03 12:33:49 +13:00
|
|
|
@click="determineModeAction" />
|
2021-03-06 08:54:03 +13:00
|
|
|
</q-card-actions>
|
|
|
|
</q-card>
|
|
|
|
</q-dialog>
|
2021-02-26 14:50:46 +13:00
|
|
|
</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"
|
2021-05-15 11:35:18 +12:00
|
|
|
import { extend, QSpinnerGears, Loading } from "quasar"
|
|
|
|
import { saveDocument } from "src/scripts/databaseManager/documentManager"
|
|
|
|
|
2021-02-26 14:50:46 +13:00
|
|
|
@Component({
|
|
|
|
components: { }
|
|
|
|
})
|
|
|
|
export default class ProjectCloseCheck extends DialogBase {
|
2021-04-03 12:33:49 +13:00
|
|
|
/**
|
|
|
|
* React to dialog opening request
|
|
|
|
*/
|
|
|
|
@Watch("dialogTrigger")
|
|
|
|
openDialog (val: string|false) {
|
|
|
|
if (val) {
|
|
|
|
this.SSET_setDialogState(true)
|
|
|
|
this.checkForDocumentsWithEdits()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines if the dialog should be used in application closing mode or in project closing mode
|
|
|
|
*/
|
2021-02-26 14:50:46 +13:00
|
|
|
@Prop() readonly dialogMode!: "appClose" | "projectClose"
|
|
|
|
|
2021-04-03 12:33:49 +13:00
|
|
|
/**
|
|
|
|
* Label text for the dialog
|
|
|
|
*/
|
2021-02-26 14:50:46 +13:00
|
|
|
get exitLabelText () {
|
|
|
|
if (this.dialogMode === "appClose") {
|
|
|
|
return "Exit app without saving"
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.dialogMode === "projectClose") {
|
|
|
|
return "Close project without saving"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-15 11:35:18 +12:00
|
|
|
/**
|
|
|
|
* Label text for the dialog
|
|
|
|
*/
|
|
|
|
get saveAllLabelText () {
|
|
|
|
if (this.dialogMode === "appClose") {
|
|
|
|
return "Save all & exit FA"
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.dialogMode === "projectClose") {
|
|
|
|
return "Save all & close project"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-03 12:33:49 +13:00
|
|
|
/**
|
|
|
|
* List of opened documents with edits in them
|
|
|
|
*/
|
|
|
|
openedDocsWithEdits: I_OpenedDocument[]= []
|
2021-02-26 14:50:46 +13:00
|
|
|
|
2021-04-03 12:33:49 +13:00
|
|
|
/**
|
|
|
|
* Check if we have any documents with edit. If not, skip the dialog and proceed.
|
|
|
|
*/
|
2021-02-26 14:50:46 +13:00
|
|
|
checkForDocumentsWithEdits () {
|
2021-04-03 12:33:49 +13:00
|
|
|
this.openedDocsWithEdits = this.SGET_allOpenedDocuments.docs.filter(doc => doc.hasEdits)
|
2021-02-26 14:50:46 +13:00
|
|
|
|
2021-04-03 12:33:49 +13:00
|
|
|
if (this.openedDocsWithEdits.length > 0) {
|
2021-02-26 14:50:46 +13:00
|
|
|
this.dialogModel = true
|
|
|
|
}
|
|
|
|
else {
|
2021-04-03 12:33:49 +13:00
|
|
|
this.determineModeAction()
|
2021-02-26 14:50:46 +13:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-03 12:33:49 +13:00
|
|
|
/**
|
|
|
|
* Decide what action to take depending on the dialog mode
|
|
|
|
*/
|
|
|
|
determineModeAction () {
|
2021-02-26 14:50:46 +13:00
|
|
|
if (this.dialogMode === "appClose") {
|
|
|
|
this.closeApp()
|
|
|
|
}
|
|
|
|
if (this.dialogMode === "projectClose") {
|
2021-04-03 12:33:49 +13:00
|
|
|
this.closeProject()
|
2021-02-26 14:50:46 +13:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-15 11:35:18 +12:00
|
|
|
async determineMassSaveAction () {
|
|
|
|
this.openedDocsWithEdits = this.SGET_allOpenedDocuments.docs.filter(doc => doc.hasEdits)
|
|
|
|
|
|
|
|
const setup = {
|
|
|
|
message: "<h4>Saving project...</h4>",
|
|
|
|
spinnerColor: "primary",
|
|
|
|
messageColor: "cultured",
|
|
|
|
spinnerSize: 120,
|
|
|
|
backgroundColor: "dark",
|
|
|
|
// @ts-ignore
|
|
|
|
spinner: QSpinnerGears
|
|
|
|
}
|
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
Loading.show(setup)
|
|
|
|
for (const document of this.openedDocsWithEdits) {
|
|
|
|
await this.saveOpenedDocument(document)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.dialogMode === "appClose") {
|
|
|
|
this.closeApp()
|
|
|
|
}
|
|
|
|
if (this.dialogMode === "projectClose") {
|
|
|
|
await this.sleep(3000)
|
|
|
|
Loading.hide()
|
|
|
|
this.closeProject()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-03 12:33:49 +13:00
|
|
|
/**
|
|
|
|
* Close the project and navigate to the intro screen
|
|
|
|
*/
|
|
|
|
closeProject () {
|
|
|
|
this.SSET_resetDocuments()
|
|
|
|
this.triggerDialogClose()
|
|
|
|
this.$router.push({ path: "/" }).catch((e: {name: string}) => {
|
|
|
|
if (e && e.name !== "NavigationDuplicated") {
|
|
|
|
console.log(e)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Close app
|
|
|
|
*/
|
2021-02-26 14:50:46 +13:00
|
|
|
closeApp () {
|
|
|
|
remote.getCurrentWindow().destroy()
|
|
|
|
}
|
2021-05-15 11:35:18 +12:00
|
|
|
|
|
|
|
async saveOpenedDocument (document: I_OpenedDocument) {
|
|
|
|
const docCopy:I_OpenedDocument = extend(true, [], document)
|
|
|
|
const allOpenedDocuments:I_OpenedDocument[] = extend(true, [], this.SGET_allOpenedDocuments)
|
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
const isNew = document.isNew
|
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
const savedDocument: {
|
|
|
|
documentCopy: I_OpenedDocument,
|
|
|
|
allOpenedDocuments: I_OpenedDocument[]
|
|
|
|
} = await saveDocument(docCopy, allOpenedDocuments, this.SGET_allDocuments.docs, false, this, true)
|
|
|
|
|
|
|
|
// Update the opened document
|
|
|
|
const dataPass = { doc: savedDocument.documentCopy, treeAction: true }
|
|
|
|
this.SSET_updateOpenedDocument(dataPass)
|
|
|
|
|
|
|
|
// Update document
|
|
|
|
if (!isNew) {
|
|
|
|
// @ts-ignore
|
|
|
|
this.SSET_updateDocument({ doc: this.mapShortDocument(savedDocument.documentCopy, this.SGET_allDocumentsByType(savedDocument.documentCopy.type).docs) })
|
|
|
|
}
|
|
|
|
// Add new document
|
|
|
|
else {
|
|
|
|
// @ts-ignore
|
|
|
|
this.SSET_addDocument({ doc: this.mapShortDocument(savedDocument.documentCopy, this.SGET_allDocumentsByType(savedDocument.documentCopy.type).docs) })
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update all others
|
|
|
|
for (const doc of savedDocument.allOpenedDocuments) {
|
|
|
|
// Update the opened document
|
|
|
|
const dataPass = { doc: doc, treeAction: true }
|
|
|
|
this.SSET_updateOpenedDocument(dataPass)
|
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
this.SSET_updateDocument({ doc: this.mapShortDocument(doc, this.SGET_allDocumentsByType(doc.type).docs) })
|
|
|
|
}
|
|
|
|
}
|
2021-02-26 14:50:46 +13:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
2021-03-03 08:59:56 +13:00
|
|
|
<style lang="scss">
|
|
|
|
|
2021-05-15 11:35:18 +12:00
|
|
|
.documentCloseCheckDialog {
|
|
|
|
width: 700px;
|
|
|
|
max-width: 700px !important;
|
|
|
|
}
|
|
|
|
|
|
|
|
.projectCloseDialogList {
|
2021-03-03 08:59:56 +13:00
|
|
|
width: 100%;
|
|
|
|
}
|
2021-03-06 08:54:03 +13:00
|
|
|
|
2021-02-26 14:50:46 +13:00
|
|
|
</style>
|