diff --git a/www/js/DataModel.js b/www/js/DataModel.js index 71062b574..168c29f17 100644 --- a/www/js/DataModel.js +++ b/www/js/DataModel.js @@ -675,6 +675,67 @@ angular.module('zmApp.controllers') debug(val); }, + evaluateTappedNotification: function() { + + var state = ""; + var stateParams1 = {}; + var stateParams2 = {}; + + debug ("Inside evaluateNotifications"); + + if ($rootScope.tappedNotification == 2) { // url launch + debug("Came via app url launch with mid=" + $rootScope.tappedMid); + debug("Came via app url launch with eid=" + $rootScope.tappedEid); + + + if (parseInt($rootScope.tappedMid) > 0) { + debug("Going to live view "); + state = "app.monitors"; + + } else if (parseInt($rootScope.tappedEid) > 0) { + debug("Going to events with EID=" + $rootScope.tappedEid); + state = "app.events"; + stateParams1 = { + "id": 0, + "playEvent": true + }; + stateParams2 = { + reload: true + }; + + } + + + } // 2 + else if ($rootScope.tappedNotification == 1) // push + { + + + debug("Came via push tap. onTapScreen=" + loginData.onTapScreen); + if (loginData.onTapScreen == $translate.instant('kTapMontage')) { + debug("Going to montage"); + state = "app.montage"; + + + } else if (loginData.onTapScreen == $translate.instant('kTapEvents')) { + debug("Going to events"); + state = "app.events"; + stateParams1 = { + "id": 0, + "playEvent": true + }; + + } else // we go to live + { + debug("Going to live view "); + state = "app.monitors"; + + } + } + $rootScope.tappedNotification = 0; + return [state, stateParams1, stateParams2]; + }, + setLastUpdateCheck: function (val) { lastUpdateCheck = val; localforage.setItem("lastUpdateCheck", lastUpdateCheck); diff --git a/www/js/DevOptionsCtrl.js b/www/js/DevOptionsCtrl.js index dab4570bd..5592baa3b 100644 --- a/www/js/DevOptionsCtrl.js +++ b/www/js/DevOptionsCtrl.js @@ -10,6 +10,17 @@ angular.module('zmApp.controllers').controller('zmApp.DevOptionsCtrl', ['$scope' }; + $scope.$on ( "process-push", function () { + NVRDataModel.debug (">> DevOptionsCtrl: push handler"); + var s = NVRDataModel.evaluateTappedNotification(); + NVRDataModel.debug("tapped Notification evaluation:"+ JSON.stringify(s)); + $ionicHistory.nextViewOptions({ + disableAnimate:true, + disableBack: true + }); + $state.go(s[0],s[1],s[2]); + }); + //---------------------------------------------------------------- // Alarm notification handling //---------------------------------------------------------------- diff --git a/www/js/EventCtrl.js b/www/js/EventCtrl.js index 2c64ce70d..cce81b3ae 100644 --- a/www/js/EventCtrl.js +++ b/www/js/EventCtrl.js @@ -71,6 +71,19 @@ angular.module('zmApp.controllers') // initial code //--------------------------------------------------- + + $scope.$on ( "process-push", function () { + NVRDataModel.debug (">> EventCtrl: push handler"); + var s = NVRDataModel.evaluateTappedNotification(); + NVRDataModel.debug("tapped Notification evaluation:"+ JSON.stringify(s)); + $ionicHistory.nextViewOptions({ + disableAnimate:true, + disableBack: true + }); + $state.go(s[0],s[1],s[2]); + }); + + //we come here is TZ is updated after the view loads var tzu = $scope.$on('tz-updated', function () { $scope.tzAbbr = NVRDataModel.getTimeZoneNow(); @@ -115,8 +128,8 @@ angular.module('zmApp.controllers') footerExpand(); // now do event playback if asked - if (parseInt($rootScope.tappedEid) > 0) { - NVRDataModel.debug(" Trying ot live play " + $rootScope.tappedEid); + if (parseInt($rootScope.tappedEid) > 0 && $stateParams.playEvent == 'true') { + NVRDataModel.debug(" Trying to play event due to push:" + $rootScope.tappedEid); playSpecificEvent($rootScope.tappedEid); } @@ -148,7 +161,7 @@ angular.module('zmApp.controllers') window.removeEventListener("resize", recomputeThumbSize, false); NVRDataModel.debug("EventCtrl: Deregistering broadcast handles"); for (var i = 0; i < broadcastHandles.length; i++) { - // broadcastHandles[i](); + // broadcastHandles[i](); } broadcastHandles = []; }); diff --git a/www/js/EventServer.js b/www/js/EventServer.js index 1340b88d2..da1e07a3a 100644 --- a/www/js/EventServer.js +++ b/www/js/EventServer.js @@ -598,13 +598,13 @@ angular.module('zmApp.controllers') $rootScope.tappedMid = mid; $rootScope.tappedEid = eid; - NVRDataModel.log("Push notification: Tapped Monitor taken as:" + $rootScope.tappedMid); + NVRDataModel.log("ES:Push notification: Tapped Monitor taken as:" + $rootScope.tappedMid); if ($rootScope.platformOS == 'ios') { - NVRDataModel.debug("iOS only: clearing background push"); + NVRDataModel.debug("ES:iOS only: clearing background push"); push.finish(function () { - NVRDataModel.debug("processing of push data is finished"); + NVRDataModel.debug("ES:processing of push data is finished"); }); } @@ -616,7 +616,9 @@ angular.module('zmApp.controllers') } // keep this emit not broadcast // see Portal latch for reason - $rootScope.$emit('process-push'); + + NVRDataModel.debug ("EventServer: broadvasting process-push"); + $rootScope.$broadcast('process-push'); } else // app is foreground { diff --git a/www/js/LogCtrl.js b/www/js/LogCtrl.js index 46db43048..9a84661ac 100644 --- a/www/js/LogCtrl.js +++ b/www/js/LogCtrl.js @@ -26,6 +26,17 @@ angular.module('zmApp.controllers').controller('zmApp.LogCtrl', ['$scope', '$roo loadLogs(); } + $scope.$on ( "process-push", function () { + NVRDataModel.debug (">> LogCtrl: push handler"); + var s = NVRDataModel.evaluateTappedNotification(); + NVRDataModel.debug("tapped Notification evaluation:"+ JSON.stringify(s)); + $ionicHistory.nextViewOptions({ + disableAnimate:true, + disableBack: true + }); + $state.go(s[0],s[1],s[2]); + }); + $scope.flipLogs = function () { if ($scope.logEntity == 'ZoneMinder') $scope.logEntity = $rootScope.appName; diff --git a/www/js/LoginCtrl.js b/www/js/LoginCtrl.js index a9a09433d..568b67edb 100644 --- a/www/js/LoginCtrl.js +++ b/www/js/LoginCtrl.js @@ -33,6 +33,17 @@ angular.module('zmApp.controllers').controller('zmApp.LoginCtrl', ['$scope', '$r } + $scope.$on ( "process-push", function () { + NVRDataModel.debug (">> LoginCtrl: push handler"); + var s = NVRDataModel.evaluateTappedNotification(); + NVRDataModel.debug("tapped Notification evaluation:"+ JSON.stringify(s)); + $ionicHistory.nextViewOptions({ + disableAnimate:true, + disableBack: true + }); + $state.go(s[0],s[1],s[2]); + }); + //---------------------------------------------------------------- // Alarm notification handling //---------------------------------------------------------------- diff --git a/www/js/MomentCtrl.js b/www/js/MomentCtrl.js index ace5d218b..d108010d3 100644 --- a/www/js/MomentCtrl.js +++ b/www/js/MomentCtrl.js @@ -23,6 +23,17 @@ angular.module('zmApp.controllers').controller('zmApp.MomentCtrl', ['$scope', '$ $ionicSideMenuDelegate.toggleLeft(); }; + $scope.$on ( "process-push", function () { + NVRDataModel.debug (">> MomentCtrl: push handler"); + var s = NVRDataModel.evaluateTappedNotification(); + NVRDataModel.debug("tapped Notification evaluation:"+ JSON.stringify(s)); + $ionicHistory.nextViewOptions({ + disableAnimate:true, + disableBack: true + }); + $state.go(s[0],s[1],s[2]); + }); + //---------------------------------------------------------------- // Alarm notification handling //---------------------------------------------------------------- diff --git a/www/js/MonitorCtrl.js b/www/js/MonitorCtrl.js index dbc4a7f3e..6e2ce0199 100644 --- a/www/js/MonitorCtrl.js +++ b/www/js/MonitorCtrl.js @@ -48,6 +48,17 @@ angular.module('zmApp.controllers') $ionicSideMenuDelegate.toggleLeft(); }; + $scope.$on ( "process-push", function () { + NVRDataModel.debug (">> MonitorCtrl: push handler"); + var s = NVRDataModel.evaluateTappedNotification(); + NVRDataModel.debug("tapped Notification evaluation:"+ JSON.stringify(s)); + $ionicHistory.nextViewOptions({ + disableAnimate:true, + disableBack: true + }); + $state.go(s[0],s[1],s[2]); + }); + //---------------------------------------------------------------- // Alarm notification handling //---------------------------------------------------------------- diff --git a/www/js/MontageCtrl.js b/www/js/MontageCtrl.js index 003e11682..dd5747040 100644 --- a/www/js/MontageCtrl.js +++ b/www/js/MontageCtrl.js @@ -47,6 +47,20 @@ angular.module('zmApp.controllers') var broadcastHandles = []; + $scope.$on ( "process-push", function () { + NVRDataModel.debug (">> MontageCtrl: push handler"); + var s = NVRDataModel.evaluateTappedNotification(); + NVRDataModel.debug("tapped Notification evaluation:"+ JSON.stringify(s)); + $ionicHistory.nextViewOptions({ + disableAnimate:true, + disableBack: true + }); + $state.go(s[0],s[1],s[2]); + }); + + + + var as = $scope.$on("auth-success", function () { /* var tnow = new Date(); @@ -2012,6 +2026,11 @@ angular.module('zmApp.controllers') currentStreamState = streamState.STOPPED; viewCleanup(); viewCleaned = true; + NVRDataModel.debug("Deregistering broadcast handles"); + for (var i = 0; i < broadcastHandles.length; i++) { + broadcastHandles[i](); + } + broadcastHandles = []; }); diff --git a/www/js/MontageHistoryCtrl.js b/www/js/MontageHistoryCtrl.js index e2782387a..ea9f7f2ff 100644 --- a/www/js/MontageHistoryCtrl.js +++ b/www/js/MontageHistoryCtrl.js @@ -11,6 +11,18 @@ angular.module('zmApp.controllers').controller('zmApp.MontageHistoryCtrl', ['$sc var viewCleaned = false; $scope.isScreenReady = false; + + $scope.$on ( "process-push", function () { + NVRDataModel.debug (">> MontageHistoryCtrl: push handler"); + var s = NVRDataModel.evaluateTappedNotification(); + NVRDataModel.debug("tapped Notification evaluation:"+ JSON.stringify(s)); + $ionicHistory.nextViewOptions({ + disableAnimate:true, + disableBack: true + }); + $state.go(s[0],s[1],s[2]); + }); + //-------------------------------------------------------------------------------------- // Handles bandwidth change, if required // diff --git a/www/js/NewsCtrl.js b/www/js/NewsCtrl.js index ba45fb0e1..d98500802 100644 --- a/www/js/NewsCtrl.js +++ b/www/js/NewsCtrl.js @@ -27,6 +27,17 @@ angular.module('zmApp.controllers').controller('zmApp.NewsCtrl', ['$scope', '$ro } }; + $scope.$on ( "process-push", function () { + NVRDataModel.debug (">> NewsCtrl: push handler"); + var s = NVRDataModel.evaluateTappedNotification(); + NVRDataModel.debug("tapped Notification evaluation:"+ JSON.stringify(s)); + $ionicHistory.nextViewOptions({ + disableAnimate:true, + disableBack: true + }); + $state.go(s[0],s[1],s[2]); + }); + //------------------------------------------------------------------------- // Lets make sure we set screen dim properly as we enter // The problem is we enter other states before we leave previous states diff --git a/www/js/PortalLoginCtrl.js b/www/js/PortalLoginCtrl.js index 592e2c431..9789ed56e 100644 --- a/www/js/PortalLoginCtrl.js +++ b/www/js/PortalLoginCtrl.js @@ -5,7 +5,7 @@ /* global vis,cordova,StatusBar,angular,console,moment */ angular.module('zmApp.controllers').controller('zmApp.PortalLoginCtrl', ['$ionicPlatform', '$scope', 'zm', 'NVRDataModel', '$ionicSideMenuDelegate', '$rootScope', '$http', '$q', '$state', '$ionicLoading', '$ionicPopover', '$ionicScrollDelegate', '$ionicModal', '$timeout', 'zmAutoLogin', '$ionicHistory', 'EventServer', '$translate', '$ionicPopup', function ($ionicPlatform, $scope, zm, NVRDataModel, $ionicSideMenuDelegate, $rootScope, $http, $q, $state, $ionicLoading, $ionicPopover, $ionicScrollDelegate, $ionicModal, $timeout, zmAutoLogin, $ionicHistory, EventServer, $translate, $ionicPopup) { - var processPush = false; + var broadcastHandles = []; $scope.$on('$ionicView.beforeLeave', function () { @@ -270,95 +270,8 @@ angular.module('zmApp.controllers').controller('zmApp.PortalLoginCtrl', ['$ionic } - //this needs to be rootScope so it lives even when we are out of view - var pp = $rootScope.$on("process-push", function () { - processPush = true; - NVRDataModel.debug("processPush set to true, but will act after login is complete..."); - - - - - }); - broadcastHandles.push(pp); - - function evaluateTappedNotification() { - NVRDataModel.debug (">>>Inside evaluateNotifications"); - var ld = NVRDataModel.getLogin(); - - - if ($rootScope.tappedNotification == 2) { // url launch - NVRDataModel.debug("Came via app url launch with mid=" + $rootScope.tappedMid); - NVRDataModel.debug("Came via app url launch with eid=" + $rootScope.tappedEid); - $rootScope.tappedNotification = 0; - $ionicHistory.nextViewOptions({ - disableBack: true - }); - - if (parseInt($rootScope.tappedMid) > 0) { - NVRDataModel.debug("Going to live view "); - $state.go("app.monitors"); - return; - - } else if (parseInt($rootScope.tappedEid) > 0) { - NVRDataModel.debug("Going to events with EID=" + $rootScope.tappedEid); - $state.go("app.events", { - //"id": $rootScope.tappedEid, - "id": 0, - "playEvent": true - }, { - reload: true - }); - return; - } - // go with monitor first, then event - just because I feel like ;) - - - } else if ($rootScope.tappedNotification == 1) // push - { - - - NVRDataModel.log("Came via push tap. onTapScreen=" + ld.onTapScreen); - $rootScope.pushOverride = true; - //console.log ("***** NOTIFICATION TAPPED "); - $rootScope.tappedNotification = 0; - $ionicHistory.nextViewOptions({ - disableBack: true - }); - - if (ld.onTapScreen == $translate.instant('kTapMontage')) { - NVRDataModel.debug("Going to montage"); - $state.go("app.montage"); - - return; - } else if (ld.onTapScreen == $translate.instant('kTapEvents')) { - NVRDataModel.debug("Going to events"); - $state.go("app.events", { - "id": 0, - "playEvent": false - }); - return; - } else // we go to live - { - NVRDataModel.debug("Going to live view "); - $state.go("app.monitors"); - return; - } - } else { - /* NVRDataModel.debug ("Inside evaluateTapped, but no tap occured."); - NVRDataModel.debug ("This can happen if timing mismatch and holy foo happens"); - $state.go("app.montage", - {}, - { - reload: true - }); - return;*/ - - } - - } - - + //broadcastHandles.push(pp); function unlock(idVerified) { /* @@ -455,7 +368,7 @@ angular.module('zmApp.controllers').controller('zmApp.PortalLoginCtrl', ['$ionic // if push happens AFTER this, then while going to // lastState, it will interrupt and go to onTap // (I HOPE...) - if (!processPush) { + //console.log ("NOTIFICATION TAPPED INSIDE CHECK IS "+$rootScope.tappedNotification); var statetoGo = $rootScope.lastState ? $rootScope.lastState : 'app.montage'; // NVRDataModel.debug("logging state transition"); @@ -465,16 +378,7 @@ angular.module('zmApp.controllers').controller('zmApp.PortalLoginCtrl', ['$ionic $state.go(statetoGo, $rootScope.lastStateParam); return; - } - else { - NVRDataModel.debug ("Authentication over, now processing push..."); - evaluateTappedNotification(); - processPush = false; - } - // else - // evaluateTappedNotification(); - - + }, function (error) { // API Error NVRDataModel.log("API Error handler: going to login getAPI returned error: " + JSON.stringify(error)); diff --git a/www/js/StateCtrl.js b/www/js/StateCtrl.js index 62bffb81b..096df1e0e 100644 --- a/www/js/StateCtrl.js +++ b/www/js/StateCtrl.js @@ -34,6 +34,18 @@ angular.module('zmApp.controllers').controller('zmApp.StateCtrl', ['$ionicPopup' var inProgress = 0; // prevents user from another op if one is in progress getRunStatus(); + + $scope.$on ( "process-push", function () { + NVRDataModel.debug (">> StateCtrl: push handler"); + var s = NVRDataModel.evaluateTappedNotification(); + NVRDataModel.debug("tapped Notification evaluation:"+ JSON.stringify(s)); + $ionicHistory.nextViewOptions({ + disableAnimate:true, + disableBack: true + }); + $state.go(s[0],s[1],s[2]); + }); + // Let's stagger this by 500ms each to see if Chrome lets these through // This may also help if your Apache is not configured to let multiple connections through diff --git a/www/js/TimelineCtrl.js b/www/js/TimelineCtrl.js index 4a1440920..a75199f41 100644 --- a/www/js/TimelineCtrl.js +++ b/www/js/TimelineCtrl.js @@ -20,6 +20,18 @@ angular.module('zmApp.controllers').controller('zmApp.TimelineCtrl', ['$ionicPla $ionicSideMenuDelegate.toggleLeft(); }; + + $scope.$on ( "process-push", function () { + NVRDataModel.debug (">> TimelineCtrl: push handler"); + var s = NVRDataModel.evaluateTappedNotification(); + NVRDataModel.debug("tapped Notification evaluation:"+ JSON.stringify(s)); + $ionicHistory.nextViewOptions({ + disableAnimate:true, + disableBack: true + }); + $state.go(s[0],s[1],s[2]); + }); + //---------------------------------------f------------------------- // Alarm notification handling //---------------------------------------------------------------- @@ -285,7 +297,7 @@ angular.module('zmApp.controllers').controller('zmApp.TimelineCtrl', ['$ionicPla NVRDataModel.debug("Timeline: Deregistering broadcast handles"); for (var i = 0; i < broadcastHandles.length; i++) { - // broadcastHandles[i](); + broadcastHandles[i](); } broadcastHandles = [];