summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGarren Smith <garren.smith@gmail.com>2014-02-19 16:47:30 +0200
committerGarren Smith <garren.smith@gmail.com>2014-03-03 11:18:42 +0200
commit0beb91caeb1733d07f920a329ecbe3bb07f55187 (patch)
tree700feec8a3551d044e34d3ea9fa7eb8ae02ddd7a
parentf796b38ef2474bdfed5303a627136ee3ad8ea8d2 (diff)
downloadcouchdb-0beb91caeb1733d07f920a329ecbe3bb07f55187.tar.gz
More pagination improvements
-rw-r--r--src/fauxton/app/addons/documents/resources.js13
-rw-r--r--src/fauxton/app/addons/documents/routes.js35
2 files changed, 34 insertions, 14 deletions
diff --git a/src/fauxton/app/addons/documents/resources.js b/src/fauxton/app/addons/documents/resources.js
index 6112bab28..6f6ed1ca8 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);
}
diff --git a/src/fauxton/app/addons/documents/routes.js b/src/fauxton/app/addons/documents/routes.js
index 5ce66b18d..eeca7b731 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;
+ }
}
});