src/js/serializers/JSONSerializer.js
author hamidouk
Mon, 19 Dec 2011 15:25:22 +0100
branchpopcorn-port
changeset 481 a46cfeee6d77
parent 395 5766e8238aaf
child 513 4589b90fe1ad
permissions -rw-r--r--
using jquery ui draggable changes the state of an element from absolute to relative positioning, which breaks the way our seek button expands itself, so we need to force absolute positioning, quite uglily, using jquery.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
108
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff changeset
     1
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff changeset
     2
IriSP.JSONSerializer = function(DataLoader, url) {
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff changeset
     3
  IriSP.Serializer.call(this, DataLoader, url);
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff changeset
     4
};
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff changeset
     5
128
f3fec80dd31c renames and inheritance bug fixes.
hamidouk
parents: 108
diff changeset
     6
IriSP.JSONSerializer.prototype = new IriSP.Serializer();
108
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff changeset
     7
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff changeset
     8
IriSP.JSONSerializer.prototype.serialize = function(data) {
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff changeset
     9
  return JSON.stringify(data);
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff changeset
    10
};
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff changeset
    11
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff changeset
    12
IriSP.JSONSerializer.prototype.deserialize = function(data) {
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff changeset
    13
  return JSON.parse(data);
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff changeset
    14
};
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff changeset
    15
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff changeset
    16
IriSP.JSONSerializer.prototype.sync = function(callback) {
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff changeset
    17
  /* we don't have to do much because jQuery handles json for us */
128
f3fec80dd31c renames and inheritance bug fixes.
hamidouk
parents: 108
diff changeset
    18
137
ef6c1252c459 clarified the closure code.
hamidouk
parents: 128
diff changeset
    19
  var self = this;
ef6c1252c459 clarified the closure code.
hamidouk
parents: 128
diff changeset
    20
ef6c1252c459 clarified the closure code.
hamidouk
parents: 128
diff changeset
    21
  var fn = function(data) {      
ef6c1252c459 clarified the closure code.
hamidouk
parents: 128
diff changeset
    22
      self._data = data;      
ef6c1252c459 clarified the closure code.
hamidouk
parents: 128
diff changeset
    23
      // sort the data too     
ef6c1252c459 clarified the closure code.
hamidouk
parents: 128
diff changeset
    24
      self._data["annotations"].sort(function(a, b) 
108
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff changeset
    25
          { var a_begin = +a.begin;
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff changeset
    26
            var b_begin = +b.begin;
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff changeset
    27
            return a_begin - b_begin;
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff changeset
    28
          });
137
ef6c1252c459 clarified the closure code.
hamidouk
parents: 128
diff changeset
    29
     
ef6c1252c459 clarified the closure code.
hamidouk
parents: 128
diff changeset
    30
      callback(data);      
108
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff changeset
    31
  };
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff changeset
    32
  
137
ef6c1252c459 clarified the closure code.
hamidouk
parents: 128
diff changeset
    33
  this._DataLoader.get(this._url, fn);
108
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff changeset
    34
};
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff changeset
    35
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff changeset
    36
IriSP.JSONSerializer.prototype.currentMedia = function() {  
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff changeset
    37
  return this._data.medias[0]; /* FIXME: don't hardcode it */
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff changeset
    38
};
147
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
    39
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
    40
/* this function searches for an annotation which matches title, description and keyword 
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
    41
   "" matches any field. 
395
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    42
   Note: it ignores tweets.
147
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
    43
*/    
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
    44
