DIsconnection

This commit is contained in:
Fabio 2020-05-18 18:06:32 +02:00
parent 14a2fad0ac
commit c23deb3760
7 changed files with 76 additions and 22 deletions

View File

@ -55,4 +55,9 @@ export default () => {
connections[conn.uid] = connection; connections[conn.uid] = connection;
return { status: 'success', response: structure }; return { status: 'success', response: structure };
}); });
ipcMain.handle('disconnect', (event, uid) => {
connections[uid].destroy();
delete connections[uid];
});
}; };

View File

@ -9,7 +9,7 @@
class="material-icons c-hand" class="material-icons c-hand"
@click="toggleExpand" @click="toggleExpand"
>{{ isExpanded ? 'expand_less' : 'expand_more' }}</i> >{{ isExpanded ? 'expand_less' : 'expand_more' }}</i>
<button class="btn btn-clear" @click="hideToast" /> <button class="btn btn-clear ml-2" @click="hideToast" />
</div> </div>
</template> </template>

View File

@ -1,5 +1,5 @@
<template> <template>
<div v-if="!isConnected" class="columns"> <div class="columns">
<div class="column col-12 empty text-light"> <div class="column col-12 empty text-light">
<div class="empty-icon"> <div class="empty-icon">
<i class="material-icons md-48">cloud_off</i> <i class="material-icons md-48">cloud_off</i>
@ -21,7 +21,7 @@
</template> </template>
<script> <script>
import { mapGetters, mapActions } from 'vuex'; import { mapActions } from 'vuex';
import Connection from '@/ipc-api/Connection'; import Connection from '@/ipc-api/Connection';
export default { export default {
@ -34,14 +34,6 @@ export default {
isConnecting: false isConnecting: false
}; };
}, },
computed: {
...mapGetters({
connected: 'workspaces/getConnected'
}),
isConnected () {
return this.connected.includes(this.connection.uid);
}
},
methods: { methods: {
...mapActions({ ...mapActions({
addNotification: 'notifications/addNotification', addNotification: 'notifications/addNotification',

View File

@ -1,13 +1,22 @@
<template> <template>
<div class="workspace-explorebar column"> <div class="workspace-explorebar column">
<div class="workspace-explorebar-title"> <div class="workspace-explorebar-header">
{{ connection.user }}@{{ connection.host }}:{{ connection.port }} <span class="workspace-explorebar-title">{{ connection.user }}@{{ connection.host }}:{{ connection.port }}</span>
<span v-if="isConnected" class="workspace-explorebar-tools">
<i class="material-icons md-18 c-hand mr-1" title="Refresh">cached</i>
<i
class="material-icons md-18 c-hand"
title="Disconnect"
@click="disconnectWorkspace(connection.uid)"
>exit_to_app</i>
</span>
</div> </div>
<DatabaseConnectPanel :connection="connection" /> <DatabaseConnectPanel v-if="!isConnected" :connection="connection" />
</div> </div>
</template> </template>
<script> <script>
import { mapGetters, mapActions } from 'vuex';
import DatabaseConnectPanel from '@/components/DatabaseConnectPanel'; import DatabaseConnectPanel from '@/components/DatabaseConnectPanel';
export default { export default {
@ -17,6 +26,19 @@ export default {
}, },
props: { props: {
connection: Object connection: Object
},
computed: {
...mapGetters({
connected: 'workspaces/getConnected'
}),
isConnected () {
return this.connected.includes(this.connection.uid);
}
},
methods: {
...mapActions({
disconnectWorkspace: 'workspaces/removeConnected'
})
} }
}; };
</script> </script>
@ -37,15 +59,33 @@ export default {
position: relative; position: relative;
padding-top: 1.4rem; padding-top: 1.4rem;
.workspace-explorebar-title{ .workspace-explorebar-header{
top: 0; top: 0;
left: 0; left: 0;
right: 0; right: 0;
padding: .3rem; padding: .3rem;
position: absolute; position: absolute;
display: flex;
justify-content: space-between;
font-size: .6rem; font-size: .6rem;
font-weight: 700; font-weight: 700;
text-transform: uppercase; text-transform: uppercase;
.workspace-explorebar-title{
width: 80%;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.workspace-explorebar-tools > i{
opacity: .6;
transition: opacity .2s;;
&:hover{
opacity: 1;
}
}
} }
} }
</style> </style>

View File

@ -2,7 +2,7 @@
<div v-show="selectedWorkspace === connection.uid" class="workspace column columns"> <div v-show="selectedWorkspace === connection.uid" class="workspace column columns">
<DatabaseExploreBar :connection="connection" /> <DatabaseExploreBar :connection="connection" />
<div class="workspace-tabs column"> <div class="workspace-tabs column">
<p>{{ connection }}</p> <pre>{{ JSON.stringify(connection, null, 3) }}</pre>
</div> </div>
</div> </div>
</template> </template>
@ -32,6 +32,7 @@ export default {
}) })
}, },
async created () { async created () {
this.addWorkspace(this.connection.uid);
const isInitiated = await Connection.checkConnection(this.connection.uid); const isInitiated = await Connection.checkConnection(this.connection.uid);
if (isInitiated) { if (isInitiated) {
try { try {
@ -51,6 +52,7 @@ export default {
methods: { methods: {
...mapActions({ ...mapActions({
addNotification: 'notifications/addNotification', addNotification: 'notifications/addNotification',
addWorkspace: 'workspaces/addWorkspace',
addConnected: 'workspaces/addConnected', addConnected: 'workspaces/addConnected',
removeConnected: 'workspaces/removeConnected' removeConnected: 'workspaces/removeConnected'
}) })

View File

@ -14,6 +14,10 @@ export default class {
return ipcRenderer.invoke('connect', params); return ipcRenderer.invoke('connect', params);
} }
static disconnect (uid) {
return ipcRenderer.invoke('disconnect', uid);
}
// TODO: refresh // TODO: refresh
// TODO: disconnect // TODO: disconnect
} }

View File

@ -1,5 +1,5 @@
'use strict'; 'use strict';
// import { uidGen } from 'common/libs/utilities'; import Connection from '@/ipc-api/Connection';
export default { export default {
namespaced: true, namespaced: true,
@ -7,11 +7,11 @@ export default {
state: { state: {
workspaces: [], workspaces: [],
connected_workspaces: [], connected_workspaces: [],
workspace_selected: null selected_workspace: null
}, },
getters: { getters: {
getSelected: state => { getSelected: state => {
if (state.workspace_selected) return state.workspace_selected; if (state.selected_workspace) return state.selected_workspace;
if (state.workspaces.length) return state.workspaces[0].uid; if (state.workspaces.length) return state.workspaces[0].uid;
return null; return null;
}, },
@ -20,13 +20,16 @@ export default {
}, },
mutations: { mutations: {
SELECT_WORKSPACE (state, uid) { SELECT_WORKSPACE (state, uid) {
state.workspace_selected = uid; state.selected_workspace = uid;
}, },
ADD_CONNECTED (state, uid) { ADD_CONNECTED (state, uid) {
state.connected_workspaces.push(uid); state.connected_workspaces.push(uid);
}, },
REMOVE_CONNECTED (state, uid) { REMOVE_CONNECTED (state, uid) {
state.connected_workspaces = state.connected_workspaces.filter(item => item.uid !== uid); state.connected_workspaces = state.connected_workspaces.filter(value => value !== uid);
},
ADD_WORKSPACE (state, workspace) {
state.workspaces.push(workspace);
} }
}, },
actions: { actions: {
@ -36,8 +39,16 @@ export default {
addConnected ({ commit }, uid) { addConnected ({ commit }, uid) {
commit('ADD_CONNECTED', uid); commit('ADD_CONNECTED', uid);
}, },
removeConnected ({ commit }, uid) { async removeConnected ({ commit }, uid) {
Connection.disconnect(uid);
commit('REMOVE_CONNECTED', uid); commit('REMOVE_CONNECTED', uid);
},
addWorkspace ({ commit }, uid) {
const workspace = {
uid,
tabs: []
};
commit('ADD_WORKSPACE', workspace);
} }
} }
}; };