diff options
author | John Molakvoæ <skjnldsv@users.noreply.github.com> | 2020-08-05 14:17:42 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-05 14:17:42 +0200 |
commit | a4d511d82767f54af086b366a6c08bc927cb870c (patch) | |
tree | df4b2e2fe552da5cf52e70ea04baef4e8658d421 /lib | |
parent | 05813561691aca15116334464a64e8be054ddcbf (diff) | |
parent | 71b62c4203a25beefeab73f73668919c813e3a50 (diff) | |
download | nextcloud-server-a4d511d82767f54af086b366a6c08bc927cb870c.tar.gz nextcloud-server-a4d511d82767f54af086b366a6c08bc927cb870c.zip |
Merge pull request #22099 from nextcloud/fix/unified-search
Diffstat (limited to 'lib')
-rw-r--r-- | lib/composer/composer/autoload_classmap.php | 2 | ||||
-rw-r--r-- | lib/composer/composer/autoload_static.php | 2 | ||||
-rw-r--r-- | lib/private/NavigationManager.php | 21 | ||||
-rw-r--r-- | lib/private/Search/Provider/File.php | 2 | ||||
-rw-r--r-- | lib/private/Search/Result/File.php | 27 | ||||
-rw-r--r-- | lib/private/Search/SearchComposer.php | 21 | ||||
-rw-r--r-- | lib/private/TemplateLayout.php | 16 | ||||
-rw-r--r-- | lib/private/legacy/OC_Template.php | 3 | ||||
-rw-r--r-- | lib/public/INavigationManager.php | 7 | ||||
-rw-r--r-- | lib/public/Search/IProvider.php | 10 | ||||
-rw-r--r-- | lib/public/Search/SearchResult.php | 8 | ||||
-rw-r--r-- | lib/public/Search/SearchResultEntry.php (renamed from lib/public/Search/ASearchResultEntry.php) | 14 |
12 files changed, 88 insertions, 45 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 854ef66f23a..49801a253b9 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -439,13 +439,13 @@ return array( 'OCP\\Route\\IRouter' => $baseDir . '/lib/public/Route/IRouter.php', 'OCP\\SabrePluginEvent' => $baseDir . '/lib/public/SabrePluginEvent.php', 'OCP\\SabrePluginException' => $baseDir . '/lib/public/SabrePluginException.php', - 'OCP\\Search\\ASearchResultEntry' => $baseDir . '/lib/public/Search/ASearchResultEntry.php', 'OCP\\Search\\IProvider' => $baseDir . '/lib/public/Search/IProvider.php', 'OCP\\Search\\ISearchQuery' => $baseDir . '/lib/public/Search/ISearchQuery.php', 'OCP\\Search\\PagedProvider' => $baseDir . '/lib/public/Search/PagedProvider.php', 'OCP\\Search\\Provider' => $baseDir . '/lib/public/Search/Provider.php', 'OCP\\Search\\Result' => $baseDir . '/lib/public/Search/Result.php', 'OCP\\Search\\SearchResult' => $baseDir . '/lib/public/Search/SearchResult.php', + 'OCP\\Search\\SearchResultEntry' => $baseDir . '/lib/public/Search/SearchResultEntry.php', 'OCP\\Security\\CSP\\AddContentSecurityPolicyEvent' => $baseDir . '/lib/public/Security/CSP/AddContentSecurityPolicyEvent.php', 'OCP\\Security\\Events\\GenerateSecurePasswordEvent' => $baseDir . '/lib/public/Security/Events/GenerateSecurePasswordEvent.php', 'OCP\\Security\\Events\\ValidatePasswordPolicyEvent' => $baseDir . '/lib/public/Security/Events/ValidatePasswordPolicyEvent.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 4a857abae35..0a9879e19d0 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -468,13 +468,13 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OCP\\Route\\IRouter' => __DIR__ . '/../../..' . '/lib/public/Route/IRouter.php', 'OCP\\SabrePluginEvent' => __DIR__ . '/../../..' . '/lib/public/SabrePluginEvent.php', 'OCP\\SabrePluginException' => __DIR__ . '/../../..' . '/lib/public/SabrePluginException.php', - 'OCP\\Search\\ASearchResultEntry' => __DIR__ . '/../../..' . '/lib/public/Search/ASearchResultEntry.php', 'OCP\\Search\\IProvider' => __DIR__ . '/../../..' . '/lib/public/Search/IProvider.php', 'OCP\\Search\\ISearchQuery' => __DIR__ . '/../../..' . '/lib/public/Search/ISearchQuery.php', 'OCP\\Search\\PagedProvider' => __DIR__ . '/../../..' . '/lib/public/Search/PagedProvider.php', 'OCP\\Search\\Provider' => __DIR__ . '/../../..' . '/lib/public/Search/Provider.php', 'OCP\\Search\\Result' => __DIR__ . '/../../..' . '/lib/public/Search/Result.php', 'OCP\\Search\\SearchResult' => __DIR__ . '/../../..' . '/lib/public/Search/SearchResult.php', + 'OCP\\Search\\SearchResultEntry' => __DIR__ . '/../../..' . '/lib/public/Search/SearchResultEntry.php', 'OCP\\Security\\CSP\\AddContentSecurityPolicyEvent' => __DIR__ . '/../../..' . '/lib/public/Security/CSP/AddContentSecurityPolicyEvent.php', 'OCP\\Security\\Events\\GenerateSecurePasswordEvent' => __DIR__ . '/../../..' . '/lib/public/Security/Events/GenerateSecurePasswordEvent.php', 'OCP\\Security\\Events\\ValidatePasswordPolicyEvent' => __DIR__ . '/../../..' . '/lib/public/Security/Events/ValidatePasswordPolicyEvent.php', diff --git a/lib/private/NavigationManager.php b/lib/private/NavigationManager.php index 81642fac234..7ae78875249 100644 --- a/lib/private/NavigationManager.php +++ b/lib/private/NavigationManager.php @@ -79,12 +79,7 @@ class NavigationManager implements INavigationManager { } /** - * Creates a new navigation entry - * - * @param array|\Closure $entry Array containing: id, name, order, icon and href key - * The use of a closure is preferred, because it will avoid - * loading the routing of your app, unless required. - * @return void + * @inheritDoc */ public function add($entry) { if ($entry instanceof \Closure) { @@ -106,10 +101,7 @@ class NavigationManager implements INavigationManager { } /** - * Get a list of navigation entries - * - * @param string $type type of the navigation entries - * @return array + * @inheritDoc */ public function getAll(string $type = 'link'): array { $this->init(); @@ -171,19 +163,14 @@ class NavigationManager implements INavigationManager { } /** - * Sets the current navigation entry of the currently running app - * @param string $id of the app entry to activate (from added $entry) + * @inheritDoc */ public function setActiveEntry($id) { $this->activeEntry = $id; } /** - * gets the active Menu entry - * @return string id or empty string - * - * This function returns the id of the active navigation entry (set by - * setActiveEntry + * @inheritDoc */ public function getActiveEntry() { return $this->activeEntry; diff --git a/lib/private/Search/Provider/File.php b/lib/private/Search/Provider/File.php index 9a41a46bd35..79e9245b1b9 100644 --- a/lib/private/Search/Provider/File.php +++ b/lib/private/Search/Provider/File.php @@ -39,7 +39,7 @@ class File extends \OCP\Search\Provider { /** * Search for files and folders matching the given query * @param string $query - * @return \OCP\Search\Result + * @return \OCP\Search\Result[] * @deprecated 20.0.0 */ public function search($query) { diff --git a/lib/private/Search/Result/File.php b/lib/private/Search/Result/File.php index f93b033c07f..25876b78279 100644 --- a/lib/private/Search/Result/File.php +++ b/lib/private/Search/Result/File.php @@ -28,6 +28,8 @@ namespace OC\Search\Result; use OCP\Files\FileInfo; use OCP\Files\Folder; +use OCP\IPreview; +use OCP\IUserSession; /** * A found file @@ -79,6 +81,14 @@ class File extends \OCP\Search\Result { public $permissions; /** + * Has a preview + * + * @var string + * @deprecated 20.0.0 + */ + public $has_preview; + + /** * Create a new file search result * @param FileInfo $data file data given by provider * @deprecated 20.0.0 @@ -101,6 +111,7 @@ class File extends \OCP\Search\Result { $this->size = $data->getSize(); $this->modified = $data->getMtime(); $this->mime_type = $data->getMimetype(); + $this->has_preview = $this->hasPreview($data); } /** @@ -118,9 +129,21 @@ class File extends \OCP\Search\Result { */ protected function getRelativePath($path) { if (!isset(self::$userFolderCache)) { - $user = \OC::$server->getUserSession()->getUser()->getUID(); - self::$userFolderCache = \OC::$server->getUserFolder($user); + $userSession = \OC::$server->get(IUserSession::class); + $userID = $userSession->getUser()->getUID(); + self::$userFolderCache = \OC::$server->getUserFolder($userID); } return self::$userFolderCache->getRelativePath($path); } + + /** + * Is the preview available + * @param FileInfo $data + * @return bool + * @deprecated 20.0.0 + */ + protected function hasPreview($data) { + $previewManager = \OC::$server->get(IPreview::class); + return $previewManager->isAvailable($data); + } } diff --git a/lib/private/Search/SearchComposer.php b/lib/private/Search/SearchComposer.php index dd4edfc5f40..7ba6296c9de 100644 --- a/lib/private/Search/SearchComposer.php +++ b/lib/private/Search/SearchComposer.php @@ -107,22 +107,31 @@ class SearchComposer { /** * Get a list of all provider IDs & Names for the consecutive calls to `search` + * Sort the list by the order property * * @return array */ public function getProviders(): array { $this->loadLazyProviders(); - /** - * Return an array with the IDs, but strip the associative keys - */ - return array_values( + $providers = array_values( array_map(function (IProvider $provider) { return [ 'id' => $provider->getId(), - 'name' => $provider->getName() + 'name' => $provider->getName(), + 'order' => $provider->getOrder() ]; - }, $this->providers)); + }, $this->providers) + ); + + usort($providers, function ($provider1, $provider2) { + return $provider1['order'] <=> $provider2['order']; + }); + + /** + * Return an array with the IDs, but strip the associative keys + */ + return $providers; } /** diff --git a/lib/private/TemplateLayout.php b/lib/private/TemplateLayout.php index 87a4d7badc1..af3aeb440d2 100644 --- a/lib/private/TemplateLayout.php +++ b/lib/private/TemplateLayout.php @@ -52,6 +52,7 @@ use OCP\AppFramework\Http\TemplateResponse; use OCP\Defaults; use OCP\IConfig; use OCP\IInitialStateService; +use OCP\INavigationManager; use OCP\Support\Subscription\IRegistry; use OCP\Util; @@ -64,6 +65,9 @@ class TemplateLayout extends \OC_Template { /** @var IInitialStateService */ private $initialState; + /** @var INavigationManager */ + private $navigationManager; + /** * @param string $renderAs * @param string $appId application id @@ -74,7 +78,7 @@ class TemplateLayout extends \OC_Template { $this->config = \OC::$server->get(IConfig::class); /** @var IInitialStateService */ - $this->initialState = \OC::$server->get(InitialStateService::class); + $this->initialState = \OC::$server->get(IInitialStateService::class); if (Util::isIE()) { Util::addStyle('ie'); @@ -82,6 +86,9 @@ class TemplateLayout extends \OC_Template { // Decide which page we show if ($renderAs === TemplateResponse::RENDER_AS_USER) { + /** @var INavigationManager */ + $this->navigationManager = \OC::$server->get(INavigationManager::class); + parent::__construct('core', 'layout.user'); if (in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) { $this->assign('bodyid', 'body-settings'); @@ -89,16 +96,19 @@ class TemplateLayout extends \OC_Template { $this->assign('bodyid', 'body-user'); } + $this->initialState->provideInitialState('core', 'active-app', $this->navigationManager->getActiveEntry()); $this->initialState->provideInitialState('unified-search', 'limit-default', SearchQuery::LIMIT_DEFAULT); Util::addScript('dist/unified-search', null, true); // Add navigation entry $this->assign('application', ''); $this->assign('appid', $appId); - $navigation = \OC::$server->getNavigationManager()->getAll(); + + $navigation = $this->navigationManager->getAll(); $this->assign('navigation', $navigation); - $settingsNavigation = \OC::$server->getNavigationManager()->getAll('settings'); + $settingsNavigation = $this->navigationManager->getAll('settings'); $this->assign('settingsnavigation', $settingsNavigation); + foreach ($navigation as $entry) { if ($entry['active']) { $this->assign('application', $entry['name']); diff --git a/lib/private/legacy/OC_Template.php b/lib/private/legacy/OC_Template.php index 32d185d25fd..18a15ad1d43 100644 --- a/lib/private/legacy/OC_Template.php +++ b/lib/private/legacy/OC_Template.php @@ -115,9 +115,6 @@ class OC_Template extends \OC\Template\Base { OC_Util::addTranslations('core', null, true); if (\OC::$server->getSystemConfig()->getValue('installed', false)) { - OC_Util::addStyle('search', 'results'); - OC_Util::addScript('search', 'search', true); - OC_Util::addScript('search', 'searchprovider'); OC_Util::addScript('merged-template-prepend', null, true); OC_Util::addScript('dist/files_client', null, true); OC_Util::addScript('dist/files_fileinfo', null, true); diff --git a/lib/public/INavigationManager.php b/lib/public/INavigationManager.php index 198a9b11a3e..ac0d27eb5a1 100644 --- a/lib/public/INavigationManager.php +++ b/lib/public/INavigationManager.php @@ -82,6 +82,13 @@ interface INavigationManager { public function setActiveEntry($appId); /** + * Get the current navigation entry of the currently running app + * @return string + * @since 20.0.0 + */ + public function getActiveEntry(); + + /** * Get a list of navigation entries * * @param string $type type of the navigation entries diff --git a/lib/public/Search/IProvider.php b/lib/public/Search/IProvider.php index bdff0a66e0e..66db62c6829 100644 --- a/lib/public/Search/IProvider.php +++ b/lib/public/Search/IProvider.php @@ -65,6 +65,16 @@ interface IProvider { public function getName(): string; /** + * Get the search provider order + * The lower the int, the higher it will be sorted (0 will be before 10) + * + * @return int + * + * @since 20.0.0 + */ + public function getOrder(): int; + + /** * Find matching search entries in an app * * Search results can either be a complete list of all the matches the app can diff --git a/lib/public/Search/SearchResult.php b/lib/public/Search/SearchResult.php index 7abb5b9f188..8dbbcd96c26 100644 --- a/lib/public/Search/SearchResult.php +++ b/lib/public/Search/SearchResult.php @@ -38,7 +38,7 @@ final class SearchResult implements JsonSerializable { /** @var bool */ private $isPaginated; - /** @var ASearchResultEntry[] */ + /** @var SearchResultEntry[] */ private $entries; /** @var int|string|null */ @@ -47,7 +47,7 @@ final class SearchResult implements JsonSerializable { /** * @param string $name the translated name of the result section or group, e.g. "Mail" * @param bool $isPaginated - * @param ASearchResultEntry[] $entries + * @param SearchResultEntry[] $entries * @param null $cursor * * @since 20.0.0 @@ -63,7 +63,7 @@ final class SearchResult implements JsonSerializable { } /** - * @param ASearchResultEntry[] $entries + * @param SearchResultEntry[] $entries * * @return static * @@ -78,7 +78,7 @@ final class SearchResult implements JsonSerializable { } /** - * @param ASearchResultEntry[] $entries + * @param SearchResultEntry[] $entries * @param int|string $cursor * * @return static diff --git a/lib/public/Search/ASearchResultEntry.php b/lib/public/Search/SearchResultEntry.php index 584ae79de4d..a3d0d98560d 100644 --- a/lib/public/Search/ASearchResultEntry.php +++ b/lib/public/Search/SearchResultEntry.php @@ -34,7 +34,7 @@ use JsonSerializable; * The app providing the results has to extend this class for customization. In * most cases apps do not have to add any additional code. * - * @example ``class MailResultEntry extends ASearchResultEntry {}` + * @example ``class MailResultEntry extends SearchResultEntry {}` * * This approach was chosen over a final class as it allows Nextcloud to later * add new optional properties of an entry without having to break the usage of @@ -42,7 +42,7 @@ use JsonSerializable; * * @since 20.0.0 */ -abstract class ASearchResultEntry implements JsonSerializable { +class SearchResultEntry implements JsonSerializable { /** * @var string @@ -72,7 +72,7 @@ abstract class ASearchResultEntry implements JsonSerializable { * @var string * @since 20.0.0 */ - protected $iconClass; + protected $icon; /** * @var boolean @@ -85,7 +85,7 @@ abstract class ASearchResultEntry implements JsonSerializable { * @param string $title a main title of the entry * @param string $subline the secondary line of the entry * @param string $resourceUrl the URL where the user can find the detail, like a deep link inside the app - * @param string $iconClass the icon class fallback + * @param string $icon the icon class or url to the icon * @param boolean $rounded is the thumbnail rounded * * @since 20.0.0 @@ -94,13 +94,13 @@ abstract class ASearchResultEntry implements JsonSerializable { string $title, string $subline, string $resourceUrl, - string $iconClass = '', + string $icon = '', bool $rounded = false) { $this->thumbnailUrl = $thumbnailUrl; $this->title = $title; $this->subline = $subline; $this->resourceUrl = $resourceUrl; - $this->iconClass = $iconClass; + $this->icon = $icon; $this->rounded = $rounded; } @@ -115,7 +115,7 @@ abstract class ASearchResultEntry implements JsonSerializable { 'title' => $this->title, 'subline' => $this->subline, 'resourceUrl' => $this->resourceUrl, - 'iconClass' => $this->iconClass, + 'icon' => $this->icon, 'rounded' => $this->rounded, ]; } |