IriSP.JSONSerializer.prototype.searchAnnotations = function(title, description, keyword) {
352
cc2cdecc5ce5 ignore tweets in search.
hamidouk
parents: 320
diff changeset
    45
    /* we can have many types of annotations. We want search to only look for regular segments */
cc2cdecc5ce5 ignore tweets in search.
hamidouk
parents: 320
diff changeset
    46
    /* the next two lines are a bit verbose because for some test data, _serializer.data.view is either
cc2cdecc5ce5 ignore tweets in search.
hamidouk
parents: 320
diff changeset
    47
       null or undefined.
cc2cdecc5ce5 ignore tweets in search.
hamidouk
parents: 320
diff changeset
    48
    */
cc2cdecc5ce5 ignore tweets in search.
hamidouk
parents: 320
diff changeset
    49
    var view;
cc2cdecc5ce5 ignore tweets in search.
hamidouk
parents: 320
diff changeset
    50
cc2cdecc5ce5 ignore tweets in search.
hamidouk
parents: 320
diff changeset
    51
    if (typeof(this._data.views) !== "undefined" && this._data.views !== null)
cc2cdecc5ce5 ignore tweets in search.
hamidouk
parents: 320
diff changeset
    52
       view = this._data.views[0];
cc2cdecc5ce5 ignore tweets in search.
hamidouk
parents: 320
diff changeset
    53
cc2cdecc5ce5 ignore tweets in search.
hamidouk
parents: 320
diff changeset
    54
    var searchViewType = "";
cc2cdecc5ce5 ignore tweets in search.
hamidouk
parents: 320
diff changeset
    55
cc2cdecc5ce5 ignore tweets in search.
hamidouk
parents: 320
diff changeset
    56
    if(typeof(view) !== "undefined" && typeof(view.annotation_types) !== "undefined" && view.annotation_types.length > 1) {
cc2cdecc5ce5 ignore tweets in search.
hamidouk
parents: 320
diff changeset
    57
            searchViewType = view.annotation_types[0];
cc2cdecc5ce5 ignore tweets in search.
hamidouk
parents: 320
diff changeset
    58
    }
cc2cdecc5ce5 ignore tweets in search.
hamidouk
parents: 320
diff changeset
    59
395
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    60
    var filterfn = function(annotation) {
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    61
      if( searchViewType  != "" && 
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    62
          typeof(annotation.meta) !== "undefined" && 
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    63
          typeof(annotation.meta["id-ref"]) !== "undefined" &&
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    64
          annotation.meta["id-ref"] !== searchViewType) {
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    65
        return true; // don't pass
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    66
      } else {
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    67
          return false;
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    68
      }
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    69
    };
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    70
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    71
    return this.searchAnnotationsFilter(title, description, keyword, filterfn);
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    72
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    73
};
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    74
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    75
/* only look for tweets */
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    76
IriSP.JSONSerializer.prototype.searchTweets = function(title, description, keyword) {
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    77
    /* we can have many types of annotations. We want search to only look for regular segments */
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    78
    /* the next two lines are a bit verbose because for some test data, _serializer.data.view is either
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    79
       null or undefined.
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    80
    */
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    81
    var view;
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    82
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    83
    if (typeof(this._data.views) !== "undefined" && this._data.views !== null)
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    84
       view = this._data.views[0];
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    85
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    86
    var searchViewType = "";
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    87
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    88
    if(typeof(view) !== "undefined" && typeof(view.annotation_types) !== "undefined" && view.annotation_types.length > 1) {
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    89
            searchViewType = view.annotation_types[0];
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    90
    }
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    91
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    92
    var filterfn = function(annotation) {
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    93
      if( searchViewType  != "" && 
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    94
          typeof(annotation.meta) !== "undefined" && 
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    95
          typeof(annotation.meta["id-ref"]) !== "undefined" &&
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    96
          annotation.meta["id-ref"] !== searchViewType) {
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    97
        return false; // pass
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    98
      } else {
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
    99
          return true;
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   100
      }
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   101
    };
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   102
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   103
    return this.searchAnnotationsFilter(title, description, keyword, filterfn);
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   104
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   105
};
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   106
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   107
/*
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   108
  the previous function call this one, which is more general:
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   109
 */    
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   110
IriSP.JSONSerializer.prototype.searchAnnotationsFilter = function(title, description, keyword, filter) {
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   111
147
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
   112
    var rTitle;
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
   113
    var rDescription;
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
   114
    var rKeyword;
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
   115
    /* match anything if given the empty string */
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
   116
    if (title == "")
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
   117
      title = ".*";
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
   118
    if (description == "")
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
   119
      description = ".*";
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
   120
    if (keyword == "")
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
   121
      keyword = ".*";
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
   122
    
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
   123
    rTitle = new RegExp(title, "i");  
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
   124
    rDescription = new RegExp(description, "i");  
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
   125
    rKeyword = new RegExp(keyword, "i");  
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
   126
    
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
   127
    var ret_array = [];
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
   128
    
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
   129
    var i;
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
   130
    for (i in this._data.annotations) {
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
   131
      var annotation = this._data.annotations[i];
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
   132
      
352
cc2cdecc5ce5 ignore tweets in search.
hamidouk
parents: 320
diff changeset
   133
      /* filter the annotations whose type is not the one we want */
395
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   134
      if (filter(annotation)) {
352
cc2cdecc5ce5 ignore tweets in search.
hamidouk
parents: 320
diff changeset
   135
          continue;
cc2cdecc5ce5 ignore tweets in search.
hamidouk
parents: 320
diff changeset
   136
      }
395
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   137
      
147
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
   138
      if (rTitle.test(annotation.content.title) && 
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
   139
          rDescription.test(annotation.content.description)) {
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
   140
          /* FIXME : implement keyword support */
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
   141
          ret_array.push(annotation);
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
   142
      }
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
   143
    }
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
   144
    
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
   145
    return ret_array;
149
a10198c95808 added a function to break a search string in words and count the number of
hamidouk
parents: 147
diff changeset
   146
};
a10198c95808 added a function to break a search string in words and count the number of
hamidouk
parents: 147
diff changeset
   147
