Table module uses promise manager

This commit is contained in:
Frédéric Vachon 2015-03-31 17:13:53 -04:00
parent 125dc9545a
commit ea1c3912a7
3 changed files with 11 additions and 15 deletions

View File

@ -33,8 +33,9 @@ angular.module('adagios', [
}])
// Reinitialise objects on url change
.run(['$rootScope', 'reinitTables', function ($rootScope, reinitTables) {
.run(['$rootScope', 'clearAjaxPromises', 'reinitTables', function ($rootScope, clearAjaxPromises, reinitTables) {
$rootScope.$on('$locationChangeStart', function () {
reinitTables();
clearAjaxPromises();
});
}]);

View File

@ -1,6 +1,7 @@
'use strict';
angular.module('adagios.table', ['adagios.live',
'adagios.utils.promiseManager',
'adagios.table.actionbar',
'adagios.filters',
'adagios.table.cell_host',
@ -16,10 +17,9 @@ angular.module('adagios.table', ['adagios.live',
.value('tablesConfig', [])
.value('ajaxQueries', [])
.controller('TableCtrl', ['$scope', '$interval', 'getObjects', 'tablesConfig', 'actionbarFilters', 'ajaxQueries', 'tableGlobalConfig',
function ($scope, $interval, getObjects, tablesConfig, actionbarFilters, ajaxQueries, tableGlobalConfig) {
.controller('TableCtrl', ['$scope', '$interval', 'getObjects', 'tablesConfig',
'actionbarFilters', 'addAjaxPromise', 'tableGlobalConfig',
function ($scope, $interval, getObjects, tablesConfig, actionbarFilters, addAjaxPromise, tableGlobalConfig) {
var requestFields = [],
conf = tablesConfig[tableGlobalConfig.nextTableIndex],
getData,
@ -49,7 +49,7 @@ angular.module('adagios.table', ['adagios.live',
getData(requestFields, conf.filters, conf.apiName, conf.additionnalQueryFields);
if (tableGlobalConfig.refreshInterval !== 0) {
ajaxQueries.push(
addAjaxPromise(
$interval(function () {
getData(requestFields, conf.filters, conf.apiName, conf.additionnalQueryFields);
}, tableGlobalConfig.refreshInterval)
@ -138,14 +138,9 @@ angular.module('adagios.table', ['adagios.live',
};
}])
.service('reinitTables', ['$interval', 'ajaxQueries', 'tablesConfig', 'tableGlobalConfig',
function ($interval, ajaxQueries, tablesConfig, tableGlobalConfig) {
.service('reinitTables', ['$interval', 'tablesConfig', 'tableGlobalConfig',
function ($interval, tablesConfig, tableGlobalConfig) {
return function () {
// Stop AJAX queries
angular.forEach(ajaxQueries, function (promise) {
$interval.cancel(promise);
});
// Reinitialise table index
tableGlobalConfig.nextTableIndex = 0;
};

View File

@ -10,8 +10,8 @@ angular.module('adagios.utils.promiseManager', [])
};
}])
.service('clearAjaxPromises', ['$interval', 'ajaxPromises', function (ajaxPromises) {
return function ($interval) {
.service('clearAjaxPromises', ['$interval', 'ajaxPromises', function ($interval, ajaxPromises) {
return function () {
angular.forEach(ajaxPromises, function (promise) {
$interval.cancel(promise);
});