Author: ygrego Date: 2015-04-07 12:59:18 +0000 (Tue, 07 Apr 2015) New Revision: 1088 Url: http://forge.nuiton.org/projects/sandbox/repository/revisions/1088 Log: A verification have been added in "getResults" concerning the validity of query. Modified: oipf/js/impl/model/SearchResults.js Modified: oipf/js/impl/model/SearchResults.js =================================================================== --- oipf/js/impl/model/SearchResults.js 2015-04-07 11:01:36 UTC (rev 1087) +++ oipf/js/impl/model/SearchResults.js 2015-04-07 12:59:18 UTC (rev 1088) @@ -117,51 +117,58 @@ .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; + + if (this.isValidField(this._search._currentQuery.field) && + this.isValidComparator( + this._search._currentQuery.comparison)) { + + var startTime = this._currentQuery.startTime; + + for (var i = 0; i< programmes.length; i++) { + var programme = programmes[i]; + var date = 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 (date.getTime() >= startTime && date.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 (date.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 { @@ -198,6 +205,30 @@ */ item: function(index) { return this[index]; + }, + + isValidField: function(field) { + var fieldMap = { + startTime: true, + name: true, + duration: true, + description: true, + episode: true + }; + return fieldMap[field]; + }, + + isValidComparator: function(comparator) { + var comparatorMap = { + 0: true, + 1: true, + 2: true, + 3: true, + 4: true, + 5: true, + 6: true + }; + return comparatorMap[comparator]; } }); \ No newline at end of file
participants (1)
-
ygregoï¼ users.nuiton.org