2017-12-15 21:39:18 +00:00
|
|
|
import { inject as service } from '@ember/service';
|
|
|
|
import { get } from '@ember/object';
|
2017-09-19 14:47:10 +00:00
|
|
|
import ApplicationSerializer from './application';
|
|
|
|
|
|
|
|
export default ApplicationSerializer.extend({
|
2017-12-15 21:39:18 +00:00
|
|
|
system: service(),
|
2017-10-23 17:22:58 +00:00
|
|
|
|
2017-09-19 14:47:10 +00:00
|
|
|
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;
|
|
|
|
});
|
|
|
|
|
2017-10-19 17:17:04 +00:00
|
|
|
hash.JobVersion = hash.JobVersion != null ? hash.JobVersion : get(hash, 'Job.Version');
|
|
|
|
|
2017-10-23 17:22:58 +00:00
|
|
|
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]);
|
|
|
|
|
2017-10-05 22:21:10 +00:00
|
|
|
// TEMPORARY: https://github.com/emberjs/data/issues/5209
|
|
|
|
hash.OriginalJobId = hash.JobID;
|
|
|
|
|
2017-11-30 23:08:31 +00:00
|
|
|
hash.ModifyTimeNanos = hash.ModifyTime % 1000000;
|
|
|
|
hash.ModifyTime = Math.floor(hash.ModifyTime / 1000000);
|
|
|
|
|
2017-09-19 14:47:10 +00:00
|
|
|
return this._super(typeHash, hash);
|
|
|
|
},
|
|
|
|
});
|