From cdd925b8afec5fa153cbed853b6e7dca66bd0c39 Mon Sep 17 00:00:00 2001 From: lana-k Date: Sat, 27 Sep 2025 17:01:50 +0200 Subject: [PATCH] #16 save as --- src/store/actions.js | 4 +-- src/views/MainView/MainMenu.vue | 58 ++++++++++++++++++++++++--------- 2 files changed, 45 insertions(+), 17 deletions(-) diff --git a/src/store/actions.js b/src/store/actions.js index 40277bd..35292d3 100644 --- a/src/store/actions.js +++ b/src/store/actions.js @@ -15,9 +15,9 @@ export default { return inquiry.id }, - async saveInquiry({ state }, { inquiryTab, newName }) { + async saveInquiry({ state }, { inquiryTab, newName, overwrite }) { const value = { - id: inquiryTab.isPredefined ? nanoid() : inquiryTab.id, + id: inquiryTab.isPredefined || !overwrite ? nanoid() : inquiryTab.id, query: inquiryTab.query, viewType: inquiryTab.dataView.mode, viewOptions: inquiryTab.dataView.getOptionsForSave(), diff --git a/src/views/MainView/MainMenu.vue b/src/views/MainView/MainMenu.vue index 78c5e04..387265c 100644 --- a/src/views/MainView/MainMenu.vue +++ b/src/views/MainView/MainMenu.vue @@ -14,10 +14,18 @@ id="save-btn" class="primary" :disabled="isSaved" - @click="checkInquiryBeforeSave" + @click="onSave" > Save + @@ -45,7 +53,9 @@
- +
@@ -69,7 +79,8 @@ export default { data() { return { name: '', - errorMsg: null + errorMsg: null, + overwrite: false } }, computed: { @@ -91,7 +102,7 @@ export default { }, created() { eventBus.$on('createNewInquiry', this.createNewInquiry) - eventBus.$on('saveInquiry', this.checkInquiryBeforeSave) + eventBus.$on('saveInquiry', this.onSave) document.addEventListener('keydown', this._keyListener) }, beforeUnmount() { @@ -112,29 +123,40 @@ export default { this.$modal.hide('save') eventBus.$off('inquirySaved') }, - checkInquiryBeforeSave() { - this.errorMsg = null - this.name = '' - + onSave() { + this.overwrite = true if (storedInquiries.isTabNeedName(this.currentInquiry)) { - this.$modal.show('save') + this.openSaveModal() } else { this.saveInquiry() } }, - async saveInquiry() { - const isNeedName = storedInquiries.isTabNeedName(this.currentInquiry) - if (isNeedName && !this.name) { + onSaveAs() { + console.log('save as') + this.overwrite = false + this.openSaveModal() + }, + openSaveModal() { + this.errorMsg = null + this.name = '' + this.$modal.show('save') + }, + validateSaveFormAndSaveInquiry() { + if (!this.name) { this.errorMsg = "Inquiry name can't be empty" return } + this.saveInquiry() + }, + async saveInquiry() { const dataSet = this.currentInquiry.result const tabView = this.currentInquiry.view // Save inquiry const value = await this.$store.dispatch('saveInquiry', { inquiryTab: this.currentInquiry, - newName: this.name + newName: this.name, + overwrite: this.overwrite }) // Update tab in store @@ -179,13 +201,19 @@ export default { } // Save inquiry Ctrl+S - if (e.key === 's' && (e.ctrlKey || e.metaKey)) { + if (e.key === 's' && (e.ctrlKey || e.metaKey) && !e.shiftKey) { e.preventDefault() if (!this.isSaved) { - this.checkInquiryBeforeSave() + this.onSave() } return } + // Save inquiry as Ctrl+Shift+S + if (e.key === 'S' && (e.ctrlKey || e.metaKey) && e.shiftKey) { + e.preventDefault() + this.onSaveAs() + return + } } // New (blank) inquiry Ctrl+B if (e.key === 'b' && (e.ctrlKey || e.metaKey)) {