mirror of https://github.com/Fabio286/antares.git
feat: option to restore session on startup
This commit is contained in:
parent
1e543aa6b0
commit
adc5477673
|
@ -104,6 +104,19 @@
|
|||
</select>
|
||||
</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="col-6 col-sm-12">
|
||||
<label class="form-label">
|
||||
|
@ -369,6 +382,7 @@ export default {
|
|||
selectedAutoComplete: 'settings/getAutoComplete',
|
||||
selectedLineWrap: 'settings/getLineWrap',
|
||||
notificationsTimeout: 'settings/getNotificationsTimeout',
|
||||
restoreTabs: 'settings/getRestoreTabs',
|
||||
applicationTheme: 'settings/getApplicationTheme',
|
||||
editorTheme: 'settings/getEditorTheme',
|
||||
editorFontSize: 'settings/getEditorFontSize',
|
||||
|
@ -423,6 +437,7 @@ ORDER BY
|
|||
closeModal: 'application/hideSettingModal',
|
||||
changeLocale: 'settings/changeLocale',
|
||||
changePageSize: 'settings/changePageSize',
|
||||
changeRestoreTabs: 'settings/changeRestoreTabs',
|
||||
changeAutoComplete: 'settings/changeAutoComplete',
|
||||
changeLineWrap: 'settings/changeLineWrap',
|
||||
changeApplicationTheme: 'settings/changeApplicationTheme',
|
||||
|
@ -447,6 +462,9 @@ ORDER BY
|
|||
if (e.key === 'Escape')
|
||||
this.closeModal();
|
||||
},
|
||||
toggleRestoreSession () {
|
||||
this.changeRestoreTabs(!this.restoreTabs);
|
||||
},
|
||||
toggleAutoComplete () {
|
||||
this.changeAutoComplete(!this.selectedAutoComplete);
|
||||
},
|
||||
|
|
|
@ -9,6 +9,11 @@
|
|||
<div class="workspace-explorebar-header">
|
||||
<span class="workspace-explorebar-title">{{ connectionName }}</span>
|
||||
<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
|
||||
class="mdi mdi-18px mdi-refresh c-hand mr-2"
|
||||
:class="{'rotate':isRefreshing}"
|
||||
|
@ -16,12 +21,7 @@
|
|||
@click="refresh"
|
||||
/>
|
||||
<i
|
||||
class="mdi mdi-18px mdi-database-plus c-hand mr-2"
|
||||
:title="$t('message.createNewSchema')"
|
||||
@click="showNewDBModal"
|
||||
/>
|
||||
<i
|
||||
class="mdi mdi-18px mdi-power-plug-off c-hand"
|
||||
class="mdi mdi-18px mdi-power c-hand"
|
||||
:title="$t('word.disconnect')"
|
||||
@click="disconnectWorkspace(connection.uid)"
|
||||
/>
|
||||
|
|
|
@ -166,7 +166,7 @@
|
|||
<BaseLoader v-if="isLoading" />
|
||||
<label class="form-label ml-2">{{ $t('message.selectStatement') }}</label>
|
||||
<QueryEditor
|
||||
v-if="isSelected"
|
||||
v-show="isSelected"
|
||||
ref="queryEditor"
|
||||
:value.sync="localView.sql"
|
||||
:workspace="workspace"
|
||||
|
@ -225,16 +225,16 @@ export default {
|
|||
}
|
||||
},
|
||||
watch: {
|
||||
schema () {
|
||||
async schema () {
|
||||
if (this.isSelected) {
|
||||
this.getViewData();
|
||||
await this.getViewData();
|
||||
this.$refs.queryEditor.editor.session.setValue(this.localView.sql);
|
||||
this.lastView = this.view;
|
||||
}
|
||||
},
|
||||
view () {
|
||||
async view () {
|
||||
if (this.isSelected) {
|
||||
this.getViewData();
|
||||
await this.getViewData();
|
||||
this.$refs.queryEditor.editor.session.setValue(this.localView.sql);
|
||||
this.lastView = this.view;
|
||||
}
|
||||
|
|
|
@ -162,7 +162,7 @@ export default {
|
|||
return this.getWorkspace(this.connection.uid);
|
||||
},
|
||||
breadcrumbsSchema () {
|
||||
return this.workspace.breadcrumbs.schema;
|
||||
return this.workspace.breadcrumbs.schema || null;
|
||||
},
|
||||
databaseSchemas () {
|
||||
return this.workspace.structure.reduce((acc, curr) => {
|
||||
|
@ -185,8 +185,8 @@ export default {
|
|||
},
|
||||
created () {
|
||||
this.query = this.tab.content;
|
||||
this.selectedSchema = this.breadcrumbsSchema;
|
||||
this.changeBreadcrumbs({ schema: this.selectedSchema, query: `Query #${this.tab.index}` });
|
||||
this.selectedSchema = this.tab.schema || this.breadcrumbsSchema;
|
||||
// this.changeBreadcrumbs({ schema: this.selectedSchema, query: `Query #${this.tab.index}` });
|
||||
|
||||
window.addEventListener('keydown', this.onKey);
|
||||
},
|
||||
|
@ -209,7 +209,8 @@ export default {
|
|||
methods: {
|
||||
...mapActions({
|
||||
addNotification: 'notifications/addNotification',
|
||||
changeBreadcrumbs: 'workspaces/changeBreadcrumbs'
|
||||
changeBreadcrumbs: 'workspaces/changeBreadcrumbs',
|
||||
updateTabContent: 'workspaces/updateTabContent'
|
||||
}),
|
||||
async runQuery (query) {
|
||||
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.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.updateTabContent({ uid: this.connection.uid, tab: this.tab.uid, type: 'query', schema: this.selectedSchema, content: query });
|
||||
}
|
||||
else
|
||||
this.addNotification({ status: 'error', message: response });
|
||||
|
|
|
@ -226,7 +226,8 @@ module.exports = {
|
|||
pageNumber: 'Page number',
|
||||
duplicateTable: 'Duplicate table',
|
||||
noOpenTabs: 'There are no open tabs, navigate on the left bar or:',
|
||||
noSchema: 'No schema'
|
||||
noSchema: 'No schema',
|
||||
restorePreviourSession: 'Restore previous session'
|
||||
},
|
||||
faker: {
|
||||
address: 'Address',
|
||||
|
|
|
@ -16,7 +16,8 @@ export default {
|
|||
line_wrap: persistentStore.get('line_wrap', true),
|
||||
application_theme: persistentStore.get('application_theme', 'dark'),
|
||||
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: {
|
||||
getLocale: state => state.locale,
|
||||
|
@ -28,7 +29,8 @@ export default {
|
|||
getLineWrap: state => state.line_wrap,
|
||||
getApplicationTheme: state => state.application_theme,
|
||||
getEditorTheme: state => state.editor_theme,
|
||||
getEditorFontSize: state => state.editor_font_size
|
||||
getEditorFontSize: state => state.editor_font_size,
|
||||
getRestoreTabs: state => state.restore_tabs
|
||||
},
|
||||
mutations: {
|
||||
SET_LOCALE (state, locale) {
|
||||
|
@ -71,6 +73,10 @@ export default {
|
|||
SET_EDITOR_FONT_SIZE (state, size) {
|
||||
state.editor_font_size = 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: {
|
||||
|
@ -103,6 +109,9 @@ export default {
|
|||
},
|
||||
changeEditorFontSize ({ commit }, size) {
|
||||
commit('SET_EDITOR_FONT_SIZE', size);
|
||||
},
|
||||
changeRestoreTabs ({ commit }, size) {
|
||||
commit('SET_RESTORE_TABS', size);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
'use strict';
|
||||
import Store from 'electron-store';
|
||||
import Connection from '@/ipc-api/Connection';
|
||||
import Schema from '@/ipc-api/Schema';
|
||||
import Users from '@/ipc-api/Users';
|
||||
import { uidGen } from 'common/libs/uidGen';
|
||||
const persistentStore = new Store({ name: 'tabs' });
|
||||
const tabIndex = [];
|
||||
|
||||
export default {
|
||||
|
@ -53,6 +55,15 @@ export default {
|
|||
SET_CONNECTED (state, 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
|
||||
? {
|
||||
...workspace,
|
||||
|
@ -62,6 +73,8 @@ export default {
|
|||
customizations,
|
||||
structure,
|
||||
connection_status: 'connected',
|
||||
tabs: cachedTabs,
|
||||
selected_tab: cachedTabs.length ? cachedTabs[0].uid : null,
|
||||
version
|
||||
}
|
||||
: workspace);
|
||||
|
@ -188,6 +201,7 @@ export default {
|
|||
content: content || '',
|
||||
autorun: !!autorun
|
||||
};
|
||||
|
||||
state.workspaces = state.workspaces.map(workspace => {
|
||||
if (workspace.uid === uid) {
|
||||
return {
|
||||
|
@ -198,6 +212,8 @@ export default {
|
|||
else
|
||||
return workspace;
|
||||
});
|
||||
|
||||
persistentStore.set(uid, state.workspaces.find(workspace => workspace.uid === uid).tabs);
|
||||
},
|
||||
REMOVE_TAB (state, { uid, tab: tUid }) {
|
||||
state.workspaces = state.workspaces.map(workspace => {
|
||||
|
@ -210,6 +226,8 @@ export default {
|
|||
else
|
||||
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
|
||||
if (elementType === 'procedure') elementType = 'routine'; // TODO: pass directly "routine"
|
||||
|
@ -228,15 +246,17 @@ export default {
|
|||
else
|
||||
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 => {
|
||||
if (workspace.uid === uid) {
|
||||
return {
|
||||
...workspace,
|
||||
tabs: workspace.tabs.map(tab => {
|
||||
if (tab.uid === tUid)
|
||||
return { ...tab, type, schema, elementName, elementType };
|
||||
return { ...tab, type, schema, content, elementName, elementType };
|
||||
|
||||
return tab;
|
||||
})
|
||||
|
@ -245,6 +265,8 @@ export default {
|
|||
else
|
||||
return workspace;
|
||||
});
|
||||
|
||||
persistentStore.set(uid, state.workspaces.find(workspace => workspace.uid === uid).tabs);
|
||||
},
|
||||
RENAME_TABS (state, { uid, schema, elementName, elementType, elementNewName }) {
|
||||
state.workspaces = state.workspaces.map(workspace => {
|
||||
|
@ -266,12 +288,15 @@ export default {
|
|||
else
|
||||
return workspace;
|
||||
});
|
||||
|
||||
persistentStore.set(uid, state.workspaces.find(workspace => workspace.uid === uid).tabs);
|
||||
},
|
||||
SELECT_TAB (state, { uid, tab }) {
|
||||
state.workspaces = state.workspaces.map(workspace => workspace.uid === uid ? { ...workspace, selected_tab: tab } : workspace);
|
||||
},
|
||||
UPDATE_TABS (state, { uid, tabs }) {
|
||||
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 }) {
|
||||
state.workspaces = state.workspaces.map(workspace => {
|
||||
|
@ -289,6 +314,8 @@ export default {
|
|||
else
|
||||
return workspace;
|
||||
});
|
||||
|
||||
persistentStore.set(uid, state.workspaces.find(workspace => workspace.uid === uid).tabs);
|
||||
},
|
||||
SET_TAB_KEY_USAGE (state, { cUid, tUid, keyUsage }) {
|
||||
state.workspaces = state.workspaces.map(workspace => {
|
||||
|
@ -306,6 +333,8 @@ export default {
|
|||
else
|
||||
return workspace;
|
||||
});
|
||||
|
||||
persistentStore.set(uid, state.workspaces.find(workspace => workspace.uid === uid).tabs);
|
||||
},
|
||||
SET_UNSAVED_CHANGES (state, { uid, tUid, isChanged }) {
|
||||
state.workspaces = state.workspaces.map(workspace => {
|
||||
|
@ -324,9 +353,6 @@ export default {
|
|||
return workspace;
|
||||
});
|
||||
},
|
||||
SET_PENDING_BREADCRUMBS (state, payload) {
|
||||
state.pending_breadcrumbs = payload;
|
||||
},
|
||||
ADD_LOADED_SCHEMA (state, payload) {
|
||||
state.workspaces = state.workspaces.map(workspace => {
|
||||
if (workspace.uid === payload.uid)
|
||||
|
@ -339,7 +365,7 @@ export default {
|
|||
selectWorkspace ({ commit }, uid) {
|
||||
commit('SELECT_WORKSPACE', uid);
|
||||
},
|
||||
async connectWorkspace ({ dispatch, commit }, connection) {
|
||||
async connectWorkspace ({ dispatch, commit, getters, rootGetters }, connection) {
|
||||
commit('SET_CONNECTING', connection.uid);
|
||||
|
||||
try {
|
||||
|
@ -372,6 +398,7 @@ export default {
|
|||
if (status === 'error')
|
||||
dispatch('notifications/addNotification', { status, message: version }, { root: true });
|
||||
|
||||
// Check if Maria or MySQL
|
||||
const isMySQL = version.name.includes('MySQL');
|
||||
|
||||
if (isMySQL && connection.client !== 'mysql') {
|
||||
|
@ -392,7 +419,8 @@ export default {
|
|||
indexTypes,
|
||||
customizations,
|
||||
structure: response,
|
||||
version
|
||||
version,
|
||||
restoreTabs: rootGetters['settings/getRestoreTabs']
|
||||
});
|
||||
dispatch('refreshCollations', connection.uid);
|
||||
dispatch('refreshVariables', connection.uid);
|
||||
|
@ -482,7 +510,7 @@ export default {
|
|||
commit('SET_DISCONNECTED', uid);
|
||||
commit('SELECT_TAB', { uid, tab: 0 });
|
||||
},
|
||||
addWorkspace ({ commit, dispatch, getters }, uid) {
|
||||
addWorkspace ({ commit }, uid) {
|
||||
const workspace = {
|
||||
uid,
|
||||
connection_status: 'disconnected',
|
||||
|
@ -675,6 +703,9 @@ export default {
|
|||
if (!isSelectedExistent && workspace.tabs.length)
|
||||
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) {
|
||||
commit('RENAME_TABS', payload);
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue