aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/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/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/lib')
-rw-r--r--apps/files/lib/app.php20
-rw-r--r--apps/files/lib/helper.php94
2 files changed, 52 insertions, 62 deletions
diff --git a/apps/files/lib/app.php b/apps/files/lib/app.php
index fea88faa92a..adfca669577 100644
--- a/apps/files/lib/app.php
+++ b/apps/files/lib/app.php
@@ -84,25 +84,7 @@ class App {
) {
// successful rename
$meta = $this->view->getFileInfo($dir . '/' . $newname);
- if ($meta['mimetype'] === 'httpd/unix-directory') {
- $meta['type'] = 'dir';
- }
- else {
- $meta['type'] = 'file';
- }
- // these need to be set for determineIcon()
- $meta['isPreviewAvailable'] = \OC::$server->getPreviewManager()->isMimeSupported($meta['mimetype']);
- $meta['directory'] = $dir;
- $fileinfo = array(
- 'id' => $meta['fileid'],
- 'mime' => $meta['mimetype'],
- 'size' => $meta['size'],
- 'etag' => $meta['etag'],
- 'directory' => $meta['directory'],
- 'name' => $newname,
- 'isPreviewAvailable' => $meta['isPreviewAvailable'],
- 'icon' => \OCA\Files\Helper::determineIcon($meta)
- );
+ $fileinfo = \OCA\Files\Helper::formatFileInfo($meta);
$result['success'] = true;
$result['data'] = $fileinfo;
} else {
diff --git a/apps/files/lib/helper.php b/apps/files/lib/helper.php
index c41e2d15581..b765fdaf3e3 100644
--- a/apps/files/lib/helper.php
+++ b/apps/files/lib/helper.php
@@ -19,11 +19,17 @@ class Helper
'usedSpacePercent' => (int)$storageInfo['relative']);
}
+ /**
+ * Determine icon for a given file
+ *
+ * @param \OC\Files\FileInfo $file file info
+ * @return string icon URL
+ */
public static function determineIcon($file) {
if($file['type'] === 'dir') {
$dir = $file['directory'];
$icon = \OC_Helper::mimetypeIcon('dir');
- $absPath = \OC\Files\Filesystem::getView()->getAbsolutePath($dir.'/'.$file['name']);
+ $absPath = $file->getPath();
$mount = \OC\Files\Filesystem::getMountManager()->find($absPath);
if (!is_null($mount)) {
$sid = $mount->getStorageId();
@@ -38,11 +44,7 @@ class Helper
}
}
}else{
- if($file['isPreviewAvailable']) {
- $pathForPreview = $file['directory'] . '/' . $file['name'];
- return \OC_Helper::previewIcon($pathForPreview) . '&c=' . $file['etag'];
- }
- $icon = \OC_Helper::mimetypeIcon($file['mimetype']);
+ $icon = \OC_Helper::mimetypeIcon($file->getMimetype());
}
return substr($icon, 0, -3) . 'svg';
@@ -69,52 +71,58 @@ class Helper
}
/**
- * Retrieves the contents of the given directory and
- * returns it as a sorted array.
- * @param string $dir path to the directory
- * @return array of files
+ * Formats the file info to be returned as JSON to the client.
+ *
+ * @param \OCP\Files\FileInfo file info
+ * @return array formatted file info
*/
- public static function getFiles($dir) {
- $content = \OC\Files\Filesystem::getDirectoryContent($dir);
- $files = array();
+ public static function formatFileInfo($i) {
+ $entry = array();
- foreach ($content as $i) {
- $i['date'] = \OCP\Util::formatDate($i['mtime']);
- if ($i['type'] === 'file') {
- $fileinfo = pathinfo($i['name']);
- $i['basename'] = $fileinfo['filename'];
- if (!empty($fileinfo['extension'])) {
- $i['extension'] = '.' . $fileinfo['extension'];
- } else {
- $i['extension'] = '';
- }
- }
- $i['directory'] = $dir;
- $i['isPreviewAvailable'] = \OC::$server->getPreviewManager()->isMimeSupported($i['mimetype']);
- $i['icon'] = \OCA\Files\Helper::determineIcon($i);
- $files[] = $i;
+ $entry['id'] = $i['fileid'];
+ $entry['date'] = \OCP\Util::formatDate($i['mtime']);
+ $entry['mtime'] = $i['mtime'] * 1000;
+ // only pick out the needed attributes
+ $entry['icon'] = \OCA\Files\Helper::determineIcon($i);
+ if (\OC::$server->getPreviewManager()->isMimeSupported($i['mimetype'])) {
+ $entry['isPreviewAvailable'] = true;
+ }
+ $entry['name'] = $i['name'];
+ $entry['permissions'] = $i['permissions'];
+ $entry['mimetype'] = $i['mimetype'];
+ $entry['size'] = $i['size'];
+ $entry['type'] = $i['type'];
+ $entry['etag'] = $i['etag'];
+ if (isset($i['displayname_owner'])) {
+ $entry['shareOwner'] = $i['displayname_owner'];
}
+ return $entry;
+ }
- usort($files, array('\OCA\Files\Helper', 'fileCmp'));
+ /**
+ * Format file info for JSON
+ * @param \OCP\Files\FileInfo[] $fileInfos file infos
+ */
+ public static function formatFileInfos($fileInfos) {
+ $files = array();
+ foreach ($fileInfos as $i) {
+ $files[] = self::formatFileInfo($i);
+ }
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
+ * Retrieves the contents of the given directory and
+ * returns it as a sorted array of FileInfo.
+ *
+ * @param string $dir path to the directory
+ * @return \OCP\Files\FileInfo[] files
*/
- public static function makeBreadcrumb($dir){
- $breadcrumb = array();
- $pathtohere = '';
- foreach (explode('/', $dir) as $i) {
- if ($i !== '') {
- $pathtohere .= '/' . $i;
- $breadcrumb[] = array('dir' => $pathtohere, 'name' => $i);
- }
- }
- return $breadcrumb;
+ public static function getFiles($dir) {
+ $content = \OC\Files\Filesystem::getDirectoryContent($dir);
+
+ usort($content, array('\OCA\Files\Helper', 'fileCmp'));
+ return $content;
}
}