Add refresh options in config.json
Change-Id: I1f8082e2de040f820c551b17eb838082e2053d05
This commit is contained in:
parent
a66a0e404c
commit
c12dec323f
@ -6,7 +6,6 @@ angular.module('bansho', [
|
||||
'angular.filter',
|
||||
'bansho.config',
|
||||
'bansho.authentication',
|
||||
'bansho.utils.promiseManager',
|
||||
'bansho.topbar',
|
||||
'bansho.sidebar',
|
||||
'bansho.surveil',
|
||||
@ -32,13 +31,12 @@ angular.module('bansho', [
|
||||
}])
|
||||
|
||||
// Reinitialise objects on url change
|
||||
.run(['$rootScope', 'promisesManager', 'sharedData', 'reinitDrupalTiles', 'reinitDrupalInfo', 'componentsConfig',
|
||||
function ($rootScope, promisesManager, sharedData, reinitDrupalTiles, reinitDrupalInfo, componentsConfig) {
|
||||
.run(['$rootScope', 'templateManager', 'reinitDrupalTiles', 'reinitDrupalInfo', 'componentsConfig',
|
||||
function ($rootScope, templateManager, reinitDrupalTiles, reinitDrupalInfo, componentsConfig) {
|
||||
componentsConfig.load();
|
||||
$rootScope.$on('$locationChangeStart', function () {
|
||||
templateManager.clearIntervals();
|
||||
reinitDrupalTiles();
|
||||
reinitDrupalInfo();
|
||||
promisesManager.clearAllPromises();
|
||||
sharedData.clear();
|
||||
});
|
||||
}]);
|
||||
|
@ -4,5 +4,6 @@
|
||||
"password":"",
|
||||
"useStoredConfig": true,
|
||||
"surveilApiUrl": "surveil/v2",
|
||||
"surveilAuthUrl": "surveil/v2/auth"
|
||||
"surveilAuthUrl": "surveil/v2/auth",
|
||||
"refreshInterval": -1
|
||||
}
|
||||
|
@ -4,9 +4,6 @@
|
||||
},
|
||||
"dashboardConfig": {
|
||||
"template": "page",
|
||||
"attributes": {
|
||||
"refreshInterval": 30
|
||||
},
|
||||
"components": [
|
||||
{
|
||||
"type": "tactical",
|
||||
@ -356,7 +353,6 @@
|
||||
"type": "table",
|
||||
"attributes": {
|
||||
"tableId": 0,
|
||||
"refreshInterval": 30,
|
||||
"cells": {
|
||||
"text": [
|
||||
"Host",
|
||||
@ -449,7 +445,6 @@
|
||||
"type": "table",
|
||||
"attributes": {
|
||||
"tableId": 0,
|
||||
"refreshInterval": 30,
|
||||
"cells": {
|
||||
"text": [
|
||||
"Host",
|
||||
@ -527,7 +522,6 @@
|
||||
{
|
||||
"type": "table",
|
||||
"attributes": {
|
||||
"refreshInterval": 30,
|
||||
"tableId": 0,
|
||||
"cells": {
|
||||
"text": [
|
||||
@ -626,17 +620,14 @@
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"refreshInterval": 30
|
||||
]
|
||||
},
|
||||
"drupal": {
|
||||
"title": "Drupal",
|
||||
"refreshInterval": 30,
|
||||
"template": "drupal"
|
||||
},
|
||||
"drupalDashboard": {
|
||||
"title": "Drupal dashboard",
|
||||
"refreshInterval": 30,
|
||||
"template": "drupal_dashboard",
|
||||
"hostsMap": {
|
||||
"drupal": "Wonderful Drupal Website"
|
||||
|
@ -96,55 +96,55 @@ angular.module('bansho.datasource', ['bansho.surveil'])
|
||||
};
|
||||
}])
|
||||
|
||||
.service('sharedData', ['$interval', 'surveilStatus',
|
||||
function ($interval, surveilStatus) {
|
||||
.service('sharedData', ['templateManager', 'surveilStatus',
|
||||
function (templateManager, surveilStatus) {
|
||||
var sharedData = {},
|
||||
listeners = {},
|
||||
providers = {
|
||||
'nbHostsOpenProblems': function (key) {
|
||||
'nbHostsOpenProblems': function () {
|
||||
surveilStatus.getNbHostOpenProblems().then(function (nbHostProblems) {
|
||||
sharedData[key].value = nbHostProblems;
|
||||
notifyListeners(key);
|
||||
sharedData.nbHostsOpenProblems = nbHostProblems;
|
||||
notifyListeners('nbHostsOpenProblems');
|
||||
});
|
||||
},
|
||||
'nbServicesOpenProblems': function (key) {
|
||||
'nbServicesOpenProblems': function () {
|
||||
surveilStatus.getNbServiceOpenProblems().then(function (nbServiceProblems) {
|
||||
sharedData[key].value = nbServiceProblems;
|
||||
notifyListeners(key);
|
||||
sharedData.nbServicesOpenProblems = nbServiceProblems;
|
||||
notifyListeners('nbServicesOpenProblems');
|
||||
});
|
||||
},
|
||||
'nbHosts': function (key) {
|
||||
'nbHosts': function () {
|
||||
surveilStatus.getNbHosts().then(function (nbHosts) {
|
||||
sharedData[key].value = nbHosts;
|
||||
notifyListeners(key);
|
||||
sharedData.nbHosts = nbHosts;
|
||||
notifyListeners('nbHosts');
|
||||
});
|
||||
|
||||
},
|
||||
'nbServices': function (key) {
|
||||
'nbServices': function () {
|
||||
surveilStatus.getNbServices().then(function (nbServices) {
|
||||
sharedData[key].value = nbServices;
|
||||
notifyListeners(key);
|
||||
sharedData.nbServices = nbServices;
|
||||
notifyListeners('nbServices');
|
||||
});
|
||||
},
|
||||
'nbServicesOpenProblemsOnly': function (key) {
|
||||
'nbServicesOpenProblemsOnly': function () {
|
||||
surveilStatus.getNbServiceOpenProblemsOnly().then(function (nbServices) {
|
||||
sharedData[key].value = nbServices;
|
||||
notifyListeners(key);
|
||||
sharedData.nbServicesOpenProblemsOnly = nbServices;
|
||||
notifyListeners('nbServicesOpenProblemsOnly');
|
||||
});
|
||||
},
|
||||
'nbServicesHostsOpenProblems': function (key) {
|
||||
'nbServicesHostsOpenProblems': function () {
|
||||
surveilStatus.getNbHostsProblems().then(function (nbHosts) {
|
||||
surveilStatus.getNbServiceOpenProblemsOnly().then(function (nbServices) {
|
||||
sharedData[key].value = nbHosts + nbServices;
|
||||
notifyListeners(key);
|
||||
sharedData.nbServicesHostsOpenProblems = nbHosts + nbServices;
|
||||
notifyListeners('nbServicesHostsOpenProblems');
|
||||
});
|
||||
});
|
||||
},
|
||||
'nbServicesHostsOpenProblemsDoubleCount': function (key) {
|
||||
'nbServicesHostsOpenProblemsDoubleCount': function () {
|
||||
surveilStatus.getNbHostsProblems().then(function (nbHosts) {
|
||||
surveilStatus.getNbServiceOpenProblems().then(function (nbServices) {
|
||||
sharedData[key].value = nbHosts + nbServices;
|
||||
notifyListeners(key);
|
||||
sharedData.nbServicesHostsOpenProblemsDoubleCount = nbHosts + nbServices;
|
||||
notifyListeners('nbServicesHostsOpenProblemsDoubleCount');
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -152,42 +152,21 @@ angular.module('bansho.datasource', ['bansho.surveil'])
|
||||
|
||||
var notifyListeners = function (key) {
|
||||
angular.forEach(listeners[key], function (onChange) {
|
||||
onChange(sharedData[key].value);
|
||||
onChange(sharedData[key]);
|
||||
});
|
||||
};
|
||||
|
||||
return {
|
||||
clear: function () {
|
||||
angular.forEach(sharedData, function (provider) {
|
||||
$interval.cancel(provider.promise);
|
||||
});
|
||||
sharedData = {};
|
||||
listeners = {};
|
||||
},
|
||||
getData: function (key, interval, onChange) {
|
||||
if (!sharedData[key]) {
|
||||
sharedData[key] = {
|
||||
interval: interval
|
||||
};
|
||||
|
||||
listeners[key] = [
|
||||
onChange
|
||||
];
|
||||
|
||||
providers[key](key);
|
||||
$interval(providers[key](key), interval);
|
||||
getData: function (key, onChange) {
|
||||
if (listeners[key] === undefined) {
|
||||
listeners[key] = [onChange];
|
||||
templateManager.addInterval(providers[key]);
|
||||
providers[key]();
|
||||
} else {
|
||||
listeners[key].push(onChange);
|
||||
|
||||
if (sharedData[key].interval >= interval) {
|
||||
sharedData[key].interval = interval;
|
||||
$interval.cancel(sharedData[key].promise);
|
||||
sharedData[key].promise = $interval(providers[key](key), interval);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return sharedData[key].value;
|
||||
return sharedData[key];
|
||||
}
|
||||
};
|
||||
}]);
|
||||
|
@ -9,9 +9,9 @@ angular.module('bansho.host', ['bansho.datasource'])
|
||||
options: '='
|
||||
},
|
||||
templateUrl: 'components/directive/host/host.html',
|
||||
controller: ['$scope', 'pageParams', 'surveilStatus', 'iframeUrl',
|
||||
function ($scope, pageParams, surveilStatus, iframeUrl) {
|
||||
var hostname = pageParams.hostname;
|
||||
controller: ['$scope', 'templateManager', 'surveilStatus', 'iframeUrl',
|
||||
function ($scope, templateManager, surveilStatus, iframeUrl) {
|
||||
var hostname = templateManager.getPageParam('hostname');
|
||||
|
||||
$scope.param = {};
|
||||
surveilStatus.getHost(hostname).then(function (data) {
|
||||
|
@ -9,10 +9,10 @@ angular.module('bansho.service', ['bansho.datasource'])
|
||||
options: '='
|
||||
},
|
||||
templateUrl: 'components/directive/service/service.html',
|
||||
controller: ['$scope', 'pageParams', 'surveilStatus', 'iframeUrl',
|
||||
function ($scope, pageParams, surveilStatus, iframeUrl) {
|
||||
var hostname = pageParams.host_name,
|
||||
serviceDescription = pageParams.service_description;
|
||||
controller: ['$scope', 'templateManager', 'surveilStatus', 'iframeUrl',
|
||||
function ($scope, templateManager, surveilStatus, iframeUrl) {
|
||||
var hostname = templateManager.getPageParam('host_name'),
|
||||
serviceDescription = templateManager.getPageParam('service_description');
|
||||
|
||||
$scope.param = {};
|
||||
surveilStatus.getService(hostname, serviceDescription).then(function (data) {
|
||||
|
@ -1,7 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
angular.module('bansho.table', ['bansho.utils.promiseManager',
|
||||
'bansho.datasource',
|
||||
angular.module('bansho.table', ['bansho.datasource',
|
||||
'bansho.actionbar',
|
||||
'bansho.filters',
|
||||
'bansho.table.cell_status_host',
|
||||
@ -18,18 +17,17 @@ angular.module('bansho.table', ['bansho.utils.promiseManager',
|
||||
'ngMaterial'
|
||||
])
|
||||
|
||||
.directive('banshoTable', ['datasource', 'tableGlobalConfig',
|
||||
function (datasource, tableGlobalConfig) {
|
||||
.directive('banshoTable', ['datasource',
|
||||
function (datasource) {
|
||||
return {
|
||||
restrict: 'E',
|
||||
scope: {
|
||||
options: '='
|
||||
},
|
||||
templateUrl: 'components/directive/table/table.html',
|
||||
controller: ['$scope', '$interval', 'headerFollow', 'datasource', 'tableGlobalConfig', 'promisesManager', 'pageParams',
|
||||
function ($scope, $interval, headerFollow, datasource, tableGlobalConfig, promisesManager, pageParams) {
|
||||
controller: ['$scope', 'headerFollow', 'datasource', 'templateManager',
|
||||
function ($scope, headerFollow, datasource, templateManager) {
|
||||
var conf = {},
|
||||
refreshInterval = pageParams.refreshInterval ? pageParams.refreshInterval : 100000,
|
||||
i;
|
||||
|
||||
$scope.tableId = $scope.options.attributes.tableId;
|
||||
@ -73,14 +71,9 @@ angular.module('bansho.table', ['bansho.utils.promiseManager',
|
||||
$scope.entries = data;
|
||||
});
|
||||
datasource.refreshTableData($scope.tableId);
|
||||
|
||||
if ($scope.options.attributes.refreshInterval && $scope.options.attributes.refreshInterval !== 0) {
|
||||
promisesManager.addAjaxPromise(
|
||||
$interval(function () {
|
||||
datasource.refreshTableData($scope.tableId);
|
||||
}, refreshInterval)
|
||||
);
|
||||
}
|
||||
templateManager.addInterval(function refreshTable () {
|
||||
datasource.refreshTableData($scope.tableId);
|
||||
});
|
||||
}]
|
||||
};
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ angular.module('bansho.tabpanel', [])
|
||||
});
|
||||
|
||||
angular.forEach(scope.options.attributes.navigation, function (panel, index) {
|
||||
panel.right = sharedData.getData(panel.provider, 30000, function (data) {
|
||||
panel.right = sharedData.getData(panel.provider, function (data) {
|
||||
panel.right = data;
|
||||
});
|
||||
});
|
||||
|
@ -13,29 +13,28 @@ angular.module('bansho.tactical', ['bansho.surveil',
|
||||
scope: {
|
||||
options: '='
|
||||
},
|
||||
controller: ['$scope', '$interval', 'surveilStatus', 'pageParams', 'sharedData',
|
||||
function ($scope, $interval, surveilStatus, pageParams, sharedData) {
|
||||
var refreshInterval = pageParams.refreshInterval ? pageParams.refreshInterval : 100000;
|
||||
controller: ['$scope', 'surveilStatus', 'sharedData',
|
||||
function ($scope, surveilStatus, sharedData) {
|
||||
$scope.title = $scope.options.attributes.title;
|
||||
|
||||
$scope.statusOverview = $scope.options.attributes.statusOverview;
|
||||
$scope.currentHealth = $scope.options.attributes.currentHealth;
|
||||
$scope.topAlertProducers = $scope.options.attributes.topAlertProducers;
|
||||
|
||||
$scope.totalHosts = sharedData.getData('nbHosts', refreshInterval, function (data) {
|
||||
$scope.totalHosts = sharedData.getData('nbHosts', function (data) {
|
||||
$scope.totalHosts = data;
|
||||
});
|
||||
|
||||
$scope.hostProblems = sharedData.getData('nbHostsOpenProblems', refreshInterval, function (data) {
|
||||
$scope.hostProblems = sharedData.getData('nbHostsOpenProblems', function (data) {
|
||||
$scope.hostProblems = data;
|
||||
$scope.hostsRatio = ($scope.totalHosts - $scope.hostProblems) / $scope.totalHosts * 100;
|
||||
});
|
||||
|
||||
$scope.totalServices = sharedData.getData('nbServices', refreshInterval, function (data) {
|
||||
$scope.totalServices = sharedData.getData('nbServices', function (data) {
|
||||
$scope.totalServices = data;
|
||||
});
|
||||
|
||||
$scope.serviceProblems = sharedData.getData('nbServicesOpenProblems', refreshInterval, function (data) {
|
||||
$scope.serviceProblems = sharedData.getData('nbServicesOpenProblems', function (data) {
|
||||
$scope.serviceProblems = data;
|
||||
$scope.servicesRatio = ($scope.totalServices - $scope.serviceProblems) / $scope.totalServices * 100;
|
||||
});
|
||||
|
@ -11,7 +11,7 @@ angular.module('bansho.title', [])
|
||||
link: function (scope) {
|
||||
if (scope.options.attributes.item) {
|
||||
scope.item = scope.options.attributes.item;
|
||||
scope.data = sharedData.getData(scope.options.attributes.provider, 30000, function (data) {
|
||||
scope.data = sharedData.getData(scope.options.attributes.provider, function (data) {
|
||||
scope.data = data;
|
||||
});
|
||||
|
||||
|
@ -1,28 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
angular.module('bansho.utils.promiseManager', [])
|
||||
|
||||
.service('promisesManager', ['$interval', function ($interval) {
|
||||
var ajaxPromises = [];
|
||||
|
||||
function clearAjaxPromises () {
|
||||
angular.forEach(ajaxPromises, function (promise) {
|
||||
$interval.cancel(promise);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new promise to check
|
||||
* @param promise
|
||||
*/
|
||||
this.addAjaxPromise = function (promise) {
|
||||
ajaxPromises.push(promise);
|
||||
};
|
||||
|
||||
/**
|
||||
* Clear all types of promises
|
||||
*/
|
||||
this.clearAllPromises = function () {
|
||||
clearAjaxPromises();
|
||||
};
|
||||
}]);
|
@ -44,7 +44,6 @@
|
||||
|
||||
<script src="app.js"></script>
|
||||
<script src="components/config/config.js"></script>
|
||||
<script src="components/utils/promise_manager.js"></script>
|
||||
|
||||
<!-- Surveil API client -->
|
||||
<script src="components/surveil/surveil.js"></script>
|
||||
@ -112,6 +111,7 @@
|
||||
<script src="components/drupal/drupal_tile/drupal_tile.js"></script>
|
||||
<script src="components/drupal/drupal_info/drupal_info.js"></script>
|
||||
<script src="routing_view/routing_view.js"></script>
|
||||
<script src="templates/template.js"></script>
|
||||
<script src="templates/page/page.js"></script>
|
||||
<script src="templates/host/host.js"></script>
|
||||
<script src="templates/config/config.js"></script>
|
||||
|
@ -2,8 +2,8 @@
|
||||
|
||||
angular.module('bansho.view.host', ['bansho.datasource'])
|
||||
|
||||
.controller('HostViewCtrl', ['$scope', '$routeParams', 'configManager', 'pageParams',
|
||||
function ($scope, $routeParams, configManager, pageParams) {
|
||||
.controller('HostViewCtrl', ['$scope', '$routeParams', 'configManager', 'templateManager',
|
||||
function ($scope, $routeParams, configManager, templateManager) {
|
||||
var hostname = $routeParams.host_name;
|
||||
|
||||
$scope.components = configManager.getConfigData($scope.viewName).components;
|
||||
@ -11,6 +11,6 @@ angular.module('bansho.view.host', ['bansho.datasource'])
|
||||
if (!hostname) {
|
||||
throw new Error("ERROR :'host_name' GET parameter must be set");
|
||||
} else {
|
||||
pageParams.hostname = hostname;
|
||||
templateManager.setPageParam('hostname', hostname);
|
||||
}
|
||||
}]);
|
||||
|
@ -1,13 +1,10 @@
|
||||
'use strict';
|
||||
|
||||
angular.module('bansho.view.page', ['bansho.table', 'bansho.tactical'])
|
||||
|
||||
.value('pageParams', {})
|
||||
|
||||
.controller('PageCtrl', ['$scope', 'configManager', 'pageParams',
|
||||
function ($scope, configManager, pageParams) {
|
||||
pageParams.page = configManager.getConfigData($scope.viewName);
|
||||
$scope.components = pageParams.page.components;
|
||||
.controller('PageCtrl', ['$scope', 'configManager', 'templateManager',
|
||||
function ($scope, configManager, templateManager) {
|
||||
templateManager.setLayout($scope.viewName);
|
||||
$scope.components = templateManager.getLayoutComponents();
|
||||
}])
|
||||
|
||||
.directive('banshoComponents', ['$compile', 'directiveBuilder', function ($compile, directiveBuilder) {
|
||||
|
@ -2,8 +2,8 @@
|
||||
|
||||
angular.module("bansho.view.service", [ "bansho.surveil" ])
|
||||
|
||||
.controller("ServiceViewCtrl", ['$scope', '$routeParams', 'configManager', 'pageParams',
|
||||
function ($scope, $routeParams, configManager, pageParams) {
|
||||
.controller("ServiceViewCtrl", ['$scope', '$routeParams', 'configManager', 'templateManager',
|
||||
function ($scope, $routeParams, configManager, templateManager) {
|
||||
var host_name = $routeParams.host_name,
|
||||
service_description = $routeParams.description;
|
||||
|
||||
@ -12,7 +12,7 @@ angular.module("bansho.view.service", [ "bansho.surveil" ])
|
||||
if (!host_name || !service_description) {
|
||||
throw new Error("ERROR :'host_name' and 'description' GET parameters must be set");
|
||||
} else {
|
||||
pageParams.host_name = host_name;
|
||||
pageParams.service_description = service_description;
|
||||
templateManager.setPageParam('host_name', host_name);
|
||||
templateManager.setPageParam('service_description', service_description);
|
||||
}
|
||||
}]);
|
||||
|
39
app/templates/template.js
Normal file
39
app/templates/template.js
Normal file
@ -0,0 +1,39 @@
|
||||
'use strict';
|
||||
|
||||
angular.module('bansho.view')
|
||||
.constant('NO_REFRESH', -1)
|
||||
|
||||
.service('templateManager', ['$interval', 'configManager', 'NO_REFRESH',
|
||||
function ($interval, configManager, NO_REFRESH) {
|
||||
var pageParam = {},
|
||||
layout = {},
|
||||
refreshInterval = -1,
|
||||
intervals = [];
|
||||
|
||||
return {
|
||||
setLayout: function (layoutName) {
|
||||
refreshInterval = configManager.getConfig().refreshInterval;
|
||||
layout = configManager.getConfigData(layoutName);
|
||||
},
|
||||
getLayoutComponents: function () {
|
||||
return layout.components;
|
||||
},
|
||||
addInterval: function (callback) {
|
||||
if (refreshInterval !== NO_REFRESH) {
|
||||
intervals.push($interval(callback, refreshInterval * 1000));
|
||||
}
|
||||
},
|
||||
clearIntervals: function () {
|
||||
angular.forEach(intervals, function (i) {
|
||||
$interval.cancel(i);
|
||||
});
|
||||
},
|
||||
setPageParam: function (key, value) {
|
||||
pageParam[key] = value;
|
||||
},
|
||||
getPageParam: function (key) {
|
||||
return pageParam[key];
|
||||
}
|
||||
};
|
||||
}]);
|
||||
|
Loading…
Reference in New Issue
Block a user