You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by yu...@apache.org on 2013/11/20 01:01:11 UTC

git commit: AMBARI-3730. Create user 'Settings' option on user dropdown menu. (xiwang via yusaku)

Updated Branches:
  refs/heads/trunk 15d4ebdef -> a0af1dbfe


AMBARI-3730. Create user 'Settings' option on user dropdown menu. (xiwang via yusaku)


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

Branch: refs/heads/trunk
Commit: a0af1dbfe97aea154cabcd1a41e32b210e650900
Parents: 15d4ebd
Author: Yusaku Sako <yu...@hortonworks.com>
Authored: Tue Nov 19 16:01:09 2013 -0800
Committer: Yusaku Sako <yu...@hortonworks.com>
Committed: Tue Nov 19 16:01:09 2013 -0800

----------------------------------------------------------------------
 ambari-web/app/controllers/application.js       | 146 +++++++++----------
 .../global/background_operations_controller.js  |  21 +--
 ambari-web/app/controllers/main/host/details.js |  65 ++++++---
 ambari-web/app/controllers/main/service.js      |  11 +-
 ambari-web/app/controllers/main/service/item.js |  36 +++--
 ambari-web/app/utils/ajax.js                    |  19 +++
 ambari-web/app/utils/host_progress_popup.js     |   1 -
 7 files changed, 176 insertions(+), 123 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/a0af1dbf/ambari-web/app/controllers/application.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/application.js b/ambari-web/app/controllers/application.js
