import JSONAPISerializer from 'ember-data/serializers/json-api';
export default JSONAPISerializer.extend({
normalizeResponse: function(store, primaryModelClass, payload, id, requestType) {
var annotations = [];
payload.annotations.forEach(function(annotation) {
console.log('ANNOT', annotation.content.data.words);
var annotationObject = {
'content': annotation.content.data.content,
'start': annotation.begin,
'end': annotation.end
};
if(annotation.content.data.transl) {
annotationObject.translation = annotation.content.data.transl['@value'];
}
if(annotation.content.data.words) {
var words = [];
annotation.content.data.words.forEach(function(word) {
var wordObject = {
'content': word.content,
'translation': word.transl['@value']
};
words.push(wordObject);
})
annotationObject.words = words;
}
annotations.push(annotationObject);
});
return {
'data': {
'id': id,
'type': 'transcript',
'attributes': {
'title': payload.meta['dc:title']['@value'],
'annotations': annotations
}
}
};
}
});