diff --git a/src/components/CsvImport/index.vue b/src/components/CsvImport/index.vue index 07a3af7..2b979f3 100644 --- a/src/components/CsvImport/index.vue +++ b/src/components/CsvImport/index.vue @@ -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 }) } } } diff --git a/src/components/DbUploader.vue b/src/components/DbUploader.vue index 18f2067..793f216 100644 --- a/src/components/DbUploader.vue +++ b/src/components/DbUploader.vue @@ -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 diff --git a/src/lib/database/index.js b/src/lib/database/index.js index 16f1704..b38be66 100644 --- a/src/lib/database/index.js +++ b/src/lib/database/index.js @@ -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) { diff --git a/src/lib/storedInquiries/index.js b/src/lib/storedInquiries/index.js index 5421d32..0a1da44 100644 --- a/src/lib/storedInquiries/index.js +++ b/src/lib/storedInquiries/index.js @@ -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 () { diff --git a/src/lib/utils/events.js b/src/lib/utils/events.js index 0c0b5ea..01bf4d7 100644 --- a/src/lib/utils/events.js +++ b/src/lib/utils/events.js @@ -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) } diff --git a/src/registerServiceWorker.js b/src/registerServiceWorker.js index 2255438..89703d0 100644 --- a/src/registerServiceWorker.js +++ b/src/registerServiceWorker.js @@ -44,9 +44,6 @@ if ('serviceWorker' in navigator) { }) window.addEventListener('appinstalled', () => { - send({ - category: 'pwa', - action: 'install' - }) + send('pwa.install') }) } diff --git a/src/views/Main/MainMenu.vue b/src/views/Main/MainMenu.vue index cea5ae7..5063cea 100644 --- a/src/views/Main/MainMenu.vue +++ b/src/views/Main/MainMenu.vue @@ -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') { diff --git a/src/views/Main/Workspace/Schema/index.vue b/src/views/Main/Workspace/Schema/index.vue index e19e2ea..62997c3 100644 --- a/src/views/Main/Workspace/Schema/index.vue +++ b/src/views/Main/Workspace/Schema/index.vue @@ -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 }) } } diff --git a/src/views/Main/Workspace/Tabs/Tab/DataView/Chart/index.vue b/src/views/Main/Workspace/Tabs/Tab/DataView/Chart/index.vue index 9b4b84f..fa096fc 100644 --- a/src/views/Main/Workspace/Tabs/Tab/DataView/Chart/index.vue +++ b/src/views/Main/Workspace/Tabs/Tab/DataView/Chart/index.vue @@ -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 } diff --git a/src/views/Main/Workspace/Tabs/Tab/DataView/Pivot/index.vue b/src/views/Main/Workspace/Tabs/Tab/DataView/Pivot/index.vue index 6f44deb..d2f68c0 100644 --- a/src/views/Main/Workspace/Tabs/Tab/DataView/Pivot/index.vue +++ b/src/views/Main/Workspace/Tabs/Tab/DataView/Pivot/index.vue @@ -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 }) } }, diff --git a/src/views/Main/Workspace/Tabs/Tab/DataView/index.vue b/src/views/Main/Workspace/Tabs/Tab/DataView/index.vue index 02e4f7d..8b28a61 100644 --- a/src/views/Main/Workspace/Tabs/Tab/DataView/index.vue +++ b/src/views/Main/Workspace/Tabs/Tab/DataView/index.vue @@ -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 + ) } } } diff --git a/src/views/Main/Workspace/Tabs/Tab/RunResult.vue b/src/views/Main/Workspace/Tabs/Tab/RunResult.vue index b12c991..23ba50d 100644 --- a/src/views/Main/Workspace/Tabs/Tab/RunResult.vue +++ b/src/views/Main/Workspace/Tabs/Tab/RunResult.vue @@ -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) { diff --git a/src/views/Main/Workspace/Tabs/Tab/index.vue b/src/views/Main/Workspace/Tabs/Tab/index.vue index a27fbd3..0c905b4 100644 --- a/src/views/Main/Workspace/Tabs/Tab/index.vue +++ b/src/views/Main/Workspace/Tabs/Tab/index.vue @@ -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 diff --git a/src/views/Main/Workspace/index.vue b/src/views/Main/Workspace/index.vue index ae02060..2ec0793 100644 --- a/src/views/Main/Workspace/index.vue +++ b/src/views/Main/Workspace/index.vue @@ -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 }) } } }