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 | |
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')
-rw-r--r-- | apps/files_versions/js/templates.js | 4 | ||||
-rw-r--r-- | apps/files_versions/js/templates/item.handlebars | 2 | ||||
-rw-r--r-- | apps/files_versions/js/versioncollection.js | 86 | ||||
-rw-r--r-- | apps/files_versions/js/versionmodel.js | 63 | ||||
-rw-r--r-- | apps/files_versions/js/versionstabview.js | 74 |
5 files changed, 80 insertions, 149 deletions
diff --git a/apps/files_versions/js/templates.js b/apps/files_versions/js/templates.js index 17293d763df..cf2c236daca 100644 --- a/apps/files_versions/js/templates.js +++ b/apps/files_versions/js/templates.js @@ -24,7 +24,9 @@ templates['item'] = template({"1":function(container,depth0,helpers,partials,dat + alias4(((helper = (helper = helpers.previewUrl || (depth0 != null ? depth0.previewUrl : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"previewUrl","hash":{},"data":data}) : helper))) + "\" width=\"44\" height=\"44\"/>\n </div>\n <div class=\"version-container\">\n <div>\n <a href=\"" + alias4(((helper = (helper = helpers.downloadUrl || (depth0 != null ? depth0.downloadUrl : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"downloadUrl","hash":{},"data":data}) : helper))) - + "\" class=\"downloadVersion\"><img src=\"" + + "\" class=\"downloadVersion\" download=\"" + + alias4(((helper = (helper = helpers.downloadName || (depth0 != null ? depth0.downloadName : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"downloadName","hash":{},"data":data}) : helper))) + + "\"><img src=\"" + alias4(((helper = (helper = helpers.downloadIconUrl || (depth0 != null ? depth0.downloadIconUrl : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"downloadIconUrl","hash":{},"data":data}) : helper))) + "\" />\n <span class=\"versiondate has-tooltip live-relative-timestamp\" data-timestamp=\"" + alias4(((helper = (helper = helpers.millisecondsTimestamp || (depth0 != null ? depth0.millisecondsTimestamp : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"millisecondsTimestamp","hash":{},"data":data}) : helper))) diff --git a/apps/files_versions/js/templates/item.handlebars b/apps/files_versions/js/templates/item.handlebars index 6d11b9c0888..e34be4bd025 100644 --- a/apps/files_versions/js/templates/item.handlebars +++ b/apps/files_versions/js/templates/item.handlebars @@ -5,7 +5,7 @@ </div> <div class="version-container"> <div> - <a href="{{downloadUrl}}" class="downloadVersion"><img src="{{downloadIconUrl}}" /> + <a href="{{downloadUrl}}" class="downloadVersion" download="{{downloadName}}"><img src="{{downloadIconUrl}}" /> <span class="versiondate has-tooltip live-relative-timestamp" data-timestamp="{{millisecondsTimestamp}}" title="{{formattedTimestamp}}">{{relativeTimestamp}}</span> </a> </div> 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; } }); diff --git a/apps/files_versions/js/versionmodel.js b/apps/files_versions/js/versionmodel.js index dc610fc2144..15469927475 100644 --- a/apps/files_versions/js/versionmodel.js +++ b/apps/files_versions/js/versionmodel.js @@ -8,50 +8,50 @@ * */ -(function() { +/* global moment */ + +(function () { /** * @memberof OCA.Versions */ var VersionModel = OC.Backbone.Model.extend({ + sync: OC.Backbone.davSync, + + davProperties: { + 'size': '{DAV:}getcontentlength', + 'mimetype': '{DAV:}getcontenttype', + 'timestamp': '{DAV:}getlastmodified', + }, /** * Restores the original file to this revision */ - revert: function(options) { + revert: function (options) { options = options ? _.clone(options) : {}; var model = this; - var file = this.getFullPath(); - var revision = this.get('timestamp'); - $.ajax({ - type: 'GET', - url: OC.generateUrl('/apps/files_versions/ajax/rollbackVersion.php'), - dataType: 'json', - data: { - file: file, - revision: revision - }, - success: function(response) { - if (response.status === 'error') { - if (options.error) { - options.error.call(options.context, model, response, options); - } - model.trigger('error', model, response, options); - } else { - if (options.success) { - options.success.call(options.context, model, response, options); - } - model.trigger('revert', model, response, options); + var client = this.get('client'); + + return client.move('/versions/' + this.get('fileId') + '/' + this.get('id'), '/restore/target', true) + .done(function () { + if (options.success) { + options.success.call(options.context, model, {}, options); + } + model.trigger('revert', model, options); + }) + .fail(function () { + if (options.error) { + options.error.call(options.context, model, {}, options); } - } - }); + model.trigger('error', model, {}, options); + }); }, - getFullPath: function() { + getFullPath: function () { return this.get('fullPath'); }, - getPreviewUrl: function() { + getPreviewUrl: function () { var url = OC.generateUrl('/apps/files_versions/preview'); var params = { file: this.get('fullPath'), @@ -60,13 +60,8 @@ return url + '?' + OC.buildQueryString(params); }, - getDownloadUrl: function() { - var url = OC.generateUrl('/apps/files_versions/download.php'); - var params = { - file: this.get('fullPath'), - revision: this.get('timestamp') - }; - return url + '?' + OC.buildQueryString(params); + getDownloadUrl: function () { + return OC.linkToRemoteBase('dav') + '/versions/' + this.get('user') + '/versions/' + this.get('fileId') + '/' + this.get('id'); } }); diff --git a/apps/files_versions/js/versionstabview.js b/apps/files_versions/js/versionstabview.js index dacd567fdc9..61309a30d50 100644 --- a/apps/files_versions/js/versionstabview.js +++ b/apps/files_versions/js/versionstabview.js @@ -8,14 +8,11 @@ * */ -/* @global Handlebars */ - (function() { /** * @memberof OCA.Versions */ - var VersionsTabView = OCA.Files.DetailTabView.extend( - /** @lends OCA.Versions.VersionsTabView.prototype */ { + var VersionsTabView = OCA.Files.DetailTabView.extend(/** @lends OCA.Versions.VersionsTabView.prototype */{ id: 'versionsTabView', className: 'tab versionsTabView', @@ -24,8 +21,7 @@ $versionsContainer: null, events: { - 'click .revertVersion': '_onClickRevertVersion', - 'click .showMoreVersions': '_onClickShowMoreVersions' + 'click .revertVersion': '_onClickRevertVersion' }, initialize: function() { @@ -43,19 +39,14 @@ }, nextPage: function() { - if (this._loading || !this.collection.hasMoreResults()) { + if (this._loading) { return; } if (this.collection.getFileInfo() && this.collection.getFileInfo().isDirectory()) { return; } - this.collection.fetchNext(); - }, - - _onClickShowMoreVersions: function(ev) { - ev.preventDefault(); - this.nextPage(); + this.collection.fetch(); }, _onClickRevertVersion: function(ev) { @@ -70,8 +61,6 @@ ev.preventDefault(); revision = $target.attr('data-revision'); - this.$el.find('.versions, .showMoreVersions').addClass('hidden'); - var versionModel = this.collection.get(revision); versionModel.revert({ success: function() { @@ -79,7 +68,7 @@ self.$versionsContainer.empty(); self.collection.setFileInfo(fileInfoModel); self.collection.reset([], {silent: true}); - self.collection.fetchNext(); + self.collection.fetch(); self.$el.find('.versions').removeClass('hidden'); @@ -97,7 +86,7 @@ fileInfoModel.trigger('busy', fileInfoModel, false); self.$el.find('.versions').removeClass('hidden'); self._toggleLoading(false); - OC.Notification.show(t('files_version', 'Failed to revert {file} to revision {timestamp}.', + OC.Notification.show(t('files_version', 'Failed to revert {file} to revision {timestamp}.', { file: versionModel.getFullPath(), timestamp: OC.Util.formatDate(versionModel.get('timestamp') * 1000) @@ -121,27 +110,16 @@ _onRequest: function() { this._toggleLoading(true); - this.$el.find('.showMoreVersions').addClass('hidden'); }, _onEndRequest: function() { this._toggleLoading(false); this.$el.find('.empty').toggleClass('hidden', !!this.collection.length); - this.$el.find('.showMoreVersions').toggleClass('hidden', !this.collection.hasMoreResults()); }, _onAddModel: function(model) { var $el = $(this.itemTemplate(this._formatItem(model))); this.$versionsContainer.append($el); - - var preview = $el.find('.preview')[0]; - this._lazyLoadPreview({ - url: model.getPreviewUrl(), - mime: model.get('mimetype'), - callback: function(url) { - preview.src = url; - } - }); $el.find('.has-tooltip').tooltip(); }, @@ -168,8 +146,9 @@ _formatItem: function(version) { var timestamp = version.get('timestamp') * 1000; var size = version.has('size') ? version.get('size') : 0; + return _.extend({ - millisecondsTimestamp: timestamp, + versionId: version.get('id'), formattedTimestamp: OC.Util.formatDate(timestamp), relativeTimestamp: OC.Util.relativeModifiedDate(timestamp), humanReadableSize: OC.Util.humanFileSize(size, true), @@ -177,7 +156,9 @@ hasDetails: version.has('size'), downloadUrl: version.getDownloadUrl(), downloadIconUrl: OC.imagePath('core', 'actions/download'), + downloadName: version.get('name'), revertIconUrl: OC.imagePath('core', 'actions/history'), + previewUrl: version.getPreviewUrl(), revertLabel: t('files_versions', 'Restore'), canRevert: (this.collection.getFileInfo().get('permissions') & OC.PERMISSION_UPDATE) !== 0 }, version.attributes); @@ -188,8 +169,7 @@ */ render: function() { this.$el.html(this.template({ - emptyResultLabel: t('files_versions', 'No earlier versions available'), - moreVersionsLabel: t('files_versions', 'More versions …') + emptyResultLabel: t('files_versions', 'No other versions available'), })); this.$el.find('.has-tooltip').tooltip(); this.$versionsContainer = this.$el.find('ul.versions'); @@ -206,38 +186,6 @@ return false; } return !fileInfo.isDirectory(); - }, - - /** - * Lazy load a file's preview. - * - * @param path path of the file - * @param mime mime type - * @param callback callback function to call when the image was loaded - * @param etag file etag (for caching) - */ - _lazyLoadPreview : function(options) { - var url = options.url; - var mime = options.mime; - var ready = options.callback; - - // get mime icon url - var iconURL = OC.MimeType.getIconUrl(mime); - ready(iconURL); // set mimeicon URL - - var img = new Image(); - img.onload = function(){ - // if loading the preview image failed (no preview for the mimetype) then img.width will < 5 - if (img.width > 5) { - ready(url, img); - } else if (options.error) { - options.error(); - } - }; - if (options.error) { - img.onerror = options.error; - } - img.src = url; } }); |