a10198c95808 added a function to break a search string in words and count the number of
hamidouk
parents: 147
diff changeset
   148
/* breaks a string in words and searches each of these words. Returns an array
a10198c95808 added a function to break a search string in words and count the number of
hamidouk
parents: 147
diff changeset
   149
   of objects with the id of the annotation and its number of occurences.
a10198c95808 added a function to break a search string in words and count the number of
hamidouk
parents: 147
diff changeset
   150
   
a10198c95808 added a function to break a search string in words and count the number of
hamidouk
parents: 147
diff changeset
   151
   FIXME: optimize ? seems to be n^2 in the worst case.
a10198c95808 added a function to break a search string in words and count the number of
hamidouk
parents: 147
diff changeset
   152
*/
a10198c95808 added a function to break a search string in words and count the number of
hamidouk
parents: 147
diff changeset
   153
IriSP.JSONSerializer.prototype.searchOccurences = function(searchString) {
a10198c95808 added a function to break a search string in words and count the number of
hamidouk
parents: 147
diff changeset
   154
  var ret = { };
a10198c95808 added a function to break a search string in words and count the number of
hamidouk
parents: 147
diff changeset
   155
  var keywords = searchString.split(/\s+/);
a10198c95808 added a function to break a search string in words and count the number of
hamidouk
parents: 147
diff changeset
   156
  
a10198c95808 added a function to break a search string in words and count the number of
hamidouk
parents: 147
diff changeset
   157
  for (var i in keywords) {
a10198c95808 added a function to break a search string in words and count the number of
hamidouk
parents: 147
diff changeset
   158
    var keyword = keywords[i];
a10198c95808 added a function to break a search string in words and count the number of
hamidouk
parents: 147
diff changeset
   159
    
150
40cf046b7049 added a comment.
hamidouk
parents: 149
diff changeset
   160
    // search this keyword in descriptions and title
149
a10198c95808 added a function to break a search string in words and count the number of
hamidouk
parents: 147
diff changeset
   161
    var found_annotations = []
a10198c95808 added a function to break a search string in words and count the number of
hamidouk
parents: 147
diff changeset
   162
    found_annotations = found_annotations.concat(this.searchAnnotations(keyword, "", ""));
a10198c95808 added a function to break a search string in words and count the number of
hamidouk
parents: 147
diff changeset
   163
    found_annotations = found_annotations.concat(this.searchAnnotations("", keyword, ""));
a10198c95808 added a function to break a search string in words and count the number of
hamidouk
parents: 147
diff changeset
   164
    
a10198c95808 added a function to break a search string in words and count the number of
hamidouk
parents: 147
diff changeset
   165
    for (var j in found_annotations) {
a10198c95808 added a function to break a search string in words and count the number of
hamidouk
parents: 147
diff changeset
   166
      var current_annotation = found_annotations[j];
a10198c95808 added a function to break a search string in words and count the number of
hamidouk
parents: 147
diff changeset
   167
      
a10198c95808 added a function to break a search string in words and count the number of
hamidouk
parents: 147
diff changeset
   168
      if (!ret.hasOwnProperty(current_annotation.id)) {
a10198c95808 added a function to break a search string in words and count the number of
hamidouk
parents: 147
diff changeset
   169
        ret[current_annotation.id] = 1;
a10198c95808 added a function to break a search string in words and count the number of
hamidouk
parents: 147
diff changeset
   170
      } else {
a10198c95808 added a function to break a search string in words and count the number of
hamidouk
parents: 147
diff changeset
   171
        ret[current_annotation.id] += 1;
a10198c95808 added a function to break a search string in words and count the number of
hamidouk
parents: 147
diff changeset
   172
      }
a10198c95808 added a function to break a search string in words and count the number of
hamidouk
parents: 147
diff changeset
   173
      
a10198c95808 added a function to break a search string in words and count the number of
hamidouk
parents: 147
diff changeset
   174
    }
a10198c95808 added a function to break a search string in words and count the number of
hamidouk
parents: 147
diff changeset
   175
a10198c95808 added a function to break a search string in words and count the number of
hamidouk
parents: 147
diff changeset
   176
  };
a10198c95808 added a function to break a search string in words and count the number of
hamidouk
parents: 147
diff changeset
   177
  
a10198c95808 added a function to break a search string in words and count the number of
hamidouk
parents: 147
diff changeset
   178
  return ret;
317
a3492448fa9a begun the implementation of annotation search according to a timecode.
hamidouk
parents: 150
diff changeset
   179
};
a3492448fa9a begun the implementation of annotation search according to a timecode.
hamidouk
parents: 150
diff changeset
   180
