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