2017-12-15 21:39:18 +00:00
|
|
|
import { alias } from '@ember/object/computed';
|
|
|
|
import Controller from '@ember/controller';
|
2019-11-15 04:23:47 +00:00
|
|
|
import { computed, observer } from '@ember/object';
|
2019-11-02 07:55:01 +00:00
|
|
|
import { task } from 'ember-concurrency';
|
2017-09-19 14:47:10 +00:00
|
|
|
import Sortable from 'nomad-ui/mixins/sortable';
|
|
|
|
import Searchable from 'nomad-ui/mixins/searchable';
|
2019-11-02 07:55:01 +00:00
|
|
|
import messageFromAdapterError from 'nomad-ui/utils/message-from-adapter-error';
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
export default Controller.extend(Sortable, Searchable, {
|
|
|
|
queryParams: {
|
|
|
|
currentPage: 'page',
|
|
|
|
searchTerm: 'search',
|
|
|
|
sortProperty: 'sort',
|
|
|
|
sortDescending: 'desc',
|
2019-04-17 18:19:54 +00:00
|
|
|
onlyPreemptions: 'preemptions',
|
2017-09-19 14:47:10 +00:00
|
|
|
},
|
|
|
|
|
2019-11-15 04:23:47 +00:00
|
|
|
// Set in the route
|
|
|
|
flagAsDraining: false,
|
|
|
|
|
2017-09-19 14:47:10 +00:00
|
|
|
currentPage: 1,
|
|
|
|
pageSize: 8,
|
|
|
|
|
|
|
|
sortProperty: 'modifyIndex',
|
|
|
|
sortDescending: true,
|
|
|
|
|
2017-10-18 19:52:24 +00:00
|
|
|
searchProps: computed(() => ['shortId', 'name']),
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2019-04-17 18:19:54 +00:00
|
|
|
onlyPreemptions: false,
|
|
|
|
|
|
|
|
visibleAllocations: computed(
|
|
|
|
'model.allocations.[]',
|
|
|
|
'preemptions.[]',
|
|
|
|
'onlyPreemptions',
|
|
|
|
function() {
|
|
|
|
return this.onlyPreemptions ? this.preemptions : this.model.allocations;
|
|
|
|
}
|
|
|
|
),
|
|
|
|
|
|
|
|
listToSort: alias('visibleAllocations'),
|
2017-12-15 21:39:18 +00:00
|
|
|
listToSearch: alias('listSorted'),
|
|
|
|
sortedAllocations: alias('listSearched'),
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2019-11-02 07:55:01 +00:00
|
|
|
eligibilityError: null,
|
2019-11-19 06:36:07 +00:00
|
|
|
stopDrainError: null,
|
2019-11-19 08:12:34 +00:00
|
|
|
drainError: null,
|
2019-11-15 04:23:47 +00:00
|
|
|
showDrainNotification: false,
|
2019-11-19 06:36:07 +00:00
|
|
|
showDrainUpdateNotification: false,
|
|
|
|
showDrainStoppedNotification: false,
|
2019-11-02 07:55:01 +00:00
|
|
|
|
2019-04-17 18:19:54 +00:00
|
|
|
preemptions: computed('model.allocations.@each.wasPreempted', function() {
|
|
|
|
return this.model.allocations.filterBy('wasPreempted');
|
|
|
|
}),
|
|
|
|
|
2018-05-08 18:23:42 +00:00
|
|
|
sortedEvents: computed('model.events.@each.time', function() {
|
|
|
|
return this.get('model.events')
|
|
|
|
.sortBy('time')
|
|
|
|
.reverse();
|
|
|
|
}),
|
|
|
|
|
2018-05-09 01:09:20 +00:00
|
|
|
sortedDrivers: computed('model.drivers.@each.name', function() {
|
|
|
|
return this.get('model.drivers').sortBy('name');
|
|
|
|
}),
|
|
|
|
|
2019-11-02 07:55:01 +00:00
|
|
|
setEligibility: task(function*(value) {
|
|
|
|
try {
|
|
|
|
yield value ? this.model.setEligible() : this.model.setIneligible();
|
|
|
|
} catch (err) {
|
|
|
|
const error = messageFromAdapterError(err) || 'Could not set eligibility';
|
|
|
|
this.set('eligibilityError', error);
|
|
|
|
}
|
|
|
|
}).drop(),
|
|
|
|
|
2019-11-19 06:36:07 +00:00
|
|
|
stopDrain: task(function*() {
|
|
|
|
try {
|
|
|
|
this.set('flagAsDraining', false);
|
|
|
|
yield this.model.cancelDrain();
|
|
|
|
this.set('showDrainStoppedNotification', true);
|
|
|
|
} catch (err) {
|
|
|
|
this.set('flagAsDraining', true);
|
|
|
|
const error = messageFromAdapterError(err) || 'Could not stop drain';
|
|
|
|
this.set('stopDrainError', error);
|
|
|
|
}
|
|
|
|
}).drop(),
|
|
|
|
|
2019-11-19 08:12:34 +00:00
|
|
|
forceDrain: task(function*() {
|
|
|
|
try {
|
|
|
|
yield this.model.forceDrain({
|
|
|
|
IgnoreSystemJobs: this.model.drainStrategy.ignoreSystemJobs,
|
|
|
|
});
|
|
|
|
} catch (err) {
|
|
|
|
const error = messageFromAdapterError(err) || 'Could not force drain';
|
|
|
|
this.set('drainError', error);
|
|
|
|
}
|
|
|
|
}).drop(),
|
|
|
|
|
2019-11-15 04:23:47 +00:00
|
|
|
triggerDrainNotification: observer('model.isDraining', function() {
|
|
|
|
if (!this.model.isDraining && this.flagAsDraining) {
|
|
|
|
this.set('showDrainNotification', true);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.set('flagAsDraining', this.model.isDraining);
|
|
|
|
}),
|
|
|
|
|
2017-09-19 14:47:10 +00:00
|
|
|
actions: {
|
|
|
|
gotoAllocation(allocation) {
|
|
|
|
this.transitionToRoute('allocations.allocation', allocation);
|
|
|
|
},
|
2019-04-17 18:19:54 +00:00
|
|
|
|
|
|
|
setPreemptionFilter(value) {
|
|
|
|
this.set('onlyPreemptions', value);
|
|
|
|
},
|
2019-11-19 06:36:07 +00:00
|
|
|
|
|
|
|
drainNotify(isUpdating) {
|
|
|
|
this.set('showDrainUpdateNotification', isUpdating);
|
|
|
|
},
|
2019-11-19 08:12:34 +00:00
|
|
|
|
|
|
|
drainError(err) {
|
|
|
|
const error = messageFromAdapterError(err) || 'Could not run drain';
|
|
|
|
this.set('drainError', error);
|
|
|
|
},
|
2017-09-19 14:47:10 +00:00
|
|
|
},
|
|
|
|
});
|