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/02/21 16:54:37 UTC

[3/3] couchdb commit: updated refs/heads/paginate-api-options to 5ab96a4

More pagination goodness


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

Branch: refs/heads/paginate-api-options
Commit: 5ab96a460b0e0fcdb582eb9ea19107b09a8458c9
Parents: 27034ef
Author: Garren Smith <ga...@gmail.com>
Authored: Fri Feb 21 17:53:12 2014 +0200
Committer: Garren Smith <ga...@gmail.com>
Committed: Fri Feb 21 17:53:12 2014 +0200

----------------------------------------------------------------------
 src/fauxton/app/addons/documents/resources.js | 29 +++++++++-------------
 src/fauxton/app/addons/documents/routes.js    | 20 ++++++++-------
 src/fauxton/app/addons/documents/views.js     |  4 ---
 3 files changed, 23 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/5ab96a46/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 fd1a558..8bc52b0 100644
--- a/src/fauxton/app/addons/documents/resources.js
+++ b/src/fauxton/app/addons/documents/resources.js
@@ -19,6 +19,7 @@ function(app, FauxtonAPI) {
   var Documents = FauxtonAPI.addon();
 
   Documents.paginate = {
+    history: [],
     calculate: function (doc, defaultParams, currentParams, _isAllDocs) {
       var docId = '',
           lastId = '',
@@ -65,14 +66,20 @@ function(app, FauxtonAPI) {
       var params = {limit: perPage, skip: 1},
           doc = _.last(docs);
           
-            return this.calculate(doc, params, currentParams, _isAllDocs);
+      this.history.push(_.clone(currentParams));
+      return this.calculate(doc, params, currentParams, _isAllDocs);
     },
 
     previous: function (docs, currentParams, perPage, _isAllDocs) {
-      var params = {descending: true, limit: perPage, skip: 1},
+      var params = this.history.pop(),
           doc = _.first(docs);
 
-      return this.calculate(doc, params, currentParams, _isAllDocs);
+      params.limit = perPage;
+      return params;
+    },
+
+    reset: function () {
+      this.history = [];
     }
   };
 
@@ -421,7 +428,7 @@ function(app, FauxtonAPI) {
       if (this.skipFirstItem) {
         rows = rows.splice(1);
       }
-      var mappedRows = _.map(rows, function(row) {
+      return _.map(rows, function(row) {
         return {
           _id: row.id,
           _rev: row.value.rev,
@@ -430,12 +437,6 @@ function(app, FauxtonAPI) {
           doc: row.doc || undefined
         };
       });
-
-      if (this.reverse) {
-        return _(mappedRows).reverse().value();
-      }
-
-      return mappedRows;
     }
   });
 
@@ -539,7 +540,7 @@ function(app, FauxtonAPI) {
         offset: resp.offset,
         update_seq: resp.update_seq
       };
-      var mappedRows =  _.map(rows, function(row) {
+      return _.map(rows, function(row) {
         return {
           value: row.value,
           key: row.key,
@@ -547,12 +548,6 @@ function(app, FauxtonAPI) {
           id: row.id
         };
       });
-
-      if (this.reverse) {
-        return _(mappedRows).reverse().value();
-      }
-
-      return mappedRows;
     },
 
     buildAllDocs: function(){

http://git-wip-us.apache.org/repos/asf/couchdb/blob/5ab96a46/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 16cc6d8..45b2825 100644
--- a/src/fauxton/app/addons/documents/routes.js
+++ b/src/fauxton/app/addons/documents/routes.js
@@ -243,6 +243,7 @@ function(app, FauxtonAPI, Documents, Databases) {
       ];
 
       this.apiUrl = [this.data.database.allDocs.url("apiurl", urlParams), this.data.database.allDocs.documentation() ];
+      Documents.paginate.reset();
     },
 
     viewFn: function (databaseName, ddoc, view) {
@@ -298,6 +299,7 @@ function(app, FauxtonAPI, Documents, Databases) {
       };
 
       this.apiUrl = [this.data.indexedDocs.url("apiurl", urlParams), "docs"];
+      Documents.paginate.reset();
     },
 
     newViewEditor: function () {
@@ -352,6 +354,7 @@ function(app, FauxtonAPI, Documents, Databases) {
       this.documentsView.setParams(docParams, urlParams);
 
       this.apiUrl = [collection.url("apiurl", urlParams), "docs"];
+      Documents.paginate.reset();
     },
 
     updateAllDocsFromPreview: function (event) {
@@ -375,8 +378,11 @@ function(app, FauxtonAPI, Documents, Databases) {
     },
 
     perPageChange: function (perPage) {
+      var params = app.getParams();
       this.perPage = perPage;
       this.documentsView.updatePerPage(perPage);
+      params.limit = perPage;
+      this.documentsView.collection.params = params;
       this.documentsView.forceRender();
     },
 
@@ -405,21 +411,17 @@ function(app, FauxtonAPI, Documents, Databases) {
                                            options.perPage, 
                                            !!collection.isAllDocs);
       } else {
-        if (currentPage <= 1) {
-          params = _.clone(urlParams);
-          params.limit = collection.params.limit;
-        } else {
-          collection.reverse = true;
           params = Documents.paginate.previous(rawCollection, 
                                                collection.params, 
                                                options.perPage, 
                                                !!collection.isAllDocs);
-        }
       }
       params.limit = options.perPage;
-      _.each(params, function (val, key) {
-        params[key] = JSON.stringify(val);
-      });
+      _.each(['startkey', 'endkey', 'key'], function (key) {
+        if (_.has(params, key)) {
+          params[key] = JSON.stringify(params[key]);
+        }
+    });
       collection.updateParams(params);
     },
 

http://git-wip-us.apache.org/repos/asf/couchdb/blob/5ab96a46/src/fauxton/app/addons/documents/views.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/addons/documents/views.js b/src/fauxton/app/addons/documents/views.js
index f222b93..1d07dae 100644
--- a/src/fauxton/app/addons/documents/views.js
+++ b/src/fauxton/app/addons/documents/views.js
@@ -740,10 +740,6 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb, resizeColum
     },
 
     updatePerPage: function (newPerPage) {
-      if (this.collection.reverse) {
-        delete this.collection.params.descending
-        this.collection.reverse = false;
-      }
       this.collection.updateLimit(newPerPage);
     }
   });