Author: ygrego Date: 2015-02-09 13:37:22 +0000 (Mon, 09 Feb 2015) New Revision: 775 Url: http://forge.nuiton.org/projects/sandbox/repository/revisions/775 Log: New approach defined(into class 'SearchResults') for a search based on call of javascript method 'Date.getTime()', addition of new javascript sources in file 'welcome.html', insertion of a console display in method 'onMetadataSearch()' when parameter 'state' takes value '3' or '4'. Modified: oipf/js/impl/model/SearchResults.js oipf/js/test/test.js oipf/view/welcome.html Modified: oipf/js/impl/model/SearchResults.js =================================================================== --- oipf/js/impl/model/SearchResults.js 2015-02-06 16:17:45 UTC (rev 774) +++ oipf/js/impl/model/SearchResults.js 2015-02-09 13:37:22 UTC (rev 775) @@ -77,34 +77,12 @@ currentChannelId = undefined, channels = metadata.tv.channel, displayName, - item, - index, programs = metadata.tv.programme, - startTime, - tmpSSTime, - currentTime = new Date(), - currentStopTime, - currentStartTime, - /* - * Usefull to retrieve severals programs when user want more than one programs information. - */ - currentProgramIndex, - - /* - * Used to found the current program : the smaller difference between current time and stop time of a program, - * means that the program stopping a this stop time is the current program. - */ - smallerDiff, - - /* - * The difference calculated during the loop of current program searching. - */ - currentDiff, pattern = /(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})\s\+(\d{2})/; - var i; + //Found the associated id of current channel in metadata because channel is referenced by id in program information - for (i = 0; i<channels.length; i++) { + for (var i = 0; i<channels.length; i++) { item = channels[i]; displayName = item[displayNameStr]; @@ -120,63 +98,71 @@ return; } console.log("[INFO] Current channel id found."); - - //Another loop will run, just a reinitialization. - startTime = this._currentQuery.startTime; - var hStart, hStop, - mStart, mStop, - sStart, sStop; - - /* - * 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) { + + var startTime = this._currentQuery.startTime; - //Found programs of current channel only - for (i = 0; i< programs.length; i++) { - item = programs[i] + //Found programs of current channel only + for (var i = 0; i< programs.length; i++) { + var item = programs[i]; + + if (item[channelStr] == currentChannelId) { // && date + + var tmpSSTime = item[startStr]; + tmpSSTime = pattern.exec(tmpSSTime); + console.log(tmpSSTime); + var dateTmp = new Date(); - if (item[channelStr] == currentChannelId) { - - tmpSSTime = item[startStr]; - tmpSSTime = pattern.exec(tmpSSTime); - - console.log(tmpSSTime); - - hStart = parseInt(tmpSSTime[4])*3600; - mStart = parseInt(tmpSSTime[5])*60; - var startTInNbSec = hStart+mStart; - console.log(hStart,mStart,startTInNbSec); - - tmpSSTime = item[stopStr]; - tmpSSTime = pattern.exec(tmpSSTime); - console.log(tmpSSTime); - - hStop = parseInt(tmpSSTime[4])*3600; - mStop = parseInt(tmpSSTime[5])*60; - var stopTInNbSec = hStop+mStop; - console.log(hStop,mStop,stopTInNbSec); - - var currentTimeInNbSec = (currentTime.getUTCHours()+1)*3600 + (currentTime.getUTCMinutes()*60) - console.log(currentTimeInNbSec); - - if ( (currentTimeInNbSec >= startTInNbSec) && (currentTimeInNbSec <= stopTInNbSec) ) { - console.log("[INFO] Program found."); - index = i; - break; - } else { - console.log("[INFO] Program not yet found."); + /*year = parseInt(tmpSSTime[1]); + month = parseInt(tmpSSTime[2]); + day = parseInt(tmpSSTime[3]);*/ + var year = dateTmp.getFullYear(); + var month = dateTmp.getUTCMonth(); + var day = dateTmp.getUTCDate(); + var hs = parseInt(tmpSSTime[4]); + var mins = parseInt(tmpSSTime[5]); + var secs = parseInt(tmpSSTime[6]); + + var startDate = new Date(year, month, day, hs, mins, secs); + + tmpSSTime = item[stopStr]; + tmpSSTime = pattern.exec(tmpSSTime); + console.log(tmpSSTime); + + year = dateTmp.getFullYear(); + month = dateTmp.getUTCMonth(); + day = dateTmp.getUTCDate(); + hs = parseInt(tmpSSTime[4]); + mins = parseInt(tmpSSTime[5]); + secs = parseInt(tmpSSTime[6]); + + var stopDate = new Date(year, month, day, hs, mins, secs); + + 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 ( (currentDate.getTime() >= startDate.getTime()) && (currentDate.getTime() <= stopDate.getTime()) ) { + console.log("[INFO] Program found."); + var currentProgramIndex = i; // Usefull to retrieve severals programs when user want more than one programs information. + break; + } + + } else { //The search use the start time like a filter to retrieve the required program information. + + if (this._currentQuery.starTime == startDate.getTime()) { + var currentProgramIndex = i; // Usefull to retrieve severals programs when user want more than one programs information. + break; } - } - } - - } else { //The search use the start time like a filter to retrieve the required program information. - - + console.log("[INFO] Program not yet found."); + } } + // document.dispatchEvent(new Event('MetadataSearch', { // 'search': metaDataSearch, // 'state': 0 @@ -186,11 +172,16 @@ setTimeout(function() { console.log("<<<<<<<<<<<<<<", new Date(), ">>>>>>>>>>>>>>>>"); //When user want more than one result into his search. - for (var i = 0; i < count; i++) { - self.push(programs[index]); - index++; + if (currentProgramIndex) { + for (var i = 0; i < count; i++) { + self.push(programs[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); + }, 0); return false; Modified: oipf/js/test/test.js =================================================================== --- oipf/js/test/test.js 2015-02-06 16:17:45 UTC (rev 774) +++ oipf/js/test/test.js 2015-02-09 13:37:22 UTC (rev 775) @@ -88,18 +88,18 @@ case 3: - var message = " MetadataSearch in Idle state because of either search abort or parameters have been modified \ - (query, constraints or search target)"; + var message = "[INFO] MetadataSearch in Idle state because of either search abort or parameters have been modified (query, constraints or search target)"; + console.log(message); break; case 4: - message = " The search cannot be complete because of lack of ressources or any other reason.\ - (memory insufficient to cache all of the requested results.)"; + message = "[INFO] The search cannot be complete because of lack of ressources or any other reason."; + console.log(message); break; default: - console.log("Unknow state :("); + console.log("Unknow state"); } } Modified: oipf/view/welcome.html =================================================================== --- oipf/view/welcome.html 2015-02-06 16:17:45 UTC (rev 774) +++ oipf/view/welcome.html 2015-02-09 13:37:22 UTC (rev 775) @@ -5,6 +5,10 @@ <script src="../js/lib/Class.js" type="text/javascript"></script> <script src="../js/lib/Collection.js" type="text/javascript"></script> <script src="../data/data.js" type="text/javascript"></script> + <script src="../js/impl/model/Query.js" type="text/javascript"></script> + <script src="../js/impl/model/Channel.js" type="text/javascript"></script> + <script src="../js/impl/model/MetadataSearch.js" type="text/javascript"></script> + <script src="../js/impl/model/SearchResults.js" type="text/javascript"></script> <script src="../js/impl/OipfObjectFactory.js" type="text/javascript"></script> <script src="../js/impl/ChannelConfig.js" type="text/javascript"></script> <script src="../js/impl/VideoBroadcastObject.js" type="text/javascript"></script>
participants (1)
-
ygregoï¼ users.nuiton.org