open-nomad/ui/app/components/exec/task-group-parent.js
Buck Doyle cd11cd290c Add manually-converted classes
I don’t know why the codemod ignored these files 🧐
2020-06-15 10:14:26 -05:00

87 lines
2.5 KiB
JavaScript

import Component from '@ember/component';
import { inject as service } from '@ember/service';
import { action, computed } from '@ember/object';
import { filterBy, mapBy, or, sort } from '@ember/object/computed';
import generateExecUrl from 'nomad-ui/utils/generate-exec-url';
import openExecUrl from 'nomad-ui/utils/open-exec-url';
import classic from 'ember-classic-decorator';
@classic
export default class TaskGroupParent extends Component {
@service router;
@or('clickedOpen', 'currentRouteIsThisTaskGroup') isOpen;
@computed('router.currentRoute')
get currentRouteIsThisTaskGroup() {
const route = this.router.currentRoute;
if (route.name.includes('task-group')) {
const taskGroupRoute = route.parent;
const execRoute = taskGroupRoute.parent;
return (
execRoute.params.job_name === this.taskGroup.job.name &&
taskGroupRoute.params.task_group_name === this.taskGroup.name
);
} else {
return false;
}
}
@computed('taskGroup.allocations.@each.clientStatus')
get hasPendingAllocations() {
return this.taskGroup.allocations.any(allocation => allocation.clientStatus === 'pending');
}
@mapBy('taskGroup.allocations', 'states') allocationTaskStatesRecordArrays;
@computed('allocationTaskStatesRecordArrays.[]')
get allocationTaskStates() {
const flattenRecordArrays = (accumulator, recordArray) =>
accumulator.concat(recordArray.toArray());
return this.allocationTaskStatesRecordArrays.reduce(flattenRecordArrays, []);
}
@filterBy('allocationTaskStates', 'isActive') activeTaskStates;
@mapBy('activeTaskStates', 'task') activeTasks;
@mapBy('activeTasks', 'taskGroup') activeTaskGroups;
@computed(
'taskGroup.name',
'activeTaskStates.@each.name',
'activeTasks.@each.name',
'activeTaskGroups.@each.name'
)
get tasksWithRunningStates() {
const activeTaskStateNames = this.activeTaskStates
.filter(taskState => {
return taskState.task && taskState.task.taskGroup.name === this.taskGroup.name;
})
.mapBy('name');
return this.taskGroup.tasks.filter(task => activeTaskStateNames.includes(task.name));
}
taskSorting = Object.freeze(['name']);
@sort('tasksWithRunningStates', 'taskSorting') sortedTasks;
clickedOpen = false;
@action
toggleOpen() {
this.toggleProperty('clickedOpen');
}
@action
openInNewWindow(job, taskGroup, task) {
let url = generateExecUrl(this.router, {
job,
taskGroup,
task,
});
openExecUrl(url);
}
}