--- a/cms/app-client/app/serializers/transcript.js Sun Aug 21 13:51:22 2016 +0200
+++ b/cms/app-client/app/serializers/transcript.js Tue Aug 23 00:32:11 2016 +0200
@@ -4,6 +4,7 @@
normalizeResponse: function(store, primaryModelClass, payload, id) {
var speakers = payload['resources'].find(resource => resource['id'] === 'speakers');
+ var topics = payload['resources'].find(resource => resource['id'] === 'topics');
var translationISO = false;
var buildFragment = function(annotation) {
@@ -47,10 +48,6 @@
'begin': annotation['begin'],
'end': annotation['end'],
};
- var information = payload['annotation-types'].find(function(t) { return t['corpus:begin'] === annotation['begin'] && t['corpus:end'] === annotation['end']; });
- if(information) {
- object.title = information['dc:title'];
- }
annotations.push(object);
}
if(!translationISO && annotation['content']['data']['transl']) {
@@ -58,6 +55,41 @@
}
});
+ if(payload['annotation-types'].length) {
+ var types = [];
+ payload['annotation-types'].forEach(function(t) {
+ var object = {
+ 'title': t['dc:title'],
+ 'begin': t['corpus:begin'],
+ 'end': t['corpus:end']
+ };
+ var fragments = annotations.find(function(annotation) { return annotation['begin'] === t['corpus:begin'] && annotation['end'] === t['corpus:end']; });
+ if(fragments) {
+ object['fragments'] = fragments['fragments'];
+ }
+ types.push(object);
+ });
+ annotations = types;
+ }
+
+ if(payload['lists'].length) {
+ var sections = [];
+ var lists = [];
+ payload['lists'].forEach(function(list) {
+ var topic = topics['content']['data'].find(topic => topic.id === list['meta']['corpus:topic']['id-ref']);
+ sections.push({
+ 'title': topic['desc'],
+ 'begin': list['meta']['corpus:begin'],
+ 'end': list['meta']['corpus:end']
+ });
+ lists.push(annotations.filter(annotation => annotation['begin'] >= list['meta']['corpus:begin'] && annotation['end'] <= list['meta']['corpus:end']));
+ });
+ annotations = lists;
+ console.log(sections);
+ } else {
+ annotations = [annotations];
+ }
+
var response = {
'data': {
'id': id,
@@ -69,6 +101,10 @@
}
};
+ if(sections) {
+ response.data.attributes.sections = sections;
+ }
+
if(Array.isArray(payload['meta']['dc:title'])) {
var original = payload['meta']['dc:title'].find(function(title) { return title['@language'] !== translationISO; });
if(original) {