From 3185db96096285c39b454655d4540e4efbb1ff0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Fri, 29 Aug 2014 12:34:04 +0200 Subject: [PATCH] new template system is starting to work 100%, not all features are in, like regex selection, influxdb support, and other stuff --- src/app/controllers/templateEditorCtrl.js | 15 +-- src/app/partials/templating_editor.html | 112 ++++++++++++--------- src/app/services/dashboard/dashboardSrv.js | 21 ++-- src/app/services/templateValuesSrv.js | 27 +++-- src/css/less/tables_lists.less | 31 +++++- src/test/specs/dashboardSrv-specs.js | 3 +- 6 files changed, 137 insertions(+), 72 deletions(-) diff --git a/src/app/controllers/templateEditorCtrl.js b/src/app/controllers/templateEditorCtrl.js index 16d388b97fd..649fefc7cfa 100644 --- a/src/app/controllers/templateEditorCtrl.js +++ b/src/app/controllers/templateEditorCtrl.js @@ -15,6 +15,8 @@ function (angular, _) { refresh_on_load: false, name: '', options: [], + includeAll: false, + allFormat: 'Glob', }; $scope.init = function() { @@ -23,13 +25,6 @@ function (angular, _) { $scope.variables = templateSrv.variables; $scope.reset(); - _.each($scope.variables, function(variable) { - if (variable.datasource === void 0) { - variable.datasource = null; - variable.type = 'query'; - } - }); - $scope.$watch('editor.index', function(index) { if ($scope.currentIsNew === false && index === 1) { $scope.reset(); @@ -50,6 +45,12 @@ function (angular, _) { $scope.current = variable; $scope.currentIsNew = false; $scope.editor.index = 2; + + if ($scope.current.datasource === void 0) { + $scope.current.datasource = null; + $scope.current.type = 'query'; + $scope.current.allFormat = 'Glob'; + } }; $scope.update = function() { diff --git a/src/app/partials/templating_editor.html b/src/app/partials/templating_editor.html index f930e153dd8..61aa68fbeda 100644 --- a/src/app/partials/templating_editor.html +++ b/src/app/partials/templating_editor.html @@ -49,57 +49,77 @@
-
+
- - -
-
- - -
-
- - -
-
- - -
-
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
-
-
- - -
-
+
+
+ + +
+
-
-
-
- - - +
+
+
+ + + +
+
+ +
+
+ + + +
+
+ +
+
+ + +
+
+ + +
+
+ + +
+
- -
-
- - - -
-
- -
-
- -
    -
  • - {{option.text}} -
  • -
+
+
+
+ +
    +
  • + {{option.text}} +
  • +
+
diff --git a/src/app/services/dashboard/dashboardSrv.js b/src/app/services/dashboard/dashboardSrv.js index e88092a4c16..c618e5074da 100644 --- a/src/app/services/dashboard/dashboardSrv.js +++ b/src/app/services/dashboard/dashboardSrv.js @@ -116,11 +116,12 @@ function (angular, $, kbn, _, moment) { }; p.updateSchema = function(old) { + var i, j, k; var oldVersion = this.version; var panelUpgrades = []; - this.version = 5; + this.version = 6; - if (oldVersion === 5) { + if (oldVersion === 6) { return; } @@ -195,7 +196,7 @@ function (angular, $, kbn, _, moment) { }); } - if (oldVersion < 5) { + if (oldVersion < 6) { // move pulldowns to new schema var filtering = _.findWhere(old.pulldowns, { type: 'filtering' }); var annotations = _.findWhere(old.pulldowns, { type: 'annotations' }); @@ -208,16 +209,24 @@ function (angular, $, kbn, _, moment) { enable: annotations.enable }; } + + // update template variables + for (i = 0 ; i < this.templating.list.length; i++) { + var variable = this.templating.list[i]; + if (variable.datasource === void 0) { variable.datasource = null; } + if (variable.type === void 0) { variable.type = 'query'; } + if (variable.allFormat === void 0) { variable.allFormat = 'Glob'; } + } } if (panelUpgrades.length === 0) { return; } - for (var i = 0; i < this.rows.length; i++) { + for (i = 0; i < this.rows.length; i++) { var row = this.rows[i]; - for (var j = 0; j < row.panels.length; j++) { - for (var k = 0; k < panelUpgrades.length; k++) { + for (j = 0; j < row.panels.length; j++) { + for (k = 0; k < panelUpgrades.length; k++) { panelUpgrades[k](row.panels[j]); } } diff --git a/src/app/services/templateValuesSrv.js b/src/app/services/templateValuesSrv.js index a076fef1028..fd766d07700 100644 --- a/src/app/services/templateValuesSrv.js +++ b/src/app/services/templateValuesSrv.js @@ -68,12 +68,7 @@ function (angular, _) { }); if (variable.includeAll) { - var allExpr = '{'; - _.each(variable.options, function(option) { - allExpr += option.text + ','; - }); - allExpr = allExpr.substring(0, allExpr.length - 1) + '}'; - variable.options.unshift({text: 'All', value: allExpr}); + self.addAllOption(variable); } // if parameter has current value @@ -89,6 +84,26 @@ function (angular, _) { }); }; + this.addAllOption = function(variable) { + var allValue = ''; + switch(variable.allFormat) { + case 'wildcard': + allValue = '*'; + break; + case 'regex wildcard': + allValue = '.*'; + break; + default: + allValue = '{'; + _.each(variable.options, function(option) { + allValue += option.text + ','; + }); + allValue = allValue.substring(0, allValue.length - 1) + '}'; + } + + variable.options.unshift({text: 'All', value: allValue}); + }; + }); }); diff --git a/src/css/less/tables_lists.less b/src/css/less/tables_lists.less index 4f95c1a1082..57cc6dce56c 100644 --- a/src/css/less/tables_lists.less +++ b/src/css/less/tables_lists.less @@ -24,11 +24,32 @@ td:last-child { border-right: 1px solid @grafanaListBorderBottom; } +} - .max-width { - overflow: hidden; - text-overflow: ellipsis; - -o-text-overflow: ellipsis; - white-space: nowrap; +.max-width { + overflow: hidden; + text-overflow: ellipsis; + -o-text-overflow: ellipsis; + white-space: nowrap; +} + +.grafana-options-list { + list-style: none; + margin: 0; + max-width: 450px; + + li:nth-child(odd) { + background-color: lighten(@grayDarker, 2%); + } + + li { + float: left; + margin: 2px; + padding: 5px 10px; + border: 1px solid @grafanaListBorderBottom; + border: 1px solid @grafanaListBorderBottom; + } + li:first-child { + border: 1px solid @grafanaListBorderBottom; } } diff --git a/src/test/specs/dashboardSrv-specs.js b/src/test/specs/dashboardSrv-specs.js index c141b746cd3..f916279db98 100644 --- a/src/test/specs/dashboardSrv-specs.js +++ b/src/test/specs/dashboardSrv-specs.js @@ -156,9 +156,8 @@ define([ expect(model.annotations.list[0].name).to.be('old'); }); - it('dashboard schema version should be set to latest', function() { - expect(model.version).to.be(5); + expect(model.version).to.be(6); }); });