github.com/manicqin/nomad@v0.9.5/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      const fullSummary = hash.Summary || {};
    13      hash.TaskGroupSummaries = Object.keys(fullSummary).map(key => {
    14        const allocStats = fullSummary[key] || {};
    15        const summary = { Name: key };
    16  
    17        Object.keys(allocStats).forEach(
    18          allocKey => (summary[`${allocKey}Allocs`] = allocStats[allocKey])
    19        );
    20  
    21        return summary;
    22      });
    23  
    24      // Lift the children stats out of the Children object
    25      const childrenStats = get(hash, 'Children');
    26      if (childrenStats) {
    27        Object.keys(childrenStats).forEach(
    28          childrenKey => (hash[`${childrenKey}Children`] = childrenStats[childrenKey])
    29        );
    30      }
    31  
    32      return this._super(modelClass, hash);
    33    },
    34  });