github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/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( 14 WithVisibilityDetection 15 ) { 16 @service store; 17 18 node = null; 19 20 onClick() {} 21 22 click(event) { 23 lazyClick([this.onClick, event]); 24 } 25 26 didReceiveAttrs() { 27 super.didReceiveAttrs(); 28 // Reload the node in order to get detail information 29 const node = this.node; 30 if (node) { 31 node.reload().then(() => { 32 this.watch.perform(node, 100); 33 }); 34 } 35 } 36 37 visibilityHandler() { 38 if (document.hidden) { 39 this.watch.cancelAll(); 40 } else { 41 const node = this.node; 42 if (node) { 43 this.watch.perform(node, 100); 44 } 45 } 46 } 47 48 willDestroy() { 49 this.watch.cancelAll(); 50 super.willDestroy(...arguments); 51 } 52 53 @watchRelationship('allocations') watch; 54 55 @computed('node.compositeStatus') 56 get compositeStatusClass() { 57 let compositeStatus = this.get('node.compositeStatus'); 58 59 if (compositeStatus === 'draining') { 60 return 'status-text is-info'; 61 } else if (compositeStatus === 'ineligible') { 62 return 'status-text is-warning'; 63 } else if (compositeStatus === 'down') { 64 return 'status-text is-danger'; 65 } else { 66 return ''; 67 } 68 } 69 }