From d485c040e32d1663ca1d8b30fd03f886c885b7ee Mon Sep 17 00:00:00 2001 From: Michael Lange Date: Mon, 20 May 2019 15:36:15 -0700 Subject: [PATCH] Restart a single task from the task detail page --- .../allocations/allocation/task/index.js | 22 ++++++++++++++++ .../allocations/allocation/task/index.hbs | 25 +++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/ui/app/controllers/allocations/allocation/task/index.js b/ui/app/controllers/allocations/allocation/task/index.js index c020bc4a2..186f6b258 100644 --- a/ui/app/controllers/allocations/allocation/task/index.js +++ b/ui/app/controllers/allocations/allocation/task/index.js @@ -1,6 +1,7 @@ import Controller from '@ember/controller'; import { computed } from '@ember/object'; import { alias } from '@ember/object/computed'; +import { task } from 'ember-concurrency'; export default Controller.extend({ network: alias('model.resources.networks.firstObject'), @@ -20,4 +21,25 @@ export default Controller.extend({ ) .sortBy('name'); }), + + error: computed(() => { + // { title, description } + return null; + }), + + onDismiss() { + this.set('error', null); + }, + + restartTask: task(function*() { + try { + yield this.model.restart(); + } catch (err) { + console.log('OOPs', err); + this.set('error', { + title: 'Could Not Restart Task', + description: 'Your ACL token does not grant allocation lifecyle permissions.', + }); + } + }), }); diff --git a/ui/app/templates/allocations/allocation/task/index.hbs b/ui/app/templates/allocations/allocation/task/index.hbs index 518e8e58d..9409934ff 100644 --- a/ui/app/templates/allocations/allocation/task/index.hbs +++ b/ui/app/templates/allocations/allocation/task/index.hbs @@ -1,8 +1,33 @@ {{partial "allocations/allocation/task/subnav"}}
+ {{#if error}} +
+
+
+

{{error.title}}

+

{{error.description}}

+
+
+ +
+
+
+ {{/if}} +

{{model.name}} {{model.state}} + {{#if model.isRunning}} + {{two-step-button + data-test-restart + idleText="Restart" + cancelText="Cancel" + confirmText="Yes, Restart" + confirmationMessage="Are you sure? This will restart the task in-place." + awaitingConfirmation=restartTask.isRunning + disabled=restartTask.isRunning + onConfirm=(perform restartTask)}} + {{/if}}