mirror of
https://github.com/lana-k/sqliteviz.git
synced 2025-12-07 02:28:54 +08:00
events refactor
This commit is contained in:
@@ -112,6 +112,7 @@ import SqlTable from '@/components/SqlTable'
|
||||
import Logs from '@/components/Logs'
|
||||
import time from '@/lib/utils/time'
|
||||
import fIo from '@/lib/utils/fileIo'
|
||||
import { send } from '@/lib/utils/events'
|
||||
|
||||
export default {
|
||||
name: 'CsvImport',
|
||||
@@ -335,6 +336,7 @@ export default {
|
||||
this.$store.commit('setCurrentTabId', tabId)
|
||||
this.importCsvCompleted = false
|
||||
this.$emit('finish')
|
||||
send('inquiry.create', undefined, { auto: true })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,11 +128,9 @@ export default {
|
||||
if (fIo.isDatabase(file)) {
|
||||
this.loadDb(file)
|
||||
} else {
|
||||
send({
|
||||
category: 'database',
|
||||
action: 'import',
|
||||
value: file.size,
|
||||
label: 'from=csv new_db=true'
|
||||
send('database.import', file.size, {
|
||||
from: 'csv',
|
||||
new_db: true
|
||||
})
|
||||
|
||||
this.file = file
|
||||
|
||||
@@ -79,13 +79,9 @@ 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'
|
||||
send('database.import', file ? file.size : 0, {
|
||||
from: file ? 'sqlite' : 'none',
|
||||
new_db: true
|
||||
})
|
||||
}
|
||||
|
||||
@@ -125,12 +121,7 @@ class Database {
|
||||
throw new Error(data.error)
|
||||
}
|
||||
fu.exportToFile(data, fileName)
|
||||
send({
|
||||
category: 'database',
|
||||
action: 'export',
|
||||
value: data.byteLength,
|
||||
label: 'to=sqlite'
|
||||
})
|
||||
send('database.export', data.byteLength, { to: 'sqlite' })
|
||||
}
|
||||
|
||||
async validateTableName (name) {
|
||||
|
||||
@@ -106,11 +106,7 @@ export default {
|
||||
.then(str => {
|
||||
const inquires = this.deserialiseInquiries(str)
|
||||
|
||||
send({
|
||||
category: 'inquiry',
|
||||
action: 'import',
|
||||
value: inquires.length
|
||||
})
|
||||
send('inquiry.import', inquires.length)
|
||||
|
||||
return inquires
|
||||
})
|
||||
@@ -119,11 +115,7 @@ export default {
|
||||
const jsonStr = this.serialiseInquiries(inquiryList)
|
||||
fu.exportToFile(jsonStr, fileName)
|
||||
|
||||
send({
|
||||
category: 'inquiry',
|
||||
action: 'export',
|
||||
value: inquiryList.length
|
||||
})
|
||||
send('inquiry.export', inquiryList.length)
|
||||
},
|
||||
|
||||
async readPredefinedInquiries () {
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
export function send (payload) {
|
||||
console.log(payload)
|
||||
export function send (name, value, labels) {
|
||||
console.log(name, value, labels)
|
||||
|
||||
const event = new CustomEvent('sqliteviz-app-event', {
|
||||
detail: payload
|
||||
detail: {
|
||||
name,
|
||||
value,
|
||||
labels
|
||||
}
|
||||
})
|
||||
window.dispatchEvent(event)
|
||||
}
|
||||
|
||||
@@ -44,9 +44,6 @@ if ('serviceWorker' in navigator) {
|
||||
})
|
||||
|
||||
window.addEventListener('appinstalled', () => {
|
||||
send({
|
||||
category: 'pwa',
|
||||
action: 'install'
|
||||
})
|
||||
send('pwa.install')
|
||||
})
|
||||
}
|
||||
|
||||
@@ -112,11 +112,7 @@ export default {
|
||||
}
|
||||
})
|
||||
|
||||
send({
|
||||
category: 'inquiry',
|
||||
action: 'create',
|
||||
label: 'auto=false'
|
||||
})
|
||||
send('inquiry.create', undefined, { auto: false })
|
||||
},
|
||||
cancelSave () {
|
||||
this.$modal.hide('save')
|
||||
@@ -170,10 +166,7 @@ export default {
|
||||
|
||||
// Signal about saving
|
||||
this.$root.$emit('inquirySaved')
|
||||
send({
|
||||
category: 'inquiry',
|
||||
action: 'save'
|
||||
})
|
||||
send('inquiry.save')
|
||||
},
|
||||
_keyListener (e) {
|
||||
if (this.$route.path === '/workspace') {
|
||||
|
||||
@@ -88,11 +88,9 @@ export default {
|
||||
await csvImport.previewCsv()
|
||||
csvImport.open()
|
||||
|
||||
send({
|
||||
category: 'database',
|
||||
action: 'import',
|
||||
value: this.file.size,
|
||||
label: 'from=csv new_db=false'
|
||||
send('database.import', this.file.size, {
|
||||
from: 'csv',
|
||||
new_db: false
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,10 +70,9 @@ export default {
|
||||
this.state.data.map(trace => `${trace.type}-${trace.mode}`)
|
||||
),
|
||||
(value) => {
|
||||
send({
|
||||
category: 'viz_plotly',
|
||||
action: 'render',
|
||||
label: `type=${value} pivot=${this.forPivot ? 'true' : 'false'}`
|
||||
send('viz_plotly.render', undefined, {
|
||||
type: value,
|
||||
pivot: !!this.forPivot
|
||||
})
|
||||
},
|
||||
{ deep: true }
|
||||
|
||||
@@ -88,12 +88,16 @@ export default {
|
||||
'pivotOptions.rendererName': {
|
||||
immediate: true,
|
||||
handler () {
|
||||
this.$emit('update:importToPngEnabled', this.pivotOptions.rendererName !== 'TSV Export')
|
||||
this.$emit('update:importToSvgEnabled', this.viewStandartChart || this.viewCustomChart)
|
||||
send({
|
||||
category: 'viz_pivot',
|
||||
action: 'render',
|
||||
label: `type=${this.pivotOptions.rendererName}`
|
||||
this.$emit(
|
||||
'update:importToPngEnabled',
|
||||
this.pivotOptions.rendererName !== 'TSV Export'
|
||||
)
|
||||
this.$emit(
|
||||
'update:importToSvgEnabled',
|
||||
this.viewStandartChart || this.viewCustomChart
|
||||
)
|
||||
send('viz_pivot.render', undefined, {
|
||||
type: this.pivotOptions.rendererName
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
@@ -201,13 +201,19 @@ export default {
|
||||
this.exportSignal('html')
|
||||
},
|
||||
exportSignal (to) {
|
||||
send({
|
||||
category: this.plotlyInPivot || this.mode === 'chart'
|
||||
? 'viz_plotly' : 'viz_pivot',
|
||||
action: 'export',
|
||||
label: `type=${to}${this.plotlyInPivot
|
||||
? ' pivot=true' : this.mode === 'chart' ? ' pivot=false' : ''}`
|
||||
})
|
||||
const eventLabels = { type: to }
|
||||
|
||||
if (this.mode === 'chart' || this.plotlyInPivot) {
|
||||
eventLabels.pivot = this.plotlyInPivot
|
||||
}
|
||||
|
||||
send(
|
||||
this.mode === 'chart' || this.plotlyInPivot
|
||||
? 'viz_plotly.export'
|
||||
: 'viz_pivot.export',
|
||||
undefined,
|
||||
eventLabels
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,12 +119,10 @@ export default {
|
||||
|
||||
exportToCsv () {
|
||||
if (this.result && this.result.values) {
|
||||
send({
|
||||
category: 'resultset',
|
||||
action: 'export',
|
||||
value: this.result.values[this.result.columns[0]].length,
|
||||
label: 'to=csv'
|
||||
})
|
||||
send('resultset.export',
|
||||
this.result.values[this.result.columns[0]].length,
|
||||
{ to: 'csv' }
|
||||
)
|
||||
}
|
||||
|
||||
fIo.exportToFile(csv.serialize(this.result), 'result_set.csv', 'text/csv')
|
||||
@@ -132,12 +130,10 @@ export default {
|
||||
|
||||
async prepareCopy () {
|
||||
if (this.result && this.result.values) {
|
||||
send({
|
||||
category: 'resultset',
|
||||
action: 'export',
|
||||
value: this.result.values[this.result.columns[0]].length,
|
||||
label: 'to=clipboard'
|
||||
})
|
||||
send('resultset.export',
|
||||
this.result.values[this.result.columns[0]].length,
|
||||
{ to: 'clipboard' }
|
||||
)
|
||||
}
|
||||
|
||||
if ('ClipboardItem' in window) {
|
||||
|
||||
@@ -109,6 +109,8 @@ export default {
|
||||
const fromPosition = this.layout[from]
|
||||
this.layout[from] = this.layout[to]
|
||||
this.layout[to] = fromPosition
|
||||
|
||||
send('inquiry.panel', undefined, { panel: to })
|
||||
},
|
||||
onDataViewUpdate () {
|
||||
this.$store.commit('updateTab', { index: this.tabIndex, isSaved: false })
|
||||
@@ -124,31 +126,19 @@ export default {
|
||||
this.time = time.getPeriod(start, new Date())
|
||||
|
||||
if (this.result && this.result.values) {
|
||||
send({
|
||||
category: 'resultset',
|
||||
action: 'create',
|
||||
value: this.result.values[this.result.columns[0]].length
|
||||
})
|
||||
send('resultset.create',
|
||||
this.result.values[this.result.columns[0]].length
|
||||
)
|
||||
}
|
||||
|
||||
send({
|
||||
category: 'query',
|
||||
action: 'run',
|
||||
value: this.time,
|
||||
label: 'status=success'
|
||||
})
|
||||
send('query.run', parseFloat(this.time), { status: 'success' })
|
||||
} catch (err) {
|
||||
this.error = {
|
||||
type: 'error',
|
||||
message: err
|
||||
}
|
||||
|
||||
send({
|
||||
category: 'query',
|
||||
action: 'run',
|
||||
value: 0,
|
||||
label: 'status=error'
|
||||
})
|
||||
send('query.run', 0, { status: 'error' })
|
||||
}
|
||||
state.db.refreshSchema()
|
||||
this.isGettingResults = false
|
||||
|
||||
@@ -51,11 +51,7 @@ export default {
|
||||
const tabId = await this.$store.dispatch('addTab', { query: stmt })
|
||||
this.$store.commit('setCurrentTabId', tabId)
|
||||
|
||||
send({
|
||||
category: 'inquiry',
|
||||
action: 'create',
|
||||
label: 'auto=true'
|
||||
})
|
||||
send('inquiry.create', undefined, { auto: true })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user