2020-03-24 23:22:16 +00:00
|
|
|
import Component from '@ember/component';
|
|
|
|
import { inject as service } from '@ember/service';
|
2020-06-11 21:23:00 +00:00
|
|
|
import { action, computed } from '@ember/object';
|
2020-04-06 18:52:42 +00:00
|
|
|
import { filterBy, mapBy, or, sort } from '@ember/object/computed';
|
2020-03-24 23:22:16 +00:00
|
|
|
import generateExecUrl from 'nomad-ui/utils/generate-exec-url';
|
|
|
|
import openExecUrl from 'nomad-ui/utils/open-exec-url';
|
2020-06-11 21:23:00 +00:00
|
|
|
import classic from 'ember-classic-decorator';
|
2020-03-24 23:22:16 +00:00
|
|
|
|
2020-06-11 21:23:00 +00:00
|
|
|
@classic
|
|
|
|
export default class TaskGroupParent extends Component {
|
|
|
|
@service router;
|
2020-03-24 23:22:16 +00:00
|
|
|
|
2020-06-11 21:23:00 +00:00
|
|
|
@or('clickedOpen', 'currentRouteIsThisTaskGroup') isOpen;
|
2020-03-24 23:22:16 +00:00
|
|
|
|
2021-02-17 21:01:44 +00:00
|
|
|
@computed('router.currentRoute', 'taskGroup.{job.name,name}')
|
2020-06-11 21:23:00 +00:00
|
|
|
get currentRouteIsThisTaskGroup() {
|
2020-03-24 23:22:16 +00:00
|
|
|
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;
|
|
|
|
}
|
2020-06-11 21:23:00 +00:00
|
|
|
}
|
2020-03-24 23:22:16 +00:00
|
|
|
|
2020-06-11 21:23:00 +00:00
|
|
|
@computed('taskGroup.allocations.@each.clientStatus')
|
|
|
|
get hasPendingAllocations() {
|
2021-12-28 16:08:12 +00:00
|
|
|
return this.taskGroup.allocations.any(
|
|
|
|
(allocation) => allocation.clientStatus === 'pending'
|
|
|
|
);
|
2020-06-11 21:23:00 +00:00
|
|
|
}
|
2020-04-06 18:52:42 +00:00
|
|
|
|
2020-06-11 21:23:00 +00:00
|
|
|
@mapBy('taskGroup.allocations', 'states') allocationTaskStatesRecordArrays;
|
|
|
|
@computed('allocationTaskStatesRecordArrays.[]')
|
|
|
|
get allocationTaskStates() {
|
2020-03-25 17:08:33 +00:00
|
|
|
const flattenRecordArrays = (accumulator, recordArray) =>
|
|
|
|
accumulator.concat(recordArray.toArray());
|
2021-12-28 16:08:12 +00:00
|
|
|
return this.allocationTaskStatesRecordArrays.reduce(
|
|
|
|
flattenRecordArrays,
|
|
|
|
[]
|
|
|
|
);
|
2020-06-11 21:23:00 +00:00
|
|
|
}
|
2020-03-24 23:22:16 +00:00
|
|
|
|
2020-06-11 21:23:00 +00:00
|
|
|
@filterBy('allocationTaskStates', 'isActive') activeTaskStates;
|
2020-03-24 23:22:16 +00:00
|
|
|
|
2020-06-11 21:23:00 +00:00
|
|
|
@mapBy('activeTaskStates', 'task') activeTasks;
|
|
|
|
@mapBy('activeTasks', 'taskGroup') activeTaskGroups;
|
2020-03-25 17:08:33 +00:00
|
|
|
|
2020-06-11 21:23:00 +00:00
|
|
|
@computed(
|
2021-02-17 21:01:44 +00:00
|
|
|
'activeTaskGroups.@each.name',
|
2020-03-25 17:08:33 +00:00
|
|
|
'activeTaskStates.@each.name',
|
|
|
|
'activeTasks.@each.name',
|
2021-02-17 21:01:44 +00:00
|
|
|
'taskGroup.{name,tasks}'
|
2020-06-11 21:23:00 +00:00
|
|
|
)
|
|
|
|
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
|
|
|
|
);
|
2020-06-11 21:23:00 +00:00
|
|
|
})
|
|
|
|
.mapBy('name');
|
|
|
|
|
2021-12-28 16:08:12 +00:00
|
|
|
return this.taskGroup.tasks.filter((task) =>
|
|
|
|
activeTaskStateNames.includes(task.name)
|
|
|
|
);
|
2020-06-11 21:23:00 +00:00
|
|
|
}
|
|
|
|
|
2020-06-12 20:48:52 +00:00
|
|
|
taskSorting = ['name'];
|
2020-06-11 21:23:00 +00:00
|
|
|
@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);
|
|
|
|
}
|
|
|
|
}
|