Browse Source

AMBARI-17497 Add validation check on UI based on minimum and maximum set for LLAP 'textbox' configs. (ababiichuk)

ababiichuk 9 years ago
parent
commit
5c41942535

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

@@ -271,7 +271,8 @@ App.ServiceConfigProperty = Em.Object.extend({
   init: function () {
     this.setInitialValues();
     this.set('viewClass', App.config.getViewClass(this.get("displayType"), this.get('dependentConfigPattern'), this.get('unit')));
-    this.set('validator', App.config.getValidator(this.get("displayType")));
+    this.set('validateErrors', App.config.getErrorValidator(this.get("displayType")));
+    this.set('validateWarnings', App.config.getWarningValidator(this.get("displayType")));
     this.validate();
   },
 
@@ -350,16 +351,23 @@ App.ServiceConfigProperty = Em.Object.extend({
         this.set('warnMessage', Em.I18n.t('config.warnMessage.llap_queue_capacity.max'));
       } else {
         this.set('warnMessage', '');
-        this.set('errorMessage', this.validator(this.get('value'), this.get('name'), this.get('retypedPassword')));
+        this.set('errorMessage', this.validateErrors(this.get('value'), this.get('name'), this.get('retypedPassword')));
       }
     } else {
-      this.set('errorMessage', this.validator(this.get('value'), this.get('name'), this.get('retypedPassword')));
+      this.set('errorMessage', this.validateErrors(this.get('value'), this.get('name'), this.get('retypedPassword')));
+    }
+    if (!this.get('widgetType') || ('text-field' === this.get('widgetType'))) {
+      //temp conditions, since other warnings are calculated directly in widget view
+      this.set('warnMessage', this.validateWarnings(this.get('value'), this.get('name'), this.get('filename'),
+        this.get('stackConfigProperty'), this.get('unit')));
     }
   }.observes('value', 'retypedPassword', 'isEditable'),
 
   viewClass: App.ServiceConfigTextField,
 
-  validator: function() { return '' },
+  validateErrors: function() { return '' },
+
+  validateWarnings: function() { return '' },
 
   /**
    * Get override for selected group

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

@@ -565,12 +565,12 @@ App.config = Em.Object.create({
   },
 
   /**
-   * Returns validator function based on config type
+   * Returns error validator function based on config type
    *
    * @param displayType
    * @returns {Function}
    */
-  getValidator: function (displayType) {
+  getErrorValidator: function (displayType) {
     switch (displayType) {
       case 'checkbox':
       case 'custom':
@@ -631,6 +631,37 @@ App.config = Em.Object.create({
     }
   },
 
+  /**
+   * Returns warning validator function based on config type
+   *
+   * @param displayType
+   * @returns {Function}
+   */
+  getWarningValidator: function(displayType) {
+    switch (displayType) {
+      case 'int':
+      case 'float':
+        return function (value, name, filename, stackConfigProperty, unitLabel) {
+          stackConfigProperty = stackConfigProperty || App.configsCollection.getConfigByName(name, filename);
+          var maximum = Em.get(stackConfigProperty || {}, 'valueAttributes.maximum'),
+            minimum = Em.get(stackConfigProperty || {}, 'valueAttributes.minimum'),
+            min = validator.isValidFloat(minimum) ? parseFloat(minimum) : NaN,
+            max = validator.isValidFloat(maximum) ? parseFloat(maximum) : NaN,
+            val = validator.isValidFloat(value) ? parseFloat(value) : NaN;
+
+          if (!isNaN(val) && !isNaN(max) && val > max) {
+            return Em.I18n.t('config.warnMessage.outOfBoundaries.greater').format(max + unitLabel);
+          }
+          if (!isNaN(val) && !isNaN(min) && val < min) {
+            return Em.I18n.t('config.warnMessage.outOfBoundaries.less').format(min + unitLabel);
+          }
+          return '';
+        };
+      default:
+        return function () { return ''; }
+    }
+  },
+
   /**
    * Defines if config support heterogeneous devices
    *

+ 1 - 0
ambari-web/test/views/common/configs/widgets/list_config_widget_view_test.js

@@ -34,6 +34,7 @@ describe('App.ListConfigWidgetView', function () {
         filename: 'f1',
         isFinal: false,
         supportsFinal: true,
+        widgetType: 'list-widget',
         stackConfigProperty: Em.Object.create({
           valueAttributes: {
             entries: [

+ 1 - 0
ambari-web/test/views/common/configs/widgets/slider_config_widget_view_test.js

@@ -645,6 +645,7 @@ describe('App.SliderConfigWidgetView', function () {
         viewInt.set('config.value', '100');
         viewInt.set('config.errorMessage', '');
         viewInt.set('config.warnMessage', '');
+        viewInt.set('config.widgetType', 'slider');
         assert.isTrue(viewInt.isValueCompatibleWithWidget(), 'value should be compatible with widget');
         assert.equal(viewInt.get('config.warnMessage'), Em.I18n.t('config.warnMessage.llap_queue_capacity.max'), 'warn message validation');
       });