Small tweaks to Annotation API and json project API and mdplayer widgets CreateAnnotation and AnnotationList to allow CreateAnnotation to create annotations on a specific project and AnnotationList to display different annotation types as well as filtering annotations based on current segment
authordurandn
Wed, 10 Jun 2015 12:19:26 +0200
changeset 1387 82d256129376
parent 1381 44ccf39aaf42
child 1388 cc17e3d211cd
Small tweaks to Annotation API and json project API and mdplayer widgets CreateAnnotation and AnnotationList to allow CreateAnnotation to create annotations on a specific project and AnnotationList to display different annotation types as well as filtering annotations based on current segment
src/ldt/ldt/api/ldt/resources/annotation.py
src/ldt/ldt/ldt_utils/views/ldt_json.py
src/ldt/ldt/static/ldt/metadataplayer/AnnotationsList.js
src/ldt/ldt/static/ldt/metadataplayer/CreateAnnotation.js
src/ldt/ldt/static/ldt/metadataplayer/LdtPlayer-core.js
--- a/src/ldt/ldt/api/ldt/resources/annotation.py	Thu May 28 11:03:58 2015 +0200
+++ b/src/ldt/ldt/api/ldt/resources/annotation.py	Wed Jun 10 12:19:26 2015 +0200
@@ -84,7 +84,7 @@
         meta = a['meta']
         author = meta['creator']
         date = meta['created']
-        #                       add(media,      cutting_id, cutting_title,  title,               text,                         tags_list,  begin, dur, author, date
+        #                                    add(media,      cutting_id, cutting_title,  title,                 text,                        tags_list, begin, dur, author, date
         type_id, new_id, ensemble_id = adder.add(a['media'], a['type'], a['type_title'], a['content']['title'], a['content']['description'], a['tags'], begin, dur, author, date, None, "2194379", audio_src, audio_href)
         if not new_id:
             protect_models()
--- a/src/ldt/ldt/ldt_utils/views/ldt_json.py	Thu May 28 11:03:58 2015 +0200
+++ b/src/ldt/ldt/ldt_utils/views/ldt_json.py	Wed Jun 10 12:19:26 2015 +0200
@@ -72,9 +72,12 @@
     one_content_bool = False
     if one_content_str:
         one_content_bool = {'true': True, 'false': False, "0": False, "1": True}.get(one_content_str.lower())
-        
-        
-    ps = ProjectJsonSerializer(project, serialize_contents, first_cutting=first_cutting)
+    
+    from_display_str = request.GET.get("from_display")
+    from_display_bool = True
+    if from_display_str:
+        from_display_bool = {'true': True, 'false': False, "0": False, "1": True}.get(from_display_str.lower())
+    ps = ProjectJsonSerializer(project, serialize_contents, from_display=from_display_bool, first_cutting=first_cutting)
     project_dict = ps.serialize_to_cinelab(one_content_bool)
     
     json_str = json.dumps(project_dict, ensure_ascii=False, indent=indent)
