Browse Source

AMBARI-8956. Alerts UI: Wrong values of percent thresholds is shown. (akovalenko)

Aleksandr Kovalenko 10 years ago
parent
commit
e8e1e34021

+ 2 - 2
ambari-web/app/controllers/main/alerts/definition_configs_controller.js

@@ -138,7 +138,7 @@ App.MainAlertDefinitionConfigsController = Em.Controller.extend({
     }
 
     configs.setEach('isDisabled', !this.get('canEdit'));
-    configs.setEach('allConfigs', configs);
+    configs.setEach('configsController', this);
 
     this.set('configs', configs);
   },
@@ -497,7 +497,7 @@ App.MainAlertDefinitionConfigsController = Em.Controller.extend({
       var largeValue = Em.get(this.get('configs').findProperty('name', 'critical_threshold'), 'value');
       var largeValid = Em.get(this.get('configs').findProperty('name', 'critical_threshold'), 'isValid');
     }
-    return smallValid && largeValid ? !(smallValue <= largeValue) : false;
+    return smallValid && largeValid ? Number(smallValue) > Number(largeValue) : false;
   }.property('configs.@each.value'),
 
   /**

+ 12 - 12
ambari-web/app/models/alert_config.js

@@ -152,12 +152,12 @@ App.AlertConfigProperty = Ember.Object.extend({
   }.property(),
 
   /**
-   * Array of a group of configs, that current config property relates to
+   * Configs controller
    * Should be set in controller in rendering configs function
-   * Used to get access to other configs properties of one group
-   * @type {App.AlertConfigProperty[]}
+   * Used to get access to other configs properties of one group or definition properties
+   * @type {App.MainAlertDefinitionConfigsController}
    */
-  allConfigs: []
+  configsController: null
 
 });
 
@@ -348,26 +348,26 @@ App.AlertConfigProperties = {
       var valueMetric = this.get('valueMetric');
       var displayValue = this.get('displayValue');
       var newDisplayValue = value;
-      if (value && '%' == valueMetric && !isNaN(value)) {
+      if (value && '%' == valueMetric && !isNaN(value) && this.get('configsController.content.type') == 'AGGREGATE') {
         newDisplayValue = (Number(value) * 100) + '';
       }
       if (newDisplayValue != displayValue) {
         this.set('displayValue', newDisplayValue);
       }
-    }.observes('value', 'valueMetric'),
+    }.observes('value', 'valueMetric', 'configsController.content.type'),
 
     displayValueWasChanged: function () {
       var value = this.get('value');
       var valueMetric = this.get('valueMetric');
       var displayValue = this.get('displayValue');
       var newValue = displayValue;
-      if (displayValue && '%' == valueMetric && !isNaN(displayValue)) {
+      if (displayValue && '%' == valueMetric && !isNaN(displayValue) && this.get('configsController.content.type') == 'AGGREGATE') {
         newValue = (Number(displayValue) / 100) + '';
       }
       if (newValue != value) {
         this.set('value', newValue);
       }
-    }.observes('displayValue', 'valueMetric')
+    }.observes('displayValue', 'valueMetric', 'configsController.content.type')
 
   }),
 
@@ -466,14 +466,14 @@ App.AlertConfigProperties.Thresholds = {
       var value = this.get('value');
       if (!value) return false;
       value = ('' + value).trim();
-      if (this.get('showInputForValue') && this.get('valueMetric') == '%') {
+      if (this.get('showInputForValue') && this.get('valueMetric') == '%' && this.get('configsController.content.type') == 'AGGREGATE') {
         return !isNaN(value) && value > 0 && value <= 1.0;
       } else if (this.get('showInputForValue')) {
         return !isNaN(value) && value > 0;
       } else {
         return true;
       }
-    }.property('value', 'showInputForValue')
+    }.property('value', 'showInputForValue', 'configsController.content.type')
   }),
 
   CriticalThreshold: App.AlertConfigProperties.Threshold.extend({
@@ -493,14 +493,14 @@ App.AlertConfigProperties.Thresholds = {
       var value = this.get('value');
       if (!value) return false;
       value = ('' + value).trim();
-      if (this.get('showInputForValue') && this.get('valueMetric') == '%') {
+      if (this.get('showInputForValue') && this.get('valueMetric') == '%' && this.get('configsController.content.type') == 'AGGREGATE') {
         return !isNaN(value) && value > 0 && value <= 1.0;
       } else if (this.get('showInputForValue')) {
         return !isNaN(value) && value > 0;
       } else {
         return true;
       }
-    }.property('value', 'showInputForValue')
+    }.property('value', 'showInputForValue', 'configsController.content.type')
   })
 
 };

+ 13 - 2
ambari-web/test/models/alert_config_test.js

@@ -54,11 +54,16 @@ describe('App.AlertConfigProperties', function () {
 
     describe('#valueWasChanged', function () {
 
-      it('value change should effect displayValue', function () {
+      it('value change should effect displayValue for AGGREGATE type', function () {
 
         model = App.AlertConfigProperties.Threshold.create({
           value: '0.4',
           valueMetric: '%',
+          configsController: Em.Object.create({
+            content: {
+              type: 'AGGREGATE'
+            }
+          }),
           text: 'text',
           showInputForValue: false,
           showInputForText: false
@@ -67,10 +72,16 @@ describe('App.AlertConfigProperties', function () {
         expect(model.get('displayValue')).to.eql('40');
       });
 
-      it('value change should not effect displayValue', function () {
+      it('value change should not effect displayValue for not AGGREGATE type', function () {
 
         model = App.AlertConfigProperties.Threshold.create({
           value: '0.4',
+          valueMetric: '%',
+          configsController: Em.Object.create({
+            content: {
+              type: 'SCRIPT'
+            }
+          }),
           text: 'text',
           showInputForValue: false,
           showInputForText: false