github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/ui/app/routes/exec.js (about)

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