open-nomad/ui/app/controllers/allocations/allocation/task/index.js
Buck Doyle 89136cbf6a Add massaged results of class codemod
Manual interventions:
• decorators on the same line for service and controller
  injections and most computed property macros
• preserving import order when possible, both per-line
  and intra-line
• moving new imports to the bottom
• removal of classic decorator for trivial cases
• conversion of init to constructor when appropriate
2020-06-10 16:18:42 -05:00

63 lines
1.6 KiB
JavaScript

import Controller from '@ember/controller';
import { computed } from '@ember/object';
import { computed as overridable } from 'ember-overridable-computed';
import { alias } from '@ember/object/computed';
import { task } from 'ember-concurrency';
import classic from 'ember-classic-decorator';
@classic
export default class IndexController extends Controller {
@computed('model.task.taskGroup.tasks.@each.name')
get otherTaskStates() {
const taskName = this.model.task.name;
return this.model.allocation.states.rejectBy('name', taskName);
}
@computed('otherTaskStates.@each.lifecycle')
get prestartTaskStates() {
return this.otherTaskStates.filterBy('task.lifecycle');
}
@alias('model.resources.networks.firstObject') network;
@computed('network.{reservedPorts.[],dynamicPorts.[]}')
get ports() {
return (this.get('network.reservedPorts') || [])
.map(port => ({
name: port.Label,
port: port.Value,
isDynamic: false,
}))
.concat(
(this.get('network.dynamicPorts') || []).map(port => ({
name: port.Label,
port: port.Value,
isDynamic: true,
}))
)
.sortBy('name');
}
@overridable(() => {
// { title, description }
return null;
})
error;
onDismiss() {
this.set('error', null);
}
@task(function*() {
try {
yield this.model.restart();
} catch (err) {
this.set('error', {
title: 'Could Not Restart Task',
description: 'Your ACL token does not grant allocation lifecycle permissions.',
});
}
})
restartTask;
}