2020-05-14 19:09:09 +00:00
|
|
|
import { get } from '@ember/object';
|
|
|
|
|
2020-03-24 23:22:16 +00:00
|
|
|
export default function generateExecUrl(router, { job, taskGroup, task, allocation }) {
|
|
|
|
const queryParams = router.currentRoute.queryParams;
|
|
|
|
|
|
|
|
if (task) {
|
2020-09-15 19:48:29 +00:00
|
|
|
const queryParamsOptions = {
|
|
|
|
...queryParams,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (allocation) {
|
|
|
|
queryParamsOptions.allocation = get(allocation, 'shortId');
|
|
|
|
}
|
|
|
|
|
2020-07-20 21:07:39 +00:00
|
|
|
return router.urlFor(
|
|
|
|
'exec.task-group.task',
|
|
|
|
get(job, 'plainId'),
|
|
|
|
get(taskGroup, 'name'),
|
|
|
|
get(task, 'name'),
|
|
|
|
{
|
2020-09-15 19:48:29 +00:00
|
|
|
queryParams: queryParamsOptions,
|
2020-07-20 21:07:39 +00:00
|
|
|
}
|
|
|
|
);
|
2020-03-24 23:22:16 +00:00
|
|
|
} else if (taskGroup) {
|
2020-07-20 21:07:39 +00:00
|
|
|
return router.urlFor('exec.task-group', get(job, 'plainId'), get(taskGroup, 'name'), {
|
|
|
|
queryParams,
|
|
|
|
});
|
2020-03-24 23:22:16 +00:00
|
|
|
} else if (allocation) {
|
2020-07-20 21:07:39 +00:00
|
|
|
if (get(allocation, 'taskGroup.tasks.length') === 1) {
|
|
|
|
return router.urlFor(
|
|
|
|
'exec.task-group.task',
|
|
|
|
get(job, 'plainId'),
|
|
|
|
get(allocation, 'taskGroup.name'),
|
|
|
|
get(allocation, 'taskGroup.tasks.firstObject.name'),
|
|
|
|
{ queryParams: { allocation: get(allocation, 'shortId'), ...queryParams } }
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return router.urlFor(
|
|
|
|
'exec.task-group',
|
|
|
|
get(job, 'plainId'),
|
|
|
|
get(allocation, 'taskGroup.name'),
|
|
|
|
{ queryParams: { allocation: get(allocation, 'shortId'), ...queryParams } }
|
|
|
|
);
|
|
|
|
}
|
2020-03-24 23:22:16 +00:00
|
|
|
} else {
|
2020-05-14 19:09:09 +00:00
|
|
|
return router.urlFor('exec', get(job, 'plainId'), { queryParams });
|
2020-03-24 23:22:16 +00:00
|
|
|
}
|
|
|
|
}
|