Add refresh options in config.json

Change-Id: I1f8082e2de040f820c551b17eb838082e2053d05
This commit is contained in:
Vincent Fournier 2015-07-31 10:43:42 -04:00
parent a66a0e404c
commit c12dec323f
16 changed files with 110 additions and 141 deletions

View File

@ -6,7 +6,6 @@ angular.module('bansho', [
'angular.filter', 'angular.filter',
'bansho.config', 'bansho.config',
'bansho.authentication', 'bansho.authentication',
'bansho.utils.promiseManager',
'bansho.topbar', 'bansho.topbar',
'bansho.sidebar', 'bansho.sidebar',
'bansho.surveil', 'bansho.surveil',
@ -32,13 +31,12 @@ angular.module('bansho', [
}]) }])
// Reinitialise objects on url change // Reinitialise objects on url change
.run(['$rootScope', 'promisesManager', 'sharedData', 'reinitDrupalTiles', 'reinitDrupalInfo', 'componentsConfig', .run(['$rootScope', 'templateManager', 'reinitDrupalTiles', 'reinitDrupalInfo', 'componentsConfig',
function ($rootScope, promisesManager, sharedData, reinitDrupalTiles, reinitDrupalInfo, componentsConfig) { function ($rootScope, templateManager, reinitDrupalTiles, reinitDrupalInfo, componentsConfig) {
componentsConfig.load(); componentsConfig.load();
$rootScope.$on('$locationChangeStart', function () { $rootScope.$on('$locationChangeStart', function () {
templateManager.clearIntervals();
reinitDrupalTiles(); reinitDrupalTiles();
reinitDrupalInfo(); reinitDrupalInfo();
promisesManager.clearAllPromises();
sharedData.clear();
}); });
}]); }]);

View File

@ -4,5 +4,6 @@
"password":"", "password":"",
"useStoredConfig": true, "useStoredConfig": true,
"surveilApiUrl": "surveil/v2", "surveilApiUrl": "surveil/v2",
"surveilAuthUrl": "surveil/v2/auth" "surveilAuthUrl": "surveil/v2/auth",
"refreshInterval": -1
} }

View File

