# HG changeset patch # User hamidouk # Date 1322130773 -3600 # Node ID a3492448fa9a1feb572b44d97788bd758ad17f50 # Parent 3b11a798f5e4999fb7b8b5fc7d00c6e792cf3c54 begun the implementation of annotation search according to a timecode. diff -r 3b11a798f5e4 -r a3492448fa9a src/js/serializers/JSONSerializer.js --- a/src/js/serializers/JSONSerializer.js Wed Nov 23 17:19:29 2011 +0100 +++ b/src/js/serializers/JSONSerializer.js Thu Nov 24 11:32:53 2011 +0100 @@ -104,4 +104,35 @@ }; return ret; -}; \ No newline at end of file +}; + +/* takes the currentTime and returns all the annotations that are displayable at the moment + NB: only takes account the first type of annotations - ignores tweets + currentTime is in seconds. + */ + +IriSP.JSONSerializer.prototype.currentAnnotations = function(currentTime) { + var view; + var currentTimeMs = 1000 * currentTime; + + if (typeof(this._data.views) !== "undefined" && this._data.views !== null) + view = this._data.views[0]; + + var view_type = ""; + + if(typeof(view) !== "undefined" && typeof(view.annotation_types) !== "undefined" && view.annotation_types.length >= 1) { + view_type = view.annotation_types[0]; + } + + var ret_array = []; + + var i; + + for (i in this._data.annotations) { + var annotation = this._data.annotations[i]; + if (annotation.meta["id-ref"] == view_type && annotation.begin < currentTimeMs && annotation.end > currentTimeMs) + ret_array.push(annotation); + } + + return ret_array; +}; diff -r 3b11a798f5e4 -r a3492448fa9a unittests/tests/serializers/JSONSerializer.js --- a/unittests/tests/serializers/JSONSerializer.js Wed Nov 23 17:19:29 2011 +0100 +++ b/unittests/tests/serializers/JSONSerializer.js Thu Nov 24 11:32:53 2011 +0100 @@ -137,4 +137,59 @@ equal(countOccurences("garrigou interview"), 2, "second request works"); equal(countOccurences("garrigou idée interview"), 3, "third request works"); }); -}; \ No newline at end of file + + test("test current annotation search", function() { + var ser = new IriSP.JSONSerializer(this.dt, "../test/test.json"); + + ser._data = { + "views": [ + { + "id": "0", + "contents": [ + "franceculture_retourdudimanche20100620" + ], + "annotation_types": [ + "c_1F07824B-F512-78A9-49DB-6FB51DAB9560" + ] + } + ], + annotations : [ + {"begin": 1234, "end" : 578900, + "content": { + "description": "professeur", + "title": "garrigou" + }, + "id" : 1, + "meta": { + "dc:contributor": "perso", + "id-ref": "c_1F07824B-F512-78A9-49DB-6FB51DAB9560", + "dc:created": "2011-10-20T13:36:18.286693", + "dc:modified": "2011-10-20T13:36:18.286693", + "dc:creator": "perso" + } + }, + {"begin": 1234, "end" : 578900, + "content": { + "description": "interview", + "title": "Revue de presse - Hervé Gardette" + }, + "id" : 2, + "meta": { + "dc:contributor": "perso", + "id-ref": "c_1F07824B-F512-78A9-49DB-6FB51DAB9560", + "dc:created": "2011-10-20T13:36:18.286693", + "dc:modified": "2011-10-20T13:36:18.286693", + "dc:creator": "perso" + } + } + ]}; + + var ret = ser.currentAnnotations(234); + equal(ret.length, 2, "the correct number of elements is returned"); + ok(ret[0].begin < 234 * 1000 && ret[0].end > 234 * 1000 && + ret[0].meta["id-ref"] == "c_1F07824B-F512-78A9-49DB-6FB51DAB9560", + "the first element is correctly configured"); + + }); + +};