Commit 8cd5a996 by Torkel Ödegaard

Fixes for filter option loading and nested filters. Fixes #447, Fixes #412

parent df796e32
...@@ -3,6 +3,12 @@ vNext ...@@ -3,6 +3,12 @@ vNext
- Allow special characters in serie names (influxdb datasource), PR #390 - thx @majst01 - Allow special characters in serie names (influxdb datasource), PR #390 - thx @majst01
- Refactoring of filterSrv (Issue #428), thx @Tetha - Refactoring of filterSrv (Issue #428), thx @Tetha
# Fixes
- Filter option loading when having muliple nested filters now works better.
Options are now reloaded correctly and there are no multiple renders/refresh inbetween (#447),
After an option is changed and a nested template param is also reloaded, if the current value
exists after the options are reloaded the current selected value is kept (Closes #447, Closes #412)
# 1.5.4 (2014-05-13) # 1.5.4 (2014-05-13)
### New features and improvements ### New features and improvements
- InfluxDB enhancement: support for multiple hosts (with retries) and raw queries (Issue #318, thx @toddboom) - InfluxDB enhancement: support for multiple hosts (with retries) and raw queries (Issue #318, thx @toddboom)
......
...@@ -14,7 +14,7 @@ function (angular, app, _) { ...@@ -14,7 +14,7 @@ function (angular, app, _) {
var module = angular.module('kibana.panels.filtering', []); var module = angular.module('kibana.panels.filtering', []);
app.useModule(module); app.useModule(module);
module.controller('filtering', function($scope, datasourceSrv, $rootScope, $timeout) { module.controller('filtering', function($scope, datasourceSrv, $rootScope, $timeout, $q) {
$scope.panelMeta = { $scope.panelMeta = {
status : "Stable", status : "Stable",
...@@ -27,56 +27,67 @@ function (angular, app, _) { ...@@ -27,56 +27,67 @@ function (angular, app, _) {
_.defaults($scope.panel,_d); _.defaults($scope.panel,_d);
$scope.init = function() { $scope.init = function() {
// empty. Don't know if I need the function then. // empty. Don't know if I need the function then.
}; };
$scope.remove = function(templateParameter) { $scope.remove = function(templateParameter) {
$scope.filter.removeTemplateParameter(templateParameter); $scope.filter.removeTemplateParameter(templateParameter);
// TODO hkraemer: check if this makes sense like this
if(!$rootScope.$$phase) {
$rootScope.$apply();
}
$timeout(function(){
$scope.dashboard.refresh();
},0);
}; };
$scope.filterOptionSelected = function(templateParameter, option) { $scope.filterOptionSelected = function(templateParameter, option, recursive) {
$scope.filter.templateOptionSelected(templateParameter, option); templateParameter.current = option;
$scope.applyFilterToOtherFilters(templateParameter);
$scope.filter.updateTemplateData();
return $scope.applyFilterToOtherFilters(templateParameter)
.then(function() {
// only refresh in the outermost call
if (!recursive) {
$scope.dashboard.refresh();
}
});
}; };
$scope.applyFilterToOtherFilters = function(updatedFilter) { $scope.applyFilterToOtherFilters = function(updatedTemplatedParam) {
_.each($scope.filter.templateParameters, function(templateParameter) { var promises = _.map($scope.filter.templateParameters, function(templateParam) {
if (templateParameter === updatedFilter) { if (templateParam === updatedTemplatedParam) {
return; return;
} }
if (templateParameter.query.indexOf(updatedFilter.name) !== -1) { if (templateParam.query.indexOf(updatedTemplatedParam.name) !== -1) {
$scope.applyFilter(templateParameter); return $scope.applyFilter(templateParam);
} }
}); });
};
$scope.applyFilter = function(filter) { return $q.all(promises);
};
datasourceSrv.default.metricFindQuery($scope.filter, filter.query) $scope.applyFilter = function(templateParam) {
return datasourceSrv.default.metricFindQuery($scope.filter, templateParam.query)
.then(function (results) { .then(function (results) {
filter.editing=undefined; templateParam.editing = undefined;
filter.options = _.map(results, function(node) { templateParam.options = _.map(results, function(node) {
return { text: node.text, value: node.text }; return { text: node.text, value: node.text };
}); });
if (filter.includeAll) { if (templateParam.includeAll) {
var allExpr = '{'; var allExpr = '{';
_.each(filter.options, function(option) { _.each(templateParam.options, function(option) {
allExpr += option.text + ','; allExpr += option.text + ',';
}); });
allExpr = allExpr.substring(0, allExpr.length - 1) + '}'; allExpr = allExpr.substring(0, allExpr.length - 1) + '}';
filter.options.unshift({text: 'All', value: allExpr}); templateParam.options.unshift({text: 'All', value: allExpr});
}
// if parameter has current value
// if it exists in options array keep value
if (templateParam.current) {
var currentExists = _.findWhere(templateParam.options, { value: templateParam.current.value });
if (currentExists) {
return $scope.filterOptionSelected(templateParam, templateParam.current, true);
}
} }
$scope.filter.templateOptionSelected(filter, filter.options[0]); return $scope.filterOptionSelected(templateParam, templateParam.options[0], true);
}); });
}; };
...@@ -89,13 +100,5 @@ function (angular, app, _) { ...@@ -89,13 +100,5 @@ function (angular, app, _) {
}); });
}; };
$scope.refresh = function() {
$scope.dashboard.refresh();
};
$scope.render = function() {
$rootScope.$broadcast('render');
};
}); });
}); });
...@@ -16,7 +16,8 @@ define([ ...@@ -16,7 +16,8 @@ define([
}; };
var result = { var result = {
_updateTemplateData: function(initial) {
updateTemplateData: function(initial) {
var _templateData = {}; var _templateData = {};
_.each(this.templateParameters, function(templateParameter) { _.each(this.templateParameters, function(templateParameter) {
if (initial) { if (initial) {
...@@ -34,15 +35,9 @@ define([ ...@@ -34,15 +35,9 @@ define([
this._templateData = _templateData; this._templateData = _templateData;
}, },
templateOptionSelected: function(templateParameter, option) {
templateParameter.current = option;
this._updateTemplateData();
dashboard.refresh();
},
addTemplateParameter: function(templateParameter) { addTemplateParameter: function(templateParameter) {
this.templateParameters.push(templateParameter); this.templateParameters.push(templateParameter);
this._updateTemplateData(); this.updateTemplateData();
}, },
applyTemplateToTarget: function(target) { applyTemplateToTarget: function(target) {
...@@ -105,7 +100,7 @@ define([ ...@@ -105,7 +100,7 @@ define([
if(dashboard.services && dashboard.services.filter) { if(dashboard.services && dashboard.services.filter) {
this.time = dashboard.services.filter.time; this.time = dashboard.services.filter.time;
this.templateParameters = dashboard.services.filter.list || []; this.templateParameters = dashboard.services.filter.list || [];
this._updateTemplateData(true); this.updateTemplateData(true);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment