Skip to content

Commit

Permalink
feat: add options to v2 route
Browse files Browse the repository at this point in the history
  • Loading branch information
adong committed Jul 2, 2024
1 parent d33d78e commit 65d694a
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 2 deletions.
42 changes: 42 additions & 0 deletions app/v2/pipeline/options/controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
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
});

this.set('isSaving', true);

pipeline
.save()
.then(() => this.set('errorMessage', ''))
.catch(err => {
this.set('errorMessage', err.errors[0].detail || '');
})
.finally(() => {
this.set('isSaving', false);
});
}
}
});
29 changes: 28 additions & 1 deletion app/v2/pipeline/options/route.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
// 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 { get } from '@ember/object';

export default Route.extend({
session: service(),
router: service(),
routeAfterAuthentication: 'pipeline.options',
model() {
// Guests should not access this page
if (get(this, 'session.data.authenticated.isGuest')) {
this.router.transitionTo('pipeline');
}

const { pipeline } = this.modelFor('v2.pipeline');

export default class NewPipelineOptionsRoute extends Route {}
// 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', '');
}
}
});
11 changes: 10 additions & 1 deletion app/v2/pipeline/options/template.hbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
{{page-title "Options"}}
<div class="pipeline-options">
<div>options content</div>
<PipelineOptions
class="padded-container"
@username={{this.session.data.authenticated.username}}
@pipeline={{this.pipeline}}
@jobs={{this.jobs}}
@errorMessage={{this.errorMessage}}
@onRemovePipeline={{action "removePipeline"}}
@isSaving={{this.isSaving}}
@onUpdatePipeline={{action "updatePipeline"}}
/>
{{outlet}}
</div>

0 comments on commit 65d694a

Please sign in to comment.