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