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))
|
||||
},
|
||||
|
||||
exportQueries (data) {
|
||||
const preparedData = JSON.parse(JSON.stringify(data))
|
||||
|
||||
// Remove isPredefined mark for exported queries
|
||||
if (Array.isArray(data)) {
|
||||
// group operation
|
||||
serialiseQueries (queryList) {
|
||||
const preparedData = JSON.parse(JSON.stringify(queryList))
|
||||
preparedData.forEach(query => delete query.isPredefined)
|
||||
} else {
|
||||
// single operation
|
||||
delete preparedData.isPredefined
|
||||
}
|
||||
return JSON.stringify(preparedData, null, 4)
|
||||
},
|
||||
|
||||
exportQueries (str, fileName, type = 'octet/stream') {
|
||||
// Create downloader
|
||||
const downloader = document.createElement('a')
|
||||
downloader.hidden = true
|
||||
document.body.append(downloader)
|
||||
|
||||
// Prepare data
|
||||
const name = data.name || 'My sqlitevis queries'
|
||||
const json = JSON.stringify(preparedData, null, 4)
|
||||
const blob = new Blob([json], { type: 'octet/stream' })
|
||||
const url = window.URL.createObjectURL(blob)
|
||||
// const name = data.name || 'My sqlitevis queries'
|
||||
const blob = new Blob([str], { type })
|
||||
const url = URL.createObjectURL(blob)
|
||||
downloader.href = url
|
||||
downloader.download = `${name}.json`
|
||||
downloader.download = fileName
|
||||
|
||||
// Trigger click
|
||||
downloader.click()
|
||||
|
||||
// Clear
|
||||
window.URL.revokeObjectURL(url)
|
||||
// Clean up
|
||||
URL.revokeObjectURL(url)
|
||||
downloader.remove()
|
||||
},
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<button
|
||||
class="toolbar"
|
||||
v-show="selectedQueriesCount > 0"
|
||||
@click="exportQuery(selectedQueriesIds)"
|
||||
@click="exportSelectedQueries()"
|
||||
>
|
||||
Export
|
||||
</button>
|
||||
@@ -81,7 +81,7 @@
|
||||
<div class="icons-container">
|
||||
<rename-icon v-if="!query.isPredefined" @click="showRenameDialog(query.id)" />
|
||||
<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)"/>
|
||||
</div>
|
||||
</div>
|
||||
@@ -348,21 +348,16 @@ export default {
|
||||
findTabIndex (id) {
|
||||
return this.$store.state.tabs.findIndex(tab => tab.id === id)
|
||||
},
|
||||
exportQuery (index) {
|
||||
let data
|
||||
|
||||
if (typeof index === 'number') {
|
||||
// single operation
|
||||
data = this.showedQueries[index]
|
||||
} else {
|
||||
// group operation
|
||||
data = this.selectAll
|
||||
exportToFile (queryList, fileName) {
|
||||
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))
|
||||
}
|
||||
|
||||
// export data to file
|
||||
storedQueries.exportQueries(data)
|
||||
this.exportToFile(queryList, 'My sqlitevis queries.json')
|
||||
},
|
||||
importQueries () {
|
||||
const onSuccess = (importedQueries) => {
|
||||
|
||||
Reference in New Issue
Block a user