From 15423e6e51313e071ac64df8a313f813e397c610 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Tue, 20 Sep 2016 17:34:38 +0200 Subject: [PATCH] feat(adhoc filters): initial base mvp for adhoc filters are donecloses #6038 --- public/app/features/templating/editor_ctrl.ts | 22 ++++++-- .../features/templating/partials/editor.html | 51 ++++++++++--------- .../plugins/datasource/influxdb/datasource.ts | 2 + 3 files changed, 47 insertions(+), 28 deletions(-) diff --git a/public/app/features/templating/editor_ctrl.ts b/public/app/features/templating/editor_ctrl.ts index 25ddec62cce..81bf2d4d71c 100644 --- a/public/app/features/templating/editor_ctrl.ts +++ b/public/app/features/templating/editor_ctrl.ts @@ -9,6 +9,7 @@ export class VariableEditorCtrl { /** @ngInject */ constructor(private $scope, private datasourceSrv, private variableSrv, templateSrv) { $scope.variableTypes = variableTypes; + $scope.ctrl = {}; $scope.refreshOptions = [ {value: 0, text: "Never"}, @@ -60,9 +61,8 @@ export class VariableEditorCtrl { }; $scope.isValid = function() { - if (!$scope.current.name) { - $scope.appEvent('alert-warning', ['Validation', 'Template variable requires a name']); - return false; + if (!$scope.ctrl.form.$valid) { + return; } if (!$scope.current.name.match(/^\w+$/)) { @@ -79,6 +79,18 @@ export class VariableEditorCtrl { return true; }; + $scope.validate = function() { + $scope.infoText = ''; + if ($scope.current.type === 'adhoc' && $scope.current.datasource !== null) { + $scope.infoText = 'Adhoc filters are applied automatically to all queries that target this datasource'; + datasourceSrv.get($scope.current.datasource).then(ds => { + if (!ds.supportAdhocFilters) { + $scope.infoText = 'This datasource does not support adhoc filters yet.'; + } + }); + } + }; + $scope.runQuery = function() { return variableSrv.updateOptions($scope.current).then(null, function(err) { if (err.data && err.data.message) { err.message = err.data.message; } @@ -90,6 +102,7 @@ export class VariableEditorCtrl { $scope.current = variable; $scope.currentIsNew = false; $scope.mode = 'edit'; + $scope.validate(); }; $scope.duplicate = function(variable) { @@ -126,6 +139,8 @@ export class VariableEditorCtrl { if (oldIndex !== -1) { this.variables[oldIndex] = $scope.current; } + + $scope.validate(); }; $scope.removeVariable = function(variable) { @@ -133,7 +148,6 @@ export class VariableEditorCtrl { $scope.variables.splice(index, 1); $scope.updateSubmenuVisibility(); }; - } } diff --git a/public/app/features/templating/partials/editor.html b/public/app/features/templating/partials/editor.html index c74245ae6be..e485072eed0 100644 --- a/public/app/features/templating/partials/editor.html +++ b/public/app/features/templating/partials/editor.html @@ -70,13 +70,13 @@ -
+
Variable
Name - +
@@ -102,15 +102,14 @@
-
-
+
Interval Options
Values - +
Auto option @@ -134,15 +133,15 @@
-
+
Custom Options
Values separated by comma - +
-
+
Constant options
Value @@ -150,14 +149,14 @@
-
+
Query Options
Data source
- +
@@ -174,7 +173,7 @@
Query - +
@@ -223,19 +222,18 @@
-
+
Options
-
Data source
- +
-
+
-
-
Selection Options
+
+
Selection Options
-
+
Preview of values (shows max 20)
@@ -280,12 +278,17 @@
-
-
- - -
-
+
+ {{infoText}} +
+ +
+ + +
+ + +
diff --git a/public/app/plugins/datasource/influxdb/datasource.ts b/public/app/plugins/datasource/influxdb/datasource.ts index dd35f42f02e..4c707dd59d1 100644 --- a/public/app/plugins/datasource/influxdb/datasource.ts +++ b/public/app/plugins/datasource/influxdb/datasource.ts @@ -21,6 +21,7 @@ export default class InfluxDatasource { interval: any; supportAnnotations: boolean; supportMetrics: boolean; + supportAdhocFilters: boolean; responseParser: any; /** @ngInject */ @@ -39,6 +40,7 @@ export default class InfluxDatasource { this.interval = (instanceSettings.jsonData || {}).timeInterval; this.supportAnnotations = true; this.supportMetrics = true; + this.supportAdhocFilters = true; this.responseParser = new ResponseParser(); }