github.com/hernad/nomad@v1.6.112/ui/app/routes/jobs/job/index.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 { collect } from '@ember/object/computed';
     9  import {
    10    watchRecord,
    11    watchRelationship,
    12    watchAll,
    13    watchQuery,
    14  } from 'nomad-ui/utils/properties/watch';
    15  import WithWatchers from 'nomad-ui/mixins/with-watchers';
    16  
    17  export default class IndexRoute extends Route.extend(WithWatchers) {
    18    @service can;
    19    @service store;
    20  
    21    async model() {
    22      return this.modelFor('jobs.job');
    23    }
    24  
    25    startWatchers(controller, model) {
    26      if (!model) {
    27        return;
    28      }
    29      controller.set('watchers', {
    30        summary: this.watchSummary.perform(model.get('summary')),
    31        allocations: this.watchAllocations.perform(model),
    32        evaluations: this.watchEvaluations.perform(model),
    33        latestDeployment:
    34          model.get('supportsDeployments') &&
    35          this.watchLatestDeployment.perform(model),
    36        list:
    37          model.get('hasChildren') &&
    38          this.watchAllJobs.perform({
    39            namespace: model.namespace.get('name'),
    40            meta: true,
    41          }),
    42        nodes:
    43          model.get('hasClientStatus') &&
    44          this.can.can('read client') &&
    45          this.watchNodes.perform(),
    46      });
    47    }
    48  
    49    setupController(controller, model) {
    50      // Parameterized and periodic detail pages, which list children jobs,
    51      // should sort by submit time.
    52      if (model && ['periodic', 'parameterized'].includes(model.templateType)) {
    53        controller.setProperties({
    54          sortProperty: 'submitTime',
    55          sortDescending: true,
    56        });
    57      }
    58      return super.setupController(...arguments);
    59    }
    60  
    61    @watchQuery('job') watchAllJobs;
    62    @watchAll('node') watchNodes;
    63    @watchRecord('job-summary') watchSummary;
    64    @watchRelationship('allocations') watchAllocations;
    65    @watchRelationship('evaluations') watchEvaluations;
    66    @watchRelationship('latestDeployment') watchLatestDeployment;
    67  
    68    @collect(
    69      'watchAllJobs',
    70      'watchSummary',
    71      'watchAllocations',
    72      'watchEvaluations',
    73      'watchLatestDeployment',
    74      'watchNodes'
    75    )
    76    watchers;
    77  }