antares/src/renderer/store/modules/connections.store.js

66 lines
2.1 KiB
JavaScript
Raw Normal View History

2020-05-08 18:02:18 +02:00
'use strict';
import Store from 'electron-store';
import Application from '../../ipc-api/Application';
const key = Application.getKey();
const persistentStore = new Store({
name: 'connections',
encryptionKey: key
});
2020-05-08 18:02:18 +02:00
export default {
namespaced: true,
strict: true,
state: {
connections: persistentStore.get('connections') || []
2020-05-12 18:27:31 +02:00
},
getters: {
2020-05-31 17:56:33 +02:00
getConnections: state => state.connections,
getConnectionName: state => uid => {
const connection = state.connections.filter(connection => connection.uid === uid)[0];
return connection.name
? connection.name
: connection.ask
? `${connection.host}:${connection.port}`
2020-05-31 17:56:33 +02:00
: `${connection.user + '@'}${connection.host}:${connection.port}`;
}
2020-05-08 18:02:18 +02:00
},
mutations: {
2020-05-12 18:27:31 +02:00
ADD_CONNECTION (state, connection) {
state.connections.push(connection);
persistentStore.set('connections', state.connections);
2020-05-12 18:27:31 +02:00
},
2020-05-23 13:32:14 +02:00
DELETE_CONNECTION (state, connection) {
state.connections = state.connections.filter(el => el.uid !== connection.uid);
persistentStore.set('connections', state.connections);
2020-05-23 13:32:14 +02:00
},
2020-05-23 22:02:09 +02:00
EDIT_CONNECTION (state, connection) {
const editedConnections = state.connections.map(conn => {
if (conn.uid === connection.uid) return connection;
return conn;
});
state.connections = editedConnections;
state.selected_conection = {};
persistentStore.set('connections', state.connections);
2020-05-23 22:02:09 +02:00
},
2020-05-22 19:32:55 +02:00
UPDATE_CONNECTIONS (state, connections) {
state.connections = connections;
persistentStore.set('connections', state.connections);
2020-05-08 18:02:18 +02:00
}
},
actions: {
2020-05-12 18:27:31 +02:00
addConnection ({ commit }, connection) {
commit('ADD_CONNECTION', connection);
},
2020-05-23 13:32:14 +02:00
deleteConnection ({ commit }, connection) {
commit('DELETE_CONNECTION', connection);
},
editConnection ({ commit }, connection) {
commit('EDIT_CONNECTION', connection);
},
2020-05-22 19:32:55 +02:00
updateConnections ({ commit }, connections) {
commit('UPDATE_CONNECTIONS', connections);
2020-05-08 18:02:18 +02:00
}
}
};