-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use newer syntax without ember data
- Loading branch information
Showing
7 changed files
with
126 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 }; | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,5 +10,4 @@ | |
@isSaving={{this.isSaving}} | ||
@onUpdatePipeline={{action "updatePipeline"}} | ||
/> | ||
{{outlet}} | ||
</div> |