Watch the next allocation on the allocation index page

This commit is contained in:
Michael Lange 2019-05-20 15:35:21 -07:00
parent 8d31474fdc
commit e40a01456b
2 changed files with 20 additions and 3 deletions

View file

@ -1,10 +1,11 @@
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
import { computed } from '@ember/object';
import { computed, observer } from '@ember/object';
import { alias } from '@ember/object/computed';
import { task } from 'ember-concurrency';
import Sortable from 'nomad-ui/mixins/sortable';
import { lazyClick } from 'nomad-ui/helpers/lazy-click';
import { watchRecord } from 'nomad-ui/utils/properties/watch';
export default Controller.extend(Sortable, {
token: service(),
@ -32,6 +33,17 @@ export default Controller.extend(Sortable, {
this.set('error', null);
},
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();
}
}),
stopAllocation: task(function*() {
try {
yield this.model.stop();
@ -49,9 +61,8 @@ export default Controller.extend(Sortable, {
try {
yield this.model.restart();
} catch (err) {
console.log('oops', err);
this.set('error', {
title: 'Could Not Stop Allocation',
title: 'Could Not Restart Allocation',
description: 'Your ACL token does not grant allocation lifecyle permissions.',
});
}

View file

@ -10,4 +10,10 @@ export default Route.extend({
return this._super(...arguments);
},
resetController(controller, isExiting) {
if (isExiting) {
controller.watchNext.cancelAll();
}
},
});