diff --git a/lib/pipeline/addon/components/input-image/component.js b/lib/pipeline/addon/components/input-image/component.js index 25b562c6e..659c2788b 100644 --- a/lib/pipeline/addon/components/input-image/component.js +++ b/lib/pipeline/addon/components/input-image/component.js @@ -4,6 +4,7 @@ import { observer } from '@ember/object'; import {analyzeImageRepo} from 'pipeline/utils/pipelineStep'; import layout from './template'; import { inject as service } from '@ember/service'; +import { set, get } from '@ember/object'; export default Component.extend({ layout, @@ -25,6 +26,8 @@ export default Component.extend({ imageTag: '', registryExist: true, savingRegistry: false, + selectedRegistry: null, + noEditingRegistry: true, }, init(){ this._super(...arguments); @@ -45,7 +48,8 @@ export default Component.extend({ let registry = Object.keys(ele.registries)[0]; return { label: registry, - value: registry + value: registry, + username: ele.registries[registry].username } })); })), @@ -67,7 +71,9 @@ export default Component.extend({ }), observerRegistry: on('init', observer('state.imageRegistry','state.registries.[]',function(){ let state = this.get('state'); - if(state.registries.find(ele=>state.imageRegistry===ele.value)){ + let selectedRegistry = state.registries.find(ele=>state.imageRegistry===ele.value); + if(selectedRegistry){ + set(this, 'state.selectedRegistry', selectedRegistry); this.set('state.registryExist',true); this.set('modalState.saveDisabled', false); }else{ @@ -76,20 +82,64 @@ export default Component.extend({ } })), actions: { + setState(state, val){ + set(this, `${state}`, val); + let username = get(this, 'state.selectedRegistry.username'); + if(state === 'state.noEditingRegistry'){ + set(this, 'state.username', val?'':username); + } + }, saveRegistry(){ let state = this.get('state'); + let noEditing = get(this, 'state.noEditingRegistry'); this.set('state.savingRegistry', true); - this.get('store').createRecord({ - type: 'dockerCredential', - registries: { - [`${state.imageRegistry}`]: { - username: state.username, - password: state.password, + if(noEditing){ + this.get('store').createRecord({ + type: 'dockerCredential', + registries: { + [`${state.imageRegistry}`]: { + username: state.username, + password: state.password, + } } + }).save().finally(()=>{ + this.set('state.savingRegistry', false); + }); + }else{ + let registries = this.get('registries'); + let selectedRegistry = get(this, 'state.selectedRegistry'); + let selectedOriginRegistry = registries.find(ele => { + return ele.registries[selectedRegistry.value]; + }); + if(!selectedOriginRegistry){ + return; } - }).save().finally(()=>{ - this.set('state.savingRegistry', false); - }); + let serilizedRegistry = selectedOriginRegistry.serialize(); + this.get('store').createRecord( + Object.assign({},serilizedRegistry,{ + registries: { + [`${state.imageRegistry}`]: { + username: state.username, + password: state.password, + } + } + }) + ) + .save().then((registry)=>{ + let registries = get(this, 'state.registries'); + set(this, 'state.registries', registries.map(ele=>{ + if(ele.value = state.imageRegistry){ + return Object.assign({}, ele, { + username: state.username + }); + } + return ele; + })) + }).finally(()=>{ + this.set('state.savingRegistry', false); + set(this, 'state.noEditingRegistry', true); + }); + } } } }); diff --git a/lib/pipeline/addon/components/input-image/template.hbs b/lib/pipeline/addon/components/input-image/template.hbs index b117b37cb..07142007a 100644 --- a/lib/pipeline/addon/components/input-image/template.hbs +++ b/lib/pipeline/addon/components/input-image/template.hbs @@ -16,10 +16,17 @@ {{input class="form-control" value=state.imageTag disabled=disabled}} {{#if registryField}} - {{#if state.registryExist}} - {{banner-message icon="icon-success" color='bg-success mb-0 mt-10' message=(concat "Registry " state.imageRegistry " exists")}} + {{#if (and state.registryExist state.noEditingRegistry)}} + {{#banner-message icon="icon-success" color='bg-success mb-0 mt-10'}} + {{t 'newPipelineStep.stepType.build.registryExist' registry=state.imageRegistry username=state.selectedRegistry.username}} + + {{/banner-message}} {{else}} - {{banner-message color='bg-warning mb-0 mt-10' message=(concat "Please add registry " state.imageRegistry " first")}} + {{#if state.noEditingRegistry}} + {{banner-message color='bg-warning mb-0 mt-10' message=(concat "Please add registry " state.imageRegistry " first")}} + {{else}} + {{banner-message color='bg-info mb-0 mt-10' message=(concat "Edit registry " state.imageRegistry)}} + {{/if}}

{{t 'newPipelineStep.stepType.build.scope'}}

{{t 'registriesPage.new.form.custom.labelText'}}: {{state.imageRegistry}}

@@ -27,7 +34,7 @@
- {{input class="form-control" value=state.username}} + {{input class="form-control" autofocus=true value=state.username}}
@@ -41,6 +48,11 @@ {{/if}} {{t 'newPipeline.save'}} + {{#unless state.noEditingRegistry}} + + {{/unless}}
diff --git a/lib/pipeline/translations/en-us.yaml b/lib/pipeline/translations/en-us.yaml index 6c3822cb9..a836c3241 100644 --- a/lib/pipeline/translations/en-us.yaml +++ b/lib/pipeline/translations/en-us.yaml @@ -180,6 +180,7 @@ newPipelineStep: pushWarning2: haven't been authenticated, click pushWarning3: to authenticate it. scope: "Scope: Available to all namespaces in this project" + registryExist: Registry {registry} registered with {username} task: label: run a script runAsService: Run As a Service diff --git a/lib/shared/addon/components/container/form-scale/component.js b/lib/shared/addon/components/container/form-scale/component.js index ec75caeef..ba148db0c 100644 --- a/lib/shared/addon/components/container/form-scale/component.js +++ b/lib/shared/addon/components/container/form-scale/component.js @@ -32,7 +32,7 @@ const DEFAULT_CONFIG = { schedule: '0 * * * *', successfulJobsHistoryLimit: HISTORY_LIMIT, }, - jobConfig: { + job: { type: 'jobConfig', }, }; diff --git a/lib/shared/addon/components/container/form-scale/template.hbs b/lib/shared/addon/components/container/form-scale/template.hbs index ca21dfe6e..5a0ff6044 100644 --- a/lib/shared/addon/components/container/form-scale/template.hbs +++ b/lib/shared/addon/components/container/form-scale/template.hbs @@ -56,6 +56,13 @@

{{pretty-cron workload.cronJobConfig.schedule 'toString'}}

{{/if}} +
+ +
{{else}}
{{#if (eq scaleMode "deployment")}}