Add title translation to transcript
authorChloe Laisne <chloe.laisne@gmail.com>
Thu, 18 Aug 2016 17:02:02 +0200
changeset 256 18f0c3ee9aa5
parent 255 ed05b89e3299
child 257 eba9edbd8f46
Add title translation to transcript
cms/app-client/app/serializers/transcript.js
cms/app-client/app/styles/components/transcript-component.scss
cms/app-client/app/templates/components/transcript-component.hbs
--- a/cms/app-client/app/serializers/transcript.js	Wed Aug 17 15:30:19 2016 +0200
+++ b/cms/app-client/app/serializers/transcript.js	Thu Aug 18 17:02:02 2016 +0200
@@ -2,41 +2,62 @@
 
 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 {
+    normalizeResponse: function(store, primaryModelClass, payload, id, requestType) {
+        var lang = false;
+
+        var annotations = [];
+        payload.annotations.forEach(function(annotation) {
+            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 (!lang) {
+                    lang = annotation.content.data.transl['@language'];    
+                }
+            }
+            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);
+        });
+
+        var response = {
             'data': {
-	            'id': id,
-	            'type': 'transcript',
-	            'attributes': {
-	                'title': payload.meta['dc:title']['@value'],
-	                'annotations': annotations
-	            }
-	        }
+                'id': id,
+                'type': 'transcript',
+                'attributes': {
+                    'title': {},
+                    'annotations': annotations
+                }
+            }
         };
-	}
+
+        if(Array.isArray(payload.meta['dc:title'])) {
+            var original = payload.meta['dc:title'].find(function(title) { return title['@language'] !== lang; });
+            var translation = payload.meta['dc:title'].find(function(title) { return title['@language'] === lang; });
+            if(original) {
+                response.data.attributes.title.original = original['@value'];
+            }
+            if(translation) {
+                response.data.attributes.title.translation = translation['@value'];
+            }            
+        } else {
+            response.data.attributes.title.original = payload.meta['dc:title']['@value'];
+        }
+
+
+        return response;
+    }
 
 });
--- a/cms/app-client/app/styles/components/transcript-component.scss	Wed Aug 17 15:30:19 2016 +0200
+++ b/cms/app-client/app/styles/components/transcript-component.scss	Thu Aug 18 17:02:02 2016 +0200
@@ -14,9 +14,15 @@
     z-index: 1;
     width: inherit;
     background: linear-gradient($light-blue, $light-blue 50%, transparent);
-    padding-bottom: 54px;
+    padding-top: 12px;
+    padding-bottom: 66px;
     line-height: 30px;
-    margin: 12px auto;
+    margin: 0px!important;
+}
+
+.transcript-component h2 span{
+    display: block;
+     color: $medium-grey; 
 }
 
 body.videoscreen .transcript-component h2 {
--- a/cms/app-client/app/templates/components/transcript-component.hbs	Wed Aug 17 15:30:19 2016 +0200
+++ b/cms/app-client/app/templates/components/transcript-component.hbs	Thu Aug 18 17:02:02 2016 +0200
@@ -1,4 +1,9 @@
-<h2>{{player.transcript.title}}</h2>
+<h2>
+	{{player.transcript.title.original}}
+{{#if player.transcript.title.translation}}
+	<span>{{player.transcript.title.translation}}</span>
+{{/if}}
+</h2>
 <ol class="transcript">
 {{#each player.transcript.annotations as |annotation|}}
 {{log 'each-annotation'}}