Browse Source

AMBARI-11341. Configs: when defining an override for a property, it goes into "Edit" mode and cannot switch back to the normal mode (onechiporenko)

Oleg Nechiporenko 10 years ago
parent
commit
a2dcc044c7

+ 10 - 1
ambari-web/app/views/common/configs/widgets/config_widget_view.js

@@ -100,6 +100,15 @@ App.ConfigWidgetView = Em.View.extend(App.SupportsDependentConfigs, App.WidgetPo
    */
   isOriginalSCPBinding: 'config.isOriginalSCP',
 
+  /**
+   * Check if property validation failed for overridden property in case when its value is equal to parent
+   * config property.
+   * @type {boolean}
+   */
+  isOverrideEqualityError: function() {
+    return this.get('config.parentSCP') && this.get('config.parentSCP.value') == this.get('config.value');
+  }.property('config.isValid'),
+
   /**
    * Alias to <code>config.isComparison</code>
    * Should be used in the templates
@@ -384,7 +393,7 @@ App.ConfigWidgetView = Em.View.extend(App.SupportsDependentConfigs, App.WidgetPo
    * @returns {boolean}
    */
   isValueCompatibleWithWidget: function() {
-    return this.get('config.isValid');
+    return (this.get('isOverrideEqualityError') && !this.get('config.isValid')) || this.get('config.isValid');
   },
 
   /**

+ 93 - 0
ambari-web/test/views/common/configs/widgets/time_interval_spinner_view_test.js

@@ -294,4 +294,97 @@ describe('App.TimeIntervalSpinnerView', function () {
     });
   });
 
+  describe('#showAsTextBox', function() {
+    Em.A([
+      {
+        config: App.ServiceConfigProperty.create({
+          value: "600",
+          isValid: true,
+          stackConfigProperty: Em.Object.create({
+            widget: {
+              units: [
+                { unit: "hours,minutes" }
+              ]
+            },
+            valueAttributes: {type: "int", maximum: "86400", minimum: "600", unit: "seconds"}
+          })
+        }),
+        m: 'original config with valid value should be shown as widget',
+        e: false
+      },
+      {
+        config: App.ServiceConfigProperty.create({
+          value: "test",
+          isValid: true,
+          stackConfigProperty: Em.Object.create({
+            widget: {
+              units: [
+                { unit: "hours,minutes" }
+              ]
+            },
+            valueAttributes: {type: "int", maximum: "86400", minimum: "600", unit: "seconds"}
+          })
+        }),
+        m: 'original config with invalid value should be shown as textbox',
+        e: true
+      },
+      {
+        config: App.ServiceConfigProperty.create({
+          value: "600",
+          isValid: true,
+          stackConfigProperty: Em.Object.create({
+            widget: {
+              units: [
+                { unit: "hours,minutes" }
+              ]
+            },
+            valueAttributes: {type: "int", maximum: "86400", minimum: "600", unit: "seconds"}
+          }),
+          parentSCP: Em.Object.create({ value: "600" })
+        }),
+        m: 'overriden config have same value as original and values of both configs are valid, widget should be shown',
+        e: false
+      },
+      {
+        config: App.ServiceConfigProperty.create({
+          value: "test",
+          isValid: true,
+          stackConfigProperty: Em.Object.create({
+            widget: {
+              units: [
+                { unit: "hours,minutes" }
+              ]
+            },
+            valueAttributes: {type: "int", maximum: "86400", minimum: "600", unit: "seconds"}
+          }),
+          parentSCP: Em.Object.create({ value: "test" })
+        }),
+        m: 'overriden config have same value as original and values of both configs are NOT valid, textbox should be shown',
+        e: true
+      },
+      {
+        config: App.ServiceConfigProperty.create({
+          value: "test",
+          isValid: true,
+          stackConfigProperty: Em.Object.create({
+            widget: {
+              units: [
+                { unit: "hours,minutes" }
+              ]
+            },
+            valueAttributes: {type: "int", maximum: "86400", minimum: "600", unit: "seconds"}
+          }),
+          parentSCP: Em.Object.create({ value: "500" })
+        }),
+        m: 'overriden config have different value as original and values of override NOT valid, textbox should be shown',
+        e: true
+      }
+    ]).forEach(function (test) {
+      it(test.m, function() {
+        view.set('config', test.config);
+        view.didInsertElement();
+        expect(view.get('config.showAsTextBox')).to.eql(test.e);
+      });
+    });
+  });
 });