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