2020-03-25 12:51:26 +00:00
|
|
|
import ApplicationSerializer from './application';
|
|
|
|
|
|
|
|
const groupBy = (list, attr) => {
|
|
|
|
return list.reduce((group, item) => {
|
|
|
|
group[item[attr]] = item;
|
|
|
|
return group;
|
|
|
|
}, {});
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ApplicationSerializer.extend({
|
|
|
|
embed: true,
|
2020-11-25 21:44:06 +00:00
|
|
|
include: ['writeAllocs', 'readAllocs', 'allocations'],
|
2020-03-25 12:51:26 +00:00
|
|
|
|
|
|
|
serialize() {
|
|
|
|
var json = ApplicationSerializer.prototype.serialize.apply(this, arguments);
|
|
|
|
if (json instanceof Array) {
|
2020-12-07 14:51:41 +00:00
|
|
|
json.forEach(serializeVolumeFromArray);
|
2020-03-25 12:51:26 +00:00
|
|
|
} else {
|
|
|
|
serializeVolume(json);
|
|
|
|
}
|
|
|
|
return json;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2020-12-07 14:51:41 +00:00
|
|
|
function serializeVolumeFromArray(volume) {
|
|
|
|
volume.CurrentWriters = volume.WriteAllocs.length;
|
|
|
|
delete volume.WriteAllocs;
|
|
|
|
|
|
|
|
volume.CurrentReaders = volume.ReadAllocs.length;
|
|
|
|
delete volume.ReadAllocs;
|
|
|
|
}
|
|
|
|
|
2020-03-25 12:51:26 +00:00
|
|
|
function serializeVolume(volume) {
|
|
|
|
volume.WriteAllocs = groupBy(volume.WriteAllocs, 'ID');
|
|
|
|
volume.ReadAllocs = groupBy(volume.ReadAllocs, 'ID');
|
|
|
|
}
|