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/03 17:58:40 UTC

[28/34] couchdb commit: updated refs/heads/paginate-api-options to b63c791

More pagination improvements


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

Branch: refs/heads/paginate-api-options
Commit: 0beb91caeb1733d07f920a329ecbe3bb07f55187
Parents: f796b38
Author: Garren Smith <ga...@gmail.com>
Authored: Wed Feb 19 16:47:30 2014 +0200
Committer: Garren Smith <ga...@gmail.com>
Committed: Mon Mar 3 11:18:42 2014 +0200

----------------------------------------------------------------------
 src/fauxton/app/addons/documents/resources.js | 13 ++++++++
 src/fauxton/app/addons/documents/routes.js    | 35 +++++++++++++---------
 2 files changed, 34 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/0beb91ca/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 6112bab..6f6ed1c 100644
--- a/src/fauxton/app/addons/documents/resources.js
+++ b/src/fauxton/app/addons/documents/resources.js
@@ -26,6 +26,10 @@ function(app, FauxtonAPI) {
           lastId = '',
           isView = !!!_isAllDocs,
           key;
+      
+      _.each(doc, function (value, key) {
+        doc[key] = JSON.stringify(doc[key]);
+      });
 
       if (currentParams.keys) {
         throw "Cannot paginate _all_docs with keys";
@@ -45,6 +49,7 @@ function(app, FauxtonAPI) {
       lastId = doc.id || doc._id;
 
       if (isView) {
+        console.log(doc.key, doc, lastId);
         key = doc.key;
         docId = lastId;
       } else {
@@ -486,6 +491,14 @@ function(app, FauxtonAPI) {
     url: function(context) {
       var query = "";
       if (this.params) {
+        /*this.params = _.reduce(['startkey', 'endkey', 'key', 'keys'], function (params, key) {
+          if (_.has(params, key)) {
+            params[key] = JSON.stringify(params[key]);
+          }
+
+          return params;
+        }, this.params);*/
+
         query = "?" + $.param(this.params);
       }
       

http://git-wip-us.apache.org/repos/asf/couchdb/blob/0beb91ca/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 5ce66b1..eeca7b7 100644
--- a/src/fauxton/app/addons/documents/routes.js
+++ b/src/fauxton/app/addons/documents/routes.js
@@ -209,6 +209,7 @@ function(app, FauxtonAPI, Documents, Databases) {
         return;
       }
 
+      docParams.limit = this.getDocPerPageLimit(urlParams, 20);
       this.data.database.buildAllDocs(docParams);
 
       if (docParams.startkey && docParams.startkey.indexOf('_design') > -1) {
@@ -245,22 +246,19 @@ function(app, FauxtonAPI, Documents, Databases) {
     },
 
     viewFn: function (databaseName, ddoc, view) {
-      var params = app.getParams(),
-          decodeDdoc = decodeURIComponent(ddoc),
-          docLimit;
-
-      if (params.limit) {
-        docLimit = params.limit;
-      } 
+      var params = this.createParams(),
+          urlParams = params.urlParams,
+          docParams = params.docParams;
+          decodeDdoc = decodeURIComponent(ddoc);
 
-      params.limit = 20; //default per page
+      docParams.limit = this.getDocPerPageLimit(urlParams, 20);
       view = view.replace(/\?.*$/,'');
 
       this.data.indexedDocs = new Documents.IndexCollection(null, {
         database: this.data.database,
         design: decodeDdoc,
         view: view,
-        params: params
+        params: docParams
       });
 
       var ddocInfo = {
@@ -273,7 +271,7 @@ function(app, FauxtonAPI, Documents, Databases) {
         model: this.data.database,
         ddocs: this.data.designDocs,
         viewName: view,
-        params: _.extend(params, {limit: docLimit}),
+        params: urlParams,
         newView: false,
         database: this.data.database,
         ddocInfo: ddocInfo
@@ -287,7 +285,8 @@ function(app, FauxtonAPI, Documents, Databases) {
         nestedView: Documents.Views.Row,
         viewList: true,
         ddocInfo: ddocInfo,
-        docLimit: parseInt(docLimit, 10)
+        docParams: docParams,
+        params: urlParams
       }));
 
       this.sidebar.setSelectedTab(app.utils.removeSpecialCharacters(ddoc) + '_' + app.utils.removeSpecialCharacters(view));
@@ -330,8 +329,7 @@ function(app, FauxtonAPI, Documents, Databases) {
           ddoc = event.ddoc,
           collection;
 
-      docParams.limit = this.documentsView.perPage();
-
+      docParams.limit = this.getDocPerPageLimit(urlParams, this.documentsView.perPage());
       this.documentsView.forceRender();
 
       if (event.allDocs) {
@@ -388,7 +386,7 @@ function(app, FauxtonAPI, Documents, Databases) {
       this.documentsView.forceRender();
 
       if (options.direction === 'next') {
-        params = Documents.paginate.next(collection.map(function (item) { return item.toJSON(); }), collection.params, options.perPage, !!collection.isAllDocs);
+          params = Documents.paginate.next(collection.map(function (item) { return item.toJSON(); }), collection.params, options.perPage, !!collection.isAllDocs);
       }
       
       collection.updateParams(params);
@@ -400,6 +398,15 @@ function(app, FauxtonAPI, Documents, Databases) {
       if (event && event.selectedTab) {
         this.sidebar.setSelectedTab(event.selectedTab);
       }
+    },
+
+
+    getDocPerPageLimit: function (urlParams, perPage) {
+      if (!urlParams.limit || urlParams.limit > perPage) {
+        return perPage;
+      } else {
+        return urlParams.limit;
+      }
     }
 
   });