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