@@ -5,7 +5,8 @@ export const networkService = { | |||||
getAll, | getAll, | ||||
getById, | getById, | ||||
getNearestRegions, | getNearestRegions, | ||||
startNetwork | |||||
startNetwork, | |||||
getNetworkStatuses | |||||
}; | }; | ||||
function getAll(userId, messages, errors) { | 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)); | 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}`; | 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)); | 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) { | function startNetwork(userId, planId, cloud, region, messages, errors) { | ||||
const cloudAndRegion = (typeof cloud === 'undefined' || typeof region === 'undefined' || cloud === null || region === null) ? "" : `?cloud=${cloud}®ion=${region}`; | 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)); | 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)); | |||||
} | } |
@@ -1,45 +1,46 @@ | |||||
import { networkService } from '../_services'; | import { networkService } from '../_services'; | ||||
import { accountPlanService } from '../_services'; | import { accountPlanService } from '../_services'; | ||||
import { account } from '../_store/account.module'; | |||||
import { util } from '../_helpers'; | import { util } from '../_helpers'; | ||||
const state = { | const state = { | ||||
loading: { | 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, | creating: null, | ||||
error: null, | error: null, | ||||
networks: null, | networks: null, | ||||
network: null, | network: null, | ||||
nearestRegions: null, | nearestRegions: null, | ||||
newNodeNotification: null | |||||
newNodeNotification: null, | |||||
networkStatuses: {} | |||||
}; | }; | ||||
const actions = { | const actions = { | ||||
getAll({ commit }, {messages, errors}) { | |||||
getAll({ commit }, {userId, messages, errors}) { | |||||
commit('getAllRequest'); | commit('getAllRequest'); | ||||
networkService.getAll(account.state.user.uuid, messages, errors) | |||||
networkService.getAll(userId, messages, errors) | |||||
.then( | .then( | ||||
networks => commit('getAllSuccess', networks), | networks => commit('getAllSuccess', networks), | ||||
error => commit('getAllFailure', error) | error => commit('getAllFailure', error) | ||||
); | ); | ||||
}, | }, | ||||
getByUuid({ commit }, {uuid, messages, errors}) { | |||||
getByUuid({ commit }, {userId, uuid, messages, errors}) { | |||||
commit('getByUuidRequest'); | commit('getByUuidRequest'); | ||||
networkService.getById(account.state.user.uuid, uuid, messages, errors) | |||||
networkService.getById(userId, uuid, messages, errors) | |||||
.then( | .then( | ||||
network => commit('getByUuidSuccess', network), | network => commit('getByUuidSuccess', network), | ||||
error => commit('getByUuidFailure', error) | error => commit('getByUuidFailure', error) | ||||
); | ); | ||||
}, | }, | ||||
addPlanAndStartNetwork({ commit }, {accountPlan, cloud, region, messages, errors}) { | |||||
addPlanAndStartNetwork({ commit }, {userId, accountPlan, cloud, region, messages, errors}) { | |||||
commit('addPlanAndStartNetworkRequest'); | commit('addPlanAndStartNetworkRequest'); | ||||
accountPlanService.newAccountPlan(account.state.user.uuid, accountPlan, messages, errors) | |||||
accountPlanService.newAccountPlan(userId, accountPlan, messages, errors) | |||||
.then( | .then( | ||||
plan => { | plan => { | ||||
networkService.startNetwork(account.state.user.uuid, plan.name, cloud, region, messages, errors) | |||||
networkService.startNetwork(userId, plan.name, cloud, region, messages, errors) | |||||
.then( | .then( | ||||
network => commit('addPlanAndStartNetworkSuccess', network), | network => commit('addPlanAndStartNetworkSuccess', network), | ||||
error => commit('addPlanSuccessStartNetworkFailure', error) | 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); | commit('deleteRequest', id); | ||||
networkService.delete(account.state.user.uuid, id, messages, errors) | |||||
networkService.delete(userId, id, messages, errors) | |||||
.then( | .then( | ||||
network => commit('deleteSuccess', network), | network => commit('deleteSuccess', network), | ||||
error => commit('deleteFailure', { id, error: error.toString() }) | error => commit('deleteFailure', { id, error: error.toString() }) | ||||
@@ -60,7 +70,7 @@ const actions = { | |||||
getNearestRegions({ commit }, {footprint, messages, errors}) { | getNearestRegions({ commit }, {footprint, messages, errors}) { | ||||
commit('getNearestRegionsRequest'); | commit('getNearestRegionsRequest'); | ||||
networkService.getNearestRegions(account.state.user.uuid, footprint, messages, errors) | |||||
networkService.getNearestRegions(footprint, messages, errors) | |||||
.then( | .then( | ||||
regions => commit('getNearestRegionsSuccess', regions), | regions => commit('getNearestRegionsSuccess', regions), | ||||
error => commit('getNearestRegionsFailure', error) | error => commit('getNearestRegionsFailure', error) | ||||
@@ -108,6 +118,18 @@ const mutations = { | |||||
state.error = { error }; | 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) { | deleteRequest(state, id) { | ||||
state.loading.deleting = true; | state.loading.deleting = true; | ||||
}, | }, | ||||
@@ -1,28 +1,51 @@ | |||||
<template> | <template> | ||||
<div> | <div> | ||||
Single network page | |||||
<h4 v-if="network">{{network.name}}.{{network.domainName}}</h4> | |||||
<hr/> | |||||
</div> | </div> | ||||
</template> | </template> | ||||
<script> | <script> | ||||
import { mapState, mapActions, mapGetters } from 'vuex' | import { mapState, mapActions, mapGetters } from 'vuex' | ||||
import { util } from '../_helpers' | |||||
export default { | export default { | ||||
data() { | |||||
return { | |||||
}; | |||||
}, | |||||
computed: { | computed: { | ||||
...mapState('networks', ['network', 'newNodeNotification', 'networkStatuses']), | |||||
...mapState({ | ...mapState({ | ||||
network: state => state.network, | |||||
error: state => state.error | error: state => state.error | ||||
}) | }) | ||||
}, | }, | ||||
created () { | created () { | ||||
this.getById(this.$route.params.uuid); | |||||
const user = util.currentUser(); | |||||
this.getById({userId: user.uuid, uuid: this.$route.params.uuid}); | |||||
this.getNetworkStatuses({ | |||||
userId: user.uuid, | |||||
network: this.$route.params.uuid, | |||||
messages: this.messages, | |||||
errors: this.errors | |||||
}); | |||||
}, | }, | ||||
methods: { | methods: { | ||||
...mapActions('networks', { | ...mapActions('networks', { | ||||
getById: 'getByUuid', | getById: 'getByUuid', | ||||
deleteNetwork: 'delete' | |||||
deleteNetwork: 'delete', | |||||
getNetworkStatuses: 'getNetworkStatuses' | |||||
}), | }), | ||||
...mapGetters('networks', ['loading']) | ...mapGetters('networks', ['loading']) | ||||
}, | |||||
watch: { | |||||
network (net) { | |||||
console.log('received network: '+JSON.stringify(net)); | |||||
}, | |||||
networkStatuses (stats) { | |||||
console.log('received stats: '+JSON.stringify(stats)); | |||||
} | |||||
} | } | ||||
}; | }; | ||||
</script> | </script> |
@@ -42,6 +42,7 @@ | |||||
<script> | <script> | ||||
import { mapState, mapActions, mapGetters } from 'vuex' | import { mapState, mapActions, mapGetters } from 'vuex' | ||||
import { util } from '../_helpers' | |||||
export default { | export default { | ||||
computed: { | computed: { | ||||
@@ -51,7 +52,7 @@ | |||||
...mapState('system', ['messages']) | ...mapState('system', ['messages']) | ||||
}, | }, | ||||
created () { | created () { | ||||
this.getAllNetworks({messages: this.messages, errors: this.errors}); | |||||
this.getAllNetworks({userId: util.currentUser().uuid, messages: this.messages, errors: this.errors}); | |||||
}, | }, | ||||
methods: { | methods: { | ||||
...mapActions('networks', { | ...mapActions('networks', { | ||||
@@ -232,7 +232,7 @@ | |||||
...mapState('plans', ['plans']), | ...mapState('plans', ['plans']), | ||||
...mapState('footprints', ['footprints']), | ...mapState('footprints', ['footprints']), | ||||
...mapState('paymentMethods', ['paymentMethods', 'accountPaymentMethod', 'paymentMethod', 'paymentInfo']), | ...mapState('paymentMethods', ['paymentMethods', 'accountPaymentMethod', 'paymentMethod', 'paymentInfo']), | ||||
...mapState('networks', ['nearestRegions']), | |||||
...mapState('networks', ['nearestRegions', 'newNodeNotification']), | |||||
...mapState('networks', { | ...mapState('networks', { | ||||
error: state => state.error | error: state => state.error | ||||
}), | }), | ||||
@@ -313,7 +313,7 @@ | |||||
this.loadPlans(this.messages, this.errors); | this.loadPlans(this.messages, this.errors); | ||||
this.loadFootprints(this.messages, this.errors); | this.loadFootprints(this.messages, this.errors); | ||||
this.loadPaymentMethods(this.messages, this.errors); | this.loadPaymentMethods(this.messages, this.errors); | ||||
this.getNearestRegions(currentUser.uuid, null, this.messages, this.errors); | |||||
this.getNearestRegions(null, this.messages, this.errors); | |||||
}, | }, | ||||
isAuthenticator(val) { return window.isAuthenticator(val); }, | isAuthenticator(val) { return window.isAuthenticator(val); }, | ||||
isNotAuthenticator(val) { return window.isNotAuthenticator(val); }, | isNotAuthenticator(val) { return window.isNotAuthenticator(val); }, | ||||
@@ -460,6 +460,11 @@ | |||||
if (status.success) { | if (status.success) { | ||||
this.initDefaults(); | this.initDefaults(); | ||||
} | } | ||||
}, | |||||
newNodeNotification (nn) { | |||||
if (nn && nn.uuid) { | |||||
this.$router.push({path:'/networks', params: {uuid: nn.network}, query: {'status': nn.uuid}}); | |||||
} | |||||
} | } | ||||
}, | }, | ||||
created() { | created() { | ||||