From d04f2d5e2b36153ecaf5839668eca9e82e9f1243 Mon Sep 17 00:00:00 2001 From: Harald Kraemer Date: Tue, 20 May 2014 09:27:54 +0200 Subject: [PATCH] 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. --- src/app/controllers/graphiteTarget.js | 10 +++---- src/app/panels/filtering/module.js | 30 ++++++++++----------- src/app/panels/graphite/module.js | 2 +- src/app/services/filterSrv.js | 39 ++++++++++++++------------- 4 files changed, 40 insertions(+), 41 deletions(-) diff --git a/src/app/controllers/graphiteTarget.js b/src/app/controllers/graphiteTarget.js index e9dc9f3867b..8e9f9799c94 100644 --- a/src/app/controllers/graphiteTarget.js +++ b/src/app/controllers/graphiteTarget.js @@ -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, }); }); diff --git a/src/app/panels/filtering/module.js b/src/app/panels/filtering/module.js index c4353202d17..5a8c49e0cff 100644 --- a/src/app/panels/filtering/module.js +++ b/src/app/panels/filtering/module.js @@ -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, diff --git a/src/app/panels/graphite/module.js b/src/app/panels/graphite/module.js index 3a35fe9be69..02f1abb43b4 100644 --- a/src/app/panels/graphite/module.js +++ b/src/app/panels/graphite/module.js @@ -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) diff --git a/src/app/services/filterSrv.js b/src/app/services/filterSrv.js index 157ca6eadc9..dd1957f9ce7 100644 --- a/src/app/services/filterSrv.js +++ b/src/app/services/filterSrv.js @@ -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;