github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/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(
    35        (allocation) => allocation.clientStatus === 'pending'
    36      );
    37    }
    38  
    39    @mapBy('taskGroup.allocations', 'states') allocationTaskStatesRecordArrays;
    40    @computed('allocationTaskStatesRecordArrays.[]')
    41    get allocationTaskStates() {
    42      const flattenRecordArrays = (accumulator, recordArray) =>
    43        accumulator.concat(recordArray.toArray());
    44      return this.allocationTaskStatesRecordArrays.reduce(
    45        flattenRecordArrays,
    46        []
    47      );
    48    }
    49  
    50    @filterBy('allocationTaskStates', 'isActive') activeTaskStates;
    51  
    52    @mapBy('activeTaskStates', 'task') activeTasks;
    53    @mapBy('activeTasks', 'taskGroup') activeTaskGroups;
    54  
    55    @computed(
    56      'activeTaskGroups.@each.name',
    57      'activeTaskStates.@each.name',
    58      'activeTasks.@each.name',
    59      'taskGroup.{name,tasks}'
    60    )
    61    get tasksWithRunningStates() {
    62      const activeTaskStateNames = this.activeTaskStates
    63        .filter((taskState) => {
    64          return (
    65            taskState.task &&
    66            taskState.task.taskGroup.name === this.taskGroup.name
    67          );
    68        })
    69        .mapBy('name');
    70  
    71      return this.taskGroup.tasks.filter((task) =>
    72        activeTaskStateNames.includes(task.name)
    73      );
    74    }
    75  
    76    taskSorting = ['name'];
    77    @sort('tasksWithRunningStates', 'taskSorting') sortedTasks;
    78  
    79    clickedOpen = false;
    80  
    81    @action
    82    toggleOpen() {
    83      this.toggleProperty('clickedOpen');
    84    }
    85  
    86    @action
    87    openInNewWindow(job, taskGroup, task) {
    88      let url = generateExecUrl(this.router, {
    89        job,
    90        taskGroup,
    91        task,
    92      });
    93  
    94      openExecUrl(url);
    95    }
    96  }