From d88048fcfec07cc1a92ba8c598b5fbd88b8d5eb6 Mon Sep 17 00:00:00 2001 From: Jonathan Cobb Date: Tue, 7 Jan 2020 20:52:03 -0500 Subject: [PATCH] fix nearest region control --- src/_services/network.service.js | 3 ++- src/account/NewNetworkPage.vue | 40 +++++++++++++++++--------------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/_services/network.service.js b/src/_services/network.service.js index be8e676..91a2e4c 100644 --- a/src/_services/network.service.js +++ b/src/_services/network.service.js @@ -3,7 +3,8 @@ import { util } from '../_helpers'; export const networkService = { getAll, - getById + getById, + getNearestRegions }; function getAll(userId, messages, errors) { diff --git a/src/account/NewNetworkPage.vue b/src/account/NewNetworkPage.vue index b28f39d..cf7f8d1 100644 --- a/src/account/NewNetworkPage.vue +++ b/src/account/NewNetworkPage.vue @@ -103,13 +103,15 @@
- +
{{ errors.first('region') }}
{{messages.field_label_region}}: - {{defaults.region.name}} + {{defaults.region.name}} (~{{parseInt(defaults.region.distance/1000)}} {{messages.msg_km_distance_away}})
@@ -183,6 +185,7 @@ locale: '', timezone: '', plan: 'bubble', + region: '', footprint: 'Worldwide', paymentMethodObject: { paymentMethodType: null, @@ -190,6 +193,7 @@ } }, cloudRegion: '', + regions: [], customize: { domain: false, locale: false, @@ -200,7 +204,7 @@ }, defaults: { domain: '', - locale: '', + locale: 'en_US', timezone: '', plan: 'bubble', footprint: 'Worldwide', @@ -273,19 +277,6 @@ } } return fp_array; - }, - regionObjects: function () { - const regions_array = []; - if (this.footprints) { - for (let i = 0; i < this.footprints.length; i++) { - fp_array.push({ - ...this.footprints[i], - localName: this.messages['footprint_name_' + this.footprints[i].name], - description: this.messages['footprint_description_' + this.footprints[i].name] - }) - } - } - return regions_array; } }, methods: { @@ -311,13 +302,15 @@ setPaymentMethod: 'setPaymentMethod' }), initDefaults() { - this.getPolicyByUuid({uuid: util.currentUser().uuid, messages: this.messages, errors: this.errors}); + const currentUser = util.currentUser(); + this.getPolicyByUuid({uuid: currentUser.uuid, messages: this.messages, errors: this.errors}); this.detectTimezone(); this.detectLocale(); - this.loadDomains(util.currentUser().uuid, this.messages, this.errors); + this.loadDomains(currentUser.uuid, this.messages, this.errors); 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); }, isAuthenticator(val) { return window.isAuthenticator(val); }, isNotAuthenticator(val) { return window.isNotAuthenticator(val); }, @@ -380,6 +373,9 @@ tzDescription(tz) { return this.messages['tz_name_'+tz] + " - " + this.messages['tz_description_'+tz] }, + regionId(region) { + return region.cloud+':'+region.internalName; + }, handleSubmit(e) { this.submitted = true; this.$validator.validate().then(valid => { @@ -400,7 +396,6 @@ if (doms && doms[0]) { if (this.network.domain == null || this.network.domain === '') this.network.domain = doms[0].name; this.defaults.domain = doms[0].name; - console.log('watch.domains, set this.defaults.domain='+this.defaults.domain); } }, detectedTimezone (tz) { @@ -415,6 +410,13 @@ this.defaults.locale = loc; } }, + nearestRegions (regions) { + if (regions) { + this.regions = regions; + if (this.network.region === '') this.network.region = this.regionId(regions[0]); + if (this.defaults.region === '') this.defaults.region = regions[0]; + } + }, paymentMethod (pm) { if (pm) { this.network.paymentMethodObject.paymentMethodType = pm.paymentMethodType;