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-06-15 18:23:51 +02:00
|
|
|
@click="getTableData"
|
2020-06-12 18:10:45 +02:00
|
|
|
>
|
|
|
|
<span>{{ $t('word.refresh') }}</span>
|
|
|
|
<i class="material-icons ml-1">refresh</i>
|
|
|
|
</button>
|
2020-06-16 18:01:22 +02:00
|
|
|
<!-- <button class="btn btn-link btn-sm">
|
2020-06-12 18:10:45 +02:00
|
|
|
<span>{{ $t('word.save') }}</span>
|
|
|
|
<i class="material-icons ml-1">save</i>
|
2020-06-16 18:01:22 +02:00
|
|
|
</button> -->
|
2020-06-12 18:10:45 +02:00
|
|
|
</div>
|
|
|
|
<div class="workspace-query-info">
|
|
|
|
<div v-if="results.rows">
|
|
|
|
{{ $t('word.results') }}: <b>{{ results.rows.length }}</b>
|
|
|
|
</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-06-28 15:31:16 +02:00
|
|
|
ref="queryTable"
|
2020-06-16 18:01:22 +02:00
|
|
|
:results="results"
|
|
|
|
:fields="resultsFields"
|
2020-06-27 15:14:08 +02:00
|
|
|
@updateField="updateField"
|
2020-06-16 18:01:22 +02:00
|
|
|
/>
|
2020-06-12 18:10:45 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2020-06-15 18:23:51 +02:00
|
|
|
import Structure from '@/ipc-api/Structure';
|
2020-06-12 18:10:45 +02:00
|
|
|
import WorkspaceQueryTable from '@/components/WorkspaceQueryTable';
|
|
|
|
import { mapGetters, mapActions } from 'vuex';
|
|
|
|
|
|
|
|
export default {
|
2020-06-13 18:14:32 +02:00
|
|
|
name: 'WorkspaceTableTab',
|
2020-06-12 18:10:45 +02:00
|
|
|
components: {
|
|
|
|
WorkspaceQueryTable
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
connection: Object,
|
|
|
|
table: String
|
|
|
|
},
|
|
|
|
data () {
|
|
|
|
return {
|
|
|
|
isQuering: false,
|
2020-06-13 18:14:32 +02:00
|
|
|
results: {},
|
2020-06-16 18:01:22 +02:00
|
|
|
fields: [],
|
2020-06-13 18:14:32 +02:00
|
|
|
lastTable: null
|
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 () {
|
|
|
|
return this.workspace.selected_tab === 1;
|
2020-06-16 18:01:22 +02:00
|
|
|
},
|
|
|
|
resultsFields () {
|
|
|
|
return this.fields.map(field => { // TODO: move to main process
|
|
|
|
return {
|
|
|
|
name: field.COLUMN_NAME,
|
|
|
|
key: field.COLUMN_KEY.toLowerCase(),
|
|
|
|
type: field.DATA_TYPE
|
|
|
|
};
|
|
|
|
});
|
2020-06-12 18:10:45 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
table: function () {
|
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;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
isSelected: function (val) {
|
|
|
|
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-06-12 18:10:45 +02:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
...mapActions({
|
|
|
|
addNotification: 'notifications/addNotification'
|
|
|
|
}),
|
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;
|
|
|
|
this.results = {};
|
|
|
|
|
|
|
|
const params = {
|
|
|
|
uid: this.connection.uid,
|
2020-06-15 18:23:51 +02:00
|
|
|
schema: this.workspace.breadcrumbs.schema,
|
|
|
|
table: this.workspace.breadcrumbs.table
|
2020-06-12 18:10:45 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
try {
|
2020-06-15 18:23:51 +02:00
|
|
|
const { status, response } = await Structure.getTableColumns(params);
|
|
|
|
if (status === 'success')
|
|
|
|
this.fields = response.rows;
|
|
|
|
else
|
|
|
|
this.addNotification({ status: 'error', message: response });
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
this.addNotification({ status: 'error', message: err.stack });
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
const { status, response } = await Structure.getTableData(params);
|
2020-06-16 18:01:22 +02:00
|
|
|
|
2020-06-12 18:10:45 +02:00
|
|
|
if (status === 'success')
|
|
|
|
this.results = response;
|
|
|
|
else
|
|
|
|
this.addNotification({ status: 'error', message: response });
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
this.addNotification({ status: 'error', message: err.stack });
|
|
|
|
}
|
|
|
|
|
|
|
|
this.isQuering = false;
|
2020-06-27 15:14:08 +02:00
|
|
|
},
|
|
|
|
async updateField (payload) {
|
|
|
|
const params = {
|
|
|
|
uid: this.connection.uid,
|
|
|
|
schema: this.workspace.breadcrumbs.schema,
|
|
|
|
table: this.workspace.breadcrumbs.table,
|
|
|
|
...payload
|
|
|
|
};
|
|
|
|
|
|
|
|
try {
|
|
|
|
const { status, response } = await Structure.updateTableCell(params);
|
2020-06-28 15:31:16 +02:00
|
|
|
if (status === 'success')
|
|
|
|
this.$refs.queryTable.applyUpdate(payload);
|
|
|
|
else
|
2020-06-27 15:14:08 +02:00
|
|
|
this.addNotification({ status: 'error', message: response });
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
this.addNotification({ status: 'error', message: err.stack });
|
|
|
|
}
|
2020-06-12 18:10:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
.workspace-tabs{
|
|
|
|
align-content: baseline;
|
|
|
|
|
|
|
|
.workspace-query-runner{
|
|
|
|
|
|
|
|
.workspace-query-runner-footer{
|
|
|
|
display: flex;
|
|
|
|
justify-content: space-between;
|
|
|
|
padding: .3rem .6rem .4rem;
|
|
|
|
align-items: center;
|
|
|
|
|
|
|
|
.workspace-query-buttons{
|
|
|
|
display: flex;
|
|
|
|
|
|
|
|
.btn{
|
|
|
|
display: flex;
|
|
|
|
align-self: center;
|
|
|
|
color: $body-font-color;
|
|
|
|
margin-right: .4rem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.workspace-query-info{
|
|
|
|
display: flex;
|
|
|
|
|
|
|
|
> div + div{
|
|
|
|
padding-left: .6rem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
</style>
|