mirror of
https://github.com/lana-k/sqliteviz.git
synced 2025-12-07 02:28:54 +08:00
export refactoring
This commit is contained in:
@@ -59,36 +59,27 @@ export default {
|
|||||||
localStorage.setItem('myQueries', JSON.stringify(value))
|
localStorage.setItem('myQueries', JSON.stringify(value))
|
||||||
},
|
},
|
||||||
|
|
||||||
exportQueries (data) {
|
serialiseQueries (queryList) {
|
||||||
const preparedData = JSON.parse(JSON.stringify(data))
|
const preparedData = JSON.parse(JSON.stringify(queryList))
|
||||||
|
preparedData.forEach(query => delete query.isPredefined)
|
||||||
// Remove isPredefined mark for exported queries
|
return JSON.stringify(preparedData, null, 4)
|
||||||
if (Array.isArray(data)) {
|
},
|
||||||
// group operation
|
|
||||||
preparedData.forEach(query => delete query.isPredefined)
|
|
||||||
} else {
|
|
||||||
// single operation
|
|
||||||
delete preparedData.isPredefined
|
|
||||||
}
|
|
||||||
|
|
||||||
|
exportQueries (str, fileName, type = 'octet/stream') {
|
||||||
// Create downloader
|
// Create downloader
|
||||||
const downloader = document.createElement('a')
|
const downloader = document.createElement('a')
|
||||||
downloader.hidden = true
|
|
||||||
document.body.append(downloader)
|
|
||||||
|
|
||||||
// Prepare data
|
// const name = data.name || 'My sqlitevis queries'
|
||||||
const name = data.name || 'My sqlitevis queries'
|
const blob = new Blob([str], { type })
|
||||||
const json = JSON.stringify(preparedData, null, 4)
|
const url = URL.createObjectURL(blob)
|
||||||
const blob = new Blob([json], { type: 'octet/stream' })
|
|
||||||
const url = window.URL.createObjectURL(blob)
|
|
||||||
downloader.href = url
|
downloader.href = url
|
||||||
downloader.download = `${name}.json`
|
downloader.download = fileName
|
||||||
|
|
||||||
// Trigger click
|
// Trigger click
|
||||||
downloader.click()
|
downloader.click()
|
||||||
|
|
||||||
// Clear
|
// Clean up
|
||||||
window.URL.revokeObjectURL(url)
|
URL.revokeObjectURL(url)
|
||||||
downloader.remove()
|
downloader.remove()
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
<button
|
<button
|
||||||
class="toolbar"
|
class="toolbar"
|
||||||
v-show="selectedQueriesCount > 0"
|
v-show="selectedQueriesCount > 0"
|
||||||
@click="exportQuery(selectedQueriesIds)"
|
@click="exportSelectedQueries()"
|
||||||
>
|
>
|
||||||
Export
|
Export
|
||||||
</button>
|
</button>
|
||||||
@@ -81,7 +81,7 @@
|
|||||||
<div class="icons-container">
|
<div class="icons-container">
|
||||||
<rename-icon v-if="!query.isPredefined" @click="showRenameDialog(query.id)" />
|
<rename-icon v-if="!query.isPredefined" @click="showRenameDialog(query.id)" />
|
||||||
<copy-icon @click="duplicateQuery(index)"/>
|
<copy-icon @click="duplicateQuery(index)"/>
|
||||||
<export-icon @click="exportQuery(index)"/>
|
<export-icon @click="exportToFile([query], `${query.name}.json`)"/>
|
||||||
<delete-icon v-if="!query.isPredefined" @click="showDeleteDialog(query.id)"/>
|
<delete-icon v-if="!query.isPredefined" @click="showDeleteDialog(query.id)"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -348,21 +348,16 @@ export default {
|
|||||||
findTabIndex (id) {
|
findTabIndex (id) {
|
||||||
return this.$store.state.tabs.findIndex(tab => tab.id === id)
|
return this.$store.state.tabs.findIndex(tab => tab.id === id)
|
||||||
},
|
},
|
||||||
exportQuery (index) {
|
exportToFile (queryList, fileName) {
|
||||||
let data
|
const jsonStr = storedQueries.serialiseQueries(queryList)
|
||||||
|
storedQueries.exportQueries(jsonStr, fileName)
|
||||||
|
},
|
||||||
|
exportSelectedQueries () {
|
||||||
|
const queryList = this.selectAll
|
||||||
|
? this.allQueries
|
||||||
|
: this.allQueries.filter(query => this.selectedQueriesIds.has(query.id))
|
||||||
|
|
||||||
if (typeof index === 'number') {
|
this.exportToFile(queryList, 'My sqlitevis queries.json')
|
||||||
// single operation
|
|
||||||
data = this.showedQueries[index]
|
|
||||||
} else {
|
|
||||||
// group operation
|
|
||||||
data = this.selectAll
|
|
||||||
? this.allQueries
|
|
||||||
: this.allQueries.filter(query => this.selectedQueriesIds.has(query.id))
|
|
||||||
}
|
|
||||||
|
|
||||||
// export data to file
|
|
||||||
storedQueries.exportQueries(data)
|
|
||||||
},
|
},
|
||||||
importQueries () {
|
importQueries () {
|
||||||
const onSuccess = (importedQueries) => {
|
const onSuccess = (importedQueries) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user