Merge pull request #41 from Freddrickk/fixAjax
Fixes non-killed AJAX queries
This commit is contained in:
commit
5d3e632a48
1
.gitignore
vendored
1
.gitignore
vendored
@ -10,6 +10,7 @@ tmp
|
||||
.DS_Store
|
||||
.idea
|
||||
*.swp
|
||||
*.swo
|
||||
app/assets/css
|
||||
.sass-cache/
|
||||
out/
|
||||
|
@ -24,4 +24,11 @@ angular.module('adagios', [
|
||||
|
||||
.config(['$routeProvider', function ($routeProvider) {
|
||||
$routeProvider.otherwise({redirectTo: '/'});
|
||||
}])
|
||||
|
||||
// Reinitialise objects on url change
|
||||
.run(['$rootScope', 'reinitTables', function($rootScope, reinitTables) {
|
||||
$rootScope.$on('$locationChangeStart', function() {
|
||||
reinitTables();
|
||||
});
|
||||
}]);
|
||||
|
@ -6,6 +6,6 @@ angular.module('adagios.table.cell_duration', ['adagios.table'])
|
||||
angular.noop();
|
||||
}])
|
||||
|
||||
.run(['tableConfig', function (tableConfig) {
|
||||
tableConfig.cellToFieldsMap.duration = ['last_state_change'];
|
||||
.run(['tableGlobalConfig', function (tableGlobalConfig) {
|
||||
tableGlobalConfig.cellToFieldsMap.duration = ['last_state_change'];
|
||||
}]);
|
||||
|
@ -16,7 +16,7 @@ angular.module('adagios.table.cell_host', ['adagios.table'])
|
||||
}
|
||||
}])
|
||||
|
||||
.run(['tableConfig', function (tableConfig) {
|
||||
tableConfig.cellToFieldsMap.host = ['host_state', 'host_name'];
|
||||
tableConfig.cellWrappableField.host = 'host_name';
|
||||
.run(['tableGlobalConfig', function (tableGlobalConfig) {
|
||||
tableGlobalConfig.cellToFieldsMap.host = ['host_state', 'host_name'];
|
||||
tableGlobalConfig.cellWrappableField.host = 'host_name';
|
||||
}]);
|
||||
|
@ -6,6 +6,6 @@ angular.module('adagios.table.cell_host_address', ['adagios.table'])
|
||||
angular.noop();
|
||||
}])
|
||||
|
||||
.run(['tableConfig', function (tableConfig) {
|
||||
tableConfig.cellToFieldsMap.host_address = ['host_address'];
|
||||
.run(['tableGlobalConfig', function (tableGlobalConfig) {
|
||||
tableGlobalConfig.cellToFieldsMap.host_address = ['host_address'];
|
||||
}]);
|
||||
|
@ -23,6 +23,6 @@ angular.module('adagios.table.cell_host_status', ['adagios.table'])
|
||||
}
|
||||
}])
|
||||
|
||||
.run(['tableConfig', function (tableConfig) {
|
||||
tableConfig.cellToFieldsMap.host_status = ['state', 'last_check', 'childs'];
|
||||
.run(['tableGlobalConfig', function (tableGlobalConfig) {
|
||||
tableGlobalConfig.cellToFieldsMap.host_status = ['state', 'last_check', 'childs'];
|
||||
}]);
|
||||
|
@ -14,6 +14,6 @@ angular.module('adagios.table.cell_hosts_host', ['adagios.table'])
|
||||
}
|
||||
}])
|
||||
|
||||
.run(['tableConfig', function (tableConfig) {
|
||||
tableConfig.cellToFieldsMap.hosts_host = ['name', 'state'];
|
||||
.run(['tableGlobalConfig', function (tableGlobalConfig) {
|
||||
tableGlobalConfig.cellToFieldsMap.hosts_host = ['name', 'state'];
|
||||
}]);
|
||||
|
@ -6,6 +6,6 @@ angular.module('adagios.table.cell_last_check', ['adagios.table'])
|
||||
angular.noop();
|
||||
}])
|
||||
|
||||
.run(['tableConfig', function (tableConfig) {
|
||||
tableConfig.cellToFieldsMap.last_check = ['last_check'];
|
||||
.run(['tableGlobalConfig', function (tableGlobalConfig) {
|
||||
tableGlobalConfig.cellToFieldsMap.last_check = ['last_check'];
|
||||
}]);
|
||||
|
@ -12,6 +12,6 @@ angular.module('adagios.table.cell_service_check', ['adagios.table'])
|
||||
}
|
||||
}])
|
||||
|
||||
.run(['tableConfig', function (tableConfig) {
|
||||
tableConfig.cellToFieldsMap.service_check = ['state', 'description', 'plugin_output'];
|
||||
.run(['tableGlobalConfig', function (tableGlobalConfig) {
|
||||
tableGlobalConfig.cellToFieldsMap.service_check = ['state', 'description', 'plugin_output'];
|
||||
}]);
|
||||
|
@ -12,13 +12,16 @@ angular.module('adagios.table', ['adagios.live',
|
||||
'adagios.table.cell_host_status'
|
||||
])
|
||||
|
||||
.value('tableConfig', {'cellToFieldsMap': {}, 'cellWrappableField': {}, 'index': 0})
|
||||
.value('tableGlobalConfig', {'cellToFieldsMap': {}, 'cellWrappableField': {}, 'nextTableIndex': 0})
|
||||
|
||||
.controller('TableCtrl', ['$scope', '$interval', 'getServices', 'tableConfig', 'actionbarFilters',
|
||||
function ($scope, $interval, getServices, tableConfig, actionbarFilters) {
|
||||
console.log(tableConfig[tableConfig.index].additionnalQueryFields);
|
||||
.value('tablesConfig', [])
|
||||
|
||||
.value('ajaxQueries', [])
|
||||
|
||||
.controller('TableCtrl', ['$scope', '$interval', 'getServices', 'tablesConfig', 'actionbarFilters', 'ajaxQueries', 'tableGlobalConfig',
|
||||
function ($scope, $interval, getServices, tablesConfig, actionbarFilters, ajaxQueries, tableGlobalConfig) {
|
||||
var requestFields = [],
|
||||
conf = tableConfig[tableConfig.index],
|
||||
conf = tablesConfig[tableGlobalConfig.nextTableIndex],
|
||||
getData,
|
||||
i;
|
||||
|
||||
@ -31,13 +34,12 @@ angular.module('adagios.table', ['adagios.live',
|
||||
}
|
||||
|
||||
angular.forEach($scope.cellsName, function (key) {
|
||||
angular.forEach(tableConfig.cellToFieldsMap[key], function (_value) {
|
||||
angular.forEach(tableGlobalConfig.cellToFieldsMap[key], function (_value) {
|
||||
requestFields.push(_value);
|
||||
});
|
||||
});
|
||||
|
||||
getData = function (requestFields, filters, apiName, additionnalFields) {
|
||||
console.log(additionnalFields);
|
||||
getServices(requestFields, filters, apiName, additionnalFields)
|
||||
.success(function (data) {
|
||||
$scope.entries = data;
|
||||
@ -46,70 +48,73 @@ angular.module('adagios.table', ['adagios.live',
|
||||
|
||||
getData(requestFields, conf.filters, conf.apiName, conf.additionnalQueryFields);
|
||||
|
||||
if (tableConfig.refreshInterval !== '0') {
|
||||
$interval(function () {
|
||||
getData(requestFields, conf.filters, conf.apiName, conf.additionnalQueryFields);
|
||||
}, tableConfig.refreshInterval);
|
||||
if (tableGlobalConfig.refreshInterval !== 0) {
|
||||
ajaxQueries.push(
|
||||
$interval(function () {
|
||||
getData(requestFields, conf.filters, conf.apiName, conf.additionnalQueryFields);
|
||||
}, tableGlobalConfig.refreshInterval)
|
||||
);
|
||||
}
|
||||
|
||||
$scope.actionbarFilters = actionbarFilters;
|
||||
|
||||
// Index needed to support multiple tables per view
|
||||
$scope.tableIndex = tableConfig.index;
|
||||
tableConfig.index += 1;
|
||||
$scope.tableIndex = tableGlobalConfig.nextTableIndex;
|
||||
tableGlobalConfig.nextTableIndex += 1;
|
||||
}])
|
||||
|
||||
.directive('adgTable', ['$http', '$compile', 'tableConfig', function ($http, $compile, tableConfig) {
|
||||
return {
|
||||
restrict: 'E',
|
||||
compile: function () {
|
||||
return function (scope, element, attrs) {
|
||||
.directive('adgTable', ['$http', '$compile', 'tablesConfig', 'tableGlobalConfig',
|
||||
function ($http, $compile, tablesConfig, tableGlobalConfig) {
|
||||
return {
|
||||
restrict: 'E',
|
||||
compile: function () {
|
||||
return function (scope, element, attrs) {
|
||||
|
||||
var template = 'components/table/table.html',
|
||||
conf;
|
||||
var template = 'components/table/table.html',
|
||||
conf;
|
||||
|
||||
if (!attrs.cellsText || !attrs.cellsName || !attrs.apiName || !attrs.isWrappable) {
|
||||
throw new Error('<adg-table> "cells-text", "cells-name", "api-name"'
|
||||
+ ' and "is-wrappable" attributes must be defined');
|
||||
}
|
||||
if (!attrs.cellsText || !attrs.cellsName || !attrs.apiName || !attrs.isWrappable) {
|
||||
throw new Error('<adg-table> "cells-text", "cells-name", "api-name"'
|
||||
+ ' and "is-wrappable" attributes must be defined');
|
||||
}
|
||||
|
||||
tableConfig[attrs.tableId] = {};
|
||||
conf = tableConfig[attrs.tableId];
|
||||
conf.filters = {};
|
||||
conf.additionnalQueryFields = {};
|
||||
tablesConfig[attrs.tableId] = {};
|
||||
conf = tablesConfig[attrs.tableId];
|
||||
conf.filters = {};
|
||||
conf.additionnalQueryFields = {};
|
||||
|
||||
conf.cells = { 'text': [], 'name': [] };
|
||||
conf.cells.text = attrs.cellsText.split(',');
|
||||
conf.cells.name = attrs.cellsName.split(',');
|
||||
conf.cells = { 'text': [], 'name': [] };
|
||||
conf.cells.text = attrs.cellsText.split(',');
|
||||
conf.cells.name = attrs.cellsName.split(',');
|
||||
|
||||
conf.apiName = attrs.apiName;
|
||||
conf.apiName = attrs.apiName;
|
||||
|
||||
conf.isWrappable = JSON.parse(attrs.isWrappable);
|
||||
conf.noRepeatCell = attrs.noRepeatCell;
|
||||
conf.tableId = attrs.tableId;
|
||||
conf.isWrappable = JSON.parse(attrs.isWrappable);
|
||||
conf.noRepeatCell = attrs.noRepeatCell;
|
||||
tableGlobalConfig.tableId = attrs.tableId;
|
||||
|
||||
if (!!attrs.filters) {
|
||||
conf.filters = JSON.parse(attrs.filters);
|
||||
}
|
||||
if (!!attrs.filters) {
|
||||
conf.filters = JSON.parse(attrs.filters);
|
||||
}
|
||||
|
||||
if (!!attrs.additionnalQueryFields) {
|
||||
conf.additionnalQueryFields = JSON.parse(attrs.additionnalQueryFields);
|
||||
}
|
||||
if (!!attrs.additionnalQueryFields) {
|
||||
conf.additionnalQueryFields = JSON.parse(attrs.additionnalQueryFields);
|
||||
}
|
||||
|
||||
if (!!attrs.refreshInterval) {
|
||||
tableConfig.refreshInterval = attrs.refreshInterval;
|
||||
}
|
||||
if (!!attrs.refreshInterval) {
|
||||
tableGlobalConfig.refreshInterval = parseInt(attrs.refreshInterval * 1000, 10);
|
||||
}
|
||||
|
||||
|
||||
$http.get(template, { cache: true })
|
||||
.success(function (data) {
|
||||
var elem = $compile(data)(scope);
|
||||
element.append(elem);
|
||||
});
|
||||
};
|
||||
}
|
||||
};
|
||||
}])
|
||||
$http.get(template, { cache: true })
|
||||
.success(function (data) {
|
||||
var elem = $compile(data)(scope);
|
||||
element.append(elem);
|
||||
});
|
||||
};
|
||||
}
|
||||
};
|
||||
}])
|
||||
|
||||
.directive('adgCell', ['$http', '$compile', function ($http, $compile) {
|
||||
|
||||
@ -134,6 +139,19 @@ angular.module('adagios.table', ['adagios.live',
|
||||
};
|
||||
}])
|
||||
|
||||
.service('reinitTables', ['$interval', 'ajaxQueries', 'tablesConfig', 'tableGlobalConfig',
|
||||
function ($interval, ajaxQueries, tablesConfig, tableGlobalConfig) {
|
||||
return function () {
|
||||
// Stop AJAX queries
|
||||
angular.forEach(ajaxQueries, function (promise) {
|
||||
$interval.cancel(promise);
|
||||
});
|
||||
|
||||
// Reinitialise table index
|
||||
tableGlobalConfig.nextTableIndex = 0;
|
||||
};
|
||||
}])
|
||||
|
||||
.value('TableConfigObj', function (config) {
|
||||
this.title = config.title;
|
||||
this.CellsText = config.cells.text.join();
|
||||
@ -145,20 +163,20 @@ angular.module('adagios.table', ['adagios.live',
|
||||
this.additionnalQueryFields = config.additionnalQueryFields;
|
||||
})
|
||||
|
||||
.filter('wrappableStyle', ['tableConfig', function (tableConfig) {
|
||||
.filter('wrappableStyle', ['tablesConfig', 'tableGlobalConfig', function (tablesConfig, tableGlobalConfig) {
|
||||
return function (input, scope) {
|
||||
var last = '',
|
||||
entry = {},
|
||||
parent_found = false,
|
||||
class_name = ['', ''],
|
||||
i,
|
||||
fieldToWrap = tableConfig.cellWrappableField[tableConfig[scope.tableIndex].noRepeatCell];
|
||||
fieldToWrap = tableGlobalConfig.cellWrappableField[tablesConfig[scope.tableIndex].noRepeatCell];
|
||||
|
||||
if (fieldToWrap === undefined) {
|
||||
return input;
|
||||
}
|
||||
|
||||
if (tableConfig[scope.tableIndex].isWrappable) {
|
||||
if (tablesConfig[scope.tableIndex].isWrappable) {
|
||||
class_name = ['state--hasChild', 'state--isChild'];
|
||||
}
|
||||
|
||||
@ -187,21 +205,21 @@ angular.module('adagios.table', ['adagios.live',
|
||||
};
|
||||
}])
|
||||
|
||||
.filter('noRepeat', ['tableConfig', function (tableConfig) {
|
||||
.filter('noRepeat', ['tablesConfig', 'tableGlobalConfig', function (tablesConfig, tableGlobalConfig) {
|
||||
return function (items, scope) {
|
||||
var newItems = [],
|
||||
previous,
|
||||
fieldToCompare = tableConfig.cellWrappableField[tableConfig[scope.tableIndex].noRepeatCell],
|
||||
new_attr = tableConfig[scope.tableIndex].noRepeatCell + "_additionnalClass";
|
||||
fieldToCompare = tableGlobalConfig.cellWrappableField[tablesConfig[scope.tableIndex].noRepeatCell],
|
||||
newAttr = tablesConfig[scope.tableIndex].noRepeatCell + "_additionnalClass";
|
||||
|
||||
angular.forEach(items, function (item) {
|
||||
|
||||
if (previous === item[fieldToCompare]) {
|
||||
item[new_attr] = 'state--rmChild';
|
||||
item[newAttr] = 'state--rmChild';
|
||||
} else {
|
||||
previous = item[fieldToCompare].slice(0);
|
||||
if (!!item[new_attr]) {
|
||||
item[new_attr] = item[new_attr].replace("state--rmChild", "");
|
||||
if (!!item[newAttr]) {
|
||||
item[newAttr] = item[newAttr].replace("state--rmChild", "");
|
||||
}
|
||||
}
|
||||
newItems.push(item);
|
||||
|
@ -1,4 +1,4 @@
|
||||
<article ng-controller="DashboardCtrl" id="tactical">
|
||||
<article id="tactical">
|
||||
<header class="main__overview">
|
||||
<h2 class="main__overview__title">{{dashboardTactical[0].title}}</h2>
|
||||
|
||||
|
@ -15,10 +15,10 @@ angular.module('adagios.view.dashboard', ['ngRoute',
|
||||
});
|
||||
}])
|
||||
|
||||
.controller('DashboardCtrl', ['$scope', '$routeParams', 'dashboardConfig', 'getServices', 'tableConfig',
|
||||
.controller('DashboardCtrl', ['$scope', '$routeParams', 'dashboardConfig', 'getServices',
|
||||
'TableConfigObj', 'TacticalConfigObj', 'getHostOpenProblems', 'getServiceOpenProblems', 'getHostProblems',
|
||||
'getServiceProblems',
|
||||
function ($scope, $routeParams, dashboardConfig, getServices, tableConfig, TableConfigObj,
|
||||
function ($scope, $routeParams, dashboardConfig, getServices, TableConfigObj,
|
||||
TacticalConfigObj, getHostOpenProblems, getServiceOpenProblems, getHostProblems, getServiceProblems) {
|
||||
var components = [],
|
||||
component,
|
||||
@ -26,8 +26,6 @@ angular.module('adagios.view.dashboard', ['ngRoute',
|
||||
viewName,
|
||||
i = 0;
|
||||
|
||||
tableConfig.index = 0;
|
||||
|
||||
if (!!$routeParams.view) {
|
||||
viewName = $routeParams.view;
|
||||
} else {
|
||||
|
@ -16,12 +16,10 @@ angular.module('adagios.view.singleTable', ['ngRoute',
|
||||
});
|
||||
}])
|
||||
|
||||
.controller('SingleTableCtrl', ['$scope', '$routeParams', 'singleTableConfig', 'tableConfig', 'TableConfigObj',
|
||||
function ($scope, $routeParams, singleTableConfig, tableConfig, TableConfigObj) {
|
||||
.controller('SingleTableCtrl', ['$scope', '$routeParams', 'singleTableConfig', 'TableConfigObj',
|
||||
function ($scope, $routeParams, singleTableConfig, TableConfigObj) {
|
||||
var viewName = "";
|
||||
|
||||
tableConfig.index = 0;
|
||||
|
||||
if (!!$routeParams.view) {
|
||||
viewName = $routeParams.view;
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user