From: Björn Schießle Date: Thu, 25 Jul 2013 08:35:19 +0000 (+0200) Subject: new version drop down X-Git-Tag: v6.0.0alpha2~400 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=9394fc5d4a89c55ecf13f481beae4072e47047c5;p=nextcloud-server.git new version drop down Squashed commit of the following: commit 0dc404a557fa8253e3a87c7babefba6de8e6dab5 Author: Björn Schießle Date: Thu Jul 25 10:26:48 2013 +0200 fix 'more versions' button for IE8 commit 5836e652857204d68dfdfa8b3318de8e2fe02493 Author: Björn Schießle Date: Wed Jul 24 16:56:46 2013 +0200 clean-up some unused code commit ac83e53fa24073783a165796fc3016dc7beca293 Author: Björn Schießle Date: Wed Jul 24 16:49:03 2013 +0200 fix order of the versions, newest version should come first commit f150a88843af316ff505728941287406f25a0751 Merge: bc713c7 b8e399b Author: Jan-Christoph Borchardt Date: Wed Jul 24 16:19:36 2013 +0200 Merge branch 'new_versions_dropdown' of github.com:owncloud/core into new_versions_dropdown commit bc713c7b0c3207d00d2f19b10a905a82724c0709 Author: Jan-Christoph Borchardt Date: Wed Jul 24 16:11:07 2013 +0200 fix position of more versions button commit b8e399b1754ae7656c3cb8cef2c53f6976a83d61 Merge: 24825b0 7b6e39d Author: Björn Schießle Date: Wed Jul 24 16:04:08 2013 +0200 Merge branch 'new_versions_dropdown' of github.com:owncloud/core into new_versions_dropdown commit 24825b02004efa953197e72b470b9b033030aeee Author: Björn Schießle Date: Wed Jul 24 16:02:53 2013 +0200 umark previous row if a new row gets selected commit 7b6e39d2939f1b3bba4fff37ca9087dbc7795f03 Merge: 5bfb0ac 7b54644 Author: Jan-Christoph Borchardt Date: Wed Jul 24 15:37:19 2013 +0200 Merge branch 'new_versions_dropdown' of github.com:owncloud/core into new_versions_dropdown commit 5bfb0ac5c102bdfd3b27a37cea8c792f69b3b803 Author: Jan-Christoph Borchardt Date: Wed Jul 24 15:37:09 2013 +0200 more style adjustments for version dropdown commit 7b54644d3036ffba448f0525ca09f6e8898b9950 Author: Björn Schießle Date: Wed Jul 24 15:12:53 2013 +0200 remove debug output commit a75662bcfdce34d4f14020a539172c7ef1b894d3 Author: Jan-Christoph Borchardt Date: Wed Jul 24 15:12:26 2013 +0200 reword Revert to Restore commit e784644daeac12bc6fa6844f24214a039266ae86 Merge: d07abfd 9978c96 Author: Björn Schießle Date: Wed Jul 24 15:00:11 2013 +0200 Merge branch 'new_versions_dropdown' of github.com:owncloud/core into new_versions_dropdown commit d07abfdbb49778a8be30b2a6adbe326e1b1f238f Author: Björn Schießle Date: Wed Jul 24 14:59:17 2013 +0200 if another drop-down is already open, always close it first commit 9978c967a6ecbd2d0e5003df3cf4cdba09dab468 Author: Jan-Christoph Borchardt Date: Wed Jul 24 14:49:47 2013 +0200 more style improvements for versions commit a13355f16e6172c02069930a60a49aba4ebfa227 Author: Jan-Christoph Borchardt Date: Wed Jul 24 14:44:13 2013 +0200 position fixes for versioning commit 02c1d6b5eabc4075749c2a7a852c9ed7bbb3644d Merge: c5a9462 203f544 Author: Jan-Christoph Borchardt Date: Wed Jul 24 14:31:16 2013 +0200 merge versions style changes commit c5a946231a3d011748248db13b6b95ce51eb3e4c Author: Jan-Christoph Borchardt Date: Wed Jul 24 14:29:56 2013 +0200 bigger clickable area for versions commit 203f544825bd49b168f2316cf2a04caca75438c8 Author: Björn Schießle Date: Wed Jul 24 14:15:38 2013 +0200 changes visual changes, as suggested by Jan commit 90b1e93676d235a61f318768661b25e5815a9784 Author: Jan-Christoph Borchardt Date: Wed Jul 24 14:12:23 2013 +0200 remove superfluous selector from ID commit 9768254fe3b2469293fca23151e54cde69bd4661 Merge: c961278 b91c682 Author: Björn Schießle Date: Wed Jul 24 12:28:06 2013 +0200 Merge branch 'master' into new_versions_dropdown commit c9612781e10a4de9e9405244f87c4e29428a0d3f Author: Björn Schießle Date: Wed Jul 24 11:05:25 2013 +0200 replace modal dialog with a OC.Notification commit 3dc7508a4c271818247afbaed0ce0b03706a8db6 Author: Björn Schießle Date: Wed Jul 24 10:33:05 2013 +0200 use image path without extension for proper svg to png fallback commit 23ea7ad46c73fa4b86021070eb58a3b92bc8362e Author: Björn Schießle Date: Tue Jul 23 17:53:58 2013 +0200 some css fixes commit 8d01499ae17e43a7d7960841a7c2127fa6de5a56 Author: Björn Schießle Date: Tue Jul 23 17:40:16 2013 +0200 small fixes and improvements according to @Kondou-ger comments commit 985b6461e81035967959659fab8ea59c733e00eb Author: Björn Schießle Date: Tue Jul 23 15:58:19 2013 +0200 replace == with === commit bc8fc3b4a664db2d819e0a7091f31207ffcfe44a Merge: c1da183 a94c55b Author: Björn Schießle Date: Tue Jul 23 13:55:45 2013 +0200 Merge branch 'master' into new_versions_dropdown commit c1da183d13b8098eb33e708d4fdd04111bdc33a5 Author: Björn Schießle Date: Tue Jul 23 13:53:37 2013 +0200 translate timestamps into strings like "X minutes ago" for the versions drop-down commit c78d2b4bfb0a6800ab8516ac115ba42268be019a Author: Björn Schießle Date: Tue Jul 23 12:52:44 2013 +0200 download versions directly from the versions drop-down commit 14aaf9907625fc76bc153cd846704b7efd15db46 Author: Björn Schießle Date: Tue Jul 23 11:01:21 2013 +0200 only show 'more versions' button of necessary commit a0d8cb46b2255be3d9b3f9bd5f835a173c9665b8 Author: Björn Schießle Date: Mon Jul 22 17:49:17 2013 +0200 remove unneeded code commit 47eec0679ce16ece0b7890e9b41bf28d7613b131 Author: Björn Schießle Date: Mon Jul 22 17:44:58 2013 +0200 add title for revert and download action commit df87ccb24327b5c2770f7c23c97e41b143d65ec3 Author: Björn Schießle Date: Mon Jul 22 17:36:40 2013 +0200 add download button to versions drop-down commit 622c87ec37c14b7b3237bc9ca980b7f35689a933 Author: Björn Schießle Date: Mon Jul 22 17:36:08 2013 +0200 adapt css file for the new versions drop-down commit 300699024fe74a9f0f998c1cce4024484311f50c Author: Björn Schießle Date: Fri Jun 7 17:28:34 2013 +0200 revert on click commit 6673ae6ed45bbda1e0d962e9b32e943afc7123c0 Author: Björn Schießle Date: Fri Jun 7 16:50:08 2013 +0200 new versions list, show the latest 5 with a button to retrieve more versions if needed --- diff --git a/apps/files_versions/ajax/getVersions.php b/apps/files_versions/ajax/getVersions.php index f9174c45a65..4f48f71d8ca 100644 --- a/apps/files_versions/ajax/getVersions.php +++ b/apps/files_versions/ajax/getVersions.php @@ -2,24 +2,22 @@ OCP\JSON::checkAppEnabled('files_versions'); $source = $_GET['source']; +$start = $_GET['start']; list ($uid, $filename) = OCA\Files_Versions\Storage::getUidAndFilename($source); $count = 5; //show the newest revisions -if( ($versions = OCA\Files_Versions\Storage::getVersions($uid, $filename, $count)) ) { +if( ($versions = OCA\Files_Versions\Storage::getVersions($uid, $filename)) ) { - $versionsFormatted = array(); - - foreach ( $versions AS $version ) { - $versionsFormatted[] = OCP\Util::formatDate( $version['version'] ); + $endReached = false; + if (count($versions) <= $start+$count) { + $endReached = true; } - $versionsSorted = array_reverse( $versions ); + $versions = array_slice($versions, $start, $count); - if ( !empty( $versionsSorted ) ) { - OCP\JSON::encodedPrint($versionsSorted); - } + \OCP\JSON::success(array('data' => array('versions' => $versions, 'endReached' => $endReached))); } else { - return; + \OCP\JSON::success(array('data' => array('versions' => false, 'endReached' => true))); } diff --git a/apps/files_versions/ajax/rollbackVersion.php b/apps/files_versions/ajax/rollbackVersion.php index 284b46ee093..900d8cd6e28 100644 --- a/apps/files_versions/ajax/rollbackVersion.php +++ b/apps/files_versions/ajax/rollbackVersion.php @@ -3,8 +3,6 @@ OCP\JSON::checkAppEnabled('files_versions'); OCP\JSON::callCheck(); -$userDirectory = "/".OCP\USER::getUser()."/files"; - $file = $_GET['file']; $revision=(int)$_GET['revision']; diff --git a/apps/files_versions/appinfo/app.php b/apps/files_versions/appinfo/app.php index 0d0850e1864..5b1e464ba6c 100644 --- a/apps/files_versions/appinfo/app.php +++ b/apps/files_versions/appinfo/app.php @@ -6,6 +6,7 @@ OC::$CLASSPATH['OCA\Files_Versions\Hooks'] = 'files_versions/lib/hooks.php'; OC::$CLASSPATH['OCA\Files_Versions\Capabilities'] = 'files_versions/lib/capabilities.php'; OCP\Util::addscript('files_versions', 'versions'); +OCP\Util::addStyle('files_versions', 'versions'); // Listen to write signals OCP\Util::connectHook('OC_Filesystem', 'write', "OCA\Files_Versions\Hooks", "write_hook"); diff --git a/apps/files_versions/css/versions.css b/apps/files_versions/css/versions.css index a9b259ce140..6146eda3372 100644 --- a/apps/files_versions/css/versions.css +++ b/apps/files_versions/css/versions.css @@ -1,16 +1,44 @@ -#history { - margin: 2em 2em 0; +#found_versions li { + width: 100%; + cursor: default; + height: 36px; + float: left; + border-bottom: 1px solid rgba(100,100,100,.1); +} +#found_versions li:last-child { + border-bottom: none; +} + +#found_versions li > * { + padding: 7px; + float: left; + vertical-align: top; + -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=50)"; + filter: alpha(opacity=50); + opacity: .5; +} +#found_versions li > *:hover, +#found_versions li > *:focus { + -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)"; + filter: alpha(opacity=100); + opacity: 1; } -#feedback-messages h3 { - font-size: 1.3em; - font-style: italic; +#found_versions img { + cursor: pointer; + padding-right: 4px; } -.success { - color: green; +#found_versions .versionDate { + min-width: 100px; + vertical-align: text-bottom; } -.failure { - color: red; -} \ No newline at end of file +#found_versions .revertVersion { + cursor: pointer; + float: right; +} + +.drop-versions #makelink { + float: left; +} diff --git a/apps/files_versions/download.php b/apps/files_versions/download.php new file mode 100644 index 00000000000..040a662e61b --- /dev/null +++ b/apps/files_versions/download.php @@ -0,0 +1,50 @@ +. +* +*/ + +OCP\JSON::checkAppEnabled('files_versions'); +//OCP\JSON::callCheck(); + +$file = $_GET['file']; +$revision=(int)$_GET['revision']; + +list($uid, $filename) = OCA\Files_Versions\Storage::getUidAndFilename($file); + +$versionName = '/'.$uid.'/files_versions/'.$filename.'.v'.$revision; + +$view = new OC\Files\View('/'); + +$ftype = $view->getMimeType('/'.$uid.'/files/'.$filename); + +header('Content-Type:'.$ftype); +if ( preg_match( "/MSIE/", $_SERVER["HTTP_USER_AGENT"] ) ) { + header( 'Content-Disposition: attachment; filename="' . rawurlencode( basename($filename) ) . '"' ); +} else { + header( 'Content-Disposition: attachment; filename*=UTF-8\'\'' . rawurlencode( basename($filename) ) + . '; filename="' . rawurlencode( basename($filename) ) . '"' ); +} +OCP\Response::disableCaching(); +header('Content-Length: '.$view->filesize($versionName)); + +OC_Util::obEnd(); + +$view->readfile($versionName); diff --git a/apps/files_versions/history.php b/apps/files_versions/history.php deleted file mode 100644 index 719a7208fed..00000000000 --- a/apps/files_versions/history.php +++ /dev/null @@ -1,78 +0,0 @@ -. - * - */ - -OCP\User::checkLoggedIn( ); -OCP\Util::addStyle('files_versions', 'versions'); -$tmpl = new OCP\Template( 'files_versions', 'history', 'user' ); -$l = OC_L10N::get('files_versions'); - -if ( isset( $_GET['path'] ) ) { - - $path = $_GET['path']; - $tmpl->assign( 'path', $path ); - $versions = new OCA\Files_Versions\Storage(); - - // roll back to old version if button clicked - if( isset( $_GET['revert'] ) ) { - - if( $versions->rollback( $path, $_GET['revert'] ) ) { - - $tmpl->assign( 'outcome_stat', $l->t('success') ); - - $message = $l->t('File %s was reverted to version %s', - array($_GET['path'], OCP\Util::formatDate( doubleval($_GET['revert']) ) ) ); - - $tmpl->assign( 'outcome_msg', $message); - - } else { - - $tmpl->assign( 'outcome_stat', $l->t('failure') ); - - $message = $l->t('File %s could not be reverted to version %s', - array($_GET['path'], OCP\Util::formatDate( doubleval($_GET['revert']) ) ) ); - - $tmpl->assign( 'outcome_msg', $message); - - } - - } - - // show the history only if there is something to show - $count = 999; //show the newest revisions - list ($uid, $filename) = OCA\Files_Versions\Storage::getUidAndFilename($path); - if( ($versions = OCA\Files_Versions\Storage::getVersions($uid, $filename, $count)) ) { - - $tmpl->assign( 'versions', array_reverse( $versions ) ); - - }else{ - - $tmpl->assign( 'message', $l->t('No old versions available') ); - - } -}else{ - - $tmpl->assign( 'message', $l->t('No path specified') ); - -} - -$tmpl->printPage( ); diff --git a/apps/files_versions/js/versions.js b/apps/files_versions/js/versions.js index a5b24417483..ca479507d48 100644 --- a/apps/files_versions/js/versions.js +++ b/apps/files_versions/js/versions.js @@ -1,4 +1,5 @@ $(document).ready(function(){ + if (typeof FileActions !== 'undefined') { // Add versions button to 'files/index.php' FileActions.register( @@ -14,39 +15,68 @@ $(document).ready(function(){ if (scanFiles.scanning){return;}//workaround to prevent additional http request block scanning feedback var file = $('#dir').val()+'/'+filename; + var createDropDown = true; // Check if drop down is already visible for a different file - if (($('#dropdown').length > 0) && $('#dropdown').hasClass('drop-versions') ) { - if (file != $('#dropdown').data('file')) { - $('#dropdown').hide('blind', function() { - $('#dropdown').remove(); - $('tr').removeClass('mouseOver'); - createVersionsDropdown(filename, file); - }); + if (($('#dropdown').length > 0) ) { + if ( $('#dropdown').hasClass('drop-versions') && file == $('#dropdown').data('file')) { + createDropDown = false; } - } else { + $('#dropdown').remove(); + $('tr').removeClass('mouseOver'); + } + + if(createDropDown === true) { createVersionsDropdown(filename, file); } } ); } + + $(document).on("click", 'span[class="revertVersion"]', function() { + var revision = $(this).attr('id'); + var file = $(this).attr('value'); + revertFile(file, revision); + }); + }); +function revertFile(file, revision) { + + $.ajax({ + type: 'GET', + url: OC.linkTo('files_versions', 'ajax/rollbackVersion.php'), + dataType: 'json', + data: {file: file, revision: revision}, + async: false, + success: function(response) { + if (response.status === 'error') { + OC.Notification.show( t('files_version', 'Failed to revert {file} to revision {timestamp}.', {file:file, timestamp:formatDate(revision * 1000)}) ); + } else { + $('#dropdown').hide('blind', function() { + $('#dropdown').remove(); + $('tr').removeClass('mouseOver'); + // TODO also update the modified time in the web ui + }); + } + } + }); + +} + function goToVersionPage(url){ window.location.assign(url); } function createVersionsDropdown(filename, files) { - var historyUrl = OC.linkTo('files_versions', 'history.php') + '?path='+encodeURIComponent( $( '#dir' ).val() ).replace( /%2F/g, '/' )+'/'+encodeURIComponent( filename ); + var start = 0; var html = '