mirror of
https://github.com/lana-k/sqliteviz.git
synced 2025-12-08 02:58:54 +08:00
add fileUtilities module
This commit is contained in:
17
src/fileUtilities.js
Normal file
17
src/fileUtilities.js
Normal 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()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -65,24 +65,6 @@ export default {
|
|||||||
return JSON.stringify(preparedData, null, 4)
|
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
|
* It calls onSuccess with imported queries as argument when
|
||||||
* file read. We can't use Promises here because we can't
|
* file read. We can't use Promises here because we can't
|
||||||
|
|||||||
@@ -157,6 +157,7 @@ import TextField from '@/components/TextField'
|
|||||||
import CheckBox from '@/components/CheckBox'
|
import CheckBox from '@/components/CheckBox'
|
||||||
import tooltipMixin from '@/mixins/tooltips'
|
import tooltipMixin from '@/mixins/tooltips'
|
||||||
import storedQueries from '@/storedQueries'
|
import storedQueries from '@/storedQueries'
|
||||||
|
import fu from '@/fileUtilities'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'MyQueries',
|
name: 'MyQueries',
|
||||||
@@ -350,7 +351,7 @@ export default {
|
|||||||
},
|
},
|
||||||
exportToFile (queryList, fileName) {
|
exportToFile (queryList, fileName) {
|
||||||
const jsonStr = storedQueries.serialiseQueries(queryList)
|
const jsonStr = storedQueries.serialiseQueries(queryList)
|
||||||
storedQueries.exportQueries(jsonStr, fileName)
|
fu.exportToFile(jsonStr, fileName)
|
||||||
},
|
},
|
||||||
exportSelectedQueries () {
|
exportSelectedQueries () {
|
||||||
const queryList = this.selectAll
|
const queryList = this.selectAll
|
||||||
|
|||||||
Reference in New Issue
Block a user