summaryrefslogtreecommitdiff
path: root/www/js
diff options
context:
space:
mode:
authorARC <arjunrc@gmail.com>2015-05-12 16:21:03 -0400
committerARC <arjunrc@gmail.com>2015-05-12 16:21:03 -0400
commit1d89f4873a603392fb16096b3816b6b232b38a63 (patch)
treef7544c00478e6e0c22c5c93d0695f67662ce10bd /www/js
parentb2367f35e32fad3f2383b9e124df87211f669b59 (diff)
Added ZM state control - start/stop/restart
Diffstat (limited to 'www/js')
-rw-r--r--www/js/DataModel.js11
-rw-r--r--www/js/EventCtrl.js6
-rw-r--r--www/js/LoginCtrl.js26
-rw-r--r--www/js/StateCtrl.js172
-rw-r--r--www/js/app.js8
5 files changed, 205 insertions, 18 deletions
diff --git a/www/js/DataModel.js b/www/js/DataModel.js
index cd08bcfd..d30c76a0 100644
--- a/www/js/DataModel.js
+++ b/www/js/DataModel.js
@@ -22,7 +22,7 @@ angular.module('zmApp.controllers').service('ZMDataModel', ['$http', '$q', '$ion
'apiurl': '', // This is the API path
'simulationMode': false, // if true, data will be simulated
'maxMontage':"10", //total # of monitors to display in montage
- 'alias':""
+ 'streamingurl':""
};
// This is really a test mode. This is how I am validating
@@ -150,9 +150,10 @@ angular.module('zmApp.controllers').service('ZMDataModel', ['$http', '$q', '$ion
}
- if (window.localStorage.getItem("alias") != undefined) {
- loginData.alias =
- window.localStorage.getItem("alias");
+ if (window.localStorage.getItem("streamingurl") != undefined) {
+ loginData.streamingurl =
+ window.localStorage.getItem("streamingurl");
+ console.log ("STREAMING URL " + loginData.streamingurl);
}
@@ -186,7 +187,7 @@ angular.module('zmApp.controllers').service('ZMDataModel', ['$http', '$q', '$ion
window.localStorage.setItem("url", loginData.url);
window.localStorage.setItem("apiurl", loginData.apiurl);
window.localStorage.setItem("simulationMode", loginData.simulationMode);
- window.localStorage.setItem("alias",loginData.alias);
+ window.localStorage.setItem("streamingurl",loginData.streamingurl);
diff --git a/www/js/EventCtrl.js b/www/js/EventCtrl.js
index a3955a76..ab25c0a7 100644
--- a/www/js/EventCtrl.js
+++ b/www/js/EventCtrl.js
@@ -128,18 +128,18 @@ angular.module('zmApp.controllers').controller('zmApp.EventCtrl', ['$ionicPlatfo
break;
}
- console.log("** POST URL " + loginData.url + 'zm/index.php');
+
// You need to POST commands to control zms
// Note that I am url encoding the parameters into the URL
// If I leave it as JSON, it gets converted to OPTONS due
// to CORS behaviour and ZM/Apache don't seem to handle it
- console.log ("POST: "+loginData.url +'/'+ loginData.alias+'/index.php');
+ console.log ("POST: "+loginData.url +'/index.php');
var req = $http({
method: 'POST',
/*timeout: 15000,*/
- url: loginData.url +'/'+ loginData.alias+'/index.php',
+ url: loginData.url +'/index.php',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
//'Accept': '*/*',
diff --git a/www/js/LoginCtrl.js b/www/js/LoginCtrl.js
index 7a4c7695..728c8b9c 100644
--- a/www/js/LoginCtrl.js
+++ b/www/js/LoginCtrl.js
@@ -32,7 +32,7 @@ angular.module('zmApp.controllers').controller('zmApp.LoginCtrl', ['$scope', '$r
$scope.loginData.url = $scope.loginData.url.trim();
$scope.loginData.apiurl = $scope.loginData.apiurl.trim();
$scope.loginData.username = $scope.loginData.username.trim();
- $scope.loginData.alias = $scope.loginData.alias.trim();
+ $scope.loginData.streamingurl = $scope.loginData.streamingurl.trim();
if ($scope.loginData.url.slice(-1) == '/')
{
@@ -47,23 +47,28 @@ angular.module('zmApp.controllers').controller('zmApp.LoginCtrl', ['$scope', '$r
}
- if ($scope.loginData.alias.slice(-1) == '/')
+ if ($scope.loginData.streamingurl.slice(-1) == '/')
{
- $scope.loginData.alias = $scope.loginData.alias.slice(0,-1);
+ $scope.loginData.streamingurl = $scope.loginData.streamingurl.slice(0,-1);
}
- // take off leading "/" in alias too
- if ($scope.loginData.alias[0] == '/')
- {
- $scope.loginData.alias = $scope.loginData.alias.substring(1);
+ // strip cgi-bin if it is there but only at the end
+ if ($scope.loginData.streamingurl.slice(-7).toLowerCase() == 'cgi-bin')
+ {
+ $scope.loginData.streamingurl = $scope.loginData.streamingurl.slice(0,-7);
}
+
// FIXME:: Do a login id check too
var apiurl = $scope.loginData.apiurl + '/host/getVersion.json';
- var portalurl = $scope.loginData.url + '/' + $scope.loginData.alias + '/index.php';
- console.log("API: " + apiurl + " PORTAL: " + portalurl);
+ var portalurl = $scope.loginData.url + '/index.php';
+ var streamingurl = $scope.loginData.streamingurl +
+ '/cgi-bin/zms?user='+$scope.loginData.username+"&pass="+$scope.loginData.password;
+
+
+ console.log("Checking API: " + apiurl + " PORTAL: " + portalurl + " CGI-BIN: "+streamingurl);
// Let's do a sanity check to see if the URLs are ok
@@ -80,7 +85,8 @@ angular.module('zmApp.controllers').controller('zmApp.LoginCtrl', ['$scope', '$r
$q.all([
$http.get(apiurl),
- $http.get(portalurl)
+ $http.get(portalurl),
+ //$http.get(streamingurl),
]).then(
function (results) {
$ionicLoading.hide();
diff --git a/www/js/StateCtrl.js b/www/js/StateCtrl.js
new file mode 100644
index 00000000..bac90e9b
--- /dev/null
+++ b/www/js/StateCtrl.js
@@ -0,0 +1,172 @@
+/* jshint -W041 */
+/* jslint browser: true*/
+/* global cordova,StatusBar,angular,console */
+
+// 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) {
+
+ $scope.zmRun="loading...";
+ $scope.zmLoad="loading...";
+ $scope.color="";
+
+ var loginData = ZMDataModel.getLogin();
+
+ var apiRun = loginData.apiurl+"/host/daemonCheck.json";
+ var apiLoad = loginData.apiurl+"/host/getLoad.json";
+
+ var apiExec = loginData.apiurl+"/states/change/";
+
+ var inProgress = 0;
+
+ $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;';
+ $scope.zmRun = 'undetermined';
+ }
+ );
+
+ $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';
+ }
+ );
+
+ $scope.controlZM = function(str)
+ {
+ if (inProgress)
+ {
+ $ionicPopup.alert({
+ title: "Operation in Progress",
+ template: "The previous operation is still in progress. Please wait..."
+ });
+ return;
+ }
+
+
+ $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)
+ {
+ 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;
+ }
+
+ }
+
+ );
+
+ }
+ }
+ ]
+ });
+
+ };
+
+ $scope.openMenu = function () {
+ $ionicSideMenuDelegate.toggleLeft();
+ };
+
+ $scope.reloadView = function () {
+ console.log("*** Refreshing Modal view ***");
+ inProgress = 0;
+ $scope.rand = Math.floor(Math.random() * (999999 - 111111 + 1)) + 111111;
+ $ionicLoading.show({
+ template: "refreshed view",
+ noBackdrop: true,
+ duration: 2000
+ });
+ };
+
+ $scope.isSimulated = function () {
+ return ZMDataModel.isSimulated();
+ };
+
+
+
+
+ $scope.doRefresh = function () {
+ console.log("***Pull to Refresh");
+ $scope.monitors = [];
+
+ var refresh = ZMDataModel.getMonitors(1);
+ refresh.then(function (data) {
+ $scope.monitors = data;
+ $scope.$broadcast('scroll.refreshComplete');
+ });
+
+ };
+
+}]);
diff --git a/www/js/app.js b/www/js/app.js
index 2769e73d..dd81cbac 100644
--- a/www/js/app.js
+++ b/www/js/app.js
@@ -245,6 +245,14 @@ angular.module('zmApp', [
controller: 'zmApp.EventsGraphsCtrl',
})
+ .state('state', {
+ data: {
+ requireLogin: true
+ },
+ url: "/state",
+ templateUrl: "templates/state.html",
+ controller: 'zmApp.StateCtrl',
+ })
.state('montage', {
data: {