mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
trying to get new templating / filtering to work
This commit is contained in:
@@ -10,7 +10,7 @@ function (angular, _, config, gfunc, Parser) {
|
|||||||
|
|
||||||
var module = angular.module('grafana.controllers');
|
var module = angular.module('grafana.controllers');
|
||||||
|
|
||||||
module.controller('GraphiteTargetCtrl', function($scope, $sce) {
|
module.controller('GraphiteTargetCtrl', function($scope, $sce, templateSrv) {
|
||||||
|
|
||||||
$scope.init = function() {
|
$scope.init = function() {
|
||||||
$scope.target.target = $scope.target.target || '';
|
$scope.target.target = $scope.target.target || '';
|
||||||
@@ -153,10 +153,10 @@ function (angular, _, config, gfunc, Parser) {
|
|||||||
return new MetricSegment({ value: segment.text, expandable: segment.expandable });
|
return new MetricSegment({ value: segment.text, expandable: segment.expandable });
|
||||||
});
|
});
|
||||||
|
|
||||||
_.each($scope.filter.templateParameters, function(templateParameter) {
|
_.each(templateSrv.variables, function(variable) {
|
||||||
$scope.altSegments.unshift(new MetricSegment({
|
$scope.altSegments.unshift(new MetricSegment({
|
||||||
type: 'template',
|
type: 'template',
|
||||||
value: '[[' + templateParameter.name + ']]',
|
value: '[[' + variable.name + ']]',
|
||||||
expandable: true,
|
expandable: true,
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -74,8 +74,10 @@ function (angular, _) {
|
|||||||
|
|
||||||
$scope.typeChanged = function () {
|
$scope.typeChanged = function () {
|
||||||
if ($scope.current.type === 'time period') {
|
if ($scope.current.type === 'time period') {
|
||||||
$scope.current.query = 'auto,1m,10m,30m,1h,6h,12h,1d,7d,14d,30d';
|
$scope.current.query = '1m,10m,30m,1h,6h,12h,1d,7d,14d,30d';
|
||||||
$scope.current.auto_count = 10;
|
}
|
||||||
|
else {
|
||||||
|
$scope.current.query = '';
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -21,9 +21,6 @@ function (angular, app, _, $) {
|
|||||||
var $input = $(inputTemplate);
|
var $input = $(inputTemplate);
|
||||||
var $button = $(buttonTemplate);
|
var $button = $(buttonTemplate);
|
||||||
var variable = $scope.variable;
|
var variable = $scope.variable;
|
||||||
var options = _.map(variable.options, function(option) {
|
|
||||||
return option.text;
|
|
||||||
});
|
|
||||||
|
|
||||||
$input.appendTo(elem);
|
$input.appendTo(elem);
|
||||||
$button.appendTo(elem);
|
$button.appendTo(elem);
|
||||||
@@ -40,7 +37,6 @@ function (angular, app, _, $) {
|
|||||||
|
|
||||||
$input.attr('data-provide', 'typeahead');
|
$input.attr('data-provide', 'typeahead');
|
||||||
$input.typeahead({
|
$input.typeahead({
|
||||||
source: options,
|
|
||||||
minLength: 0,
|
minLength: 0,
|
||||||
items: 10,
|
items: 10,
|
||||||
updater: function(value) {
|
updater: function(value) {
|
||||||
@@ -52,8 +48,9 @@ function (angular, app, _, $) {
|
|||||||
|
|
||||||
var typeahead = $input.data('typeahead');
|
var typeahead = $input.data('typeahead');
|
||||||
typeahead.lookup = function () {
|
typeahead.lookup = function () {
|
||||||
|
var options = _.map(variable.options, function(option) { return option.text; });
|
||||||
this.query = this.$element.val() || '';
|
this.query = this.$element.val() || '';
|
||||||
return this.process(this.source);
|
return this.process(options);
|
||||||
};
|
};
|
||||||
|
|
||||||
$button.click(function() {
|
$button.click(function() {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div ng-model="editor.index" bs-tabs style="text-transform:capitalize;">
|
<div ng-model="editor.index" bs-tabs style="text-transform:capitalize;">
|
||||||
<div ng-repeat="tab in ['Overview', 'Add', 'Edit']" data-title="{{tab}}">
|
<div ng-repeat="tab in ['Variables', 'Add', 'Edit']" data-title="{{tab}}">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -71,16 +71,6 @@
|
|||||||
<label class="small">Values</label>
|
<label class="small">Values</label>
|
||||||
<input type="text" class="input-xxlarge" ng-model='current.query' placeholder="name"></input>
|
<input type="text" class="input-xxlarge" ng-model='current.query' placeholder="name"></input>
|
||||||
</div>
|
</div>
|
||||||
<div class="editor-option">
|
|
||||||
<label class="small">Auto period count <tip>The number you want to divide the time range in</tip></label>
|
|
||||||
<select class="input-small" ng-model="current.auto_count" ng-options="f for f in [5,6,7,8,9,10,15,20,30,40,50,70,90,100]"></select>
|
|
||||||
</div>
|
|
||||||
<p class="small">
|
|
||||||
<br>
|
|
||||||
<i class="icon-info-sign"></i>
|
|
||||||
This special type of template replacement is useful as the auto word will be calculated depending on the time range divided by
|
|
||||||
the number of periods you wish.
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div ng-show="current.type === 'query'">
|
<div ng-show="current.type === 'query'">
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ function (angular, _, $, config, kbn, moment) {
|
|||||||
|
|
||||||
var module = angular.module('grafana.services');
|
var module = angular.module('grafana.services');
|
||||||
|
|
||||||
module.factory('ElasticDatasource', function($q, $http) {
|
module.factory('ElasticDatasource', function($q, $http, templateSrv) {
|
||||||
|
|
||||||
function ElasticDatasource(datasource) {
|
function ElasticDatasource(datasource) {
|
||||||
this.type = 'elastic';
|
this.type = 'elastic';
|
||||||
@@ -60,7 +60,7 @@ function (angular, _, $, config, kbn, moment) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
ElasticDatasource.prototype.annotationQuery = function(annotation, filterSrv, rangeUnparsed) {
|
ElasticDatasource.prototype.annotationQuery = function(annotation, rangeUnparsed) {
|
||||||
var range = {};
|
var range = {};
|
||||||
var timeField = annotation.timeField || '@timestamp';
|
var timeField = annotation.timeField || '@timestamp';
|
||||||
var queryString = annotation.query || '*';
|
var queryString = annotation.query || '*';
|
||||||
@@ -73,7 +73,7 @@ function (angular, _, $, config, kbn, moment) {
|
|||||||
to: rangeUnparsed.to,
|
to: rangeUnparsed.to,
|
||||||
};
|
};
|
||||||
|
|
||||||
var queryInterpolated = filterSrv.applyTemplateToTarget(queryString);
|
var queryInterpolated = templateSrv.replace(queryString);
|
||||||
var filter = { "bool": { "must": [{ "range": range }] } };
|
var filter = { "bool": { "must": [{ "range": range }] } };
|
||||||
var query = { "bool": { "should": [{ "query_string": { "query": queryInterpolated } }] } };
|
var query = { "bool": { "should": [{ "query_string": { "query": queryInterpolated } }] } };
|
||||||
var data = { "query" : { "filtered": { "query" : query, "filter": filter } }, "size": 100 };
|
var data = { "query" : { "filtered": { "query" : query, "filter": filter } }, "size": 100 };
|
||||||
|
|||||||
@@ -2,14 +2,15 @@ define([
|
|||||||
'angular',
|
'angular',
|
||||||
'lodash',
|
'lodash',
|
||||||
'kbn',
|
'kbn',
|
||||||
'store'
|
'config'
|
||||||
],
|
],
|
||||||
function (angular, _) {
|
function (angular, _, kbn, config) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var module = angular.module('grafana.services');
|
var module = angular.module('grafana.services');
|
||||||
|
|
||||||
module.service('templateSrv', function($q, $routeParams) {
|
module.service('templateSrv', function($q, $routeParams) {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
this.init = function(variables) {
|
this.init = function(variables) {
|
||||||
this.templateSettings = { interpolate : /\[\[([\s\S]+?)\]\]/g };
|
this.templateSettings = { interpolate : /\[\[([\s\S]+?)\]\]/g };
|
||||||
@@ -29,7 +30,9 @@ function (angular, _) {
|
|||||||
if (!variable.current || !variable.current.value) {
|
if (!variable.current || !variable.current.value) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_templateData[variable.name] = variable.current.value;
|
_templateData[variable.name] = variable.current.value;
|
||||||
|
|
||||||
});
|
});
|
||||||
this._templateData = _templateData;
|
this._templateData = _templateData;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
// -------------------------
|
// -------------------------
|
||||||
@black: #000;
|
@black: #000;
|
||||||
@gray: #bbb;
|
@gray: #bbb;
|
||||||
@grayDark: #242424;
|
@grayDark: #262626;
|
||||||
@grayDarker: #1f1f1f;
|
@grayDarker: #1f1f1f;
|
||||||
|
|
||||||
@grayLight: #ADAFAE;
|
@grayLight: #ADAFAE;
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ define([
|
|||||||
this.datasource = {};
|
this.datasource = {};
|
||||||
this.annotationsSrv = {};
|
this.annotationsSrv = {};
|
||||||
this.timeSrv = new TimeSrvStub();
|
this.timeSrv = new TimeSrvStub();
|
||||||
|
this.templateSrv = new TemplateSrvStub();
|
||||||
this.datasourceSrv = {
|
this.datasourceSrv = {
|
||||||
getMetricSources: function() {},
|
getMetricSources: function() {},
|
||||||
get: function() { return self.datasource; }
|
get: function() { return self.datasource; }
|
||||||
@@ -19,6 +20,7 @@ define([
|
|||||||
$provide.value('datasourceSrv', self.datasourceSrv);
|
$provide.value('datasourceSrv', self.datasourceSrv);
|
||||||
$provide.value('annotationsSrv', self.annotationsSrv);
|
$provide.value('annotationsSrv', self.annotationsSrv);
|
||||||
$provide.value('timeSrv', self.timeSrv);
|
$provide.value('timeSrv', self.timeSrv);
|
||||||
|
$provide.value('templateSrv', self.templateSrv);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -78,6 +80,12 @@ define([
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function TemplateSrvStub() {
|
||||||
|
this.variables = [];
|
||||||
|
this.replace = function() {};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
ControllerTestContext: ControllerTestContext,
|
ControllerTestContext: ControllerTestContext,
|
||||||
|
|||||||
@@ -29,14 +29,9 @@ define([
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('updateTemplateData', function() {
|
describe('updateTemplateData with simple value', function() {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
_templateSrv.init([{
|
_templateSrv.init([{ name: 'test', current: { value: 'muuuu' } }]);
|
||||||
name: 'test',
|
|
||||||
value: 'muuu',
|
|
||||||
current: { value: 'muuuu' }
|
|
||||||
}]);
|
|
||||||
|
|
||||||
_templateSrv.updateTemplateData();
|
_templateSrv.updateTemplateData();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user