diff options
Diffstat (limited to 'www/js')
| -rw-r--r-- | www/js/DataModel.js | 42 | ||||
| -rw-r--r-- | www/js/EventCtrl.js | 3 | ||||
| -rw-r--r-- | www/js/EventsGraphsCtrl.js | 2 | ||||
| -rw-r--r-- | www/js/HelpCtrl.js | 3 | ||||
| -rw-r--r-- | www/js/LogCtrl.js | 61 | ||||
| -rw-r--r-- | www/js/LoginCtrl.js | 2 | ||||
| -rw-r--r-- | www/js/ModalCtrl.js | 1 | ||||
| -rw-r--r-- | www/js/MonitorCtrl.js | 3 | ||||
| -rw-r--r-- | www/js/MontageCtrl.js | 2 | ||||
| -rw-r--r-- | www/js/StateCtrl.js | 4 | ||||
| -rw-r--r-- | www/js/app.js | 22 |
11 files changed, 140 insertions, 5 deletions
diff --git a/www/js/DataModel.js b/www/js/DataModel.js index d1470685..bfd81b74 100644 --- a/www/js/DataModel.js +++ b/www/js/DataModel.js @@ -7,7 +7,7 @@ // that many other controllers use // It's grown over time. I guess I may have to split this into multiple services in the future -angular.module('zmApp.controllers').service('ZMDataModel', ['$http', '$q', '$ionicLoading', '$ionicBackdrop', function ($http, $q, $ionicLoading, $ionicBackdrop) { +angular.module('zmApp.controllers').service('ZMDataModel', ['$http', '$q', '$ionicLoading', '$ionicBackdrop', '$fileLogger', function ($http, $q, $ionicLoading, $ionicBackdrop,$fileLogger) { var monitorsLoaded = 0; var montageSize = 3; @@ -26,8 +26,28 @@ angular.module('zmApp.controllers').service('ZMDataModel', ['$http', '$q', '$ion 'keepAwake':true // don't dim/dim during live view }; + //-------------------------------------------------------------------------- + // uses fileLogger to write logs to file for later investigation + //-------------------------------------------------------------------------- + function zmLog(val,logtype) + { + $fileLogger.log(logtype, val); + } + return { + //------------------------------------------------------------- + // used by various controllers to log messages to file + //------------------------------------------------------------- + + zmLog: function (val,type) { + var logtype = 'info'; + if (type != undefined) + logtype = type ; + zmLog(val,logtype); + + }, + // This function is called when the app is ready to run // sets up various variables // including persistent login data for the ZM apis and portal @@ -36,10 +56,17 @@ angular.module('zmApp.controllers').service('ZMDataModel', ['$http', '$q', '$ion // the ZM portal authentication, which is pretty messy. But unless // the ZM authors fix this and streamline the access of images // from APIs, I don't have an option - init: function () { console.log("****** DATAMODEL INIT SERVICE CALLED ********"); + zmLog("ZMData init: checking for stored variables & setting up log file"); + + $fileLogger.setStorageFilename('zmNinjaLog.txt'); + + $fileLogger.deleteLogfile().then(function() { + console.log('Logfile deleted'); + }); + if (window.localStorage.getItem("username") != undefined) { loginData.username = window.localStorage.getItem("username"); @@ -140,6 +167,7 @@ angular.module('zmApp.controllers').service('ZMDataModel', ['$http', '$q', '$ion console.log ("**** setAwake called with:" + val); + zmLog("Switching screen always on to " + val); if (val) { @@ -170,7 +198,7 @@ angular.module('zmApp.controllers').service('ZMDataModel', ['$http', '$q', '$ion setLogin: function (newLogin) { loginData = newLogin; - + zmLog("Saving all parameters to storage"); window.localStorage.setItem("username", loginData.username); window.localStorage.setItem("password", loginData.password); window.localStorage.setItem("url", loginData.url); @@ -222,6 +250,7 @@ angular.module('zmApp.controllers').service('ZMDataModel', ['$http', '$q', '$ion if ((monitorsLoaded == 0) || (forceReload == 1)) // monitors are empty or force reload { console.log("ZMDataModel: Invoking HTTP get to load monitors"); + zmLog ( (forceReload==1)? "getMonitors:Force reloading all monitors" : "getMonitors:Loading all monitors"); var apiurl = loginData.apiurl; var myurl = apiurl + "/monitors.json"; $http.get(myurl /*,{timeout:15000}*/ ) @@ -232,9 +261,11 @@ angular.module('zmApp.controllers').service('ZMDataModel', ['$http', '$q', '$ion monitorsLoaded = 1; d.resolve(monitors); $ionicLoading.hide(); + zmLog ("Monitor load was successful, loaded " + monitors.length + " monitors"); }) .error(function (err) { console.log("HTTP Error " + err); + zmLog ("Monitor load failed " + JSON.stringify(err), "error"); // To keep it simple for now, I'm translating an error // to imply no monitors could be loaded. FIXME: conver to proper error monitors = []; @@ -248,6 +279,7 @@ angular.module('zmApp.controllers').service('ZMDataModel', ['$http', '$q', '$ion } else // monitors are loaded { console.log("Returning pre-loaded list of " + monitors.length + " monitors"); + zmLog("Returning pre-loaded list of " + monitors.length + " monitors"); d.resolve(monitors); $ionicLoading.hide(); return d.promise; @@ -285,6 +317,7 @@ angular.module('zmApp.controllers').service('ZMDataModel', ['$http', '$q', '$ion }) .error(function (error) { console.log("*** ERROR GETTING TOTAL PAGES ***"); + zmLog ("Error retrieving page count of events " + JSON.stringify(error), "error"); d.reject(error); return d.promise; }); @@ -349,6 +382,7 @@ angular.module('zmApp.controllers').service('ZMDataModel', ['$http', '$q', '$ion .error(function (err) { if (loadingStr != 'none') $ionicLoading.hide(); console.log("HTTP Events error " + err); + zmLog("Error fetching events for page " + pageId + " Err: " + JSON.stringify(err), "error"); // I need to reject this as I have infinite scrolling // implemented in EventCtrl.js --> and if it does not know // it got an error going to the next page, it will get into @@ -379,6 +413,8 @@ angular.module('zmApp.controllers').service('ZMDataModel', ['$http', '$q', '$ion montageSize = montage; }, + + //----------------------------------------------------------------------------- // //----------------------------------------------------------------------------- diff --git a/www/js/EventCtrl.js b/www/js/EventCtrl.js index 284c0147..e4ac3516 100644 --- a/www/js/EventCtrl.js +++ b/www/js/EventCtrl.js @@ -208,7 +208,7 @@ angular.module('zmApp.controllers').controller('zmApp.EventCtrl', ['$ionicPlatfo //-------------------------------------------------------- this.pollEventsProgress = function() { - console.log ("**************"); + // console.log ("**************"); }; //-------------------------------------------------------- @@ -322,6 +322,7 @@ angular.module('zmApp.controllers').controller('zmApp.EventCtrl', ['$ionicPlatfo req.error(function (resp) { console.log("ERROR: " + JSON.stringify(resp)); + ZMDataModel.zmLog("Error sending event command " +JSON.stringify(resp), "error"); }); }; diff --git a/www/js/EventsGraphsCtrl.js b/www/js/EventsGraphsCtrl.js index 92bc870a..ca2653d3 100644 --- a/www/js/EventsGraphsCtrl.js +++ b/www/js/EventsGraphsCtrl.js @@ -81,6 +81,7 @@ angular.module('zmApp.controllers').controller('zmApp.EventsGraphsCtrl', ['$ioni endDate = cur.format("YYYY-MM-DD hh:mm:ss"); startDate = cur.subtract(hrs, 'hours').format("YYYY-MM-DD hh:mm:ss"); console.log("Start and End " + startDate + "==" + endDate); + ZMDataModel.zmLog("Generating graph for " + startDate + " to " + endDate); } @@ -139,6 +140,7 @@ angular.module('zmApp.controllers').controller('zmApp.EventsGraphsCtrl', ['$ioni // but what I am really doing now is treating it like no events // works but TBD: make this into a proper error handler $scope.data.datasets[0].data[j] = 0; + ZMDataModel.zmLog ("Error retrieving events for graph " + JSON.stringify(data), "error"); }); })(i); // j } //for diff --git a/www/js/HelpCtrl.js b/www/js/HelpCtrl.js index 89c2171b..270cbf33 100644 --- a/www/js/HelpCtrl.js +++ b/www/js/HelpCtrl.js @@ -8,6 +8,8 @@ $scope.openMenu = function () { }; + + //------------------------------------------------------------------------- // Lets make sure we set screen dim properly as we enter // The problem is we enter other states before we leave previous states @@ -18,6 +20,7 @@ $scope.openMenu = function () { $scope.$on('$ionicView.enter', function () { console.log("**VIEW ** Help Ctrl Entered"); ZMDataModel.setAwake(false); + }); }]); diff --git a/www/js/LogCtrl.js b/www/js/LogCtrl.js new file mode 100644 index 00000000..1ac903a7 --- /dev/null +++ b/www/js/LogCtrl.js @@ -0,0 +1,61 @@ +/* jshint -W041 */ +/* jslint browser: true*/ +/* global cordova,StatusBar,angular,console */ + +angular.module('zmApp.controllers').controller('zmApp.LogCtrl', ['$scope', '$rootScope', '$ionicModal', 'ZMDataModel', '$ionicSideMenuDelegate', '$fileLogger', '$cordovaEmailComposer', function ($scope, $rootScope, $ionicModal, ZMDataModel, $ionicSideMenuDelegate, $fileLogger, $cordovaEmailComposer) { + $scope.openMenu = function () { + $ionicSideMenuDelegate.toggleLeft(); + }; + + + //-------------------------------------------------------------------------- + // Convenience function to send logs via email + //-------------------------------------------------------------------------- + $scope.sendEmail = function (logstring) { + if (window.cordova) { + // pass= password= should be replaced + //logstring = logstring.replace(/password=*?/g, 'password=xxxx' + $cordovaEmailComposer.isAvailable().then(function () { + var email = { + to: '', + subject: 'zmNinja Logs', + body: logstring, + isHtml: false + }; + $cordovaEmailComposer.open(email); + }, function () { + ZMDataModel.zmLog("Email plugin not found", "error"); + }); + } else { + console.log("Skipping email module as cordova does not exist"); + } + + }; + + //------------------------------------------------------------------------- + // Lets make sure we set screen dim properly as we enter + // The problem is we enter other states before we leave previous states + // from a callback perspective in ionic, so we really can't predictably + // reset power state on exit as if it is called after we enter another + // state, that effectively overwrites current view power management needs + //------------------------------------------------------------------------ + $scope.$on('$ionicView.enter', function () { + console.log("**VIEW ** Log Ctrl Entered"); + ZMDataModel.setAwake(false); + + $scope.zmLog = { + logString: "" + }; + $fileLogger.getLogfile().then(function (l) { + + $scope.zmLog.logString = l; + //console.log ("LOGS" + logstring); + }, + function (error) { + $scope.zmLog.logString = "Error getting log: " + JSON.stringify(error); + }); + + + }); + +}]); diff --git a/www/js/LoginCtrl.js b/www/js/LoginCtrl.js index 1da2f83d..4bf04285 100644 --- a/www/js/LoginCtrl.js +++ b/www/js/LoginCtrl.js @@ -138,6 +138,7 @@ function addhttp(url) { }, function (error) { $ionicLoading.hide(); + ZMDataModel.zmLog("Settings check error: " +JSON.stringify(error),"error"); //alert("Error string" + JSON.stringify(error)); $ionicPopup.show({ @@ -155,6 +156,7 @@ function addhttp(url) { title: 'Error Details', template: JSON.stringify(error) }); + } } ] diff --git a/www/js/ModalCtrl.js b/www/js/ModalCtrl.js index d8f61b03..a9c45c34 100644 --- a/www/js/ModalCtrl.js +++ b/www/js/ModalCtrl.js @@ -203,6 +203,7 @@ angular.module('zmApp.controllers').controller('ModalCtrl', ['$scope', '$rootSco req.error(function (resp) { $ionicLoading.hide(); console.log("ERROR: " + JSON.stringify(resp)); + ZMDataModel.zmLog("Error sending PTZ:" + JSON.stringify(resp), "error"); }); } diff --git a/www/js/MonitorCtrl.js b/www/js/MonitorCtrl.js index ee9605fc..bf94f48f 100644 --- a/www/js/MonitorCtrl.js +++ b/www/js/MonitorCtrl.js @@ -231,10 +231,13 @@ angular.module('zmApp.controllers').controller('zmApp.MonitorCtrl', ['$ionicPopu .success(function(data) { $scope.ptzMoveCommand = (data.control.Control.CanMoveCon == '1')? 'moveCon':'move'; console.log("***moveCommand: " +$scope.ptzMoveCommand ); + ZMDataModel.zmLog ("ControlDB reports PTZ command to be " + $scope.ptzMoveCommand ); }) .error(function(data) { console.log ("** Error retrieving move PTZ command"); + ZMDataModel.zmLog ("Error retrieving PTZ command " + JSON.stringify(data),"error"); }); + } diff --git a/www/js/MontageCtrl.js b/www/js/MontageCtrl.js index bd2ab1ef..b95d2553 100644 --- a/www/js/MontageCtrl.js +++ b/www/js/MontageCtrl.js @@ -146,9 +146,11 @@ angular.module('zmApp.controllers').controller('zmApp.MontageCtrl', ['$scope', ' .success(function(data) { $scope.ptzMoveCommand = (data.control.Control.CanMoveCon == '1')? 'moveCon':'move'; console.log("***moveCommand: " +$scope.ptzMoveCommand ); + ZMDataModel.zmLog ("ControlDB reports PTZ command to be " + $scope.ptzMoveCommand ); }) .error(function(data) { console.log ("** Error retrieving move PTZ command"); + ZMDataModel.zmLog ("Error retrieving PTZ command " + JSON.stringify(data),"error"); }); } diff --git a/www/js/StateCtrl.js b/www/js/StateCtrl.js index ec3a771a..cf6d97d9 100644 --- a/www/js/StateCtrl.js +++ b/www/js/StateCtrl.js @@ -64,6 +64,7 @@ angular.module('zmApp.controllers').controller('zmApp.StateCtrl', ['$ionicPopup' function (error) { $scope.zmDisk = "unknown"; console.log("ERROR:" + JSON.stringify(error)); + ZMDataModel.zmLog("Error retrieving DiskStatus: " + JSON.stringify(error),"error"); } ); } @@ -95,6 +96,7 @@ angular.module('zmApp.controllers').controller('zmApp.StateCtrl', ['$ionicPopup' }, function (error) { console.log("ERROR in getRun: " + JSON.stringify(error)); + ZMDataModel.zmLog("Error getting RunStatus " + JSON.stringify(error),"error"); $scope.color = 'color:red;'; $scope.zmRun = 'undetermined'; } @@ -119,6 +121,7 @@ angular.module('zmApp.controllers').controller('zmApp.StateCtrl', ['$ionicPopup' }, function (error) { console.log("ERROR in getLoad: " + JSON.stringify(error)); + ZMDataModel.zmLog("Error retrieving loadStatus " + JSON.stringify(error),"error"); $scope.zmLoad = 'undetermined'; } ); @@ -176,6 +179,7 @@ angular.module('zmApp.controllers').controller('zmApp.StateCtrl', ['$ionicPopup' //if (error.status) // it seems to return error with status 0 if ok // { console.log("ERROR in Change State:" + JSON.stringify(error)); + ZMDataModel.zmLog("Error in change run state:"+JSON.stringify(error),"error"); $scope.zmRun = 'undetermined'; $scope.color = 'color:orange;'; inProgress = 0; diff --git a/www/js/app.js b/www/js/app.js index ffff0c68..bd21fabe 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -7,6 +7,7 @@ angular.module('zmApp', [ 'ionic', 'zmApp.controllers', + 'fileLogger' ]) //------------------------------------------------------------------ @@ -51,7 +52,7 @@ angular.module('zmApp', [ } else { - console.log ("HTTP INTERCEPT:Skipping HTTP timeout for "+config.url); + //console.log ("HTTP INTERCEPT:Skipping HTTP timeout for "+config.url); } //console.log("*** HTTP URL INTERCEPTOR CALLED with "+config.url+" ***"); return config; @@ -70,6 +71,7 @@ angular.module('zmApp', [ function doLogin() { console.log ("**** ZM AUTO LOGIN CALLED"); + ZMDataModel.zmLog("zmAutologin timer started"); var loginData = ZMDataModel.getLogin(); $http({ method:'POST', @@ -98,10 +100,12 @@ angular.module('zmApp', [ .success(function(data) { console.log ("**** ZM Login OK"); + ZMDataModel.zmLog("zmAutologin successfully logged into Zoneminder"); }) .error(function(error) { console.log ("**** ZM Login FAILED"); + ZMDataModel.zmLog ("zmAutologin Error " + JSON.stringify(error), "error"); }); } @@ -120,6 +124,7 @@ angular.module('zmApp', [ function stop() { $interval.cancel(zmAutoLoginHandle); + ZMDataModel.zmLog("Cancelling zmAutologin timer"); } @@ -166,6 +171,7 @@ angular.module('zmApp', [ var loginData = ZMDataModel.getLogin(); if (ZMDataModel.isLoggedIn()) { + ZMDataModel.zmLog ("User is logged in"); console.log("VALID CREDENTIALS. Grabbing Monitors"); ZMDataModel.getMonitors(0); @@ -179,6 +185,7 @@ angular.module('zmApp', [ $rootScope.devWidth = ((window.innerWidth > 0) ? window.innerWidth : screen.width); $rootScope.devHeight = ((window.innerHeight > 0) ? window.innerHeight : screen.height); console.log("********NEW Computed Dev Width & Height as" + $rootScope.devWidth + "*" + $rootScope.devHeight); + ZMDataModel.zmLog("Device orientation change: "+$rootScope.devWidth + "*" + $rootScope.devHeight); }; window.addEventListener("resize", checkOrientation, false); @@ -211,9 +218,11 @@ angular.module('zmApp', [ $ionicPlatform.ready(function () { // generates and error in desktops but works fine + ZMDataModel.zmLog("Device is ready"); console.log("**** DEVICE READY ***"); + setTimeout(function () { if (window.cordova) { @@ -234,6 +243,7 @@ angular.module('zmApp', [ // from foreground to background and back document.addEventListener("resume", function () { console.log("****The application is resuming from the background"); + ZMDataModel.zmLog("App is resuming from background"); $rootScope.rand = Math.floor((Math.random() * 100000) + 1); console.log("** generated Random of " + $rootScope.rand); $state.go($state.current, {}, { @@ -246,6 +256,7 @@ angular.module('zmApp', [ document.addEventListener("pause", function () { console.log("****The application is going into background"); + ZMDataModel.zmLog("App is going into background"); zmAutoLogin.stop(); }, false); @@ -361,6 +372,15 @@ angular.module('zmApp', [ controller: 'zmApp.DevOptionsCtrl', }) + .state('log', { + data: { + requireLogin: false + }, + url: "/log", + templateUrl: "templates/log.html", + controller: 'zmApp.LogCtrl', + }) + .state('montage', { data: { requireLogin: true |
