1
1
mirror of https://github.com/Fabio286/antares.git synced 2025-06-05 21:59:22 +02:00

feat: support to multiple queries in the same tab

This commit is contained in:
2020-09-06 08:41:57 +02:00
parent 3385744260
commit 48f77bae01
7 changed files with 171 additions and 100 deletions

View File

@ -55,6 +55,11 @@
</a>
</li>
</ul>
<div v-show="selectedTab === 'prop'" class="column col-12">
<p class="px-2">
In future releases
</p>
</div>
<WorkspaceTableTab
v-show="selectedTab === 'data'"
:connection="connection"

View File

@ -15,11 +15,11 @@
</button>
</div>
<div class="workspace-query-info">
<div v-if="results.rows">
{{ $t('word.results') }}: <b>{{ results.rows.length }}</b>
<div v-if="results[selectedResultsset] && results[selectedResultsset].rows">
{{ $t('word.results') }}: <b>{{ resultsCount }}</b>
</div>
<div v-if="results.report">
{{ $t('message.affectedRows') }}: <b>{{ results.report.affectedRows }}</b>
<div v-if="results[selectedResultsset] && results[selectedResultsset].report">
{{ $t('message.affectedRows') }}: <b>{{ affectedCount }}</b>
</div>
<div v-if="workspace.breadcrumbs.schema">
{{ $t('word.schema') }}: <b>{{ workspace.breadcrumbs.schema }}</b>
@ -66,8 +66,10 @@ export default {
query: '',
lastQuery: '',
isQuering: false,
results: {},
selectedFields: []
results: [],
resultsCount: 0,
affectedCount: 0,
selectedResultsset: 0
};
},
computed: {
@ -77,11 +79,6 @@ export default {
workspace () {
return this.getWorkspace(this.connection.uid);
},
table () {
if ('fields' in this.results && this.results.fields.length)
return this.results.fields[0].orgTable;
return '';
},
schema () {
if ('fields' in this.results && this.results.fields.length)
return this.results.fields[0].db;
@ -94,6 +91,11 @@ export default {
setTabFields: 'workspaces/setTabFields',
setTabKeyUsage: 'workspaces/setTabKeyUsage'
}),
getTable (index) {
if ('fields' in this.results[index] && this.results[index].fields.length)
return this.results[index].fields[0].orgTable;
return '';
},
async runQuery (query) {
if (!query) return;
this.isQuering = true;
@ -107,56 +109,69 @@ export default {
};
const { status, response } = await Connection.rawQuery(params);
if (status === 'success') {
this.results = response;
if (response.rows) { // if is a select
this.selectedFields = response.fields.map(field => field.orgName);
this.results = Array.isArray(response) ? response : [response];
try { // Table data
const params = {
uid: this.connection.uid,
schema: this.schema,
table: this.table
};
let selectedFields = [];
const fieldsArr = [];
const keysArr = [];
const { status, response } = await Tables.getTableColumns(params);
for (const [index, result] of this.results.entries()) {
if (result.rows) { // if is a select
selectedFields = result.fields.map(field => field.orgName);
this.resultsCount += result.rows.length;
if (status === 'success') {
let fields = response.filter(field => this.selectedFields.includes(field.name));
if (this.selectedFields.length) {
fields = fields.map((field, index) => {
return { ...field, alias: this.results.fields[index].name };
});
try { // Table data
const params = {
uid: this.connection.uid,
schema: this.schema,
table: this.getTable(index)
};
const { status, response } = await Tables.getTableColumns(params);
if (status === 'success') {
let fields = response.filter(field => selectedFields.includes(field.name));
if (selectedFields.length) {
fields = fields.map((field, index) => {
return { ...field, alias: result.fields[index].name };
});
}
fieldsArr.push(fields);
}
this.setTabFields({ cUid: this.connection.uid, tUid: this.tabUid, fields });
else
this.addNotification({ status: 'error', message: response });
}
catch (err) {
this.addNotification({ status: 'error', message: err.stack });
}
else
this.addNotification({ status: 'error', message: response });
}
catch (err) {
this.addNotification({ status: 'error', message: err.stack });
}
try { // Key usage (foreign keys)
const params = {
uid: this.connection.uid,
schema: this.schema,
table: this.table
};
try { // Key usage (foreign keys)
const params = {
uid: this.connection.uid,
schema: this.schema,
table: this.getTable(index)
};
const { status, response } = await Tables.getKeyUsage(params);
if (status === 'success')
this.setTabKeyUsage({ cUid: this.connection.uid, tUid: this.tabUid, keyUsage: response });
else
this.addNotification({ status: 'error', message: response });
const { status, response } = await Tables.getKeyUsage(params);
if (status === 'success')
keysArr.push(response);
else
this.addNotification({ status: 'error', message: response });
}
catch (err) {
this.addNotification({ status: 'error', message: err.stack });
}
}
catch (err) {
this.addNotification({ status: 'error', message: err.stack });
else { // if is a query without results
this.affectedCount += result.report.affectedRows;
}
}
else { // if is a query without results
}
console.log(fieldsArr);
this.setTabFields({ cUid: this.connection.uid, tUid: this.tabUid, fields: fieldsArr });
this.setTabKeyUsage({ cUid: this.connection.uid, tUid: this.tabUid, keyUsage: keysArr });
}
else
this.addNotification({ status: 'error', message: response });
@ -172,7 +187,9 @@ export default {
this.runQuery(this.lastQuery);
},
clearTabData () {
this.results = {};
this.results = [];
this.resultsCount = 0;
this.affectedCount = 0;
this.setTabFields({ cUid: this.connection.uid, tUid: this.tabUid, fields: [] });
}
}

View File

@ -11,6 +11,17 @@
@delete-selected="deleteSelected"
@close-context="isContext = false"
/>
<ul v-if="results.length > 1" class="tab tab-block result-tabs">
<li
v-for="(result, index) in results"
:key="index"
class="tab-item"
:class="{'active': resultsetIndex === index}"
@click="selectResultset(index)"
>
<a>{{ result.fields[0].orgTable }} ({{ result.rows.length }})</a>
</li>
</ul>
<div ref="table" class="table table-hover">
<div class="thead">
<div class="tr">
@ -39,7 +50,7 @@
</div>
</div>
<BaseVirtualScroll
v-if="results.rows"
v-if="results[resultsetIndex] && results[resultsetIndex].rows"
ref="resultTable"
:items="sortedResults"
:item-height="22"
@ -81,7 +92,7 @@ export default {
TableContext
},
props: {
results: Object,
results: Array,
tabUid: [String, Number]
},
data () {
@ -93,7 +104,9 @@ export default {
selectedCell: null,
selectedRows: [],
currentSort: '',
currentSortDir: 'asc'
currentSortDir: 'asc',
resultsetIndex: 0,
scrollElement: null
};
},
computed: {
@ -119,26 +132,27 @@ export default {
return this.localResults;
},
fields () {
return this.getWorkspaceTab(this.tabUid) ? this.getWorkspaceTab(this.tabUid).fields : [];
return this.getWorkspaceTab(this.tabUid) && this.getWorkspaceTab(this.tabUid).fields[this.resultsetIndex] ? this.getWorkspaceTab(this.tabUid).fields[this.resultsetIndex] : [];
},
keyUsage () {
return this.getWorkspaceTab(this.tabUid) ? this.getWorkspaceTab(this.tabUid).keyUsage : [];
},
scrollElement () {
return this.$refs.tableWrapper;
return this.getWorkspaceTab(this.tabUid) && this.getWorkspaceTab(this.tabUid).keyUsage[this.resultsetIndex] ? this.getWorkspaceTab(this.tabUid).keyUsage[this.resultsetIndex] : [];
}
},
watch: {
results () {
this.resetSort();
this.localResults = this.results.rows ? this.results.rows.map(item => {
return { ...item, _id: uidGen() };
}) : [];
this.setLocalResults();
this.resultsetIndex = 0;
},
resultsetIndex () {
this.setLocalResults();
}
},
updated () {
if (this.$refs.table)
this.refreshScroller();
if (this.$refs.tableWrapper)
this.scrollElement = this.$refs.tableWrapper;
},
mounted () {
window.addEventListener('resize', this.resizeResults);
@ -178,6 +192,12 @@ export default {
return 'UNKNOWN ' + key;
}
},
setLocalResults () {
this.resetSort();
this.localResults = this.results[this.resultsetIndex] && this.results[this.resultsetIndex].rows ? this.results[this.resultsetIndex].rows.map(item => {
return { ...item, _id: uidGen() };
}) : [];
},
resizeResults () {
if (this.$refs.resultTable) {
const el = this.$refs.tableWrapper;
@ -275,12 +295,15 @@ export default {
resetSort () {
this.currentSort = '';
this.currentSortDir = 'asc';
},
selectResultset (index) {
this.resultsetIndex = index;
}
}
};
</script>
<style lang="scss">
<style lang="scss" scoped>
.vscroll {
height: 1000px;
overflow: auto;
@ -305,4 +328,9 @@ export default {
line-height: 1;
margin-left: 0.2rem;
}
.result-tabs {
background: transparent !important;
margin: 0;
}
</style>

View File

@ -186,7 +186,10 @@ export default {
},
props: {
row: Object,
fields: Array,
fields: {
type: Array,
default: () => []
},
keyUsage: Array
},
data () {
@ -253,10 +256,12 @@ export default {
return this.keyUsage.map(key => key.column);
}
},
created () {
this.fields.forEach(field => {
this.isInlineEditor[field.name] = false;
});
watch: {
fields () {
this.fields.forEach(field => {
this.isInlineEditor[field.name] = false;
});
}
},
methods: {
getFieldType (cKey) {

View File

@ -33,8 +33,9 @@
<div class="workspace-query-results column col-12">
<WorkspaceQueryTable
v-if="results"
v-show="!isQuering"
ref="queryTable"
:results="results"
:results="[results]"
:tab-uid="tabUid"
@update-field="updateField"
@delete-selected="deleteSelected"
@ -116,6 +117,8 @@ export default {
if (!this.table) return;
this.isQuering = true;
this.results = {};
const fieldsArr = [];
const keysArr = [];
this.setTabFields({ cUid: this.connection.uid, tUid: this.tabUid, fields: [] });
const params = {
@ -128,7 +131,7 @@ export default {
const { status, response } = await Tables.getTableColumns(params);
if (status === 'success') {
this.fields = response;// Needed to add new rows
this.setTabFields({ cUid: this.connection.uid, tUid: this.tabUid, fields: response });
fieldsArr.push(response);
}
else
this.addNotification({ status: 'error', message: response });
@ -153,7 +156,7 @@ export default {
const { status, response } = await Tables.getKeyUsage(params);
if (status === 'success') {
this.keyUsage = response;// Needed to add new rows
this.setTabKeyUsage({ cUid: this.connection.uid, tUid: this.tabUid, keyUsage: response });
keysArr.push(response);
}
else
this.addNotification({ status: 'error', message: response });
@ -162,6 +165,8 @@ export default {
this.addNotification({ status: 'error', message: err.stack });
}
this.setTabFields({ cUid: this.connection.uid, tUid: this.tabUid, fields: fieldsArr });
this.setTabKeyUsage({ cUid: this.connection.uid, tUid: this.tabUid, keyUsage: keysArr });
this.isQuering = false;
},
reloadTable () {