You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ga...@apache.org on 2014/03/14 17:45:44 UTC

[06/28] couchdb commit: updated refs/heads/Query-Options-UI to 1295cce

Store the initial collection parameters to allow a safe reset to the first page.

When adjusting page size, the desired behaviour is to navigate back to the
first page of the collection. This was previously done using the browser
URL but that does not capture additional defaults that are set in JavaScript.

This commit adds 2 new methods to the document collections:

saveDefaultParameters()
restoreDefaultParameters()

When each collection is initialized, we save the parameters (which represent the
initial state) - these can then be correctly restored when the page size is changed.

Fixes COUCHDB-2187.


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

Branch: refs/heads/Query-Options-UI
Commit: adf9ae25c6be1c654fededfc72350b48abfda1de
Parents: b63ff1b
Author: Will Holley <wi...@gmail.com>
Authored: Fri Mar 7 10:16:19 2014 +0000
Committer: Will Holley <wi...@gmail.com>
Committed: Fri Mar 7 10:23:54 2014 +0000

----------------------------------------------------------------------
 src/fauxton/app/addons/documents/resources.js | 42 +++++++++++++++++-----
 src/fauxton/app/addons/documents/routes.js    |  7 ++--
 2 files changed, 37 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/adf9ae25/src/fauxton/app/addons/documents/resources.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/addons/documents/resources.js b/src/fauxton/app/addons/documents/resources.js
index c0b736f..6f4323a 100644
--- a/src/fauxton/app/addons/documents/resources.js
+++ b/src/fauxton/app/addons/documents/resources.js
@@ -358,7 +358,23 @@ function(app, FauxtonAPI) {
 
   });
 
-  Documents.AllDocs = FauxtonAPI.Collection.extend({
+  var DefaultParametersMixin = function() {
+    // keep this variable private
+    var defaultParams;
+
+    return {
+      saveDefaultParameters: function() {
+        // store the default parameters so we can reset to the first page
+        defaultParams = _.clone(this.params);
+      },
+
+      restoreDefaultParameters: function() {
+        this.params = _.clone(defaultParams);
+      }
+    };
+  };
+
+  Documents.AllDocs = FauxtonAPI.Collection.extend(_.extend({}, DefaultParametersMixin(), {
     model: Documents.Doc,
     isAllDocs: true,
     documentation: function(){
@@ -367,12 +383,15 @@ function(app, FauxtonAPI) {
     initialize: function(_models, options) {
       this.database = options.database;
       this.params = _.clone(options.params);
+
       this.on("remove",this.decrementTotalRows , this);
       this.perPageLimit = options.perPageLimit || 20;
 
       if (!this.params.limit) {
-        this.params.limit = this.perPageLimit; 
+        this.params.limit = this.perPageLimit;
       }
+
+      this.saveDefaultParameters();
     },
 
     url: function(context, params) {
@@ -459,9 +478,9 @@ function(app, FauxtonAPI) {
         };
       });
     }
-  });
+  }));
 
-  Documents.IndexCollection = FauxtonAPI.Collection.extend({
+  Documents.IndexCollection = FauxtonAPI.Collection.extend(_.extend({}, DefaultParametersMixin(), {
     model: Documents.ViewRow,
     documentation: function(){
       return "docs";
@@ -469,6 +488,7 @@ function(app, FauxtonAPI) {
     initialize: function(_models, options) {
       this.database = options.database;
       this.params = _.extend({limit: 20, reduce: false}, options.params);
+
       this.idxType = "_view";
       this.view = options.view;
       this.design = options.design.replace('_design/','');
@@ -476,9 +496,10 @@ function(app, FauxtonAPI) {
       this.perPageLimit = options.perPageLimit || 20;
 
       if (!this.params.limit) {
-        this.params.limit = this.perPageLimit; 
+        this.params.limit = this.perPageLimit;
       }
-
+      
+      this.saveDefaultParameters();
     },
 
     url: function(context, params) {
@@ -618,10 +639,10 @@ function(app, FauxtonAPI) {
       return timeString;
     }
 
-  });
+  }));
 
   
-  Documents.PouchIndexCollection = FauxtonAPI.Collection.extend({
+  Documents.PouchIndexCollection = FauxtonAPI.Collection.extend(_.extend({}, DefaultParametersMixin(), {
     model: Documents.ViewRow,
     documentation: function(){
       return "docs";
@@ -632,7 +653,10 @@ function(app, FauxtonAPI) {
       this.view = options.view;
       this.design = options.design.replace('_design/','');
       this.params = _.extend({limit: 20, reduce: false}, options.params);
+
       this.idxType = "_view";
+
+      this.saveDefaultParameters();
     },
 
     url: function () {
@@ -687,7 +711,7 @@ function(app, FauxtonAPI) {
     allDocs: function(){
       return this.models;
     }
-  });
+  }));
 
 
 

http://git-wip-us.apache.org/repos/asf/couchdb/blob/adf9ae25/src/fauxton/app/addons/documents/routes.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/addons/documents/routes.js b/src/fauxton/app/addons/documents/routes.js
index f340195..ff518e4 100644
--- a/src/fauxton/app/addons/documents/routes.js
+++ b/src/fauxton/app/addons/documents/routes.js
@@ -377,12 +377,13 @@ function(app, FauxtonAPI, Documents, Databases) {
     },
 
     perPageChange: function (perPage) {
-      var params = app.getParams();
+      // We need to restore the collection parameters to the defaults (1st page)
+      // and update the page size
+      var params = this.documentsView.collection.restoreDefaultParameters();
       this.perPage = perPage;
       this.documentsView.updatePerPage(perPage);
       this.documentsView.forceRender();
-      params.limit = perPage;
-      this.documentsView.collection.params = params;
+      this.documentsView.collection.params.limit = perPage;
       this.setDocPerPageLimit(perPage);
     },