github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/ui/app/controllers/jobs/job/task-group.js (about)

     1  import { inject as service } from '@ember/service';
     2  import { alias, readOnly } from '@ember/object/computed';
     3  import Controller from '@ember/controller';
     4  import { action, computed, get } from '@ember/object';
     5  import Sortable from 'nomad-ui/mixins/sortable';
     6  import Searchable from 'nomad-ui/mixins/searchable';
     7  import WithNamespaceResetting from 'nomad-ui/mixins/with-namespace-resetting';
     8  import classic from 'ember-classic-decorator';
     9  
    10  @classic
    11  export default class TaskGroupController extends Controller.extend(
    12      Sortable,
    13      Searchable,
    14      WithNamespaceResetting
    15    ) {
    16    @service userSettings;
    17    @service can;
    18  
    19    queryParams = [
    20      {
    21        currentPage: 'page',
    22      },
    23      {
    24        searchTerm: 'search',
    25      },
    26      {
    27        sortProperty: 'sort',
    28      },
    29      {
    30        sortDescending: 'desc',
    31      },
    32    ];
    33  
    34    currentPage = 1;
    35    @readOnly('userSettings.pageSize') pageSize;
    36  
    37    sortProperty = 'modifyIndex';
    38    sortDescending = true;
    39  
    40    @computed
    41    get searchProps() {
    42      return ['shortId', 'name'];
    43    }
    44  
    45    @computed('model.allocations.[]')
    46    get allocations() {
    47      return this.get('model.allocations') || [];
    48    }
    49  
    50    @alias('allocations') listToSort;
    51    @alias('listSorted') listToSearch;
    52    @alias('listSearched') sortedAllocations;
    53  
    54    @computed('model.scaleState.events.@each.time', function() {
    55      const events = get(this, 'model.scaleState.events');
    56      if (events) {
    57        return events.sortBy('time').reverse();
    58      }
    59      return [];
    60    })
    61    sortedScaleEvents;
    62  
    63    @computed('sortedScaleEvents.@each.hasCount', function() {
    64      const countEventsCount = this.sortedScaleEvents.filterBy('hasCount').length;
    65      return countEventsCount > 1 && countEventsCount >= this.sortedScaleEvents.length / 2;
    66    })
    67    shouldShowScaleEventTimeline;
    68  
    69    @computed('model.job.runningDeployment')
    70    get tooltipText() {
    71      if (this.can.cannot('scale job')) return "You aren't allowed to scale task groups";
    72      if (this.model.job.runningDeployment) return 'You cannot scale task groups during a deployment';
    73      return undefined;
    74    }
    75  
    76    @action
    77    gotoAllocation(allocation) {
    78      this.transitionToRoute('allocations.allocation', allocation);
    79    }
    80  
    81    @action
    82    scaleTaskGroup(count) {
    83      return this.model.scale(count);
    84    }
    85  }