Просмотр исходного кода

escape dimension if it is variable name

Mitsuhiro Tanda 10 лет назад
Родитель
Сommit
f1e5238e16

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

@@ -97,7 +97,7 @@
         <li class="tight-form-item" style="width: 100px">
           Dimensions
         </li>
-        <li ng-repeat="(key, value) in target.dimensions track by $index" class="tight-form-item">
+        <li ng-repeat="(key, value) in target.escapedDimensions track by $index" class="tight-form-item">
           {{key}}&nbsp;=&nbsp;{{value}}
           <a ng-click="removeDimension(key)">
             <i class="fa fa-remove"></i>

+ 16 - 0
public/app/plugins/datasource/cloudwatch/queryCtrl.js

@@ -13,6 +13,7 @@ function (angular, _) {
       $scope.target.namespace = $scope.target.namespace || '';
       $scope.target.metricName = $scope.target.metricName || '';
       $scope.target.dimensions = $scope.target.dimensions || {};
+      $scope.target.escapedDimensions = this.escapeDimensions($scope.target.dimensions);
       $scope.target.statistics = $scope.target.statistics || {};
       $scope.target.period = $scope.target.period || 60;
       $scope.target.region = $scope.target.region || $scope.datasource.getDefaultRegion();
@@ -94,6 +95,7 @@ function (angular, _) {
       }
 
       $scope.target.dimensions[$scope.target.currentDimensionKey] = $scope.target.currentDimensionValue;
+      $scope.target.escapedDimensions = this.escapeDimensions($scope.target.dimensions);
       $scope.target.currentDimensionKey = '';
       $scope.target.currentDimensionValue = '';
       $scope.refreshMetricData();
@@ -102,10 +104,24 @@ function (angular, _) {
     };
 
     $scope.removeDimension = function(key) {
+      key = key.replace(/\\\$/g, '$');
       delete $scope.target.dimensions[key];
+      $scope.target.escapedDimensions = this.escapeDimensions($scope.target.dimensions);
       $scope.refreshMetricData();
     };
 
+    $scope.escapeDimensions = function(d) {
+      var result = {};
+      _.chain(d)
+      .keys(d)
+      .each(function(k) {
+        var v = d[k];
+        result[k.replace(/\$/g, '\\$')] = v.replace(/\$/g, '\\$');
+      });
+
+      return result;
+    };
+
     $scope.statisticsOptionChanged = function() {
       $scope.refreshMetricData();
     };