index 1b41900..705c29d 100644
--- a/ambari-web/app/controllers/application.js
+++ b/ambari-web/app/controllers/application.js
@@ -41,104 +41,100 @@ App.ApplicationController = Em.Controller.extend({
     this._super();
   },
 
-  loadShowBgChecked: function () {
-    if (App.testMode) {
-      return true;
-    } else {
-      this.getUserPref(this.persistKey());
-      var currentPrefObject = this.get('currentPrefObject');
-      if (currentPrefObject != null) {
-        return currentPrefObject;
-      } else {
-        // post persist
-        this.postUserPref(this.persistKey(), true);
-        return true;
-      }
-    }
+  dataLoading: function () {
+    var dfd = $.Deferred();
+    var self = this;
+    this.getUserPref(this.persistKey()).done(function () {
+      var curPref = self.get('currentPrefObject');
+      self.set('currentPrefObject', null);
+      dfd.resolve(curPref);
+    });
+    return dfd.promise();
   },
   persistKey: function () {
     var loginName = App.router.get('loginName');
     return 'admin-settings-show-bg-' + loginName;
   },
   currentPrefObject: null,
+
   /**
    * get persist value from server with persistKey
    */
-  getUserPref: function (key) {
-    var self = this;
-    var url = App.apiPrefix + '/persist/' + key;
-    jQuery.ajax(
-      {
-        url: url,
-        context: this,
-        async: false,
-        success: function (response) {
-          if (response) {
-            var value = jQuery.parseJSON(response);
-            console.log('Got persist value from server with key: ' + key + '. Value is: ' + response);
-            self.set('currentPrefObject', value);
-            return value;
-          }
-        },
-        error: function (xhr) {
-          // this user is first time login
-          if (xhr.status == 404) {
-            console.log('Persist did NOT find the key: '+ key);
-            self.set('currentPrefObject', null);
-            return null;
-          }
-        },
-        statusCode: require('data/statusCodes')
-      }
-    );
+  getUserPref: function(key){
+    return App.ajax.send({
+      name: 'settings.get.user_pref',
+      sender: this,
+      data: {
+        key: key
+      },
+      success: 'getUserPrefSuccessCallback',
+        error: 'getUserPrefErrorCallback'
+    });
+  },
+  getUserPrefSuccessCallback: function (response, request, data) {
+    if (response != null) {
+      console.log('Got persist value from server with key ' + data.key + '. Value is: ' + response);
+      this.set('currentPrefObject', response);
+      return response;
+    }
+  },
+  getUserPrefErrorCallback: function (request, ajaxOptions, error) {
+    // this user is first time login
+    if (request.status == 404) {
+      console.log('Persist did NOT find the key');
+      this.set('currentPrefObject', true);
+      this.postUserPref(this.persistKey(), true);
+      return true;
+    }
   },
   /**
    * post persist key/value to server, value is object
    */
   postUserPref: function (key, value) {
-    var url = App.apiPrefix + '/persist/';
     var keyValuePair = {};
     keyValuePair[key] = JSON.stringify(value);
-    jQuery.ajax({
-      async: false,
-      context: this,
-      type: "POST",
-      url: url,
-      data: JSON.stringify(keyValuePair),
-      beforeSend: function () {
-        console.log('BeforeSend to persist: persistKeyValues', keyValuePair);
+    App.ajax.send({
+      'name': 'settings.post.user_pref',
+      'sender': this,
+      'beforeSend': 'postUserPrefBeforeSend',
+      'data': {
+        'keyValuePair': keyValuePair
       }
     });
   },
+  postUserPrefBeforeSend: function(request, ajaxOptions, data){
+    console.log('BeforeSend to persist: persistKeyValues', data.keyValuePair);
+  },
+
   showSettingsPopup: function() {
     var self = this;
-    var initValue = this.loadShowBgChecked();
     var curValue = null;
-    App.ModalPopup.show({
-      header: Em.I18n.t('common.userSettings'),
-      bodyClass: Em.View.extend({
-        templateName: require('templates/common/settings'),
-        isShowBgChecked: initValue,
-        updateValue: function () {
-          curValue = this.get('isShowBgChecked');
-        }.observes('isShowBgChecked')
-      }),
-      primary: Em.I18n.t('common.save'),
-      onPrimary: function() {
-        if (curValue == null) {
-          curValue = initValue;
-        }
-        var key = self.persistKey();
-        if (!App.testMode) {
-          self.postUserPref(key, curValue);
+    this.dataLoading().done(function (initValue) {
+      App.ModalPopup.show({
+        header: Em.I18n.t('common.userSettings'),
+        bodyClass: Em.View.extend({
+          templateName: require('templates/common/settings'),
+          isShowBgChecked: initValue,
+          updateValue: function () {
+            curValue = this.get('isShowBgChecked');
+          }.observes('isShowBgChecked')
+        }),
+        primary: Em.I18n.t('common.save'),
+        onPrimary: function() {
+          if (curValue == null) {
+            curValue = initValue;
+          }
+          var key = self.persistKey();
+          if (!App.testMode) {
+            self.postUserPref(key, curValue);
+          }
+          this.hide();
+        },
+        onSecondary: function() {
+          this.hide();
         }
-        this.hide();
-      },
-      onSecondary: function() {
-        this.hide();
-      }
-    })
+      })
+    });
   }
 
-
 });
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/a0af1dbf/ambari-web/app/controllers/global/background_operations_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/global/background_operations_controller.js b/ambari-web/app/controllers/global/background_operations_controller.js
index 78d162a..da3370c 100644
--- a/ambari-web/app/controllers/global/background_operations_controller.js
+++ b/ambari-web/app/controllers/global/background_operations_controller.js
@@ -223,15 +223,18 @@ App.BackgroundOperationsController = Em.Controller.extend({
    * @return PopupObject For testing purposes
    */
   showPopup: function(){
-    App.updater.immediateRun('requestMostRecent');
-
-    if(this.get('popupView') && App.HostPopup.get('isBackgroundOperations')){
-      this.set ('popupView.isNotShowBgChecked', !App.router.get('applicationController').loadShowBgChecked());
-      this.set('popupView.isOpen', true);
-      $(this.get('popupView.element')).appendTo('#wrapper');
-    } else {
-      this.set('popupView', App.HostPopup.initPopup("", this, true));
-    }
+    // load the checkbox on footer first, then show popup.
+    var self = this;
+    App.router.get('applicationController').dataLoading().done(function (initValue) {
+      App.updater.immediateRun('requestMostRecent');
+      if(self.get('popupView') && App.HostPopup.get('isBackgroundOperations')){
+        self.set ('popupView.isNotShowBgChecked', !initValue);
+        self.set('popupView.isOpen', true);
+        $(self.get('popupView.element')).appendTo('#wrapper');
+      } else {
+        self.set('popupView', App.HostPopup.initPopup("", self, true));
+      }
+    });
   }
 
 });

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/a0af1dbf/ambari-web/app/controllers/main/host/details.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/host/details.js b/ambari-web/app/controllers/main/host/details.js
index 9f1a976..9e4ed70 100644
--- a/ambari-web/app/controllers/main/host/details.js
+++ b/ambari-web/app/controllers/main/host/details.js
@@ -156,9 +156,13 @@ App.MainHostDetailsController = Em.Controller.extend({
       } else {
         App.router.get('clusterController').loadUpdatedStatusDelayed(500);
       }
-      if (App.router.get('applicationController').loadShowBgChecked()) {
-        App.router.get('backgroundOperationsController').showPopup();
-      }
+      // load data (if we need to show this background operations popup) from persist
+      App.router.get('applicationController').dataLoading().done(function (initValue) {
+        if (initValue) {
+          App.router.get('backgroundOperationsController').showPopup();
+        }
+      });
+
     });
   },
 
@@ -269,9 +273,12 @@ App.MainHostDetailsController = Em.Controller.extend({
               App.router.get('clusterController').loadUpdatedStatusDelayed(500);
             }
 
-            if (App.router.get('applicationController').loadShowBgChecked()) {
-              App.router.get('backgroundOperationsController').showPopup();
-            }
+            // load data (if we need to show this background operations popup) from persist
+            App.router.get('applicationController').dataLoading().done(function (initValue) {
+              if (initValue) {
+                App.router.get('backgroundOperationsController').showPopup();
+              }
+            });
 
           });
     });
