added revert attempt outcome messages, removed contextual ajax revert button for now as it's not functional, improved readaibility of scripts

This commit is contained in:
Sam Tuke 2012-04-27 13:19:16 +01:00
parent 768041b6cb
commit 80c850d018
6 changed files with 77 additions and 32 deletions

View File

@ -1,3 +1,16 @@
#history {
margin: 2em 2em 0;
margin: 2em 2em 0;
}
#feedback-messages h3 {
font-size: 1.3em;
font-style: italic;
}
.success {
color: green;
}
.failure {
color: red;
}

View File

@ -24,43 +24,52 @@ require_once( '../../lib/base.php' );
OC_Util::checkLoggedIn( );
OC_Util::addStyle('files_versions','versions');
$tmpl = new OC_Template( 'files_versions', 'history', 'user' );
if ( isset( $_GET['path'] ) ) {
$path = $_GET['path'];
$path = strip_tags( $path );
$tmpl->assign( 'path', $path );
// roll back to old version if button clicked
if( isset( $_GET['revert'] ) ) {
if( \OCA_Versions\Storage::rollback( $path, $_GET['revert'] ) ) {
echo "<script>OC.dialogs.alert(response.data.message, t('contacts', 'Error'))</script>";
$tmpl->assign( 'outcome_stat', 'success' );
$tmpl->assign( 'outcome_msg', "File {$_GET['path']} was reverted to version ".OC_Util::formatDate( $_GET['revert'] ) );
} else {
$tmpl->assign( 'outcome_stat', 'failure' );
$tmpl->assign( 'outcome_msg', "File {$_GET['path']} could not be reverted to version ".OC_Util::formatDate( $_GET['revert'] ) );
}
}
// show the history only if there is something to show
if( OCA_Versions\Storage::isversioned( $path ) ) {
$count=999; //show the newest revisions
$versions=OCA_Versions\Storage::getversions( $path, $count);
$tmpl = new OC_Template( 'files_versions', 'history', 'user' );
$tmpl->assign( 'path', $path);
$tmpl->assign( 'versions', array_reverse( $versions) );
$tmpl->printPage( );
$tmpl->assign( 'versions', array_reverse( $versions ) );
}else{
$tmpl = new OC_Template( 'files_versions', 'history', 'user' );
$tmpl->assign( 'path', $path);
$tmpl->assign( 'message', 'No old versions available' );
$tmpl->printPage( );
}
}else{
$tmpl = new OC_Template( 'files_versions', 'history', 'user' );
$tmpl->assign( 'message', 'No path specified' );
$tmpl->printPage( );
}
$tmpl->printPage( );
?>

View File

@ -31,11 +31,11 @@ function createVersionsDropdown(filename, files) {
var html = '<div id="dropdown" class="drop" data-file="'+files+'">';
html += '<div id="private">';
html += '<select data-placeholder="File Version" id="found_versions" class="chzen-select">';
html += '<option value="">Select version</option>';
html += '<option value="">Saved versions</option>';
html += '</select>';
html += '</div>';
html += '<input type="button" value="Revert file" onclick="revertFile()" />';
html += '<input type="button" value="More..." onclick="window.location=\''+historyUrl+'\'" name="makelink" id="makelink" />';
//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 += '<br />';
html += '<input id="link" style="display:none; width:90%;" />';

View File

@ -1,24 +1,33 @@
<div id="history">
<?php
if(isset($_['message'])){
if( isset( $_['message'] ) ) {
if(isset($_['path'])) echo('<strong>File: '.$_['path']).'</strong><br>';
echo('<strong>'.$_['message']).'</strong><br>';
if( isset($_['path'] ) ) echo('<strong>File: '.$_['path'] ).'</strong><br>';
echo('<strong>'.$_['message'] ).'</strong><br>';
}else{
}else{
echo('<strong>Versions of '.$_['path']).'</strong><br>';
echo('<p><em>You can click on the revert button to revert to the specific verson.</em></p><br />');
foreach ( $_['versions'] as $v ){
echo ' ';
echo OC_Util::formatDate( $v );
echo ' <a href="history.php?path='.urlencode( $_['path'] ).'&revert='. $v .'" class="button">Revert</a><br /><br />';
}
if( isset( $_['outcome_stat'] ) ) {
echo( '<div id="feedback-messages" class="'.$_['outcome_stat'].'"><h3>'.$_['outcome_msg'] ).'</h3></div><br>';
}
echo( '<strong>Versions of '.$_['path'] ).'</strong><br>';
echo('<p><em>You can click on the revert button to revert to the specific verson.</em></p><br />');
foreach ( $_['versions'] as $v ) {
echo ' ';
echo OC_Util::formatDate( $v );
echo ' <a href="history.php?path='.urlencode( $_['path'] ).'&revert='. $v .'" class="button">Revert</a><br /><br />';
}
}
?>
</div>

View File

@ -4,4 +4,4 @@
Configuration goes here...
</fieldset>
</form>
</form>

View File

@ -36,7 +36,7 @@ class Storage {
const DEFAULTFOLDER='versions';
const DEFAULTBLACKLIST='avi mp3 mpg mp4';
const DEFAULTMAXFILESIZE=1048576; // 10MB
const DEFAULTMININTERVAL=1; // 5 min
const DEFAULTMININTERVAL=120; // 2 min
const DEFAULTMAXVERSIONS=50;
/**
@ -122,12 +122,26 @@ class Storage {
* rollback to an old version of a file.
*/
public static function rollback($filename,$revision) {
if(\OC_Config::getValue('files_versions', Storage::DEFAULTENABLED)=='true') {
$versionsfoldername=\OC_Config::getValue('datadirectory').'/'. \OC_User::getUser() .'/'.\OC_Config::getValue('files_versionsfolder', Storage::DEFAULTFOLDER);
$filesfoldername=\OC_Config::getValue('datadirectory').'/'. \OC_User::getUser() .'/files';
// rollback
@copy($versionsfoldername.$filename.'.v'.$revision,$filesfoldername.$filename);
if ( @copy($versionsfoldername.$filename.'.v'.$revision,$filesfoldername.$filename) ) {
return true;
}else{
return false;
}
}
}
/**