1
0
mirror of https://github.com/lana-k/sqliteviz.git synced 2025-12-06 18:18:53 +08:00
This commit is contained in:
lana-k
2025-09-27 17:01:50 +02:00
parent 12fa0749b1
commit cdd925b8af
2 changed files with 45 additions and 17 deletions

View File

@@ -15,9 +15,9 @@ export default {
return inquiry.id return inquiry.id
}, },
async saveInquiry({ state }, { inquiryTab, newName }) { async saveInquiry({ state }, { inquiryTab, newName, overwrite }) {
const value = { const value = {
id: inquiryTab.isPredefined ? nanoid() : inquiryTab.id, id: inquiryTab.isPredefined || !overwrite ? nanoid() : inquiryTab.id,
query: inquiryTab.query, query: inquiryTab.query,
viewType: inquiryTab.dataView.mode, viewType: inquiryTab.dataView.mode,
viewOptions: inquiryTab.dataView.getOptionsForSave(), viewOptions: inquiryTab.dataView.getOptionsForSave(),

View File

@@ -14,10 +14,18 @@
id="save-btn" id="save-btn"
class="primary" class="primary"
:disabled="isSaved" :disabled="isSaved"
@click="checkInquiryBeforeSave" @click="onSave"
> >
Save Save
</button> </button>
<button
v-show="currentInquiry && $route.path === '/workspace'"
id="save-as-btn"
class="primary"
@click="onSaveAs"
>
Save as ...
</button>
<button id="create-btn" class="primary" @click="createNewInquiry"> <button id="create-btn" class="primary" @click="createNewInquiry">
Create Create
</button> </button>
@@ -45,7 +53,9 @@
</div> </div>
<div class="dialog-buttons-container"> <div class="dialog-buttons-container">
<button class="secondary" @click="cancelSave">Cancel</button> <button class="secondary" @click="cancelSave">Cancel</button>
<button class="primary" @click="saveInquiry">Save</button> <button class="primary" @click="validateSaveFormAndSaveInquiry">
Save
</button>
</div> </div>
</modal> </modal>
</nav> </nav>
@@ -69,7 +79,8 @@ export default {
data() { data() {
return { return {
name: '', name: '',
errorMsg: null errorMsg: null,
overwrite: false
} }
}, },
computed: { computed: {
@@ -91,7 +102,7 @@ export default {
}, },
created() { created() {
eventBus.$on('createNewInquiry', this.createNewInquiry) eventBus.$on('createNewInquiry', this.createNewInquiry)
eventBus.$on('saveInquiry', this.checkInquiryBeforeSave) eventBus.$on('saveInquiry', this.onSave)
document.addEventListener('keydown', this._keyListener) document.addEventListener('keydown', this._keyListener)
}, },
beforeUnmount() { beforeUnmount() {
@@ -112,29 +123,40 @@ export default {
this.$modal.hide('save') this.$modal.hide('save')
eventBus.$off('inquirySaved') eventBus.$off('inquirySaved')
}, },
checkInquiryBeforeSave() { onSave() {
this.errorMsg = null this.overwrite = true
this.name = ''
if (storedInquiries.isTabNeedName(this.currentInquiry)) { if (storedInquiries.isTabNeedName(this.currentInquiry)) {
this.$modal.show('save') this.openSaveModal()
} else { } else {
this.saveInquiry() this.saveInquiry()
} }
}, },
async saveInquiry() { onSaveAs() {
const isNeedName = storedInquiries.isTabNeedName(this.currentInquiry) console.log('save as')
if (isNeedName && !this.name) { 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" this.errorMsg = "Inquiry name can't be empty"
return return
} }
this.saveInquiry()
},
async saveInquiry() {
const dataSet = this.currentInquiry.result const dataSet = this.currentInquiry.result
const tabView = this.currentInquiry.view const tabView = this.currentInquiry.view
// Save inquiry // Save inquiry
const value = await this.$store.dispatch('saveInquiry', { const value = await this.$store.dispatch('saveInquiry', {
inquiryTab: this.currentInquiry, inquiryTab: this.currentInquiry,
newName: this.name newName: this.name,
overwrite: this.overwrite
}) })
// Update tab in store // Update tab in store
@@ -179,13 +201,19 @@ export default {
} }
// Save inquiry Ctrl+S // Save inquiry Ctrl+S
if (e.key === 's' && (e.ctrlKey || e.metaKey)) { if (e.key === 's' && (e.ctrlKey || e.metaKey) && !e.shiftKey) {
e.preventDefault() e.preventDefault()
if (!this.isSaved) { if (!this.isSaved) {
this.checkInquiryBeforeSave() this.onSave()
} }
return 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 // New (blank) inquiry Ctrl+B
if (e.key === 'b' && (e.ctrlKey || e.metaKey)) { if (e.key === 'b' && (e.ctrlKey || e.metaKey)) {