couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kxe...@apache.org
Subject [13/50] [abbrv] fauxton commit: updated refs/heads/import-master to b32c617
Date Tue, 01 Apr 2014 09:14:29 GMT
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-fauxton/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/commit/5d406150
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/tree/5d406150
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/diff/5d406150

Branch: refs/heads/import-master
Commit: 5d406150159cf483bda426f6bf27013d53dfeb83
Parents: 9993b1c
Author: Will Holley <willholley@gmail.com>
Authored: Fri Mar 7 10:16:19 2014 +0000
Committer: Will Holley <willholley@gmail.com>
Committed: Fri Mar 7 10:23:54 2014 +0000

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


http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/5d406150/app/addons/documents/resources.js
----------------------------------------------------------------------
diff --git a/app/addons/documents/resources.js b/app/addons/documents/resources.js
index c0b736f..6f4323a 100644
--- a/app/addons/documents/resources.js
+++ b/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-fauxton/blob/5d406150/app/addons/documents/routes.js
----------------------------------------------------------------------
diff --git a/app/addons/documents/routes.js b/app/addons/documents/routes.js
index f340195..ff518e4 100644
--- a/app/addons/documents/routes.js
+++ b/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);
     },
 


Mime
View raw message