Prechádzať zdrojové kódy

AMBARI-10601 Going to HBase enhanced configs page causes config change. (ababiichuk)

aBabiichuk 10 rokov pred
rodič
commit
b1d9cf98bc

+ 27 - 3
ambari-web/app/utils/config.js

@@ -307,11 +307,11 @@ App.config = Em.Object.create({
         if (!configsPropertyDef) {
           configsPropertyDef = advancedConfig;
         }
-
+        var value = this.parseValue(properties[index], configsPropertyDef, advancedConfig);
         var serviceConfigObj = App.ServiceConfig.create({
           name: index,
-          value: properties[index],
-          defaultValue: properties[index],
+          value: value,
+          defaultValue: value,
           filename: filename,
           isUserProperty: !advancedConfig,
           isVisible: !!service,
@@ -370,6 +370,30 @@ App.config = Em.Object.create({
     }
   },
 
+  /**
+   * additional parsing when value is int of float
+   * ex: if value is "0.40" result will be "0.4"
+   * @param value
+   * @param predefinedConfig
+   * @param advancedConfig
+   * @returns {String}
+   */
+  parseValue: function(value, predefinedConfig, advancedConfig) {
+    var type = predefinedConfig ? Em.get(predefinedConfig, 'displayType') :
+      advancedConfig && Em.get(advancedConfig, 'valueAttributes.type');
+    switch (type) {
+      case 'int':
+        var res = parseInt(value);
+        return Number.isNaN(res) ? "" : res.toString();
+      case 'float':
+        var res = parseFloat(value);
+        return Number.isNaN(res) ? "" : res.toString();
+      default:
+        return value;
+    }
+  },
+
+
   tweakConfigVisibility: function (config, allSiteConfigs) {
     var kdcType = allSiteConfigs['kdc_type'];
     if (kdcType === 'active-directory' && ['container_dn', 'ldap_url'].contains(Em.get(config, 'name'))) {

+ 2 - 0
ambari-web/test/utils/config_test.js

@@ -607,6 +607,7 @@ describe('App.config', function () {
     var result;
 
     before(function() {
+      sinon.stub(App.config, 'parseValue', function(value) {return value});
       setups.setupStackVersion(this, 'HDP-2.2');
       loadServiceModelsData(['HDFS', 'STORM']);
       App.config.loadAdvancedConfigSuccess(modelSetup.advancedConfigs, { url: '/serviceName/configurations'}, {
@@ -629,6 +630,7 @@ describe('App.config', function () {
     });
 
     after(function() {
+      App.config.parseValue.restore();
       setups.restoreStackVersion(this);
       removeServiceModelData(['HDFS', 'STORM']);
     });