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 // Reinitialise objects on url change
.run(['$rootScope', 'reinitTables', function ($rootScope, reinitTables) { .run(['$rootScope', 'clearAjaxPromises', 'reinitTables', function ($rootScope, clearAjaxPromises, reinitTables) {
$rootScope.$on('$locationChangeStart', function () { $rootScope.$on('$locationChangeStart', function () {
reinitTables(); reinitTables();
clearAjaxPromises();
}); });
}]); }]);

View File

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

View File

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