github.com/hernad/nomad@v1.6.112/ui/app/controllers/jobs/job/services/index.js (about)

     1  /**
     2   * Copyright (c) HashiCorp, Inc.
     3   * SPDX-License-Identifier: MPL-2.0
     4   */
     5  
     6  import Controller from '@ember/controller';
     7  import WithNamespaceResetting from 'nomad-ui/mixins/with-namespace-resetting';
     8  import Sortable from 'nomad-ui/mixins/sortable';
     9  import { alias } from '@ember/object/computed';
    10  import { computed } from '@ember/object';
    11  import { union } from '@ember/object/computed';
    12  
    13  export default class JobsJobServicesIndexController extends Controller.extend(
    14    WithNamespaceResetting,
    15    Sortable
    16  ) {
    17    @alias('model') job;
    18    @alias('job.taskGroups') taskGroups;
    19  
    20    queryParams = [
    21      {
    22        sortProperty: 'sort',
    23      },
    24      {
    25        sortDescending: 'desc',
    26      },
    27    ];
    28  
    29    sortProperty = 'name';
    30    sortDescending = false;
    31  
    32    @alias('services') listToSort;
    33    @alias('listSorted') sortedServices;
    34  
    35    @computed('taskGroups.@each.tasks')
    36    get tasks() {
    37      return this.taskGroups.map((group) => group.tasks.toArray()).flat();
    38    }
    39  
    40    @computed('tasks.@each.services')
    41    get taskServices() {
    42      return this.tasks
    43        .map((t) => (t.services || []).toArray())
    44        .flat()
    45        .compact()
    46        .map((service) => {
    47          service.level = 'task';
    48          return service;
    49        });
    50    }
    51  
    52    @computed('model.taskGroup.services.@each.name', 'taskGroups')
    53    get groupServices() {
    54      return this.taskGroups
    55        .map((g) => (g.services || []).toArray())
    56        .flat()
    57        .compact()
    58        .map((service) => {
    59          service.level = 'group';
    60          return service;
    61        });
    62    }
    63  
    64    @union('taskServices', 'groupServices') serviceFragments;
    65  
    66    // Services, grouped by name, with aggregatable allocations.
    67    @computed(
    68      'job.services.@each.{name,allocation}',
    69      'job.services.length',
    70      'serviceFragments'
    71    )
    72    get services() {
    73      return this.serviceFragments.map((fragment) => {
    74        fragment.instances = this.job.services.filter(
    75          (s) => s.name === fragment.name && s.derivedLevel === fragment.level
    76        );
    77        return fragment;
    78      });
    79    }
    80  }