ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ababiic...@apache.org
Subject ambari git commit: AMBARI-17497 Add validation check on UI based on minimum and maximum set for LLAP 'textbox' configs. (ababiichuk)
Date Mon, 11 Jul 2016 10:45:53 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk dcefe3902 -> a377f74f2


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


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/a377f74f
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/a377f74f
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/a377f74f

Branch: refs/heads/trunk
Commit: a377f74f27c835eac0dc2f6ad5a8d0a6780fc9e9
Parents: dcefe39
Author: ababiichuk <ababiichuk@hortonworks.com>
Authored: Mon Jul 11 13:19:03 2016 +0300
Committer: ababiichuk <ababiichuk@hortonworks.com>
Committed: Mon Jul 11 13:35:43 2016 +0300

----------------------------------------------------------------------
 .../configs/objects/service_config_property.js  | 16 ++++++---
 ambari-web/app/utils/config.js                  | 35 ++++++++++++++++++--
 .../widgets/list_config_widget_view_test.js     |  1 +
 .../widgets/slider_config_widget_view_test.js   |  1 +
 4 files changed, 47 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/a377f74f/ambari-web/app/models/configs/objects/service_config_property.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/models/configs/objects/service_config_property.js b/ambari-web/app/models/configs/objects/service_config_property.js
index 861d599..844806f 100644
--- a/ambari-web/app/models/configs/objects/service_config_property.js
+++ b/ambari-web/app/models/configs/objects/service_config_property.js
@@ -270,7 +270,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();
   },
 
@@ -345,16 +346,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

http://git-wip-us.apache.org/repos/asf/ambari/blob/a377f74f/ambari-web/app/utils/config.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/utils/config.js b/ambari-web/app/utils/config.js
index 6c6e7f6..dcdb236 100644
--- a/ambari-web/app/utils/config.js
+++ b/ambari-web/app/utils/config.js
@@ -560,12 +560,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':
@@ -627,6 +627,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
    *
    * @param {string} name

http://git-wip-us.apache.org/repos/asf/ambari/blob/a377f74f/ambari-web/test/views/common/configs/widgets/list_config_widget_view_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/views/common/configs/widgets/list_config_widget_view_test.js
b/ambari-web/test/views/common/configs/widgets/list_config_widget_view_test.js
index 66f9d09..84db9b1 100644
--- a/ambari-web/test/views/common/configs/widgets/list_config_widget_view_test.js
+++ b/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: [

http://git-wip-us.apache.org/repos/asf/ambari/blob/a377f74f/ambari-web/test/views/common/configs/widgets/slider_config_widget_view_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/views/common/configs/widgets/slider_config_widget_view_test.js
b/ambari-web/test/views/common/configs/widgets/slider_config_widget_view_test.js
index 86f9431..a6b25ce 100644
--- a/ambari-web/test/views/common/configs/widgets/slider_config_widget_view_test.js
+++ b/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');
       });


Mime
View raw message