diff options
| author | Damir Merdan <44159556+dado-ca@users.noreply.github.com> | 2018-11-14 11:17:18 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-11-14 11:17:18 +0100 |
| commit | bb78ec417458347887a0668223dc7fd7bad377ea (patch) | |
| tree | 494a609118c85467702061a743e9fd0b7dba1860 /www/js/StateCtrl.js | |
| parent | b2cccc52c08f8195a1ddbb747c949915134940b4 (diff) | |
| parent | dbee219a9674daadd05aa1a27b36e76d91a35b5f (diff) | |
Merge branch 'master' into master
Diffstat (limited to 'www/js/StateCtrl.js')
| -rw-r--r-- | www/js/StateCtrl.js | 136 |
1 files changed, 108 insertions, 28 deletions
diff --git a/www/js/StateCtrl.js b/www/js/StateCtrl.js index 62bffb81..34255287 100644 --- a/www/js/StateCtrl.js +++ b/www/js/StateCtrl.js @@ -26,27 +26,59 @@ angular.module('zmApp.controllers').controller('zmApp.StateCtrl', ['$ionicPopup' var apiRun = loginData.apiurl + "/host/daemonCheck.json"; var apiLoad = loginData.apiurl + "/host/getLoad.json"; - var apiDisk = loginData.apiurl + "/host/getDiskPercent.json"; + var apiStorage = loginData.apiurl + "/storage.json"; + var apiServer = loginData.apiurl + "/servers.json"; var apiCurrentState = loginData.apiurl + "/States.json"; var apiExec = loginData.apiurl + "/states/change/"; var inProgress = 0; // prevents user from another op if one is in progress getRunStatus(); + getLoadStatus(); + getCurrentState(); + getStorageStatus(); + getServerStatus(); + + +// credit https://stackoverflow.com/a/14919494/1361529 + $scope.humanFileSize = function(bytes, si) { + var thresh = si ? 1000 : 1024; + bytes = parseFloat(bytes); + if (isNaN(bytes)) bytes=0; + if(Math.abs(bytes) < thresh) { + return bytes + ' B'; + } + var units = si? ['kB','MB','GB','TB','PB','EB','ZB','YB']:['KiB','MiB','GiB','TiB','PiB','EiB','ZiB','YiB']; + var u = -1; + do { + bytes /= thresh; + ++u; + } while(Math.abs(bytes) >= thresh && u < units.length - 1); + return bytes.toFixed(1)+' '+units[u]; +}; + +$scope.matchServer = function (id) { + var str = id; + var name = ""; + for (var i=0; i< $scope.servers.length; i++) { + if ($scope.servers[i].Server.Id == id) { + name = $scope.servers[i].Server.Name; + break; + } + } + if (name) { + str = name + " ("+id+")"; + } + return str; +}; - // 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 - - $timeout(function () { - NVRDataModel.debug("invoking LoadStatus..."); - getLoadStatus(); - }, 2000); - - $timeout(function () { - NVRDataModel.debug("invoking CurrentState..."); - getCurrentState(); - }, 4000); +$scope.toggleStorage = function() { + $scope.showStorage = !$scope.showStorage; +}; +$scope.toggleServer = function() { + $scope.showServer = !$scope.showServer; +}; /* $timeout(function () { NVRDataModel.debug("invoking DiskStatus..."); @@ -60,6 +92,25 @@ angular.module('zmApp.controllers').controller('zmApp.StateCtrl', ['$ionicPopup' // 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.beforeEnter', function () { + + $scope.showStorage = true; + $scope.showServer = true; + + $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]); + }); + }); + $scope.$on('$ionicView.enter', function () { // console.log("**VIEW ** Montage Ctrl Entered"); NVRDataModel.setAwake(false); @@ -175,22 +226,46 @@ angular.module('zmApp.controllers').controller('zmApp.StateCtrl', ['$ionicPopup' } //---------------------------------------------------------------------- - // returns disk space in gigs taken up by events + // returns Storage data //---------------------------------------------------------------------- - function getDiskStatus() { - NVRDataModel.debug("StateCtrl/getDiskStatus: " + apiDisk); - $http.get(apiDisk) + function getStorageStatus() { + + $scope.storage = []; + NVRDataModel.debug("StorageStatus: " + apiStorage); + $http.get(apiStorage) .then( function (success) { - NVRDataModel.debug("StateCtrl/getDiskStatus: success"); - NVRDataModel.debug("Disk results: " + JSON.stringify(success)); - var obj = success.data.usage; - if (obj.Total.space != undefined) { - $scope.zmDisk = parseFloat(obj.Total.space).toFixed(1).toString() + "G"; - } else { - $scope.zmDisk = "unknown"; - NVRDataModel.log("Error retrieving disk space, API returned null for obj.Total.space"); + + $scope.storage = success.data.storage; + //console.log (JSON.stringify($scope.storage)); + + }, + function (error) { + $scope.zmDisk = "unknown"; + // console.log("ERROR:" + JSON.stringify(error)); + NVRDataModel.log("Error retrieving DiskStatus: " + JSON.stringify(error), "error"); + } + ); + } + + + //---------------------------------------------------------------------- + // returns Storage data + //---------------------------------------------------------------------- + function getServerStatus() { + + $scope.servers = []; + NVRDataModel.debug("ServerStatus: " + apiStorage); + $http.get(apiServer) + .then( + function (success) { + + $scope.servers = success.data.servers; + if ($scope.servers.length > 0) { + $scope.zmRun =$translate.instant('kStateMultiServer'); + $scope.color = 'grey'; } + // console.log (JSON.stringify($scope.storage)); }, function (error) { @@ -205,6 +280,10 @@ angular.module('zmApp.controllers').controller('zmApp.StateCtrl', ['$ionicPopup' // returns ZM running status //---------------------------------------------------------------------- function getRunStatus() { + + + + NVRDataModel.debug("StateCtrl/getRunStatus: " + apiRun); $http.get(apiRun) .then( @@ -367,9 +446,10 @@ angular.module('zmApp.controllers').controller('zmApp.StateCtrl', ['$ionicPopup' //console.log("***Pull to Refresh"); NVRDataModel.debug("StateCtrl/refresh: calling getRun/Load/Disk/CurrentState"); getRunStatus(); - $timeout(getLoadStatus, 2000); - $timeout(getCurrentState, 4000); - //$timeout (getDiskStatus,6000); + getLoadStatus(); + getCurrentState(); + getStorageStatus(); + getServerStatus(); $scope.$broadcast('scroll.refreshComplete'); }; |
