1
1
mirror of https://github.com/Fabio286/antares.git synced 2024-12-25 08:20:39 +01:00

feat(UI): database version in app footer

This commit is contained in:
Fabio Di Stasio 2021-02-01 16:31:48 +01:00
parent 88ab7c5a62
commit 15417e8a77
5 changed files with 73 additions and 9 deletions

View File

@ -94,6 +94,17 @@ export default connections => {
}
});
ipcMain.handle('get-version', async (event, uid) => {
try {
const result = await connections[uid].getVersion();
return { status: 'success', response: result };
}
catch (err) {
return { status: 'error', response: err.toString() };
}
});
ipcMain.handle('use-schema', async (event, { uid, schema }) => {
if (!schema) return;

View File

@ -920,6 +920,35 @@ export class MySQLClient extends AntaresCore {
});
}
/**
* SHOW VARIABLES LIKE '%vers%'
*
* @returns {Array.<Object>} version parameters
* @memberof MySQLClient
*/
async getVersion () {
const sql = 'SHOW VARIABLES LIKE "%vers%"';
const { rows } = await this.raw(sql);
return rows.reduce((acc, curr) => {
switch (curr.Variable_name) {
case 'version':
acc.number = curr.Value.split('-')[0];
break;
case 'version_comment':
acc.name = curr.Value.replace('(GPL)', '');
break;
case 'version_compile_machine':
acc.arch = curr.Value;
break;
case 'version_compile_os':
acc.os = curr.Value;
break;
}
return acc;
}, {});
}
/**
* CREATE TABLE
*
@ -1231,7 +1260,7 @@ export class MySQLClient extends AntaresCore {
const response = await this.getTableColumns(paramObj);
remappedFields = remappedFields.map(field => {
const detailedField = response.find(f => f.name === field.name);
if (field.orgTable === paramObj.table && field.schema === paramObj.schema && detailedField.name === field.orgName)
if (detailedField && field.orgTable === paramObj.table && field.schema === paramObj.schema && detailedField.name === field.orgName)
field = { ...detailedField, ...field };
return field;
});

View File

@ -2,9 +2,9 @@
<div id="footer" class="text-light">
<div class="footer-left-elements">
<ul class="footer-elements">
<li class="footer-element" :title="$t('word.version')">
<i class="mdi mdi-18px mdi-memory mr-1" />
<small>{{ appVersion }}</small>
<li class="footer-element">
<i class="mdi mdi-18px mdi-database mr-1" />
<small>{{ versionString }}</small>
</li>
</ul>
</div>
@ -34,9 +34,18 @@ export default {
name: 'TheFooter',
computed: {
...mapGetters({
appName: 'application/appName',
workspace: 'workspaces/getSelected',
getWorkspace: 'workspaces/getWorkspace',
appVersion: 'application/appVersion'
})
}),
version () {
return this.getWorkspace(this.workspace) ? this.getWorkspace(this.workspace).version : null;
},
versionString () {
if (this.version)
return `${this.version.name} ${this.version.number} (${this.version.arch} ${this.version.os})`;
return '';
}
},
methods: {
...mapActions({

View File

@ -34,6 +34,10 @@ export default class {
return ipcRenderer.invoke('get-engines', uid);
}
static getVersion (uid) {
return ipcRenderer.invoke('get-version', uid);
}
static useSchema (params) {
return ipcRenderer.invoke('use-schema', params);
}

View File

@ -51,7 +51,7 @@ export default {
SELECT_WORKSPACE (state, uid) {
state.selected_workspace = uid;
},
ADD_CONNECTED (state, { uid, client, dataTypes, indexTypes, structure }) {
ADD_CONNECTED (state, { uid, client, dataTypes, indexTypes, structure, version }) {
state.workspaces = state.workspaces.map(workspace => workspace.uid === uid
? {
...workspace,
@ -59,7 +59,8 @@ export default {
dataTypes,
indexTypes,
structure,
connected: true
connected: true,
version
}
: workspace);
},
@ -245,12 +246,22 @@ export default {
indexTypes = require('common/index-types/mysql');
break;
}
const { status, response: version } = await Database.getVersion(connection.uid);
if (status === 'error')
dispatch('notifications/addNotification', { status, message: version }, { root: true });
else {
//
}
commit('ADD_CONNECTED', {
uid: connection.uid,
client: connection.client,
dataTypes,
indexTypes,
structure: response
structure: response,
version
});
dispatch('refreshCollations', connection.uid);
dispatch('refreshVariables', connection.uid);