2020-03-24 23:22:16 +00:00
|
|
|
import { inject as service } from '@ember/service';
|
|
|
|
import Route from '@ember/routing/route';
|
|
|
|
import notifyError from 'nomad-ui/utils/notify-error';
|
2020-04-06 18:52:42 +00:00
|
|
|
import { collect } from '@ember/object/computed';
|
|
|
|
import WithWatchers from 'nomad-ui/mixins/with-watchers';
|
|
|
|
import { watchRecord, watchRelationship } from 'nomad-ui/utils/properties/watch';
|
2020-06-11 21:23:00 +00:00
|
|
|
import classic from 'ember-classic-decorator';
|
2020-03-24 23:22:16 +00:00
|
|
|
|
2020-06-11 21:23:00 +00:00
|
|
|
@classic
|
|
|
|
export default class ExecRoute extends Route.extend(WithWatchers) {
|
|
|
|
@service store;
|
|
|
|
@service token;
|
2020-03-24 23:22:16 +00:00
|
|
|
|
|
|
|
serialize(model) {
|
|
|
|
return { job_name: model.get('plainId') };
|
2020-06-11 21:23:00 +00:00
|
|
|
}
|
2020-03-24 23:22:16 +00:00
|
|
|
|
|
|
|
model(params, transition) {
|
|
|
|
const namespace = transition.to.queryParams.namespace || this.get('system.activeNamespace.id');
|
|
|
|
const name = params.job_name;
|
|
|
|
const fullId = JSON.stringify([name, namespace || 'default']);
|
2020-05-26 14:56:25 +00:00
|
|
|
|
|
|
|
const jobPromise = this.store
|
2020-04-06 18:52:42 +00:00
|
|
|
.findRecord('job', fullId)
|
2020-03-24 23:22:16 +00:00
|
|
|
.then(job => {
|
|
|
|
return job.get('allocations').then(() => job);
|
|
|
|
})
|
|
|
|
.catch(notifyError(this));
|
2020-05-26 14:56:25 +00:00
|
|
|
|
|
|
|
const xtermImport = import('xterm').then(module => module.Terminal);
|
|
|
|
|
|
|
|
return Promise.all([jobPromise, xtermImport]);
|
2020-06-11 21:23:00 +00:00
|
|
|
}
|
2020-05-26 14:56:25 +00:00
|
|
|
|
|
|
|
setupController(controller, [job, Terminal]) {
|
2020-06-11 21:23:00 +00:00
|
|
|
super.setupController(controller, job);
|
2020-05-26 14:56:25 +00:00
|
|
|
controller.setUpTerminal(Terminal);
|
2020-06-11 21:23:00 +00:00
|
|
|
}
|
2020-04-06 18:52:42 +00:00
|
|
|
|
|
|
|
startWatchers(controller, model) {
|
|
|
|
if (model) {
|
|
|
|
controller.set('watcher', this.watch.perform(model));
|
|
|
|
controller.set('watchAllocations', this.watchAllocations.perform(model));
|
|
|
|
}
|
2020-06-11 21:23:00 +00:00
|
|
|
}
|
2020-04-06 18:52:42 +00:00
|
|
|
|
2020-06-11 21:23:00 +00:00
|
|
|
@watchRecord('job') watch;
|
|
|
|
@watchRelationship('allocations') watchAllocations;
|
2020-04-06 18:52:42 +00:00
|
|
|
|
2020-06-11 21:23:00 +00:00
|
|
|
@collect('watch', 'watchAllocations') watchers;
|
|
|
|
}
|