From a45c053235fc63154b27f6833958a3be7f73fac0 Mon Sep 17 00:00:00 2001 From: Jonathan Cobb Date: Tue, 14 Jan 2020 21:00:15 -0500 Subject: [PATCH] add support for fork host --- src/_services/network.service.js | 12 +++++++++++- src/_store/networks.module.js | 19 ++++++++++++++----- src/_store/system.module.js | 10 ++++++---- src/account/NewNetworkPage.vue | 32 +++++++++++++++++++++++++++++--- 4 files changed, 60 insertions(+), 13 deletions(-) diff --git a/src/_services/network.service.js b/src/_services/network.service.js index 075c04f..3ca0698 100644 --- a/src/_services/network.service.js +++ b/src/_services/network.service.js @@ -6,6 +6,7 @@ export const networkService = { getNetworkById, getNearestRegions, startNetwork, + forkNetwork, getStatusesByNetworkId, getNodesByNetworkId, stopNetwork, @@ -27,11 +28,20 @@ function getNearestRegions(footprint, messages, errors) { return fetch(`${config.apiUrl}/me/regions/closest${footprintParam}`, util.getWithAuth()).then(util.handleCrudResponse(messages, errors)); } +function getCloudAndRegion(cloud, region) { + return (typeof cloud === 'undefined' || typeof region === 'undefined' || cloud === null || region === null) ? "" : `?cloud=${cloud}®ion=${region}`; +} + 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 = getCloudAndRegion(cloud, region); return fetch(`${config.apiUrl}/users/${userId}/networks/${planId}/actions/start${cloudAndRegion}`, util.postWithAuth()).then(util.handleCrudResponse(messages, errors)); } +function forkNetwork(userId, planId, forkHost, cloud, region, messages, errors) { + const cloudAndRegion = getCloudAndRegion(cloud, region); + return fetch(`${config.apiUrl}/users/${userId}/networks/${planId}/actions/fork/${forkHost}${cloudAndRegion}`, util.postWithAuth()).then(util.handleCrudResponse(messages, errors)); +} + function getStatusesByNetworkId(userId, networkId, messages, errors) { return fetch(`${config.apiUrl}/users/${userId}/networks/${networkId}/actions/status`, util.getWithAuth()).then(util.handleCrudResponse(messages, errors)); } diff --git a/src/_store/networks.module.js b/src/_store/networks.module.js index 91dbcff..8446f93 100644 --- a/src/_store/networks.module.js +++ b/src/_store/networks.module.js @@ -45,11 +45,20 @@ const actions = { accountPlanService.newAccountPlan(userId, accountPlan, messages, errors) .then( plan => { - networkService.startNetwork(userId, plan.name, cloud, region, messages, errors) - .then( - newNodeNotification => commit('addPlanAndStartNetworkSuccess', newNodeNotification), - error => commit('addPlanSuccessStartNetworkFailure', error) - ); + if (accountPlan.forkHost && accountPlan.forkHost !== '') { + networkService.forkNetwork(userId, plan.name, accountPlan.forkHost, cloud, region, messages, errors) + .then( + newNodeNotification => commit('addPlanAndStartNetworkSuccess', newNodeNotification), + error => commit('addPlanSuccessStartNetworkFailure', error) + ); + + } else { + networkService.startNetwork(userId, plan.name, cloud, region, messages, errors) + .then( + newNodeNotification => commit('addPlanAndStartNetworkSuccess', newNodeNotification), + error => commit('addPlanSuccessStartNetworkFailure', error) + ); + } }, error => commit('addPlanFailure', error) ); diff --git a/src/_store/system.module.js b/src/_store/system.module.js index f9be5cd..542229d 100644 --- a/src/_store/system.module.js +++ b/src/_store/system.module.js @@ -151,10 +151,6 @@ const getters = { href: '/me', title: messages.label_menu_account, icon: messages.label_menu_account_icon - }, { - href: '/devices', - title: messages.label_menu_devices, - icon: messages.label_menu_devices_icon }, { href: '/notifications', title: messages.label_menu_notifications, @@ -170,6 +166,12 @@ const getters = { title: messages.label_menu_networks, icon: messages.label_menu_networks_icon }); + } else { + menu.splice(3, 0, { + href: '/devices', + title: messages.label_menu_devices, + icon: messages.label_menu_devices_icon + }); } if (configs.paymentsEnabled) { menu.splice(4, 0,{ diff --git a/src/account/NewNetworkPage.vue b/src/account/NewNetworkPage.vue index e5070b1..d9f580a 100644 --- a/src/account/NewNetworkPage.vue +++ b/src/account/NewNetworkPage.vue @@ -30,8 +30,32 @@
+ +
+ +
+ + +
+ +
+ + +
{{ errors.first('forkHost') }}
+ {{messages.field_description_network_fork_host}} +
+ +
+ + +
{{ errors.first('name') }}
+
+
-
+
{{ errors.first('name') }}
@@ -237,8 +261,10 @@ paymentMethodType: null, paymentInfo: null }, - sshKey: '' + sshKey: '', + forkHost: '' }, + networkType: 'bubble', cloudRegionUuid: null, regions: [], customize: { @@ -270,7 +296,7 @@ }; }, computed: { - ...mapState('system', ['messages', 'locales', 'timezones', 'detectedTimezone', 'detectedLocale']), + ...mapState('system', ['messages', 'locales', 'timezones', 'detectedTimezone', 'detectedLocale', 'configs']), ...mapState('domains', ['domains']), ...mapState('plans', ['plans']), ...mapState('footprints', ['footprints']),