Frontend: - The files app list now uses ajax calls to refresh the list. - Added support the browser back button (history API). - Added mask + spinner while loading file list Backend: - Added utility function in core JS for parsing query strings. - Moved file list + breadcrumb template data code to helper functions - Fixed some file paths in trashbin app to be similar to the files appremotes/origin/stable6
parent
c149b57d3b
commit
1304b511e9
@ -0,0 +1,51 @@ |
||||
<?php |
||||
|
||||
// only need filesystem apps |
||||
$RUNTIME_APPTYPES=array('filesystem'); |
||||
|
||||
// Init owncloud |
||||
|
||||
|
||||
OCP\JSON::checkLoggedIn(); |
||||
|
||||
// Load the files |
||||
$dir = isset( $_GET['dir'] ) ? $_GET['dir'] : ''; |
||||
$doBreadcrumb = isset( $_GET['breadcrumb'] ) ? true : false; |
||||
$data = array(); |
||||
|
||||
// Make breadcrumb |
||||
if($doBreadcrumb) { |
||||
$breadcrumb = \OCA\files_trashbin\lib\Helper::makeBreadcrumb($dir); |
||||
|
||||
$breadcrumbNav = new OCP\Template('files_trashbin', 'part.breadcrumb', ''); |
||||
$breadcrumbNav->assign('breadcrumb', $breadcrumb, false); |
||||
$breadcrumbNav->assign('baseURL', OCP\Util::linkTo('files_trashbin', 'index.php') . '?dir='); |
||||
$breadcrumbNav->assign('home', OCP\Util::linkTo('files', 'index.php')); |
||||
|
||||
$data['breadcrumb'] = $breadcrumbNav->fetchPage(); |
||||
} |
||||
|
||||
// make filelist |
||||
$files = \OCA\files_trashbin\lib\Helper::getTrashFiles($dir); |
||||
|
||||
if ($files === null){ |
||||
header("HTTP/1.0 404 Not Found"); |
||||
exit(); |
||||
} |
||||
|
||||
$dirlisting = false; |
||||
if ($dir && $dir !== '/') { |
||||
$dirlisting = true; |
||||
} |
||||
|
||||
$encodedDir = \OCP\Util::encodePath($dir); |
||||
$list = new OCP\Template('files_trashbin', 'part.list', ''); |
||||
$list->assign('files', $files, false); |
||||
$list->assign('baseURL', OCP\Util::linkTo('files_trashbin', 'index.php'). '?dir='.$encodedDir); |
||||
$list->assign('downloadURL', OCP\Util::linkToRoute('download', array('file' => '/'))); |
||||
$list->assign('dirlisting', $dirlisting); |
||||
$list->assign('disableDownloadActions', true); |
||||
$data['files'] = $list->fetchPage(); |
||||
|
||||
OCP\JSON::success(array('data' => $data)); |
||||
|
@ -0,0 +1,29 @@ |
||||
// override reload with own ajax call
|
||||
FileList.reload = function(){ |
||||
FileList.showMask(); |
||||
if (FileList._reloadCall){ |
||||
FileList._reloadCall.abort(); |
||||
} |
||||
$.ajax({ |
||||
url: OC.filePath('files_trashbin','ajax','list.php'), |
||||
data: { |
||||
dir : $('#dir').val(), |
||||
breadcrumb: true |
||||
}, |
||||
error: function(result) { |
||||
FileList.reloadCallback(result); |
||||
}, |
||||
success: function(result) { |
||||
FileList.reloadCallback(result); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
FileList.setCurrentDir = function(targetDir, changeUrl){ |
||||
$('#dir').val(targetDir); |
||||
// Note: IE8 handling ignored for now
|
||||
if (window.history.pushState && changeUrl !== false){ |
||||
url = OC.linkTo('files_trashbin', 'index.php')+"?dir="+ encodeURIComponent(targetDir).replace(/%2F/g, '/'), |
||||
window.history.pushState({dir: targetDir}, '', url); |
||||
} |
||||
} |
@ -0,0 +1,97 @@ |
||||
<?php |
||||
|
||||
namespace OCA\files_trashbin\lib; |
||||
|
||||
class Helper |
||||
{ |
||||
/** |
||||
* Retrieves the contents of a trash bin directory. |
||||
* @param string $dir path to the directory inside the trashbin |
||||
* or empty to retrieve the root of the trashbin |
||||
* @return array of files |
||||
*/ |
||||
public static function getTrashFiles($dir){ |
||||
$result = array(); |
||||
$user = \OCP\User::getUser(); |
||||
|
||||
if ($dir && $dir !== '/') { |
||||
$view = new \OC_Filesystemview('/'.$user.'/files_trashbin/files'); |
||||
$dirContent = $view->opendir($dir); |
||||
if ($dirContent === false){ |
||||
return null; |
||||
} |
||||
if(is_resource($dirContent)){ |
||||
while(($entryName = readdir($dirContent)) !== false) { |
||||
if (!\OC\Files\Filesystem::isIgnoredDir($entryName)) { |
||||
$pos = strpos($dir.'/', '/', 1); |
||||
$tmp = substr($dir, 0, $pos); |
||||
$pos = strrpos($tmp, '.d'); |
||||
$timestamp = substr($tmp, $pos+2); |
||||
$result[] = array( |
||||
'id' => $entryName, |
||||
'timestamp' => $timestamp, |
||||
'mime' => $view->getMimeType($dir.'/'.$entryName), |
||||
'type' => $view->is_dir($dir.'/'.$entryName) ? 'dir' : 'file', |
||||
'location' => $dir, |
||||
); |
||||
} |
||||
} |
||||
closedir($dirContent); |
||||
} |
||||
} else { |
||||
$query = \OC_DB::prepare('SELECT `id`,`location`,`timestamp`,`type`,`mime` FROM `*PREFIX*files_trash` WHERE `user` = ?'); |
||||
$result = $query->execute(array($user))->fetchAll(); |
||||
} |
||||
|
||||
$files = array(); |
||||
foreach ($result as $r) { |
||||
$i = array(); |
||||
$i['name'] = $r['id']; |
||||
$i['date'] = \OCP\Util::formatDate($r['timestamp']); |
||||
$i['timestamp'] = $r['timestamp']; |
||||
$i['mimetype'] = $r['mime']; |
||||
$i['type'] = $r['type']; |
||||
if ($i['type'] === 'file') { |
||||
$fileinfo = pathinfo($r['id']); |
||||
$i['basename'] = $fileinfo['filename']; |
||||
$i['extension'] = isset($fileinfo['extension']) ? ('.'.$fileinfo['extension']) : ''; |
||||
} |
||||
$i['directory'] = $r['location']; |
||||
if ($i['directory'] === '/') { |
||||
$i['directory'] = ''; |
||||
} |
||||
$i['permissions'] = \OCP\PERMISSION_READ; |
||||
$i['isPreviewAvailable'] = \OCP\Preview::isMimeSupported($r['mime']); |
||||
$i['icon'] = \OCA\files\lib\Helper::determineIcon($i); |
||||
$files[] = $i; |
||||
} |
||||
|
||||
usort($files, array('\OCA\files\lib\Helper', 'fileCmp')); |
||||
|
||||
return $files; |
||||
} |
||||
|
||||
/** |
||||
* Splits the given path into a breadcrumb structure. |
||||
* @param string $dir path to process |
||||
* @return array where each entry is a hash of the absolute |
||||
* directory path and its name |
||||
*/ |
||||
public static function makeBreadcrumb($dir){ |
||||
// Make breadcrumb |
||||
$pathtohere = ''; |
||||
$breadcrumb = array(); |
||||
foreach (explode('/', $dir) as $i) { |
||||
if ($i !== '') { |
||||
if ( preg_match('/^(.+)\.d[0-9]+$/', $i, $match) ) { |
||||
$name = $match[1]; |
||||
} else { |
||||
$name = $i; |
||||
} |
||||
$pathtohere .= '/' . $i; |
||||
$breadcrumb[] = array('dir' => $pathtohere, 'name' => $name); |
||||
} |
||||
} |
||||
return $breadcrumb; |
||||
} |
||||
} |
Loading…
Reference in new issue