open-nomad/ui/app/components/client-node-row.js

67 lines
1.7 KiB
JavaScript
Raw Normal View History

import { inject as service } from '@ember/service';
import Component from '@ember/component';
import { lazyClick } from '../helpers/lazy-click';
import { watchRelationship } from 'nomad-ui/utils/properties/watch';
import WithVisibilityDetection from 'nomad-ui/mixins/with-component-visibility-detection';
import { computed } from '@ember/object';
import { classNames, tagName } from '@ember-decorators/component';
import classic from 'ember-classic-decorator';
2017-09-19 14:47:10 +00:00
@classic
@tagName('tr')
@classNames('client-node-row', 'is-interactive')
export default class ClientNodeRow extends Component.extend(WithVisibilityDetection) {
@service store;
node = null;
2017-09-19 14:47:10 +00:00
onClick() {}
2017-09-19 14:47:10 +00:00
click(event) {
2019-03-26 07:46:44 +00:00
lazyClick([this.onClick, event]);
}
2017-09-19 14:47:10 +00:00
didReceiveAttrs() {
// Reload the node in order to get detail information
2019-03-26 07:46:44 +00:00
const node = this.node;
2017-09-19 14:47:10 +00:00
if (node) {
node.reload().then(() => {
2019-03-26 07:46:44 +00:00
this.watch.perform(node, 100);
});
2017-09-19 14:47:10 +00:00
}
}
visibilityHandler() {
if (document.hidden) {
2019-03-26 07:46:44 +00:00
this.watch.cancelAll();
} else {
2019-03-26 07:46:44 +00:00
const node = this.node;
if (node) {
2019-03-26 07:46:44 +00:00
this.watch.perform(node, 100);
}
}
}
willDestroy() {
2019-03-26 07:46:44 +00:00
this.watch.cancelAll();
super.willDestroy(...arguments);
}
@watchRelationship('allocations') watch;
@computed('node.compositeStatus')
get compositeStatusClass() {
let compositeStatus = this.get('node.compositeStatus');
if (compositeStatus === 'draining') {
return 'status-text is-info';
} else if (compositeStatus === 'ineligible') {
return 'status-text is-warning';
} else if (compositeStatus === 'down') {
return 'status-text is-danger';
} else {
return '';
}
}
}