diff --git a/app/components/secret-view/component.js b/app/components/secret-view/component.js index 96f7ee98e..8a3f78d42 100644 --- a/app/components/secret-view/component.js +++ b/app/components/secret-view/component.js @@ -1,4 +1,4 @@ -import { computed } from '@ember/object'; +import { computed, get } from '@ember/object'; import Component from '@ember/component'; export default Component.extend({ @@ -10,8 +10,8 @@ export default Component.extend({ get() { const { secret, pipeline } = this; - if (pipeline.get('configPipelineId')) { - if (secret.get('pipelineId') === pipeline.get('configPipelineId')) { + if (get(pipeline, 'configPipelineId')) { + if (get(secret, 'pipelineId') === get(pipeline, 'configPipelineId')) { return 'Override'; } @@ -31,7 +31,7 @@ export default Component.extend({ get() { const { secret, pipeline } = this; - if (secret.get('pipelineId') === pipeline.get('configPipelineId')) { + if (get(secret, 'pipelineId') === get(pipeline, 'configPipelineId')) { return 'Inherited from parent pipeline'; } @@ -57,14 +57,14 @@ export default Component.extend({ } secret.save(); this.set('newValue', null); - this.set('originalAllowInPR', secret.get('allowInPR')); + this.set('originalAllowInPR', get(secret, 'allowInPR')); } else if (this.newValue) { // Create child pipeline secret to override inherited secret of same name return this.onCreateSecret( - secret.get('name'), + get(secret, 'name'), this.newValue, this.get('pipeline.id'), - secret.get('allowInPR') + get(secret, 'allowInPR') ); } diff --git a/app/components/token-view/component.js b/app/components/token-view/component.js index a49b75bed..609ffe7e2 100644 --- a/app/components/token-view/component.js +++ b/app/components/token-view/component.js @@ -1,4 +1,4 @@ -import { computed } from '@ember/object'; +import { computed, get } from '@ember/object'; import Component from '@ember/component'; export default Component.extend({ @@ -14,8 +14,8 @@ export default Component.extend({ get() { const { token } = this; - return this.newName !== token.get('name') || - this.newDescription !== token.get('description') + return this.newName !== get(token, 'name') || + this.newDescription !== get(token, 'description') ? 'Update' : 'Delete'; } diff --git a/app/pipeline/service.js b/app/pipeline/service.js index c87455110..fcd59882c 100644 --- a/app/pipeline/service.js +++ b/app/pipeline/service.js @@ -42,14 +42,21 @@ export default Service.extend({ // No preferences for the pipeline exist, so we will create the default set. // Note: the newly created preferences for this pipeline are not saved back on the server as they are just default settings. // When a user changes the options in the options view of the pipeline, then the settings are saved. - const pipelinePreference = await this.store.createRecord( + let pipelinePreference = await this.store.peekRecord( 'preference/pipeline', - { - id: pipelineId, - ...pipelinePreferences - } + `${pipelineId}` ); + if (pipelinePreference === null) { + pipelinePreference = await this.store.createRecord( + 'preference/pipeline', + { + id: pipelineId, + ...pipelinePreferences + } + ); + } + return pipelinePreference; } }); diff --git a/app/shuttle/service.js b/app/shuttle/service.js index ba49942a1..a4cf86f84 100644 --- a/app/shuttle/service.js +++ b/app/shuttle/service.js @@ -353,6 +353,14 @@ export default Service.extend({ const method = 'get'; const url = `/pipelines/${pipelineId}/stages`; + return this.fetchFromApi(method, url); + }, + + // GET /pipelines/{id}/jobs + async fetchJobs(pipelineId) { + const method = 'get'; + const url = `/pipelines/${pipelineId}/jobs`; + return this.fetchFromApi(method, url); } }); diff --git a/app/v2/pipeline/options/controller.js b/app/v2/pipeline/options/controller.js index b6f914d30..56e352fab 100644 --- a/app/v2/pipeline/options/controller.js +++ b/app/v2/pipeline/options/controller.js @@ -1,42 +1,68 @@ import Controller from '@ember/controller'; -import { reads } from '@ember/object/computed'; -import { inject as service } from '@ember/service'; - -export default Controller.extend({ - session: service(), - router: service(), - errorMessage: '', - isSaving: false, - pipeline: reads('model.pipeline'), - jobs: reads('model.jobs'), - actions: { - removePipeline() { - this.pipeline - .destroyRecord() - .then(() => { - this.router.transitionTo('home'); - }) - .catch(error => this.set('errorMessage', error.errors[0].detail || '')); - }, - updatePipeline({ scmUrl, rootDir }) { - const { pipeline } = this; - - pipeline.setProperties({ - checkoutUrl: scmUrl, - rootDir +import { service } from '@ember/service'; +import { action } from '@ember/object'; + +export default class PipelineOptionsController extends Controller { + @service session; + + @service router; + + errorMessage = ''; + + isSaving = false; + + get pipeline() { + return this.model.pipeline; + } + + get jobs() { + return this.model.jobs; + } + + @action + async removePipeline() { + const currentPipeline = await this.store.findRecord( + 'pipeline', + this.pipeilne.id + ); + + currentPipeline + .destroyRecord() + .then(() => { + this.router.transitionTo('home'); + }) + .catch(err => { + this.errorMessage = err.errors[0].detail || ''; }); + } + + @action + async updatePipeline({ scmUrl, rootDir }) { + const { pipeline } = this; - this.set('isSaving', true); - - pipeline - .save() - .then(() => this.set('errorMessage', '')) - .catch(err => { - this.set('errorMessage', err.errors[0].detail || ''); - }) - .finally(() => { - this.set('isSaving', false); - }); - } + pipeline.setProperties({ + checkoutUrl: scmUrl, + rootDir + }); + this.isSaving = true; + + const currentPipeline = await this.store.findRecord( + 'pipeline', + this.pipeline.id + ); + + currentPipeline.setProperties({ + ...pipeline + }); + + currentPipeline + .save() + .then(() => (this.errorMessage = '')) + .catch(err => { + this.errorMessage = err.errors[0].detail || ''; + }) + .finally(() => { + this.isSaving = false; + }); } -}); +} diff --git a/app/v2/pipeline/options/route.js b/app/v2/pipeline/options/route.js index c1916f95e..a23dc7dc2 100644 --- a/app/v2/pipeline/options/route.js +++ b/app/v2/pipeline/options/route.js @@ -1,30 +1,45 @@ -// import Route from '@ember/routing/route'; - -// export default class NewPipelineOptionsRoute extends Route {} - import Route from '@ember/routing/route'; -import { inject as service } from '@ember/service'; +import { service } from '@ember/service'; import { get } from '@ember/object'; -export default Route.extend({ - session: service(), - router: service(), - routeAfterAuthentication: 'pipeline.options', - model() { +export default class PipelineOptionsRoute extends Route { + @service session; + + @service router; + + @service shuttle; + + constructor() { + super(...arguments); + // Reset error message when switching pages + this.router.on('routeWillChange', (/* transition */) => { + const pipelineOptionsController = this.controllerFor( + 'v2.pipeline.options' + ); + + pipelineOptionsController.set('errorMessage', ''); + }); + } + + async model() { // Guests should not access this page if (get(this, 'session.data.authenticated.isGuest')) { this.router.transitionTo('pipeline'); } const { pipeline } = this.modelFor('v2.pipeline'); + const pipelineId = pipeline.id; + let jobs = []; // Prevent double render when jobs list updates asynchronously - return pipeline.get('jobs').then(jobs => ({ pipeline, jobs })); - }, - actions: { - willTransition() { - // Reset error message when switching pages - this.controller.set('errorMessage', ''); + + try { + jobs = await this.shuttle.fetchJobs(pipelineId); + } catch (e) { + // eslint-disable-next-line no-console + console.error(e); } + + return { pipeline, jobs }; } -}); +} diff --git a/app/v2/pipeline/options/template.hbs b/app/v2/pipeline/options/template.hbs index 8cf3a34fe..783bdd547 100644 --- a/app/v2/pipeline/options/template.hbs +++ b/app/v2/pipeline/options/template.hbs @@ -10,5 +10,4 @@ @isSaving={{this.isSaving}} @onUpdatePipeline={{action "updatePipeline"}} /> - {{outlet}}