ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From onechipore...@apache.org
Subject ambari git commit: AMBARI-10234. Widgets validation rules should affect config internal valid/invalid state (onechiporenko)
Date Fri, 27 Mar 2015 12:35:13 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 3937b6f7a -> 589faa74a


AMBARI-10234. Widgets validation rules should affect config internal valid/invalid state (onechiporenko)


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

Branch: refs/heads/trunk
Commit: 589faa74a9eb7a521ce2e601895d11bc4ad93743
Parents: 3937b6f
Author: Oleg Nechiporenko <onechiporenko@apache.org>
Authored: Fri Mar 27 14:30:50 2015 +0200
Committer: Oleg Nechiporenko <onechiporenko@apache.org>
Committed: Fri Mar 27 14:30:50 2015 +0200

----------------------------------------------------------------------
 .../configs/widgets/list_config_widget_view.js      | 16 +++++++++++++---
 .../configs/widgets/slider_config_widget_view.js    |  3 +++
 .../configs/widgets/time_interval_spinner_view.js   |  7 +++++--
 .../configs/widgets/list_config_widget_view_test.js | 16 ++++++++++++++++
 .../widgets/slider_config_widget_view_test.js       |  4 ++++
 .../widgets/time_interval_spinner_view_test.js      |  4 +++-
 6 files changed, 44 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/589faa74/ambari-web/app/views/common/configs/widgets/list_config_widget_view.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/common/configs/widgets/list_config_widget_view.js b/ambari-web/app/views/common/configs/widgets/list_config_widget_view.js
