From a5502a37510814d1ca0fbef668c02a23e0b6eb79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Wed, 5 Mar 2014 12:43:44 +0100 Subject: [PATCH] added typeahead to column for influxdb, #103 --- src/app/controllers/influxTargetCtrl.js | 41 +++++++++++++------ src/app/partials/influxdb/editor.html | 4 +- .../services/influxdb/influxdbDatasource.js | 13 +++++- 3 files changed, 44 insertions(+), 14 deletions(-) diff --git a/src/app/controllers/influxTargetCtrl.js b/src/app/controllers/influxTargetCtrl.js index eeb4340426d..66439c5e757 100644 --- a/src/app/controllers/influxTargetCtrl.js +++ b/src/app/controllers/influxTargetCtrl.js @@ -15,14 +15,7 @@ function (angular) { $scope.target.function = 'mean'; } - if (!seriesList) { - seriesList = []; - $scope.datasource.listSeries().then(function(series) { - seriesList = series; - }); - } - - $scope.oldSeris = $scope.target.series; + $scope.oldSeries = $scope.target.series; $scope.$on('typeahead-updated', function(){ $timeout($scope.get_data); }); @@ -30,14 +23,38 @@ function (angular) { // Cannot use typeahead and ng-change on blur at the same time $scope.seriesBlur = function() { - if ($scope.oldSeris !== $scope.target.series) { - $scope.oldSeris = $scope.target.series; + if ($scope.oldSeries !== $scope.target.series) { + $scope.oldSeries = $scope.target.series; $scope.get_data(); } }; - $scope.listSeries = function() { - return seriesList; + // called outside of digest + $scope.listColumns = function(query, callback) { + if (!$scope.columnList) { + $scope.$apply(function() { + $scope.datasource.listColumns($scope.target.series).then(function(columns) { + $scope.columnList = columns; + callback(columns); + }); + }); + } + else { + return $scope.columnList; + } + }; + + $scope.listSeries = function(query, callback) { + if (!seriesList) { + seriesList = []; + $scope.datasource.listSeries().then(function(series) { + seriesList = series; + callback(seriesList); + }); + } + else { + return seriesList; + } }; $scope.duplicate = function() { diff --git a/src/app/partials/influxdb/editor.html b/src/app/partials/influxdb/editor.html index 79eba938824..4a6927e5984 100644 --- a/src/app/partials/influxdb/editor.html +++ b/src/app/partials/influxdb/editor.html @@ -66,7 +66,9 @@ ng-model="target.column" placeholder="value column" spellcheck='false' - ng-model-onblur ng-change="get_data()" > + bs-typeahead="listColumns" + data-min-length=0 + ng-blur="get_data()">
  • function diff --git a/src/app/services/influxdb/influxdbDatasource.js b/src/app/services/influxdb/influxdbDatasource.js index 20c24ad3cb4..9f92627e32d 100644 --- a/src/app/services/influxdb/influxdbDatasource.js +++ b/src/app/services/influxdb/influxdbDatasource.js @@ -41,7 +41,6 @@ function (angular, _, kbn) { }; var query = _.template(template, templateData, this.templateSettings); - console.log(query); return this.doInfluxRequest(query).then(handleInfluxQueryResponse); @@ -54,6 +53,17 @@ function (angular, _, kbn) { }; + InfluxDatasource.prototype.listColumns = function(seriesName) { + return this.doInfluxRequest('select * from ' + seriesName + ' limit 1').then(function(results) { + console.log('response!'); + if (!results.data) { + return []; + } + + return results.data[0].columns; + }); + }; + InfluxDatasource.prototype.listSeries = function() { return this.doInfluxRequest('list series').then(function(results) { if (!results.data) { @@ -79,6 +89,7 @@ function (angular, _, kbn) { params: params, }; + console.log(query); return $http(options); };