Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 0 additions & 56 deletions apps/files_versions/ajax/getVersions.php

This file was deleted.

41 changes: 0 additions & 41 deletions apps/files_versions/ajax/rollbackVersion.php

This file was deleted.

59 changes: 0 additions & 59 deletions apps/files_versions/download.php

This file was deleted.

4 changes: 3 additions & 1 deletion apps/files_versions/js/templates.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apps/files_versions/js/templates/item.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
86 changes: 36 additions & 50 deletions apps/files_versions/js/versioncollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
});

Expand Down
63 changes: 29 additions & 34 deletions apps/files_versions/js/versionmodel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -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');
}
});

Expand Down
Loading