diff --git a/common/js/ogAPI2.js b/common/js/ogAPI2.js index 48d6172..7f2c4b5 100644 --- a/common/js/ogAPI2.js +++ b/common/js/ogAPI2.js @@ -588,11 +588,16 @@ var GLOBAL_UPDATE_TARGET; service.getNowAndNext = function () { return $http.get( API_PATH + 'tv/currentgrid' ) .then(stripData); - } + }; service.changeChannel = function ( channelNum ) { return $http.post( API_PATH + 'tv/change/' + channelNum ); - } + }; + + service.getCurrentChannel = function () { + return $http.get( API_PATH + 'tv/currentchannel') + .then(stripData); + }; return service; } ) diff --git a/control/app/components/directives/StationCell.directive.js b/control/app/components/directives/StationCell.directive.js index 77ddadb..0d1a376 100644 --- a/control/app/components/directives/StationCell.directive.js +++ b/control/app/components/directives/StationCell.directive.js @@ -27,11 +27,60 @@ app.directive( 'stationCell', var hud = uibHelper.curtainModal( 'Changing...' ); $log.debug( "Changing channel to: " + scope.grid.channel.channelNumber ); - ogProgramGuide.changeChannel( scope.grid.channel.channelNumber ); - $rootScope.currentChannel = scope.grid; - $timeout(function(){ hud.dismiss() }, 5000); + ogProgramGuide.changeChannel( scope.grid.channel.channelNumber ) + .then( function () { + return $timeout(5000); + }) + .then( function () { + return ogProgramGuide.getCurrentChannel(); + }) + .then( function( channel ) { + if ( scope.grid.channel.channelNumber != channel.channelNumber ) { + $log.debug("channel numbers do NOT match!"); + hud.dismiss(); + uibHelper.headsupModal('Unable to Change Channel', 'The channel change was unsuccessful. You are not subscribed to the channel.'); + } else { + $log.debug("channel change successful"); + $rootScope.currentChannel = scope.grid; + hud.dismiss(); + } + }) + .catch( function ( err ) { + hud.dismiss(); + switch ( err.status ) { + case 406: + uibHelper.headsupModal( "Problem Changing Channel", "There was an issue with changing the channel and your request could not be completed."); + break; + case 500: + uibHelper.headsupModal( "Internal Server Error", "The device was not able to change the channel."); + break; + default: + uibHelper.headsupModal( "Error: Unable to connect", "Unable to connect to the system. Please check wifi connection and try again."); + break; + } + }); - } + // $rootScope.tempCurrentChannel = scope.grid; + // $timeout(function() { + // ogProgramGuide.getCurrentChannel() + // .then(function ( channel ) { + // if ($rootScope.tempCurrentChannel.channel.channelNumber != channel.data.channelNumber) { + // $log.debug("channel numbers do NOT match!"); + // hud.dismiss(); + // uibHelper.headsupModal('Unable to Change Channel', 'The channel change was unsuccessful. You are not subscribed to the channel.'); + // } else { + // $log.debug("channel change successful"); + // $rootScope.currentChannel = $rootScope.tempCurrentChannel; + // hud.dismiss(); + // } + // }) + // .catch(function ( err ) { + // hud.dismiss(); + // uibHelper.headsupModal('Error', 'An error has occurred while getting the current channel.'); + // }) + // }, 5000); + + }; scope.displayTime = function ( timeStr) { diff --git a/control/app/components/guide/guide.controller.js b/control/app/components/guide/guide.controller.js index f619b01..f94a9eb 100644 --- a/control/app/components/guide/guide.controller.js +++ b/control/app/components/guide/guide.controller.js @@ -17,7 +17,7 @@ app.controller( "guideController", $rootScope.currentChannel = {}; - function getCurrentChannel() { + function getCurrentProgramming() { return ogProgramGuide.getNowAndNext() .then(function (grid) { $log.debug("Got the grid and current channel."); @@ -25,7 +25,7 @@ app.controller( "guideController", }); } - getCurrentChannel(); + getCurrentProgramming(); function loadListings(){ ogNet.getGrid(false)