From 0452b7728e679f2a828f57a1f4d2725972b3b1db Mon Sep 17 00:00:00 2001 From: root Date: Sat, 27 Aug 2016 22:46:06 +0200 Subject: Added Global Configuration function for monitors Former-commit-id: a088873ff83c5ae7bdd6cfcb2d972b3199833384 --- www/js/MonitorCtrl.js | 168 +++++++++++++++++++++++++------------------- www/lang/locale-en.json | 1 + www/templates/monitors.html | 4 ++ 3 files changed, 99 insertions(+), 74 deletions(-) (limited to 'www') diff --git a/www/js/MonitorCtrl.js b/www/js/MonitorCtrl.js index ce6b7255..885796f0 100644 --- a/www/js/MonitorCtrl.js +++ b/www/js/MonitorCtrl.js @@ -6,8 +6,8 @@ // refer to comments in EventCtrl for the modal stuff. They are almost the same angular.module('zmApp.controllers') - .controller('zmApp.MonitorCtrl', ['$ionicPopup', 'zm', '$scope', 'ZMDataModel', 'message', '$ionicSideMenuDelegate', '$ionicLoading', '$ionicModal', '$state', '$http', '$rootScope', '$timeout', '$ionicHistory', '$ionicPlatform', '$translate', - function ($ionicPopup, zm, $scope, ZMDataModel, message, $ionicSideMenuDelegate, $ionicLoading, $ionicModal, $state, $http, $rootScope, $timeout, $ionicHistory, $ionicPlatform, $translate) { + .controller('zmApp.MonitorCtrl', ['$ionicPopup', 'zm', '$scope', 'ZMDataModel', 'message', '$ionicSideMenuDelegate', '$ionicLoading', '$ionicModal', '$state', '$http', '$rootScope', '$timeout', '$ionicHistory', '$ionicPlatform', '$translate', '$q', + function ($ionicPopup, zm, $scope, ZMDataModel, message, $ionicSideMenuDelegate, $ionicLoading, $ionicModal, $state, $http, $rootScope, $timeout, $ionicHistory, $ionicPlatform, $translate, $q) { //----------------------------------------------------------------------- @@ -86,6 +86,17 @@ angular.module('zmApp.controllers') //console.log("called with " + monitorId + ":" + enabled + ":" + func); if (enabled == '1') checked = true; + //if monitorId is not specified, all monitors will be changed + var monitorsIds = new Array(); + if (monitorId == '') { + for (var i = 0; i < $scope.monitors.length; i++) { + monitorsIds[i] = $scope.monitors[i].Monitor.Id; + } + } + else { + monitorsIds[0] = monitorId; + } + $scope.monFunctions = [ { text: $translate.instant('kMonModect'), @@ -114,8 +125,11 @@ angular.module('zmApp.controllers') ]; $scope.monfunc = { + mymonitorsIds: monitorsIds, myfunc: func, - myenabled: checked + myenabled: checked, + myfailedIds: new Array(), + mypromises: new Array() }; $rootScope.zmPopup = $ionicPopup.show({ @@ -133,87 +147,93 @@ angular.module('zmApp.controllers') { text: $translate.instant('kButtonSave'), onTap: function (e) { + $scope.monfunc.mymonitorsIds.forEach( function(item, index) { + ZMDataModel.zmDebug("MonitorCtrl:changeConfig selection:" + $scope.monfunc.myenabled + + $scope.monfunc.myfunc); + var loginData = ZMDataModel.getLogin(); + var apiRestart = loginData.apiurl + "/states/change/restart.json"; + var apiMon = loginData.apiurl + "/monitors/" + item + ".json"; + + ZMDataModel.zmDebug("MonitorCtrl: URLs for changeConfig save:" + apiMon); + + var isEnabled = ""; + isEnabled = ($scope.monfunc.myenabled == true) ? '1' : '0'; + + $ionicLoading.show({ + template: $translate.instant('kApplyingChanges') + "...", + noBackdrop: true, + duration: zm.largeHttpTimeout, + }); - ZMDataModel.zmDebug("MonitorCtrl:changeConfig selection:" + $scope.monfunc.myenabled + - $scope.monfunc.myfunc); - var loginData = ZMDataModel.getLogin(); - var apiRestart = loginData.apiurl + "/states/change/restart.json"; - var apiMon = loginData.apiurl + "/monitors/" + monitorId + ".json"; - - ZMDataModel.zmDebug("MonitorCtrl: URLs for changeConfig save:" + apiMon); - - var isEnabled = ""; - isEnabled = ($scope.monfunc.myenabled == true) ? '1' : '0'; - - $ionicLoading.show({ - template: $translate.instant('kApplyingChanges') + "...", - noBackdrop: true, - duration: zm.largeHttpTimeout, - }); - - $http({ - url: apiMon, - method: 'post', - headers: { - 'Content-Type': 'application/x-www-form-urlencoded', - 'Accept': '*/*', - }, - 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); - ZMDataModel.zmDebug("MonitorCtrl: parmeters constructed: " + foo); - return foo; - }, - data: { - 'Monitor[Function]': $scope.monfunc.myfunc, - 'Monitor[Enabled]': isEnabled, - } - - }) - - // I am not restarting ZM after monitor change + var httpPromise = $http({ + url: apiMon, + method: 'post', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + 'Accept': '*/*', + }, + 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); + ZMDataModel.zmDebug("MonitorCtrl: parmeters constructed: " + foo); + return foo; + }, + data: { + 'Monitor[Function]': $scope.monfunc.myfunc, + 'Monitor[Enabled]': isEnabled, + } - .success(function () { - $ionicLoading.hide(); + }) + .success(function () { ZMDataModel.zmDebug("MonitorCtrl: Not restarting ZM - Make sure you have the patch installed in MonitorsController.php or this won't work"); - doRefresh(); - /* ZMDataModel.zmDebug ("MonitorCtrl: Restarting ZM"); - $ionicLoading.show({ - template: "Successfully changed Monitor. Please wait, restarting ZoneMinder...", - noBackdrop: true, - duration: zm.largeHttpTimeout, - }); - $http.post(apiRestart) - .then(function (success) { - $ionicLoading.hide(); - var refresh = ZMDataModel.getMonitors(1); - refresh.then(function (data) { - $scope.monitors = data; - $scope.$broadcast('scroll.refreshComplete'); - }); - - }, - function (error) { - $ionicLoading.hide(); - - } - );*/ - }) .error(function (data, status, headers, config) { ZMDataModel.zmDebug("MonitorCtrl: Error changing monitor " + JSON.stringify(data)); - $ionicLoading.hide(); + $scope.monfunc.myfailedIds.push(item); + }); + + $scope.monfunc.mypromises.push(httpPromise); + }); + + $q.all($scope.monfunc.mypromises).then(function(e) { + $ionicLoading.hide(); + // if there's a failed ID, an error has occurred + if ($scope.monfunc.myfailedIds.length != 0) { $ionicLoading.show({ - template: $translate.instant('kErrorChangingMonitors') + "...", + template: $translate.instant('kErrorChangingMonitors') + ". Monitor IDs : " + $scope.monfunc.myfailedIds.toString(), noBackdrop: true, duration: 3000, }); - }); - + } + else { + // I am not restarting ZM after monitor change + /* ZMDataModel.zmDebug ("MonitorCtrl: Restarting ZM"); + $ionicLoading.show({ + template: "Successfully changed Monitor. Please wait, restarting ZoneMinder...", + noBackdrop: true, + duration: zm.largeHttpTimeout, + }); + $http.post(apiRestart) + .then(function (success) { + $ionicLoading.hide(); + var refresh = ZMDataModel.getMonitors(1); + refresh.then(function (data) { + $scope.monitors = data; + $scope.$broadcast('scroll.refreshComplete'); + }); + + }, + function (error) { + $ionicLoading.hide(); + + });*/ + doRefresh(); + } + }); } diff --git a/www/lang/locale-en.json b/www/lang/locale-en.json index 4db47f2f..7ba8f0fc 100644 --- a/www/lang/locale-en.json +++ b/www/lang/locale-en.json @@ -114,6 +114,7 @@ "kFrom" :"From", "kFromDate" :"From Date", "kFromTime" :"From Time", + "kGlobalConfiguration" :"Global Configuration", "kGraphAlarmed" :"alarmed", "kGraphAll" :"all", "kGraphError" :"there was an error rendering the graph. Please see logs", diff --git a/www/templates/monitors.html b/www/templates/monitors.html index fd338df9..dec1adf2 100644 --- a/www/templates/monitors.html +++ b/www/templates/monitors.html @@ -10,6 +10,10 @@ +
+ {{'kGlobalConfiguration' | translate}} +

