github.com/aminovpavel/nomad@v0.11.8/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 { 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 8 export default Component.extend({ 9 router: service(), 10 11 isOpen: or('clickedOpen', 'currentRouteIsThisTaskGroup'), 12 13 currentRouteIsThisTaskGroup: computed('router.currentRoute', function() { 14 const route = this.router.currentRoute; 15 16 if (route.name.includes('task-group')) { 17 const taskGroupRoute = route.parent; 18 const execRoute = taskGroupRoute.parent; 19 20 return ( 21 execRoute.params.job_name === this.taskGroup.job.name && 22 taskGroupRoute.params.task_group_name === this.taskGroup.name 23 ); 24 } else { 25 return false; 26 } 27 }), 28 29 hasPendingAllocations: computed('taskGroup.allocations.@each.clientStatus', function() { 30 return this.taskGroup.allocations.any(allocation => allocation.clientStatus === 'pending'); 31 }), 32 33 allocationTaskStatesRecordArrays: mapBy('taskGroup.allocations', 'states'), 34 allocationTaskStates: computed('allocationTaskStatesRecordArrays.[]', function() { 35 const flattenRecordArrays = (accumulator, recordArray) => 36 accumulator.concat(recordArray.toArray()); 37 return this.allocationTaskStatesRecordArrays.reduce(flattenRecordArrays, []); 38 }), 39 40 activeTaskStates: filterBy('allocationTaskStates', 'isActive'), 41 42 activeTasks: mapBy('activeTaskStates', 'task'), 43 activeTaskGroups: mapBy('activeTasks', 'taskGroup'), 44 45 tasksWithRunningStates: computed( 46 'taskGroup.name', 47 'activeTaskStates.@each.name', 48 'activeTasks.@each.name', 49 'activeTaskGroups.@each.name', 50 function() { 51 const activeTaskStateNames = this.activeTaskStates 52 .filter(taskState => { 53 return taskState.task && taskState.task.taskGroup.name === this.taskGroup.name; 54 }) 55 .mapBy('name'); 56 57 return this.taskGroup.tasks.filter(task => activeTaskStateNames.includes(task.name)); 58 } 59 ), 60 61 taskSorting: Object.freeze(['name']), 62 sortedTasks: sort('tasksWithRunningStates', 'taskSorting'), 63 64 clickedOpen: false, 65 66 actions: { 67 toggleOpen() { 68 this.toggleProperty('clickedOpen'); 69 }, 70 71 openInNewWindow(job, taskGroup, task) { 72 let url = generateExecUrl(this.router, { 73 job, 74 taskGroup, 75 task, 76 }); 77 78 openExecUrl(url); 79 }, 80 }, 81 });