Skip to content

Commit

Permalink
Migrate files versions frontend to use dav for versions
Browse files Browse the repository at this point in the history
  • Loading branch information
DeepDiver1975 committed Nov 2, 2017
1 parent 704ccaa commit 8654b6c
Show file tree
Hide file tree
Showing 14 changed files with 98 additions and 562 deletions.
11 changes: 10 additions & 1 deletion apps/dav/lib/Meta/MetaFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
namespace OCA\DAV\Meta;


use OC\Files\Meta\MetaFileVersionNode;
use OCA\DAV\Files\ICopySource;
use Sabre\DAV\File;

/**
Expand All @@ -31,7 +33,7 @@
*
* @package OCA\DAV\Meta
*/
class MetaFile extends File {
class MetaFile extends File implements ICopySource {

/** @var \OCP\Files\File */
private $file;
Expand Down Expand Up @@ -83,4 +85,11 @@ public function getLastModified() {
public function getETag() {
return $this->file->getEtag();
}

public function copy($path) {
if ($this->file instanceof MetaFileVersionNode) {
return $this->file->copy($path);
}
return false;
}
}
2 changes: 0 additions & 2 deletions apps/dav/tests/unit/DAV/CopyPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,4 @@ public function testCopyPluginReturnFalse() {
$returnValue = $this->plugin->httpCopy($this->request, $this->response);
$this->assertFalse($returnValue);
}


}
56 changes: 0 additions & 56 deletions apps/files_versions/ajax/getVersions.php

This file was deleted.

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

This file was deleted.

7 changes: 0 additions & 7 deletions apps/files_versions/appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,3 @@ function() {
require_once __DIR__ . '/../ajax/preview.php';
});

$this->create('files_versions_download', 'download.php')
->actionInclude('files_versions/download.php');
$this->create('files_versions_ajax_getVersions', 'ajax/getVersions.php')
->actionInclude('files_versions/ajax/getVersions.php');
$this->create('files_versions_ajax_rollbackVersion', 'ajax/rollbackVersion.php')
->actionInclude('files_versions/ajax/rollbackVersion.php');

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

This file was deleted.

58 changes: 11 additions & 47 deletions apps/files_versions/js/versioncollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,79 +13,43 @@
* @memberof OCA.Versions
*/
var VersionCollection = OC.Backbone.Collection.extend({
sync: OC.Backbone.davSync,

model: OCA.Versions.VersionModel,

/**
* @var OCA.Files.FileInfoModel
*/
_fileInfo: null,

_endReached: false,
_currentIndex: 0,

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);
return OC.linkToRemoteBase('dav') + '/meta/' +
encodeURIComponent(this._fileInfo.get('id')) + '/v';
},

setFileInfo: function(fileInfo) {
this._fileInfo = fileInfo;
// reset
this._endReached = false;
this._currentIndex = 0;
},

getFileInfo: function() {
return this._fileInfo;
},

hasMoreResults: function() {
return !this._endReached;
},

fetch: function(options) {
if (!options || options.remove) {
this._currentIndex = 0;
}
return OC.Backbone.Collection.prototype.fetch.apply(this, arguments);
},

/**
* 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});
},

reset: function() {
this._currentIndex = 0;
OC.Backbone.Collection.prototype.reset.apply(this, arguments);
},

parse: function(result) {
var fullPath = this._fileInfo.getFullPath();
var results = _.map(result.data.versions, function(version) {
var revision = parseInt(version.version, 10);
var fileId = this._fileInfo.get('id');
var results = _.map(result, function(version) {
var revision = parseInt(version.id, 10);
return {
id: revision,
name: version.name,
name: revision,
fullPath: fullPath,
timestamp: revision,
size: version.size
versionId: revision,
size: version['{DAV:}getcontentlength'],
fileId: fileId
};
});
this._endReached = result.data.endReached;
this._currentIndex += results.length;
return results;
}
});
Expand Down
49 changes: 20 additions & 29 deletions apps/files_versions/js/versionmodel.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,25 @@
revert: function(options) {
options = options ? _.clone(options) : {};
var model = this;
var file = this.getFullPath();
var revision = this.get('timestamp');
var client = new OC.Files.Client({
host: OC.getHost(),
root: OC.linkToRemoteBase('dav') + '/files/' + OC.getCurrentUser().uid,
useHTTPS: OC.getProtocol() === 'https'
});

$.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);
client.copy(this.getDownloadUrl(), this.getFullPath(), true, {}, {pathIsUrl: 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() {
Expand All @@ -61,12 +55,9 @@
},

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);
return OC.linkToRemoteBase('dav') + '/meta/' +
encodeURIComponent(this.get('fileId')) + '/v/' +
encodeURIComponent(this.get('versionId'));
}
});

Expand Down
Loading

0 comments on commit 8654b6c

Please sign in to comment.