allow reverting file from history dropdown
This commit is contained in:
parent
4ccfd27fa2
commit
bfdb374a2c
3 changed files with 29 additions and 42 deletions
|
@ -1,7 +1,4 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
require_once('lib/base.php');
|
|
||||||
|
|
||||||
OCP\JSON::checkAppEnabled('files_versions');
|
OCP\JSON::checkAppEnabled('files_versions');
|
||||||
|
|
||||||
require_once('apps/files_versions/versions.php');
|
require_once('apps/files_versions/versions.php');
|
||||||
|
@ -14,15 +11,8 @@ if( OCA_Versions\Storage::isversioned( $source ) ) {
|
||||||
|
|
||||||
$count=5; //show the newest revisions
|
$count=5; //show the newest revisions
|
||||||
$versions = OCA_Versions\Storage::getversions( $source, $count);
|
$versions = OCA_Versions\Storage::getversions( $source, $count);
|
||||||
$versionsFormatted = array();
|
|
||||||
|
|
||||||
foreach ( $versions AS $version ) {
|
|
||||||
|
|
||||||
$versionsFormatted[] = OCP\Util::formatDate( $version );
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
$versionsSorted = array_reverse( $versionsFormatted );
|
$versionsSorted = array_reverse( $versions );
|
||||||
|
|
||||||
if ( !empty( $versionsSorted ) ) {
|
if ( !empty( $versionsSorted ) ) {
|
||||||
OCP\JSON::encodedPrint($versionsSorted);
|
OCP\JSON::encodedPrint($versionsSorted);
|
||||||
|
|
|
@ -1,26 +1,18 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
require_once('../../../lib/base.php');
|
|
||||||
OCP\JSON::checkAppEnabled('files_versions');
|
OCP\JSON::checkAppEnabled('files_versions');
|
||||||
require_once('../versions.php');
|
|
||||||
|
require_once('apps/files_versions/versions.php');
|
||||||
|
|
||||||
$userDirectory = "/".OCP\USER::getUser()."/files";
|
$userDirectory = "/".OCP\USER::getUser()."/files";
|
||||||
|
|
||||||
$source = $_GET['source'];
|
$file = $_GET['file'];
|
||||||
|
$revision=(int)$_GET['revision'];
|
||||||
|
|
||||||
$source = strip_tags( $source );
|
if( OCA_Versions\Storage::isversioned( $file ) ) {
|
||||||
|
if(OCA_Versions\Storage::rollback( $file, $revision )){
|
||||||
echo "\n\n$source\n\n";
|
OCP\JSON::success(array("data" => array( "revision" => $revision, "file" => $file )));
|
||||||
|
}else{
|
||||||
$revision = strtotime( $source );
|
OCP\JSON::error(array("data" => array( "message" => "Could not revert:" . $file )));
|
||||||
|
}
|
||||||
echo "\n\n$revision\n\n";
|
|
||||||
|
|
||||||
if( OCA_Versions\Storage::isversioned( $source ) ) {
|
|
||||||
|
|
||||||
|
|
||||||
#\OCA_Versions\Storage::rollback( $source, $revision );
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
|
@ -34,7 +34,7 @@ function createVersionsDropdown(filename, files) {
|
||||||
html += '</select>';
|
html += '</select>';
|
||||||
html += '</div>';
|
html += '</div>';
|
||||||
//html += '<input type="button" value="Revert file" onclick="revertFile()" />';
|
//html += '<input type="button" value="Revert file" onclick="revertFile()" />';
|
||||||
html += '<input type="button" value="Revert file..." onclick="window.location=\''+historyUrl+'\'" name="makelink" id="makelink" />';
|
html += '<input type="button" value="All versions..." onclick="window.location=\''+historyUrl+'\'" name="makelink" id="makelink" />';
|
||||||
html += '<br />';
|
html += '<br />';
|
||||||
html += '<input id="link" style="display:none; width:90%;" />';
|
html += '<input id="link" style="display:none; width:90%;" />';
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ function createVersionsDropdown(filename, files) {
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: 'GET',
|
type: 'GET',
|
||||||
url: OC.linkTo('files_versions', 'ajax/getVersions.php'),
|
url: OC.filePath('files_versions', 'ajax', 'getVersions.php'),
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
data: { source: files },
|
data: { source: files },
|
||||||
async: false,
|
async: false,
|
||||||
|
@ -58,34 +58,39 @@ function createVersionsDropdown(filename, files) {
|
||||||
if (versions) {
|
if (versions) {
|
||||||
|
|
||||||
$.each( versions, function(index, row ) {
|
$.each( versions, function(index, row ) {
|
||||||
|
addVersion( row );
|
||||||
addVersion( row );
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
$('#found_versions').change(function(){
|
||||||
|
var revision=parseInt($(this).val());
|
||||||
|
revertFile(files,revision);
|
||||||
|
})
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function revertFile() {
|
function revertFile(file, revision) {
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: 'GET',
|
type: 'GET',
|
||||||
url: OC.linkTo('files_versions', 'ajax/rollbackVersion.php'),
|
url: OC.linkTo('files_versions', 'ajax/rollbackVersion.php'),
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
data: {path: file, revision: 'revision'},
|
data: {file: file, revision: revision},
|
||||||
async: false,
|
async: false,
|
||||||
success: function(versions) {
|
success: function(response) {
|
||||||
if (versions) {
|
if (response.status=='error') {
|
||||||
|
OC.dialogs.alert('Failed to revert '+file+' to revision '+formatDate(revision*1000)+'.','Failed to revert');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function addVersion( name ) {
|
function addVersion(revision ) {
|
||||||
|
name=formatDate(revision*1000);
|
||||||
var version = '<option>'+name+'</option>';
|
var version=$('<option/>');
|
||||||
|
version.attr('value',revision);
|
||||||
|
version.text(name);
|
||||||
|
|
||||||
// } else {
|
// } else {
|
||||||
// var checked = ((permissions > 0) ? 'checked="checked"' : 'style="display:none;"');
|
// var checked = ((permissions > 0) ? 'checked="checked"' : 'style="display:none;"');
|
||||||
|
@ -98,7 +103,7 @@ function createVersionsDropdown(filename, files) {
|
||||||
// user += '</li>';
|
// user += '</li>';
|
||||||
// }
|
// }
|
||||||
|
|
||||||
$(version).appendTo('#found_versions');
|
version.appendTo('#found_versions');
|
||||||
}
|
}
|
||||||
|
|
||||||
$('#dropdown').show('blind');
|
$('#dropdown').show('blind');
|
||||||
|
|
Loading…
Reference in a new issue