Added filter into AnnotationsList so that it displays only the latest annotation for each user that made an annotation 00.00.17
authordurandn
Thu, 10 Sep 2015 15:47:00 +0200
changeset 120 93af8545dd96
parent 119 5f78fdba6ecc
child 121 e8a484a9bc98
Added filter into AnnotationsList so that it displays only the latest annotation for each user that made an annotation
server/src/remie/static/remie/metadataplayer/AnnotationsList.js
server/src/remie/templates/remie/iframe_segments_group.html
--- a/server/src/remie/static/remie/metadataplayer/AnnotationsList.js	Thu Sep 10 14:10:06 2015 +0200
+++ b/server/src/remie/static/remie/metadataplayer/AnnotationsList.js	Thu Sep 10 15:47:00 2015 +0200
@@ -37,14 +37,22 @@
     start_visible: true,
     show_audio : true,
     show_filters : false,
+    keyword_filter: true,
+    date_filter: true,
+    user_filter: true,
+    segment_filter: true,
+    latest_contributions_filter: false,
+    current_day_filter: true,
     show_header : false,
     custom_header : false,
+    annotation_count_header : true,
     show_creation_date : false,
     show_timecode : true,
     /*
      * Only annotation in the current segment will be displayed. Designed to work with the Segments Widget.
      */
     filter_by_segments: false,
+    segment_filter: true,
     segments_annotation_type: "chap",
     /*
      * Set to a username if you only want to display annotations from a given user
@@ -53,7 +61,6 @@
     /*
      * Show a text field that filter annotations by username
      */
-    filter_by_user: false,
     tags : true,
     polemics : [{
         keyword: "++",
@@ -75,13 +82,17 @@
         voice_annotation: "Voice Annotation",
         now_playing: "Now playing...",
         everyone: "Everyone",
-        header: "Annotations for this content"
+        header: "Annotations for this content",
+        segment_filter: "All cuttings",
+        latest_contributions: "Latest contributions",
     },
     fr: {
         voice_annotation: "Annotation Vocale",
         now_playing: "Lecture en cours...",
         everyone: "Tous",
-        header: "Annotations sur ce contenu"
+        header: "Annotations sur ce contenu",
+        segment_filter: "Tous les segments",
+        latest_contributions: "Dernières contributions",
     }
 };
 
@@ -93,10 +104,11 @@
     + '<div class="Ldt-AnnotationsListWidget">'
     + '{{#show_filters}}'
     + '<div class="Ldt-AnnotationsList-Filters">'
-    +    '<input class="Ldt-AnnotationsList-filter-text" id="Ldt-AnnotationsList-keywordsFilter" type="text" value=""></input>'
-    +    '<select class="Ldt-AnnotationsList-filter-dropdown" id="Ldt-AnnotationsList-userFilter"><option selected value="">{{l10n.everyone}}</option></select>'
-    +    '<label class="Ldt-AnnotationsList-filter-date">Date: <input id="Ldt-AnnotationsList-dateFilter" type="text"></input></label>'
-    +    '<label class="Ldt-AnnotationsList-filter-checkbox"><input type="checkbox" id="Ldt-AnnotationsList-ignoreSegmentsFilter">Toutes annotations</label>'
+    +    '{{#keyword_filter}}<input class="Ldt-AnnotationsList-filter-text" id="Ldt-AnnotationsList-keywordsFilter" type="text" value=""></input>{{/keyword_filter}}'
+    +    '{{#user_filter}}<select class="Ldt-AnnotationsList-filter-dropdown" id="Ldt-AnnotationsList-userFilter"><option selected value="">{{l10n.everyone}}</option></select>{{/user_filter}}'
+    +    '{{#date_filter}}<label class="Ldt-AnnotationsList-filter-date">Date: <input id="Ldt-AnnotationsList-dateFilter" type="text"></input></label>{{/date_filter}}'
+    +    '{{#segment_filter}}<label class="Ldt-AnnotationsList-filter-checkbox"><input type="checkbox" id="Ldt-AnnotationsList-ignoreSegmentsFilter">{{l10n.segment_filter}}</label>{{/segment_filter}}'
+    +    '{{#latest_contributions_filter}}<label class="Ldt-AnnotationsList-filter-checkbox"><input type="checkbox" id="Ldt-AnnotationsList-latestContributionsFilter">{{l10n.latest_contributions}}</label>{{/latest_contributions_filter}}'
     + '</div>'
     + '{{/show_filters}}'
     + '{{#show_audio}}<div class="Ldt-AnnotationsList-Audio"></div>{{/show_audio}}'
