couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gar...@apache.org
Subject git commit: updated refs/heads/fauxton-pagination to 4362cc6
Date Tue, 07 Jan 2014 12:30:45 GMT
Updated Branches:
  refs/heads/fauxton-pagination [created] 4362cc6b5


Improve pagination


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

Branch: refs/heads/fauxton-pagination
Commit: 4362cc6b5ec59a24fae400abe53249f8d838a62d
Parents: 1c0fe36
Author: Garren Smith <garren.smith@gmail.com>
Authored: Tue Jan 7 14:30:30 2014 +0200
Committer: Garren Smith <garren.smith@gmail.com>
Committed: Tue Jan 7 14:30:30 2014 +0200

----------------------------------------------------------------------
 src/fauxton/app/modules/documents/resources.js  | 39 +++++++++++---------
 src/fauxton/app/modules/documents/routes.js     |  2 -
 src/fauxton/app/modules/documents/views.js      | 17 +++++++--
 src/fauxton/app/modules/fauxton/components.js   |  9 +++--
 .../templates/documents/all_docs_number.html    |  2 +-
 5 files changed, 40 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/4362cc6b/src/fauxton/app/modules/documents/resources.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/modules/documents/resources.js b/src/fauxton/app/modules/documents/resources.js
index 83589ca..4258c2a 100644
--- a/src/fauxton/app/modules/documents/resources.js
+++ b/src/fauxton/app/modules/documents/resources.js
@@ -225,6 +225,10 @@ function(app, FauxtonAPI) {
   });
 
   Documents.ViewRow = Backbone.Model.extend({
+    // this is a hack so that backbone.collections doesn't group 
+    // these by id and reduce the number of items returned.
+    idAttribute: "_id",
+
     docType: function() {
       if (!this.id) return "reduction";
 
@@ -329,16 +333,15 @@ function(app, FauxtonAPI) {
       return this.url('app');
     },
 
-    urlPreviousPage: function (num, firstId) {
-      this.params.limit = num;
-      if (firstId) { 
-        this.params.startkey_docid = '"' + firstId + '"';
-        this.params.startkey = '"' + firstId + '"';
+    urlPreviousPage: function (num, params) {
+      if (params) { 
+        this.params = params;
       } else {
-        delete this.params.startkey;
-        delete this.params.startkey_docid;
+        this.params = {reduce: false};
       }
-      return this.url('app');
+
+      this.params.limit = num;
+      return this.url('app'); 
     },
 
     totalRows: function() {
@@ -429,24 +432,24 @@ function(app, FauxtonAPI) {
 
     urlNextPage: function (num, lastId) {
       if (!lastId) {
-        lastId = this.last().id;
+        lastDoc = this.last();
       }
 
-      this.params.startkey_docid = '"' + lastId + '"';
-      this.params.startkey = '"' + lastId + '"';
+      this.params.startkey_docid = '"' + lastDoc.get("id") + '"';
+      this.params.startkey = '"' + lastDoc.get('key') + '"';
       this.params.limit = num;
+      console.log('url next params', this.params, lastDoc);
       return this.url('app');
     },
 
-     urlPreviousPage: function (num, firstId) {
-      this.params.limit = num;
-      if (firstId) { 
-        this.params.startkey_docid = '"' + firstId + '"';
-        this.params.startkey = '"' + firstId + '"';
+     urlPreviousPage: function (num, params) {
+      if (params) { 
+        this.params = params;
       } else {
-        delete this.params.startkey;
-        delete this.params.startkey_docid;
+        this.params = {reduce: false};
       }
+
+      this.params.limit = num;
       return this.url('app');
     },
 

http://git-wip-us.apache.org/repos/asf/couchdb/blob/4362cc6b/src/fauxton/app/modules/documents/routes.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/modules/documents/routes.js b/src/fauxton/app/modules/documents/routes.js
index 538cd56..493f892 100644
--- a/src/fauxton/app/modules/documents/routes.js
+++ b/src/fauxton/app/modules/documents/routes.js
@@ -234,8 +234,6 @@ function(app, FauxtonAPI, Documents, Databases) {
         params: params
       });
 
-
-
       var ddocInfo = {
         id: "_design/" + decodeDdoc,
         currView: view,

http://git-wip-us.apache.org/repos/asf/couchdb/blob/4362cc6b/src/fauxton/app/modules/documents/views.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/modules/documents/views.js b/src/fauxton/app/modules/documents/views.js
index e155435..747f828 100644
--- a/src/fauxton/app/modules/documents/views.js
+++ b/src/fauxton/app/modules/documents/views.js
@@ -446,6 +446,7 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb, resizeColum
 
     initialize: function (options) {
       this.newView = options.newView || false;
+      this.showNumbers = options.showNumbers;
       
       this.listenTo(this.collection, 'totalRows:decrement', this.render);
     },
@@ -467,6 +468,7 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb, resizeColum
         updateSeq: updateSeq,
         offset: recordStart,
         totalRows: totalRows,
+        showNumbers: this.showNumbers,
         numModels: this.collection.models.length + recordStart - 1,
       };
     }
@@ -672,17 +674,17 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb,
resizeColum
         collection: this.collection,
         scrollToSelector: '#dashboard-content',
         previousUrlfn: function () {
-          return collection.urlPreviousPage(20, this.previousIds.pop());
+          return collection.urlPreviousPage(20, this.previousParams.pop());
         },
         canShowPreviousfn: function () {
-          if (collection.viewMeta.offset === 0) {
+          if (this.previousParams.length === 0) {
             return false;
           }
 
           return true;
         },
         canShowNextfn: function () {
-          if (collection.length === 0 || (collection.viewMeta.offset + collection.length
+ 2) >= collection.viewMeta.total_rows) {
+          if (collection.length < 20) {
             return false;
           }
 
@@ -696,9 +698,16 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb,
resizeColum
     },
 
     beforeRender: function() {
+      var showNumbers = true;
+
+      if (this.designDocs || this.collection.params.startkey === '"_design"') {
+        showNumbers = false;
+      }
+
       this.allDocsNumber = this.setView('#item-numbers', new Views.AllDocsNumber({
         collection: this.collection,
-        newView: this.newView
+        newView: this.newView,
+        showNumbers: showNumbers
       }));
 
       this.insertView('#documents-pagination', this.pagination);

http://git-wip-us.apache.org/repos/asf/couchdb/blob/4362cc6b/src/fauxton/app/modules/fauxton/components.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/modules/fauxton/components.js b/src/fauxton/app/modules/fauxton/components.js
index 6afe046..65ced15 100644
--- a/src/fauxton/app/modules/fauxton/components.js
+++ b/src/fauxton/app/modules/fauxton/components.js
@@ -60,7 +60,7 @@ function(app, FauxtonAPI, ace) {
       "click a#previous": 'previousClicked'
     },
 
-    previousIds: [],
+    previousParams: [],
 
     scrollTo: function () {
       if (!this.scrollToSelector) { return; }
@@ -88,10 +88,11 @@ function(app, FauxtonAPI, ace) {
       event.preventDefault();
       event.stopPropagation();
       if (!this.canShowNextfn()) { return; }
-      var doc = this.collection.first();
 
-      if (doc) {
-        this.previousIds.push(doc.id);
+      var params = _.clone(this.collection.params);
+
+      if (params) {
+        this.previousParams.push(params);
       }
 
       FauxtonAPI.navigate(this.nextUrlfn(), {trigger: false});

http://git-wip-us.apache.org/repos/asf/couchdb/blob/4362cc6b/src/fauxton/app/templates/documents/all_docs_number.html
----------------------------------------------------------------------
diff --git a/src/fauxton/app/templates/documents/all_docs_number.html b/src/fauxton/app/templates/documents/all_docs_number.html
index c4ea8f6..77ef36a 100644
--- a/src/fauxton/app/templates/documents/all_docs_number.html
+++ b/src/fauxton/app/templates/documents/all_docs_number.html
@@ -13,7 +13,7 @@ the License.
 -->
 <% if (totalRows === "unknown"){ %>
   Showing 0 documents. <a href="#/database/<%=database%>/new"> Create your first
document.</a>
-<% } else { %>
+<% } else if (showNumbers) { %>
   Showing <%=offset%> - <%= numModels %> of <%= totalRows %> rows
 <%}%>
 <% if (updateSeq) { %>


Mime
View raw message