couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From deathb...@apache.org
Subject [1/3] couchdb commit: updated refs/heads/2189-ddoc-info-on-demand to f04b0fe
Date Mon, 10 Mar 2014 17:09:18 GMT
Repository: couchdb
Updated Branches:
  refs/heads/2189-ddoc-info-on-demand 672198ebe -> f04b0fe76 (forced update)


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/2189-ddoc-info-on-demand
Commit: adf9ae25c6be1c654fededfc72350b48abfda1de
Parents: b63ff1b
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

----------------------------------------------------------------------
 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);
     },
 


Mime
View raw message