index 770f746..bd79501 100644
--- a/ambari-web/app/views/common/configs/widgets/list_config_widget_view.js
+++ b/ambari-web/app/views/common/configs/widgets/list_config_widget_view.js
@@ -98,6 +98,12 @@ App.ListConfigWidgetView = App.ConfigWidgetView.extend({
    */
   allowedToSelect: 1,
 
+  /**
+   * Minimum number of options needed to select (based on <code>config.valueAttributes.selection_cardinality</code>)
+   * @type {number}
+   */
+  neededToSelect: 0,
+
   templateName: require('templates/common/configs/widgets/list_config_widget'),
 
   willInsertElement: function () {
@@ -177,24 +183,28 @@ App.ListConfigWidgetView = App.ConfigWidgetView.extend({
 
   /**
    * If user already selected maximum of allowed options, disable other options
+   * If user selected less than minimum of needed options, mark config.value as invalid
    * If user deselect some option, all disabled options become enabled
    * Triggers on each option select/deselect
    * @method checkSelectedItemsCount
    */
   checkSelectedItemsCount: function () {
     var allowedToSelect = this.get('allowedToSelect'),
+      neededToSelect = this.get('neededToSelect'),
       currentlySelected = this.get('options').filterProperty('isSelected').length,
       selectionDisabled = allowedToSelect <= currentlySelected;
     this.get('options').filterProperty('isSelected', false).setEach('isDisabled', selectionDisabled);
+    this.set('config.errorMessage', currentlySelected < neededToSelect ? 'You should select
at least ' + neededToSelect + ' item(s)' : '');
   },
 
   /**
-   * Get maximum number of options allowed to select basing on config cardinality value
+   * Get maximum number of options allowed to select and needed to select basing on config
cardinality value
    * @method parseCardinality
    */
   parseCardinality: function () {
-    var cardinality = numberUtils.getCardinalityValue(this.get('config.stackConfigProperty.valueAttributes.selection_cardinality'),
true);
-    this.set('allowedToSelect', cardinality);
+    var cardinality = this.get('config.stackConfigProperty.valueAttributes.selection_cardinality');
+    this.set('allowedToSelect', numberUtils.getCardinalityValue(cardinality, true));
+    this.set('neededToSelect', numberUtils.getCardinalityValue(cardinality, false));
   },
 
   /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/589faa74/ambari-web/app/views/common/configs/widgets/slider_config_widget_view.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/common/configs/widgets/slider_config_widget_view.js b/ambari-web/app/views/common/configs/widgets/slider_config_widget_view.js
index 58be1e2..118f50f 100644
--- a/ambari-web/app/views/common/configs/widgets/slider_config_widget_view.js
+++ b/ambari-web/app/views/common/configs/widgets/slider_config_widget_view.js
@@ -111,6 +111,7 @@ App.SliderConfigWidgetView = App.ConfigWidgetView.extend({
       var parsed = parseFunction(mirrorValue);
       if (parsed >= min && parsed <= max) {
         this.set('isMirrorValueValid', true);
+        this.set('config.errorMessage', '');
         this.set('config.value', '' + parsed);
         if (slider) {
           slider.setValue(parsed);
@@ -118,10 +119,12 @@ App.SliderConfigWidgetView = App.ConfigWidgetView.extend({
       }
       else {
         this.set('isMirrorValueValid', false);
+        this.set('config.errorMessage', 'Invalid value');
       }
     }
     else {
       this.set('isMirrorValueValid', false);
+      this.set('config.errorMessage', 'Invalid value');
     }
   },
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/589faa74/ambari-web/app/views/common/configs/widgets/time_interval_spinner_view.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/common/configs/widgets/time_interval_spinner_view.js b/ambari-web/app/views/common/configs/widgets/time_interval_spinner_view.js
index 83881e1..d76e698 100644
--- a/ambari-web/app/views/common/configs/widgets/time_interval_spinner_view.js
+++ b/ambari-web/app/views/common/configs/widgets/time_interval_spinner_view.js
@@ -251,8 +251,11 @@ App.TimeIntervalSpinnerView = App.ConfigWidgetView.extend({
     else if (convertedValue > parseInt(this.get('config.stackConfigProperty.valueAttributes.maximum')))
{
       errorMessage = Em.I18n.t('number.validate.moreThanMaximum').format(this.dateToText(this.get('maxValue')));
     }
-    this.set('isValid', !errorMessage);
-    this.set('errorMessage', errorMessage);
+    this.setProperties({
+      isValid: !errorMessage,
+      errorMessage: errorMessage
+    });
+    this.get('config').set('errorMessage', errorMessage);
   },
 
   /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/589faa74/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 62d8ec1..4e7fb81 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
@@ -138,4 +138,20 @@ describe('App.ListConfigWidgetView', function () {
 
   });
 
+  describe('#checkSelectedItemsCount', function () {
+
+    beforeEach(function () {
+      view.set('config.stackConfigProperty.valueAttributes.selection_cardinality', '1+');
+      view.parseCardinality();
+    });
+
+    it('should check minimum count of the selected items', function () {
+      view.get('options').setEach('isSelected', false);
+      expect(view.get('config.errorMessage')).to.have.property('length').that.is.least(1);
+      view.get('options').setEach('isSelected', true);
+      expect(view.get('config.errorMessage')).to.equal('');
+    });
+
+  });
+
 });

http://git-wip-us.apache.org/repos/asf/ambari/blob/589faa74/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 4a25ddf..34a254f 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
@@ -86,20 +86,24 @@ describe('App.SliderConfigWidgetView', function () {
       viewInt.set('mirrorValue', 1000);
       expect(viewInt.get('isMirrorValueValid')).to.be.true;
       expect(viewInt.get('config.value')).to.equal('1000');
+      expect(viewInt.get('config.errorMessage')).to.equal('');
 
       viewInt.set('mirrorValue', 100500);
       expect(viewInt.get('isMirrorValueValid')).to.be.false;
       expect(viewInt.get('config.value')).to.equal('1000');
+      expect(viewInt.get('config.errorMessage')).to.have.property('length').that.is.least(1);
     });
 
     it('check float', function () {
       viewFloat.set('mirrorValue', 55.5);
       expect(viewFloat.get('isMirrorValueValid')).to.be.true;
       expect(viewFloat.get('config.value')).to.equal('55.5');
+      expect(viewFloat.get('config.errorMessage')).to.equal('');
 
       viewFloat.set('mirrorValue', 100500.5);
       expect(viewFloat.get('isMirrorValueValid')).to.be.false;
       expect(viewFloat.get('config.value')).to.equal('55.5');
+      expect(viewFloat.get('config.errorMessage')).to.have.property('length').that.is.least(1);
     });
 
   });

http://git-wip-us.apache.org/repos/asf/ambari/blob/589faa74/ambari-web/test/views/common/configs/widgets/time_interval_spinner_view_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/views/common/configs/widgets/time_interval_spinner_view_test.js
b/ambari-web/test/views/common/configs/widgets/time_interval_spinner_view_test.js
index c238709..c7a4486 100644
--- a/ambari-web/test/views/common/configs/widgets/time_interval_spinner_view_test.js
+++ b/ambari-web/test/views/common/configs/widgets/time_interval_spinner_view_test.js
@@ -19,6 +19,7 @@
 var App = require('app');
 
 describe('App.TimeIntervalSpinnerView', function() {
+
   describe('#convertToWidgetUnits', function(){
     beforeEach(function() {
       this.view = App.TimeIntervalSpinnerView.create({});
@@ -86,7 +87,7 @@ describe('App.TimeIntervalSpinnerView', function() {
         inputType: 'hours',
         desiredUnits: "hours",
         e: [
-          { label: 'Hours', value: 2},
+          { label: 'Hours', value: 2}
         ]
       }
     ];
@@ -139,4 +140,5 @@ describe('App.TimeIntervalSpinnerView', function() {
       });
     });
   });
+
 });


Mime
View raw message