summaryrefslogtreecommitdiff
path: root/www/js
diff options
context:
space:
mode:
authorArjun Roychowdhury <pliablepixels@gmail.com>2015-10-23 07:25:36 -0400
committerArjun Roychowdhury <pliablepixels@gmail.com>2015-10-23 07:25:36 -0400
commitdc29a463418d49e02c71493ca7d3e13b6b65e650 (patch)
tree5083f3a8f66e9a55e8f5c44134090fd336764872 /www/js
parentb5cbc97a8b555d73d102d7742ae1f014e7349492 (diff)
You can now specify a minimum reporting interval per monitor for notifications
Diffstat (limited to 'www/js')
-rw-r--r--www/js/DataModel.js4
-rw-r--r--www/js/EventServer.js3
-rw-r--r--www/js/EventServerSettingsCtrl.js239
3 files changed, 156 insertions, 90 deletions
diff --git a/www/js/DataModel.js b/www/js/DataModel.js
index 3c0765c2..b8a5e53b 100644
--- a/www/js/DataModel.js
+++ b/www/js/DataModel.js
@@ -39,8 +39,8 @@ angular.module('zmApp.controllers')
'keepAwake':true, // don't dim/dim during live view
'isUseAuth':true, // true if user wants ZM auth
'isUseEventServer':false, // true if you configure the websocket event server
- 'eventServerMonitors':'',
- 'eventServerInterval':0,
+ 'eventServerMonitors':'', // list of monitors to notify from ES
+ 'eventServerInterval':'', // list of intervals for all monitors
'refreshSec':"2", // timer value for frame change in sec
'enableDebug':false, // if enabled with log messages with "debug"
'usePin':false,
diff --git a/www/js/EventServer.js b/www/js/EventServer.js
index e47ca109..77922f0e 100644
--- a/www/js/EventServer.js
+++ b/www/js/EventServer.js
@@ -20,9 +20,6 @@ angular.module('zmApp.controllers')
var localNotificationId = 0;
-
-
-
//--------------------------------------------------------------------------
// used to compare versions of event server
//--------------------------------------------------------------------------
diff --git a/www/js/EventServerSettingsCtrl.js b/www/js/EventServerSettingsCtrl.js
index 2156f169..3763973a 100644
--- a/www/js/EventServerSettingsCtrl.js
+++ b/www/js/EventServerSettingsCtrl.js
@@ -2,71 +2,157 @@
/* jslint browser: true*/
/* global cordova,StatusBar,angular,console */
-angular.module('zmApp.controllers').controller('zmApp.EventServerSettingsCtrl', ['$scope','$ionicSideMenuDelegate', 'zm', '$stateParams','EventServer', '$ionicHistory', '$rootScope', '$state', 'message', 'ZMDataModel', function ($scope,$ionicSideMenuDelegate,zm, $stateParams, EventServer, $ionicHistory, $rootScope, $state, message, ZMDataModel) {
-$scope.openMenu = function () {
- $ionicSideMenuDelegate.toggleLeft();
- };
+angular.module('zmApp.controllers').controller('zmApp.EventServerSettingsCtrl', ['$scope', '$ionicSideMenuDelegate', 'zm', '$stateParams', 'EventServer', '$ionicHistory', '$rootScope', '$state', 'message', 'ZMDataModel', function ($scope, $ionicSideMenuDelegate, zm, $stateParams, EventServer, $ionicHistory, $rootScope, $state, message, ZMDataModel) {
+ $scope.openMenu = function () {
+ $ionicSideMenuDelegate.toggleLeft();
+ };
- $scope.openMenu = function () {
+ $scope.openMenu = function () {
$ionicSideMenuDelegate.toggleLeft();
};
-
- //----------------------------------------------------------------
+
+ //----------------------------------------------------------------
// Alarm notification handling
//----------------------------------------------------------------
- $scope.handleAlarms = function()
- {
- $rootScope.isAlarm=!$rootScope.isAlarm;
- if (!$rootScope.isAlarm)
- {
- $rootScope.alarmCount="0";
- $ionicHistory.nextViewOptions({disableBack: true});
-
-
- $state.go("events", {"id": 0}, { reload: true });
- }
- };
+ $scope.handleAlarms = function () {
+ $rootScope.isAlarm = !$rootScope.isAlarm;
+ if (!$rootScope.isAlarm) {
+ $rootScope.alarmCount = "0";
+ $ionicHistory.nextViewOptions({
+ disableBack: true
+ });
+
+ $state.go("events", {
+ "id": 0
+ }, {
+ reload: true
+ });
+ }
+ };
+
+ //----------------------------------------------------------------
+ // Save anyway when you exit
+ //----------------------------------------------------------------
$scope.$on('$ionicView.beforeLeave', function () {
- ZMDataModel.zmDebug("Saving Event Server data");
- var monstring="";
- for (var i=0; i < $scope.monitors.length; i++)
- {
- if ($scope.monitors[i].Monitor.isChecked)
- {
- monstring = monstring + $scope.monitors[i].Monitor.Id+",";
- }
- }
-
- if (monstring.charAt(monstring.length - 1) == ',')
+ saveItems();
+
+
+ });
+
+ //----------------------------------------------------------------
+ // Accordion list show/hide
+ //----------------------------------------------------------------
+
+ $scope.toggleGroup = function (group) {
+ if ($scope.isGroupShown(group)) {
+ $scope.shownGroup = null;
+ } else {
+ $scope.shownGroup = group;
+ }
+ };
+ $scope.isGroupShown = function (group) {
+ return $scope.shownGroup === group;
+ };
+
+ $scope.saveItems = function () {
+ saveItems();
+ };
+
+ //----------------------------------------------------------------
+ // Saves ES data
+ //----------------------------------------------------------------
+
+ function saveItems() {
+ ZMDataModel.zmDebug("Saving Event Server data");
+ var monstring = "";
+ var intervalstring = "";
+ for (var i = 0; i < $scope.monitors.length; i++) {
+ if (isNaN($scope.monitors[i].Monitor.reportingInterval)) {
+ $scope.monitors[i].Monitor.reportingInterval = 0;
+ }
+ if ($scope.monitors[i].Monitor.isChecked) {
+ monstring = monstring + $scope.monitors[i].Monitor.Id + ",";
+ var tint = isNaN($scope.monitors[i].Monitor.reportingInterval) ? 0 : parseInt($scope.monitors[i].Monitor.reportingInterval);
+ intervalstring = intervalstring + tint + ",";
+ }
+
+ }
+
+ if (monstring.charAt(monstring.length - 1) == ',')
monstring = monstring.substr(0, monstring.length - 1);
-
- $scope.loginData.eventServerMonitors = monstring;
-
- $scope.loginData.isUseEventServer = ($scope.check.isUseEventServer) ? "1" : "0";
-
- ZMDataModel.setLogin($scope.loginData);
- console.log ("**** EVENT MONSTRING " + monstring);
-
- if ($scope.loginData.isUseEventServer)
- {
+
+ if (intervalstring.charAt(intervalstring.length - 1) == ',')
+ intervalstring = intervalstring.substr(0, intervalstring.length - 1);
+
+ $scope.loginData.eventServerMonitors = monstring;
+ $scope.loginData.eventServerInterval = intervalstring;
+
+ $scope.loginData.isUseEventServer = ($scope.check.isUseEventServer) ? "1" : "0";
+
+ ZMDataModel.setLogin($scope.loginData);
+ console.log("**** EVENT MONSTRING " + monstring);
+ console.log("**** EVENT INTERVALSTRING " + intervalstring);
+
+ if ($scope.loginData.isUseEventServer) {
EventServer.init()
- .then(function(data) {
- console.log ("Sending control filter");
- EventServer.sendMessage ("control", { type:'filter',monlist:monstring});
- });
+ .then(function (data) {
+ console.log("Sending control filter");
+ EventServer.sendMessage("control", {
+ type: 'filter',
+ monlist: monstring,
+ intervalist: intervalstring
+ });
+ });
}
-
- });
+ }
+
+
+ //----------------------------------------------------------------
+ // returns reporting interval for monitor ID
+ //----------------------------------------------------------------
+ function getInterval(id) {
+ // means no interval, should only happen one time
+ // till we save
+ if ($scope.loginData.eventServerInterval == "")
+ return 0;
+ var retval = 0;
+ for (var i = 0; i < res.length; i++) {
+ if (res[i] == id) {
+ retval = parseInt(minterval[i]);
+ break;
+ }
+ }
+ return retval;
+ }
+
+ //----------------------------------------------------------------
+ // Returns true/false if monitor ID is in event monitor list
+ //----------------------------------------------------------------
+ function isEnabled(id) {
+ if ($scope.loginData.eventServerMonitors == "")
+ return true;
+
+ var isThere = false;
+ for (var i = 0; i < res.length; i++) {
+ if (res[i] == id) {
+ isThere = true;
+ console.log("isRes found: " + id);
+ break;
+ }
+ }
+ return isThere;
+ }
+
//-------------------------------------------------------------------------
// Controller Main
//------------------------------------------------------------------------
$scope.monitors = [];
$scope.monitors = message;
-
+
$scope.loginData = ZMDataModel.getLogin();
$scope.check = {
@@ -75,45 +161,28 @@ $scope.openMenu = function () {
$scope.check.isUseEventServer = ($scope.loginData.isUseEventServer == '1') ? true : false;
var res = $scope.loginData.eventServerMonitors.split(",");
-
- function isEnabled(id)
- {
- if ($scope.loginData.eventServerMonitors=="")
- return true;
-
- var isThere = false;
- for (var i=0; i<res.length; i++)
- {
- if (res[i]==id)
- {
- isThere = true;
- console.log ("isRes found: " + id);
- break;
- }
- }
- return isThere;
- }
-
-
-
- for (var i=0; i < $scope.monitors.length; i++)
- {
- if (!isEnabled($scope.monitors[i].Monitor.Id))
- {
+ var minterval = $scope.loginData.eventServerInterval.split(",");
+
+
+ for (var i = 0; i < $scope.monitors.length; i++) {
+
+
+ if (!isEnabled($scope.monitors[i].Monitor.Id)) {
// if the filter list has IDs and this is not part of it, uncheck it
- $scope.monitors[i].Monitor.isChecked = false;
- console.log ("Marking false");
- }
- else
- {
- console.log ("Marking true");
- $scope.monitors[i].Monitor.isChecked = true;
+ $scope.monitors[i].Monitor.isChecked = false;
+ console.log("Marking false");
+ $scope.monitors[i].Monitor.reportingInterval = 0;
+ } else {
+ console.log("Marking true");
+ $scope.monitors[i].Monitor.isChecked = true;
+ $scope.monitors[i].Monitor.reportingInterval = getInterval($scope.monitors[i].Monitor.Id);
}
+
}
-
-
-
-
-
-}]);
+
+
+
+
+
+}]); \ No newline at end of file