cms/app-client/app/serializers/transcript.js
changeset 256 18f0c3ee9aa5
parent 255 ed05b89e3299
child 257 eba9edbd8f46
equal deleted inserted replaced
255:ed05b89e3299 256:18f0c3ee9aa5
     1 import JSONAPISerializer from 'ember-data/serializers/json-api';
     1 import JSONAPISerializer from 'ember-data/serializers/json-api';
     2 
     2 
     3 export default JSONAPISerializer.extend({
     3 export default JSONAPISerializer.extend({
     4 
     4 
     5 	normalizeResponse: function(store, primaryModelClass, payload, id, requestType) {
     5     normalizeResponse: function(store, primaryModelClass, payload, id, requestType) {
     6 		var annotations = [];
     6         var lang = false;
     7 		payload.annotations.forEach(function(annotation) {
     7 
     8 			console.log('ANNOT', annotation.content.data.words);
     8         var annotations = [];
     9 			var annotationObject = {
     9         payload.annotations.forEach(function(annotation) {
    10 				'content': annotation.content.data.content,
    10             var annotationObject = {
    11 				'start': annotation.begin,
    11                 'content': annotation.content.data.content,
    12 				'end': annotation.end
    12                 'start': annotation.begin,
    13 			};
    13                 'end': annotation.end
    14 			if(annotation.content.data.transl) {
    14             };
    15 				annotationObject.translation = annotation.content.data.transl['@value'];
    15             if(annotation.content.data.transl) {
    16 			}
    16                 annotationObject.translation = annotation.content.data.transl['@value'];
    17 			if(annotation.content.data.words) {
    17                 if (!lang) {
    18 				var words = [];
    18                     lang = annotation.content.data.transl['@language'];    
    19 				annotation.content.data.words.forEach(function(word) {
    19                 }
    20 					var wordObject = {
    20             }
    21 						'content': word.content,
    21             if(annotation.content.data.words) {
    22 						'translation': word.transl['@value']
    22                 var words = [];
    23 					};
    23                 annotation.content.data.words.forEach(function(word) {
    24 					words.push(wordObject);
    24                     var wordObject = {
    25 				})
    25                         'content': word.content,
    26 				annotationObject.words = words;
    26                         'translation': word.transl['@value']
    27 			}
    27                     };
    28 			annotations.push(annotationObject);
    28                     words.push(wordObject);
    29 		});
    29                 })
    30         return {
    30                 annotationObject.words = words;
       
    31             }
       
    32             annotations.push(annotationObject);
       
    33         });
       
    34 
       
    35         var response = {
    31             'data': {
    36             'data': {
    32 	            'id': id,
    37                 'id': id,
    33 	            'type': 'transcript',
    38                 'type': 'transcript',
    34 	            'attributes': {
    39                 'attributes': {
    35 	                'title': payload.meta['dc:title']['@value'],
    40                     'title': {},
    36 	                'annotations': annotations
    41                     'annotations': annotations
    37 	            }
    42                 }
    38 	        }
    43             }
    39         };
    44         };
    40 	}
    45 
       
    46         if(Array.isArray(payload.meta['dc:title'])) {
       
    47             var original = payload.meta['dc:title'].find(function(title) { return title['@language'] !== lang; });
       
    48             var translation = payload.meta['dc:title'].find(function(title) { return title['@language'] === lang; });
       
    49             if(original) {
       
    50                 response.data.attributes.title.original = original['@value'];
       
    51             }
       
    52             if(translation) {
       
    53                 response.data.attributes.title.translation = translation['@value'];
       
    54             }            
       
    55         } else {
       
    56             response.data.attributes.title.original = payload.meta['dc:title']['@value'];
       
    57         }
       
    58 
       
    59 
       
    60         return response;
       
    61     }
    41 
    62 
    42 });
    63 });