2020-06-12 18:10:45 +02:00
|
|
|
<template>
|
2020-10-20 13:30:36 +02:00
|
|
|
<div v-show="isSelected" class="workspace-query-tab column col-12 columns col-gapless">
|
2020-06-12 18:10:45 +02:00
|
|
|
<div class="workspace-query-runner column col-12">
|
|
|
|
<div class="workspace-query-runner-footer">
|
|
|
|
<div class="workspace-query-buttons">
|
2020-10-08 18:51:08 +02:00
|
|
|
<div class="dropdown">
|
|
|
|
<div class="btn-group">
|
|
|
|
<button
|
2020-10-18 10:27:02 +02:00
|
|
|
class="btn btn-dark btn-sm mr-0 pr-1"
|
2020-10-08 18:51:08 +02:00
|
|
|
:class="{'loading':isQuering}"
|
|
|
|
title="F5"
|
|
|
|
@click="reloadTable"
|
|
|
|
>
|
|
|
|
<span>{{ $t('word.refresh') }}</span>
|
|
|
|
<i v-if="!+autorefreshTimer" class="mdi mdi-24px mdi-refresh ml-1" />
|
|
|
|
<i v-else class="mdi mdi-24px mdi-history mdi-flip-h ml-1" />
|
|
|
|
</button>
|
2020-10-18 10:27:02 +02:00
|
|
|
<div class="btn btn-dark btn-sm dropdown-toggle pl-0 pr-0" tabindex="0">
|
2020-10-08 18:51:08 +02:00
|
|
|
<i class="mdi mdi-24px mdi-menu-down" />
|
|
|
|
</div>
|
|
|
|
<div class="menu px-3">
|
|
|
|
<span>{{ $t('word.autoRefresh') }}: <b>{{ +autorefreshTimer ? `${autorefreshTimer}s` : 'OFF' }}</b></span>
|
|
|
|
<input
|
|
|
|
v-model="autorefreshTimer"
|
|
|
|
class="slider no-border"
|
|
|
|
type="range"
|
|
|
|
min="0"
|
|
|
|
max="30"
|
|
|
|
step="1"
|
|
|
|
@change="setRefreshInterval"
|
|
|
|
>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-01-08 21:55:03 +01:00
|
|
|
|
2021-02-16 19:13:20 +01:00
|
|
|
<button
|
|
|
|
v-if="isTable"
|
|
|
|
class="btn btn-dark btn-sm"
|
2021-02-20 18:55:08 +01:00
|
|
|
:disabled="isQuering"
|
2021-02-16 19:13:20 +01:00
|
|
|
@click="showFakerModal"
|
|
|
|
>
|
|
|
|
<span>{{ $t('message.tableFiller') }}</span>
|
2020-08-12 10:48:18 +02:00
|
|
|
<i class="mdi mdi-24px mdi-playlist-plus ml-1" />
|
2020-08-05 22:08:20 +02:00
|
|
|
</button>
|
2021-02-13 18:45:16 +01:00
|
|
|
|
|
|
|
<div class="dropdown export-dropdown pr-2">
|
2021-01-08 21:55:03 +01:00
|
|
|
<button
|
|
|
|
:disabled="isQuering"
|
|
|
|
class="btn btn-dark btn-sm dropdown-toggle mr-0 pr-0"
|
|
|
|
tabindex="0"
|
|
|
|
>
|
|
|
|
<span>{{ $t('word.export') }}</span>
|
|
|
|
<i class="mdi mdi-24px mdi-file-export ml-1" />
|
|
|
|
<i class="mdi mdi-24px mdi-menu-down" />
|
|
|
|
</button>
|
|
|
|
<ul class="menu text-left">
|
|
|
|
<li class="menu-item">
|
|
|
|
<a class="c-hand" @click="downloadTable('json')">JSON</a>
|
|
|
|
</li>
|
|
|
|
<li class="menu-item">
|
|
|
|
<a class="c-hand" @click="downloadTable('csv')">CSV</a>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
2020-06-12 18:10:45 +02:00
|
|
|
</div>
|
|
|
|
<div class="workspace-query-info">
|
2021-02-26 18:45:00 +01:00
|
|
|
<div
|
|
|
|
v-if="results.length"
|
|
|
|
class="d-flex"
|
|
|
|
:title="$t('message.queryDuration')"
|
|
|
|
>
|
|
|
|
<i class="mdi mdi-timer-sand mdi-rotate-180 pr-1" /> <b>{{ results[0].duration / 1000 }}s</b>
|
|
|
|
</div>
|
2020-09-14 12:49:09 +02:00
|
|
|
<div v-if="results.length && results[0].rows">
|
2020-11-25 11:47:35 +01:00
|
|
|
{{ $t('word.results') }}: <b>{{ results[0].rows.length.toLocaleString() }}</b>
|
|
|
|
</div>
|
2021-04-15 10:13:55 +02:00
|
|
|
<div v-if="hasApproximately">
|
2020-11-25 11:47:35 +01:00
|
|
|
{{ $t('word.total') }}: <b>{{ tableInfo.rows.toLocaleString() }}</b> <small>({{ $t('word.approximately') }})</small>
|
2020-06-12 18:10:45 +02:00
|
|
|
</div>
|
|
|
|
<div v-if="workspace.breadcrumbs.database">
|
|
|
|
{{ $t('word.schema') }}: <b>{{ workspace.breadcrumbs.database }}</b>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-03-09 19:14:02 +01:00
|
|
|
<div class="workspace-query-results p-relative column col-12">
|
|
|
|
<BaseLoader v-if="isQuering" />
|
2020-06-16 18:01:22 +02:00
|
|
|
<WorkspaceQueryTable
|
|
|
|
v-if="results"
|
2020-06-28 15:31:16 +02:00
|
|
|
ref="queryTable"
|
2020-09-14 11:08:11 +02:00
|
|
|
:results="results"
|
2020-08-14 18:07:29 +02:00
|
|
|
:tab-uid="tabUid"
|
2020-09-18 12:54:02 +02:00
|
|
|
:conn-uid="connection.uid"
|
2021-03-05 17:10:52 +01:00
|
|
|
:is-selected="isSelected"
|
2020-09-18 12:54:02 +02:00
|
|
|
mode="table"
|
2020-08-18 18:03:59 +02:00
|
|
|
@update-field="updateField"
|
|
|
|
@delete-selected="deleteSelected"
|
2020-12-07 17:51:48 +01:00
|
|
|
@hard-sort="hardSort"
|
2020-06-16 18:01:22 +02:00
|
|
|
/>
|
2020-06-12 18:10:45 +02:00
|
|
|
</div>
|
2020-08-12 18:12:30 +02:00
|
|
|
<ModalNewTableRow
|
|
|
|
v-if="isAddModal"
|
2020-10-27 16:41:00 +01:00
|
|
|
:fields="fields"
|
|
|
|
:key-usage="keyUsage"
|
2020-08-17 15:10:19 +02:00
|
|
|
:tab-uid="tabUid"
|
2020-08-12 18:12:30 +02:00
|
|
|
@hide="hideAddModal"
|
|
|
|
@reload="reloadTable"
|
|
|
|
/>
|
2021-02-13 18:45:16 +01:00
|
|
|
<ModalFakerRows
|
|
|
|
v-if="isFakerModal"
|
|
|
|
:fields="fields"
|
|
|
|
:key-usage="keyUsage"
|
|
|
|
:tab-uid="tabUid"
|
|
|
|
@hide="hideFakerModal"
|
|
|
|
@reload="reloadTable"
|
|
|
|
/>
|
2020-06-12 18:10:45 +02:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2020-07-24 13:26:56 +02:00
|
|
|
import Tables from '@/ipc-api/Tables';
|
2021-03-09 19:14:02 +01:00
|
|
|
import BaseLoader from '@/components/BaseLoader';
|
2020-06-12 18:10:45 +02:00
|
|
|
import WorkspaceQueryTable from '@/components/WorkspaceQueryTable';
|
2020-08-12 18:12:30 +02:00
|
|
|
import ModalNewTableRow from '@/components/ModalNewTableRow';
|
2021-02-13 18:45:16 +01:00
|
|
|
import ModalFakerRows from '@/components/ModalFakerRows';
|
2020-06-12 18:10:45 +02:00
|
|
|
import { mapGetters, mapActions } from 'vuex';
|
2020-07-23 19:10:14 +02:00
|
|
|
import tableTabs from '@/mixins/tableTabs';
|
2020-06-12 18:10:45 +02:00
|
|
|
|
|
|
|
export default {
|
2020-06-13 18:14:32 +02:00
|
|
|
name: 'WorkspaceTableTab',
|
2020-06-12 18:10:45 +02:00
|
|
|
components: {
|
2021-03-09 19:14:02 +01:00
|
|
|
BaseLoader,
|
2020-08-12 18:12:30 +02:00
|
|
|
WorkspaceQueryTable,
|
2021-02-13 18:45:16 +01:00
|
|
|
ModalNewTableRow,
|
|
|
|
ModalFakerRows
|
2020-06-12 18:10:45 +02:00
|
|
|
},
|
2020-07-23 19:10:14 +02:00
|
|
|
mixins: [tableTabs],
|
2020-06-12 18:10:45 +02:00
|
|
|
props: {
|
|
|
|
connection: Object,
|
|
|
|
table: String
|
|
|
|
},
|
|
|
|
data () {
|
|
|
|
return {
|
2020-08-19 18:20:57 +02:00
|
|
|
tabUid: 'data',
|
2020-06-12 18:10:45 +02:00
|
|
|
isQuering: false,
|
2020-09-14 11:08:11 +02:00
|
|
|
results: [],
|
2020-08-12 10:48:18 +02:00
|
|
|
lastTable: null,
|
2020-10-08 18:51:08 +02:00
|
|
|
isAddModal: false,
|
2021-02-13 18:45:16 +01:00
|
|
|
isFakerModal: false,
|
2020-10-08 18:51:08 +02:00
|
|
|
autorefreshTimer: 0,
|
2020-12-08 18:41:08 +01:00
|
|
|
refreshInterval: null,
|
|
|
|
sortParams: {}
|
2020-06-12 18:10:45 +02:00
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
...mapGetters({
|
2021-02-18 18:01:12 +01:00
|
|
|
getWorkspace: 'workspaces/getWorkspace',
|
|
|
|
selectedWorkspace: 'workspaces/getSelected'
|
2020-06-12 18:10:45 +02:00
|
|
|
}),
|
|
|
|
workspace () {
|
|
|
|
return this.getWorkspace(this.connection.uid);
|
|
|
|
},
|
2020-06-13 18:14:32 +02:00
|
|
|
isSelected () {
|
2021-02-18 18:01:12 +01:00
|
|
|
return this.workspace.selected_tab === 'data' && this.workspace.uid === this.selectedWorkspace;
|
2020-10-27 16:41:00 +01:00
|
|
|
},
|
2021-02-16 19:13:20 +01:00
|
|
|
isTable () {
|
|
|
|
return !!this.workspace.breadcrumbs.table;
|
|
|
|
},
|
2020-10-27 16:41:00 +01:00
|
|
|
fields () {
|
|
|
|
return this.results.length ? this.results[0].fields : [];
|
|
|
|
},
|
|
|
|
keyUsage () {
|
|
|
|
return this.results.length ? this.results[0].keys : [];
|
2020-11-25 11:47:35 +01:00
|
|
|
},
|
|
|
|
tableInfo () {
|
2020-12-03 16:15:10 +01:00
|
|
|
try {
|
|
|
|
return this.workspace.structure.find(db => db.name === this.schema).tables.find(table => table.name === this.table);
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
return { rows: 0 };
|
|
|
|
}
|
2021-04-15 10:13:55 +02:00
|
|
|
},
|
|
|
|
hasApproximately () {
|
|
|
|
return this.results.length &&
|
|
|
|
this.results[0].rows &&
|
|
|
|
this.tableInfo &&
|
|
|
|
this.results[0].rows.length === 1000 &&
|
|
|
|
this.results[0].rows.length < this.tableInfo.rows;
|
2020-06-12 18:10:45 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
watch: {
|
2020-07-24 13:26:56 +02:00
|
|
|
table () {
|
2020-06-13 18:14:32 +02:00
|
|
|
if (this.isSelected) {
|
2020-12-08 18:41:08 +01:00
|
|
|
this.sortParams = {};
|
2020-06-15 18:23:51 +02:00
|
|
|
this.getTableData();
|
2020-06-13 18:14:32 +02:00
|
|
|
this.lastTable = this.table;
|
2020-12-07 17:51:48 +01:00
|
|
|
this.$refs.queryTable.resetSort();
|
2020-06-13 18:14:32 +02:00
|
|
|
}
|
|
|
|
},
|
2020-07-24 13:26:56 +02:00
|
|
|
isSelected (val) {
|
2020-06-13 18:14:32 +02:00
|
|
|
if (val && this.lastTable !== this.table) {
|
2020-06-15 18:23:51 +02:00
|
|
|
this.getTableData();
|
2020-06-13 18:14:32 +02:00
|
|
|
this.lastTable = this.table;
|
|
|
|
}
|
2020-06-12 18:10:45 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
created () {
|
2020-06-15 18:23:51 +02:00
|
|
|
this.getTableData();
|
2020-10-04 17:32:15 +02:00
|
|
|
window.addEventListener('keydown', this.onKey);
|
|
|
|
},
|
|
|
|
beforeDestroy () {
|
|
|
|
window.removeEventListener('keydown', this.onKey);
|
2020-10-08 18:51:08 +02:00
|
|
|
clearInterval(this.refreshInterval);
|
2020-06-12 18:10:45 +02:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
...mapActions({
|
2020-10-27 16:41:00 +01:00
|
|
|
addNotification: 'notifications/addNotification'
|
2020-06-12 18:10:45 +02:00
|
|
|
}),
|
2020-12-07 17:51:48 +01:00
|
|
|
async getTableData (sortParams) {
|
2020-06-12 18:10:45 +02:00
|
|
|
if (!this.table) return;
|
|
|
|
this.isQuering = true;
|
2020-10-07 20:42:04 +02:00
|
|
|
|
|
|
|
// if table changes clear cached values
|
2020-10-27 16:41:00 +01:00
|
|
|
if (this.lastTable !== this.table)
|
2020-10-07 20:42:04 +02:00
|
|
|
this.results = [];
|
2020-06-12 18:10:45 +02:00
|
|
|
|
|
|
|
const params = {
|
|
|
|
uid: this.connection.uid,
|
2020-09-08 11:47:01 +02:00
|
|
|
schema: this.schema,
|
2020-12-26 14:47:15 +01:00
|
|
|
table: this.workspace.breadcrumbs.table || this.workspace.breadcrumbs.view,
|
2020-12-07 17:51:48 +01:00
|
|
|
sortParams
|
2020-06-12 18:10:45 +02:00
|
|
|
};
|
|
|
|
|
2020-10-07 20:42:04 +02:00
|
|
|
try { // Table data
|
|
|
|
const { status, response } = await Tables.getTableData(params);
|
2020-09-24 13:09:01 +02:00
|
|
|
|
2020-10-07 20:42:04 +02:00
|
|
|
if (status === 'success')
|
|
|
|
this.results = [response];
|
2020-08-14 18:07:29 +02:00
|
|
|
else
|
|
|
|
this.addNotification({ status: 'error', message: response });
|
2020-06-12 18:10:45 +02:00
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
this.addNotification({ status: 'error', message: err.stack });
|
|
|
|
}
|
|
|
|
|
|
|
|
this.isQuering = false;
|
2020-08-04 17:54:19 +02:00
|
|
|
},
|
2020-09-06 10:35:32 +02:00
|
|
|
getTable () {
|
|
|
|
return this.table;
|
|
|
|
},
|
2020-08-04 17:54:19 +02:00
|
|
|
reloadTable () {
|
2020-12-08 18:41:08 +01:00
|
|
|
this.getTableData(this.sortParams);
|
2020-08-05 22:08:20 +02:00
|
|
|
},
|
2020-12-07 17:51:48 +01:00
|
|
|
hardSort (sortParams) {
|
2020-12-08 18:41:08 +01:00
|
|
|
this.sortParams = sortParams;
|
2020-12-07 17:51:48 +01:00
|
|
|
this.getTableData(sortParams);
|
|
|
|
},
|
2020-08-12 10:48:18 +02:00
|
|
|
showAddModal () {
|
|
|
|
this.isAddModal = true;
|
|
|
|
},
|
|
|
|
hideAddModal () {
|
|
|
|
this.isAddModal = false;
|
2020-10-04 17:32:15 +02:00
|
|
|
},
|
2021-02-13 18:45:16 +01:00
|
|
|
showFakerModal () {
|
2021-02-20 18:55:08 +01:00
|
|
|
if (this.isQuering) return;
|
2021-02-13 18:45:16 +01:00
|
|
|
this.isFakerModal = true;
|
|
|
|
},
|
|
|
|
hideFakerModal () {
|
|
|
|
this.isFakerModal = false;
|
|
|
|
},
|
2020-10-04 17:32:15 +02:00
|
|
|
onKey (e) {
|
2020-11-13 12:39:40 +01:00
|
|
|
if (this.isSelected) {
|
|
|
|
e.stopPropagation();
|
2020-10-27 17:04:39 +01:00
|
|
|
if (e.key === 'F5')
|
|
|
|
this.reloadTable();
|
|
|
|
}
|
2020-10-08 18:51:08 +02:00
|
|
|
},
|
|
|
|
setRefreshInterval () {
|
|
|
|
if (this.refreshInterval)
|
|
|
|
clearInterval(this.refreshInterval);
|
|
|
|
|
|
|
|
if (+this.autorefreshTimer) {
|
|
|
|
this.refreshInterval = setInterval(() => {
|
|
|
|
if (!this.isQuering)
|
|
|
|
this.reloadTable();
|
|
|
|
}, this.autorefreshTimer * 1000);
|
|
|
|
}
|
2021-01-08 21:55:03 +01:00
|
|
|
},
|
|
|
|
downloadTable (format) {
|
|
|
|
this.$refs.queryTable.downloadTable(format, this.table);
|
2020-08-12 10:48:18 +02:00
|
|
|
}
|
2020-06-12 18:10:45 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|
2021-01-08 21:55:03 +01:00
|
|
|
<style lang="scss" scoped>
|
|
|
|
.export-dropdown {
|
|
|
|
.menu {
|
|
|
|
min-width: 100%;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|