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-03-24 23:22:16 +00:00
|
|
|
|
2020-04-06 18:52:42 +00:00
|
|
|
export default Route.extend(WithWatchers, {
|
2020-03-24 23:22:16 +00:00
|
|
|
store: service(),
|
|
|
|
token: service(),
|
|
|
|
|
|
|
|
serialize(model) {
|
|
|
|
return { job_name: model.get('plainId') };
|
|
|
|
},
|
|
|
|
|
|
|
|
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]);
|
|
|
|
},
|
|
|
|
|
|
|
|
setupController(controller, [job, Terminal]) {
|
|
|
|
this._super(controller, job);
|
|
|
|
controller.setUpTerminal(Terminal);
|
2020-03-24 23:22:16 +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));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
watch: watchRecord('job'),
|
|
|
|
watchAllocations: watchRelationship('allocations'),
|
|
|
|
|
|
|
|
watchers: collect('watch', 'watchAllocations'),
|
2020-03-24 23:22:16 +00:00
|
|
|
});
|