open-nomad/ui/app/routes/exec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

55 lines
1.5 KiB
JavaScript
Raw Normal View History

import { inject as service } from '@ember/service';
import Route from '@ember/routing/route';
import notifyError from 'nomad-ui/utils/notify-error';
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';
import classic from 'ember-classic-decorator';
@classic
export default class ExecRoute extends Route.extend(WithWatchers) {
@service store;
@service token;
serialize(model) {
return { job_name: model.get('plainId') };
}
model(params, transition) {
const namespace = transition.to.queryParams.namespace;
const name = params.job_name;
const fullId = JSON.stringify([name, namespace || 'default']);
const jobPromise = this.store
.findRecord('job', fullId)
2021-12-28 14:45:20 +00:00
.then((job) => {
return job.get('allocations').then(() => job);
})
.catch(notifyError(this));
2021-12-28 14:45:20 +00:00
const xtermImport = import('xterm').then((module) => module.Terminal);
return Promise.all([jobPromise, xtermImport]);
}
setupController(controller, [job, Terminal]) {
super.setupController(controller, job);
controller.setUpTerminal(Terminal);
}
startWatchers(controller, model) {
if (model) {
controller.set('watcher', this.watch.perform(model));
controller.set('watchAllocations', this.watchAllocations.perform(model));
}
}
@watchRecord('job') watch;
@watchRelationship('allocations') watchAllocations;
@collect('watch', 'watchAllocations') watchers;
}