@@ -189,7 +201,7 @@
         return _annotation.found !== false;
     });
     
-    if ((this.filter_by_segments)&&(!(this.show_filters && this.ignoresegmentcheckbox_$[0].checked))) {
+    if ((this.filter_by_segments)&&(!(this.show_filters && this.segment_filter && this.ignoresegmentcheckbox_$[0].checked))) {
         /*
          *  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)
@@ -240,25 +252,43 @@
     }
     
     if (this.show_filters){
-        _username = this.userselect_$[0].options[this.userselect_$[0].selectedIndex].value;
-        if (_username != "false")
-        {
-            _list = _list.filter(function(_annotation){
-                return _annotation.creator == _username
-            })
+        if (this.user_filter){
+            _username = this.userselect_$[0].options[this.userselect_$[0].selectedIndex].value;
+            if (_username != "false")
+            {
+                _list = _list.filter(function(_annotation){
+                    return _annotation.creator == _username
+                })
+            }
         }
+        if (this.keyword_filter){
         _keyword = this.keywordinput_$[0].value;
-        if (_keyword != ""){
-            _list = _list.filter(function(_annotation){
-               return _annotation.description.toLowerCase().match(_keyword.toLowerCase());
-            });
+            if (_keyword != ""){
+                _list = _list.filter(function(_annotation){
+                   return _annotation.description.toLowerCase().match(_keyword.toLowerCase());
+                });
+            }
         }
-        
-        
-        if(this.datefilterinput_$[0].value != ""){
-            _date = this.datefilterinput_$.datepicker("getDate");
-            _list = _list.filter(function(_annotation){
-                return ((_annotation.created.getDate() == _date.getDate())&&(_annotation.created.getMonth() == _date.getMonth())&&(_annotation.created.getFullYear() == _date.getFullYear()))
+        if (this.date_filter){
+            if(this.datefilterinput_$[0].value != ""){
+                _date = this.datefilterinput_$.datepicker("getDate");
+                _list = _list.filter(function(_annotation){
+                    return ((_annotation.created.getDate() == _date.getDate())&&(_annotation.created.getMonth() == _date.getMonth())&&(_annotation.created.getFullYear() == _date.getFullYear()));
+                });
+            }
+        }
+        if (this.latest_contributions_filter && this.latestcontributionscheckbox_$[0].checked){
+            _list = _list.sortBy(function(_annotation) {
+                return -_annotation.created.valueOf();
+            });
+            this.usernames.forEach(function(_user){
+                
+                latest_ann = _list.filter(function(_annotation){
+                    return _annotation.creator == _user;
+                })[0];
+                _list = _list.filter(function(_annotation){
+                    return _annotation.id == (latest_ann ? latest_ann.id : false) || _annotation.creator != _user;
+                });
             });
         }
         
@@ -478,26 +508,59 @@
     this.renderTemplate();
     
     var _this = this;
-        
+    
     this.list_$ = this.$.find(".Ldt-AnnotationsList-ul");
     this.widget_$ = this.$.find(".Ldt-AnnotationsListWidget");
-    this.userselect_$ = this.$.find("#Ldt-AnnotationsList-userFilter");
-    this.userselect_$.change(function(){
-        _this.player.trigger("AnnotationsList.refresh");
-    });
-    this.keywordinput_$ = this.$.find("#Ldt-AnnotationsList-keywordsFilter");
-    this.keywordinput_$.keyup(function(){
-        _this.player.trigger("AnnotationsList.refresh");
-    });
-    this.ignoresegmentcheckbox_$ = this.$.find("#Ldt-AnnotationsList-ignoreSegmentsFilter");
-    this.ignoresegmentcheckbox_$.click(function(){
-        _this.player.trigger("AnnotationsList.refresh");
-    });
-    this.datefilterinput_$ = this.$.find("#Ldt-AnnotationsList-dateFilter");
-    this.datefilterinput_$.datepicker({ dateFormat: 'dd/mm/yy' });
-    this.datefilterinput_$.change(function(){
-        _this.player.trigger("AnnotationsList.refresh")
-    })
+    
+    if (this.show_filters){
+        this.usernames = Array();
+        _list = this.getWidgetAnnotations()
+        _list.forEach(function(_annotation){
+            if(_this.usernames.indexOf(_annotation.creator) == -1){
+                _this.usernames.push(_annotation.creator);
+            }
+        });
+        if (this.user_filter){
+            this.userselect_$ = this.$.find("#Ldt-AnnotationsList-userFilter");
+            this.userselect_$.change(function(){
+                _this.player.trigger("AnnotationsList.refresh");
+            });
+            this.userselect_$.html("<option selected value='false'>"+this.l10n.everyone+"</option>");
+            this.usernames.forEach(function(_user){
+                _this.userselect_$.append("<option value='"+_user+"'>"+_user+"</option>");
+            });
+        }
+        if (this.keyword_filter){
+            this.keywordinput_$ = this.$.find("#Ldt-AnnotationsList-keywordsFilter");
+            this.keywordinput_$.keyup(function(){
+                _this.player.trigger("AnnotationsList.refresh");
+            });
+            
+        }
+        if (this.segment_filter){
+            this.ignoresegmentcheckbox_$ = this.$.find("#Ldt-AnnotationsList-ignoreSegmentsFilter");
+            this.ignoresegmentcheckbox_$.click(function(){
+                _this.player.trigger("AnnotationsList.refresh");
+            });
+        }
+        if(this.date_filter){
+            this.datefilterinput_$ = this.$.find("#Ldt-AnnotationsList-dateFilter");
+            this.datefilterinput_$.datepicker({ dateFormat: 'dd/mm/yy' });
+            this.datefilterinput_$.change(function(){
+                _this.player.trigger("AnnotationsList.refresh")
+            })
+            if (this.current_day_filter){
+                currentDate = new Date();
+                this.datefilterinput_$.datepicker("setDate",currentDate);
+            }
+        }
+        if(this.latest_contributions_filter){
+            this.latestcontributionscheckbox_$ = this.$.find("#Ldt-AnnotationsList-latestContributionsFilter");
+            this.latestcontributionscheckbox_$.click(function(){
+                _this.player.trigger("AnnotationsList.refresh");
+            });
+        }
+    }
     
     this.source.getAnnotations().on("search", function(_text) {
         _this.searchString = _text;
@@ -523,17 +586,7 @@
     });
     
     if (this.show_filters){
-        _usernames = Array();
-        _list = this.getWidgetAnnotations()
-        _list.forEach(function(_annotation){
-            if(_usernames.indexOf(_annotation.creator) == -1){
-                _usernames.push(_annotation.creator);
-            }
-        });
-        this.userselect_$.html("<option selected value='false'>"+this.l10n.everyone+"</option>");
-        _usernames.forEach(function(_user){
-            _this.userselect_$.append("<option value='"+_user+"'>"+_user+"</option>");
-        });
+        
     }
     
     this.onMdpEvent("AnnotationsList.refresh", function() {
--- a/server/src/remie/templates/remie/iframe_segments_group.html	Thu Sep 10 14:10:06 2015 +0200
+++ b/server/src/remie/templates/remie/iframe_segments_group.html	Thu Sep 10 15:47:00 2015 +0200
@@ -132,6 +132,10 @@
             show_only_annotation_from_user: false,
             show_timecode: false,
             show_filters: true,
+            keyword_filter: false,
+            date_filter: false,
+            segment_filter: false,
+            latest_contributions_filter: true,
             show_header: true,
             custom_header: "Travail du groupe",
             limit_count: false,