mirror of
https://github.com/lana-k/sqliteviz.git
synced 2025-12-06 18:18:53 +08:00
add import queries feature
This commit is contained in:
5
package-lock.json
generated
5
package-lock.json
generated
@@ -10672,6 +10672,11 @@
|
|||||||
"thenify-all": "^1.0.0"
|
"thenify-all": "^1.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"nanoid": {
|
||||||
|
"version": "3.1.12",
|
||||||
|
"resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.1.12.tgz",
|
||||||
|
"integrity": "sha512-1qstj9z5+x491jfiC4Nelk+f8XBad7LN20PmyWINJEMRSf3wcAjAWysw1qaA8z6NSKe2sjq1hRSDpBH5paCb6A=="
|
||||||
|
},
|
||||||
"nanomatch": {
|
"nanomatch": {
|
||||||
"version": "1.2.13",
|
"version": "1.2.13",
|
||||||
"resolved": "https://registry.npmjs.org/nanomatch/-/nanomatch-1.2.13.tgz",
|
"resolved": "https://registry.npmjs.org/nanomatch/-/nanomatch-1.2.13.tgz",
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"codemirror": "^5.57.0",
|
"codemirror": "^5.57.0",
|
||||||
"core-js": "^3.6.5",
|
"core-js": "^3.6.5",
|
||||||
|
"nanoid": "^3.1.12",
|
||||||
"plotly.js": "^1.54.6",
|
"plotly.js": "^1.54.6",
|
||||||
"react": "^16.13.1",
|
"react": "^16.13.1",
|
||||||
"react-chart-editor": "^0.41.7",
|
"react-chart-editor": "^0.41.7",
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ button.toolbar {
|
|||||||
background: transparent;
|
background: transparent;
|
||||||
border: none;
|
border: none;
|
||||||
color: var(--color-text-base);
|
color: var(--color-text-base);
|
||||||
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
button.toolbar:hover {
|
button.toolbar:hover {
|
||||||
|
|||||||
@@ -19,12 +19,14 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { nanoid } from 'nanoid'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'MainMenu',
|
name: 'MainMenu',
|
||||||
methods: {
|
methods: {
|
||||||
createNewQuery () {
|
createNewQuery () {
|
||||||
const tab = {
|
const tab = {
|
||||||
id: Number(new Date()),
|
id: nanoid(),
|
||||||
name: null,
|
name: null,
|
||||||
tempName: this.$store.state.untitledLastIndex
|
tempName: this.$store.state.untitledLastIndex
|
||||||
? `Untitled ${this.$store.state.untitledLastIndex}`
|
? `Untitled ${this.$store.state.untitledLastIndex}`
|
||||||
@@ -69,6 +71,7 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
nav {
|
nav {
|
||||||
height: 68px;
|
height: 68px;
|
||||||
|
|||||||
@@ -3,7 +3,18 @@
|
|||||||
<div id="my-queries-content">
|
<div id="my-queries-content">
|
||||||
<div id="my-queries-toolbar">
|
<div id="my-queries-toolbar">
|
||||||
<div id="toolbar-buttons">
|
<div id="toolbar-buttons">
|
||||||
<button class="toolbar">Import</button>
|
<input
|
||||||
|
ref="importFile"
|
||||||
|
type="file"
|
||||||
|
accept=".json"
|
||||||
|
id="import-file"
|
||||||
|
@change="importQueries"
|
||||||
|
/>
|
||||||
|
<button class="toolbar">
|
||||||
|
<label for="import-file">
|
||||||
|
Import
|
||||||
|
</label>
|
||||||
|
</button>
|
||||||
<button class="toolbar">Export</button>
|
<button class="toolbar">Export</button>
|
||||||
<button class="toolbar">Delete</button>
|
<button class="toolbar">Delete</button>
|
||||||
</div>
|
</div>
|
||||||
@@ -103,6 +114,7 @@ import ExportIcon from '@/components/svg/export'
|
|||||||
import DeleteIcon from '@/components/svg/delete'
|
import DeleteIcon from '@/components/svg/delete'
|
||||||
import CloseIcon from '@/components/svg/close'
|
import CloseIcon from '@/components/svg/close'
|
||||||
import TextField from '@/components/TextField'
|
import TextField from '@/components/TextField'
|
||||||
|
import { nanoid } from 'nanoid'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'MyQueries',
|
name: 'MyQueries',
|
||||||
@@ -179,7 +191,7 @@ export default {
|
|||||||
duplicateQuery (index) {
|
duplicateQuery (index) {
|
||||||
const newQuery = JSON.parse(JSON.stringify(this.queries[index]))
|
const newQuery = JSON.parse(JSON.stringify(this.queries[index]))
|
||||||
newQuery.name = newQuery.name + ' Copy'
|
newQuery.name = newQuery.name + ' Copy'
|
||||||
newQuery.id = Number(new Date())
|
newQuery.id = nanoid()
|
||||||
newQuery.createdAt = new Date()
|
newQuery.createdAt = new Date()
|
||||||
this.queries.push(newQuery)
|
this.queries.push(newQuery)
|
||||||
this.saveQueriesInLocalStorage()
|
this.saveQueriesInLocalStorage()
|
||||||
@@ -215,6 +227,27 @@ export default {
|
|||||||
downloader.click()
|
downloader.click()
|
||||||
window.URL.revokeObjectURL(url)
|
window.URL.revokeObjectURL(url)
|
||||||
},
|
},
|
||||||
|
importQueries () {
|
||||||
|
const file = this.$refs.importFile.files[0]
|
||||||
|
const reader = new FileReader()
|
||||||
|
reader.onload = () => {
|
||||||
|
let importedQueries = JSON.parse(event.target.result)
|
||||||
|
|
||||||
|
if (!Array.isArray(importedQueries)) {
|
||||||
|
importedQueries = [importedQueries]
|
||||||
|
}
|
||||||
|
|
||||||
|
importedQueries.forEach(query => {
|
||||||
|
query.id = nanoid()
|
||||||
|
query.createdAt = new Date()
|
||||||
|
})
|
||||||
|
|
||||||
|
this.queries = this.queries.concat(importedQueries)
|
||||||
|
this.saveQueriesInLocalStorage()
|
||||||
|
this.$refs.importFile.value = null
|
||||||
|
}
|
||||||
|
reader.readAsText(file)
|
||||||
|
},
|
||||||
saveQueriesInLocalStorage () {
|
saveQueriesInLocalStorage () {
|
||||||
localStorage.setItem('myQueries', JSON.stringify(this.queries))
|
localStorage.setItem('myQueries', JSON.stringify(this.queries))
|
||||||
}
|
}
|
||||||
@@ -292,7 +325,17 @@ tbody tr:hover .icons-container {
|
|||||||
.dialog input {
|
.dialog input {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
a {
|
a, #import-file {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
button.toolbar {
|
||||||
|
margin-right: 16px;
|
||||||
|
}
|
||||||
|
button label {
|
||||||
|
display: block;
|
||||||
|
line-height: 36px;
|
||||||
|
}
|
||||||
|
button label:hover {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Reference in New Issue
Block a user