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