2018-06-27 20:39:57 +00:00
|
|
|
import Controller from '@ember/controller';
|
2018-08-30 00:18:42 +00:00
|
|
|
import { inject as service } from '@ember/service';
|
2019-05-20 22:35:21 +00:00
|
|
|
import { computed, observer } from '@ember/object';
|
2019-04-17 23:17:48 +00:00
|
|
|
import { alias } from '@ember/object/computed';
|
2019-05-17 00:43:12 +00:00
|
|
|
import { task } from 'ember-concurrency';
|
2017-10-30 20:39:15 +00:00
|
|
|
import Sortable from 'nomad-ui/mixins/sortable';
|
2018-06-06 21:25:48 +00:00
|
|
|
import { lazyClick } from 'nomad-ui/helpers/lazy-click';
|
2019-05-20 22:35:21 +00:00
|
|
|
import { watchRecord } from 'nomad-ui/utils/properties/watch';
|
2017-10-30 20:39:15 +00:00
|
|
|
|
|
|
|
export default Controller.extend(Sortable, {
|
2018-08-30 00:18:42 +00:00
|
|
|
token: service(),
|
|
|
|
|
2017-10-30 20:39:15 +00:00
|
|
|
queryParams: {
|
|
|
|
sortProperty: 'sort',
|
|
|
|
sortDescending: 'desc',
|
|
|
|
},
|
|
|
|
|
|
|
|
sortProperty: 'name',
|
|
|
|
sortDescending: false,
|
|
|
|
|
2017-12-15 21:39:18 +00:00
|
|
|
listToSort: alias('model.states'),
|
|
|
|
sortedStates: alias('listSorted'),
|
2018-06-06 21:25:48 +00:00
|
|
|
|
2019-04-17 23:17:48 +00:00
|
|
|
// Set in the route
|
|
|
|
preempter: null,
|
|
|
|
|
2019-05-17 00:43:12 +00:00
|
|
|
error: computed(() => {
|
|
|
|
// { title, description }
|
|
|
|
return null;
|
|
|
|
}),
|
|
|
|
|
|
|
|
onDismiss() {
|
|
|
|
this.set('error', null);
|
|
|
|
},
|
|
|
|
|
2019-05-20 22:35:21 +00:00
|
|
|
watchNext: watchRecord('allocation'),
|
|
|
|
|
|
|
|
observeWatchNext: observer('model.nextAllocation.clientStatus', function() {
|
|
|
|
const nextAllocation = this.model.nextAllocation;
|
|
|
|
if (nextAllocation && nextAllocation.content) {
|
|
|
|
this.watchNext.perform(nextAllocation);
|
|
|
|
} else {
|
|
|
|
this.watchNext.cancelAll();
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
|
2019-05-17 00:43:12 +00:00
|
|
|
stopAllocation: task(function*() {
|
|
|
|
try {
|
|
|
|
yield this.model.stop();
|
|
|
|
// Eagerly update the allocation clientStatus to avoid flickering
|
|
|
|
this.model.set('clientStatus', 'complete');
|
|
|
|
} catch (err) {
|
|
|
|
this.set('error', {
|
|
|
|
title: 'Could Not Stop Allocation',
|
|
|
|
description: 'Your ACL token does not grant allocation lifecyle permissions.',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
|
|
|
|
restartAllocation: task(function*() {
|
|
|
|
try {
|
|
|
|
yield this.model.restart();
|
|
|
|
} catch (err) {
|
|
|
|
this.set('error', {
|
2019-05-20 22:35:21 +00:00
|
|
|
title: 'Could Not Restart Allocation',
|
2019-05-17 00:43:12 +00:00
|
|
|
description: 'Your ACL token does not grant allocation lifecyle permissions.',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
|
2018-06-06 21:25:48 +00:00
|
|
|
actions: {
|
|
|
|
gotoTask(allocation, task) {
|
|
|
|
this.transitionToRoute('allocations.allocation.task', task);
|
|
|
|
},
|
|
|
|
|
|
|
|
taskClick(allocation, task, event) {
|
|
|
|
lazyClick([() => this.send('gotoTask', allocation, task), event]);
|
|
|
|
},
|
|
|
|
},
|
2017-10-30 20:39:15 +00:00
|
|
|
});
|