github.com/hernad/nomad@v1.6.112/ui/app/routes/exec.js (about) 1 /** 2 * Copyright (c) HashiCorp, Inc. 3 * SPDX-License-Identifier: MPL-2.0 4 */ 5 6 import { inject as service } from '@ember/service'; 7 import Route from '@ember/routing/route'; 8 import notifyError from 'nomad-ui/utils/notify-error'; 9 import { collect } from '@ember/object/computed'; 10 import WithWatchers from 'nomad-ui/mixins/with-watchers'; 11 import { 12 watchRecord, 13 watchRelationship, 14 } from 'nomad-ui/utils/properties/watch'; 15 import classic from 'ember-classic-decorator'; 16 17 @classic 18 export default class ExecRoute extends Route.extend(WithWatchers) { 19 @service store; 20 @service token; 21 22 serialize(model) { 23 return { job_name: model.get('plainId') }; 24 } 25 26 model(params, transition) { 27 const namespace = transition.to.queryParams.namespace; 28 const name = params.job_name; 29 const fullId = JSON.stringify([name, namespace || 'default']); 30 31 const jobPromise = this.store 32 .findRecord('job', fullId) 33 .then((job) => { 34 return job.get('allocations').then(() => job); 35 }) 36 .catch(notifyError(this)); 37 38 const xtermImport = import('xterm').then((module) => module.Terminal); 39 40 return Promise.all([jobPromise, xtermImport]); 41 } 42 43 setupController(controller, [job, Terminal]) { 44 super.setupController(controller, job); 45 controller.setUpTerminal(Terminal); 46 } 47 48 startWatchers(controller, model) { 49 if (model) { 50 controller.set('watcher', this.watch.perform(model)); 51 controller.set('watchAllocations', this.watchAllocations.perform(model)); 52 } 53 } 54 55 @watchRecord('job') watch; 56 @watchRelationship('allocations') watchAllocations; 57 58 @collect('watch', 'watchAllocations') watchers; 59 }