Github user deathbearbrown commented on a diff in the pull request:

    https://github.com/apache/couchdb/pull/162#discussion_r10220399
  
    --- Diff: src/fauxton/app/addons/documents/routes.js ---
    @@ -345,14 +376,62 @@ function(app, FauxtonAPI, Documents, Databases) {
           }));
         },
     
    -    paginate: function (direction) {
    -      _.extend(this.documentsView.collection.params, app.getParams());
    +    perPageChange: function (perPage) {
    +      var params = app.getParams();
    +      this.perPage = perPage;
    +      this.documentsView.updatePerPage(perPage);
    +      this.documentsView.forceRender();
    +      params.limit = perPage;
    +      this.documentsView.collection.params = params;
    +      this.setDocPerPageLimit(perPage);
    +    },
    +
    +    paginate: function (options) {
    +      var params = {},
    +          urlParams = app.getParams(),
    +          collection = this.documentsView.collection;
    +
           this.documentsView.forceRender();
    -      if (direction === 'next') {
    -        this.documentsView.collection.skipFirstItem = true;
    +      var rawCollection = collection.map(function (item) { return 
item.toJSON(); });
    +
    +      // this is really ugly. But we basically need to make sure that
    +      // all parameters are in the correct state and have been parsed 
before we
    +      // calculate how to paginate the collection
    +      _.each(['startkey', 'endkey', 'key'], function (key) {
    +        if (_.has(collection.params, key)) {
    +          collection.params[key] = JSON.parse(collection.params[key]);
    +        }
    +
    +        if (_.has(urlParams, key)) {
    +          urlParams[key] = JSON.parse(urlParams[key]);
    +        }
    +      });
    +
    +      if (options.direction === 'next') {
    +          params = Documents.paginate.next(rawCollection, 
    +                                           collection.params,
    +                                           options.perPage, 
    +                                           !!collection.isAllDocs);
           } else {
    -        this.documentsView.collection.skipFirstItem = false;
    +          params = Documents.paginate.previous(rawCollection, 
    +                                               collection.params, 
    +                                               options.perPage, 
    +                                               !!collection.isAllDocs);
           }
    +
    +      // use the perPage sent from IndexPagination as it calculates how 
many
    +      // docs to fetch for next page
    +      params.limit = options.perPage;
    +
    +      // again not pretty but need to make sure all the parameters can be 
correctly
    +      // built into a query
    +      _.each(['startkey', 'endkey', 'key'], function (key) {
    --- End diff --
    
    same as prev. comment.  Just pull it out and then you can reuse it. 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to