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:34 UTC
[22/34] couchdb commit: updated refs/heads/paginate-api-options to
b63c791
Paginiation with no limit
Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/98b54724
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/98b54724
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/98b54724
Branch: refs/heads/paginate-api-options
Commit: 98b54724520bbebe46c09c8164690a42a3cda3d5
Parents: 69fa6c4
Author: Garren Smith <ga...@gmail.com>
Authored: Tue Feb 11 17:24:02 2014 +0200
Committer: Garren Smith <ga...@gmail.com>
Committed: Mon Mar 3 11:18:41 2014 +0200
----------------------------------------------------------------------
.../app/addons/databases/templates/item.html | 2 +-
src/fauxton/app/addons/databases/views.js | 3 +-
src/fauxton/app/addons/documents/routes.js | 44 ++++++++++++---
.../documents/templates/all_docs_number.html | 22 ++++----
.../app/addons/documents/templates/sidebar.html | 4 +-
src/fauxton/app/addons/documents/views.js | 58 +++++++++-----------
src/fauxton/app/addons/fauxton/components.js | 45 +++++++++------
7 files changed, 104 insertions(+), 74 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb/blob/98b54724/src/fauxton/app/addons/databases/templates/item.html
----------------------------------------------------------------------
diff --git a/src/fauxton/app/addons/databases/templates/item.html b/src/fauxton/app/addons/databases/templates/item.html
index e2f8071..549f421 100644
--- a/src/fauxton/app/addons/databases/templates/item.html
+++ b/src/fauxton/app/addons/databases/templates/item.html
@@ -13,7 +13,7 @@ the License.
-->
<td>
- <a href="#/database/<%=encoded%>/_all_docs?limit=<%=docLimit%>"><%= database.get("name") %></a>
+ <a href="#/database/<%=encoded%>/_all_docs"><%= database.get("name") %></a>
</td>
<td><%= database.status.humanSize() %></td>
<td><%= database.status.numDocs() %></td>
http://git-wip-us.apache.org/repos/asf/couchdb/blob/98b54724/src/fauxton/app/addons/databases/views.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/addons/databases/views.js b/src/fauxton/app/addons/databases/views.js
index 7f23d65..a56267f 100644
--- a/src/fauxton/app/addons/databases/views.js
+++ b/src/fauxton/app/addons/databases/views.js
@@ -31,8 +31,7 @@ function(app, Components, FauxtonAPI, Databases) {
return {
encoded: app.utils.safeURLName(this.model.get("name")),
- database: this.model,
- docLimit: Databases.DocLimit
+ database: this.model
};
}
});
http://git-wip-us.apache.org/repos/asf/couchdb/blob/98b54724/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 a0edc07..0d143de 100644
--- a/src/fauxton/app/addons/documents/routes.js
+++ b/src/fauxton/app/addons/documents/routes.js
@@ -187,8 +187,19 @@ function(app, FauxtonAPI, Documents, Databases) {
},
allDocs: function(databaseName, options) {
- var docOptions = app.getParams(options);
+ var docOptions = app.getParams(options),
+ docLimit;
+ if (this.eventAllDocs) {
+ this.eventAllDocs = false;
+ return;
+ }
+
+ if (docOptions.limit) {
+ docLimit = docOptions.limit;
+ }
+
+ docOptions.limit = 20; //default per page
this.data.database.buildAllDocs(docOptions);
if (docOptions.startkey && docOptions.startkey.indexOf('_design') > -1) {
@@ -212,7 +223,7 @@ function(app, FauxtonAPI, Documents, Databases) {
this.documentsView = this.setView("#dashboard-lower-content", new Documents.Views.AllDocsList({
collection: this.data.database.allDocs,
- docLimit: parseInt(docOptions.limit, 10)
+ docLimit: parseInt(docLimit, 10)
}));
this.crumbs = [
@@ -224,8 +235,14 @@ function(app, FauxtonAPI, Documents, Databases) {
viewFn: function (databaseName, ddoc, view) {
var params = app.getParams(),
- decodeDdoc = decodeURIComponent(ddoc);
+ decodeDdoc = decodeURIComponent(ddoc),
+ docLimit;
+
+ if (params.limit) {
+ docLimit = params.limit;
+ }
+ params.limit = 20; //default per page
view = view.replace(/\?.*$/,'');
this.data.indexedDocs = new Documents.IndexCollection(null, {
@@ -245,7 +262,7 @@ function(app, FauxtonAPI, Documents, Databases) {
model: this.data.database,
ddocs: this.data.designDocs,
viewName: view,
- params: params,
+ params: _.extend(params, {limit: docLimit}),
newView: false,
database: this.data.database,
ddocInfo: ddocInfo
@@ -258,7 +275,8 @@ function(app, FauxtonAPI, Documents, Databases) {
collection: this.data.indexedDocs,
nestedView: Documents.Views.Row,
viewList: true,
- ddocInfo: ddocInfo
+ ddocInfo: ddocInfo,
+ docLimit: parseInt(docLimit, 10)
}));
this.sidebar.setSelectedTab(app.utils.removeSpecialCharacters(ddoc) + '_' + app.utils.removeSpecialCharacters(view));
@@ -296,14 +314,22 @@ function(app, FauxtonAPI, Documents, Databases) {
updateAllDocsFromView: function (event) {
var view = event.view,
docOptions = app.getParams(),
- ddoc = event.ddoc;
+ ddoc = event.ddoc,
+ docLimit;
+
+ if (docOptions.limit) {
+ docLimit = docOptions.limit;
+ }
+ docOptions.limit = this.documentsView.perPage();
this.documentsView && this.documentsView.remove();
if (event.allDocs) {
+ this.eventAllDocs = true; // this is horrible. But I cannot get the trigger not to fire the route!
this.data.database.buildAllDocs(docOptions);
this.documentsView = this.setView("#dashboard-lower-content", new Documents.Views.AllDocsList({
- collection: this.data.database.allDocs
+ collection: this.data.database.allDocs,
+ docLimit: parseInt(docLimit, 10)
}));
return;
}
@@ -319,7 +345,8 @@ function(app, FauxtonAPI, Documents, Databases) {
database: this.data.database,
collection: this.data.indexedDocs,
nestedView: Documents.Views.Row,
- viewList: true
+ viewList: true,
+ docLimit: parseInt(docLimit, 10)
}));
this.apiUrl = [this.data.indexedDocs.url("apiurl"), "docs"];
@@ -352,6 +379,7 @@ function(app, FauxtonAPI, Documents, Databases) {
paginate: function (options) {
this.documentsView.forceRender();
+
if (options.direction === 'next') {
this.documentsView.collection.skipFirstItem = true;
this.documentsView.collection.nextPage(options.perPage);
http://git-wip-us.apache.org/repos/asf/couchdb/blob/98b54724/src/fauxton/app/addons/documents/templates/all_docs_number.html
----------------------------------------------------------------------
diff --git a/src/fauxton/app/addons/documents/templates/all_docs_number.html b/src/fauxton/app/addons/documents/templates/all_docs_number.html
index fb9ea11..0461a4b 100644
--- a/src/fauxton/app/addons/documents/templates/all_docs_number.html
+++ b/src/fauxton/app/addons/documents/templates/all_docs_number.html
@@ -21,15 +21,15 @@ Showing <%=pageStart%> - <%= pageEnd %>
<% } %>
<div id="per-page">
-<label id="per-page" class="drop-down inline">
- Per page:
- <select id="select-per-page" name="per-page" class="input-small">
- <option value="5">5</option>
- <option value="10">10</option>
- <option value="20">20</option>
- <option value="30">30</option>
- <option value="50">50</option>
- <option value="100">100</option>
- </select>
-</label>
+ <label id="per-page" class="drop-down inline">
+ Per page:
+ <select id="select-per-page" name="per-page" class="input-small">
+ <option value="5">5</option>
+ <option value="10">10</option>
+ <option value="20">20</option>
+ <option value="30">30</option>
+ <option value="50">50</option>
+ <option value="100">100</option>
+ </select>
+ </label>
</div>
http://git-wip-us.apache.org/repos/asf/couchdb/blob/98b54724/src/fauxton/app/addons/documents/templates/sidebar.html
----------------------------------------------------------------------
diff --git a/src/fauxton/app/addons/documents/templates/sidebar.html b/src/fauxton/app/addons/documents/templates/sidebar.html
index 7358960..750cd30 100644
--- a/src/fauxton/app/addons/documents/templates/sidebar.html
+++ b/src/fauxton/app/addons/documents/templates/sidebar.html
@@ -55,8 +55,8 @@ the License.
<nav>
<ul class="nav nav-list">
- <li class="active"><a id="all-docs" href="#<%= database.url('index') %>?limit=<%= docLimit %>" class="toggle-view"> All documents</a></li>
- <li><a id="design-docs" href='#<%= database.url("index") %>?limit=<%= docLimit %>&startkey="_design"&endkey="_e"' class="toggle-view"> All design docs</a></li>
+ <li class="active"><a id="all-docs" href="#<%= database.url('index') %>" class="toggle-view"> All documents</a></li>
+ <li><a id="design-docs" href='#<%= database.url("index") %>?startkey="_design"&endkey="_e"' class="toggle-view"> All design docs</a></li>
</ul>
<ul class="nav nav-list views">
<li class="nav-header">Secondary Indexes</li>
http://git-wip-us.apache.org/repos/asf/couchdb/blob/98b54724/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 e9a0ee6..4f81016 100644
--- a/src/fauxton/app/addons/documents/views.js
+++ b/src/fauxton/app/addons/documents/views.js
@@ -416,8 +416,7 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb, resizeColum
this.newView = options.newView || false;
this.pagination = options.pagination;
- this.perPage = 20;
-
+ this._perPage = 20;
this.listenTo(this.collection, 'totalRows:decrement', this.render);
},
@@ -427,13 +426,13 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb, resizeColum
},
updatePerPage: function (event) {
- this.perPage = parseInt(this.$('#select-per-page :selected').val(), 10);
- FauxtonAPI.triggerRouteEvent('perPageChange', this.perPage);
- this.pagination.updatePerPage(this.perPage);
+ this._perPage = parseInt(this.$('#select-per-page :selected').val(), 10);
+ this.pagination.updatePerPage(this.perPage());
+ FauxtonAPI.triggerRouteEvent('perPageChange', this.pagination.documentsLeftToFetch());
},
afterRender: function () {
- this.$('option[value="' + this.perPage + '"]').attr('selected', "selected");
+ this.$('option[value="' + this.perPage() + '"]').attr('selected', "selected");
},
serialize: function () {
@@ -463,6 +462,10 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb, resizeColum
pageStart: pageStart,
pageEnd: pageEnd
};
+ },
+
+ perPage: function () {
+ return this._perPage;
}
});
@@ -495,19 +498,11 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb, resizeColum
database: this.database,
eventer: this.eventer
}));
-
- /*this.advancedOptionsMenu = this.insertView('#query-options-wrapper', new Views.AdvancedOptionsMenu({
- hasReduce: false,
- eventer: this.eventer
- }));*/
-
- //this.$('#query').hide();
},
afterRender: function () {
if (this.params) {
this.advancedOptions.updateFromParams(this.params);
- //this.advancedOptionsMenu.updateFromParams(this.params);
}
},
@@ -540,9 +535,12 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb, resizeColum
}
var fragment = window.location.hash.replace(/\?.*$/, '');
- fragment = fragment + '?' + $.param(params);
- FauxtonAPI.navigate(fragment, {trigger: false});
+ if (!_.isEmpty(params)) {
+ fragment = fragment + '?' + $.param(params);
+ }
+
+ FauxtonAPI.navigate(fragment, {trigger: false});
FauxtonAPI.triggerRouteEvent('updateAllDocs', {allDocs: true});
},
@@ -706,6 +704,10 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb, resizeColum
afterRender: function(){
prettyPrint();
+ },
+
+ perPage: function () {
+ return this.allDocsNumber.perPage();
}
});
@@ -1142,10 +1144,10 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb, resizeColum
var $form = this.$(".view-query-update");
// Ignore params without a value
var params = _.reduce($form.serializeArray(), function(params, param) {
- if (!params.value) { return params; }
+ if (!param.value) { return params; }
if (param.name === "limit" && param.value === 'None') { return params; }
- params.push(param.value);
+ params.push(param);
return params;
}, []);
@@ -1209,6 +1211,7 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb, resizeColum
switch (key) {
case "limit":
case "group_level":
+ if (!val) { return; }
$form.find("select[name='"+key+"']").val(val);
break;
case "include_docs":
@@ -1469,9 +1472,6 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb, resizeColum
that.advancedOptions.renderOnUpdatehasReduce(that.hasReduce());
}
- //that.advancedOptionsMenu.setHasReduce(that.hasReduce());
- //that.advancedOptionsMenu.render();
-
FauxtonAPI.triggerRouteEvent('updateAllDocs', {ddoc: ddocName, view: viewName});
}, function(xhr) {
@@ -1525,9 +1525,11 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb, resizeColum
}
var fragment = window.location.hash.replace(/\?.*$/, '');
- fragment = fragment + '?' + $.param(params);
- FauxtonAPI.navigate(fragment, {trigger: false});
+ if (!_.isEmpty(params)) {
+ fragment = fragment + '?' + $.param(params);
+ }
+ FauxtonAPI.navigate(fragment, {trigger: false});
FauxtonAPI.triggerRouteEvent('updateAllDocs', {ddoc: this.ddocID, view: this.viewName});
},
@@ -1712,11 +1714,6 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb, resizeColum
hasReduce: this.hasReduce(),
eventer: this.eventer
}));
-
- /*this.advancedOptionsMenu = this.insertView('#query-options-wrapper', new Views.AdvancedOptionsMenu({
- hasReduce: this.hasReduce(),
- eventer: this.eventer
- }));*/
}
},
@@ -1724,7 +1721,6 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb, resizeColum
afterRender: function() {
if (this.params && !this.newView) {
this.advancedOptions.updateFromParams(this.params);
- //this.advancedOptionsMenu.updateFromParams(this.params);
}
this.designDocSelector.updateDesignDoc();
@@ -1736,7 +1732,6 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb, resizeColum
this.$('#index-nav').parent().removeClass('active');
}
-
},
showEditors: function () {
@@ -1827,11 +1822,10 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb, resizeColum
return {
changes_url: '#' + this.database.url('changes'),
permissions_url: '#' + this.database.url('app') + '/permissions',
- db_url: '#' + this.database.url('index') + '?limit=' + Databases.DocLimit,
+ db_url: '#' + this.database.url('index'),
database: this.collection.database,
database_url: '#' + this.database.url('app'),
docLinks: docLinks,
- docLimit: Databases.DocLimit,
addLinks: addLinks,
newLinks: newLinks,
extensionList: extensionList > 0
http://git-wip-us.apache.org/repos/asf/couchdb/blob/98b54724/src/fauxton/app/addons/fauxton/components.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/addons/fauxton/components.js b/src/fauxton/app/addons/fauxton/components.js
index b31c623..f8032fe 100644
--- a/src/fauxton/app/addons/fauxton/components.js
+++ b/src/fauxton/app/addons/fauxton/components.js
@@ -71,15 +71,15 @@ function(app, FauxtonAPI, ace, spin) {
this.nextUrlfn = options.nextUrlfn;
this.scrollToSelector = options.scrollToSelector;
_.bindAll(this);
- this.pageNumber = 0;
+ this._pageNumber = [];
this._pageStart = 1;
this.perPage = 20;
- this.docLimit = options.docLimit || 100;
+ this.docLimit = options.docLimit || 1000000;
this.paramsHistory = [];
},
canShowPreviousfn: function () {
- if (this.pageNumber <= 0) {
+ if (this._pageStart === 1) {
return false;
}
return true;
@@ -102,8 +102,7 @@ function(app, FauxtonAPI, ace, spin) {
event.stopPropagation();
if (!this.canShowPreviousfn()) { return; }
- this.pageNumber = this.pageNumber -1;
- this.decPageStart();
+ this.decPageNumber();
FauxtonAPI.triggerRouteEvent('paginate', {
direction: 'previous',
@@ -112,25 +111,28 @@ function(app, FauxtonAPI, ace, spin) {
});
},
+ documentsLeftToFetch: function () {
+ var documentsLeftToFetch = this.docLimit - this.totalDocsViewed(),
+ limit = this.perPage;
+
+ if (documentsLeftToFetch < this.perPage ) {
+ limit = documentsLeftToFetch;
+ }
+
+ return limit;
+ },
+
nextClicked: function (event) {
event.preventDefault();
event.stopPropagation();
if (!this.canShowNextfn()) { return; }
this.paramsHistory.push(_.clone(this.collection.params));
- this.pageNumber = this.pageNumber + 1;
- this.incPageStart();
-
- var documentsLeftToFetch = this.docLimit - (this.pageNumber * this.perPage),
- limit = this.perPage;
-
- if (documentsLeftToFetch < this.perPage) {
- limit = documentsLeftToFetch;
- }
+ this.incPageNumber();
FauxtonAPI.triggerRouteEvent('paginate', {
direction: 'next',
- perPage: limit
+ perPage: this.documentsLeftToFetch()
});
},
@@ -150,11 +152,19 @@ function(app, FauxtonAPI, ace, spin) {
return this._pageStart - 1;
},
- incPageStart: function () {
+ incPageNumber: function () {
+ this._pageNumber.push({perPage: this.perPage});
this._pageStart = this._pageStart + this.perPage;
},
- decPageStart: function () {
+ totalDocsViewed: function () {
+ return _.reduce(this._pageNumber, function (total, value) {
+ return total + value.perPage;
+ }, 0);
+ },
+
+ decPageNumber: function () {
+ this._pageNumber.pop();
var val = this._pageStart - this.perPage;
if (val < 1) {
this._pageStart = 1;
@@ -175,7 +185,6 @@ function(app, FauxtonAPI, ace, spin) {
return this.page() + this.perPage;
}
-
});
//TODO allow more of the typeahead options.