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