-- cgit v1.2.3 From f665c94e21854f30bcaf63d96af19ead9eb7a876 Mon Sep 17 00:00:00 2001 From: Pliable Pixels Date: Sat, 27 Aug 2016 19:00:49 -0400 Subject: used all instead of global Former-commit-id: 26feb397dd105965804af5fb26b2a2d1adea611f --- www/templates/monitors.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'www') diff --git a/www/templates/monitors.html b/www/templates/monitors.html index dec1adf2..da4252fb 100644 --- a/www/templates/monitors.html +++ b/www/templates/monitors.html @@ -12,7 +12,7 @@
{{'kGlobalConfiguration' | translate}} + href="" ng-click="changeConfig('All', '','1','Monitor');">{{'kGlobalConfiguration' | translate}}

-- cgit v1.2.3 From 6f61ef7e4b5f1240bc2c08b31fad1eed4c34979b Mon Sep 17 00:00:00 2001 From: Pliable Pixels Date: Sat, 27 Aug 2016 19:01:04 -0400 Subject: kAll definition Former-commit-id: 95c1d4cba26c3fb36f9b7d4dab62ee294eeede59 --- www/lang/locale-en.json | 1 + 1 file changed, 1 insertion(+) (limited to 'www') diff --git a/www/lang/locale-en.json b/www/lang/locale-en.json index cb5fc2ef..191d4479 100644 --- a/www/lang/locale-en.json +++ b/www/lang/locale-en.json @@ -7,6 +7,7 @@ "kAlarmFrameCount" :"Alarm Frame Count", "kAlarmMaxFPS" :"Alarm Max FPS", "kAlarms" :"Alarms", + "kAll" : "All", "kAnalyze" :"Analyze", "kApiUrl" :"ZM api url", "kApplyingChanges" :"Applying changes. Please wait", -- cgit v1.2.3 From 5e7d231a702b087542da7e4d19534ae9b375a5ca Mon Sep 17 00:00:00 2001 From: Pliable Pixels Date: Sat, 27 Aug 2016 19:01:51 -0400 Subject: eliminate JSHint 'prefer array literal notation' warning and use kAll Former-commit-id: 3c2665b549b7de527f6a00ed06112897f707b8b9 --- www/js/MonitorCtrl.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'www') diff --git a/www/js/MonitorCtrl.js b/www/js/MonitorCtrl.js index 885796f0..e56ae47d 100644 --- a/www/js/MonitorCtrl.js +++ b/www/js/MonitorCtrl.js @@ -83,11 +83,17 @@ angular.module('zmApp.controllers') //----------------------------------------------------------------------- $scope.changeConfig = function (monitorName, monitorId, enabled, func) { var checked = false; + + if (monitorName == 'All') + { + monitorName = $translate.instant('kAll'); + } + //console.log("called with " + monitorId + ":" + enabled + ":" + func); if (enabled == '1') checked = true; //if monitorId is not specified, all monitors will be changed - var monitorsIds = new Array(); + var monitorsIds = []; if (monitorId == '') { for (var i = 0; i < $scope.monitors.length; i++) { monitorsIds[i] = $scope.monitors[i].Monitor.Id; @@ -128,8 +134,8 @@ angular.module('zmApp.controllers') mymonitorsIds: monitorsIds, myfunc: func, myenabled: checked, - myfailedIds: new Array(), - mypromises: new Array() + myfailedIds: [], + mypromises: [] }; $rootScope.zmPopup = $ionicPopup.show({ -- cgit v1.2.3