From 5929c083466af4326f149feef4576b3fb1f9b89c Mon Sep 17 00:00:00 2001 From: Jonathan Cobb Date: Wed, 8 Jan 2020 07:41:10 -0500 Subject: [PATCH] working on network view page --- src/_services/network.service.js | 9 ++++-- src/_store/networks.module.js | 48 +++++++++++++++++++++++--------- src/account/NetworkPage.vue | 31 ++++++++++++++++++--- src/account/NetworksPage.vue | 3 +- src/account/NewNetworkPage.vue | 9 ++++-- 5 files changed, 78 insertions(+), 22 deletions(-) diff --git a/src/_services/network.service.js b/src/_services/network.service.js index 3942567..291c1d0 100644 --- a/src/_services/network.service.js +++ b/src/_services/network.service.js @@ -5,7 +5,8 @@ export const networkService = { getAll, getById, getNearestRegions, - startNetwork + startNetwork, + getNetworkStatuses }; function getAll(userId, messages, errors) { @@ -16,7 +17,7 @@ function getById(userId, networkId, messages, errors) { return fetch(`${config.apiUrl}/users/${userId}/networks/${networkId}`, util.getWithAuth()).then(util.handleCrudResponse(messages, errors)); } -function getNearestRegions(userId, footprint, messages, errors) { +function getNearestRegions(footprint, messages, errors) { const footprintParam = (typeof footprint === 'undefined' || footprint === null || footprint === '') ? "" : `?footprint=${footprint}`; return fetch(`${config.apiUrl}/me/regions/closest${footprintParam}`, util.getWithAuth()).then(util.handleCrudResponse(messages, errors)); } @@ -24,4 +25,8 @@ function getNearestRegions(userId, footprint, messages, errors) { function startNetwork(userId, planId, cloud, region, messages, errors) { const cloudAndRegion = (typeof cloud === 'undefined' || typeof region === 'undefined' || cloud === null || region === null) ? "" : `?cloud=${cloud}®ion=${region}`; return fetch(`${config.apiUrl}/users/${userId}/networks/${planId}/actions/start${cloudAndRegion}`, util.postWithAuth()).then(util.handleCrudResponse(messages, errors)); +} + +function getNetworkStatuses(userId, network, messages, errors) { + return fetch(`${config.apiUrl}/users/${userId}/networks/${network}/actions/status`, util.getWithAuth()).then(util.handleCrudResponse(messages, errors)); } \ No newline at end of file diff --git a/src/_store/networks.module.js b/src/_store/networks.module.js index 3f19c52..a51d601 100644 --- a/src/_store/networks.module.js +++ b/src/_store/networks.module.js @@ -1,45 +1,46 @@ import { networkService } from '../_services'; import { accountPlanService } from '../_services'; -import { account } from '../_store/account.module'; import { util } from '../_helpers'; const state = { loading: { - networks: false, network: false, deleting: false, nearestRegions: false, startingNetwork: false + networks: false, network: false, deleting: false, + nearestRegions: false, startingNetwork: false, networkStatuses: false }, creating: null, error: null, networks: null, network: null, nearestRegions: null, - newNodeNotification: null + newNodeNotification: null, + networkStatuses: {} }; const actions = { - getAll({ commit }, {messages, errors}) { + getAll({ commit }, {userId, messages, errors}) { commit('getAllRequest'); - networkService.getAll(account.state.user.uuid, messages, errors) + networkService.getAll(userId, messages, errors) .then( networks => commit('getAllSuccess', networks), error => commit('getAllFailure', error) ); }, - getByUuid({ commit }, {uuid, messages, errors}) { + getByUuid({ commit }, {userId, uuid, messages, errors}) { commit('getByUuidRequest'); - networkService.getById(account.state.user.uuid, uuid, messages, errors) + networkService.getById(userId, uuid, messages, errors) .then( network => commit('getByUuidSuccess', network), error => commit('getByUuidFailure', error) ); }, - addPlanAndStartNetwork({ commit }, {accountPlan, cloud, region, messages, errors}) { + addPlanAndStartNetwork({ commit }, {userId, accountPlan, cloud, region, messages, errors}) { commit('addPlanAndStartNetworkRequest'); - accountPlanService.newAccountPlan(account.state.user.uuid, accountPlan, messages, errors) + accountPlanService.newAccountPlan(userId, accountPlan, messages, errors) .then( plan => { - networkService.startNetwork(account.state.user.uuid, plan.name, cloud, region, messages, errors) + networkService.startNetwork(userId, plan.name, cloud, region, messages, errors) .then( network => commit('addPlanAndStartNetworkSuccess', network), error => commit('addPlanSuccessStartNetworkFailure', error) @@ -49,9 +50,18 @@ const actions = { ); }, - delete({ commit }, {id, messages, errors}) { + getNetworkStatuses({ commit }, {userId, network, messages, errors}) { + commit('getNetworkStatusRequest', network); + networkService.getNetworkStatuses(userId, network, messages, errors) + .then( + statuses => commit('getNetworkStatusSuccess', { network, statuses }), + error => commit('getNetworkStatusFailure', { network, error }) + ); + }, + + delete({ commit }, {userId, id, messages, errors}) { commit('deleteRequest', id); - networkService.delete(account.state.user.uuid, id, messages, errors) + networkService.delete(userId, id, messages, errors) .then( network => commit('deleteSuccess', network), error => commit('deleteFailure', { id, error: error.toString() }) @@ -60,7 +70,7 @@ const actions = { getNearestRegions({ commit }, {footprint, messages, errors}) { commit('getNearestRegionsRequest'); - networkService.getNearestRegions(account.state.user.uuid, footprint, messages, errors) + networkService.getNearestRegions(footprint, messages, errors) .then( regions => commit('getNearestRegionsSuccess', regions), error => commit('getNearestRegionsFailure', error) @@ -108,6 +118,18 @@ const mutations = { state.error = { error }; }, + getNetworkStatusRequest(state, network) { + state.loading.networkStatuses = true; + }, + getNetworkStatusSuccess(state, {network, statuses}) { + state.loading.networkStatuses = false; + state.networkStatuses[network] = statuses; + }, + getNetworkStatusFailure(state, {network, error}) { + state.loading.networkStatuses = false; + state.error = { error }; + }, + deleteRequest(state, id) { state.loading.deleting = true; }, diff --git a/src/account/NetworkPage.vue b/src/account/NetworkPage.vue index debef5b..3e86c6c 100644 --- a/src/account/NetworkPage.vue +++ b/src/account/NetworkPage.vue @@ -1,28 +1,51 @@ \ No newline at end of file diff --git a/src/account/NetworksPage.vue b/src/account/NetworksPage.vue index 5cf03c7..6d35adb 100644 --- a/src/account/NetworksPage.vue +++ b/src/account/NetworksPage.vue @@ -42,6 +42,7 @@