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