github.com/manicqin/nomad@v0.9.5/ui/app/routes/jobs/job/task-group.js (about)

     1  import Route from '@ember/routing/route';
     2  import { collect } from '@ember/object/computed';
     3  import EmberError from '@ember/error';
     4  import { resolve } from 'rsvp';
     5  import { watchRecord, watchRelationship } from 'nomad-ui/utils/properties/watch';
     6  import WithWatchers from 'nomad-ui/mixins/with-watchers';
     7  import { qpBuilder } from 'nomad-ui/utils/classes/query-params';
     8  import notifyError from 'nomad-ui/utils/notify-error';
     9  
    10  export default Route.extend(WithWatchers, {
    11    breadcrumbs(model) {
    12      if (!model) return [];
    13      return [
    14        {
    15          label: model.get('name'),
    16          args: [
    17            'jobs.job.task-group',
    18            model.get('job'),
    19            model.get('name'),
    20            qpBuilder({ jobNamespace: model.get('job.namespace.name') || 'default' }),
    21          ],
    22        },
    23      ];
    24    },
    25  
    26    model({ name }) {
    27      const job = this.modelFor('jobs.job');
    28  
    29      // If there is no job, then there is no task group.
    30      // Let the job route handle the 404.
    31      if (!job) return;
    32  
    33      // If the job is a partial (from the list request) it won't have task
    34      // groups. Reload the job to ensure task groups are present.
    35      const reload = job.get('isPartial') ? job.reload() : resolve();
    36      return reload
    37        .then(() => {
    38          const taskGroup = job.get('taskGroups').findBy('name', name);
    39          if (!taskGroup) {
    40            const err = new EmberError(`Task group ${name} for job ${job.get('name')} not found`);
    41            err.code = '404';
    42            throw err;
    43          }
    44  
    45          // Refresh job allocations before-hand (so page sort works on load)
    46          return job
    47            .hasMany('allocations')
    48            .reload()
    49            .then(() => taskGroup);
    50        })
    51        .catch(notifyError(this));
    52    },
    53  
    54    startWatchers(controller, model) {
    55      if (model) {
    56        const job = model.get('job');
    57        controller.set('watchers', {
    58          job: this.watchJob.perform(job),
    59          summary: this.watchSummary.perform(job.get('summary')),
    60          allocations: this.watchAllocations.perform(job),
    61        });
    62      }
    63    },
    64  
    65    watchJob: watchRecord('job'),
    66    watchSummary: watchRecord('job-summary'),
    67    watchAllocations: watchRelationship('allocations'),
    68  
    69    watchers: collect('watchJob', 'watchSummary', 'watchAllocations'),
    70  });