aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_trashbin/lib
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2013-10-28 20:22:06 +0100
committerVincent Petry <pvince81@owncloud.com>2014-04-02 15:33:47 +0200
commit0be9de5df558232e12e2f582af5d08e1f488ba90 (patch)
treede37dea2e23dd28f631948295979980ec774027f /apps/files_trashbin/lib
parent268206cec55921d2d0309469ebd5d9533e4f79ee (diff)
downloadnextcloud-server-0be9de5df558232e12e2f582af5d08e1f488ba90.tar.gz
nextcloud-server-0be9de5df558232e12e2f582af5d08e1f488ba90.zip
Files, trashbin, public apps use ajax/JSON for the file list
Files app: - removed file list template, now rendering list from JSON response - FileList.addFile/addDir is now FileList.add() and takes a JS map with all required arguments instead of having a long number of function arguments - added unit tests for many FileList operations - fixed newfile.php, newfolder.php and rename.php to return the file's full JSON on success - removed obsolete/unused undo code - removed download_url / loading options, now using Files.getDownloadUrl() for that - server side now uses Helper::getFileInfo() to prepare file JSON response - previews are now client-side only Breadcrumbs are now JS only: - Added BreadCrumb class to handle breadcrumb rendering and events - Added unit test for BreadCrumb class - Moved all relevant JS functions to the BreadCrumb class Public page now uses ajax to load the file list: - Added Helper class in sharing app to make it easier to authenticate and retrieve the file's real path - Added ajax/list.php to retrieve the file list - Fixed FileActions and FileList to work with the ajax list Core: - Fixed file picker dialog to use the same list format as files app
Diffstat (limited to 'apps/files_trashbin/lib')
-rw-r--r--apps/files_trashbin/lib/helper.php83
1 files changed, 26 insertions, 57 deletions
diff --git a/apps/files_trashbin/lib/helper.php b/apps/files_trashbin/lib/helper.php
index 9c24332a964..e6ca73520a6 100644
--- a/apps/files_trashbin/lib/helper.php
+++ b/apps/files_trashbin/lib/helper.php
@@ -27,6 +27,10 @@ class Helper
if ($dirContent === false) {
return $result;
}
+
+ list($storage, $internalPath) = $view->resolvePath($dir);
+ $absoluteDir = $view->getAbsolutePath($dir);
+
if (is_resource($dirContent)) {
while (($entryName = readdir($dirContent)) !== false) {
if (!\OC\Files\Filesystem::isIgnoredDir($entryName)) {
@@ -40,76 +44,41 @@ class Helper
$parts = explode('/', ltrim($dir, '/'));
$timestamp = substr(pathinfo($parts[0], PATHINFO_EXTENSION), 1);
}
- $result[] = array(
- 'id' => $id,
- 'timestamp' => $timestamp,
- 'mime' => \OC_Helper::getFileNameMimeType($id),
+ $i = array(
+ 'name' => $id,
+ 'mtime' => $timestamp,
+ 'mimetype' => \OC_Helper::getFileNameMimeType($id),
'type' => $view->is_dir($dir . '/' . $entryName) ? 'dir' : 'file',
- 'location' => $dir,
+ 'directory' => ($dir === '/') ? '' : $dir,
);
+ $result[] = new FileInfo($absoluteDir . '/' . $i['name'], $storage, $internalPath . '/' . $i['name'], $i);
}
}
closedir($dirContent);
}
- $files = array();
- $id = 0;
- list($storage, $internalPath) = $view->resolvePath($dir);
- $absoluteDir = $view->getAbsolutePath($dir);
- foreach ($result as $r) {
- $i = array();
- $i['id'] = $id++;
- $i['name'] = $r['id'];
- $i['date'] = \OCP\Util::formatDate($r['timestamp']);
- $i['timestamp'] = $r['timestamp'];
- $i['etag'] = $r['timestamp']; // add fake etag, it is only needed to identify the preview image
- $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;
- if (\OCP\App::isEnabled('files_encryption')) {
- $i['isPreviewAvailable'] = false;
- } else {
- $i['isPreviewAvailable'] = \OC::$server->getPreviewManager()->isMimeSupported($r['mime']);
- }
- $i['icon'] = \OCA\Files\Helper::determineIcon($i);
- $files[] = new FileInfo($absoluteDir . '/' . $i['name'], $storage, $internalPath . '/' . $i['name'], $i);
- }
-
- usort($files, array('\OCA\Files\Helper', 'fileCmp'));
+ usort($result, array('\OCA\Files\Helper', 'fileCmp'));
- return $files;
+ return $result;
}
/**
- * 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
+ * Format file infos for JSON
+ * @param \OCP\Files\FileInfo[] $fileInfos file infos
*/
- 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);
+ public static function formatFileInfos($fileInfos) {
+ $files = array();
+ $id = 0;
+ foreach ($fileInfos as $i) {
+ $entry = \OCA\Files\Helper::formatFileInfo($i);
+ $entry['id'] = $id++;
+ $entry['etag'] = $entry['mtime']; // add fake etag, it is only needed to identify the preview image
+ $entry['permissions'] = \OCP\PERMISSION_READ;
+ if (\OCP\App::isEnabled('files_encryption')) {
+ $entry['isPreviewAvailable'] = false;
}
+ $files[] = $entry;
}
- return $breadcrumb;
+ return $files;
}
}