summaryrefslogtreecommitdiff
path: root/www/js/StateCtrl.js
diff options
context:
space:
mode:
authorPliablePixels <pliablepixels@gmail.com>2015-06-21 18:05:01 -0400
committerPliablePixels <pliablepixels@gmail.com>2015-06-21 18:05:01 -0400
commitd442629aa825aab6bc55ab6be19e3aba060867fe (patch)
treea58b5cc3b6e30018ad3802b57d9c99a9b0604980 /www/js/StateCtrl.js
parent2782a0757f730ac622bb1768e33ae4e1ab43f9e4 (diff)
remove simulation code completely to keep things easy to understand.
Diffstat (limited to 'www/js/StateCtrl.js')
-rw-r--r--www/js/StateCtrl.js247
1 files changed, 121 insertions, 126 deletions
diff --git a/www/js/StateCtrl.js b/www/js/StateCtrl.js
index b2bde9ed..4c44b6b5 100644
--- a/www/js/StateCtrl.js
+++ b/www/js/StateCtrl.js
@@ -4,113 +4,107 @@
// controller for State View
-angular.module('zmApp.controllers').controller('zmApp.StateCtrl', ['$ionicPopup', '$scope', 'ZMDataModel', '$ionicSideMenuDelegate', '$ionicLoading', '$ionicModal', '$state', '$http', function ($ionicPopup,$scope, ZMDataModel, $ionicSideMenuDelegate, $ionicLoading, $ionicModal, $state, $http, $rootScope) {
+angular.module('zmApp.controllers').controller('zmApp.StateCtrl', ['$ionicPopup', '$scope', 'ZMDataModel', '$ionicSideMenuDelegate', '$ionicLoading', '$ionicModal', '$state', '$http', function ($ionicPopup, $scope, ZMDataModel, $ionicSideMenuDelegate, $ionicLoading, $ionicModal, $state, $http, $rootScope) {
- $scope.zmRun="loading...";
- $scope.zmLoad="loading...";
+ $scope.zmRun = "loading...";
+ $scope.zmLoad = "loading...";
$scope.zmDisk = "loading...";
- $scope.color="";
- $scope.showDanger=false;
+ $scope.color = "";
+ $scope.showDanger = false;
$scope.dangerText = ["Show ZoneMinder Controls", "Hide ZoneMinder Controls"];
$scope.dangerButtonColor = ["button-positive", "button-assertive"];
var loginData = ZMDataModel.getLogin();
- var apiRun = loginData.apiurl+"/host/daemonCheck.json";
- var apiLoad = loginData.apiurl+"/host/getLoad.json";
- var apiDisk = loginData.apiurl+"/host/getDiskPercent.json";
+ var apiRun = loginData.apiurl + "/host/daemonCheck.json";
+ var apiLoad = loginData.apiurl + "/host/getLoad.json";
+ var apiDisk = loginData.apiurl + "/host/getDiskPercent.json";
- var apiExec = loginData.apiurl+"/states/change/";
+ var apiExec = loginData.apiurl + "/states/change/";
var inProgress = 0;
getRunStatus();
getLoadStatus();
getDiskStatus();
- function getDiskStatus(){
+ function getDiskStatus() {
$http.get(apiDisk)
- .then(
- function(success)
- {
+ .then(
+ function (success) {
var obj = success.data.usage;
var du = 0;
- console.log ("DISK:"+JSON.stringify(success));
- for (var p in obj)
- {
- if (obj.hasOwnProperty(p))
- {
+ console.log("DISK:" + JSON.stringify(success));
+ for (var p in obj) {
+ if (obj.hasOwnProperty(p)) {
du += parseFloat(obj[p].space);
}
}
- $scope.zmDisk=du.toFixed(1).toString()+"G";
+ $scope.zmDisk = du.toFixed(1).toString() + "G";
},
- function (error)
- {
- $scope.zmDisk="unknown";
- console.log ("ERROR:"+JSON.stringify(error));
+ function (error) {
+ $scope.zmDisk = "unknown";
+ console.log("ERROR:" + JSON.stringify(error));
}
);
}
function getRunStatus() {
- $http.get(apiRun)
- .then(
- function (success) {
- switch (success.data.result) {
- case 1:
- $scope.zmRun = 'running';
- $scope.color = 'color:green;';
- break;
- case 0:
- $scope.zmRun = 'stopped';
+ $http.get(apiRun)
+ .then(
+ function (success) {
+ switch (success.data.result) {
+ case 1:
+ $scope.zmRun = 'running';
+ $scope.color = 'color:green;';
+ break;
+ case 0:
+ $scope.zmRun = 'stopped';
+ $scope.color = 'color:red;';
+ break;
+ default:
+ $scope.zmRun = 'undetermined';
+ $scope.color = 'color:orange;';
+ break;
+ }
+
+
+ // console.log("X"+success.data.result+"X");
+ },
+ function (error) {
+ console.log("ERROR in getRun: " + JSON.stringify(error));
$scope.color = 'color:red;';
- break;
- default:
$scope.zmRun = 'undetermined';
- $scope.color = 'color:orange;';
- break;
}
+ );
-
- // console.log("X"+success.data.result+"X");
- },
- function (error) {
- console.log("ERROR in getRun: " + JSON.stringify(error));
- $scope.color = 'color:red;';
- $scope.zmRun = 'undetermined';
- }
- );
-
-}
+ }
function getLoadStatus() {
- $http.get(apiLoad)
- .then(
- function (success) {
- //console.log(JSON.stringify(success));
- // load returns 3 params - one in the middle is avg.
- $scope.zmLoad = success.data.load[1];
+ $http.get(apiLoad)
+ .then(
+ function (success) {
+ //console.log(JSON.stringify(success));
+ // load returns 3 params - one in the middle is avg.
+ $scope.zmLoad = success.data.load[1];
- // console.log("X"+success.data.result+"X");
- },
- function (error) {
- console.log("ERROR in getLoad: " + JSON.stringify(error));
- $scope.zmLoad = 'undetermined';
- }
- );
-}
+ // console.log("X"+success.data.result+"X");
+ },
+ function (error) {
+ console.log("ERROR in getLoad: " + JSON.stringify(error));
+ $scope.zmLoad = 'undetermined';
+ }
+ );
+ }
- $scope.controlZM = function(str)
- {
- if (inProgress)
- {
+ $scope.controlZM = function (str) {
+ if (inProgress) {
$ionicPopup.alert({
title: "Operation in Progress",
template: "The previous operation is still in progress. Please wait..."
@@ -119,67 +113,69 @@ angular.module('zmApp.controllers').controller('zmApp.StateCtrl', ['$ionicPopup'
}
- $ionicPopup.show({
- title: 'Please Confirm',
- template: 'Are you sure you want to '+str+' Zoneminder?',
- buttons: [
- {
- text: 'Cancel',
- type: 'button-positive'
+ $ionicPopup.show({
+ title: 'Please Confirm',
+ template: 'Are you sure you want to ' + str + ' Zoneminder?',
+ buttons: [
+ {
+ text: 'Cancel',
+ type: 'button-positive'
},
- {
- text: 'Yes, '+str+' Zoneminder',
- type: 'button-assertive',
- onTap: function (e)
- {
- $scope.zmRun = "please wait...";
- $scope.color = 'color:orange;';
- console.log ("Control command is " +apiExec+str+".json");
- inProgress = 1;
- $http.post(apiExec+str+".json")
- .then(
- function(success)
- {
- switch (str)
- {
- case "stop":$scope.zmRun = 'stopped';
- $scope.color='color:red;'; break;
- case "start":
- case "restart":$scope.zmRun = 'running';
- $scope.color = 'color:green;';break;
-
- }
- inProgress = 0;
- },
- function (error)
+ {
+ text: 'Yes, ' + str + ' Zoneminder',
+ type: 'button-assertive',
+ onTap: function (e) {
+ $scope.zmRun = "please wait...";
+ $scope.color = 'color:orange;';
+ console.log("Control command is " + apiExec + str + ".json");
+ inProgress = 1;
+ $http.post(apiExec + str + ".json")
+ .then(
+ function (success) {
+ switch (str) {
+ case "stop":
+ $scope.zmRun = 'stopped';
+ $scope.color = 'color:red;';
+ break;
+ case "start":
+ case "restart":
+ $scope.zmRun = 'running';
+ $scope.color = 'color:green;';
+ break;
+
+ }
+ inProgress = 0;
+ },
+ function (error) {
+ //if (error.status) // it seems to return error with status 0 if ok
+ // {
+ console.log("ERROR in Change State:" + JSON.stringify(error));
+ $scope.zmRun = 'undetermined';
+ $scope.color = 'color:orange;';
+ inProgress = 0;
+ // }
+ /*else
+ {
+ switch (str)
{
- //if (error.status) // it seems to return error with status 0 if ok
- // {
- console.log("ERROR in Change State:"+JSON.stringify(error));
- $scope.zmRun = 'undetermined'; $scope.color='color:orange;';
- // }
- /*else
- {
- switch (str)
- {
- case "stop":$scope.zmRun = 'stopped';
- $scope.color='color:red;'; break;
- case "start":
- case "restart":$scope.zmRun = 'running';
- $scope.color = 'color:green;';break;
-
- }
- inProgress = 0;
- }*/
+ case "stop":$scope.zmRun = 'stopped';
+ $scope.color='color:red;'; break;
+ case "start":
+ case "restart":$scope.zmRun = 'running';
+ $scope.color = 'color:green;';break;
}
+ inProgress = 0;
+ }*/
+
+ }
- );
+ );
- }
+ }
}
]
- });
+ });
};
@@ -187,6 +183,12 @@ angular.module('zmApp.controllers').controller('zmApp.StateCtrl', ['$ionicPopup'
$ionicSideMenuDelegate.toggleLeft();
};
+ $scope.$on('$ionicView.leave', function () {
+ console.log("**VIEW ** State Ctrl Left");
+ // FIXME not the best way...
+ inProgress = 0;
+ });
+
$scope.reloadView = function () {
console.log("*** Refreshing Modal view ***");
inProgress = 0;
@@ -198,13 +200,6 @@ angular.module('zmApp.controllers').controller('zmApp.StateCtrl', ['$ionicPopup'
});
};
- $scope.isSimulated = function () {
- return ZMDataModel.isSimulated();
- };
-
-
-
-
$scope.doRefresh = function () {
console.log("***Pull to Refresh");
getRunStatus();