Selaa lähdekoodia

working on network view page

pull/1/head
Jonathan Cobb 4 vuotta sitten
vanhempi
commit
5929c08346
5 muutettua tiedostoa jossa 78 lisäystä ja 22 poistoa
  1. +7
    -2
      src/_services/network.service.js
  2. +35
    -13
      src/_store/networks.module.js
  3. +27
    -4
      src/account/NetworkPage.vue
  4. +2
    -1
      src/account/NetworksPage.vue
  5. +7
    -2
      src/account/NewNetworkPage.vue

+ 7
- 2
src/_services/network.service.js Näytä tiedosto

@@ -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}&region=${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));
}

+ 35
- 13
src/_store/networks.module.js Näytä tiedosto

@@ -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;
},


+ 27
- 4
src/account/NetworkPage.vue Näytä tiedosto

@@ -1,28 +1,51 @@
<template>
<div>
Single network page
<h4 v-if="network">{{network.name}}.{{network.domainName}}</h4>
<hr/>

</div>
</template>

<script>
import { mapState, mapActions, mapGetters } from 'vuex'
import { util } from '../_helpers'

export default {
data() {
return {
};
},
computed: {
...mapState('networks', ['network', 'newNodeNotification', 'networkStatuses']),
...mapState({
network: state => state.network,
error: state => state.error
})
},
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: {
...mapActions('networks', {
getById: 'getByUuid',
deleteNetwork: 'delete'
deleteNetwork: 'delete',
getNetworkStatuses: 'getNetworkStatuses'
}),
...mapGetters('networks', ['loading'])
},
watch: {
network (net) {
console.log('received network: '+JSON.stringify(net));
},
networkStatuses (stats) {
console.log('received stats: '+JSON.stringify(stats));
}
}
};
</script>

+ 2
- 1
src/account/NetworksPage.vue Näytä tiedosto

@@ -42,6 +42,7 @@

<script>
import { mapState, mapActions, mapGetters } from 'vuex'
import { util } from '../_helpers'

export default {
computed: {
@@ -51,7 +52,7 @@
...mapState('system', ['messages'])
},
created () {
this.getAllNetworks({messages: this.messages, errors: this.errors});
this.getAllNetworks({userId: util.currentUser().uuid, messages: this.messages, errors: this.errors});
},
methods: {
...mapActions('networks', {


+ 7
- 2
src/account/NewNetworkPage.vue Näytä tiedosto

@@ -232,7 +232,7 @@
...mapState('plans', ['plans']),
...mapState('footprints', ['footprints']),
...mapState('paymentMethods', ['paymentMethods', 'accountPaymentMethod', 'paymentMethod', 'paymentInfo']),
...mapState('networks', ['nearestRegions']),
...mapState('networks', ['nearestRegions', 'newNodeNotification']),
...mapState('networks', {
error: state => state.error
}),
@@ -313,7 +313,7 @@
this.loadPlans(this.messages, this.errors);
this.loadFootprints(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); },
isNotAuthenticator(val) { return window.isNotAuthenticator(val); },
@@ -460,6 +460,11 @@
if (status.success) {
this.initDefaults();
}
},
newNodeNotification (nn) {
if (nn && nn.uuid) {
this.$router.push({path:'/networks', params: {uuid: nn.network}, query: {'status': nn.uuid}});
}
}
},
created() {


Ladataan…
Peruuta
Tallenna