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';
|
2021-12-28 16:08:12 +00:00
|
|
|
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) {
|
2021-04-29 20:00:59 +00:00
|
|
|
const namespace = transition.to.queryParams.namespace;
|
2020-03-24 23:22:16 +00:00
|
|
|
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)
|
2021-12-28 14:45:20 +00:00
|
|
|
.then((job) => {
|
2020-03-24 23:22:16 +00:00
|
|
|
return job.get('allocations').then(() => job);
|
|
|
|
})
|
|
|
|
.catch(notifyError(this));
|
2020-05-26 14:56:25 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
const xtermImport = import('xterm').then((module) => module.Terminal);
|
2020-05-26 14:56:25 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|