Changes to AnnotationsList and LatestAnnotations to display user full names, added a way for widgets to make request pre-draw in order to fill users data before drawing
authordurandn
Fri, 18 Sep 2015 12:58:47 +0200
changeset 154 cc84bf4cfc56
parent 153 a5a4c9022534
child 155 46fa7451f951
Changes to AnnotationsList and LatestAnnotations to display user full names, added a way for widgets to make request pre-draw in order to fill users data before drawing
server/src/remie/static/remie/metadataplayer/AnnotationsList.js
server/src/remie/static/remie/metadataplayer/LatestAnnotation.js
server/src/remie/static/remie/metadataplayer/LdtPlayer-core.js
server/src/remie/templates/remie/iframe_segments_group.html
server/src/remie/templates/remie/iframe_segments_single.html
server/src/remie/templates/remie/iframe_teacher.html
--- a/server/src/remie/static/remie/metadataplayer/AnnotationsList.js	Thu Sep 17 11:58:01 2015 +0200
+++ b/server/src/remie/static/remie/metadataplayer/AnnotationsList.js	Fri Sep 18 12:58:47 2015 +0200
@@ -12,6 +12,9 @@
 IriSP.Widgets.AnnotationsList.prototype = new IriSP.Widgets.Widget();
 
 IriSP.Widgets.AnnotationsList.prototype.defaults = {
+    pre_draw_callback: function(){
+        return this.importUsers();
+    },
     /*
      * URL when the annotations are to be reloaded from an LDT-like segment API
      * e.g.
@@ -57,6 +60,11 @@
      */
     api_delete_endpoint : "",
     api_delete_method: "DELETE",
+    api_users_endpoint: "",
+    api_users_method: "GET",
+    make_name_string_function: function(params){
+        return params.username ? params.username : "Anonymous";
+    },
     filter_by_segments: false,
     segment_filter: true,
     segments_annotation_type: "chap",
@@ -83,6 +91,40 @@
     }]
 };
 