@@ -347,9 +354,12 @@ App.MainHostDetailsController = Em.Controller.extend({
         App.router.get('clusterController').loadUpdatedStatusDelayed(500);
       }
 
-      if (App.router.get('applicationController').loadShowBgChecked()) {
-        App.router.get('backgroundOperationsController').showPopup();
-      }
+      // load data (if we need to show this background operations popup) from persist
+      App.router.get('applicationController').dataLoading().done(function (initValue) {
+        if (initValue) {
+          App.router.get('backgroundOperationsController').showPopup();
+        }
+      });
     });
   },
 
@@ -469,9 +479,12 @@ App.MainHostDetailsController = Em.Controller.extend({
               App.router.get('clusterController').loadUpdatedStatusDelayed(500);
             }
 
-            if (App.router.get('applicationController').loadShowBgChecked() && showPopup) {
-              App.router.get('backgroundOperationsController').showPopup();
-            }
+            // load data (if we need to show this background operations popup) from persist
+            App.router.get('applicationController').dataLoading().done(function (initValue) {
+              if (initValue) {
+                App.router.get('backgroundOperationsController').showPopup();
+              }
+            });
             if (componentName === 'ZOOKEEPER_SERVER') {
               self.checkZkConfigs();
             }
@@ -600,10 +613,12 @@ App.MainHostDetailsController = Em.Controller.extend({
               App.router.get('clusterController').loadUpdatedStatusDelayed(500);
             }
 
-            if (App.router.get('applicationController').loadShowBgChecked()) {
-              App.router.get('backgroundOperationsController').showPopup();
-            }
-
+            // load data (if we need to show this background operations popup) from persist
+            App.router.get('applicationController').dataLoading().done(function (initValue) {
+              if (initValue) {
+                App.router.get('backgroundOperationsController').showPopup();
+              }
+            });
           });
       }
     });
@@ -630,9 +645,12 @@ App.MainHostDetailsController = Em.Controller.extend({
         }
         self.doDatanodeDecommission(decommissionHostNames, true);
       }
-      if (App.router.get('applicationController').loadShowBgChecked()) {
-        App.router.get('backgroundOperationsController').showPopup();
-      }
+      // load data (if we need to show this background operations popup) from persist
+      App.router.get('applicationController').dataLoading().done(function (initValue) {
+        if (initValue) {
+          App.router.get('backgroundOperationsController').showPopup();
+        }
+      });
     });
   },
 
