diff --git a/src/_services/network.service.js b/src/_services/network.service.js index 5a1d499..9d923ff 100644 --- a/src/_services/network.service.js +++ b/src/_services/network.service.js @@ -8,6 +8,7 @@ export const networkService = { startNetwork, getStatusesByNetworkId, getNodesByNetworkId, + stopNetwork, deleteNetwork }; @@ -37,6 +38,11 @@ function getNodesByNetworkId(userId, networkId, messages, errors) { return fetch(`${config.apiUrl}/users/${userId}/networks/${networkId}/nodes`, util.getWithAuth()).then(util.handleCrudResponse(messages, errors)); } -function deleteNetwork(userId, networkId, messages, errors) { +function stopNetwork(userId, networkId, messages, errors) { return fetch(`${config.apiUrl}/users/${userId}/networks/${networkId}/actions/stop`, util.postWithAuth()).then(util.handleCrudResponse(messages, errors)); } + +// deleting network is not allowed via API, instead we delete the AccountPlan, which in turn deletes the network +function deleteNetwork(userId, networkId, messages, errors) { + return fetch(`${config.apiUrl}/users/${userId}/plans/${networkId}`, util.deleteWithAuth()).then(util.handleCrudResponse(messages, errors)); +} diff --git a/src/_store/networks.module.js b/src/_store/networks.module.js index 2d98149..6da30c3 100644 --- a/src/_store/networks.module.js +++ b/src/_store/networks.module.js @@ -69,12 +69,21 @@ const actions = { ); }, + stopNetwork({ commit }, {userId, networkId, messages, errors}) { + commit('stopNetworkRequest', id); + networkService.stopNetwork(userId, networkId, messages, errors) + .then( + network => commit('stopNetworkSuccess', network), + error => commit('stopNetworkFailure', { networkId, error: error.toString() }) + ); + }, + deleteNetwork({ commit }, {userId, networkId, messages, errors}) { - commit('deleteRequest', id); + commit('deleteNetworkRequest', id); networkService.deleteNetwork(userId, networkId, messages, errors) .then( - network => commit('deleteSuccess', network), - error => commit('deleteFailure', { networkId, error: error.toString() }) + network => commit('deleteNetworkSuccess', network), + error => commit('deleteNetworkFailure', { networkId, error: error.toString() }) ); }, @@ -154,21 +163,33 @@ const mutations = { state.error = { error }; }, - deleteRequest(state, id) { + stopNetworkRequest(state, id) { + state.loading.stopping = true; + }, + stopNetworkSuccess(state, id) { + state.loading.stopping = false; + }, + stopNetworkFailure(state, { id, error }) { + state.loading.stopping = false; + state.error = error; + }, + + deleteNetworkRequest(state, id) { state.loading.deleting = true; }, - deleteSuccess(state, id) { + deleteNetworkSuccess(state, id) { state.loading.deleting = false; // remove deleted network from state if (state.networks) { state.networks = state.networks.filter(network => (network.uuid !== id && network.name !== id)) } }, - deleteFailure(state, { id, error }) { + deleteNetworkFailure(state, { id, error }) { state.loading.deleting = false; - // remove 'deleting:true' property and add 'deleteError:[error]' property to network + // remove 'deleting:true' property and add 'deleteNetworkError:[error]' property to network state.error = error; }, + getNearestRegionsRequest(state) { state.loading.nearestRegions = true; }, diff --git a/src/account/NetworksPage.vue b/src/account/NetworksPage.vue index 1b2c5ca..e9ce4f0 100644 --- a/src/account/NetworksPage.vue +++ b/src/account/NetworksPage.vue @@ -11,7 +11,7 @@ {{messages.label_field_networks_timezone}} {{messages.label_field_networks_object_state}} {{messages.label_field_networks_action_view}} - {{messages.label_field_networks_action_start_stop}} + {{messages.label_field_networks_action_stop}} {{messages.label_field_networks_action_delete}} @@ -23,11 +23,14 @@ {{messages['msg_network_state_'+network.state]}} {{messages.table_row_networks_action_view}} - {{messages.table_row_networks_action_stop}} - {{messages.table_row_networks_action_start}} + + {{messages.table_row_networks_action_stop}} + - {{messages.table_row_networks_action_delete}} + + {{messages.table_row_networks_action_delete}} + @@ -58,7 +61,7 @@ this.getAllNetworks({userId: util.currentUser().uuid, messages: this.messages, errors: this.errors}); }, methods: { - ...mapActions('networks', ['getAllNetworks', 'deleteNetwork']), + ...mapActions('networks', ['getAllNetworks', 'stopNetwork', 'deleteNetwork']), ...mapGetters('networks', ['loading']) } };