github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/ui/app/components/exec/task-group-parent.js (about)

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