Files
nomad/ui/app/controllers/jobs/run/templates/template.js
Phil Renaud f88e3b0125 [ui, helios] Toast Component (#16099)
* Template and styles

* @type to @color on flash messages

* Notifications service as wrapper

* Test cases updated for new notifs
2023-03-02 13:52:16 -05:00

74 lines
1.8 KiB
JavaScript

import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking';
import { task } from 'ember-concurrency';
export default class JobsRunTemplatesController extends Controller {
@service notifications;
@service router;
@service system;
@tracked formModalActive = false;
@action
updateKeyValue(key, value) {
if (this.model.keyValues.find((kv) => kv.key === key)) {
this.model.keyValues.find((kv) => kv.key === key).value = value;
} else {
this.model.keyValues.pushObject({ key, value });
}
}
@action
toggleModal() {
this.formModalActive = !this.formModalActive;
}
@action
async save(e, overwrite = false) {
if (e.type === 'submit') {
e.preventDefault();
}
try {
await this.model.save({ adapterOptions: { overwrite } });
this.notifications.add({
title: 'Job template saved',
message: `${this.model.path} successfully editted`,
color: 'success',
});
this.router.transitionTo('jobs.run.templates');
} catch (e) {
this.notifications.add({
title: 'Job template cannot be editted.',
message: e,
color: 'critical',
});
}
}
@task(function* () {
try {
yield this.model.destroyRecord();
this.notifications.add({
title: 'Job template deleted',
message: `${this.model.path} successfully deleted`,
color: 'success',
});
this.router.transitionTo('jobs.run.templates.manage');
} catch (err) {
this.notifications.add({
title: `Job template could not be deleted.`,
message: err,
color: 'critical',
sticky: true,
});
}
})
deleteTemplate;
}