Author: ygrego Date: 2015-04-07 11:01:36 +0000 (Tue, 07 Apr 2015) New Revision: 1087 Url: http://forge.nuiton.org/projects/sandbox/repository/revisions/1087 Log: A "if" condition block has been added in method "getResults" in order to manage subsequent calls to this one when all results have been found, this method must use the previously cached results. Modified: oipf/js/impl/model/SearchResults.js Modified: oipf/js/impl/model/SearchResults.js =================================================================== --- oipf/js/impl/model/SearchResults.js 2015-04-07 09:46:45 UTC (rev 1086) +++ oipf/js/impl/model/SearchResults.js 2015-04-07 11:01:36 UTC (rev 1087) @@ -84,52 +84,85 @@ var programmes = this._search._searchManager._metadata; + /* + * Verify some conditions before beginning of + * search. + */ if (this._currentQuery && programmes && offset && count) { - var startTime = this._currentQuery.startTime; - for (var i = 0; i< programmes.length; i++) { - var programme = programmes[i]; - var currentDate = new Date(); - /* - * The user searches information on the current program, broadcasted on the current channel. - * In this case don't need start time of program, the search must be proceeded on current time. - */ - if (startTime == null) { - if (programme.duration) { - var stopTime = startTime + programme.duration; - if (currentDate.getTime() >= startTime && currentDate.getTime() <= stopTime) { - console.log("[INFO] Program found."); - // Usefull to retrieve severals programs when user wants more than one programmes information. - var currentProgramIndex = i; - break; + /* + * A verification must be done on the presence of cached results + * in order to not restart a complete search when + * that's not necessary. + */ + if (this._cachedResults) { + + var getResultFromInterval = function(count) { + this.length = 0; + + for (var i = this.offset, l = count; i < l; i++) { + var programme = this._cachedResults[i]; + if (programme) { + this.push(programme); + } else { + this.fireEvent(createCustomEvent("MetadataSearch", + [this._search, + this.SEARCH_CANNOT_BE_COMPLETED])); + break; } } + }; + + this._timeout + .then(getResultFromInterval.bind(null, count)); + + } else { + var startTime = this._currentQuery.startTime; + + for (var i = 0; i< programmes.length; i++) { + var programme = programmes[i]; + var currentDate = new Date(); + /* + * The user searches information on the current program, broadcasted on the current channel. + * In this case don't need start time of program, the search must be proceeded on current time. + */ + if (startTime == null) { + if (programme.duration) { + var stopTime = startTime + programme.duration; + if (currentDate.getTime() >= startTime && currentDate.getTime() <= stopTime) { + console.log("[INFO] Program found."); + // Usefull to retrieve severals programs when user wants more than one programmes information. + var currentProgramIndex = i; + break; + } + } - } else { //The search use the start time like a filter to retrieve the required program information. + } else { //The search use the start time like a filter to retrieve the required program information. - if (currentDate.getTime() == startTime) { - currentProgramIndex = i; - break; + if (currentDate.getTime() == startTime) { + currentProgramIndex = i; + break; + } } + console.log("[INFO] Program not yet found."); } - console.log("[INFO] Program not yet found."); - } - var self = this; - setTimeout(function() { - console.log("<<<<<<<<<<<<<<", new Date(), ">>>>>>>>>>>>>>>>", currentProgramIndex); - //When user want more than one result into his search. - if (currentProgramIndex != undefined) { - for (var i = 0; i < count; i++) { - self.push(programmes[currentProgramIndex]); - currentProgramIndex++; + var self = this; + setTimeout(function() { + console.log("<<<<<<<<<<<<<<", new Date(), ">>>>>>>>>>>>>>>>", currentProgramIndex); + //When user want more than one result into his search. + if (currentProgramIndex != undefined) { + for (var i = 0; i < count; i++) { + self.push(programmes[currentProgramIndex]); + currentProgramIndex++; + } + self._search._searchManager.onMetadataSearch && self._search._searchManager.onMetadataSearch(self._search, 0); + } else { + self._search._searchManager.onMetadataSearch && self._search._searchManager.onMetadataSearch(self._search, 4); } - self._search._searchManager.onMetadataSearch && self._search._searchManager.onMetadataSearch(self._search, 0); - } else { - self._search._searchManager.onMetadataSearch && self._search._searchManager.onMetadataSearch(self._search, 4); - } - }, 0); + }, 0); + } } else { this._fireEvent(createCustomEvent("MetadataSearch",
participants (1)
-
ygregoï¼ users.nuiton.org