github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/ui/app/utils/generate-exec-url.js (about) 1 import { get } from '@ember/object'; 2 3 export default function generateExecUrl( 4 router, 5 { job, taskGroup, task, allocation } 6 ) { 7 const queryParams = {}; 8 9 const namespace = get(job, 'namespace.name'); 10 const region = get(job, 'region'); 11 12 if (namespace) { 13 queryParams.namespace = namespace; 14 } 15 16 if (region) { 17 queryParams.region = region; 18 } 19 20 if (task) { 21 const queryParamsOptions = { 22 ...queryParams, 23 }; 24 25 if (allocation) { 26 queryParamsOptions.allocation = get(allocation, 'shortId'); 27 } 28 29 return router.urlFor( 30 'exec.task-group.task', 31 get(job, 'plainId'), 32 get(taskGroup, 'name'), 33 get(task, 'name'), 34 { 35 queryParams: queryParamsOptions, 36 } 37 ); 38 } else if (taskGroup) { 39 return router.urlFor( 40 'exec.task-group', 41 get(job, 'plainId'), 42 get(taskGroup, 'name'), 43 { 44 queryParams, 45 } 46 ); 47 } else if (allocation) { 48 if (get(allocation, 'taskGroup.tasks.length') === 1) { 49 return router.urlFor( 50 'exec.task-group.task', 51 get(job, 'plainId'), 52 get(allocation, 'taskGroup.name'), 53 get(allocation, 'taskGroup.tasks.firstObject.name'), 54 { 55 queryParams: { 56 allocation: get(allocation, 'shortId'), 57 ...queryParams, 58 }, 59 } 60 ); 61 } else { 62 return router.urlFor( 63 'exec.task-group', 64 get(job, 'plainId'), 65 get(allocation, 'taskGroup.name'), 66 { 67 queryParams: { 68 allocation: get(allocation, 'shortId'), 69 ...queryParams, 70 }, 71 } 72 ); 73 } 74 } else { 75 return router.urlFor('exec', get(job, 'plainId'), { queryParams }); 76 } 77 }