open-nomad/ui/mirage/serializers/allocation.js
Alex Dadgar e5ec915ac3 sync
2017-09-19 10:08:23 -05:00

23 lines
667 B
JavaScript

import ApplicationSerializer from './application';
import { arrToObj } from '../utils';
export default ApplicationSerializer.extend({
embed: true,
include: ['task_states', 'task_resources'],
serialize() {
var json = ApplicationSerializer.prototype.serialize.apply(this, arguments);
if (json instanceof Array) {
json.forEach(serializeAllocation);
} else {
serializeAllocation(json);
}
return json;
},
});
function serializeAllocation(allocation) {
allocation.TaskStates = allocation.TaskStates.reduce(arrToObj('Name'), {});
allocation.TaskResources = allocation.TaskResources.reduce(arrToObj('Name', 'Resources'), {});
}