mirror of
				https://github.com/Fabio286/antares.git
				synced 2025-06-05 21:59:22 +02:00 
			
		
		
		
	Additions, again
This commit is contained in:
		| @@ -60,4 +60,15 @@ export default () => { | ||||
|       connections[uid].destroy(); | ||||
|       delete connections[uid]; | ||||
|    }); | ||||
|  | ||||
|    ipcMain.handle('refresh', async (event, uid) => { | ||||
|       try { | ||||
|          structure = await InformationSchema.getStructure(connection); | ||||
|       } | ||||
|       catch (err) { | ||||
|          return { status: 'error', response: err.toString() }; | ||||
|       } | ||||
|  | ||||
|       return { status: 'success', response: structure }; | ||||
|    }); | ||||
| }; | ||||
|   | ||||
| @@ -22,7 +22,6 @@ | ||||
|  | ||||
| <script> | ||||
| import { mapActions } from 'vuex'; | ||||
| import Connection from '@/ipc-api/Connection'; | ||||
|  | ||||
| export default { | ||||
|    name: 'DatabaseConnectPanel', | ||||
| @@ -37,20 +36,11 @@ export default { | ||||
|    methods: { | ||||
|       ...mapActions({ | ||||
|          addNotification: 'notifications/addNotification', | ||||
|          addConnected: 'workspaces/addConnected' | ||||
|          connectWorkspace: 'workspaces/connectWorkspace' | ||||
|       }), | ||||
|       async startConnection () { | ||||
|          this.isConnecting = true; | ||||
|          try { | ||||
|             const { status, response } = await Connection.connect(this.connection); | ||||
|             if (status === 'error') | ||||
|                this.addNotification({ status, message: response }); | ||||
|             else | ||||
|                this.addConnected(this.connection.uid); | ||||
|          } | ||||
|          catch (err) { | ||||
|             this.addNotification({ status: 'error', message: err.stack }); | ||||
|          } | ||||
|          await this.connectWorkspace(this.connection); | ||||
|          this.isConnecting = false; | ||||
|       } | ||||
|    } | ||||
|   | ||||
| @@ -20,11 +20,6 @@ export default { | ||||
|    props: { | ||||
|       connection: Object | ||||
|    }, | ||||
|    data () { | ||||
|       return { | ||||
|          structure: null | ||||
|       }; | ||||
|    }, | ||||
|    computed: { | ||||
|       ...mapGetters({ | ||||
|          selectedWorkspace: 'workspaces/getSelected', | ||||
| @@ -34,26 +29,14 @@ export default { | ||||
|    async created () { | ||||
|       this.addWorkspace(this.connection.uid); | ||||
|       const isInitiated = await Connection.checkConnection(this.connection.uid); | ||||
|       if (isInitiated) { | ||||
|          try { | ||||
|             const { status, response } = await Connection.connect(this.connection); | ||||
|             if (status === 'success') { | ||||
|                this.structure = response; | ||||
|                this.addConnected(this.connection.uid); | ||||
|             } | ||||
|             else | ||||
|                this.addNotification({ status, message: response }); | ||||
|          } | ||||
|          catch (err) { | ||||
|             this.addNotification({ status: 'error', message: err.toString() }); | ||||
|          } | ||||
|       } | ||||
|       if (isInitiated) | ||||
|          this.connectWorkspace(this.connection); | ||||
|    }, | ||||
|    methods: { | ||||
|       ...mapActions({ | ||||
|          addNotification: 'notifications/addNotification', | ||||
|          addWorkspace: 'workspaces/addWorkspace', | ||||
|          addConnected: 'workspaces/addConnected', | ||||
|          connectWorkspace: 'workspaces/connectWorkspace', | ||||
|          removeConnected: 'workspaces/removeConnected' | ||||
|       }) | ||||
|    } | ||||
|   | ||||
| @@ -18,6 +18,7 @@ export default class { | ||||
|       return ipcRenderer.invoke('disconnect', uid); | ||||
|    } | ||||
|  | ||||
|    // TODO: refresh | ||||
|    // TODO: disconnect | ||||
|    static refresh (uid) { | ||||
|       return ipcRenderer.invoke('refresh', uid); | ||||
|    } | ||||
| } | ||||
|   | ||||
| @@ -6,7 +6,7 @@ export default { | ||||
|    strict: true, | ||||
|    state: { | ||||
|       workspaces: [], | ||||
|       connected_workspaces: [], | ||||
|       connected_workspaces: [], // TODO: move to state.workspaces | ||||
|       selected_workspace: null | ||||
|    }, | ||||
|    getters: { | ||||
| @@ -22,11 +22,13 @@ export default { | ||||
|       SELECT_WORKSPACE (state, uid) { | ||||
|          state.selected_workspace = uid; | ||||
|       }, | ||||
|       ADD_CONNECTED (state, uid) { | ||||
|       ADD_CONNECTED (state, { uid, structure }) { | ||||
|          state.connected_workspaces.push(uid); | ||||
|          state.workspaces = state.workspaces.map(workspace => workspace.uid === uid ? { ...workspace, structure } : workspace); | ||||
|       }, | ||||
|       REMOVE_CONNECTED (state, uid) { | ||||
|          state.connected_workspaces = state.connected_workspaces.filter(value => value !== uid); | ||||
|          state.workspaces = state.workspaces.map(workspace => workspace.uid === uid ? { ...workspace, structure: {} } : workspace); | ||||
|       }, | ||||
|       ADD_WORKSPACE (state, workspace) { | ||||
|          state.workspaces.push(workspace); | ||||
| @@ -36,8 +38,17 @@ export default { | ||||
|       selectWorkspace ({ commit }, uid) { | ||||
|          commit('SELECT_WORKSPACE', uid); | ||||
|       }, | ||||
|       addConnected ({ commit }, uid) { | ||||
|          commit('ADD_CONNECTED', uid); | ||||
|       async connectWorkspace ({ dispatch, commit }, connection) { | ||||
|          try { | ||||
|             const { status, response } = await Connection.connect(connection); | ||||
|             if (status === 'error') | ||||
|                dispatch('notifications/addNotification', { status, message: response }, { root: true }); | ||||
|             else | ||||
|                commit('ADD_CONNECTED', { uid: connection.uid, structure: response }); | ||||
|          } | ||||
|          catch (err) { | ||||
|             dispatch('notifications/addNotification', { status: 'error', message: err.stack }, { root: true }); | ||||
|          } | ||||
|       }, | ||||
|       async removeConnected ({ commit }, uid) { | ||||
|          Connection.disconnect(uid); | ||||
| @@ -46,7 +57,9 @@ export default { | ||||
|       addWorkspace ({ commit }, uid) { | ||||
|          const workspace = { | ||||
|             uid, | ||||
|             tabs: [] | ||||
|             connected: false, | ||||
|             tabs: [], | ||||
|             structure: {} | ||||
|          }; | ||||
|          commit('ADD_WORKSPACE', workspace); | ||||
|       } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user