Return-Path: X-Original-To: apmail-couchdb-commits-archive@www.apache.org Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 4C1C6106B7 for ; Mon, 3 Mar 2014 16:59:08 +0000 (UTC) Received: (qmail 41109 invoked by uid 500); 3 Mar 2014 16:58:32 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 40700 invoked by uid 500); 3 Mar 2014 16:58:22 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 40263 invoked by uid 99); 3 Mar 2014 16:58:15 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Mar 2014 16:58:15 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 75A89933CF1; Mon, 3 Mar 2014 16:58:14 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: garren@apache.org To: commits@couchdb.apache.org Date: Mon, 03 Mar 2014 16:58:40 -0000 Message-Id: <6502756334f140d983e5a568c49c2791@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [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 Authored: Wed Feb 19 16:47:30 2014 +0200 Committer: Garren Smith 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; + } } });