Change promise manager to only one service
This commit is contained in:
parent
76cf0a556d
commit
5043619558
@ -33,9 +33,9 @@ angular.module('bansho', [
|
||||
}])
|
||||
|
||||
// Reinitialise objects on url change
|
||||
.run(['$rootScope', 'clearAjaxPromises', 'reinitTables', function ($rootScope, clearAjaxPromises, reinitTables) {
|
||||
.run(['$rootScope', 'promisesManager', 'reinitTables', function ($rootScope, promisesManager, reinitTables) {
|
||||
$rootScope.$on('$locationChangeStart', function () {
|
||||
reinitTables();
|
||||
clearAjaxPromises();
|
||||
promisesManager.clearAllPromises();
|
||||
});
|
||||
}]);
|
||||
|
@ -17,8 +17,8 @@ angular.module('bansho.table', ['bansho.live',
|
||||
.value('tablesConfig', [])
|
||||
|
||||
.controller('TableCtrl', ['$scope', '$interval', 'getTableData', 'tablesConfig',
|
||||
'actionbarFilters', 'addAjaxPromise', 'tableGlobalConfig',
|
||||
function ($scope, $interval, getTableData, tablesConfig, actionbarFilters, addAjaxPromise, tableGlobalConfig) {
|
||||
'actionbarFilters', 'promisesManager', 'tableGlobalConfig',
|
||||
function ($scope, $interval, getTableData, tablesConfig, actionbarFilters, promisesManager, tableGlobalConfig) {
|
||||
var requestFields = [],
|
||||
conf = tablesConfig[tableGlobalConfig.nextTableIndex],
|
||||
getData,
|
||||
@ -51,7 +51,7 @@ angular.module('bansho.table', ['bansho.live',
|
||||
getData(requestFields, conf.filters, conf.apiName, conf.additionnalQueryFields);
|
||||
|
||||
if (tableGlobalConfig.refreshInterval !== 0) {
|
||||
addAjaxPromise(
|
||||
promisesManager.addAjaxPromise(
|
||||
$interval(function () {
|
||||
getData(requestFields, conf.filters, conf.apiName, conf.additionnalQueryFields);
|
||||
}, tableGlobalConfig.refreshInterval)
|
||||
|
@ -17,9 +17,9 @@ angular.module('bansho.tactical', ['bansho.live',
|
||||
})
|
||||
|
||||
.controller('TacticalCtrl', ['$scope', '$interval', 'tacticalConfig', 'getHostProblems', 'getServiceProblems',
|
||||
'getTotalHosts', 'getTotalServices', 'addAjaxPromise',
|
||||
'getTotalHosts', 'getTotalServices', 'promisesManager',
|
||||
function ($scope, $interval, tacticalConfig, getHostProblems, getServiceProblems, getTotalHosts,
|
||||
getTotalServices, addAjaxPromise) {
|
||||
getTotalServices, promisesManager) {
|
||||
|
||||
var getData;
|
||||
|
||||
@ -53,7 +53,7 @@ angular.module('bansho.tactical', ['bansho.live',
|
||||
};
|
||||
|
||||
if (tacticalConfig.refreshInterval !== 0) {
|
||||
addAjaxPromise(
|
||||
promisesManager.addAjaxPromise(
|
||||
$interval(getData, tacticalConfig.refreshInterval)
|
||||
);
|
||||
}
|
||||
|
@ -2,8 +2,8 @@
|
||||
|
||||
angular.module('bansho.topbar', ['bansho.live'])
|
||||
|
||||
.controller('TopBarCtrl', ['$scope', '$interval', 'getServiceProblems', 'getHostProblems', 'addAjaxPromise',
|
||||
function ($scope, $interval, getServiceProblems, getHostProblems, addAjaxPromise) {
|
||||
.controller('TopBarCtrl', ['$scope', '$interval', 'getServiceProblems', 'getHostProblems', 'promisesManager',
|
||||
function ($scope, $interval, getServiceProblems, getHostProblems, promisesManager) {
|
||||
var getData,
|
||||
hostProblems,
|
||||
serviceProblems;
|
||||
@ -19,7 +19,7 @@ angular.module('bansho.topbar', ['bansho.live'])
|
||||
};
|
||||
|
||||
// TODO: Change hardcoded interval when the topbar dashboard will be implemented
|
||||
addAjaxPromise($interval(getData, 10000));
|
||||
promisesManager.addAjaxPromise($interval(getData, 10000));
|
||||
getData();
|
||||
}])
|
||||
|
||||
|
@ -2,25 +2,27 @@
|
||||
|
||||
angular.module('bansho.utils.promiseManager', [])
|
||||
|
||||
.value('ajaxPromises', [])
|
||||
.service('promisesManager', ['$interval', function ($interval) {
|
||||
var ajaxPromises = [];
|
||||
|
||||
.service('addAjaxPromise', ['ajaxPromises', function (ajaxPromises) {
|
||||
return function (promise) {
|
||||
ajaxPromises.push(promise);
|
||||
};
|
||||
}])
|
||||
|
||||
.service('clearAjaxPromises', ['$interval', 'ajaxPromises', function ($interval, ajaxPromises) {
|
||||
return function () {
|
||||
function clearAjaxPromises () {
|
||||
angular.forEach(ajaxPromises, function (promise) {
|
||||
$interval.cancel(promise);
|
||||
});
|
||||
};
|
||||
}])
|
||||
}
|
||||
|
||||
.service('clearAllPromises', ['ajaxPromises', 'clearAjaxPromises',
|
||||
function (ajaxPromises, clearAjaxPromises) {
|
||||
return function () {
|
||||
/**
|
||||
* Add a new promise to check
|
||||
* @param promise
|
||||
*/
|
||||
this.addAjaxPromise = function (promise) {
|
||||
ajaxPromises.push(promise);
|
||||
};
|
||||
|
||||
/**
|
||||
* Clear all types of promises
|
||||
*/
|
||||
this.clearAllPromises = function () {
|
||||
clearAjaxPromises();
|
||||
};
|
||||
}]);
|
||||
|
@ -11,9 +11,9 @@ angular.module('bansho.view.dashboard', ['ngRoute',
|
||||
|
||||
.controller('DashboardCtrl', ['$scope', '$routeParams', '$interval', 'dashboardConfig', 'getObjects',
|
||||
'TableConfigObj', 'TacticalConfigObj', 'getHostOpenProblems', 'getServiceOpenProblems', 'getHostProblems',
|
||||
'getServiceProblems', 'addAjaxPromise',
|
||||
'getServiceProblems', 'promisesManager',
|
||||
function ($scope, $routeParams, $interval, dashboardConfig, getObjects, TableConfigObj, TacticalConfigObj, getHostOpenProblems,
|
||||
getServiceOpenProblems, getHostProblems, getServiceProblems, addAjaxPromise) {
|
||||
getServiceOpenProblems, getHostProblems, getServiceProblems, promisesManager) {
|
||||
var components = [],
|
||||
component,
|
||||
config,
|
||||
@ -60,7 +60,7 @@ angular.module('bansho.view.dashboard', ['ngRoute',
|
||||
};
|
||||
|
||||
if ($scope.dashboardRefreshInterval !== 0) {
|
||||
addAjaxPromise(
|
||||
promisesManager.addAjaxPromise(
|
||||
$interval(getData, $scope.dashboardRefreshInterval * 1000)
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user