@@ -735,9 +753,12 @@ App.MainHostDetailsController = Em.Controller.extend({
         decommissionHostNames.splice(index, 1);
         self.doDatanodeDecommission(decommissionHostNames, false);
       }
-      if (App.router.get('applicationController').loadShowBgChecked()) {
-        App.router.get('backgroundOperationsController').showPopup();
-      }
+      // load data (if we need to show this background operations popup) from persist
+      App.router.get('applicationController').dataLoading().done(function (initValue) {
+        if (initValue) {
+          App.router.get('backgroundOperationsController').showPopup();
+        }
+      });
     });
   },
   

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/a0af1dbf/ambari-web/app/controllers/main/service.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/service.js b/ambari-web/app/controllers/main/service.js
index da60de0..77c9813 100644
--- a/ambari-web/app/controllers/main/service.js
+++ b/ambari-web/app/controllers/main/service.js
@@ -142,9 +142,12 @@ App.MainServiceController = Em.ArrayController.extend({
     var requestId = data.Requests.id;
     console.log('requestId is: ' + requestId);
 
-    if (App.router.get('applicationController').loadShowBgChecked()) {
-      App.router.get('backgroundOperationsController').showPopup();
-    }
+    // load data (if we need to show this background operations popup) from persist
+    App.router.get('applicationController').dataLoading().done(function (initValue) {
+      if (initValue) {
+        App.router.get('backgroundOperationsController').showPopup();
+      }
+    });
   },
   allServicesCallErrorCallback: function() {
     console.log("ERROR");
@@ -157,4 +160,4 @@ App.MainServiceController = Em.ArrayController.extend({
     App.router.transitionTo('main.serviceAdd');
   }
 
-});
\ No newline at end of file
+});

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/a0af1dbf/ambari-web/app/controllers/main/service/item.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/service/item.js b/ambari-web/app/controllers/main/service/item.js
index e087462..86b660e 100644
--- a/ambari-web/app/controllers/main/service/item.js
+++ b/ambari-web/app/controllers/main/service/item.js
@@ -76,9 +76,12 @@ App.MainServiceItemController = Em.Controller.extend({
     else {
       App.router.get('clusterController').loadUpdatedStatusDelayed(500);// @todo check working without param 500
     }
-    if (App.router.get('applicationController').loadShowBgChecked()) {
-      App.router.get('backgroundOperationsController').showPopup();
-    }
+    // load data (if we need to show this background operations popup) from persist
+    App.router.get('applicationController').dataLoading().done(function (initValue) {
+      if (initValue) {
+        App.router.get('backgroundOperationsController').showPopup();
+      }
+    });
   },
   /**
    * Confirmation popup for start/stop services
@@ -142,9 +145,12 @@ App.MainServiceItemController = Em.Controller.extend({
     var self = this;
     App.showConfirmationPopup(function() {
       self.content.set('runRebalancer', true);
-      if (App.router.get('applicationController').loadShowBgChecked()) {
-        App.router.get('backgroundOperationsController').showPopup();
-      }
+      // load data (if we need to show this background operations popup) from persist
+      App.router.get('applicationController').dataLoading().done(function (initValue) {
+        if (initValue) {
+          App.router.get('backgroundOperationsController').showPopup();
+        }
+      });
     });
   },
 
@@ -156,9 +162,12 @@ App.MainServiceItemController = Em.Controller.extend({
     var self = this;
     App.showConfirmationPopup(function() {
       self.content.set('runCompaction', true);
-      if (App.router.get('applicationController').loadShowBgChecked()) {
-        App.router.get('backgroundOperationsController').showPopup();
-      }
+      // load data (if we need to show this background operations popup) from persist
+      App.router.get('applicationController').dataLoading().done(function (initValue) {
+        if (initValue) {
+          App.router.get('backgroundOperationsController').showPopup();
+        }
+      });
     });
   },
 
@@ -192,9 +201,12 @@ App.MainServiceItemController = Em.Controller.extend({
 
   runSmokeTestSuccessCallBack: function(data) {
     if (data.Requests.id) {
-      if (App.router.get('applicationController').loadShowBgChecked()) {
-        App.router.get('backgroundOperationsController').showPopup();
-      }
+      // load data (if we need to show this background operations popup) from persist
+      App.router.get('applicationController').dataLoading().done(function (initValue) {
+        if (initValue) {
+          App.router.get('backgroundOperationsController').showPopup();
+        }
+      });
     }
     else {
       console.warn('error during runSmokeTestSuccessCallBack');

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/a0af1dbf/ambari-web/app/utils/ajax.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/utils/ajax.js b/ambari-web/app/utils/ajax.js
index 06413f5..ee4e849 100644
--- a/ambari-web/app/utils/ajax.js
+++ b/ambari-web/app/utils/ajax.js
@@ -591,6 +591,25 @@ var urls = {
       };
     }
   },
+  'settings.get.user_pref': {
+    'real': '/persist/{key}',
+    'mock': '',
+    'type': 'GET',
+    'format': function (data, opt) {
+      return {
+      };
+    }
+  },
+  'settings.post.user_pref': {
+    'real': '/persist',
+    'mock': '',
+    'type': 'POST',
+    'format': function (data) {
+      return {
+        data: JSON.stringify(data.keyValuePair)
+      }
+    }
+  },
   'cluster.load_cluster_name': {
     'real': '/clusters',
     'mock': '/data/clusters/info.json',

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/a0af1dbf/ambari-web/app/utils/host_progress_popup.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/utils/host_progress_popup.js b/ambari-web/app/utils/host_progress_popup.js
index bcd0043..f25f4c4 100644
--- a/ambari-web/app/utils/host_progress_popup.js
+++ b/ambari-web/app/utils/host_progress_popup.js
@@ -473,7 +473,6 @@ App.HostPopup = Em.Object.create({
       isOpen: false,
       didInsertElement: function(){
         this.set('isOpen', true);
-        this.set ('isNotShowBgChecked', !App.router.get('applicationController').loadShowBgChecked());
       },
       headerClass: Ember.View.extend({
         controller: this,