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

     1  import Component from '@ember/component';
     2  import { inject as service } from '@ember/service';
     3  import { computed, action } from '@ember/object';
     4  import { alias, oneWay } from '@ember/object/computed';
     5  import { debounce } from '@ember/runloop';
     6  import { classNames, tagName } from '@ember-decorators/component';
     7  import classic from 'ember-classic-decorator';
     8  import { lazyClick } from '../helpers/lazy-click';
     9  
    10  @classic
    11  @tagName('tr')
    12  @classNames('task-group-row', 'is-interactive')
    13  export default class TaskGroupRow extends Component {
    14    @service can;
    15  
    16    taskGroup = null;
    17    debounce = 500;
    18  
    19    @oneWay('taskGroup.count') count;
    20    @alias('taskGroup.job.runningDeployment') runningDeployment;
    21  
    22    @computed('runningDeployment')
    23    get tooltipText() {
    24      if (this.can.cannot('scale job')) return "You aren't allowed to scale task groups";
    25      if (this.runningDeployment) return 'You cannot scale task groups during a deployment';
    26      return undefined;
    27    }
    28  
    29    onClick() {}
    30  
    31    click(event) {
    32      lazyClick([this.onClick, event]);
    33    }
    34  
    35    @computed('count', 'taskGroup.scaling.min')
    36    get isMinimum() {
    37      const scaling = this.taskGroup.scaling;
    38      if (!scaling || scaling.min == null) return false;
    39      return this.count <= scaling.min;
    40    }
    41  
    42    @computed('count', 'taskGroup.scaling.max')
    43    get isMaximum() {
    44      const scaling = this.taskGroup.scaling;
    45      if (!scaling || scaling.max == null) return false;
    46      return this.count >= scaling.max;
    47    }
    48  
    49    @action
    50    countUp() {
    51      const scaling = this.taskGroup.scaling;
    52      if (!scaling || scaling.max == null || this.count < scaling.max) {
    53        this.incrementProperty('count');
    54        this.scale(this.count);
    55      }
    56    }
    57  
    58    @action
    59    countDown() {
    60      const scaling = this.taskGroup.scaling;
    61      if (!scaling || scaling.min == null || this.count > scaling.min) {
    62        this.decrementProperty('count');
    63        this.scale(this.count);
    64      }
    65    }
    66  
    67    scale(count) {
    68      debounce(this, sendCountAction, count, this.debounce);
    69    }
    70  }
    71  
    72  function sendCountAction(count) {
    73    return this.taskGroup.scale(count);
    74  }