]> source.dussan.org Git - nextcloud-server.git/commitdiff
Add pagination support for comments GUI
authorVincent Petry <pvince81@owncloud.com>
Thu, 28 Jan 2016 13:24:12 +0000 (14:24 +0100)
committerVincent Petry <pvince81@owncloud.com>
Tue, 2 Feb 2016 17:01:15 +0000 (18:01 +0100)
apps/comments/js/commentcollection.js
apps/comments/js/commentstabview.js
core/js/oc-backbone-webdav.js
core/vendor/davclient.js/lib/client.js

index 61b5adb7da7eb80e477e0d78cc492e4eb6568656..1fda4a4c709e713b8c68d8a3acd3d5d11a6e3948 100644 (file)
@@ -10,9 +10,7 @@
 
 (function(OC, OCA) {
 
-       function filterFunction(model, term) {
-               return model.get('name').substr(0, term.length) === term;
-       }
+       var NS_OWNCLOUD = 'http://owncloud.org/ns';
 
        /**
         * @class OCA.Comments.CommentsCollection
@@ -32,7 +30,7 @@
                _objectId: null,
 
                _endReached: false,
-               _currentIndex: 0,
+               _limit : 5,
 
                initialize: function(models, options) {
                        options = options || {};
                        return !this._endReached;
                },
 
+               reset: function() {
+                       this._endReached = false;
+                       return OC.Backbone.Collection.prototype.reset.apply(this, arguments);
+               },
+
                /**
                 * Fetch the next set of results
                 */
-               fetchNext: function() {
+               fetchNext: function(options) {
+                       var self = this;
                        if (!this.hasMoreResults()) {
                                return null;
                        }
-                       if (this._currentIndex === 0) {
-                               return this.fetch();
+
+                       var body = '<?xml version="1.0" encoding="utf-8" ?>\n' +
+                               '<D:report xmlns:D="DAV:" xmlns:oc="http://owncloud.org/ns">\n' +
+                               '   <oc:limit>' + this._limit + '</oc:limit>\n';
+
+                       if (this.length > 0) {
+                               body += '   <oc:datetime>' + this.first().get('creationDateTime') + '</oc:datetime>\n';
                        }
-                       return this.fetch({remove: false});
-               },
 
-               reset: function() {
-                       this._currentIndex = 0;
-                       OC.Backbone.Collection.prototype.reset.apply(this, arguments);
+                       body += '</D:report>\n';
+
+                       var oldLength = this.length;
+
+                       options = options || {};
+                       var success = options.success;
+                       options = _.extend({
+                               remove: false,
+                               data: body,
+                               davProperties: CommentsCollection.prototype.model.prototype.davProperties,
+                               success: function(resp) {
+                                       if (resp.length === oldLength) {
+                                               // no new entries, end reached
+                                               self._endReached = true;
+                                       }
+                                       if (!self.set(resp, options)) {
+                                               return false;
+                                       }
+                                       if (success) {
+                                               success.apply(null, arguments);
+                                       }
+                                       self.trigger('sync', 'REPORT', self, options);
+                               }
+                       }, options);
+
+                       return this.sync('REPORT', this, options);
                }
        });
 
index b1a3f854fe13338bfbb009d43919e731a947f7d9..6e51173280303da425fd807c84405c6d05ee3cf0 100644 (file)
                '   </ul>' +
                '</div>' +
                '<div class="empty hidden">{{emptyResultLabel}}</div>' +
-               /*
                '<input type="button" class="showMore hidden" value="{{moreLabel}}"' +
                ' name="show-more" id="show-more" />' +
-               */
                '<div class="loading hidden" style="height: 50px"></div>';
 
        var COMMENT_TEMPLATE =
@@ -44,7 +42,8 @@
                className: 'tab commentsTabView',
 
                events: {
-                       'submit .newCommentForm': '_onSubmitComment'
+                       'submit .newCommentForm': '_onSubmitComment',
+                       'click .showMore': '_onClickShowMore'
                },
 
                initialize: function() {
                        this.collection.fetchNext();
                },
 
-               _onClickShowMoreVersions: function(ev) {
+               _onClickShowMore: function(ev) {
                        ev.preventDefault();
                        this.nextPage();
                },
index 7c32116f01106f7048bb8753dc78027e27b901b4..d231a5b1ba01bb52aaeb24810421b8ceb32772c6 100644 (file)
         * @param {Object} davProperties properties mapping
         */
        function parsePropFindResult(result, davProperties) {
+               if (_.isArray(result)) {
+                       return _.map(result, function(subResult) {
+                               return parsePropFindResult(subResult, davProperties);
+                       });
+               }
                var props = {
                        href: result.href
                };
                        if (isSuccessStatus(response.status)) {
                                if (_.isFunction(options.success)) {
                                        var propsMapping = _.invert(options.davProperties);
-                                       var results;
+                                       var results = parsePropFindResult(response.body, propsMapping);
                                        if (options.depth > 0) {
-                                               results = _.map(response.body, function(data) {
-                                                       return parsePropFindResult(data, propsMapping);
-                                               });
                                                // discard root entry
                                                results.shift();
-                                       } else {
-                                               results = parsePropFindResult(response.body, propsMapping);
                                        }
 
                                        options.success(results);
                                        options.success(responseJson);
                                        return;
                                }
-                               options.success(result.body);
+                               // if multi-status, parse
+                               if (result.status === 207) {
+                                       var propsMapping = _.invert(options.davProperties);
+                                       options.success(parsePropFindResult(result.body, propsMapping));
+                               } else {
+                                       options.success(result.body);
+                               }
                        }
                });
        }
         * DAV transport
         */
        function davSync(method, model, options) {
-               var params = {type: methodMap[method]};
+               var params = {type: methodMap[method] || method};
                var isCollection = (model instanceof Backbone.Collection);
 
                if (method === 'update' && (model.usePUT || (model.collection && model.collection.usePUT))) {
index 1a73c7db020b7c5c04e957f50624e9c1d3e7453c..dbdfd3823e4ee66d06f7425b13d6f71fae0a5faa 100644 (file)
@@ -1,17 +1,17 @@
 if (typeof dav == 'undefined') { dav = {}; };
 
 dav._XML_CHAR_MAP = {
-       '<': '&lt;',
-       '>': '&gt;',
-       '&': '&amp;',
-       '"': '&quot;',
-       "'": '&apos;'
+    '<': '&lt;',
+    '>': '&gt;',
+    '&': '&amp;',
+    '"': '&quot;',
+    "'": '&apos;'
 };
 
 dav._escapeXml = function(s) {
-       return s.replace(/[<>&"']/g, function (ch) {
-               return dav._XML_CHAR_MAP[ch];
-       });
+    return s.replace(/[<>&"']/g, function (ch) {
+        return dav._XML_CHAR_MAP[ch];
+    });
 };
 
 dav.Client = function(options) {
@@ -79,17 +79,16 @@ dav.Client.prototype = {
         return this.request('PROPFIND', url, headers, body).then(
             function(result) {
 
-                var resultBody = this.parseMultiStatus(result.body);
                 if (depth===0) {
                     return {
                         status: result.status,
-                        body: resultBody[0],
+                        body: result.body[0],
                         xhr: result.xhr
                     };
                 } else {
                     return {
                         status: result.status,
-                        body: resultBody,
+                        body: result.body,
                         xhr: result.xhr
                     };
                 }
@@ -161,6 +160,7 @@ dav.Client.prototype = {
      */
     request : function(method, url, headers, body) {
 
+        var self = this;
         var xhr = this.xhrProvider();
 
         if (this.userName) {
@@ -182,8 +182,13 @@ dav.Client.prototype = {
                     return;
                 }
 
+                var resultBody = xhr.response;
+                if (xhr.status === 207) {
+                    resultBody = self.parseMultiStatus(xhr.response);
+                }
+
                 fulfill({
-                    body: xhr.response,
+                    body: resultBody,
                     status: xhr.status,
                     xhr: xhr
                 });