open-nomad/ui/app/components/job-row.js

49 lines
1.1 KiB
JavaScript
Raw Normal View History

2018-02-12 23:27:19 +00:00
import { inject as service } from '@ember/service';
import Component from '@ember/component';
import { lazyClick } from '../helpers/lazy-click';
2018-02-12 23:27:19 +00:00
import { watchRelationship } from 'nomad-ui/utils/properties/watch';
import WithVisibilityDetection from 'nomad-ui/mixins/with-component-visibility-detection';
2017-09-19 14:47:10 +00:00
export default Component.extend(WithVisibilityDetection, {
2018-02-12 23:27:19 +00:00
store: service(),
2017-09-19 14:47:10 +00:00
tagName: 'tr',
classNames: ['job-row', 'is-interactive'],
job: null,
onClick() {},
click(event) {
lazyClick([this.get('onClick'), event]);
2017-09-19 14:47:10 +00:00
},
didReceiveAttrs() {
// Reload the job in order to get detail information
const job = this.get('job');
2017-10-23 17:29:26 +00:00
if (job && !job.get('isLoading')) {
2018-02-12 23:27:19 +00:00
job.reload().then(() => {
this.get('watch').perform(job, 100);
});
2017-09-19 14:47:10 +00:00
}
},
2018-02-12 23:27:19 +00:00
visibilityHandler() {
if (document.hidden) {
this.get('watch').cancelAll();
} else {
const job = this.get('job');
if (job && !job.get('isLoading')) {
this.get('watch').perform(job, 100);
}
}
},
2018-02-14 23:42:03 +00:00
willDestroy() {
this.get('watch').cancelAll();
this._super(...arguments);
},
2018-02-16 02:55:59 +00:00
watch: watchRelationship('summary'),
2017-09-19 14:47:10 +00:00
});