Author: ygrego Date: 2015-02-06 16:10:09 +0000 (Fri, 06 Feb 2015) New Revision: 773 Url: http://forge.nuiton.org/projects/sandbox/repository/revisions/773 Log: Addition of creation of a object query 'currentQuery' into object 'MetadaSearch'(into method findProgrammesFromStream), implementation of method 'getResults' only for current program, creation of current channel into 'OipfObjectFactory' constructor. Modified: oipf/js/impl/OipfObjectFactory.js oipf/js/impl/SearchManagerObject.js oipf/js/impl/model/MetadataSearch.js oipf/js/impl/model/SearchResults.js oipf/js/initObj/init.js oipf/js/test/test.js Modified: oipf/js/impl/OipfObjectFactory.js =================================================================== --- oipf/js/impl/OipfObjectFactory.js 2015-02-05 15:13:26 UTC (rev 772) +++ oipf/js/impl/OipfObjectFactory.js 2015-02-06 16:10:09 UTC (rev 773) @@ -29,6 +29,9 @@ //this.applicationManagerObject = new ApplicationManagerObject(); //this.capabilitiesObject = new CapabilitiesObject(); //this.codManagerObject = new CodManagerObject(); + var currentChannelType = "TYPE_TV"; + var currentChannelName = "ARTE"; + var currentChannel = new Channel(currentChannelName, currentChannelType); this.channelConfig = new ChannelConfig(null, currentChannel); //this.imsObject = new IMSObecjet(); //this.mdtfObject = new MDTFObject(); Modified: oipf/js/impl/SearchManagerObject.js =================================================================== --- oipf/js/impl/SearchManagerObject.js 2015-02-05 15:13:26 UTC (rev 772) +++ oipf/js/impl/SearchManagerObject.js 2015-02-06 16:10:09 UTC (rev 773) @@ -109,7 +109,7 @@ */ createSearch: function(searchTarget) { - return new MetadataSearch(searchTarget); + return new MetadataSearch(searchTarget, this); }, /* Modified: oipf/js/impl/model/MetadataSearch.js =================================================================== --- oipf/js/impl/model/MetadataSearch.js 2015-02-05 15:13:26 UTC (rev 772) +++ oipf/js/impl/model/MetadataSearch.js 2015-02-06 16:10:09 UTC (rev 773) @@ -95,7 +95,8 @@ * of search results determined by the getResults() parameters, or take an alternative approach not described here. */ var MetadataSearch = Class.extend({ - + + _searchManager: null, /* * Description: * The subset of search results that has been requested by the application. @@ -121,10 +122,9 @@ */ searchTarget: null, - init: function(searchTarget) { - + init: function(searchTarget, searchManager) { this.searchTarget = searchTarget; - this.result = new SearchResults(); + this._searchManager = searchManager; }, /* @@ -156,7 +156,9 @@ */ findProgrammesFromStream: function(channel, startTime, count) { console.log("[INFO]: findProgrammesFromStream [IN]"); - currentQuery = new Query(channel, startTime, count); + var currentQuery = new Query(channel, startTime, count); + this.result = new SearchResults(currentQuery); + this.result._search = this; console.log("[INFO]: findProgrammesFromStream [Out]"); }, Modified: oipf/js/impl/model/SearchResults.js =================================================================== --- oipf/js/impl/model/SearchResults.js 2015-02-05 15:13:26 UTC (rev 772) +++ oipf/js/impl/model/SearchResults.js 2015-02-06 16:10:09 UTC (rev 773) @@ -14,7 +14,7 @@ * In addition to the properties and methods defined below a SearchResults object SHALL support the array notation to * access the results in this collection. */ -var SearchResults = Class.extend({ +var SearchResults = Array.extend({ /* * Description: @@ -45,7 +45,11 @@ */ totalSize: null, - init: function() { + _search: null, + _currentQuery: null, + + init: function(currentQuery) { + this._currentQuery = currentQuery; this.lentgh = 0; this.totalSize = 0; }, @@ -71,11 +75,11 @@ stopStr = "-stop", startStr = "-start", currentChannelId = undefined, - channels = data.tv.channel, + channels = metadata.tv.channel, displayName, item, index, - programs = data.tv.programme, + programs = metadata.tv.programme, startTime, tmpSSTime, currentTime = new Date(), @@ -96,7 +100,7 @@ * 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})/; + 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 @@ -105,7 +109,7 @@ item = channels[i]; displayName = item[displayNameStr]; - if (displayName == currentChannel.name) { + if (displayName == this._currentQuery.channel.name) { currentChannelId = item[idStr] break; } @@ -118,7 +122,7 @@ console.log("[INFO] Current channel id found."); //Another loop will run, just a reinitialization. - startTime = currentQuery.startTime; + startTime = this._currentQuery.startTime; var hStart, hStop, mStart, mStop, sStart, sStop; @@ -137,32 +141,34 @@ tmpSSTime = item[startStr]; tmpSSTime = pattern.exec(tmpSSTime); + console.log(tmpSSTime); - hStart = parseInt(tmpSSTime[0]) +1; - mStart = parseInt(tmpSSTime[1]); - sStart = parseInt(tmpSSTime[2]); + 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[0]) +1; - mStop = parseInt(tmpSSTime[1]); - sStop = parseInt(tmpSSTime[2]); + hStop = parseInt(tmpSSTime[4])*3600; + mStop = parseInt(tmpSSTime[5])*60; + var stopTInNbSec = hStop+mStop; + console.log(hStop,mStop,stopTInNbSec); - if (currentTime.getUTCHours() >= hStart && currentTime.getUTCHours() >= mStart && currentTime.getUTCHours()>=sStart && - currentTime.getUTCHours() >= hStop && currentTime.getUTCHours() >= mStop && currentTime.getUTCHours()>=sStop - ) { - - console.log("[INFO] Program found.") + 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.") + console.log("[INFO] Program not yet found."); } - + } } @@ -171,18 +177,22 @@ } - //When user want more than one result into his search. - for (i = 0; i < count; i++) { - - this.[i] = programs[index]; - index++; - } +// document.dispatchEvent(new Event('MetadataSearch', { +// 'search': metaDataSearch, +// 'state': 0 +// })); +// console.log(this._search); + var self = this; + 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++; + } + self._search._searchManager.onMetadataSearch && self._search._searchManager.onMetadataSearch(self._search, 0); + }, 0); - this.dispatchEvent(new Event('MetadataSearch', { - 'search': metaDataSearch, - 'state': 0 - }); - return false; }, @@ -211,7 +221,7 @@ * */ item: function(index) { - + return this[index]; } }); \ No newline at end of file Modified: oipf/js/initObj/init.js =================================================================== --- oipf/js/initObj/init.js 2015-02-05 15:13:26 UTC (rev 772) +++ oipf/js/initObj/init.js 2015-02-06 16:10:09 UTC (rev 773) @@ -6,9 +6,5 @@ extends: "object" }); -var currentQuery; -var currentChannelType = "TYPE_TV"; -var currentChannelName = "ARTE"; -var currentChannel = new Channel(currentChannelName, currentChannelType); var oipfObjectFactory = new OipfObjectFactory(); var metadata = data; Modified: oipf/js/test/test.js =================================================================== --- oipf/js/test/test.js 2015-02-05 15:13:26 UTC (rev 772) +++ oipf/js/test/test.js 2015-02-06 16:10:09 UTC (rev 773) @@ -73,18 +73,11 @@ function testGetCurrentProgram(searchTarget, channel, startTime, offset, count){ - searchManagerObject = oipfObjectFactory.createSearchManagerObject(); - channelConfig = oipfObjectFactory.createChannelConfig(); - metaDataSearch = searchManagerObject.createSearch(searchTarget); - metaDataSearch.findProgrammesFromStream(channelConfig.currentChannel, null); - metaDataSearch.result.getResults(offset,count); - + var searchManagerObject = oipfObjectFactory.createSearchManagerObject(); searchManagerObject.onMetadataSearch = function(search, state) { - console.log("[INFO]: onMetadataSearch called", search); + console.log("[INFO]: onMetadataSearch called"); - var message = ""; - switch(state) { case 0: @@ -95,7 +88,7 @@ case 3: - message = " MetadataSearch in Idle state because of either search abort or parameters have been modified \ + var message = " MetadataSearch in Idle state because of either search abort or parameters have been modified \ (query, constraints or search target)"; break; @@ -110,4 +103,10 @@ } } + var channelConfig = oipfObjectFactory.createChannelConfig(); + var metaDataSearch = searchManagerObject.createSearch(searchTarget); + console.log(metaDataSearch); + metaDataSearch.findProgrammesFromStream(channelConfig.currentChannel, null); + metaDataSearch.result.getResults(offset, count); + console.log(">>>>>>>>>>>>>>>>>>>>>><<", metaDataSearch.result[0], ">>>>"); } \ No newline at end of file