github.com/blixtra/nomad@v0.7.2-0.20171221000451-da9a1d7bb050/ui/app/serializers/allocation.js (about)

     1  import Ember from 'ember';
     2  import ApplicationSerializer from './application';
     3  
     4  const { get, inject } = Ember;
     5  
     6  export default ApplicationSerializer.extend({
     7    system: inject.service(),
     8  
     9    attrs: {
    10      taskGroupName: 'TaskGroup',
    11      states: 'TaskStates',
    12    },
    13  
    14    normalize(typeHash, hash) {
    15      // Transform the map-based TaskStates object into an array-based
    16      // TaskState fragment list
    17      hash.TaskStates = Object.keys(get(hash, 'TaskStates') || {}).map(key => {
    18        const state = get(hash, `TaskStates.${key}`);
    19        const summary = { Name: key };
    20        Object.keys(state).forEach(stateKey => (summary[stateKey] = state[stateKey]));
    21        summary.Resources = hash.TaskResources && hash.TaskResources[key];
    22        return summary;
    23      });
    24  
    25      hash.JobVersion = hash.JobVersion != null ? hash.JobVersion : get(hash, 'Job.Version');
    26  
    27      hash.PlainJobId = hash.JobID;
    28      hash.Namespace =
    29        hash.Namespace ||
    30        get(hash, 'Job.Namespace') ||
    31        this.get('system.activeNamespace.id') ||
    32        'default';
    33      hash.JobID = JSON.stringify([hash.JobID, hash.Namespace]);
    34  
    35      // TEMPORARY: https://github.com/emberjs/data/issues/5209
    36      hash.OriginalJobId = hash.JobID;
    37  
    38      hash.ModifyTimeNanos = hash.ModifyTime % 1000000;
    39      hash.ModifyTime = Math.floor(hash.ModifyTime / 1000000);
    40  
    41      return this._super(typeHash, hash);
    42    },
    43  });