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