github.com/hernad/nomad@v1.6.112/ui/app/components/exec/task-group-parent.js (about)

     1  /**
     2   * Copyright (c) HashiCorp, Inc.
     3   * SPDX-License-Identifier: MPL-2.0
     4   */
     5  
     6  import Component from '@ember/component';
     7  import { inject as service } from '@ember/service';
     8  import { action, computed } from '@ember/object';
     9  import { filterBy, mapBy, or, sort } from '@ember/object/computed';
    10  import generateExecUrl from 'nomad-ui/utils/generate-exec-url';
    11  import openExecUrl from 'nomad-ui/utils/open-exec-url';
    12  import classic from 'ember-classic-decorator';
    13  
    14  @classic
    15  export default class TaskGroupParent extends Component {
    16    @service router;
    17  
    18    @or('clickedOpen', 'currentRouteIsThisTaskGroup') isOpen;
    19  
    20    @computed('router.currentRoute', 'taskGroup.{job.name,name}')
    21    get currentRouteIsThisTaskGroup() {
    22      const route = this.router.currentRoute;
    23  
    24      if (route.name.includes('task-group')) {
    25        const taskGroupRoute = route.parent;
    26        const execRoute = taskGroupRoute.parent;
    27  
    28        return (
    29          execRoute.params.job_name === this.taskGroup.job.name &&
    30          taskGroupRoute.params.task_group_name === this.taskGroup.name
    31        );
    32      } else {
    33        return false;
    34      }
    35    }
    36  
    37    @computed('taskGroup.allocations.@each.clientStatus')
    38    get hasPendingAllocations() {
    39      return this.taskGroup.allocations.any(
    40        (allocation) => allocation.clientStatus === 'pending'
    41      );
    42    }
    43  
    44    @mapBy('taskGroup.allocations', 'states') allocationTaskStatesRecordArrays;
    45    @computed('allocationTaskStatesRecordArrays.[]')
    46    get allocationTaskStates() {
    47      const flattenRecordArrays = (accumulator, recordArray) =>
    48        accumulator.concat(recordArray.toArray());
    49      return this.allocationTaskStatesRecordArrays.reduce(
    50        flattenRecordArrays,
    51        []
    52      );
    53    }
    54  
    55    @filterBy('allocationTaskStates', 'isActive') activeTaskStates;
    56  
    57    @mapBy('activeTaskStates', 'task') activeTasks;
    58    @mapBy('activeTasks', 'taskGroup') activeTaskGroups;
    59  
    60    @computed(
    61      'activeTaskGroups.@each.name',
    62      'activeTaskStates.@each.name',
    63      'activeTasks.@each.name',
    64      'taskGroup.{name,tasks}'
    65    )
    66    get tasksWithRunningStates() {
    67      const activeTaskStateNames = this.activeTaskStates
    68        .filter((taskState) => {
    69          return (
    70            taskState.task &&
    71            taskState.task.taskGroup.name === this.taskGroup.name
    72          );
    73        })
    74        .mapBy('name');
    75  
    76      return this.taskGroup.tasks.filter((task) =>
    77        activeTaskStateNames.includes(task.name)
    78      );
    79    }
    80  
    81    taskSorting = ['name'];
    82    @sort('tasksWithRunningStates', 'taskSorting') sortedTasks;
    83  
    84    clickedOpen = false;
    85  
    86    @action
    87    toggleOpen() {
    88      this.toggleProperty('clickedOpen');
    89    }
    90  
    91    @action
    92    openInNewWindow(job, taskGroup, task) {
    93      let url = generateExecUrl(this.router, {
    94        job,
    95        taskGroup,
    96        task,
    97      });
    98  
    99      openExecUrl(url);
   100    }
   101  }