feat(templating): added new template variable type constant

This commit is contained in:
Torkel Ödegaard 2016-05-28 16:59:29 +02:00
parent ca8543348b
commit 1ea54049d0
3 changed files with 36 additions and 2 deletions

View File

@ -25,6 +25,7 @@ function (angular, _) {
{value: "interval", text: "Interval"}, {value: "interval", text: "Interval"},
{value: "datasource", text: "Data source"}, {value: "datasource", text: "Data source"},
{value: "custom", text: "Custom"}, {value: "custom", text: "Custom"},
{value: "constant", text: "Constant"},
]; ];
$scope.refreshOptions = [ $scope.refreshOptions = [
@ -141,15 +142,34 @@ function (angular, _) {
$scope.current = angular.copy(replacementDefaults); $scope.current = angular.copy(replacementDefaults);
}; };
$scope.showSelectionOptions = function() {
if ($scope.current) {
if ($scope.current.type === 'query') {
return true;
}
if ($scope.current.type === 'custom') {
return true;
}
}
return false;
};
$scope.typeChanged = function () { $scope.typeChanged = function () {
if ($scope.current.type === 'interval') { if ($scope.current.type === 'interval') {
$scope.current.query = '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.refresh = 0;
} }
if ($scope.current.type === 'query') { if ($scope.current.type === 'query') {
$scope.current.query = ''; $scope.current.query = '';
} }
if ($scope.current.type === 'constant') {
$scope.current.query = '';
$scope.current.refresh = 0;
$scope.current.hide = 2;
}
if ($scope.current.type === 'datasource') { if ($scope.current.type === 'datasource') {
$scope.current.query = $scope.datasourceTypes[0].value; $scope.current.query = $scope.datasourceTypes[0].value;
$scope.current.regex = ''; $scope.current.regex = '';

View File

@ -152,6 +152,14 @@
</div> </div>
</div> </div>
<div ng-show="current.type === 'constant'" class="gf-form-group">
<h5 class="section-heading">Constant options</h5>
<div class="gf-form">
<span class="gf-form-label">Value</span>
<input type="text" class="gf-form-input" ng-model='current.query' ng-blur="runQuery()" placeholder="your metric prefix"></input>
</div>
</div>
<div ng-show="current.type === 'query'" class="gf-form-group"> <div ng-show="current.type === 'query'" class="gf-form-group">
<h5 class="section-heading">Query Options</h5> <h5 class="section-heading">Query Options</h5>
@ -214,7 +222,7 @@
</div> </div>
</div> </div>
<div class="section gf-form-group" ng-hide="current.type === 'datasource'"> <div class="section gf-form-group" ng-show="showSelectionOptions()">
<h5 class="section-heading">Selection Options</h5> <h5 class="section-heading">Selection Options</h5>
<div class="section"> <div class="section">
<gf-form-switch class="gf-form" <gf-form-switch class="gf-form"

View File

@ -168,6 +168,11 @@ function (angular, _, kbn) {
return; return;
} }
if (variable.type === 'constant') {
variable.options = [{text: variable.query, value: variable.query}];
return;
}
// extract options in comma seperated string // extract options in comma seperated string
variable.options = _.map(variable.query.split(/[,]+/), function(text) { variable.options = _.map(variable.query.split(/[,]+/), function(text) {
return { text: text.trim(), value: text.trim() }; return { text: text.trim(), value: text.trim() };
@ -175,6 +180,7 @@ function (angular, _, kbn) {
if (variable.type === 'interval') { if (variable.type === 'interval') {
self.updateAutoInterval(variable); self.updateAutoInterval(variable);
return;
} }
if (variable.type === 'custom' && variable.includeAll) { if (variable.type === 'custom' && variable.includeAll) {
@ -273,7 +279,7 @@ function (angular, _, kbn) {
if (currentOption) { if (currentOption) {
return self.setVariableValue(variable, currentOption, false); return self.setVariableValue(variable, currentOption, false);
} else { } else {
if (!variable.options.length) { return; } if (!variable.options.length) { return $q.when(null); }
return self.setVariableValue(variable, variable.options[0]); return self.setVariableValue(variable, variable.options[0]);
} }
} }