mirror of
https://github.com/lana-k/sqliteviz.git
synced 2025-12-10 03:58:54 +08:00
events
This commit is contained in:
@@ -7,6 +7,8 @@ import Worker from './_worker.js'
|
||||
// https://github.com/nolanlawson/promise-worker
|
||||
import PromiseWorker from 'promise-worker'
|
||||
|
||||
import { send } from '@/lib/utils/events'
|
||||
|
||||
function getNewDatabase () {
|
||||
const worker = new Worker()
|
||||
return new Database(worker)
|
||||
@@ -76,6 +78,15 @@ class Database {
|
||||
|
||||
this.dbName = file ? fu.getFileName(file) : 'database'
|
||||
this.refreshSchema()
|
||||
|
||||
send({
|
||||
category: 'database',
|
||||
action: 'import',
|
||||
value: file ? file.size : 0,
|
||||
label: file
|
||||
? 'from=sqlite new_db=true'
|
||||
: 'from=none new_db=true'
|
||||
})
|
||||
}
|
||||
|
||||
async refreshSchema () {
|
||||
@@ -114,6 +125,12 @@ class Database {
|
||||
throw new Error(data.error)
|
||||
}
|
||||
fu.exportToFile(data, fileName)
|
||||
send({
|
||||
category: 'database',
|
||||
action: 'export',
|
||||
value: data.byteLength,
|
||||
label: 'to=sqlite'
|
||||
})
|
||||
}
|
||||
|
||||
async validateTableName (name) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { nanoid } from 'nanoid'
|
||||
import fu from '@/lib/utils/fileIo'
|
||||
import { send } from '@/lib/utils/events'
|
||||
import migration from './_migrations'
|
||||
|
||||
const migrate = migration._migrate
|
||||
@@ -103,9 +104,27 @@ export default {
|
||||
importInquiries () {
|
||||
return fu.importFile()
|
||||
.then(str => {
|
||||
return this.deserialiseInquiries(str)
|
||||
const inquires = this.deserialiseInquiries(str)
|
||||
|
||||
send({
|
||||
category: 'inquiry',
|
||||
action: 'import',
|
||||
value: inquires.length
|
||||
})
|
||||
|
||||
return inquires
|
||||
})
|
||||
},
|
||||
export (inquiryList, fileName) {
|
||||
const jsonStr = this.serialiseInquiries(inquiryList)
|
||||
fu.exportToFile(jsonStr, fileName)
|
||||
|
||||
send({
|
||||
category: 'inquiry',
|
||||
action: 'export',
|
||||
value: inquiryList.length
|
||||
})
|
||||
},
|
||||
|
||||
async readPredefinedInquiries () {
|
||||
const res = await fu.readFile('./inquiries.json')
|
||||
|
||||
11
src/lib/utils/events.js
Normal file
11
src/lib/utils/events.js
Normal file
@@ -0,0 +1,11 @@
|
||||
export function send (payload) {
|
||||
console.log(payload)
|
||||
if (!window.sendEvent) {
|
||||
return
|
||||
}
|
||||
|
||||
const event = new CustomEvent('sqliteviz-app-event', {
|
||||
detail: payload
|
||||
})
|
||||
window.dispatchEvent(event)
|
||||
}
|
||||
Reference in New Issue
Block a user