395
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   181
/* breaks a string in words and searches each of these words. Returns an array
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   182
   of objects with the id of the annotation and its number of occurences.
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   183
   
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   184
   FIXME: optimize ? seems to be n^2 in the worst case.
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   185
*/
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   186
IriSP.JSONSerializer.prototype.searchTweetsOccurences = function(searchString) {
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   187
  var ret = { };
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   188
  var keywords = searchString.split(/\s+/);
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   189
  
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   190
  for (var i in keywords) {
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   191
    var keyword = keywords[i];
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   192
    
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   193
    // search this keyword in descriptions and title
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   194
    var found_annotations = []
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   195
    found_annotations = found_annotations.concat(this.searchTweets(keyword, "", ""));
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   196
    found_annotations = found_annotations.concat(this.searchTweets("", keyword, ""));
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   197
    
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   198
    for (var j in found_annotations) {
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   199
      var current_annotation = found_annotations[j];
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   200
      
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   201
      if (!ret.hasOwnProperty(current_annotation.id)) {
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   202
        ret[current_annotation.id] = 1;
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   203
      } else {
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   204
        ret[current_annotation.id] += 1;
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   205
      }
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   206
      
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   207
    }
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   208
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   209
  };
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   210
  
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   211
  return ret;
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   212
};
5766e8238aaf search in twitter feed now works.
hamidouk
parents: 352
diff changeset
   213
317
a3492448fa9a begun the implementation of annotation search according to a timecode.
hamidouk
parents: 150
diff changeset
   214
/* takes the currentTime and returns all the annotations that are displayable at the moment 
a3492448fa9a begun the implementation of annotation search according to a timecode.
hamidouk
parents: 150
diff changeset
   215
   NB: only takes account the first type of annotations - ignores tweets 
a3492448fa9a begun the implementation of annotation search according to a timecode.
hamidouk
parents: 150
diff changeset
   216
   currentTime is in seconds.
a3492448fa9a begun the implementation of annotation search according to a timecode.
hamidouk
parents: 150
diff changeset
   217
 */
