diff options
Diffstat (limited to 'www/js')
| -rw-r--r-- | www/js/MonitorCtrl.js | 185 | ||||
| -rw-r--r-- | www/js/app.js | 126 |
2 files changed, 157 insertions, 154 deletions
diff --git a/www/js/MonitorCtrl.js b/www/js/MonitorCtrl.js index b06e024b..5175237d 100644 --- a/www/js/MonitorCtrl.js +++ b/www/js/MonitorCtrl.js @@ -1,4 +1,4 @@ -/* jshint -W041 */ +/* jshint -W041, -W083 */ /* jslint browser: true*/ /* global cordova,StatusBar,angular,console */ @@ -13,9 +13,6 @@ angular.module('zmApp.controllers').controller('zmApp.MonitorCtrl', ['$ionicPopu $scope.monitors = []; - - - $scope.openMenu = function () { $ionicSideMenuDelegate.toggleLeft(); }; @@ -30,117 +27,7 @@ angular.module('zmApp.controllers').controller('zmApp.MonitorCtrl', ['$ionicPopu }); }; - $scope.radialMenuOptions = { - content: '', - - background: '#2F4F4F', - isOpen: false, - toggleOnClick: false, - button: { - cssClass: "fa fa-arrows-alt", - }, - items: [ - { - content: '', - cssClass: 'fa fa-chevron-circle-up', - empty: false, - onclick: function () { - controlPTZ($scope.monitorId, 'Down'); - } - }, - - { - content: '', - cssClass: 'fa fa-chevron-circle-up', - empty: false, - onclick: function () { - controlPTZ($scope.monitorId, 'DownLeft'); - } - }, - - { - content: '', - cssClass: 'fa fa-chevron-circle-up', - empty: false, - - onclick: function () { - controlPTZ($scope.monitorId, 'Left'); - } - }, - { - content: 'D', - empty: true, - - onclick: function () { - console.log('About'); - } - }, - - { - content: '', - cssClass: 'fa fa-chevron-circle-up', - empty: false, - onclick: function () { - controlPTZ($scope.monitorId, 'UpLeft'); - } - }, - { - content: '', - cssClass: 'fa fa-chevron-circle-up', - empty: false, - onclick: function () { - controlPTZ($scope.monitorId, 'Up'); - } - }, - - { - content: '', - cssClass: 'fa fa-chevron-circle-up', - empty: false, - onclick: function () { - controlPTZ($scope.monitorId, 'UpRight'); - } - }, - - { - content: 'H', - empty: true, - onclick: function () { - console.log('About'); - } - }, - - { - content: '', - cssClass: 'fa fa-chevron-circle-up', - empty: false, - onclick: function () { - controlPTZ($scope.monitorId, 'Right'); - } - }, - - - { - content: '', - cssClass: 'fa fa-chevron-circle-up', - empty: false, - onclick: function () { - controlPTZ($scope.monitorId, 'DownRight'); - } - }, - - { - content: 'K', - empty: true, - onclick: function () { - console.log('About'); - } - }, - - - ] - }; // This function takes care of changing function parameters @@ -450,7 +337,8 @@ angular.module('zmApp.controllers').controller('zmApp.MonitorCtrl', ['$ionicPopu // console.log('Set-Cookie'+ header('Set-Cookie')); // - + // FIXME: Put in an interval and do this once every few + // minutes so it does not time out var req = $http({ method: 'POST', /*timeout: 15000,*/ @@ -469,6 +357,12 @@ angular.module('zmApp.controllers').controller('zmApp.MonitorCtrl', ['$ionicPopu return foo; }, + // FIXME: Refer to + // zoneminder/skins/mobile/includes/control_functions.php + // for move commands + // logic - /zm/api/monitors/X.json, read ControlId = Y + // then zm/api/controls/Y.json + data: { view: "request", request: "control", @@ -505,14 +399,75 @@ angular.module('zmApp.controllers').controller('zmApp.MonitorCtrl', ['$ionicPopu console.log("***EVENTS: Waiting for Monitors to load before I proceed"); $scope.monitors = message; + var loginData = ZMDataModel.getLogin(); + monitorStateCheck(); + function monitorStateCheck() + { + var apiMonCheck; + + // The status is provided by zmdc.pl + // "not running", "pending", "running since", "Unable to connect" + + for (var i = 0; i < $scope.monitors.length; i++) { + (function (j) + { + $scope.monitors[j].Monitor.isRunningText = "..."; + $scope.monitors[j].Monitor.isRunning = "..."; + $scope.monitors[j].Monitor.color = '#1E90FF'; + $scope.monitors[j].Monitor.char = "ion-checkmark-circled"; + apiMonCheck = loginData.apiurl + "/monitors/daemonStatus/id:" + $scope.monitors[j].Monitor.Id + "/daemon:zmc.json"; + console.log ("**** ZMC CHECK " + apiMonCheck); + $http.get(apiMonCheck) + .success(function(data) + { + if (data.statustext.indexOf("not running")>-1) + { + $scope.monitors[j].Monitor.isRunning = "false" ; + $scope.monitors[j].Monitor.color = 'red'; + $scope.monitors[j].Monitor.char = "ion-close-circled"; + } + else if (data.statustext.indexOf("pending")>-1) + { + $scope.monitors[j].Monitor.isRunning = "pending" ; + $scope.monitors[j].Monitor.color = 'orange'; + } + else if (data.statustext.indexOf("running since")>-1) + { + $scope.monitors[j].Monitor.isRunning = "true" ; + $scope.monitors[j].Monitor.color = 'green'; + } + + else if (data.statustext.indexOf("Unable to connect")>-1) + { + $scope.monitors[j].Monitor.isRunning = "false" ; + $scope.monitors[j].Monitor.color = 'red'; + $scope.monitors[j].Monitor.char = "ion-close-circled"; + } + + + $scope.monitors[j].Monitor.isRunningText = data.statustext; + }) + .error (function (data) + { + $scope.monitors[j].Monitor.isRunning = "error"; + $scope.monitors[j].Monitor.color = '#800000'; + $scope.monitors[j].Monitor.char = "ion-help-circled"; + }); + + + })(i); + } + } $scope.doRefresh = function () { console.log("***Pull to Refresh"); $scope.monitors = []; var refresh = ZMDataModel.getMonitors(1); + refresh.then(function (data) { $scope.monitors = data; + monitorStateCheck(); $scope.$broadcast('scroll.refreshComplete'); }); diff --git a/www/js/app.js b/www/js/app.js index dc50e41d..e8ac220e 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -12,6 +12,8 @@ angular.module('zmApp', [ + + // this directive will be load any time an image completes loading // via img tags where this directive is added (I am using this in // events and mionitor view to show a loader while the image is @@ -31,6 +33,9 @@ angular.module('zmApp', [ }; }) + + + // In Android, HTTP requests seem to get stuck once in a while // It may be a crosswalk issue. // To tackle this gracefully, I've set up a global interceptor @@ -61,6 +66,70 @@ angular.module('zmApp', [ }; }) +.factory('zmAutoLogin', function($interval, ZMDataModel, $http) { + var zmAutoLoginHandle; + function doLogin() + { + console.log ("**** ZM AUTO LOGIN CALLED"); + var loginData = ZMDataModel.getLogin(); + $http({ + method:'POST', + url:loginData.url + '/index.php', + headers:{ + 'Content-Type': 'application/x-www-form-urlencoded', + 'Accept': 'application/json', + }, + transformRequest: function (obj) { + var str = []; + for (var p in obj) + str.push(encodeURIComponent(p) + "=" + + encodeURIComponent(obj[p])); + var foo = str.join("&"); + //console.log("****RETURNING " + foo); + return foo; + }, + + data: { + username:loginData.username, + password:loginData.password, + action:"login", + view:"console" + } + }) + .success(function(data) + { + console.log ("**** ZM Login OK"); + }) + .error(function(error) + { + console.log ("**** ZM Login FAILED"); + }); + } + + function start() + { + $interval.cancel(zmAutoLoginHandle); + doLogin(); + zmAutoLoginHandle = $interval(function() + { + doLogin(); + + },5*60*1000); // Auto login every 5 minutes + // PHP timeout is around 10 minutes + // should be ok? + } + function stop() + { + $interval.cancel(zmAutoLoginHandle); + + } + + return { + start: start, + stop: stop + }; +}) + /* For future use - does not work with img src intercepts .factory ('httpAuthIntercept', function ($rootScope, $q) { @@ -88,7 +157,8 @@ angular.module('zmApp', [ */ -.run(function ($ionicPlatform, $ionicPopup, $rootScope, $state, ZMDataModel, $cordovaSplashscreen, $http) { + +.run(function ($ionicPlatform, $ionicPopup, $rootScope, $state, ZMDataModel, $cordovaSplashscreen, $http, $interval, zmAutoLogin) { ZMDataModel.init(); var loginData = ZMDataModel.getLogin(); @@ -115,7 +185,7 @@ angular.module('zmApp', [ $rootScope.$on('$stateChangeStart', function (event, toState, toParams) { var requireLogin = toState.data.requireLogin; - if (ZMDataModel.isLoggedIn() || ZMDataModel.isSimulated()) { + if (ZMDataModel.isLoggedIn()) { console.log("State transition is authorized"); return; } @@ -126,7 +196,7 @@ angular.module('zmApp', [ $ionicPopup.alert({ title: "Credentials Required", - template: "Please provide your ZoneMinder credentials or switch to simulation mode" + template: "Please provide your ZoneMinder credentials" }); // for whatever reason, .go was resulting in digest loops. // if you don't prevent, states will stack @@ -165,9 +235,20 @@ angular.module('zmApp', [ $state.go($state.current, {}, { reload: true }); + zmAutoLogin.start(); }, false); + document.addEventListener("pause", function () { + console.log("****The application is going into background"); + zmAutoLogin.stop(); + + }, false); + + + + + if (window.cordova && window.cordova.plugins.Keyboard) { cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); } @@ -183,45 +264,12 @@ angular.module('zmApp', [ // lets POST so we get a session ID right hre // var loginData = ZMDataModel.getLogin(); - console.log ("*** INIT LOGIN ****"); - $http({ - method:'POST', - url:loginData.url + '/index.php', - headers:{ - 'Content-Type': 'application/x-www-form-urlencoded', - 'Accept': 'application/json', - }, - transformRequest: function (obj) { - var str = []; - for (var p in obj) - str.push(encodeURIComponent(p) + "=" + - encodeURIComponent(obj[p])); - var foo = str.join("&"); - console.log("****RETURNING " + foo); - return foo; - }, - - data: { - username:loginData.username, - password:loginData.password, - action:"login", - view:"console" - } - }) - .success(function(data) - { - console.log ("**** INIT LOGIN OK"); - }) - .error(function(error) - { - console.log ("**** INIT LOGIN FAILED"); - }); + console.log ("Setting up POST LOGIN timer"); + zmAutoLogin.start(); - - -}) +}) //run // My route map connecting menu options to their respective templates and controllers .config(function ($stateProvider, $urlRouterProvider, $httpProvider) { |
