2020-06-12 18:10:45 +02:00
|
|
|
<template>
|
|
|
|
<div class="workspace-query-tab column col-12 columns col-gapless">
|
|
|
|
<div class="workspace-query-runner column col-12">
|
|
|
|
<div class="workspace-query-runner-footer">
|
|
|
|
<div class="workspace-query-buttons">
|
|
|
|
<button
|
|
|
|
class="btn btn-link btn-sm"
|
|
|
|
:class="{'loading':isQuering}"
|
2020-10-04 17:32:15 +02:00
|
|
|
title="F5"
|
2020-08-04 17:54:19 +02:00
|
|
|
@click="reloadTable"
|
2020-06-12 18:10:45 +02:00
|
|
|
>
|
|
|
|
<span>{{ $t('word.refresh') }}</span>
|
2020-08-12 10:48:18 +02:00
|
|
|
<i class="mdi mdi-24px mdi-refresh ml-1" />
|
2020-06-12 18:10:45 +02:00
|
|
|
</button>
|
2020-08-05 22:08:20 +02:00
|
|
|
<button
|
|
|
|
class="btn btn-link btn-sm"
|
|
|
|
:class="{'disabled':isQuering}"
|
|
|
|
@click="showAddModal"
|
|
|
|
>
|
|
|
|
<span>{{ $t('word.add') }}</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>
|
2020-06-12 18:10:45 +02:00
|
|
|
</div>
|
|
|
|
<div class="workspace-query-info">
|
2020-09-14 12:49:09 +02:00
|
|
|
<div v-if="results.length && results[0].rows">
|
|
|
|
{{ $t('word.results') }}: <b>{{ results[0].rows.length }}</b>
|
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>
|
|
|
|
<div class="workspace-query-results column col-12">
|
2020-06-16 18:01:22 +02:00
|
|
|
<WorkspaceQueryTable
|
|
|
|
v-if="results"
|
2020-09-06 08:41:57 +02:00
|
|
|
v-show="!isQuering"
|
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"
|
|
|
|
mode="table"
|
2020-08-18 18:03:59 +02:00
|
|
|
@update-field="updateField"
|
|
|
|
@delete-selected="deleteSelected"
|
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-08-17 15:10:19 +02:00
|
|
|
:tab-uid="tabUid"
|
2020-08-12 18:12:30 +02:00
|
|
|
@hide="hideAddModal"
|
|
|
|
@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';
|
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';
|
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: {
|
2020-08-12 18:12:30 +02:00
|
|
|
WorkspaceQueryTable,
|
|
|
|
ModalNewTableRow
|
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-06-16 18:01:22 +02:00
|
|
|
fields: [],
|
2020-08-14 18:07:29 +02:00
|
|
|
keyUsage: [],
|
2020-08-12 10:48:18 +02:00
|
|
|
lastTable: null,
|
|
|
|
isAddModal: false
|
2020-06-12 18:10:45 +02:00
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
...mapGetters({
|
|
|
|
getWorkspace: 'workspaces/getWorkspace'
|
|
|
|
}),
|
|
|
|
workspace () {
|
|
|
|
return this.getWorkspace(this.connection.uid);
|
|
|
|
},
|
2020-06-13 18:14:32 +02:00
|
|
|
isSelected () {
|
2020-08-19 18:20:57 +02:00
|
|
|
return this.workspace.selected_tab === 'data';
|
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-06-15 18:23:51 +02:00
|
|
|
this.getTableData();
|
2020-06-13 18:14:32 +02:00
|
|
|
this.lastTable = this.table;
|
|
|
|
}
|
|
|
|
},
|
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-06-12 18:10:45 +02:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
...mapActions({
|
2020-08-14 18:07:29 +02:00
|
|
|
addNotification: 'notifications/addNotification',
|
|
|
|
setTabFields: 'workspaces/setTabFields',
|
|
|
|
setTabKeyUsage: 'workspaces/setTabKeyUsage'
|
2020-06-12 18:10:45 +02:00
|
|
|
}),
|
2020-06-15 18:23:51 +02:00
|
|
|
async getTableData () {
|
2020-06-12 18:10:45 +02:00
|
|
|
if (!this.table) return;
|
|
|
|
this.isQuering = true;
|
2020-09-14 11:08:11 +02:00
|
|
|
this.results = [];
|
2020-09-06 08:41:57 +02:00
|
|
|
const fieldsArr = [];
|
|
|
|
const keysArr = [];
|
2020-08-14 18:07:29 +02:00
|
|
|
this.setTabFields({ cUid: this.connection.uid, tUid: this.tabUid, fields: [] });
|
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-06-15 18:23:51 +02:00
|
|
|
table: this.workspace.breadcrumbs.table
|
2020-06-12 18:10:45 +02:00
|
|
|
};
|
|
|
|
|
2020-08-14 18:07:29 +02:00
|
|
|
try { // Columns data
|
2020-07-24 13:26:56 +02:00
|
|
|
const { status, response } = await Tables.getTableColumns(params);
|
2020-08-14 18:07:29 +02:00
|
|
|
if (status === 'success') {
|
|
|
|
this.fields = response;// Needed to add new rows
|
2020-09-06 08:41:57 +02:00
|
|
|
fieldsArr.push(response);
|
2020-08-14 18:07:29 +02:00
|
|
|
}
|
2020-06-15 18:23:51 +02:00
|
|
|
else
|
|
|
|
this.addNotification({ status: 'error', message: response });
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
this.addNotification({ status: 'error', message: err.stack });
|
|
|
|
}
|
|
|
|
|
2020-08-14 18:07:29 +02:00
|
|
|
try { // Table data
|
2020-07-24 13:26:56 +02:00
|
|
|
const { status, response } = await Tables.getTableData(params);
|
2020-06-16 18:01:22 +02:00
|
|
|
|
2020-06-12 18:10:45 +02:00
|
|
|
if (status === 'success')
|
2020-09-14 11:08:11 +02:00
|
|
|
this.results = [response];
|
2020-06-12 18:10:45 +02:00
|
|
|
else
|
|
|
|
this.addNotification({ status: 'error', message: response });
|
2020-08-14 18:07:29 +02:00
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
this.addNotification({ status: 'error', message: err.stack });
|
|
|
|
}
|
|
|
|
|
|
|
|
try { // Key usage (foreign keys)
|
|
|
|
const { status, response } = await Tables.getKeyUsage(params);
|
2020-09-24 13:09:01 +02:00
|
|
|
|
2020-08-14 18:07:29 +02:00
|
|
|
if (status === 'success') {
|
|
|
|
this.keyUsage = response;// Needed to add new rows
|
2020-09-06 08:41:57 +02:00
|
|
|
keysArr.push(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 });
|
|
|
|
}
|
|
|
|
|
2020-09-06 08:41:57 +02:00
|
|
|
this.setTabFields({ cUid: this.connection.uid, tUid: this.tabUid, fields: fieldsArr });
|
|
|
|
this.setTabKeyUsage({ cUid: this.connection.uid, tUid: this.tabUid, keyUsage: keysArr });
|
2020-06-12 18:10:45 +02:00
|
|
|
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-10-04 17:32:15 +02:00
|
|
|
if (!this.isQuering) this.getTableData();
|
2020-08-05 22:08:20 +02:00
|
|
|
},
|
2020-08-12 10:48:18 +02:00
|
|
|
showAddModal () {
|
|
|
|
this.isAddModal = true;
|
|
|
|
},
|
|
|
|
hideAddModal () {
|
|
|
|
this.isAddModal = false;
|
2020-10-04 17:32:15 +02:00
|
|
|
},
|
|
|
|
onKey (e) {
|
|
|
|
e.stopPropagation();
|
|
|
|
if (e.key === 'F5')
|
|
|
|
this.reloadTable();
|
2020-08-12 10:48:18 +02:00
|
|
|
}
|
2020-06-12 18:10:45 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss">
|
2020-07-31 18:16:28 +02:00
|
|
|
.workspace-tabs {
|
|
|
|
align-content: baseline;
|
2020-06-12 18:10:45 +02:00
|
|
|
|
2020-07-31 18:16:28 +02:00
|
|
|
.workspace-query-runner {
|
|
|
|
.workspace-query-runner-footer {
|
|
|
|
display: flex;
|
|
|
|
justify-content: space-between;
|
|
|
|
padding: 0.3rem 0.6rem 0.4rem;
|
|
|
|
align-items: center;
|
2020-06-12 18:10:45 +02:00
|
|
|
|
2020-07-31 18:16:28 +02:00
|
|
|
.workspace-query-buttons {
|
|
|
|
display: flex;
|
2020-06-12 18:10:45 +02:00
|
|
|
|
2020-07-31 18:16:28 +02:00
|
|
|
.btn {
|
|
|
|
display: flex;
|
|
|
|
align-self: center;
|
|
|
|
color: $body-font-color;
|
|
|
|
margin-right: 0.4rem;
|
|
|
|
}
|
|
|
|
}
|
2020-06-12 18:10:45 +02:00
|
|
|
|
2020-07-31 18:16:28 +02:00
|
|
|
.workspace-query-info {
|
|
|
|
display: flex;
|
2020-06-12 18:10:45 +02:00
|
|
|
|
2020-07-31 18:16:28 +02:00
|
|
|
> div + div {
|
|
|
|
padding-left: 0.6rem;
|
|
|
|
}
|
2020-06-12 18:10:45 +02:00
|
|
|
}
|
2020-07-31 18:16:28 +02:00
|
|
|
}
|
|
|
|
}
|
2020-06-12 18:10:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
</style>
|