Browse Source

AMBARI-15940 Discard-button is active even there are no changes for configs. (ababiichuk)

ababiichuk 9 years ago
parent
commit
5d03b5288f

+ 33 - 38
ambari-web/app/models/configs/objects/service_config.js

@@ -38,17 +38,23 @@ App.ServiceConfig = Ember.Object.extend({
 
   errorCount: Em.computed.alias('configsWithErrors.length'),
 
-  visibleProperties: function() {
+  /**
+   * Properties for which some aggregations should be calculated
+   * like <code>configsWithErrors<code>, <code>changedConfigProperties<code> etc.
+   *
+   * @type {Object[]}
+   */
+  activeProperties: function() {
     return this.get('configs').filter(function(c) {
-      return c.get('isVisible') && !c.get('hiddenBySection');
+      return c.get('isVisible') && !c.get('hiddenBySection') && c.get('isRequiredByAgent');
     });
-  }.property('configs.@each.isVisible', 'configs.@each.hiddenBySection'),
+  }.property('configs.@each.isVisible', 'configs.@each.hiddenBySection', 'configs.@each.isRequiredByAgent'),
 
   configsWithErrors: function() {
-    return this.get('visibleProperties').filter(function(c) {
+    return this.get('activeProperties').filter(function(c) {
       return !c.get('isValid') || !c.get('isValidOverride');
     });
-  }.property('visibleProperties.@each.isValid', 'visibleProperties.@each.isValidOverride'),
+  }.property('activeProperties.@each.isValid', 'activeProperties.@each.isValidOverride'),
 
   observeErrors: function() {
     this.get('configCategories').setEach('errorCount', 0);
@@ -83,29 +89,6 @@ App.ServiceConfig = Ember.Object.extend({
       }
     });
   }.observes('configs.@each.isVisible'),
-  /**
-   * checks if for example for kdc_type, the value isn't just the pretty version of the saved value, for example mit-kdc
-   * and Existing MIT KDC are the same value, but they are interpreted as being changed. This function fixes that
-   * @param configs
-   * @returns {boolean} - checks
-   */
-  checkDefaultValues: function (configs) {
-    var kdcType = configs.findProperty('name', 'kdc_type');
-
-    if (!kdcType) {
-      return configs.someProperty('isNotDefaultValue')
-    }
-
-    // if there is only one value changed and that value is for kdc_type, check if the value has really changed or just
-    // the string shown to the user is different
-    if (configs.filterProperty('isNotDefaultValue').length === 1) {
-      if (configs.findProperty('isNotDefaultValue', true) === kdcType) {
-        return App.router.get('mainAdminKerberosController.kdcTypesValues')[kdcType.get('savedValue')] !== kdcType.get('value');
-      }
-    }
-
-    return configs.someProperty('isNotDefaultValue');
-  },
 
   /**
    * Collection of properties that were changed:
@@ -113,22 +96,34 @@ App.ServiceConfig = Ember.Object.extend({
    * for not saved properties (on wizards, for new services) use
    *    - <code>isNotInitialValue<code>
    * for added properties use - <code>isNotSaved<code>
+   * @type {Object[]}
    */
   changedConfigProperties: function() {
-    return this.get('configs').filter(function(c) {
+    return this.get('activeProperties').filter(function(c) {
       return c.get('isNotDefaultValue') || c.get('isNotSaved') || c.get('isNotInitialValue');
     }, this);
-  }.property('configs.@each.isNotDefaultValue', 'configs.@each.isNotSaved', 'configs.@each.isNotInitialValue'),
+  }.property('activeProperties.@each.isNotDefaultValue', 'activeProperties.@each.isNotSaved', 'activeProperties.@each.isNotInitialValue'),
+
+  /**
+   * Config with overrides that has values that differs from saved
+   *
+   * @type {Object[]}
+   */
+  configsWithChangedOverrides: Em.computed.filterBy('activeProperties', 'isOverrideChanged', true),
 
-  isPropertiesChanged: function() {
-    var requiredByAgent = this.get('configs').filterProperty('isRequiredByAgent');
-    var isNotSaved = requiredByAgent.someProperty('isNotSaved');
-    var isNotDefaultValue = this.checkDefaultValues(requiredByAgent);
-    var isOverrideChanged = requiredByAgent.someProperty('isOverrideChanged');
-    var differentConfigLengths = this.get('configs.length') !== this.get('initConfigsLength');
+  /**
+   * Defines if some configs were added/removed
+   * @type {boolean}
+   */
+  configsLengthWasChanged: Em.computed.notEqualProperties('configs.length', 'initConfigsLength'),
 
-    return  isNotSaved || isNotDefaultValue || isOverrideChanged || differentConfigLengths;
-  }.property('configs.@each.isNotDefaultValue', 'configs.@each.isOverrideChanged', 'configs.length', 'configs.@each.isNotSaved', 'initConfigsLength'),
+  /**
+   * @type {boolean}
+   */
+  isPropertiesChanged: Em.computed.or(
+    'configsLengthWasChanged',
+    'changedConfigProperties.length',
+    'configsWithChangedOverrides.length'),
 
   init: function() {
     this._super();

+ 12 - 6
ambari-web/app/models/configs/objects/service_config_property.js

@@ -245,7 +245,7 @@ App.ServiceConfigProperty = Em.Object.extend({
     if (Em.isNone(this.get('overrides')) && this.get('overrideValues.length') === 0) return false;
     return JSON.stringify(this.get('overrides').mapProperty('isFinal')) !== JSON.stringify(this.get('overrideIsFinalValues'))
       || JSON.stringify(this.get('overrides').mapProperty('value')) !== JSON.stringify(this.get('overrideValues'));
-  }.property('isOverridden', 'overrides.@each.isNotDefaultValue', 'overrideValues.length'),
+  }.property('overrides.@each.isNotDefaultValue', 'overrides.@each.overrideIsFinalValues', 'overrideValues.length'),
 
   isRemovable: function() {
     return this.get('isEditable') && this.get('isRequiredByAgent') && !(this.get('overrides.length') > 0)
@@ -271,13 +271,19 @@ App.ServiceConfigProperty = Em.Object.extend({
   /**
    * Indicates when value is not the default value.
    * Returns false when there is no default value.
+   *
+   * @type {boolean}
    */
   isNotDefaultValue: function () {
-    var value = this.get('value');
-    var savedValue = this.get('savedValue');
-    var supportsFinal = this.get('supportsFinal');
-    var isFinal = this.get('isFinal');
-    var savedIsFinal = this.get('savedIsFinal');
+    var value = this.get('value'),
+      savedValue = this.get('savedValue'),
+      supportsFinal = this.get('supportsFinal'),
+      isFinal = this.get('isFinal'),
+      savedIsFinal = this.get('savedIsFinal');
+
+    if (this.get('name') === 'kdc_type') {
+      return App.router.get('mainAdminKerberosController.kdcTypesValues')[savedValue] !== value;
+    }
     // ignore precision difference for configs with type of `float` which value may ends with 0
     // e.g. between 0.4 and 0.40
     if (this.get('stackConfigProperty') && this.get('stackConfigProperty.valueAttributes.type') == 'float') {

+ 6 - 2
ambari-web/app/utils/config.js

@@ -918,6 +918,8 @@ App.config = Em.Object.create({
 
     var newOverride = App.ServiceConfigProperty.create(serviceConfigProperty);
 
+    newOverride.setProperties({ 'savedValue': null, 'savedIsFinal': null });
+
     if (!Em.isNone(override)) {
       for (var key in override) {
         newOverride.set(key, override[key]);
@@ -937,8 +939,10 @@ App.config = Em.Object.create({
     configGroup.set('properties', configGroup.get('properties').concat(newOverride));
 
     serviceConfigProperty.get('overrides').pushObject(newOverride);
-    serviceConfigProperty.set('overrideValues', serviceConfigProperty.get('overrides').mapProperty('value'));
-    serviceConfigProperty.set('overrideIsFinalValues', serviceConfigProperty.get('overrides').mapProperty('isFinal'));
+
+    var savedOverrides = serviceConfigProperty.get('overrides').filterProperty('savedValue');
+    serviceConfigProperty.set('overrideValues', savedOverrides.mapProperty('savedValue'));
+    serviceConfigProperty.set('overrideIsFinalValues', savedOverrides.mapProperty('savedIsFinal'));
 
     newOverride.validate();
     return newOverride;

+ 16 - 3
ambari-web/test/models/configs/objects/service_config_test.js

@@ -26,6 +26,7 @@ var serviceConfig,
         'name': 'p1',
         'isVisible': true,
         'hiddenBySection': false,
+        'isRequiredByAgent': true,
         'isValid': true,
         'isValidOverride': true
       }),
@@ -33,6 +34,7 @@ var serviceConfig,
         'name': 'p2',
         'isVisible': false,
         'hiddenBySection': false,
+        'isRequiredByAgent': true,
         'isValid': true,
         'isValidOverride': true
       }),
@@ -40,6 +42,7 @@ var serviceConfig,
         'name': 'p3',
         'isVisible': true,
         'hiddenBySection': true,
+        'isRequiredByAgent': true,
         'isValid': true,
         'isValidOverride': true
       }),
@@ -47,6 +50,7 @@ var serviceConfig,
         'name': 'p4',
         'isVisible': true,
         'hiddenBySection': false,
+        'isRequiredByAgent': true,
         'isValid': false,
         'isValidOverride': true
       }),
@@ -54,9 +58,18 @@ var serviceConfig,
         'name': 'p5',
         'isVisible': true,
         'hiddenBySection': false,
+        'isRequiredByAgent': true,
         'isValid': true,
         'isValidOverride': false
-      })
+      }),
+    Em.Object.create({
+      'name': 'p6',
+      'isVisible': true,
+      'hiddenBySection': false,
+      'isRequiredByAgent': false,
+      'isValid': true,
+      'isValidOverride': false
+    })
   ];
 
 describe('App.ServiceConfig', function () {
@@ -67,9 +80,9 @@ describe('App.ServiceConfig', function () {
     });
   });
 
-  describe('#visibleProperties', function() {
+  describe('#activeProperties', function() {
     it('returns collection of properties that should be shown', function() {
-      expect(serviceConfig.get('visibleProperties').mapProperty('name')).to.be.eql(['p1','p4','p5']);
+      expect(serviceConfig.get('activeProperties').mapProperty('name')).to.be.eql(['p1','p4','p5']);
     });
   });
 

+ 7 - 3
ambari-web/test/utils/config_test.js

@@ -430,7 +430,11 @@ describe('App.config', function () {
     Object.keys(template).forEach(function (key) {
       it(key, function () {
         var override = App.config.createOverride(configProperty, {}, group);
-        expect(override.get(key)).to.equal(template[key]);
+        if (['savedValue', 'savedIsFinal'].contains(key)) {
+          expect(override.get(key)).to.equal(null);
+        } else {
+          expect(override.get(key)).to.equal(template[key]);
+        }
       });
     });
 
@@ -501,10 +505,10 @@ describe('App.config', function () {
         expect(configProperty.get('overrides')[0]).to.be.eql(override);
       });
       it('overrideValues is valid', function () {
-        expect(configProperty.get('overrideValues')).to.be.eql([overridenTemplate2.value]);
+        expect(configProperty.get('overrideValues')).to.be.eql([overridenTemplate2.savedValue]);
       });
       it('overrideIsFinalValues is valid', function () {
-        expect(configProperty.get('overrideIsFinalValues')).to.be.eql([overridenTemplate2.isFinal]);
+        expect(configProperty.get('overrideIsFinalValues')).to.be.eql([overridenTemplate2.savedIsFinal]);
       });
 
     });