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

View file

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