diff --git a/app/app.js b/app/app.js index c95cf4b..cdc7456 100644 --- a/app/app.js +++ b/app/app.js @@ -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(); }); }]); diff --git a/app/components/table/table.js b/app/components/table/table.js index c180a0d..24b86dd 100644 --- a/app/components/table/table.js +++ b/app/components/table/table.js @@ -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; }; diff --git a/app/components/utils/promise_manager.js b/app/components/utils/promise_manager.js index 519b19f..8852d54 100644 --- a/app/components/utils/promise_manager.js +++ b/app/components/utils/promise_manager.js @@ -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); });