diff options
author | Robin Appelman <robin@icewind.nl> | 2018-10-11 16:59:04 +0200 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2018-10-11 20:42:41 +0200 |
commit | ee84d8351953ed8afee9abcd8fc7cb1449e44a4b (patch) | |
tree | 9c6696889c3cb97410be1b390f51547ccd324ddf /apps/files_versions/js/versioncollection.js | |
parent | 6e56a7b31e89b7abea4e9bcf78eec21f54dfd74c (diff) | |
download | nextcloud-server-ee84d8351953ed8afee9abcd8fc7cb1449e44a4b.tar.gz nextcloud-server-ee84d8351953ed8afee9abcd8fc7cb1449e44a4b.zip |
move versions webui over to the dav api
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'apps/files_versions/js/versioncollection.js')
-rw-r--r-- | apps/files_versions/js/versioncollection.js | 86 |
1 files changed, 36 insertions, 50 deletions
diff --git a/apps/files_versions/js/versioncollection.js b/apps/files_versions/js/versioncollection.js index 24a4ba7fc62..e48368adfa2 100644 --- a/apps/files_versions/js/versioncollection.js +++ b/apps/files_versions/js/versioncollection.js @@ -8,86 +8,72 @@ * */ -(function() { +(function () { /** * @memberof OCA.Versions */ var VersionCollection = OC.Backbone.Collection.extend({ model: OCA.Versions.VersionModel, + sync: OC.Backbone.davSync, /** * @var OCA.Files.FileInfoModel */ _fileInfo: null, - _endReached: false, - _currentIndex: 0, + _currentUser: null, - url: function() { - var url = OC.generateUrl('/apps/files_versions/ajax/getVersions.php'); - var query = { - source: this._fileInfo.getFullPath(), - start: this._currentIndex - }; - return url + '?' + OC.buildQueryString(query); - }, + _client: null, - setFileInfo: function(fileInfo) { + setFileInfo: function (fileInfo) { this._fileInfo = fileInfo; - // reset - this._endReached = false; - this._currentIndex = 0; }, - getFileInfo: function() { + getFileInfo: function () { return this._fileInfo; }, - hasMoreResults: function() { - return !this._endReached; + setCurrentUser: function(user) { + this._currentUser = user; }, - fetch: function(options) { - if (!options || options.remove) { - this._currentIndex = 0; - } - return OC.Backbone.Collection.prototype.fetch.apply(this, arguments); + getCurrentUser: function() { + return this._currentUser || OC.getCurrentUser().uid; }, - /** - * Fetch the next set of results - */ - fetchNext: function() { - if (!this.hasMoreResults()) { - return null; - } - if (this._currentIndex === 0) { - return this.fetch(); - } - return this.fetch({remove: false}); + setClient: function(client) { + this._client = client; + }, + + getClient: function() { + return this._client || new OC.Files.Client({ + host: OC.getHost(), + root: OC.linkToRemoteBase('dav') + '/versions/' + this.getCurrentUser(), + useHTTPS: OC.getProtocol() === 'https' + }); }, - reset: function() { - this._currentIndex = 0; - OC.Backbone.Collection.prototype.reset.apply(this, arguments); + url: function () { + return OC.linkToRemoteBase('dav') + '/versions/' + this.getCurrentUser() + '/versions/' + this._fileInfo.get('id'); }, parse: function(result) { var fullPath = this._fileInfo.getFullPath(); - var results = _.map(result.data.versions, function(version) { - var revision = parseInt(version.version, 10); - return { - id: revision, - name: version.name, - fullPath: fullPath, - timestamp: revision, - size: version.size, - mimetype: version.mimetype - }; + var fileId = this._fileInfo.get('id'); + var name = this._fileInfo.get('name'); + var user = this.getCurrentUser(); + var client = this.getClient(); + return _.map(result, function(version) { + version.fullPath = fullPath; + version.fileId = fileId; + version.name = name; + version.timestamp = parseInt(moment(new Date(version.timestamp)).format('X'), 10); + version.id = parseInt(OC.basename(version.href), 10); + version.size = parseInt(version.size, 10); + version.user = user; + version.client = client; + return version; }); - this._endReached = result.data.endReached; - this._currentIndex += results.length; - return results; } }); |