Procházet zdrojové kódy

Finalized work on influxdb field and func selection, #2311

Torkel Ödegaard před 10 roky
rodič
revize
150fd869a0

+ 1 - 1
public/app/plugins/datasource/influxdb/funcEditor.js

@@ -124,7 +124,7 @@ function (angular, _, $) {
           function addElementsAndCompile() {
           function addElementsAndCompile() {
             $funcLink.appendTo(elem);
             $funcLink.appendTo(elem);
 
 
-            var $paramLink = $('<a ng-click="" class="graphite-func-param-link">value</a>');
+            var $paramLink = $('<a ng-click="" class="graphite-func-param-link">' + $scope.field.name + '</a>');
             var $input = $(paramTemplate);
             var $input = $(paramTemplate);
 
 
             $paramLink.appendTo(elem);
             $paramLink.appendTo(elem);

+ 4 - 1
public/app/plugins/datasource/influxdb/partials/query.editor.html

@@ -66,9 +66,12 @@
 					SELECT
 					SELECT
 				</li>
 				</li>
 				<li class="dropdown" ng-repeat="field in target.fields">
 				<li class="dropdown" ng-repeat="field in target.fields">
-					<span influxdb-func-editor field="field" get-fields="getFields()" on-change="get_data()" class="tight-form-item">
+					<span influxdb-func-editor field="field" get-fields="getFields()" on-change="fieldChanged(field)" class="tight-form-item">
 					</span>
 					</span>
 				</li>
 				</li>
+				<li>
+					<metric-segment segment="addFieldSegment" get-alt-segments="getFieldSegments()" on-value-changed="addField()"></metric-segment>
+				</li>
 			</ul>
 			</ul>
 
 
 			<div class="clearfix"></div>
 			<div class="clearfix"></div>

+ 26 - 1
public/app/plugins/datasource/influxdb/queryCtrl.js

@@ -27,6 +27,8 @@ function (angular, _, InfluxQueryBuilder) {
         $scope.measurementSegment = new MetricSegment(target.measurement);
         $scope.measurementSegment = new MetricSegment(target.measurement);
       }
       }
 
 
+      $scope.addFieldSegment = MetricSegment.newPlusButton();
+
       $scope.tagSegments = [];
       $scope.tagSegments = [];
       _.each(target.tags, function(tag) {
       _.each(target.tags, function(tag) {
         if (tag.condition) {
         if (tag.condition) {
@@ -92,7 +94,11 @@ function (angular, _, InfluxQueryBuilder) {
       var fieldsQuery = $scope.queryBuilder.buildExploreQuery('FIELDS');
       var fieldsQuery = $scope.queryBuilder.buildExploreQuery('FIELDS');
       return $scope.datasource.metricFindQuery(fieldsQuery)
       return $scope.datasource.metricFindQuery(fieldsQuery)
       .then(function(results) {
       .then(function(results) {
-        return _.pluck(results, 'text');
+        var values = _.pluck(results, 'text');
+        if ($scope.target.fields.length > 1) {
+          values.splice(0, 0, "-- remove from select --");
+        }
+        return values;
       });
       });
     };
     };
 
 
@@ -161,6 +167,25 @@ function (angular, _, InfluxQueryBuilder) {
       .then(null, $scope.handleQueryError);
       .then(null, $scope.handleQueryError);
     };
     };
 
 
+    $scope.getFieldSegments = function() {
+      var fieldsQuery = $scope.queryBuilder.buildExploreQuery('FIELDS');
+      return $scope.datasource.metricFindQuery(fieldsQuery)
+        .then($scope.transformToSegments)
+        .then(null, $scope.handleQueryError);
+    };
+
+    $scope.addField = function() {
+      $scope.target.fields.push({name: $scope.addFieldSegment.value, func: 'mean'});
+      _.extend($scope.addFieldSegment, MetricSegment.newPlusButton());
+    };
+
+    $scope.fieldChanged = function(field) {
+      if (field.name === '-- remove from select --') {
+        $scope.target.fields = _.without($scope.target.fields, field);
+      }
+      $scope.get_data();
+    };
+
     $scope.getGroupByTagSegments = function(segment) {
     $scope.getGroupByTagSegments = function(segment) {
       var query = $scope.queryBuilder.buildExploreQuery('TAG_KEYS');
       var query = $scope.queryBuilder.buildExploreQuery('TAG_KEYS');