mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-22 23:00:56 +01:00
WIP Et2VfsSelect - user file type filter
This commit is contained in:
parent
80dd602e66
commit
2539089d02
@ -90,7 +90,18 @@ export class Et2VfsSelect extends Et2InputWidget(LitElement) implements SearchMi
|
||||
@property() mime : string | string[] | RegExp = "";
|
||||
|
||||
/** List of mimetypes to allow user to filter. */
|
||||
@property() mimeList : SelectOption[] = [];
|
||||
@property() mimeList : SelectOption[] = [
|
||||
{
|
||||
value: "/(application\\/vnd.oasis.opendocument.text|application\\/vnd.openxmlformats-officedocument.wordprocessingml.document)/i",
|
||||
label: "Documents"
|
||||
},
|
||||
{
|
||||
value: "/(application\\/vnd.oasis.opendocument.spreadsheet|application\\/vnd.openxmlformats-officedocument.spreadsheetml.sheet)/i",
|
||||
label: "Spreadsheets"
|
||||
},
|
||||
{value: "image/", label: "Images"},
|
||||
{value: "video/", label: "Videos"}
|
||||
];
|
||||
|
||||
/** The select's help text. If you need to display HTML, use the `help-text` slot instead. */
|
||||
@property({attribute: 'help-text'}) helpText = '';
|
||||
@ -699,6 +710,8 @@ export class Et2VfsSelect extends Et2InputWidget(LitElement) implements SearchMi
|
||||
const hasToolbar = !!hasToolbarSlot;
|
||||
|
||||
const hasFilename = this.mode == "saveas";
|
||||
const mime = this.mimeList.length == 1 ? this.mimeList[0].value :
|
||||
(typeof this.mime == "string" ? this.mime : "");
|
||||
|
||||
return html`
|
||||
<et2-dialog
|
||||
@ -744,8 +757,15 @@ export class Et2VfsSelect extends Et2InputWidget(LitElement) implements SearchMi
|
||||
id="mimeFilter"
|
||||
part="mimefilter"
|
||||
class="vfs_select__mimefilter"
|
||||
emptyLabel=${this.egw().lang("All files")}
|
||||
?readonly=${this.mimeList.length == 1}
|
||||
.emptyLabel=${this.egw().lang("All files")}
|
||||
.select_options=${this.mimeList}
|
||||
.value=${mime}
|
||||
@change=${(e) =>
|
||||
{
|
||||
this.mime = e.target.value;
|
||||
this.startSearch();
|
||||
}}
|
||||
>
|
||||
${this.mimeOptionsTemplate()}
|
||||
</et2-select>
|
||||
|
@ -643,10 +643,7 @@ class Vfs extends File
|
||||
$name = $path['name'] ?? Api\Vfs::basename($path);
|
||||
$is_dir = $path['isDir'] ?? Api\Vfs::is_dir($path);
|
||||
$mime = $path['mime'] ?? Api\Vfs::mime_content_type($path);
|
||||
if($content['mime'] && !$is_dir && $mime != $content['mime'])
|
||||
{
|
||||
continue; // does not match mime-filter --> ignore
|
||||
}
|
||||
|
||||
$response['files'][] = array(
|
||||
'name' => $name,
|
||||
'path' => $path,
|
||||
@ -671,15 +668,21 @@ class Vfs extends File
|
||||
array('.{1}', '.*'),
|
||||
preg_quote($search)) . '/i';
|
||||
}
|
||||
$dirs = [];
|
||||
if($params['mime'])
|
||||
{
|
||||
// Always get dirs
|
||||
$vfs_options['type'] = 'd';
|
||||
$dirs = Api\Vfs::find($params['path'], $vfs_options);
|
||||
$vfs_options['type'] = 'f';
|
||||
$vfs_options['mime'] = $params['mime'];
|
||||
}
|
||||
if($params['num_rows'])
|
||||
{
|
||||
$vfs_options['limit'] = (int)$params['num_rows'];
|
||||
}
|
||||
if(!($files = Api\Vfs::find($params['path'], $vfs_options)))
|
||||
{
|
||||
return lang("Can't open directory %1!", $params['path']);
|
||||
}
|
||||
return $files;
|
||||
$files = Api\Vfs::find($params['path'], $vfs_options);
|
||||
return array_merge($dirs, $files);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user