github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/ui/app/utils/generate-exec-url.js (about)

     1  import { get } from '@ember/object';
     2  
     3  export default function generateExecUrl(router, { job, taskGroup, task, allocation }) {
     4    const queryParams = {};
     5  
     6    const namespace = get(job, 'namespace.name');
     7    const region = get(job, 'region');
     8  
     9    if (namespace) {
    10      queryParams.namespace = namespace;
    11    }
    12  
    13    if (region) {
    14      queryParams.region = region;
    15    }
    16  
    17    if (task) {
    18      const queryParamsOptions = {
    19        ...queryParams,
    20      };
    21  
    22      if (allocation) {
    23        queryParamsOptions.allocation = get(allocation, 'shortId');
    24      }
    25  
    26      return router.urlFor(
    27        'exec.task-group.task',
    28        get(job, 'plainId'),
    29        get(taskGroup, 'name'),
    30        get(task, 'name'),
    31        {
    32          queryParams: queryParamsOptions,
    33        }
    34      );
    35    } else if (taskGroup) {
    36      return router.urlFor('exec.task-group', get(job, 'plainId'), get(taskGroup, 'name'), {
    37        queryParams,
    38      });
    39    } else if (allocation) {
    40      if (get(allocation, 'taskGroup.tasks.length') === 1) {
    41        return router.urlFor(
    42          'exec.task-group.task',
    43          get(job, 'plainId'),
    44          get(allocation, 'taskGroup.name'),
    45          get(allocation, 'taskGroup.tasks.firstObject.name'),
    46          { queryParams: { allocation: get(allocation, 'shortId'), ...queryParams } }
    47        );
    48      } else {
    49        return router.urlFor(
    50          'exec.task-group',
    51          get(job, 'plainId'),
    52          get(allocation, 'taskGroup.name'),
    53          { queryParams: { allocation: get(allocation, 'shortId'), ...queryParams } }
    54        );
    55      }
    56    } else {
    57      return router.urlFor('exec', get(job, 'plainId'), { queryParams });
    58    }
    59  }