github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/ui/app/controllers/jobs/job/services/index.js (about) 1 import Controller from '@ember/controller'; 2 import WithNamespaceResetting from 'nomad-ui/mixins/with-namespace-resetting'; 3 import Sortable from 'nomad-ui/mixins/sortable'; 4 import { alias } from '@ember/object/computed'; 5 import { computed } from '@ember/object'; 6 import { union } from '@ember/object/computed'; 7 8 export default class JobsJobServicesIndexController extends Controller.extend( 9 WithNamespaceResetting, 10 Sortable 11 ) { 12 @alias('model') job; 13 @alias('job.taskGroups') taskGroups; 14 15 queryParams = [ 16 { 17 sortProperty: 'sort', 18 }, 19 { 20 sortDescending: 'desc', 21 }, 22 ]; 23 24 sortProperty = 'name'; 25 sortDescending = false; 26 27 @alias('services') listToSort; 28 @alias('listSorted') sortedServices; 29 30 @computed('taskGroups.@each.tasks') 31 get tasks() { 32 return this.taskGroups.map((group) => group.tasks.toArray()).flat(); 33 } 34 35 @computed('tasks.@each.services') 36 get taskServices() { 37 return this.tasks 38 .map((t) => (t.services || []).toArray()) 39 .flat() 40 .compact() 41 .map((service) => { 42 service.level = 'task'; 43 return service; 44 }); 45 } 46 47 @computed('model.taskGroup.services.@each.name', 'taskGroups') 48 get groupServices() { 49 return this.taskGroups 50 .map((g) => (g.services || []).toArray()) 51 .flat() 52 .compact() 53 .map((service) => { 54 service.level = 'group'; 55 return service; 56 }); 57 } 58 59 @union('taskServices', 'groupServices') serviceFragments; 60 61 // Services, grouped by name, with aggregatable allocations. 62 @computed( 63 'job.services.@each.{name,allocation}', 64 'job.services.length', 65 'serviceFragments' 66 ) 67 get services() { 68 return this.serviceFragments.map((fragment) => { 69 fragment.instances = this.job.services.filter( 70 (s) => s.name === fragment.name && s.derivedLevel === fragment.level 71 ); 72 return fragment; 73 }); 74 } 75 }