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