1
0
mirror of https://github.com/lana-k/sqliteviz.git synced 2025-12-07 02:28:54 +08:00

add fileUtilities module

This commit is contained in:
lana-k
2021-01-20 17:16:33 +01:00
parent eb1f71608d
commit 86825475f0
3 changed files with 19 additions and 19 deletions

17
src/fileUtilities.js Normal file
View File

@@ -0,0 +1,17 @@
export default {
exportToFile (str, fileName, type = 'octet/stream') {
// Create downloader
const downloader = document.createElement('a')
const blob = new Blob([str], { type })
const url = URL.createObjectURL(blob)
downloader.href = url
downloader.download = fileName
// Trigger click
downloader.click()
// Clean up
URL.revokeObjectURL(url)
downloader.remove()
}
}

View File

@@ -65,24 +65,6 @@ export default {
return JSON.stringify(preparedData, null, 4)
},
exportQueries (str, fileName, type = 'octet/stream') {
// Create downloader
const downloader = document.createElement('a')
// const name = data.name || 'My sqlitevis queries'
const blob = new Blob([str], { type })
const url = URL.createObjectURL(blob)
downloader.href = url
downloader.download = fileName
// Trigger click
downloader.click()
// Clean up
URL.revokeObjectURL(url)
downloader.remove()
},
/**
* It calls onSuccess with imported queries as argument when
* file read. We can't use Promises here because we can't

View File

@@ -157,6 +157,7 @@ import TextField from '@/components/TextField'
import CheckBox from '@/components/CheckBox'
import tooltipMixin from '@/mixins/tooltips'
import storedQueries from '@/storedQueries'
import fu from '@/fileUtilities'
export default {
name: 'MyQueries',
@@ -350,7 +351,7 @@ export default {
},
exportToFile (queryList, fileName) {
const jsonStr = storedQueries.serialiseQueries(queryList)
storedQueries.exportQueries(jsonStr, fileName)
fu.exportToFile(jsonStr, fileName)
},
exportSelectedQueries () {
const queryList = this.selectAll