2018-08-15 00:29:51 +00:00
|
|
|
import Controller from '@ember/controller';
|
|
|
|
import { computed } from '@ember/object';
|
|
|
|
import { task } from 'ember-concurrency';
|
2018-08-15 22:18:38 +00:00
|
|
|
import messageFromAdapterError from 'nomad-ui/utils/message-from-adapter-error';
|
|
|
|
import localStorageProperty from 'nomad-ui/utils/properties/local-storage';
|
2018-08-15 00:29:51 +00:00
|
|
|
|
|
|
|
export default Controller.extend({
|
2018-08-15 22:18:38 +00:00
|
|
|
parseError: null,
|
|
|
|
planError: null,
|
|
|
|
runError: null,
|
|
|
|
|
|
|
|
showPlanMessage: localStorageProperty('nomadMessageJobPlan', true),
|
|
|
|
showEditorMessage: localStorageProperty('nomadMessageJobEditor', true),
|
|
|
|
|
2018-08-15 00:29:51 +00:00
|
|
|
stage: computed('planOutput', function() {
|
|
|
|
return this.get('planOutput') ? 'plan' : 'editor';
|
|
|
|
}),
|
|
|
|
|
|
|
|
plan: task(function*() {
|
2018-08-15 22:18:38 +00:00
|
|
|
this.reset();
|
2018-08-15 00:29:51 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
yield this.get('model').parse();
|
|
|
|
} catch (err) {
|
2018-08-15 22:18:38 +00:00
|
|
|
const error = messageFromAdapterError(err) || 'Could not parse input';
|
|
|
|
this.set('parseError', error);
|
|
|
|
return;
|
2018-08-15 00:29:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
const planOutput = yield this.get('model').plan();
|
|
|
|
this.set('planOutput', planOutput);
|
|
|
|
} catch (err) {
|
2018-08-15 22:18:38 +00:00
|
|
|
const error = messageFromAdapterError(err) || 'Could not plan job';
|
|
|
|
this.set('planError', error);
|
2018-08-15 00:29:51 +00:00
|
|
|
}
|
|
|
|
}).drop(),
|
|
|
|
|
2018-08-15 01:26:26 +00:00
|
|
|
submit: task(function*() {
|
|
|
|
try {
|
|
|
|
yield this.get('model').run();
|
2018-08-15 22:18:38 +00:00
|
|
|
|
2018-08-15 01:26:26 +00:00
|
|
|
const id = this.get('model.plainId');
|
|
|
|
const namespace = this.get('model.namespace.name') || 'default';
|
2018-08-15 22:18:38 +00:00
|
|
|
|
|
|
|
this.reset();
|
|
|
|
|
2018-08-15 01:26:26 +00:00
|
|
|
// navigate to the new job page
|
|
|
|
this.transitionToRoute('jobs.job', id, {
|
|
|
|
queryParams: { jobNamespace: namespace },
|
|
|
|
});
|
|
|
|
} catch (err) {
|
2018-08-15 22:18:38 +00:00
|
|
|
const error = messageFromAdapterError(err) || 'Could not submit job';
|
|
|
|
this.set('runError', error);
|
2018-08-15 01:26:26 +00:00
|
|
|
}
|
|
|
|
}),
|
2018-08-15 00:29:51 +00:00
|
|
|
|
2018-08-15 22:18:38 +00:00
|
|
|
reset() {
|
2018-08-15 00:29:51 +00:00
|
|
|
this.set('planOutput', null);
|
|
|
|
this.set('planError', null);
|
|
|
|
this.set('parseError', null);
|
|
|
|
},
|
|
|
|
});
|