1
1
mirror of https://github.com/Fabio286/antares.git synced 2025-04-15 18:47:24 +02:00

feat: option to restore session on startup

This commit is contained in:
Fabio Di Stasio 2021-07-22 10:41:06 +02:00
parent 1e543aa6b0
commit adc5477673
7 changed files with 88 additions and 26 deletions

View File

@ -104,6 +104,19 @@
</select> </select>
</div> </div>
</div> </div>
<div class="form-group">
<div class="col-6 col-sm-12">
<label class="form-label">
{{ $t('message.restorePreviourSession') }}
</label>
</div>
<div class="col-6 col-sm-12">
<label class="form-switch d-inline-block" @click.prevent="toggleRestoreSession">
<input type="checkbox" :checked="restoreTabs">
<i class="form-icon" />
</label>
</div>
</div>
<div class="form-group"> <div class="form-group">
<div class="col-6 col-sm-12"> <div class="col-6 col-sm-12">
<label class="form-label"> <label class="form-label">
@ -369,6 +382,7 @@ export default {
selectedAutoComplete: 'settings/getAutoComplete', selectedAutoComplete: 'settings/getAutoComplete',
selectedLineWrap: 'settings/getLineWrap', selectedLineWrap: 'settings/getLineWrap',
notificationsTimeout: 'settings/getNotificationsTimeout', notificationsTimeout: 'settings/getNotificationsTimeout',
restoreTabs: 'settings/getRestoreTabs',
applicationTheme: 'settings/getApplicationTheme', applicationTheme: 'settings/getApplicationTheme',
editorTheme: 'settings/getEditorTheme', editorTheme: 'settings/getEditorTheme',
editorFontSize: 'settings/getEditorFontSize', editorFontSize: 'settings/getEditorFontSize',
@ -423,6 +437,7 @@ ORDER BY
closeModal: 'application/hideSettingModal', closeModal: 'application/hideSettingModal',
changeLocale: 'settings/changeLocale', changeLocale: 'settings/changeLocale',
changePageSize: 'settings/changePageSize', changePageSize: 'settings/changePageSize',
changeRestoreTabs: 'settings/changeRestoreTabs',
changeAutoComplete: 'settings/changeAutoComplete', changeAutoComplete: 'settings/changeAutoComplete',
changeLineWrap: 'settings/changeLineWrap', changeLineWrap: 'settings/changeLineWrap',
changeApplicationTheme: 'settings/changeApplicationTheme', changeApplicationTheme: 'settings/changeApplicationTheme',
@ -447,6 +462,9 @@ ORDER BY
if (e.key === 'Escape') if (e.key === 'Escape')
this.closeModal(); this.closeModal();
}, },
toggleRestoreSession () {
this.changeRestoreTabs(!this.restoreTabs);
},
toggleAutoComplete () { toggleAutoComplete () {
this.changeAutoComplete(!this.selectedAutoComplete); this.changeAutoComplete(!this.selectedAutoComplete);
}, },

View File

@ -9,6 +9,11 @@
<div class="workspace-explorebar-header"> <div class="workspace-explorebar-header">
<span class="workspace-explorebar-title">{{ connectionName }}</span> <span class="workspace-explorebar-title">{{ connectionName }}</span>
<span v-if="workspace.connection_status === 'connected'" class="workspace-explorebar-tools"> <span v-if="workspace.connection_status === 'connected'" class="workspace-explorebar-tools">
<i
class="mdi mdi-18px mdi-database-plus c-hand mr-2"
:title="$t('message.createNewSchema')"
@click="showNewDBModal"
/>
<i <i
class="mdi mdi-18px mdi-refresh c-hand mr-2" class="mdi mdi-18px mdi-refresh c-hand mr-2"
:class="{'rotate':isRefreshing}" :class="{'rotate':isRefreshing}"
@ -16,12 +21,7 @@
@click="refresh" @click="refresh"
/> />
<i <i
class="mdi mdi-18px mdi-database-plus c-hand mr-2" class="mdi mdi-18px mdi-power c-hand"
:title="$t('message.createNewSchema')"
@click="showNewDBModal"
/>
<i
class="mdi mdi-18px mdi-power-plug-off c-hand"
:title="$t('word.disconnect')" :title="$t('word.disconnect')"
@click="disconnectWorkspace(connection.uid)" @click="disconnectWorkspace(connection.uid)"
/> />

