Skip to content

Commit

Permalink
fix: use new syntax for controller
Browse files Browse the repository at this point in the history
  • Loading branch information
adong committed Jun 27, 2024
1 parent 5de9eda commit 22544a5
Showing 1 changed file with 78 additions and 56 deletions.
134 changes: 78 additions & 56 deletions app/v2/pipeline/secrets/controller.js
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;
});
}
});
}

0 comments on commit 22544a5

Please sign in to comment.