diff options
author | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2020-08-03 12:54:37 +0200 |
---|---|---|
committer | npmbuildbot[bot] <npmbuildbot[bot]@users.noreply.github.com> | 2020-08-03 11:26:03 +0000 |
commit | 1a1b3e20e470a945dd9f5fab1d99174b10cbb141 (patch) | |
tree | aacff8872bcfd47685e9a9fb3e5e3a423e498f59 /apps/files/lib | |
parent | 4987fe9a51f0b889d2b99428c967014d95bb13ae (diff) | |
download | nextcloud-server-1a1b3e20e470a945dd9f5fab1d99174b10cbb141.tar.gz nextcloud-server-1a1b3e20e470a945dd9f5fab1d99174b10cbb141.zip |
Fix unified search
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Signed-off-by: npmbuildbot[bot] <npmbuildbot[bot]@users.noreply.github.com>
Diffstat (limited to 'apps/files/lib')
-rw-r--r-- | apps/files/lib/Search/FilesSearchProvider.php | 32 | ||||
-rw-r--r-- | apps/files/lib/Search/FilesSearchResultEntry.php | 5 |
2 files changed, 32 insertions, 5 deletions
diff --git a/apps/files/lib/Search/FilesSearchProvider.php b/apps/files/lib/Search/FilesSearchProvider.php index 3f1c4de0aa1..077335e220a 100644 --- a/apps/files/lib/Search/FilesSearchProvider.php +++ b/apps/files/lib/Search/FilesSearchProvider.php @@ -57,17 +57,43 @@ class FilesSearchProvider implements IProvider { return 'files'; } + public function getName(): string { + return $this->l10n->t('Files'); + } + public function search(IUser $user, ISearchQuery $query): SearchResult { return SearchResult::complete( $this->l10n->t('Files'), array_map(function (FileResult $result) { + // Generate thumbnail url + $thumbnailUrl = $result->type === 'folder' + ? '' + : $this->urlGenerator->linkToRoute('core.Preview.getPreviewByFileId', ['x' => 32, 'y' => 32, 'fileId' => $result->id]); + return new FilesSearchResultEntry( - $this->urlGenerator->linkToRoute('core.Preview.getPreviewByFileId', ['x' => 32, 'y' => 32, 'fileId' => $result->id]), + $thumbnailUrl, $result->name, - $result->path, - $result->link + $this->formatSubline($result), + $result->link, + $result->type === 'folder' ? 'icon-folder' : 'icon-filetype-file' ); }, $this->fileSearch->search($query->getTerm())) ); } + + /** + * Format subline for files + * + * @param FileResult $result + * @return string + */ + private function formatSubline($result): string { + // Do not show the location if the file is in root + if ($result->path === '/' . $result->name) { + return ''; + } + + $path = ltrim(dirname($result->path), '/'); + return $this->l10n->t('in %s', [$path]); + } } diff --git a/apps/files/lib/Search/FilesSearchResultEntry.php b/apps/files/lib/Search/FilesSearchResultEntry.php index c4f6e491d6f..53346154be1 100644 --- a/apps/files/lib/Search/FilesSearchResultEntry.php +++ b/apps/files/lib/Search/FilesSearchResultEntry.php @@ -31,7 +31,8 @@ class FilesSearchResultEntry extends ASearchResultEntry { public function __construct(string $thumbnailUrl, string $filename, string $path, - string $url) { - parent::__construct($thumbnailUrl, $filename, $path, $url); + string $url, + string $icon) { + parent::__construct($thumbnailUrl, $filename, $path, $url, $icon, false); } } |