From 3a8334e720fc788050a86306c2455128c8536656 Mon Sep 17 00:00:00 2001 From: Michael Lange Date: Mon, 20 May 2019 15:35:21 -0700 Subject: [PATCH] Watch the next allocation on the allocation index page --- .../controllers/allocations/allocation/index.js | 17 ++++++++++++++--- ui/app/routes/allocations/allocation/index.js | 6 ++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/ui/app/controllers/allocations/allocation/index.js b/ui/app/controllers/allocations/allocation/index.js index 662aac437..e2eaf5223 100644 --- a/ui/app/controllers/allocations/allocation/index.js +++ b/ui/app/controllers/allocations/allocation/index.js @@ -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.', }); } diff --git a/ui/app/routes/allocations/allocation/index.js b/ui/app/routes/allocations/allocation/index.js index ebe985da2..323af0e82 100644 --- a/ui/app/routes/allocations/allocation/index.js +++ b/ui/app/routes/allocations/allocation/index.js @@ -10,4 +10,10 @@ export default Route.extend({ return this._super(...arguments); }, + + resetController(controller, isExiting) { + if (isExiting) { + controller.watchNext.cancelAll(); + } + }, });