open-nomad/ui/app/controllers/jobs/job/versions.js
Buck Doyle 90ecbdf522
Add job version revert buttons (#10336)
This adds a Revert two-step button to the JobVersions component for
not-current versions, which redirects to the overview on success. It
checks the job version before and after reversion to mitigate the edge
case where reverting to an otherwise-identical version has no effect, as
discussed in #10337.

It uses existing facilities for handling other errors and disabling the
button when permissions are lacking.
2021-04-20 08:33:16 -05:00

34 lines
803 B
JavaScript

import Controller from '@ember/controller';
import WithNamespaceResetting from 'nomad-ui/mixins/with-namespace-resetting';
import { alias } from '@ember/object/computed';
import { action, computed } from '@ember/object';
import classic from 'ember-classic-decorator';
const alertClassFallback = 'is-info';
const errorLevelToAlertClass = {
danger: 'is-danger',
warn: 'is-warning',
};
@classic
export default class VersionsController extends Controller.extend(WithNamespaceResetting) {
error = null;
@alias('model') job;
@computed('error.level')
get errorLevelClass() {
return errorLevelToAlertClass[this.get('error.level')] || alertClassFallback;
}
onDismiss() {
this.set('error', null);
}
@action
handleError(errorObject) {
this.set('error', errorObject);
}
}