| author | hamidouk |
| Tue, 29 Nov 2011 15:42:53 +0100 | |
| branch | popcorn-port |
| changeset 352 | cc2cdecc5ce5 |
| parent 320 | b693ba1a83be |
| child 395 | 5766e8238aaf |
| permissions | -rw-r--r-- |
|
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 | 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 | 18 |
|
| 137 | 19 |
var self = this; |
20 |
||
21 |
var fn = function(data) { |
|
22 |
self._data = data; |
|
23 |
// sort the data too |
|
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 | 29 |
|
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 | 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. |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
42 |
*/ |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
43 |
IriSP.JSONSerializer.prototype.searchAnnotations = function(title, description, keyword) { |
| 352 | 44 |
|
45 |
/* we can have many types of annotations. We want search to only look for regular segments */ |
|
46 |
/* the next two lines are a bit verbose because for some test data, _serializer.data.view is either |
|
47 |
null or undefined. |
|
48 |
*/ |
|
49 |
var view; |
|
50 |
||
51 |
if (typeof(this._data.views) !== "undefined" && this._data.views !== null) |
|
52 |
view = this._data.views[0]; |
|
53 |
||
54 |
var searchViewType = ""; |
|
55 |
||
56 |
if(typeof(view) !== "undefined" && typeof(view.annotation_types) !== "undefined" && view.annotation_types.length > 1) { |
|
57 |
searchViewType = view.annotation_types[0]; |
|
58 |
} |
|
59 |
||
|
147
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
60 |
var rTitle; |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
61 |
var rDescription; |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
62 |
var rKeyword; |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
63 |
|
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
64 |
/* match anything if given the empty string */ |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
65 |
if (title == "") |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
66 |
title = ".*"; |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
67 |
if (description == "") |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
68 |
description = ".*"; |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
69 |
if (keyword == "") |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
70 |
keyword = ".*"; |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
71 |
|
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
72 |
rTitle = new RegExp(title, "i"); |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
73 |
rDescription = new RegExp(description, "i"); |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
74 |
rKeyword = new RegExp(keyword, "i"); |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
75 |
|
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
76 |
var ret_array = []; |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
77 |
|
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
78 |
var i; |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
79 |
for (i in this._data.annotations) { |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
80 |
var annotation = this._data.annotations[i]; |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
81 |
|
| 352 | 82 |
/* filter the annotations whose type is not the one we want */ |
83 |
if (searchViewType != "" && typeof(annotation.meta) !== "undefined" && typeof(annotation.meta["id-ref"]) !== "undefined" |
|
84 |
&& annotation.meta["id-ref"] !== searchViewType) { |
|
85 |
continue; |
|
86 |
} |
|
87 |
|
|
|
147
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
88 |
if (rTitle.test(annotation.content.title) && |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
89 |
rDescription.test(annotation.content.description)) { |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
90 |
/* FIXME : implement keyword support */ |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
91 |
ret_array.push(annotation); |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
92 |
} |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
93 |
} |
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
94 |
|
|
955119f901b4
added a function to search annotations to the json serializer.
hamidouk
parents:
137
diff
changeset
|
95 |
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
|
96 |
}; |
|
a10198c95808
added a function to break a search string in words and count the number of
hamidouk
parents:
147
diff
changeset
|
97 |
|
|
a10198c95808
added a function to break a search string in words and count the number of
hamidouk
parents:
147
diff
changeset
|
98 |
/* 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
|
99 |
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
|
100 |
|
|
a10198c95808
added a function to break a search string in words and count the number of
hamidouk
parents:
147
diff
changeset
|
101 |
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
|
102 |
*/ |
|
a10198c95808
added a function to break a search string in words and count the number of
hamidouk
parents:
147
diff
changeset
|
103 |
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
|
104 |
var ret = { }; |
|
a10198c95808
added a function to break a search string in words and count the number of
hamidouk
parents:
147
diff
changeset
|
105 |
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
|
106 |
|
|
a10198c95808
added a function to break a search string in words and count the number of
hamidouk
parents:
147
diff
changeset
|
107 |
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
|
108 |
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
|
109 |
|
| 150 | 110 |
// 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
|
111 |
var found_annotations = [] |
|
a10198c95808
added a function to break a search string in words and count the number of
hamidouk
parents:
147
diff
changeset
|
112 |
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
|
113 |
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
|
114 |
|
|
a10198c95808
added a function to break a search string in words and count the number of
hamidouk
parents:
147
diff
changeset
|
115 |
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
|
116 |
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
|
117 |
|
|
a10198c95808
added a function to break a search string in words and count the number of
hamidouk
parents:
147
diff
changeset
|
118 |
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
|
119 |
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
|
120 |
} else { |
|
a10198c95808
added a function to break a search string in words and count the number of
hamidouk
parents:
147
diff
changeset
|
121 |
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
|
122 |
} |
|
a10198c95808
added a function to break a search string in words and count the number of
hamidouk
parents:
147
diff
changeset
|
123 |
|
|
a10198c95808
added a function to break a search string in words and count the number of
hamidouk
parents:
147
diff
changeset
|
124 |
} |
|
a10198c95808
added a function to break a search string in words and count the number of
hamidouk
parents:
147
diff
changeset
|
125 |
|
|
a10198c95808
added a function to break a search string in words and count the number of
hamidouk
parents:
147
diff
changeset
|
126 |
}; |
|
a10198c95808
added a function to break a search string in words and count the number of
hamidouk
parents:
147
diff
changeset
|
127 |
|
|
a10198c95808
added a function to break a search string in words and count the number of
hamidouk
parents:
147
diff
changeset
|
128 |
return ret; |
|
317
a3492448fa9a
begun the implementation of annotation search according to a timecode.
hamidouk
parents:
150
diff
changeset
|
129 |
}; |
|
a3492448fa9a
begun the implementation of annotation search according to a timecode.
hamidouk
parents:
150
diff
changeset
|
130 |
|
|
a3492448fa9a
begun the implementation of annotation search according to a timecode.
hamidouk
parents:
150
diff
changeset
|
131 |
/* 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
|
132 |
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
|
133 |
currentTime is in seconds. |
|
a3492448fa9a
begun the implementation of annotation search according to a timecode.
hamidouk
parents:
150
diff
changeset
|
134 |
*/ |
|
a3492448fa9a
begun the implementation of annotation search according to a timecode.
hamidouk
parents:
150
diff
changeset
|
135 |
|
|
a3492448fa9a
begun the implementation of annotation search according to a timecode.
hamidouk
parents:
150
diff
changeset
|
136 |
IriSP.JSONSerializer.prototype.currentAnnotations = function(currentTime) { |
|
a3492448fa9a
begun the implementation of annotation search according to a timecode.
hamidouk
parents:
150
diff
changeset
|
137 |
var view; |
|
a3492448fa9a
begun the implementation of annotation search according to a timecode.
hamidouk
parents:
150
diff
changeset
|
138 |
var currentTimeMs = 1000 * currentTime; |
|
a3492448fa9a
begun the implementation of annotation search according to a timecode.
hamidouk
parents:
150
diff
changeset
|
139 |
|
|
a3492448fa9a
begun the implementation of annotation search according to a timecode.
hamidouk
parents:
150
diff
changeset
|
140 |
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
|
141 |
view = this._data.views[0]; |
|
a3492448fa9a
begun the implementation of annotation search according to a timecode.
hamidouk
parents:
150
diff
changeset
|
142 |
|
|
a3492448fa9a
begun the implementation of annotation search according to a timecode.
hamidouk
parents:
150
diff
changeset
|
143 |
var view_type = ""; |
|
a3492448fa9a
begun the implementation of annotation search according to a timecode.
hamidouk
parents:
150
diff
changeset
|
144 |
|
|
a3492448fa9a
begun the implementation of annotation search according to a timecode.
hamidouk
parents:
150
diff
changeset
|
145 |
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
|
146 |
view_type = view.annotation_types[0]; |
|
a3492448fa9a
begun the implementation of annotation search according to a timecode.
hamidouk
parents:
150
diff
changeset
|
147 |
} |
|
a3492448fa9a
begun the implementation of annotation search according to a timecode.
hamidouk
parents:
150
diff
changeset
|
148 |
|
|
a3492448fa9a
begun the implementation of annotation search according to a timecode.
hamidouk
parents:
150
diff
changeset
|
149 |
var ret_array = []; |
|
a3492448fa9a
begun the implementation of annotation search according to a timecode.
hamidouk
parents:
150
diff
changeset
|
150 |
|
|
a3492448fa9a
begun the implementation of annotation search according to a timecode.
hamidouk
parents:
150
diff
changeset
|
151 |
var i; |
|
a3492448fa9a
begun the implementation of annotation search according to a timecode.
hamidouk
parents:
150
diff
changeset
|
152 |
|
|
a3492448fa9a
begun the implementation of annotation search according to a timecode.
hamidouk
parents:
150
diff
changeset
|
153 |
for (i in this._data.annotations) { |
|
a3492448fa9a
begun the implementation of annotation search according to a timecode.
hamidouk
parents:
150
diff
changeset
|
154 |
var annotation = this._data.annotations[i]; |
| 320 | 155 |
|
156 |
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
|
157 |
ret_array.push(annotation); |
|
a3492448fa9a
begun the implementation of annotation search according to a timecode.
hamidouk
parents:
150
diff
changeset
|
158 |
} |
| 320 | 159 |
|
|
317
a3492448fa9a
begun the implementation of annotation search according to a timecode.
hamidouk
parents:
150
diff
changeset
|
160 |
return ret_array; |
|
a3492448fa9a
begun the implementation of annotation search according to a timecode.
hamidouk
parents:
150
diff
changeset
|
161 |
}; |