open-nomad/ui/app/components/exec/task-group-parent.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

102 lines
2.7 KiB
JavaScript
Raw Normal View History

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
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', 'taskGroup.{job.name,name}')
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() {
2021-12-28 16:08:12 +00:00
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());
2021-12-28 16:08:12 +00:00
return this.allocationTaskStatesRecordArrays.reduce(
flattenRecordArrays,
[]
);
}
@filterBy('allocationTaskStates', 'isActive') activeTaskStates;
@mapBy('activeTaskStates', 'task') activeTasks;
@mapBy('activeTasks', 'taskGroup') activeTaskGroups;
@computed(
'activeTaskGroups.@each.name',
'activeTaskStates.@each.name',
'activeTasks.@each.name',
'taskGroup.{name,tasks}'
)
get tasksWithRunningStates() {
const activeTaskStateNames = this.activeTaskStates
2021-12-28 14:45:20 +00:00
.filter((taskState) => {
2021-12-28 16:08:12 +00:00
return (
taskState.task &&
taskState.task.taskGroup.name === this.taskGroup.name
);
})
.mapBy('name');
2021-12-28 16:08:12 +00:00
return this.taskGroup.tasks.filter((task) =>
activeTaskStateNames.includes(task.name)
);
}
taskSorting = ['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);
}
}