2020-06-06 16:27:42 +02:00
|
|
|
<template>
|
|
|
|
<div class="workspace-query-tab column col-12 columns col-gapless">
|
|
|
|
<div class="workspace-query-runner column col-12">
|
|
|
|
<QueryEditor v-model="query" />
|
|
|
|
<div class="workspace-query-runner-footer">
|
|
|
|
<div class="workspace-query-buttons">
|
2020-06-10 19:29:10 +02:00
|
|
|
<button
|
|
|
|
class="btn btn-link btn-sm"
|
|
|
|
:class="{'loading':isQuering}"
|
|
|
|
@click="runQuery"
|
|
|
|
>
|
|
|
|
<span>{{ $t('word.run') }}</span>
|
|
|
|
<i class="material-icons text-success">play_arrow</i>
|
|
|
|
</button>
|
|
|
|
<button class="btn btn-link btn-sm">
|
|
|
|
<span>{{ $t('word.save') }}</span>
|
|
|
|
<i class="material-icons ml-1">save</i>
|
|
|
|
</button>
|
2020-06-06 16:27:42 +02:00
|
|
|
</div>
|
2020-06-10 19:29:10 +02:00
|
|
|
<div v-if="workspace.breadcrumbs.database">
|
|
|
|
{{ $t('word.schema') }}: <b>{{ workspace.breadcrumbs.database }}</b>
|
2020-06-06 16:27:42 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2020-06-11 23:34:38 +02:00
|
|
|
<div class="workspace-query-results column col-12">
|
2020-06-10 19:29:10 +02:00
|
|
|
<WorkspaceQueryTable v-if="results" :results="results" />
|
2020-06-06 16:27:42 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2020-06-07 14:38:38 +02:00
|
|
|
import Connection from '@/ipc-api/Connection';
|
2020-06-06 16:27:42 +02:00
|
|
|
import QueryEditor from '@/components/QueryEditor';
|
2020-06-10 19:29:10 +02:00
|
|
|
import WorkspaceQueryTable from '@/components/WorkspaceQueryTable';
|
2020-06-06 16:27:42 +02:00
|
|
|
import { mapGetters, mapActions } from 'vuex';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'WorkspaceQueryTab',
|
|
|
|
components: {
|
2020-06-10 19:29:10 +02:00
|
|
|
QueryEditor,
|
|
|
|
WorkspaceQueryTable
|
2020-06-06 16:27:42 +02:00
|
|
|
},
|
|
|
|
props: {
|
|
|
|
connection: Object
|
|
|
|
},
|
|
|
|
data () {
|
|
|
|
return {
|
|
|
|
query: '',
|
2020-06-10 19:29:10 +02:00
|
|
|
isQuering: false,
|
2020-06-07 14:38:38 +02:00
|
|
|
results: {}
|
2020-06-06 16:27:42 +02:00
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
...mapGetters({
|
|
|
|
getWorkspace: 'workspaces/getWorkspace'
|
|
|
|
}),
|
|
|
|
workspace () {
|
|
|
|
return this.getWorkspace(this.connection.uid);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
...mapActions({
|
|
|
|
addNotification: 'notifications/addNotification'
|
|
|
|
}),
|
|
|
|
async runQuery () {
|
2020-06-07 14:38:38 +02:00
|
|
|
if (!this.query) return;
|
2020-06-10 19:29:10 +02:00
|
|
|
this.isQuering = true;
|
2020-06-07 14:38:38 +02:00
|
|
|
this.results = {};
|
2020-06-06 16:27:42 +02:00
|
|
|
|
|
|
|
const params = {
|
2020-06-07 14:38:38 +02:00
|
|
|
uid: this.connection.uid,
|
2020-06-06 16:27:42 +02:00
|
|
|
query: this.query,
|
|
|
|
database: this.workspace.breadcrumbs.database
|
|
|
|
};
|
|
|
|
|
|
|
|
try {
|
2020-06-07 14:38:38 +02:00
|
|
|
const { status, response } = await Connection.rawQuery(params);
|
|
|
|
if (status === 'success')
|
|
|
|
this.results = response;
|
|
|
|
else
|
|
|
|
this.addNotification({ status: 'error', message: response });
|
2020-06-06 16:27:42 +02:00
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
this.addNotification({ status: 'error', message: err.stack });
|
|
|
|
}
|
2020-06-10 19:29:10 +02:00
|
|
|
|
|
|
|
this.isQuering = false;
|
2020-06-06 16:27:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
.workspace-tabs{
|
|
|
|
align-content: baseline;
|
|
|
|
|
|
|
|
.workspace-query-runner{
|
|
|
|
|
|
|
|
.workspace-query-runner-footer{
|
|
|
|
display: flex;
|
|
|
|
justify-content: space-between;
|
2020-06-10 19:29:10 +02:00
|
|
|
padding: .3rem .6rem .4rem;
|
2020-06-06 16:27:42 +02:00
|
|
|
align-items: center;
|
|
|
|
|
|
|
|
.workspace-query-buttons{
|
|
|
|
display: flex;
|
2020-06-10 19:29:10 +02:00
|
|
|
|
|
|
|
.btn{
|
|
|
|
display: flex;
|
|
|
|
align-self: center;
|
|
|
|
color: $body-font-color;
|
|
|
|
margin-right: .4rem;
|
|
|
|
}
|
2020-06-06 16:27:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.workspace-query-results{
|
|
|
|
overflow: auto;
|
|
|
|
white-space: nowrap;
|
|
|
|
|
2020-06-10 19:29:10 +02:00
|
|
|
.table{
|
|
|
|
width: auto;
|
2020-06-07 14:38:38 +02:00
|
|
|
|
2020-06-10 19:29:10 +02:00
|
|
|
.tr:focus{
|
|
|
|
background: rgba($color: #000000, $alpha: .3);
|
2020-06-07 14:38:38 +02:00
|
|
|
}
|
2020-06-10 19:29:10 +02:00
|
|
|
|
|
|
|
.th{
|
|
|
|
position: sticky;
|
|
|
|
top: 0;
|
|
|
|
background: $bg-color;
|
|
|
|
border-color: $bg-color-light;
|
|
|
|
padding: .1rem .4rem;
|
|
|
|
font-weight: 400;
|
2020-06-07 14:38:38 +02:00
|
|
|
}
|
2020-06-10 19:29:10 +02:00
|
|
|
|
|
|
|
.td{
|
|
|
|
border-left: 1px solid;
|
|
|
|
border-color: $bg-color-light;
|
|
|
|
padding: 0 .4rem;
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
max-width: 200px;
|
|
|
|
white-space: nowrap;
|
|
|
|
overflow: hidden;
|
|
|
|
|
|
|
|
&:first-child{
|
|
|
|
border-left: none;
|
2020-06-07 14:38:38 +02:00
|
|
|
}
|
|
|
|
}
|
2020-06-06 16:27:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
</style>
|