@ -4,9 +4,6 @@
}, },
"dashboardConfig": { "dashboardConfig": {
"template": "page", "template": "page",
"attributes": {
"refreshInterval": 30
},
"components": [ "components": [
{ {
"type": "tactical", "type": "tactical",
@ -356,7 +353,6 @@
"type": "table", "type": "table",
"attributes": { "attributes": {
"tableId": 0, "tableId": 0,
"refreshInterval": 30,
"cells": { "cells": {
"text": [ "text": [
"Host", "Host",
@ -449,7 +445,6 @@
"type": "table", "type": "table",
"attributes": { "attributes": {
"tableId": 0, "tableId": 0,
"refreshInterval": 30,
"cells": { "cells": {
"text": [ "text": [
"Host", "Host",
@ -527,7 +522,6 @@
{ {
"type": "table", "type": "table",
"attributes": { "attributes": {
"refreshInterval": 30,
"tableId": 0, "tableId": 0,
"cells": { "cells": {
"text": [ "text": [
@ -626,17 +620,14 @@
} }
] ]
} }
], ]
"refreshInterval": 30
}, },
"drupal": { "drupal": {
"title": "Drupal", "title": "Drupal",
"refreshInterval": 30,
"template": "drupal" "template": "drupal"
}, },
"drupalDashboard": { "drupalDashboard": {
"title": "Drupal dashboard", "title": "Drupal dashboard",
"refreshInterval": 30,
"template": "drupal_dashboard", "template": "drupal_dashboard",
"hostsMap": { "hostsMap": {
"drupal": "Wonderful Drupal Website" "drupal": "Wonderful Drupal Website"

View File

@ -96,55 +96,55 @@ angular.module('bansho.datasource', ['bansho.surveil'])
}; };
}]) }])
.service('sharedData', ['$interval', 'surveilStatus', .service('sharedData', ['templateManager', 'surveilStatus',
function ($interval, surveilStatus) { function (templateManager, surveilStatus) {
var sharedData = {}, var sharedData = {},
listeners = {}, listeners = {},
providers = { providers = {
'nbHostsOpenProblems': function (key) { 'nbHostsOpenProblems': function () {
surveilStatus.getNbHostOpenProblems().then(function (nbHostProblems) { surveilStatus.getNbHostOpenProblems().then(function (nbHostProblems) {
sharedData[key].value = nbHostProblems; sharedData.nbHostsOpenProblems = nbHostProblems;
notifyListeners(key); notifyListeners('nbHostsOpenProblems');
}); });
}, },
'nbServicesOpenProblems': function (key) { 'nbServicesOpenProblems': function () {
surveilStatus.getNbServiceOpenProblems().then(function (nbServiceProblems) { surveilStatus.getNbServiceOpenProblems().then(function (nbServiceProblems) {
sharedData[key].value = nbServiceProblems; sharedData.nbServicesOpenProblems = nbServiceProblems;
notifyListeners(key); notifyListeners('nbServicesOpenProblems');
}); });
}, },
'nbHosts': function (key) { 'nbHosts': function () {
surveilStatus.getNbHosts().then(function (nbHosts) { surveilStatus.getNbHosts().then(function (nbHosts) {
sharedData[key].value = nbHosts; sharedData.nbHosts = nbHosts;
notifyListeners(key); notifyListeners('nbHosts');
}); });
}, },
'nbServices': function (key) { 'nbServices': function () {
surveilStatus.getNbServices().then(function (nbServices) { surveilStatus.getNbServices().then(function (nbServices) {
sharedData[key].value = nbServices; sharedData.nbServices = nbServices;
notifyListeners(key); notifyListeners('nbServices');
}); });
}, },
'nbServicesOpenProblemsOnly': function (key) { 'nbServicesOpenProblemsOnly': function () {
surveilStatus.getNbServiceOpenProblemsOnly().then(function (nbServices) { surveilStatus.getNbServiceOpenProblemsOnly().then(function (nbServices) {
sharedData[key].value = nbServices; sharedData.nbServicesOpenProblemsOnly = nbServices;
notifyListeners(key); notifyListeners('nbServicesOpenProblemsOnly');
}); });
}, },
'nbServicesHostsOpenProblems': function (key) { 'nbServicesHostsOpenProblems': function () {
surveilStatus.getNbHostsProblems().then(function (nbHosts) { surveilStatus.getNbHostsProblems().then(function (nbHosts) {
surveilStatus.getNbServiceOpenProblemsOnly().then(function (nbServices) { surveilStatus.getNbServiceOpenProblemsOnly().then(function (nbServices) {
sharedData[key].value = nbHosts + nbServices; sharedData.nbServicesHostsOpenProblems = nbHosts + nbServices;
notifyListeners(key); notifyListeners('nbServicesHostsOpenProblems');
}); });
}); });
}, },
'nbServicesHostsOpenProblemsDoubleCount': function (key) { 'nbServicesHostsOpenProblemsDoubleCount': function () {
surveilStatus.getNbHostsProblems().then(function (nbHosts) { surveilStatus.getNbHostsProblems().then(function (nbHosts) {
surveilStatus.getNbServiceOpenProblems().then(function (nbServices) { surveilStatus.getNbServiceOpenProblems().then(function (nbServices) {
sharedData[key].value = nbHosts + nbServices; sharedData.nbServicesHostsOpenProblemsDoubleCount = nbHosts + nbServices;
notifyListeners(key); notifyListeners('nbServicesHostsOpenProblemsDoubleCount');
}); });
}); });
} }
@ -152,42 +152,21 @@ angular.module('bansho.datasource', ['bansho.surveil'])
var notifyListeners = function (key) { var notifyListeners = function (key) {
angular.forEach(listeners[key], function (onChange) { angular.forEach(listeners[key], function (onChange) {
onChange(sharedData[key].value); onChange(sharedData[key]);
}); });
}; };
return { return {
clear: function () { getData: function (key, onChange) {
angular.forEach(sharedData, function (provider) { if (listeners[key] === undefined) {
$interval.cancel(provider.promise); listeners[key] = [onChange];
}); templateManager.addInterval(providers[key]);
sharedData = {}; providers[key]();
listeners = {};
},
getData: function (key, interval, onChange) {
if (!sharedData[key]) {
sharedData[key] = {
interval: interval
};
listeners[key] = [
onChange
];
providers[key](key);
$interval(providers[key](key), interval);
} else { } else {
listeners[key].push(onChange); 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];
} }
}; };
}]); }]);

View File

@ -9,9 +9,9 @@ angular.module('bansho.host', ['bansho.datasource'])
options: '=' options: '='
}, },
templateUrl: 'components/directive/host/host.html', templateUrl: 'components/directive/host/host.html',
controller: ['$scope', 'pageParams', 'surveilStatus', 'iframeUrl', controller: ['$scope', 'templateManager', 'surveilStatus', 'iframeUrl',
function ($scope, pageParams, surveilStatus, iframeUrl) { function ($scope, templateManager, surveilStatus, iframeUrl) {
var hostname = pageParams.hostname; var hostname = templateManager.getPageParam('hostname');
$scope.param = {}; $scope.param = {};
surveilStatus.getHost(hostname).then(function (data) { surveilStatus.getHost(hostname).then(function (data) {

View File

@ -9,10 +9,10 @@ angular.module('bansho.service', ['bansho.datasource'])
options: '=' options: '='
}, },
templateUrl: 'components/directive/service/service.html', templateUrl: 'components/directive/service/service.html',
controller: ['$scope', 'pageParams', 'surveilStatus', 'iframeUrl', controller: ['$scope', 'templateManager', 'surveilStatus', 'iframeUrl',
function ($scope, pageParams, surveilStatus, iframeUrl) { function ($scope, templateManager, surveilStatus, iframeUrl) {
var hostname = pageParams.host_name, var hostname = templateManager.getPageParam('host_name'),
serviceDescription = pageParams.service_description; serviceDescription = templateManager.getPageParam('service_description');
$scope.param = {}; $scope.param = {};
surveilStatus.getService(hostname, serviceDescription).then(function (data) { surveilStatus.getService(hostname, serviceDescription).then(function (data) {

View File

@ -1,7 +1,6 @@
'use strict'; 'use strict';
angular.module('bansho.table', ['bansho.utils.promiseManager', angular.module('bansho.table', ['bansho.datasource',
'bansho.datasource',
'bansho.actionbar', 'bansho.actionbar',
'bansho.filters', 'bansho.filters',
'bansho.table.cell_status_host', 'bansho.table.cell_status_host',
@ -18,18 +17,17 @@ angular.module('bansho.table', ['bansho.utils.promiseManager',
'ngMaterial' 'ngMaterial'
]) ])
.directive('banshoTable', ['datasource', 'tableGlobalConfig', .directive('banshoTable', ['datasource',
function (datasource, tableGlobalConfig) { function (datasource) {
return { return {
restrict: 'E', restrict: 'E',
scope: { scope: {
options: '=' options: '='
}, },
templateUrl: 'components/directive/table/table.html', templateUrl: 'components/directive/table/table.html',
controller: ['$scope', '$interval', 'headerFollow', 'datasource', 'tableGlobalConfig', 'promisesManager', 'pageParams', controller: ['$scope', 'headerFollow', 'datasource', 'templateManager',
function ($scope, $interval, headerFollow, datasource, tableGlobalConfig, promisesManager, pageParams) { function ($scope, headerFollow, datasource, templateManager) {
var conf = {}, var conf = {},
refreshInterval = pageParams.refreshInterval ? pageParams.refreshInterval : 100000,
i; i;
$scope.tableId = $scope.options.attributes.tableId; $scope.tableId = $scope.options.attributes.tableId;
@ -73,14 +71,9 @@ angular.module('bansho.table', ['bansho.utils.promiseManager',
$scope.entries = data; $scope.entries = data;
}); });
datasource.refreshTableData($scope.tableId); datasource.refreshTableData($scope.tableId);
templateManager.addInterval(function refreshTable () {
if ($scope.options.attributes.refreshInterval && $scope.options.attributes.refreshInterval !== 0) { datasource.refreshTableData($scope.tableId);
promisesManager.addAjaxPromise( });
$interval(function () {
datasource.refreshTableData($scope.tableId);
}, refreshInterval)
);
}
}] }]
}; };
} }

View File

@ -21,7 +21,7 @@ angular.module('bansho.tabpanel', [])
}); });
angular.forEach(scope.options.attributes.navigation, function (panel, index) { 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; panel.right = data;
}); });
}); });

View File

@ -13,29 +13,28 @@ angular.module('bansho.tactical', ['bansho.surveil',
scope: { scope: {
options: '=' options: '='
}, },
controller: ['$scope', '$interval', 'surveilStatus', 'pageParams', 'sharedData', controller: ['$scope', 'surveilStatus', 'sharedData',
function ($scope, $interval, surveilStatus, pageParams, sharedData) { function ($scope, surveilStatus, sharedData) {
var refreshInterval = pageParams.refreshInterval ? pageParams.refreshInterval : 100000;
$scope.title = $scope.options.attributes.title; $scope.title = $scope.options.attributes.title;
$scope.statusOverview = $scope.options.attributes.statusOverview; $scope.statusOverview = $scope.options.attributes.statusOverview;
$scope.currentHealth = $scope.options.attributes.currentHealth; $scope.currentHealth = $scope.options.attributes.currentHealth;
$scope.topAlertProducers = $scope.options.attributes.topAlertProducers; $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.totalHosts = data;
}); });
$scope.hostProblems = sharedData.getData('nbHostsOpenProblems', refreshInterval, function (data) { $scope.hostProblems = sharedData.getData('nbHostsOpenProblems', function (data) {
$scope.hostProblems = data; $scope.hostProblems = data;
$scope.hostsRatio = ($scope.totalHosts - $scope.hostProblems) / $scope.totalHosts * 100; $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.totalServices = data;
}); });
$scope.serviceProblems = sharedData.getData('nbServicesOpenProblems', refreshInterval, function (data) { $scope.serviceProblems = sharedData.getData('nbServicesOpenProblems', function (data) {
$scope.serviceProblems = data; $scope.serviceProblems = data;
$scope.servicesRatio = ($scope.totalServices - $scope.serviceProblems) / $scope.totalServices * 100; $scope.servicesRatio = ($scope.totalServices - $scope.serviceProblems) / $scope.totalServices * 100;
}); });

View File

@ -11,7 +11,7 @@ angular.module('bansho.title', [])
link: function (scope) { link: function (scope) {
if (scope.options.attributes.item) { if (scope.options.attributes.item) {
scope.item = 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; scope.data = data;
}); });

View File

@ -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();
};
}]);

View File

@ -44,7 +44,6 @@
<script src="app.js"></script> <script src="app.js"></script>
<script src="components/config/config.js"></script> <script src="components/config/config.js"></script>
<script src="components/utils/promise_manager.js"></script>
<!-- Surveil API client --> <!-- Surveil API client -->
<script src="components/surveil/surveil.js"></script> <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_tile/drupal_tile.js"></script>
<script src="components/drupal/drupal_info/drupal_info.js"></script> <script src="components/drupal/drupal_info/drupal_info.js"></script>
<script src="routing_view/routing_view.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/page/page.js"></script>
<script src="templates/host/host.js"></script> <script src="templates/host/host.js"></script>
<script src="templates/config/config.js"></script> <script src="templates/config/config.js"></script>

View File

@ -2,8 +2,8 @@
angular.module('bansho.view.host', ['bansho.datasource']) angular.module('bansho.view.host', ['bansho.datasource'])
.controller('HostViewCtrl', ['$scope', '$routeParams', 'configManager', 'pageParams', .controller('HostViewCtrl', ['$scope', '$routeParams', 'configManager', 'templateManager',
function ($scope, $routeParams, configManager, pageParams) { function ($scope, $routeParams, configManager, templateManager) {
var hostname = $routeParams.host_name; var hostname = $routeParams.host_name;
$scope.components = configManager.getConfigData($scope.viewName).components; $scope.components = configManager.getConfigData($scope.viewName).components;
@ -11,6 +11,6 @@ angular.module('bansho.view.host', ['bansho.datasource'])
if (!hostname) { if (!hostname) {
throw new Error("ERROR :'host_name' GET parameter must be set"); throw new Error("ERROR :'host_name' GET parameter must be set");
} else { } else {
pageParams.hostname = hostname; templateManager.setPageParam('hostname', hostname);
} }
}]); }]);

View File

@ -1,13 +1,10 @@
'use strict'; 'use strict';
angular.module('bansho.view.page', ['bansho.table', 'bansho.tactical']) angular.module('bansho.view.page', ['bansho.table', 'bansho.tactical'])
.controller('PageCtrl', ['$scope', 'configManager', 'templateManager',
.value('pageParams', {}) function ($scope, configManager, templateManager) {
templateManager.setLayout($scope.viewName);
.controller('PageCtrl', ['$scope', 'configManager', 'pageParams', $scope.components = templateManager.getLayoutComponents();
function ($scope, configManager, pageParams) {
pageParams.page = configManager.getConfigData($scope.viewName);
$scope.components = pageParams.page.components;
}]) }])
.directive('banshoComponents', ['$compile', 'directiveBuilder', function ($compile, directiveBuilder) { .directive('banshoComponents', ['$compile', 'directiveBuilder', function ($compile, directiveBuilder) {

View File

@ -2,8 +2,8 @@
angular.module("bansho.view.service", [ "bansho.surveil" ]) angular.module("bansho.view.service", [ "bansho.surveil" ])
.controller("ServiceViewCtrl", ['$scope', '$routeParams', 'configManager', 'pageParams', .controller("ServiceViewCtrl", ['$scope', '$routeParams', 'configManager', 'templateManager',
function ($scope, $routeParams, configManager, pageParams) { function ($scope, $routeParams, configManager, templateManager) {
var host_name = $routeParams.host_name, var host_name = $routeParams.host_name,
service_description = $routeParams.description; service_description = $routeParams.description;
@ -12,7 +12,7 @@ angular.module("bansho.view.service", [ "bansho.surveil" ])
if (!host_name || !service_description) { if (!host_name || !service_description) {
throw new Error("ERROR :'host_name' and 'description' GET parameters must be set"); throw new Error("ERROR :'host_name' and 'description' GET parameters must be set");
} else { } else {
pageParams.host_name = host_name; templateManager.setPageParam('host_name', host_name);
pageParams.service_description = service_description; templateManager.setPageParam('service_description', service_description);
} }
}]); }]);

39
app/templates/template.js Normal file
View 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];
}
};
}]);