github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/ui/app/serializers/job-summary.js (about) 1 import { get } from '@ember/object'; 2 import ApplicationSerializer from './application'; 3 import classic from 'ember-classic-decorator'; 4 5 @classic 6 export default class JobSummary extends ApplicationSerializer { 7 normalize(modelClass, hash) { 8 hash.PlainJobId = hash.JobID; 9 hash.ID = JSON.stringify([hash.JobID, hash.Namespace || 'default']); 10 hash.JobID = hash.ID; 11 12 // Transform the map-based Summary object into an array-based 13 // TaskGroupSummary fragment list 14 15 const fullSummary = hash.Summary || {}; 16 hash.TaskGroupSummaries = Object.keys(fullSummary) 17 .sort() 18 .map((key) => { 19 const allocStats = fullSummary[key] || {}; 20 const summary = { Name: key }; 21 22 Object.keys(allocStats).forEach( 23 (allocKey) => (summary[`${allocKey}Allocs`] = allocStats[allocKey]) 24 ); 25 26 return summary; 27 }); 28 29 // Lift the children stats out of the Children object 30 const childrenStats = get(hash, 'Children'); 31 if (childrenStats) { 32 Object.keys(childrenStats).forEach( 33 (childrenKey) => 34 (hash[`${childrenKey}Children`] = childrenStats[childrenKey]) 35 ); 36 } 37 38 return super.normalize(modelClass, hash); 39 } 40 }