diff options
| author | Pliable Pixels <pliablepixels@users.noreply.github.com> | 2016-08-27 19:19:23 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-08-27 19:19:23 -0400 |
| commit | 9c102c42405f7d6a8f6732dd2c26ef1b78067916 (patch) | |
| tree | c4cd9f07e90ac35ed741cb232357b9b9a3e64ee7 /www | |
| parent | 210a8c986e32d963d97c76be892bd205df731ae0 (diff) | |
| parent | 5e7d231a702b087542da7e4d19534ae9b375a5ca (diff) | |
Merge pull request #315 from pliablepixels/sctt-master
tweaks to #313
Former-commit-id: 6a32df94fc8d37166e9c26d6b92c28f03aaac861
Diffstat (limited to 'www')
| -rw-r--r-- | www/js/MonitorCtrl.js | 174 | ||||
| -rw-r--r-- | www/lang/locale-en.json | 2 | ||||
| -rw-r--r-- | www/templates/monitors.html | 4 |
3 files changed, 106 insertions, 74 deletions
diff --git a/www/js/MonitorCtrl.js b/www/js/MonitorCtrl.js index ce6b7255..e56ae47d 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) { //----------------------------------------------------------------------- @@ -83,9 +83,26 @@ 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 = []; + 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 +131,11 @@ angular.module('zmApp.controllers') ]; $scope.monfunc = { + mymonitorsIds: monitorsIds, myfunc: func, - myenabled: checked + myenabled: checked, + myfailedIds: [], + mypromises: [] }; $rootScope.zmPopup = $ionicPopup.show({ @@ -133,87 +153,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 cde95b43..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", @@ -114,6 +115,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..da4252fb 100644 --- a/www/templates/monitors.html +++ b/www/templates/monitors.html @@ -10,6 +10,10 @@ <ion-content overflow-scroll="false"> <ion-refresher pulling-text="Pull to reload Monitors..." spinner="bubbles" on-refresh="doRefresh()"> </ion-refresher> + <div style="float:right;margin-top:3px;margin-right:8px;"> + <a class="button button-small icon icon-left icon ion-gear-a" + href="" ng-click="changeConfig('All', '','1','Monitor');">{{'kGlobalConfiguration' | translate}}</a> + </div><br/> <div class="list card" ng-repeat="monitor in monitors"> <div class="item" ng-style="{'background-color': monitor.Monitor.Enabled=='1'?'white':'white'}"> <div ng-if="monitor.Monitor.Enabled == '1'"> |
