50 lines
1.6 KiB
JavaScript
50 lines
1.6 KiB
JavaScript
import { inject as service } from '@ember/service';
|
|
import { get } from '@ember/object';
|
|
import ApplicationSerializer from './application';
|
|
|
|
export default ApplicationSerializer.extend({
|
|
system: service(),
|
|
|
|
attrs: {
|
|
taskGroupName: 'TaskGroup',
|
|
states: 'TaskStates',
|
|
},
|
|
|
|
normalize(typeHash, hash) {
|
|
// Transform the map-based TaskStates object into an array-based
|
|
// TaskState fragment list
|
|
hash.TaskStates = Object.keys(get(hash, 'TaskStates') || {}).map(key => {
|
|
const state = get(hash, `TaskStates.${key}`);
|
|
const summary = { Name: key };
|
|
Object.keys(state).forEach(stateKey => (summary[stateKey] = state[stateKey]));
|
|
summary.Resources = hash.TaskResources && hash.TaskResources[key];
|
|
return summary;
|
|
});
|
|
|
|
hash.JobVersion = hash.JobVersion != null ? hash.JobVersion : get(hash, 'Job.Version');
|
|
|
|
hash.PlainJobId = hash.JobID;
|
|
hash.Namespace =
|
|
hash.Namespace ||
|
|
get(hash, 'Job.Namespace') ||
|
|
this.get('system.activeNamespace.id') ||
|
|
'default';
|
|
hash.JobID = JSON.stringify([hash.JobID, hash.Namespace]);
|
|
|
|
// TEMPORARY: https://github.com/emberjs/data/issues/5209
|
|
hash.OriginalJobId = hash.JobID;
|
|
|
|
hash.ModifyTimeNanos = hash.ModifyTime % 1000000;
|
|
hash.ModifyTime = Math.floor(hash.ModifyTime / 1000000);
|
|
|
|
hash.RescheduleEvents = (hash.RescheduleTracker || {}).Events;
|
|
|
|
if (hash.RescheduleEvents && hash.RescheduleEvents.length) {
|
|
hash.PreviousAllocationID = hash.RescheduleEvents[0].PrevAllocID;
|
|
hash.PreviousNodeID = hash.RescheduleEvents[0].PrevNodeID;
|
|
}
|
|
|
|
return this._super(typeHash, hash);
|
|
},
|
|
});
|