--- a/src/ldt/ldt/static/ldt/metadataplayer/AnnotationsList.js	Thu May 28 11:03:58 2015 +0200
+++ b/src/ldt/ldt/static/ldt/metadataplayer/AnnotationsList.js	Wed Jun 10 12:19:26 2015 +0200
@@ -12,16 +12,21 @@
 IriSP.Widgets.AnnotationsList.prototype = new IriSP.Widgets.Widget();
 
 IriSP.Widgets.AnnotationsList.prototype.defaults = {
-    /* URL when the annotations are to be reloaded from an LDT-like segment API
-     * e.g. http://ldt.iri.centrepompidou.fr/ldtplatform/api/ldt/segments/{{media}}/{{begin}}/{{end}}?callback=?
+    /*
+     * URL when the annotations are to be reloaded from an LDT-like segment API
+     * e.g.
+     * http://ldt.iri.centrepompidou.fr/ldtplatform/api/ldt/segments/{{media}}/{{begin}}/{{end}}?callback=?
      */
     ajax_url : false,
-    /* number of milliseconds before/after the current timecode when calling the segment API
+    /*
+     * number of milliseconds before/after the current timecode when calling the
+     * segment API
      */
     ajax_granularity : 600000, 
     default_thumbnail : "",
-    /* URL when the annotation is not in the current project,
-     * e.g. http://ldt.iri.centrepompidou.fr/ldtplatform/ldt/front/player/{{media}}/{{project}}/{{annotationType}}#id={{annotation}}
+    /*
+     * URL when the annotation is not in the current project, e.g.
+     * http://ldt.iri.centrepompidou.fr/ldtplatform/ldt/front/player/{{media}}/{{project}}/{{annotationType}}#id={{annotation}}
      */
     foreign_url : "",
     annotation_type : false,
@@ -29,6 +34,8 @@
     limit_count : 20,
     newest_first : false,
     show_audio: true,
+    filter_by_segments: false,
+    segments_annotation_type: "chap",
     polemics : [{
         keyword: "++",
         background_color: "#c9ecc6"
@@ -88,7 +95,8 @@
     + '{{#audio}}<div class="Ldt-AnnotationsList-Play" data-annotation-id="{{id}}">{{l10n.voice_annotation}}</div>{{/audio}}'
     + '</li>';
 
-//obj.url = this.project_url + "/" + media + "/" + annotations[i].meta.project + "/" + annotations[i].meta["id-ref"] + '#id=' + annotations[i].id;
+// obj.url = this.project_url + "/" + media + "/" + annotations[i].meta.project
+// + "/" + annotations[i].meta["id-ref"] + '#id=' + annotations[i].id;
 
 IriSP.Widgets.AnnotationsList.prototype.ajaxSource = function() {
     var _currentTime = this.media.getCurrentTime(),
@@ -142,6 +150,27 @@
     _list = _list.filter(function(_annotation) {
         return _annotation.found !== false;
     });
+    if (this.filter_by_segments) {
+        /*
+         *  A given annotation is considered "in" segment if the middle of it is between the segment beginning and the segment end. 
+         *  Note this is meant to be used for "markings" annotations (not segments)
+         */
+        _segments_annotations = this.currentSource.getAnnotationsByTypeTitle(this.segments_annotation_type)
+        _current_segments = _segments_annotations.filter(function(_segment){
+            return (_currentTime >= _segment.begin && _currentTime <= _segment.end)
+        });
+        if (_current_segments.length == 0) {
+            _list = [];
+        }
+        else {
+            _list = _list.filter(function(_annotation){
+                _annotation_time = (_annotation.begin+_annotation.end)/2;
+                return (_current_segments[0].begin <= _annotation_time && _current_segments[0].end >= _annotation_time)
+            });
+        }
+        
+        
+    }
     if (this.limit_count) {
         /* Get the n annotations closest to current timecode */
         _list = _list.sortBy(function(_annotation) {
@@ -188,13 +217,13 @@
                 _thumbnail = (typeof _annotation.thumbnail !== "undefined" && _annotation.thumbnail ? _annotation.thumbnail : _this.default_thumbnail);
             // Update : display creator
             if (_annotation.creator) {
-            	_title = _annotation.creator;
+                _title = _annotation.creator;
             }
             if (_annotation.title) {
-            	var tempTitle = _annotation.title;
-            	if( tempTitle.substr(0, _title.length + 1) == (_title + ":") ){
-            		_title = "";
-            	}
+                var tempTitle = _annotation.title;
+                if( tempTitle.substr(0, _title.length + 1) == (_title + ":") ){
+                    _title = "";
+                }
                 _title = _title + ( (_title=="") ? "" : ": ") + _annotation.title;
             }
             var _bgcolor;
@@ -263,10 +292,10 @@
                 })
                 .appendTo(_this.list_$);
             IriSP.attachDndData(_el.find("[draggable]"), {
-            	title: _title,
-            	description: _description,
-            	uri: _url,
-            	image: _annotation.thumbnail
+                title: _title,
+                description: _description,
+                uri: _url,
+                image: _annotation.thumbnail
             });
             _el.on("remove", function() {
                 _annotation.off("select", _onselect);
--- a/src/ldt/ldt/static/ldt/metadataplayer/CreateAnnotation.js	Thu May 28 11:03:58 2015 +0200
+++ b/src/ldt/ldt/static/ldt/metadataplayer/CreateAnnotation.js	Wed Jun 10 12:19:26 2015 +0200
@@ -44,6 +44,7 @@
     api_serializer: "ldt_annotate",
     api_endpoint_template: "",
     api_method: "POST",
+    project_id: "",
     after_send_timeout: 0,
     close_after_send: false,
     tag_prefix: "#"
@@ -408,6 +409,9 @@
     if (this.show_title_field) {
         /* Champ titre, seulement s'il est visible */
         _annotation.title = this.$.find(".Ldt-CreateAnnotation-Title").val();
+    }if (this.project_id != ""){
+    	/* Champ id projet, seulement si on l'a renseigné dans la config */
+    	_annotation.project_id = this.project_id;
     }
     _annotation.created = new Date(); /* Date de création de l'annotation */
     _annotation.description = this.$.find(".Ldt-CreateAnnotation-Description").val(); /* Champ description */
@@ -449,7 +453,7 @@
     }
     _exportedAnnotations.push(_annotation); /* Ajout de l'annotation à la liste à exporter */
     _export.addList("annotation",_exportedAnnotations); /* Ajout de la liste à exporter à l'objet Source */
-    
+    console.log(_export)
     var _this = this;
     /* Envoi de l'annotation via AJAX au serveur ! */
     IriSP.jQuery.ajax({
--- a/src/ldt/ldt/static/ldt/metadataplayer/LdtPlayer-core.js	Thu May 28 11:03:58 2015 +0200
+++ b/src/ldt/ldt/static/ldt/metadataplayer/LdtPlayer-core.js	Wed Jun 10 12:19:26 2015 +0200
@@ -1915,6 +1915,7 @@
             },
             tags: _data.getTagTexts(),
             media: _data.getMedia().id,
+            project: _data.project_id,
             type_title: _annType.title,
             type: ( typeof _annType.dont_send_id !== "undefined" && _annType.dont_send_id ? "" : _annType.id ),
             meta: {