View File

@ -166,7 +166,7 @@
<BaseLoader v-if="isLoading" /> <BaseLoader v-if="isLoading" />
<label class="form-label ml-2">{{ $t('message.selectStatement') }}</label> <label class="form-label ml-2">{{ $t('message.selectStatement') }}</label>
<QueryEditor <QueryEditor
v-if="isSelected" v-show="isSelected"
ref="queryEditor" ref="queryEditor"
:value.sync="localView.sql" :value.sync="localView.sql"
:workspace="workspace" :workspace="workspace"
@ -225,16 +225,16 @@ export default {
} }
}, },
watch: { watch: {
schema () { async schema () {
if (this.isSelected) { if (this.isSelected) {
this.getViewData(); await this.getViewData();
this.$refs.queryEditor.editor.session.setValue(this.localView.sql); this.$refs.queryEditor.editor.session.setValue(this.localView.sql);
this.lastView = this.view; this.lastView = this.view;
} }
}, },
view () { async view () {
if (this.isSelected) { if (this.isSelected) {
this.getViewData(); await this.getViewData();
this.$refs.queryEditor.editor.session.setValue(this.localView.sql); this.$refs.queryEditor.editor.session.setValue(this.localView.sql);
this.lastView = this.view; this.lastView = this.view;
} }

View File

@ -162,7 +162,7 @@ export default {
return this.getWorkspace(this.connection.uid); return this.getWorkspace(this.connection.uid);
}, },
breadcrumbsSchema () { breadcrumbsSchema () {
return this.workspace.breadcrumbs.schema; return this.workspace.breadcrumbs.schema || null;
}, },
databaseSchemas () { databaseSchemas () {
return this.workspace.structure.reduce((acc, curr) => { return this.workspace.structure.reduce((acc, curr) => {
@ -185,8 +185,8 @@ export default {
}, },
created () { created () {
this.query = this.tab.content; this.query = this.tab.content;
this.selectedSchema = this.breadcrumbsSchema; this.selectedSchema = this.tab.schema || this.breadcrumbsSchema;
this.changeBreadcrumbs({ schema: this.selectedSchema, query: `Query #${this.tab.index}` }); // this.changeBreadcrumbs({ schema: this.selectedSchema, query: `Query #${this.tab.index}` });
window.addEventListener('keydown', this.onKey); window.addEventListener('keydown', this.onKey);
}, },
@ -209,7 +209,8 @@ export default {
methods: { methods: {
...mapActions({ ...mapActions({
addNotification: 'notifications/addNotification', addNotification: 'notifications/addNotification',
changeBreadcrumbs: 'workspaces/changeBreadcrumbs' changeBreadcrumbs: 'workspaces/changeBreadcrumbs',
updateTabContent: 'workspaces/updateTabContent'
}), }),
async runQuery (query) { async runQuery (query) {
if (!query || this.isQuering) return; if (!query || this.isQuering) return;
@ -231,6 +232,8 @@ export default {
this.resultsCount += this.results.reduce((acc, curr) => acc + (curr.rows ? curr.rows.length : 0), 0); this.resultsCount += this.results.reduce((acc, curr) => acc + (curr.rows ? curr.rows.length : 0), 0);
this.durationsCount += this.results.reduce((acc, curr) => acc + curr.duration, 0); this.durationsCount += this.results.reduce((acc, curr) => acc + curr.duration, 0);
this.affectedCount += this.results.reduce((acc, curr) => acc + (curr.report ? curr.report.affectedRows : 0), 0); this.affectedCount += this.results.reduce((acc, curr) => acc + (curr.report ? curr.report.affectedRows : 0), 0);
this.updateTabContent({ uid: this.connection.uid, tab: this.tab.uid, type: 'query', schema: this.selectedSchema, content: query });
} }
else else
this.addNotification({ status: 'error', message: response }); this.addNotification({ status: 'error', message: response });

View File

@ -226,7 +226,8 @@ module.exports = {
pageNumber: 'Page number', pageNumber: 'Page number',
duplicateTable: 'Duplicate table', duplicateTable: 'Duplicate table',
noOpenTabs: 'There are no open tabs, navigate on the left bar or:', noOpenTabs: 'There are no open tabs, navigate on the left bar or:',
noSchema: 'No schema' noSchema: 'No schema',
restorePreviourSession: 'Restore previous session'
}, },
faker: { faker: {
address: 'Address', address: 'Address',

View File

@ -16,7 +16,8 @@ export default {
line_wrap: persistentStore.get('line_wrap', true), line_wrap: persistentStore.get('line_wrap', true),
application_theme: persistentStore.get('application_theme', 'dark'), application_theme: persistentStore.get('application_theme', 'dark'),
editor_theme: persistentStore.get('editor_theme', 'twilight'), editor_theme: persistentStore.get('editor_theme', 'twilight'),
editor_font_size: persistentStore.get('editor_font_size', 'medium') editor_font_size: persistentStore.get('editor_font_size', 'medium'),
restore_tabs: persistentStore.get('restore_tabs', true)
}, },
getters: { getters: {
getLocale: state => state.locale, getLocale: state => state.locale,
@ -28,7 +29,8 @@ export default {
getLineWrap: state => state.line_wrap, getLineWrap: state => state.line_wrap,
getApplicationTheme: state => state.application_theme, getApplicationTheme: state => state.application_theme,
getEditorTheme: state => state.editor_theme, getEditorTheme: state => state.editor_theme,
getEditorFontSize: state => state.editor_font_size getEditorFontSize: state => state.editor_font_size,
getRestoreTabs: state => state.restore_tabs
}, },
mutations: { mutations: {
SET_LOCALE (state, locale) { SET_LOCALE (state, locale) {
@ -71,6 +73,10 @@ export default {
SET_EDITOR_FONT_SIZE (state, size) { SET_EDITOR_FONT_SIZE (state, size) {
state.editor_font_size = size; state.editor_font_size = size;
persistentStore.set('editor_font_size', state.editor_font_size); persistentStore.set('editor_font_size', state.editor_font_size);
},
SET_RESTORE_TABS (state, val) {
state.restore_tabs = val;
persistentStore.set('restore_tabs', state.restore_tabs);
} }
}, },
actions: { actions: {
@ -103,6 +109,9 @@ export default {
}, },
changeEditorFontSize ({ commit }, size) { changeEditorFontSize ({ commit }, size) {
commit('SET_EDITOR_FONT_SIZE', size); commit('SET_EDITOR_FONT_SIZE', size);
},
changeRestoreTabs ({ commit }, size) {
commit('SET_RESTORE_TABS', size);
} }
} }
}; };

View File

@ -1,8 +1,10 @@
'use strict'; 'use strict';
import Store from 'electron-store';
import Connection from '@/ipc-api/Connection'; import Connection from '@/ipc-api/Connection';
import Schema from '@/ipc-api/Schema'; import Schema from '@/ipc-api/Schema';
import Users from '@/ipc-api/Users'; import Users from '@/ipc-api/Users';
import { uidGen } from 'common/libs/uidGen'; import { uidGen } from 'common/libs/uidGen';
const persistentStore = new Store({ name: 'tabs' });
const tabIndex = []; const tabIndex = [];
export default { export default {
@ -53,6 +55,15 @@ export default {
SET_CONNECTED (state, payload) { SET_CONNECTED (state, payload) {
const { uid, client, dataTypes, indexTypes, customizations, structure, version } = payload; const { uid, client, dataTypes, indexTypes, customizations, structure, version } = payload;
const cachedTabs = payload.restoreTabs ? persistentStore.get(uid, []) : [];
if (cachedTabs.length) {
tabIndex[uid] = cachedTabs.reduce((acc, curr) => {
if (curr.index > acc) acc = curr.index;
return acc;
}, null);
}
state.workspaces = state.workspaces.map(workspace => workspace.uid === uid state.workspaces = state.workspaces.map(workspace => workspace.uid === uid
? { ? {
...workspace, ...workspace,
@ -62,6 +73,8 @@ export default {
customizations, customizations,
structure, structure,
connection_status: 'connected', connection_status: 'connected',
tabs: cachedTabs,
selected_tab: cachedTabs.length ? cachedTabs[0].uid : null,
version version
} }
: workspace); : workspace);
@ -188,6 +201,7 @@ export default {
content: content || '', content: content || '',
autorun: !!autorun autorun: !!autorun
}; };
state.workspaces = state.workspaces.map(workspace => { state.workspaces = state.workspaces.map(workspace => {
if (workspace.uid === uid) { if (workspace.uid === uid) {
return { return {
@ -198,6 +212,8 @@ export default {
else else
return workspace; return workspace;
}); });
persistentStore.set(uid, state.workspaces.find(workspace => workspace.uid === uid).tabs);
}, },
REMOVE_TAB (state, { uid, tab: tUid }) { REMOVE_TAB (state, { uid, tab: tUid }) {
state.workspaces = state.workspaces.map(workspace => { state.workspaces = state.workspaces.map(workspace => {
@ -210,6 +226,8 @@ export default {
else else
return workspace; return workspace;
}); });
persistentStore.set(uid, state.workspaces.find(workspace => workspace.uid === uid).tabs);
}, },
REMOVE_TABS (state, { uid, schema, elementName, elementType }) { // Multiple tabs based on schema and element name REMOVE_TABS (state, { uid, schema, elementName, elementType }) { // Multiple tabs based on schema and element name
if (elementType === 'procedure') elementType = 'routine'; // TODO: pass directly "routine" if (elementType === 'procedure') elementType = 'routine'; // TODO: pass directly "routine"
@ -228,15 +246,17 @@ export default {
else else
return workspace; return workspace;
}); });
persistentStore.set(uid, state.workspaces.find(workspace => workspace.uid === uid).tabs);
}, },
REPLACE_TAB (state, { uid, tab: tUid, type, schema, elementName, elementType }) { REPLACE_TAB (state, { uid, tab: tUid, type, schema, content, elementName, elementType }) {
state.workspaces = state.workspaces.map(workspace => { state.workspaces = state.workspaces.map(workspace => {
if (workspace.uid === uid) { if (workspace.uid === uid) {
return { return {
...workspace, ...workspace,
tabs: workspace.tabs.map(tab => { tabs: workspace.tabs.map(tab => {
if (tab.uid === tUid) if (tab.uid === tUid)
return { ...tab, type, schema, elementName, elementType }; return { ...tab, type, schema, content, elementName, elementType };
return tab; return tab;
}) })
@ -245,6 +265,8 @@ export default {
else else
return workspace; return workspace;
}); });
persistentStore.set(uid, state.workspaces.find(workspace => workspace.uid === uid).tabs);
}, },
RENAME_TABS (state, { uid, schema, elementName, elementType, elementNewName }) { RENAME_TABS (state, { uid, schema, elementName, elementType, elementNewName }) {
state.workspaces = state.workspaces.map(workspace => { state.workspaces = state.workspaces.map(workspace => {
@ -266,12 +288,15 @@ export default {
else else
return workspace; return workspace;
}); });
persistentStore.set(uid, state.workspaces.find(workspace => workspace.uid === uid).tabs);
}, },
SELECT_TAB (state, { uid, tab }) { SELECT_TAB (state, { uid, tab }) {
state.workspaces = state.workspaces.map(workspace => workspace.uid === uid ? { ...workspace, selected_tab: tab } : workspace); state.workspaces = state.workspaces.map(workspace => workspace.uid === uid ? { ...workspace, selected_tab: tab } : workspace);
}, },
UPDATE_TABS (state, { uid, tabs }) { UPDATE_TABS (state, { uid, tabs }) {
state.workspaces = state.workspaces.map(workspace => workspace.uid === uid ? { ...workspace, tabs } : workspace); state.workspaces = state.workspaces.map(workspace => workspace.uid === uid ? { ...workspace, tabs } : workspace);
persistentStore.set(uid, state.workspaces.find(workspace => workspace.uid === uid).tabs);
}, },
SET_TAB_FIELDS (state, { cUid, tUid, fields }) { SET_TAB_FIELDS (state, { cUid, tUid, fields }) {
state.workspaces = state.workspaces.map(workspace => { state.workspaces = state.workspaces.map(workspace => {
@ -289,6 +314,8 @@ export default {
else else
return workspace; return workspace;
}); });
persistentStore.set(uid, state.workspaces.find(workspace => workspace.uid === uid).tabs);
}, },
SET_TAB_KEY_USAGE (state, { cUid, tUid, keyUsage }) { SET_TAB_KEY_USAGE (state, { cUid, tUid, keyUsage }) {
state.workspaces = state.workspaces.map(workspace => { state.workspaces = state.workspaces.map(workspace => {
@ -306,6 +333,8 @@ export default {
else else
return workspace; return workspace;
}); });
persistentStore.set(uid, state.workspaces.find(workspace => workspace.uid === uid).tabs);
}, },
SET_UNSAVED_CHANGES (state, { uid, tUid, isChanged }) { SET_UNSAVED_CHANGES (state, { uid, tUid, isChanged }) {
state.workspaces = state.workspaces.map(workspace => { state.workspaces = state.workspaces.map(workspace => {
@ -324,9 +353,6 @@ export default {
return workspace; return workspace;
}); });
}, },
SET_PENDING_BREADCRUMBS (state, payload) {
state.pending_breadcrumbs = payload;
},
ADD_LOADED_SCHEMA (state, payload) { ADD_LOADED_SCHEMA (state, payload) {
state.workspaces = state.workspaces.map(workspace => { state.workspaces = state.workspaces.map(workspace => {
if (workspace.uid === payload.uid) if (workspace.uid === payload.uid)
@ -339,7 +365,7 @@ export default {
selectWorkspace ({ commit }, uid) { selectWorkspace ({ commit }, uid) {
commit('SELECT_WORKSPACE', uid); commit('SELECT_WORKSPACE', uid);
}, },
async connectWorkspace ({ dispatch, commit }, connection) { async connectWorkspace ({ dispatch, commit, getters, rootGetters }, connection) {
commit('SET_CONNECTING', connection.uid); commit('SET_CONNECTING', connection.uid);
try { try {
@ -372,6 +398,7 @@ export default {
if (status === 'error') if (status === 'error')
dispatch('notifications/addNotification', { status, message: version }, { root: true }); dispatch('notifications/addNotification', { status, message: version }, { root: true });
// Check if Maria or MySQL
const isMySQL = version.name.includes('MySQL'); const isMySQL = version.name.includes('MySQL');
if (isMySQL && connection.client !== 'mysql') { if (isMySQL && connection.client !== 'mysql') {
@ -392,7 +419,8 @@ export default {
indexTypes, indexTypes,
customizations, customizations,
structure: response, structure: response,
version version,
restoreTabs: rootGetters['settings/getRestoreTabs']
}); });
dispatch('refreshCollations', connection.uid); dispatch('refreshCollations', connection.uid);
dispatch('refreshVariables', connection.uid); dispatch('refreshVariables', connection.uid);
@ -482,7 +510,7 @@ export default {
commit('SET_DISCONNECTED', uid); commit('SET_DISCONNECTED', uid);
commit('SELECT_TAB', { uid, tab: 0 }); commit('SELECT_TAB', { uid, tab: 0 });
}, },
addWorkspace ({ commit, dispatch, getters }, uid) { addWorkspace ({ commit }, uid) {
const workspace = { const workspace = {
uid, uid,
connection_status: 'disconnected', connection_status: 'disconnected',
@ -675,6 +703,9 @@ export default {
if (!isSelectedExistent && workspace.tabs.length) if (!isSelectedExistent && workspace.tabs.length)
commit('SELECT_TAB', { uid, tab: workspace.tabs[workspace.tabs.length - 1].uid }); commit('SELECT_TAB', { uid, tab: workspace.tabs[workspace.tabs.length - 1].uid });
}, },
updateTabContent ({ commit }, { uid, tab, type, schema, content }) {
commit('REPLACE_TAB', { uid, tab, type, schema, content });
},
renameTabs ({ commit }, payload) { renameTabs ({ commit }, payload) {
commit('RENAME_TABS', payload); commit('RENAME_TABS', payload);
}, },