-
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.
- Loading branch information
Showing
1 changed file
with
78 additions
and
56 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,87 @@ | ||
import Controller from '@ember/controller'; | ||
import { reads } from '@ember/object/computed'; | ||
import { inject as service } from '@ember/service'; | ||
import { service } from '@ember/service'; | ||
import { action } from '@ember/object'; | ||
import { tracked } from '@glimmer/tracking'; | ||
|
||
export default Controller.extend({ | ||
store: service(), | ||
session: service(), | ||
errorMessage: '', | ||
pipeline: reads('model.pipeline'), | ||
secrets: reads('model.secrets'), | ||
pipelineTokens: reads('model.tokens'), | ||
pipelineId: reads('model.pipeline.id'), | ||
newToken: null, | ||
refreshService: service('pipeline.secrets'), | ||
actions: { | ||
createSecret(name, value, pipelineId, allowInPR) { | ||
const newSecret = this.store.createRecord('secret', { | ||
name, | ||
value, | ||
pipelineId, | ||
allowInPR | ||
}); | ||
export default class NewPipelineController extends Controller { | ||
@service store; | ||
|
||
@service session; | ||
|
||
@service('pipeline.secrets') | ||
refreshService; | ||
|
||
@tracked newToken = ''; | ||
|
||
@tracked newToken = null; | ||
|
||
get pipeline() { | ||
return this.model.pipeline; | ||
} | ||
|
||
get secrets() { | ||
return this.model.secrets; | ||
} | ||
|
||
get pipelineTokens() { | ||
return this.model.tokens; | ||
} | ||
|
||
get pipelineId() { | ||
return this.model.pipeline.id; | ||
} | ||
|
||
@action | ||
createSecret(name, value, pipelineId, allowInPR) { | ||
const newSecret = this.store.createRecord('secret', { | ||
name, | ||
value, | ||
pipelineId, | ||
allowInPR | ||
}); | ||
|
||
return newSecret.save().then( | ||
s => { | ||
this.errorMessage = ''; | ||
this.secrets.reload(); | ||
|
||
return newSecret.save().then( | ||
s => { | ||
this.set('errorMessage', ''); | ||
this.secrets.reload(); | ||
return s; | ||
}, | ||
err => { | ||
this.errorMessage = err.errors[0].detail; | ||
} | ||
); | ||
} | ||
|
||
@action | ||
createPipelineToken(name, description) { | ||
const newToken = this.store.createRecord('token', { | ||
name, | ||
description: description || '', | ||
action: 'created' | ||
}); | ||
|
||
return s; | ||
return newToken | ||
.save({ adapterOptions: { pipelineId: this.pipelineId } }) | ||
.then( | ||
token => { | ||
this.newToken = token; | ||
}, | ||
err => { | ||
this.set('errorMessage', err.errors[0].detail); | ||
error => { | ||
newToken.destroyRecord({ | ||
adapterOptions: { pipelineId: this.pipelineId } | ||
}); | ||
throw error; | ||
} | ||
); | ||
}, | ||
createPipelineToken(name, description) { | ||
const newToken = this.store.createRecord('token', { | ||
name, | ||
description: description || '', | ||
action: 'created' | ||
}); | ||
} | ||
|
||
return newToken | ||
.save({ adapterOptions: { pipelineId: this.pipelineId } }) | ||
.then( | ||
token => { | ||
this.set('newToken', token); | ||
}, | ||
error => { | ||
newToken.destroyRecord({ | ||
adapterOptions: { pipelineId: this.pipelineId } | ||
}); | ||
throw error; | ||
} | ||
); | ||
}, | ||
refreshPipelineToken(tokenId) { | ||
return this.refreshService | ||
.refreshPipelineToken(this.pipelineId, tokenId) | ||
.then(token => { | ||
this.set('newToken', token); | ||
}); | ||
} | ||
@action | ||
refreshPipelineToken(tokenId) { | ||
return this.refreshService | ||
.refreshPipelineToken(this.pipelineId, tokenId) | ||
.then(token => { | ||
this.newToken = token; | ||
}); | ||
} | ||
}); | ||
} |