fix filepicker

* add ability to filter for mimetype
* fixes #15526
* fixes #11563
remotes/origin/poc-doctrine-migrations
Morris Jobke 10 years ago
parent 0a72e66e9f
commit 59efcb63a3
  1. 24
      apps/files/ajax/list.php
  2. 5
      apps/files/lib/helper.php
  3. 2
      core/js/oc-dialogs.js

@ -45,10 +45,32 @@ try {
$sortAttribute = isset($_GET['sort']) ? (string)$_GET['sort'] : 'name'; $sortAttribute = isset($_GET['sort']) ? (string)$_GET['sort'] : 'name';
$sortDirection = isset($_GET['sortdirection']) ? ($_GET['sortdirection'] === 'desc') : false; $sortDirection = isset($_GET['sortdirection']) ? ($_GET['sortdirection'] === 'desc') : false;
$mimetypeFilters = isset($_GET['mimetypes']) ? json_decode($_GET['mimetypes']) : '';
// make filelist $files = [];
// Clean up duplicates from array
if (is_array($mimetypeFilters) && count($mimetypeFilters)) {
$mimetypeFilters = array_unique($mimetypeFilters);
if (!in_array('httpd/unix-directory', $mimetypeFilters)) {
// append folder filter to be able to browse folders
$mimetypeFilters[] = 'httpd/unix-directory';
}
// create filelist with mimetype filter - as getFiles only supports on
// mimetype filter at once we will filter this folder for each
// mimetypeFilter
foreach ($mimetypeFilters as $mimetypeFilter) {
$files = array_merge($files, \OCA\Files\Helper::getFiles($dir, $sortAttribute, $sortDirection, $mimetypeFilter));
}
// sort the files accordingly
$files = \OCA\Files\Helper::sortFiles($files, $sortAttribute, $sortDirection);
} else {
// create file list without mimetype filter
$files = \OCA\Files\Helper::getFiles($dir, $sortAttribute, $sortDirection); $files = \OCA\Files\Helper::getFiles($dir, $sortAttribute, $sortDirection);
}
$files = \OCA\Files\Helper::populateTags($files); $files = \OCA\Files\Helper::populateTags($files);
$data['directory'] = $dir; $data['directory'] = $dir;
$data['files'] = \OCA\Files\Helper::formatFileInfos($files); $data['files'] = \OCA\Files\Helper::formatFileInfos($files);

@ -196,10 +196,11 @@ class Helper {
* @param string $dir path to the directory * @param string $dir path to the directory
* @param string $sortAttribute attribute to sort on * @param string $sortAttribute attribute to sort on
* @param bool $sortDescending true for descending sort, false otherwise * @param bool $sortDescending true for descending sort, false otherwise
* @param string $mimetypeFilter limit returned content to this mimetype or mimepart
* @return \OCP\Files\FileInfo[] files * @return \OCP\Files\FileInfo[] files
*/ */
public static function getFiles($dir, $sortAttribute = 'name', $sortDescending = false) { public static function getFiles($dir, $sortAttribute = 'name', $sortDescending = false, $mimetypeFilter = '') {
$content = \OC\Files\Filesystem::getDirectoryContent($dir); $content = \OC\Files\Filesystem::getDirectoryContent($dir, $mimetypeFilter);
return self::sortFiles($content, $sortAttribute, $sortDescending); return self::sortFiles($content, $sortAttribute, $sortDescending);
} }

@ -138,7 +138,7 @@ var OCdialogs = {
* @param title dialog title * @param title dialog title
* @param callback which will be triggered when user presses Choose * @param callback which will be triggered when user presses Choose
* @param multiselect whether it should be possible to select multiple files * @param multiselect whether it should be possible to select multiple files
* @param mimetypeFilter mimetype to filter by * @param mimetypeFilter mimetype to filter by - directories will always be included
* @param modal make the dialog modal * @param modal make the dialog modal
*/ */
filepicker:function(title, callback, multiselect, mimetypeFilter, modal) { filepicker:function(title, callback, multiselect, mimetypeFilter, modal) {

Loading…
Cancel
Save