1
0
mirror of https://github.com/lana-k/sqliteviz.git synced 2025-12-06 10:08:52 +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
},
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(),

View File

@@ -14,10 +14,18 @@
id="save-btn"
class="primary"
:disabled="isSaved"
@click="checkInquiryBeforeSave"
@click="onSave"
>
Save
</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">
Create
</button>
@@ -45,7 +53,9 @@
</div>
<div class="dialog-buttons-container">
<button class="secondary" @click="cancelSave">Cancel</button>
<button class="primary" @click="saveInquiry">Save</button>
<button class="primary" @click="validateSaveFormAndSaveInquiry">
Save
</button>
</div>
</modal>
</nav>
@@ -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)) {