# HG changeset patch # User durandn # Date 1442573927 -7200 # Node ID cc84bf4cfc5654fcc99f9c843603b492ae499a4d # Parent a5a4c902253486a28665c8df19587a4ae54f9452 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 diff -r a5a4c9022534 -r cc84bf4cfc56 server/src/remie/static/remie/metadataplayer/AnnotationsList.js --- 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(){ diff -r a5a4c9022534 -r cc84bf4cfc56 server/src/remie/static/remie/metadataplayer/LatestAnnotation.js --- 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 @@ + "" +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, diff -r a5a4c9022534 -r cc84bf4cfc56 server/src/remie/static/remie/metadataplayer/LdtPlayer-core.js --- 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(); } } diff -r a5a4c9022534 -r cc84bf4cfc56 server/src/remie/templates/remie/iframe_segments_group.html --- 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", diff -r a5a4c9022534 -r cc84bf4cfc56 server/src/remie/templates/remie/iframe_segments_single.html --- 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", diff -r a5a4c9022534 -r cc84bf4cfc56 server/src/remie/templates/remie/iframe_teacher.html --- 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",