a3492448fa9a begun the implementation of annotation search according to a timecode.
hamidouk
parents: 150
diff changeset
   218
a3492448fa9a begun the implementation of annotation search according to a timecode.
hamidouk
parents: 150
diff changeset
   219
IriSP.JSONSerializer.prototype.currentAnnotations = function(currentTime) {
a3492448fa9a begun the implementation of annotation search according to a timecode.
hamidouk
parents: 150
diff changeset
   220
  var view;
a3492448fa9a begun the implementation of annotation search according to a timecode.
hamidouk
parents: 150
diff changeset
   221
  var currentTimeMs = 1000 * currentTime;
a3492448fa9a begun the implementation of annotation search according to a timecode.
hamidouk
parents: 150
diff changeset
   222
a3492448fa9a begun the implementation of annotation search according to a timecode.
hamidouk
parents: 150
diff changeset
   223
  if (typeof(this._data.views) !== "undefined" && this._data.views !== null)
a3492448fa9a begun the implementation of annotation search according to a timecode.
hamidouk
parents: 150
diff changeset
   224
     view = this._data.views[0];
a3492448fa9a begun the implementation of annotation search according to a timecode.
hamidouk
parents: 150
diff changeset
   225
a3492448fa9a begun the implementation of annotation search according to a timecode.
hamidouk
parents: 150
diff changeset
   226
  var view_type = "";
a3492448fa9a begun the implementation of annotation search according to a timecode.
hamidouk
parents: 150
diff changeset
   227
a3492448fa9a begun the implementation of annotation search according to a timecode.
hamidouk
parents: 150
diff changeset
   228
  if(typeof(view) !== "undefined" && typeof(view.annotation_types) !== "undefined" && view.annotation_types.length >= 1) {
a3492448fa9a begun the implementation of annotation search according to a timecode.
hamidouk
parents: 150
diff changeset
   229
          view_type = view.annotation_types[0];
a3492448fa9a begun the implementation of annotation search according to a timecode.
hamidouk
parents: 150
diff changeset
   230
  }
a3492448fa9a begun the implementation of annotation search according to a timecode.
hamidouk
parents: 150
diff changeset
   231
a3492448fa9a begun the implementation of annotation search according to a timecode.
hamidouk
parents: 150
diff changeset
   232
  var ret_array = [];
a3492448fa9a begun the implementation of annotation search according to a timecode.
hamidouk
parents: 150
diff changeset
   233
  
a3492448fa9a begun the implementation of annotation search according to a timecode.
hamidouk
parents: 150
diff changeset
   234
  var i;
a3492448fa9a begun the implementation of annotation search according to a timecode.
hamidouk
parents: 150
diff changeset
   235
 
a3492448fa9a begun the implementation of annotation search according to a timecode.
hamidouk
parents: 150
diff changeset
   236
  for (i in this._data.annotations) {
a3492448fa9a begun the implementation of annotation search according to a timecode.
hamidouk
parents: 150
diff changeset
   237
    var annotation = this._data.annotations[i];
320
b693ba1a83be fixed bug in search method
hamidouk
parents: 317
diff changeset
   238
    
b693ba1a83be fixed bug in search method
hamidouk
parents: 317
diff changeset
   239
    if (annotation.meta["id-ref"] === view_type && annotation.begin <= currentTimeMs && annotation.end >= currentTimeMs)
317
a3492448fa9a begun the implementation of annotation search according to a timecode.
hamidouk
parents: 150
diff changeset
   240
      ret_array.push(annotation);
a3492448fa9a begun the implementation of annotation search according to a timecode.
hamidouk
parents: 150
diff changeset
   241
  }
320
b693ba1a83be fixed bug in search method
hamidouk
parents: 317
diff changeset
   242
317
a3492448fa9a begun the implementation of annotation search according to a timecode.
hamidouk
parents: 150
diff changeset
   243
  return ret_array;
a3492448fa9a begun the implementation of annotation search according to a timecode.
hamidouk
parents: 150
diff changeset
   244
};