Author: ygrego Date: 2015-04-10 15:11:31 +0000 (Fri, 10 Apr 2015) New Revision: 1150 Url: http://forge.nuiton.org/projects/sandbox/repository/revisions/1150 Log: The method "getResults" has been modified so that this current search be stopped. Modified: oipf/js/impl/model/SearchResults.js Modified: oipf/js/impl/model/SearchResults.js =================================================================== --- oipf/js/impl/model/SearchResults.js 2015-04-10 13:37:22 UTC (rev 1149) +++ oipf/js/impl/model/SearchResults.js 2015-04-10 15:11:31 UTC (rev 1150) @@ -125,101 +125,99 @@ } else { - var time = new Date().getTime(); if (this.isValidField(this._search._currentQuery._field) && this.isValidComparator( this._search._currentQuery._comparison)) { - for (var i = 0; i< programmes.length; i++) { - - var programme = programmes[i]; - var methodToCall = { - 0: "equals", - 1: "notEquals", - 2: "superior", - 3: "superiorOrEquals", - 4: "inferior", - 5: "inferiorOrEquals", - 6: "contains" - }; + var loop = function (context, count){ + var time = new Date().getTime(); + for (var i = 0; i< programmes.length; i++) { + console.log("Hey"); + var programme = programmes[i]; + var methodToCall = { + 0: "equals", + 1: "notEquals", + 2: "superior", + 3: "superiorOrEquals", + 4: "inferior", + 5: "inferiorOrEquals", + 6: "contains" + }; - var field = this._search._currentQuery._field; - var comparison = this._search._currentQuery._comparison; - var value = this._search._currentQuery._value; - var methodName = methodToCall[comparison]; - - /* - * When the search corresponds to current programme - * the code differs from other usual query. - */ - if (this._search._currentQuery._type == "current") { - - var constraints = this._search. - _constraints.channels; - - if (constraints.length > 0 && + var field = context._search._currentQuery._field; + var comparison = context._search._currentQuery._comparison; + var value = context._search._currentQuery._value; + var methodName = methodToCall[comparison]; + + /* + * When the search corresponds to current programme + * the code differs from other usual query. + */ + if (context._search._currentQuery._type == "current") { + + var constraints = context._search. + _constraints.channels; + + if (constraints.length > 0 && + oipf.utils.isPresent(constraints, + programme.channel.name) && + programme.duration) { + + var stopTime = programme.startTime + + programme.duration*1000; + + if (time >= programme.startTime + && time <= stopTime) { + context._timeout() + .then(function() { + self._cachedResults.push(programme); + // self.push(programme); + // self.totalSize = self.length; + }) + .then(context._timeout.bind(self, 10000)) + .then(getResultFromInterval.bind(null, count)) + .then(context._fireEvent.bind(context, + createCustomEvent("MetadataSearch", + [context._search, context.SEARCH_FINISHED]))); + break; + } + } + + } else if (programme[field] && + oipf.utils[methodName].call(null, + programme[field], value)) { + + var constraints = context._search. + _constraints.channels; + + if(constraints.length > 0 && oipf.utils.isPresent(constraints, - programme.channel.name) && - programme.duration) { - - var stopTime = programme.startTime + - programme.duration*1000; - - if (time >= programme.startTime - && time <= stopTime) { - console.log(programme); - this._timeout() - .then(function() { - self._cachedResults.push(programme); -// self.push(programme); -// self.totalSize = self.length; - console.log("[INFO] Program found."); - }) - .then(this._timeout.bind(self, 10000)) - .then(getResultFromInterval.bind(null, count)) - .then(this._fireEvent.bind(this, - createCustomEvent("MetadataSearch", - [this._search, this.SEARCH_FINISHED]))); - break; + programme.channel.name)) { + + context._cachedResults.push(programme); + continue; } + + if (constraints.length == 0) { + + context._cachedResults.push(programme); + // + } } - - } else if (programme[field] && - oipf.utils[methodName].call(null, - programme[field], value)) { - - var constraints = this._search. - _constraints.channels; + } + }; - if(constraints.length > 0 && - oipf.utils.isPresent(constraints, - programme.channel.name)) { - console.log("constraint", programme); - /* - * The results found are firstly put in a cache, - * then gathered. - */ -// this._timeout() -// .then(function() { -// self._cachedResults.push(programme); -// console.log("[INFO] Program found."); -// }); - this._cachedResults.push(programme); - continue; - } - - if (constraints.length == 0) { - - console.log("without constraint", programme); - this._cachedResults.push(programme); -// this._timeout() -// .then(function() { -// self._cachedResults.push(programme); -// console.log("[INFO] Program found."); -// }); - } + this._timeout() + .then(loop.bind(null, this, count)) + .then(function() { + if (self._search._currentQuery._type == "undifferent") { + self._timeout() + .then(getResultFromInterval.bind(null, count)) + .then(self._fireEvent.bind(self, + createCustomEvent("MetadataSearch", + [self._search, self.SEARCH_FINISHED]))); } - } + }); // if (this._search._ordering) { // this._timeout() @@ -227,14 +225,8 @@ // getResultFromInterval(count); // }); // } - if (this._search._currentQuery._type == "undifferent") { - this._timeout() - .then(getResultFromInterval.bind(null, count)) - .then(this._fireEvent.bind(this, - createCustomEvent("MetadataSearch", - [this._search, this.SEARCH_FINISHED]))); - } + } else { this._fireEvent(createCustomEvent("MetadataSearch", [this._search, this.SEARCH_CANNOT_BE_COMPLETED]));
participants (1)
-
ygregoï¼ users.nuiton.org