diff --git a/public/app/features/templating/constant_variable.ts b/public/app/features/templating/constant_variable.ts index f76d2c04818..f0a659e0c20 100644 --- a/public/app/features/templating/constant_variable.ts +++ b/public/app/features/templating/constant_variable.ts @@ -1,8 +1,8 @@ /// import _ from 'lodash'; -import {Variable, assignModelProperties} from './variable'; -import {VariableSrv, variableConstructorMap} from './variable_srv'; +import {Variable, assignModelProperties, variableTypes} from './variable'; +import {VariableSrv} from './variable_srv'; export class ConstantVariable implements Variable { query: string; @@ -45,4 +45,8 @@ export class ConstantVariable implements Variable { } } -variableConstructorMap['constant'] = ConstantVariable; +variableTypes['constant'] = { + name: 'Constant', + ctor: ConstantVariable, + description: 'Define a hidden constant variable, useful for metric prefixes in dashboards you want to share' , +}; diff --git a/public/app/features/templating/custom_variable.ts b/public/app/features/templating/custom_variable.ts index 6095bdd1582..77dfd57cae8 100644 --- a/public/app/features/templating/custom_variable.ts +++ b/public/app/features/templating/custom_variable.ts @@ -2,8 +2,8 @@ import _ from 'lodash'; import kbn from 'app/core/utils/kbn'; -import {Variable, assignModelProperties} from './variable'; -import {VariableSrv, variableConstructorMap} from './variable_srv'; +import {Variable, assignModelProperties, variableTypes} from './variable'; +import {VariableSrv} from './variable_srv'; export class CustomVariable implements Variable { query: string; @@ -23,9 +23,7 @@ export class CustomVariable implements Variable { multi: false, }; - supportsMulti = true; - - /** @ngInject */ + /** @ngInject **/ constructor(private model, private timeSrv, private templateSrv, private variableSrv) { assignModelProperties(this, model, this.defaults); } @@ -65,4 +63,9 @@ export class CustomVariable implements Variable { } } -variableConstructorMap['custom'] = CustomVariable; +variableTypes['custom'] = { + name: 'Custom', + ctor: CustomVariable, + description: 'Define variable values manually' , + supportsMulti: true, +}; diff --git a/public/app/features/templating/datasource_variable.ts b/public/app/features/templating/datasource_variable.ts index 8bc13c9f44b..b23b5e04e42 100644 --- a/public/app/features/templating/datasource_variable.ts +++ b/public/app/features/templating/datasource_variable.ts @@ -2,8 +2,8 @@ import _ from 'lodash'; import kbn from 'app/core/utils/kbn'; -import {Variable, assignModelProperties} from './variable'; -import {VariableSrv, variableConstructorMap} from './variable_srv'; +import {Variable, assignModelProperties, variableTypes} from './variable'; +import {VariableSrv} from './variable_srv'; export class DatasourceVariable implements Variable { regex: any; @@ -75,4 +75,8 @@ export class DatasourceVariable implements Variable { } } -variableConstructorMap['datasource'] = DatasourceVariable; +variableTypes['datasource'] = { + name: 'Datasource', + ctor: DatasourceVariable, + description: 'Enabled you to dynamically switch the datasource for multiple panels', +}; diff --git a/public/app/features/templating/editor_ctrl.ts b/public/app/features/templating/editor_ctrl.ts index a185d7d838d..25ddec62cce 100644 --- a/public/app/features/templating/editor_ctrl.ts +++ b/public/app/features/templating/editor_ctrl.ts @@ -1,24 +1,14 @@ /// -import angular from 'angular'; import _ from 'lodash'; -import $ from 'jquery'; -import kbn from 'app/core/utils/kbn'; import coreModule from 'app/core/core_module'; -import appEvents from 'app/core/app_events'; +import {variableTypes} from './variable'; export class VariableEditorCtrl { /** @ngInject */ constructor(private $scope, private datasourceSrv, private variableSrv, templateSrv) { - $scope.variableTypes = [ - {value: "query", text: "Query"}, - {value: "adhoc", text: "Ad hoc filters"}, - {value: "interval", text: "Interval"}, - {value: "datasource", text: "Data source"}, - {value: "custom", text: "Custom"}, - {value: "constant", text: "Constant"}, - ]; + $scope.variableTypes = variableTypes; $scope.refreshOptions = [ {value: 0, text: "Never"}, diff --git a/public/app/features/templating/interval_variable.ts b/public/app/features/templating/interval_variable.ts index e532a054188..94bb608e7e3 100644 --- a/public/app/features/templating/interval_variable.ts +++ b/public/app/features/templating/interval_variable.ts @@ -2,8 +2,8 @@ import _ from 'lodash'; import kbn from 'app/core/utils/kbn'; -import {Variable, assignModelProperties} from './variable'; -import {VariableSrv, variableConstructorMap} from './variable_srv'; +import {Variable, assignModelProperties, variableTypes} from './variable'; +import {VariableSrv} from './variable_srv'; export class IntervalVariable implements Variable { auto_count: number; @@ -77,4 +77,8 @@ export class IntervalVariable implements Variable { } } -variableConstructorMap['interval'] = IntervalVariable; +variableTypes['interval'] = { + name: 'Interval', + ctor: IntervalVariable, + description: 'Define a timespan interval (ex 1m, 1h, 1d)', +}; diff --git a/public/app/features/templating/partials/editor.html b/public/app/features/templating/partials/editor.html index 8158846f790..c74245ae6be 100644 --- a/public/app/features/templating/partials/editor.html +++ b/public/app/features/templating/partials/editor.html @@ -82,21 +82,11 @@ Type -
-
Query
-
Variable values are fetched from a metric names query to a data source
-
Interval
-
Timespan variable type
-
Datasource
-
Dynamically switch data sources using this type of variable
-
Custom
-
Define variable values manually
-
- Templating docs + {{variableTypes[current.type].description}}
- +
@@ -215,26 +205,26 @@
-
- + + -
-
+ + + + +
-
Options
+
Options
Data source @@ -242,58 +232,58 @@
- + -
-
Selection Options
-
- - - - -
-
- Custom all value - -
-
+
+
Selection Options
+
+ + + + +
+
+ Custom all value + +
+
-
-
Value groups/tags (Experimental feature)
-
- -
-
- Tags query - -
-
-
  • Tag values query
  • - -
    -
    +
    +
    Value groups/tags (Experimental feature)
    +
    + +
    +
    + Tags query + +
    +
    +
  • Tag values query
  • + +
    +
    -
    -
    Preview of values (shows max 20)
    -
    -
    - {{option.text}} -
    -
    -
    - +
    +
    Preview of values (shows max 20)
    +
    +
    + {{option.text}} +
    +
    +
    + -
    - +
    +
    diff --git a/public/app/features/templating/query_variable.ts b/public/app/features/templating/query_variable.ts index 82aaa2e5b8f..5d6492849f4 100644 --- a/public/app/features/templating/query_variable.ts +++ b/public/app/features/templating/query_variable.ts @@ -2,8 +2,8 @@ import _ from 'lodash'; import kbn from 'app/core/utils/kbn'; -import {Variable, containsVariable, assignModelProperties} from './variable'; -import {VariableSrv, variableConstructorMap} from './variable_srv'; +import {Variable, containsVariable, assignModelProperties, variableTypes} from './variable'; +import {VariableSrv} from './variable_srv'; function getNoneOption() { return { text: 'None', value: '', isNone: true }; @@ -37,8 +37,6 @@ export class QueryVariable implements Variable { current: {text: '', value: ''}, }; - supportsMulti = true; - constructor(private model, private datasourceSrv, private templateSrv, private variableSrv, private $q) { // copy model properties to this instance assignModelProperties(this, model, this.defaults); @@ -151,4 +149,9 @@ export class QueryVariable implements Variable { } } -variableConstructorMap['query'] = QueryVariable; +variableTypes['query'] = { + name: 'Query', + ctor: QueryVariable, + description: 'Variable values are fetched from a datasource query', + supportsMulti: true, +}; diff --git a/public/app/features/templating/variable.ts b/public/app/features/templating/variable.ts index b9441b55840..9a478b50840 100644 --- a/public/app/features/templating/variable.ts +++ b/public/app/features/templating/variable.ts @@ -11,6 +11,7 @@ export interface Variable { getModel(); } +export var variableTypes = {}; export function assignModelProperties(target, source, defaults) { _.forEach(defaults, function(value, key) { diff --git a/public/app/features/templating/variable_srv.ts b/public/app/features/templating/variable_srv.ts index f31ce7515e0..d2efdeb971e 100644 --- a/public/app/features/templating/variable_srv.ts +++ b/public/app/features/templating/variable_srv.ts @@ -3,9 +3,7 @@ import angular from 'angular'; import _ from 'lodash'; import coreModule from 'app/core/core_module'; -import {Variable} from './variable'; - -export var variableConstructorMap: any = {}; +import {Variable, variableTypes} from './variable'; export class VariableSrv { dashboard: any; @@ -85,7 +83,7 @@ export class VariableSrv { } createVariableFromModel(model) { - var ctor = variableConstructorMap[model.type]; + var ctor = variableTypes[model.type].ctor; if (!ctor) { throw "Unable to find variable constructor for " + model.type; }