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