From 260a4ac5f91d6a759565ab2fffeaa4390c85cfcc Mon Sep 17 00:00:00 2001 From: Westly Wright Date: Tue, 30 Oct 2018 11:58:14 -0700 Subject: [PATCH] Sets the first added private reg as default --- .../cluster-driver/driver-rke/component.js | 8 ++++++ .../cru-private-registry/component.js | 9 ++++--- .../cru-private-registry/template.hbs | 1 + .../addon/components/input-url/component.js | 25 ++++++++++++++++--- translations/en-us.yaml | 1 + 5 files changed, 38 insertions(+), 6 deletions(-) diff --git a/lib/shared/addon/components/cluster-driver/driver-rke/component.js b/lib/shared/addon/components/cluster-driver/driver-rke/component.js index 1a6f59297..b113ccf23 100644 --- a/lib/shared/addon/components/cluster-driver/driver-rke/component.js +++ b/lib/shared/addon/components/cluster-driver/driver-rke/component.js @@ -603,6 +603,14 @@ export default InputTextFile.extend(ClusterDriver, { errors.push(get(this, 'intl').t('clusterNew.psp.required')); } + if (get(this, 'config.privateRegistries.length') >= 1) { + let hasDefault = get(this, 'config.privateRegistries').findBy('isDefault') || false; + + if (!hasDefault) { + errors.push(get(this, 'intl').t('cruPrivateRegistry.defaultError')); + } + } + const clusterOptErrors = get(this, 'clusterOptErrors') || []; set(this, 'errors', errors); diff --git a/lib/shared/addon/components/cru-private-registry/component.js b/lib/shared/addon/components/cru-private-registry/component.js index b9f2e7894..f2268de67 100644 --- a/lib/shared/addon/components/cru-private-registry/component.js +++ b/lib/shared/addon/components/cru-private-registry/component.js @@ -59,7 +59,7 @@ export default Component.extend({ const config = set(this, 'config', get(this, `cluster.${ get(this, 'configName') }`)); if (( config.privateRegistries || [] ).length <= 0) { - set(config, 'privateRegistries', [this.newPrivateRegistry()]); + set(config, 'privateRegistries', [this.newPrivateRegistry('privateRegistry', true)]); } }, @@ -82,7 +82,10 @@ export default Component.extend({ } })), - newPrivateRegistry(registryType = 'privateRegistry') { - return get(this, 'globalStore').createRecord({ type: registryType }); + newPrivateRegistry(registryType = 'privateRegistry', isDefault = false) { + return get(this, 'globalStore').createRecord({ + isDefault, + type: registryType, + }); } }); diff --git a/lib/shared/addon/components/cru-private-registry/template.hbs b/lib/shared/addon/components/cru-private-registry/template.hbs index c56ca0f9d..a62a65ace 100644 --- a/lib/shared/addon/components/cru-private-registry/template.hbs +++ b/lib/shared/addon/components/cru-private-registry/template.hbs @@ -22,6 +22,7 @@ urlWarning=(action (mut urlWarning)) urlError=(action (mut urlError)) value=reg.url + stripScheme=false }} {{/input-or-display}} diff --git a/lib/shared/addon/components/input-url/component.js b/lib/shared/addon/components/input-url/component.js index ac085b0b8..4af3b0cb8 100644 --- a/lib/shared/addon/components/input-url/component.js +++ b/lib/shared/addon/components/input-url/component.js @@ -22,13 +22,20 @@ export default TextField.extend({ type: 'url', classNameBindings: ['invalid:input-error'], invalid: false, + stripScheme: true, isInvalid: null, urlWarning: null, urlError: null, init() { this._super(...arguments); scheduleOnce('afterRender', () => { - let val = stripScheme(get(this, 'value') || ''); + let val = null; + + if (get(this, 'stripScheme')) { + val = stripScheme(get(this, 'element.value') || ''); + } else { + val = get(this, 'element.value') || ''; + } set(this, 'value', this.validateInput(val)); }); @@ -39,7 +46,13 @@ export default TextField.extend({ return; } - let val = stripScheme(get(this, 'element.value') || ''); + let val = null; + + if (get(this, 'stripScheme')) { + val = stripScheme(get(this, 'element.value') || ''); + } else { + val = get(this, 'element.value') || ''; + } debounce(this, 'validateInput', val, 250); @@ -49,7 +62,13 @@ export default TextField.extend({ focusOut() { this._super(...arguments); - let val = stripScheme(get(this, 'element.value')); + let val = null; + + if (get(this, 'stripScheme')) { + val = stripScheme(get(this, 'element.value') || ''); + } else { + val = get(this, 'element.value') || ''; + } set(this, 'value', this.validateInput(val)); }, diff --git a/translations/en-us.yaml b/translations/en-us.yaml index f0fad2b39..bb91af285 100644 --- a/translations/en-us.yaml +++ b/translations/en-us.yaml @@ -934,6 +934,7 @@ cruPrivateRegistry: label: Private Registries detail: Add private registries to this cluster noData: This cluster does not have any private registries defined + defaultError: You must designate one private registry as the default add: label: Add Private Registry registry: