Commit d04f2d5e by Harald Kraemer

Renamed most filter-related things in filterSrv to template.

After all, we are using the function "template" to apply some
data we pull from the URL or other situations in order to call
a function called template. Hence, filtering doesn't make sense
as a term here.
parent b1c9d5fd
......@@ -120,7 +120,7 @@ function (angular, _, config, gfunc, Parser) {
}
var path = getSegmentPathUpTo(fromIndex + 1);
return $scope.datasource.metricFindQuery($scope.filterSrv, path)
return $scope.datasource.metricFindQuery($scope.filter, path)
.then(function(segments) {
if (segments.length === 0) {
$scope.segments = $scope.segments.splice(0, fromIndex);
......@@ -157,17 +157,17 @@ function (angular, _, config, gfunc, Parser) {
var query = index === 0 ?
'*' : getSegmentPathUpTo(index) + '.*';
return $scope.datasource.metricFindQuery($scope.filterSrv, query)
return $scope.datasource.metricFindQuery($scope.filter, query)
.then(function(segments) {
_.each(segments, function(segment) {
segment.html = segment.val = segment.text;
});
_.each($scope.filter.list, function(filter) {
_.each($scope.filter.templateParameters, function( templateParameter ) {
segments.unshift({
type: 'template',
html: '[[' + filter.name + ']]',
val: '[[' + filter.name + ']]',
html: '[[' + templateParameter.name + ']]',
val: '[[' + templateParameter.name + ']]',
expandable: true,
});
});
......
......@@ -14,7 +14,7 @@ function (angular, app, _) {
var module = angular.module('kibana.panels.filtering', []);
app.useModule(module);
module.controller('filtering', function($scope, datasourceSrv, $rootScope, $timeout, dashboard) {
module.controller('filtering', function($scope, datasourceSrv, $rootScope, $timeout) {
$scope.panelMeta = {
status : "Stable",
......@@ -27,13 +27,11 @@ function (angular, app, _) {
_.defaults($scope.panel,_d);
$scope.init = function() {
$scope.filterSrv = filterSrv;
console.log( "Filtering panel " + $scope.dashboard );
$scope.filterSrv.init( $scope.dashboard );
// empty. Don't know if I need the function then.
};
$scope.remove = function(filter) {
this.filter.removeFilter(filter);
$scope.remove = function( templateParameter ) {
this.filter.removeTemplateParameter( templateParameter );
// TODO hkraemer: check if this makes sense like this
if(!$rootScope.$$phase) {
......@@ -44,24 +42,24 @@ function (angular, app, _) {
},0);
};
$scope.filterOptionSelected = function(filter, option) {
this.filter.filterOptionSelected(option);
this.applyFilterToOtherFilters(filter);
$scope.filterOptionSelected = function( templateParameter, option ) {
this.filter.templateOptionSelected(option);
this.applyFilterToOtherFilters(templateParameter);
};
$scope.applyFilterToOtherFilters = function(updatedFilter) {
_.each(this.filter.list, function(filter) {
if (filter === updatedFilter) {
_.each(this.filter.templateParameters, function( templateParameter ) {
if (templateParameter === updatedFilter) {
return;
}
if (filter.query.indexOf(updatedFilter.name) !== -1) {
$scope.applyFilter(filter);
if (templateParameter.query.indexOf(updatedFilter.name) !== -1) {
$scope.applyFilter(templateParameter);
}
});
};
$scope.applyFilter = function(filter) {
var query = this.filter.applyFilterToTarget(filter.query);
var query = this.filter.applyTemplateToTarget(filter.query);
datasourceSrv.default.metricFindQuery($scope, query)
.then(function (results) {
......@@ -79,12 +77,12 @@ function (angular, app, _) {
filter.options.unshift({text: 'All', value: allExpr});
}
this.filterSrv.filterOptionSelected(filter, filter.options[0]);
this.filter.templateOptionSelected(filter, filter.options[0]);
});
};
$scope.add = function() {
this.filter.add({
this.filter.addTemplateParameter({
type : 'filter',
name : 'filter name',
editing : true,
......
......@@ -258,7 +258,7 @@ function (angular, app, $, _, kbn, moment, timeSeries) {
datasource: $scope.panel.datasource
};
$scope.annotationsPromise = annotationsSrv.getAnnotations($scope.filterSrv, $scope.rangeUnparsed);
$scope.annotationsPromise = annotationsSrv.getAnnotations($scope.filter, $scope.rangeUnparsed);
return $scope.datasource.query($scope.filter, graphiteQuery)
.then($scope.dataHandler)
......
......@@ -11,43 +11,43 @@ define([
module.factory('filterSrv', function(dashboard, $rootScope, $timeout, $routeParams) {
// defaults
var _d = {
list: [],
templateParameters: [],
time: {}
};
var result = {
_updateTemplateData : function( initial ) {
this._filterTemplateData = {};
_.each(this.list, function(filter) {
if (initial) {
var urlValue = $routeParams[filter.name];
if (urlValue) {
filter.current = { text: urlValue, value: urlValue };
this._templateData = {};
_.each(this.templateParameters, function( templateParameter ) {
if (initial) {
var urlValue = $routeParams[ templateParameter.name ];
if (urlValue) {
templateParameter.current = { text: urlValue, value: urlValue };
}
}
if (!templateParameter.current || !templateParameter.current.value) {
return;
}
}
if (!filter.current || !filter.current.value) {
return;
}
this._filterTemplateData[filter.name] = filter.current.value;
this._templateData[ templateParameter.name ] = templateParameter.current.value;
});
},
filterOptionSelected : function(option) {
templateOptionSelected : function(option) {
this.current = option;
this._updateTemplateData();
},
add : function(filter) {
this.list.push(filter);
addTemplateParameter : function( templateParameter ) {
this.templateParameters.push( templateParameter );
},
applyFilterToTarget : function(target) {
applyTemplateToTarget : function(target) {
if (target.indexOf('[[') === -1) {
return target;
}
return _.template(target, this._filterTemplateData, this.templateSettings);
return _.template(target, this._templateData, this.templateSettings);
},
setTime : function(time) {
......@@ -86,9 +86,10 @@ define([
}
},
removeFilter : function( filter ) {
this.list = _.without(this.list, filter);
removeTemplateParameter : function( templateParameter ) {
this.templateParameters = _.without( this.templateParameters, templateParameter );
},
init : function( dashboard ) {
_.defaults(this, _d);
this.dashboard = dashboard;
......
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