github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/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 {
     7    watchRecord,
     8    watchRelationship,
     9  } from 'nomad-ui/utils/properties/watch';
    10  import classic from 'ember-classic-decorator';
    11  
    12  @classic
    13  export default class ExecRoute extends Route.extend(WithWatchers) {
    14    @service store;
    15    @service token;
    16  
    17    serialize(model) {
    18      return { job_name: model.get('plainId') };
    19    }
    20  
    21    model(params, transition) {
    22      const namespace = transition.to.queryParams.namespace;
    23      const name = params.job_name;
    24      const fullId = JSON.stringify([name, namespace || 'default']);
    25  
    26      const jobPromise = this.store
    27        .findRecord('job', fullId)
    28        .then((job) => {
    29          return job.get('allocations').then(() => job);
    30        })
    31        .catch(notifyError(this));
    32  
    33      const xtermImport = import('xterm').then((module) => module.Terminal);
    34  
    35      return Promise.all([jobPromise, xtermImport]);
    36    }
    37  
    38    setupController(controller, [job, Terminal]) {
    39      super.setupController(controller, job);
    40      controller.setUpTerminal(Terminal);
    41    }
    42  
    43    startWatchers(controller, model) {
    44      if (model) {
    45        controller.set('watcher', this.watch.perform(model));
    46        controller.set('watchAllocations', this.watchAllocations.perform(model));
    47      }
    48    }
    49  
    50    @watchRecord('job') watch;
    51    @watchRelationship('allocations') watchAllocations;
    52  
    53    @collect('watch', 'watchAllocations') watchers;
    54  }