+IriSP.Widgets.AnnotationsList.prototype.importUsers = function(){
+    if (!this.source.users_data){
+        this.usernames = Array();
+        var _this = this,
+            _list = this.getWidgetAnnotations(),
+            usernames_list_string = "";
+        
+        _list.forEach(function(_annotation){
+            if(_this.usernames.indexOf(_annotation.creator) == -1){
+                _this.usernames.push(_annotation.creator);
+            }
+        });
+        this.usernames.forEach(function(_username){
+            usernames_list_string+=_username+","
+        })
+        usernames_list_string = usernames_list_string.substring(0, usernames_list_string.length - 1);
+        _url = Mustache.to_html(this.api_users_endpoint, {usernames_list_string: encodeURIComponent(usernames_list_string), usernames_list_length: this.usernames.length});
+        return IriSP.jQuery.ajax({
+            async: false,
+            url: _url,
+            type: "GET",
+            success: function(_data) {
+                console.log(_data)
+                _this.source.users_data = _data.objects
+            },
+            error: function(_xhr, _error, _thrown) {
+                console.log(_xhr)
+                console.log(_error)
+                console.log(_thrown)
+            }
+        })
+    }
+}
+
 IriSP.Widgets.AnnotationsList.prototype.messages = {
     en: {
         voice_annotation: "Voice Annotation",
@@ -378,7 +420,17 @@
             
             // Update : display creator
             if (_annotation.creator) {
-                _title = _annotation.creator;
+                var _users = _this.source.users_data.filter(function(_user_data){
+                    return _user_data.username == _annotation.creator
+                }),
+                    _user = {};
+                if (_users.length == 0){
+                    _user.username = _annotation.creator
+                }
+                else{
+                    _user = _users[0]
+                }
+                _title = _this.make_name_string_function(_user);
             }
             if (_annotation.title) {
                 var tempTitle = _annotation.title;
@@ -542,7 +594,17 @@
         _this = this;
     console.log(_annotation)
     if (_annotation.creator) {
-        _title = _annotation.creator;
+        var _users = _this.source.users_data.filter(function(_user_data){
+            return _user_data.username == _annotation.creator
+        }),
+            _user = {};
+        if (_users.length == 0){
+            _user.username = _annotation.creator
+        }
+        else{
+            _user = _users[0]
+        }
+        _title = _this.make_name_string_function(_user);
     }
     if (_annotation.title) {
         var tempTitle = _annotation.title;
@@ -659,13 +721,6 @@
     this.widget_$ = this.$.find(".Ldt-AnnotationsListWidget");
     
     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(){
--- a/server/src/remie/static/remie/metadataplayer/LatestAnnotation.js	Thu Sep 17 11:58:01 2015 +0200
+++ b/server/src/remie/static/remie/metadataplayer/LatestAnnotation.js	Fri Sep 18 12:58:47 2015 +0200
@@ -7,6 +7,9 @@
 IriSP.Widgets.LatestAnnotation.prototype = new IriSP.Widgets.Widget();
 
 IriSP.Widgets.LatestAnnotation.prototype.defaults = {
+    pre_draw_callback: function(){
+        return this.importUsers();
+    },
     from_user: false,
     filter_by_segment: false,
     segments_annotation_type: "chap",
@@ -28,6 +31,9 @@
     starts_hidden: false,
     show_header: false,
     custom_header: false,
+    make_name_string_function: function(params){
+        return params.username ? params.username : "Anonymous";
+    }, 
 };
 
 IriSP.Widgets.LatestAnnotation.prototype.messages = {
@@ -64,6 +70,40 @@
     + "</div>"
 
 
+IriSP.Widgets.LatestAnnotation.prototype.importUsers = function(){
+    if (!this.source.users_data){
+        this.usernames = Array();
+        var _this = this,
+            _list = this.getWidgetAnnotations(),
+            usernames_list_string = "";
+        
+        _list.forEach(function(_annotation){
+            if(_this.usernames.indexOf(_annotation.creator) == -1){
+                _this.usernames.push(_annotation.creator);
+            }
+        });
+        this.usernames.forEach(function(_username){
+            usernames_list_string+=_username+","
+        })
+        usernames_list_string = usernames_list_string.substring(0, usernames_list_string.length - 1);
+        _url = Mustache.to_html(this.api_users_endpoint, {usernames_list_string: encodeURIComponent(usernames_list_string), usernames_list_length: this.usernames.length});
+        return IriSP.jQuery.ajax({
+            async: false,
+            url: _url,
+            type: "GET",
+            success: function(_data) {
+                _this.source.users_data = _data.objects
+            },
+            error: function(_xhr, _error, _thrown) {
+                console.log(_xhr)
+                console.log(_error)
+                console.log(_thrown)
+            }
+        })
+    }
+    console.log(this.source.users_data)
+}
+    
 IriSP.Widgets.LatestAnnotation.prototype.draw = function(){
     var _this = this;
     this.renderTemplate();
@@ -182,13 +222,25 @@
             return _annotation.created;
         });
         
-        var _latestAnnotation = false;
-        var _html="";
+        var _latestAnnotation = false,
+            _html="",
+            _user_display_string = "",
+            _user = {};
         if (_list.length != 0){
             _latestAnnotation = _list.pop();
+            _users = this.source.users_data.filter(function(_user_data){
+                return _user_data.username == _latestAnnotation.creator
+            })
+            if (_users.length == 0){
+                _user.username = _latestAnnotation.creator;
+            }
+            else {
+                _user = _users[0];
+            }
+            _user_display_string = this.make_name_string_function(_user)
             _html = Mustache.to_html(this.annotationTemplate, {
                 annotation_created: _latestAnnotation.created.toLocaleDateString()+", "+_latestAnnotation.created.toLocaleTimeString(),
-                annotation_creator: _latestAnnotation.creator,
+                annotation_creator: _user_display_string,
                 annotation_title: _latestAnnotation.title,
                 annotation_content: _latestAnnotation.description,
                 copy_and_edit_button: this.copy_and_edit_button,
--- a/server/src/remie/static/remie/metadataplayer/LdtPlayer-core.js	Thu Sep 17 11:58:01 2015 +0200
+++ b/server/src/remie/static/remie/metadataplayer/LdtPlayer-core.js	Fri Sep 18 12:58:47 2015 +0200
@@ -2457,29 +2457,24 @@
                 };
                 _this.media = _this.source.getCurrentMedia(_mediaopts);
             }
-            
-        _this.draw();
+        if (_this.pre_draw_callback){
+            IriSP.jQuery.when(_this.pre_draw_callback()).done(_this.draw());
+        }
+        else {
+            _this.draw();
+        }
         _this.player.trigger("widget-loaded");
     }
-    
-    if (this.pre_draw_callback){
-        onloadcallback = function(){
-            IriSP.jQuery.when(_this.pre_draw_callback()).done(onsourceloaded());
-        }     
-     }
-     else {
-         onloadcallback = onsourceloaded;
-     }
-    
+
     if (this.metadata) {
         /* Getting metadata */
         this.source = player.loadMetadata(this.metadata);
         
         /* Call draw when loaded */
-        this.source.onLoad(onloadcallback);
+        this.source.onLoad(onsourceloaded);
     } else {
         if (this.source) {
-            onloadcallback();
+            onsourceloaded();
         }
     }
     
--- a/server/src/remie/templates/remie/iframe_segments_group.html	Thu Sep 17 11:58:01 2015 +0200
+++ b/server/src/remie/templates/remie/iframe_segments_group.html	Fri Sep 18 12:58:47 2015 +0200
@@ -125,6 +125,7 @@
         },{
             type: "AnnotationsList",
             container: "AnnotationsList_container",
+            api_users_endpoint: "{% url 'api_dispatch_list' resource_name='users' api_name='1.0' %}?username__in={% templatetag openvariable %}usernames_list_string{% templatetag closevariable %}&limit={% templatetag openvariable %}usernames_list_length{% templatetag closevariable %}",
             annotation_type: "user_",
             filter_by_segments: true,
             segments_annotation_type: "découpage",
@@ -142,9 +143,17 @@
             start_visible: false,
             newest_first: true,
             tags: false,
+            make_name_string_function: function(params){
+                display_string = params.username;
+                if (params.first_name && params.last_name){
+                    display_string = params.first_name.charAt(0)+". "+params.last_name
+                }
+                return display_string;
+            }
         },{
             type: "LatestAnnotation",
             annotation_type: "user_",
+            api_users_endpoint: "{% url 'api_dispatch_list' resource_name='users' api_name='1.0' %}?username__in={% templatetag openvariable %}usernames_list_string{% templatetag closevariable %}&limit={% templatetag openvariable %}usernames_list_length{% templatetag closevariable %}",
             container: "LatestAnnotation_container",
            	filter_by_segment: true,
            	starts_hidden: true,
@@ -153,6 +162,13 @@
            	selectable_annotations: true,
            	copy_and_edit_button: true,
            	show_header: false,
+            make_name_string_function: function(params){
+                display_string = params.username;
+                if (params.first_name && params.last_name){
+                    display_string = params.first_name.charAt(0)+". "+params.last_name
+                }
+                return display_string;
+            }
         },{
          	type: "CurrentSegmentInfobox",
          	annotation_type: "découpage",
--- a/server/src/remie/templates/remie/iframe_segments_single.html	Thu Sep 17 11:58:01 2015 +0200
+++ b/server/src/remie/templates/remie/iframe_segments_single.html	Fri Sep 18 12:58:47 2015 +0200
@@ -137,6 +137,14 @@
             start_visible: false,
             newest_first: true,
             tags: false,
+            api_users_endpoint: "{% url 'api_dispatch_list' resource_name='users' api_name='1.0' %}?username__in={% templatetag openvariable %}usernames_list_string{% templatetag closevariable %}&limit={% templatetag openvariable %}usernames_list_length{% templatetag closevariable %}",
+            make_name_string_function: function(params){
+                display_string = params.username;
+                if (params.first_name && params.last_name){
+                    display_string = params.first_name.charAt(0)+". "+params.last_name
+                }
+                return display_string;
+            }
         },{
             type: "LatestAnnotation",
             annotation_type: "user_{% if not group_mode %}{{current_user}}{% endif %}",
@@ -148,6 +156,14 @@
             selectable_annotations: true,
             copy_and_edit_button: true,
             show_header: false,
+            api_users_endpoint: "{% url 'api_dispatch_list' resource_name='users' api_name='1.0' %}?username__in={% templatetag openvariable %}usernames_list_string{% templatetag closevariable %}&limit={% templatetag openvariable %}usernames_list_length{% templatetag closevariable %}",
+            make_name_string_function: function(params){
+                display_string = params.username;
+                if (params.first_name && params.last_name){
+                    display_string = params.first_name.charAt(0)+". "+params.last_name
+                }
+                return display_string;
+            }
         },{
           type: "CurrentSegmentInfobox",
           annotation_type: "découpage",
--- a/server/src/remie/templates/remie/iframe_teacher.html	Thu Sep 17 11:58:01 2015 +0200
+++ b/server/src/remie/templates/remie/iframe_teacher.html	Fri Sep 18 12:58:47 2015 +0200
@@ -138,7 +138,15 @@
             newest_first: true,
             tags: false,
             allow_annotations_deletion: true,
-            api_delete_endpoint: "{% url 'api_dispatch_list' resource_name='annotations' api_name='1.0' %}{% templatetag openvariable %}annotation_id{% templatetag closevariable %}/"
+            api_delete_endpoint: "{% url 'api_dispatch_list' resource_name='annotations' api_name='1.0' %}{% templatetag openvariable %}annotation_id{% templatetag closevariable %}/",
+            api_users_endpoint: "{% url 'api_dispatch_list' resource_name='users' api_name='1.0' %}?username__in={% templatetag openvariable %}usernames_list_string{% templatetag closevariable %}&limit={% templatetag openvariable %}usernames_list_length{% templatetag closevariable %}",
+            make_name_string_function: function(params){
+                display_string = params.username;
+                if (params.first_name && params.last_name){
+                    display_string = params.first_name.charAt(0)+". "+params.last_name
+                }
+                return display_string;
+            },
         },{
             type: "LatestAnnotation",
             annotation_type: "user_",
@@ -150,6 +158,14 @@
             selectable_annotations: true,
             copy_and_edit_button: true,
             show_header: false,
+            api_users_endpoint: "{% url 'api_dispatch_list' resource_name='users' api_name='1.0' %}?username__in={% templatetag openvariable %}usernames_list_string{% templatetag closevariable %}&limit={% templatetag openvariable %}usernames_list_length{% templatetag closevariable %}",
+            make_name_string_function: function(params){
+                display_string = params.username;
+                if (params.first_name && params.last_name){
+                    display_string = params.first_name.charAt(0)+". "+params.last_name
+                }
+                return display_string;
+            },
         },{
           type: "CurrentSegmentInfobox",
           annotation_type: "découpage",