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-10521. Toggling 'ACID Transactions' config does not update depended_by configs (onechiporenko)
Date Thu, 16 Apr 2015 16:41:27 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk d3e647a90 -> 39306bf58


AMBARI-10521. Toggling 'ACID Transactions' config does not update depended_by configs (onechiporenko)


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

Branch: refs/heads/trunk
Commit: 39306bf5817070377e7206e0d6e6fd4b074a9813
Parents: d3e647a
Author: Oleg Nechiporenko <onechiporenko@apache.org>
Authored: Thu Apr 16 19:41:15 2015 +0300
Committer: Oleg Nechiporenko <onechiporenko@apache.org>
Committed: Thu Apr 16 19:41:15 2015 +0300

----------------------------------------------------------------------
 .../widgets/toggle_config_widget_view.js        | 25 ++++++++++++++++----
 .../widgets/toggle_config_widget_view_test.js   | 19 ++++++++-------
 2 files changed, 31 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/39306bf5/ambari-web/app/views/common/configs/widgets/toggle_config_widget_view.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/common/configs/widgets/toggle_config_widget_view.js b/ambari-web/app/views/common/configs/widgets/toggle_config_widget_view.js
index 8e002e3..059257b 100644
--- a/ambari-web/app/views/common/configs/widgets/toggle_config_widget_view.js
+++ b/ambari-web/app/views/common/configs/widgets/toggle_config_widget_view.js
@@ -44,23 +44,23 @@ App.ToggleConfigWidgetView = App.ConfigWidgetView.extend({
 
   /**
    * Update config value using <code>switcherValue</code>.
-   * switcherValue is boolean, but config value should be a string 'true'|'false'.
+   * switcherValue is boolean, but config value should be a string.
    *
    * @method updateConfigValue
    */
   updateConfigValue: function () {
-    this.set('config.value', '' + this.get('switcherValue'));
+    this.set('config.value', this.get('config.stackConfigProperty.valueAttributes.entries')[this.get('switcherValue')
? 0 : 1].value);
   },
 
   /**
    * Get value for <code>switcherValue</code> (boolean) using <code>config.value</code>
(string).
    *
    * @param configValue
-   * @returns {boolean} true for 'true', false for 'false'
+   * @returns {boolean}
    * @method getNewSwitcherValue
    */
   getNewSwitcherValue: function (configValue) {
-    return 'true' === configValue;
+    return this.get('config.stackConfigProperty.valueAttributes.entries')[0].value === ''
+ configValue;
   },
 
   didInsertElement: function () {
@@ -71,11 +71,25 @@ App.ToggleConfigWidgetView = App.ConfigWidgetView.extend({
       this.toggleWidgetState();
       this.initPopover();
     }.bind(this), 10);
-    this.addObserver('switcherValue', this.updateConfigValue);
+    this.addObserver('switcherValue', this, this.updateConfigValue);
     this._super();
   },
 
   /**
+   * Value may be changed after recommendations are received
+   * So, switcher should be updated too
+   *
+   * @method setValue
+   */
+  setValue: function (configValue) {
+    var value = this.getNewSwitcherValue(configValue);
+    if (this.get('switcherValue') !== value) {
+      this.get('switcher').bootstrapSwitch('toggleState', value);
+      this.set('switcherValue', value);
+    }
+  },
+
+  /**
    * Init switcher plugin.
    *
    * @method initSwitcher
@@ -83,6 +97,7 @@ App.ToggleConfigWidgetView = App.ConfigWidgetView.extend({
   initSwitcher: function () {
     var labels = this.get('config.stackConfigProperty.valueAttributes.entries'),
       self = this;
+    Em.assert('toggle for `' + this.get('config.name') + '` should contain two entries',
labels.length === 2);
     if (this.$()) {
       var switcher = this.$("input").bootstrapSwitch({
         onText: labels[0].label,

http://git-wip-us.apache.org/repos/asf/ambari/blob/39306bf5/ambari-web/test/views/common/configs/widgets/toggle_config_widget_view_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/views/common/configs/widgets/toggle_config_widget_view_test.js
b/ambari-web/test/views/common/configs/widgets/toggle_config_widget_view_test.js
index d048472..98e974b 100644
--- a/ambari-web/test/views/common/configs/widgets/toggle_config_widget_view_test.js
+++ b/ambari-web/test/views/common/configs/widgets/toggle_config_widget_view_test.js
@@ -27,13 +27,16 @@ describe('App.ToggleConfigWidgetView', function () {
       initPopover: Em.K,
       config: Em.Object.create({
         name: 'a.b.c',
-        value: 'true',
-        defaultValue: 'true',
+        value: 'active',
+        defaultValue: 'active',
         stackConfigProperty: Em.Object.create({
           valueAttributes: {
             "type": "value-list",
-            "entries": ["true", "false"],
-            "entry_labels": ["Active", "Inactive"],
+            "entries":
+              [
+                {value: "active", label: "Active"},
+                {value: "inactive", label: "Inactive"}
+              ],
             "entries_editable": "false",
             "selection_cardinality": 1
           }
@@ -51,8 +54,8 @@ describe('App.ToggleConfigWidgetView', function () {
   describe('#getNewSwitcherValue', function () {
 
     it('should represent string value to boolean', function () {
-      expect(this.view.getNewSwitcherValue('false')).to.be.false;
-      expect(this.view.getNewSwitcherValue('true')).to.be.true;
+      expect(this.view.getNewSwitcherValue('inactive')).to.be.false;
+      expect(this.view.getNewSwitcherValue('active')).to.be.true;
     });
 
   });
@@ -61,9 +64,9 @@ describe('App.ToggleConfigWidgetView', function () {
 
     it('should represent boolean value to string', function () {
       this.view.set('switcherValue', false);
-      expect(this.view.get('config.value')).to.equal('false');
+      expect(this.view.get('config.value')).to.equal('inactive');
       this.view.set('switcherValue', true);
-      expect(this.view.get('config.value')).to.equal('true');
+      expect(this.view.get('config.value')).to.equal('active');
     });
 
   });


Mime
View raw message