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