src/js/serializers/JSONSerializer.js
branchpopcorn-port
changeset 536 b7e545e35287
parent 528 a5894f09825a
child 566 098929cd2d62
equal deleted inserted replaced
535:7c25af985344 536:b7e545e35287
   232 
   232 
   233 IriSP.JSONSerializer.prototype.currentAnnotations = function(currentTime) {
   233 IriSP.JSONSerializer.prototype.currentAnnotations = function(currentTime) {
   234   var view;
   234   var view;
   235   var currentTimeMs = 1000 * currentTime;
   235   var currentTimeMs = 1000 * currentTime;
   236 
   236 
   237   if (typeof(this._data.views) !== "undefined" && this._data.views !== null)
   237   var legal_ids = this.getNonTweetIds();
   238      view = this._data.views[0];
   238   
   239 
       
   240   var view_type = "";
       
   241 
       
   242   if(typeof(view) !== "undefined" && typeof(view.annotation_types) !== "undefined" && view.annotation_types.length >= 1) {
       
   243           view_type = view.annotation_types[0];
       
   244   }
       
   245 
       
   246   var ret_array = [];
   239   var ret_array = [];
   247   
   240   
   248   var i;
   241   var i;
   249  
   242   
   250   for (i in this._data.annotations) {
   243   for (i in this._data.annotations) {
   251     var annotation = this._data.annotations[i];
   244     var annotation = this._data.annotations[i];
   252     
   245     
   253     if (annotation.meta["id-ref"] === view_type && annotation.begin <= currentTimeMs && annotation.end >= currentTimeMs)
   246     if (IriSP.underscore.include(legal_ids, annotation.meta["id-ref"]) && annotation.begin <= currentTimeMs && annotation.end >= currentTimeMs)
   254       ret_array.push(annotation);
   247       ret_array.push(annotation);
   255   }
   248   }
   256 
   249 
   257   return ret_array;
   250   return ret_array;
   258 };
   251 };
   277 /** this function returns a list of lines which are not tweet lines */
   270 /** this function returns a list of lines which are not tweet lines */
   278 IriSP.JSONSerializer.prototype.getNonTweetIds = function() {
   271 IriSP.JSONSerializer.prototype.getNonTweetIds = function() {
   279   if (typeof(this._data.lists) === "undefined" || this._data.lists === null)
   272   if (typeof(this._data.lists) === "undefined" || this._data.lists === null)
   280     return [];
   273     return [];
   281   
   274   
   282   /* get all the ids */
   275   /* complicated : for each list in this._data.lists, get the id-ref.
   283   var ids = IriSP.underscore.map(this._data.lists, function(entry) {                                                         
   276      flatten the returned array because pluck returns a string afterwards.
   284                                                          return IriSP.underscore.pluck(entry.items, "id-ref"); });
   277   */
       
   278   var ids = IriSP.underscore.flatten(IriSP.underscore.map(this._data.lists, function(entry) {                                                         
       
   279                                                          return IriSP.underscore.pluck(entry.items, "id-ref"); }));
   285                                                          
   280                                                          
   286   var illegal_values = this.getTweetIds();
   281   var illegal_values = this.getTweetIds();
   287   return IriSP.underscore.difference(ids, illegal_values);
   282   return IriSP.underscore.difference(ids, illegal_values);
   288   
   283   
   289 };
   284 };