github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/ui/app/components/client-node-row.js (about) 1 import { inject as service } from '@ember/service'; 2 import Component from '@ember/component'; 3 import { lazyClick } from '../helpers/lazy-click'; 4 import { watchRelationship } from 'nomad-ui/utils/properties/watch'; 5 import WithVisibilityDetection from 'nomad-ui/mixins/with-component-visibility-detection'; 6 import { computed } from '@ember/object'; 7 import { classNames, tagName } from '@ember-decorators/component'; 8 import classic from 'ember-classic-decorator'; 9 10 @classic 11 @tagName('tr') 12 @classNames('client-node-row', 'is-interactive') 13 export default class ClientNodeRow extends Component.extend(WithVisibilityDetection) { 14 @service store; 15 16 node = null; 17 18 onClick() {} 19 20 click(event) { 21 lazyClick([this.onClick, event]); 22 } 23 24 didReceiveAttrs() { 25 // Reload the node in order to get detail information 26 const node = this.node; 27 if (node) { 28 node.reload().then(() => { 29 this.watch.perform(node, 100); 30 }); 31 } 32 } 33 34 visibilityHandler() { 35 if (document.hidden) { 36 this.watch.cancelAll(); 37 } else { 38 const node = this.node; 39 if (node) { 40 this.watch.perform(node, 100); 41 } 42 } 43 } 44 45 willDestroy() { 46 this.watch.cancelAll(); 47 super.willDestroy(...arguments); 48 } 49 50 @watchRelationship('allocations') watch; 51 52 @computed('node.compositeStatus') 53 get compositeStatusClass() { 54 let compositeStatus = this.get('node.compositeStatus'); 55 56 if (compositeStatus === 'draining') { 57 return 'status-text is-info'; 58 } else if (compositeStatus === 'ineligible') { 59 return 'status-text is-warning'; 60 } else if (compositeStatus === 'down') { 61 return 'status-text is-danger'; 62 } else { 63 return ''; 64 } 65 } 66 }