ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yus...@apache.org
Subject git commit: AMBARI-4098. host pagination size not persisted between login/logout. (xiwang via yusaku)
Date Fri, 20 Dec 2013 23:22:38 GMT
Updated Branches:
  refs/heads/trunk c5105ee1f -> 31143fac4


AMBARI-4098. host pagination size not persisted between login/logout. (xiwang via yusaku)


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

Branch: refs/heads/trunk
Commit: 31143fac4f281a60a4ed3e65cd3aae32e454c7cf
Parents: c5105ee
Author: Yusaku Sako <yusaku@hortonworks.com>
Authored: Fri Dec 20 15:22:19 2013 -0800
Committer: Yusaku Sako <yusaku@hortonworks.com>
Committed: Fri Dec 20 15:22:19 2013 -0800

----------------------------------------------------------------------
 ambari-web/app/views/common/table_view.js | 88 +++++++++++++++++++++++---
 ambari-web/app/views/main/host.js         |  1 -
 2 files changed, 78 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/31143fac/ambari-web/app/views/common/table_view.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/common/table_view.js b/ambari-web/app/views/common/table_view.js
index cc21fb8..ad2b4b8 100644
--- a/ambari-web/app/views/common/table_view.js
+++ b/ambari-web/app/views/common/table_view.js
@@ -32,7 +32,7 @@ App.TableView = Em.View.extend({
    */
   startIndexOnLoad: null,
   /**
-   * Loaded from local storage displayLength value
+   * Loaded from server persist value
    */
   displayLengthOnLoad: null,
 
@@ -44,7 +44,9 @@ App.TableView = Em.View.extend({
     var name = this.get('controller.name');
 
     this.set('startIndexOnLoad', App.db.getStartIndex(name));
-    this.set('displayLengthOnLoad', App.db.getDisplayLength(name));
+    self.dataLoading().done(function (initValue) {
+      self.set('displayLength', initValue);
+    });
 
     var filterConditions = App.db.getFilterConditions(name);
     if (filterConditions) {
@@ -73,6 +75,75 @@ App.TableView = Em.View.extend({
   },
 
   /**
+   * Load user preference value on hosts page from server
+   */
+  dataLoading: function () {
+    var dfd = $.Deferred();
+    var self = this;
+    this.getUserPref(this.displayLengthKey()).done(function () {
+      var curLength = self.get('displayLengthOnLoad');
+      self.set('displayLengthOnLoad', null);
+      dfd.resolve(curLength);
+    });
+    return dfd.promise();
+  },
+  displayLengthKey: function (loginName) {
+    if (!loginName)
+      loginName = App.router.get('loginName');
+    return 'hosts-pagination-displayLength-' + loginName;
+  },
+
+  /**
+   * get display length persist value from server with displayLengthKey
+   */
+  getUserPref: function(key){
+    return App.ajax.send({
+      name: 'settings.get.user_pref',
+      sender: this,
+      data: {
+        key: key
+      },
+      success: 'getDisplayLengthSuccessCallback',
+      error: 'getDisplayLengthErrorCallback'
+    });
+  },
+  getDisplayLengthSuccessCallback: function (response, request, data) {
+    if (response != null) {
+      console.log('Got DisplayLength value from server with key ' + data.key + '. Value is:
' + response);
+      this.set('displayLengthOnLoad', response);
+      return response;
+    }
+  },
+  getDisplayLengthErrorCallback: function (request, ajaxOptions, error) {
+    // this user is first time login
+    if (request.status == 404) {
+      console.log('Persist did NOT find the key');
+      var displayLengthDefault = 10;
+      this.set('displayLengthOnLoad', displayLengthDefault);
+      this.postUserPref(this.displayLengthKey(), displayLengthDefault);
+      return displayLengthDefault;
+    }
+  },
+  /**
+   * post display length persist key/value to server, value is object
+   */
+  postUserPref: function (key, value) {
+    var keyValuePair = {};
+    keyValuePair[key] = JSON.stringify(value);
+    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);
+  },
+
+  /**
    * Do pagination after filtering and sorting
    * Don't call this method! It's already used where it's need
    */
@@ -80,9 +151,6 @@ App.TableView = Em.View.extend({
     var self = this;
     Em.run.next(function() {
       Em.run.next(function() {
-        if (self.get('displayLengthOnLoad')) {
-          self.set('displayLength', self.get('displayLengthOnLoad'));
-        }
         if(self.get('startIndexOnLoad')) {
           self.set('startIndex', self.get('startIndexOnLoad'));
         }
@@ -209,7 +277,11 @@ App.TableView = Em.View.extend({
   saveDisplayLength: function() {
     var self = this;
     Em.run.next(function() {
-      App.db.setDisplayLength(self.get('controller.name'), self.get('displayLength'));
+      //App.db.setDisplayLength(self.get('controller.name'), self.get('displayLength'));
+      var key = self.displayLengthKey();
+      if (!App.testMode) {
+        self.postUserPref(key, self.get('displayLength'));
+      }
     });
   }.observes('displayLength'),
 
@@ -223,10 +295,6 @@ App.TableView = Em.View.extend({
     App.db.setFilterConditions(this.get('controller.name'), null);
   },
 
-  clearDisplayLength: function() {
-    App.db.setDisplayLength(this.get('controller.name'), null);
-  },
-
   clearStartIndex: function() {
     App.db.setStartIndex(this.get('controller.name'), null);
   },

http://git-wip-us.apache.org/repos/asf/ambari/blob/31143fac/ambari-web/app/views/main/host.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/main/host.js b/ambari-web/app/views/main/host.js
index b03e394..4e455f7 100644
--- a/ambari-web/app/views/main/host.js
+++ b/ambari-web/app/views/main/host.js
@@ -36,7 +36,6 @@ App.MainHostView = App.TableView.extend({
     Em.run.next(function() {
       if (self.get('controller.clearFilters')) {
         self.clearFilters();
-        self.clearDisplayLength();
         self.clearStartIndex();
       }
     });


Mime
View raw message