diff --git a/app/app.js b/app/app.js index 1bb6648..18385ef 100644 --- a/app/app.js +++ b/app/app.js @@ -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(); }); }]); diff --git a/app/components/config/config.json b/app/components/config/config.json index 242e452..afe0de0 100644 --- a/app/components/config/config.json +++ b/app/components/config/config.json @@ -4,5 +4,6 @@ "password":"", "useStoredConfig": true, "surveilApiUrl": "surveil/v2", - "surveilAuthUrl": "surveil/v2/auth" + "surveilAuthUrl": "surveil/v2/auth", + "refreshInterval": -1 } diff --git a/app/components/config/defaultLayoutConfig.json b/app/components/config/defaultLayoutConfig.json index 53e2508..a246e71 100644 --- a/app/components/config/defaultLayoutConfig.json +++ b/app/components/config/defaultLayoutConfig.json @@ -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" diff --git a/app/components/datasource/datasource.js b/app/components/datasource/datasource.js index 24b6a73..ab24a4b 100644 --- a/app/components/datasource/datasource.js +++ b/app/components/datasource/datasource.js @@ -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]; } }; }]); diff --git a/app/components/directive/host/host.js b/app/components/directive/host/host.js index 8c32f2f..2234ac8 100644 --- a/app/components/directive/host/host.js +++ b/app/components/directive/host/host.js @@ -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) { diff --git a/app/components/directive/service/service.js b/app/components/directive/service/service.js index a5f0c86..f7cc835 100644 --- a/app/components/directive/service/service.js +++ b/app/components/directive/service/service.js @@ -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) { diff --git a/app/components/directive/table/table.js b/app/components/directive/table/table.js index 53f7bcd..4e9fbd3 100644 --- a/app/components/directive/table/table.js +++ b/app/components/directive/table/table.js @@ -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); + }); }] }; } diff --git a/app/components/directive/tabpanel/tabpanel.js b/app/components/directive/tabpanel/tabpanel.js index d8db625..9ef2af9 100644 --- a/app/components/directive/tabpanel/tabpanel.js +++ b/app/components/directive/tabpanel/tabpanel.js @@ -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; }); }); diff --git a/app/components/directive/tactical/tactical.js b/app/components/directive/tactical/tactical.js index d155571..f193a4d 100644 --- a/app/components/directive/tactical/tactical.js +++ b/app/components/directive/tactical/tactical.js @@ -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; }); diff --git a/app/components/directive/title/title.js b/app/components/directive/title/title.js index c935938..a53ff76 100644 --- a/app/components/directive/title/title.js +++ b/app/components/directive/title/title.js @@ -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; }); diff --git a/app/components/utils/promise_manager.js b/app/components/utils/promise_manager.js deleted file mode 100644 index a226229..0000000 --- a/app/components/utils/promise_manager.js +++ /dev/null @@ -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(); - }; - }]); diff --git a/app/index.html b/app/index.html index 9da3beb..91cf7bd 100644 --- a/app/index.html +++ b/app/index.html @@ -44,7 +44,6 @@ - @@ -112,6 +111,7 @@ + diff --git a/app/templates/host/host.js b/app/templates/host/host.js index 9b8d1fe..548b1cf 100644 --- a/app/templates/host/host.js +++ b/app/templates/host/host.js @@ -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); } }]); diff --git a/app/templates/page/page.js b/app/templates/page/page.js index 3dc45a5..a7db2b2 100644 --- a/app/templates/page/page.js +++ b/app/templates/page/page.js @@ -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) { diff --git a/app/templates/service/service.js b/app/templates/service/service.js index b1a6128..869d5a7 100644 --- a/app/templates/service/service.js +++ b/app/templates/service/service.js @@ -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); } }]); diff --git a/app/templates/template.js b/app/templates/template.js new file mode 100644 index 0000000..30042e6 --- /dev/null +++ b/app/templates/template.js @@ -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]; + } + }; + }]); +