mirror of
https://github.com/nextcloud/passman.git
synced 2024-09-20 14:56:21 +08:00
add search provider for global nextcloud search
This commit is contained in:
parent
db7e020360
commit
990ecf3534
|
@ -29,6 +29,7 @@ use OCA\Passman\Controller\ShareController;
|
|||
use OCA\Passman\Middleware\APIMiddleware;
|
||||
use OCA\Passman\Middleware\ShareMiddleware;
|
||||
use OCA\Passman\Notifier;
|
||||
use OCA\Passman\Search\Provider;
|
||||
use OCA\Passman\Service\ActivityService;
|
||||
use OCA\Passman\Service\CredentialService;
|
||||
use OCA\Passman\Service\CronService;
|
||||
|
@ -65,6 +66,7 @@ class Application extends App implements IBootstrap {
|
|||
UserDeletedListener::class
|
||||
);
|
||||
|
||||
$context->registerSearchProvider(Provider::class);
|
||||
|
||||
$context->registerService(View::class, function () {
|
||||
return new View('');
|
||||
|
|
78
lib/Search/Provider.php
Normal file
78
lib/Search/Provider.php
Normal file
|
@ -0,0 +1,78 @@
|
|||
<?php
|
||||
/**
|
||||
* Nextcloud - passman
|
||||
*
|
||||
* @copyright Copyright (c) 2016, Sander Brand (brantje@gmail.com)
|
||||
* @copyright Copyright (c) 2016, Marcos Zuriaga Miguel (wolfi@wolfi.es)
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Passman\Search;
|
||||
|
||||
use OCA\Passman\AppInfo\Application;
|
||||
use OCP\IL10N;
|
||||
use OCP\IURLGenerator;
|
||||
use OCP\IUser;
|
||||
use OCP\Search\IProvider;
|
||||
use OCP\Search\ISearchQuery;
|
||||
use OCP\Search\SearchResult;
|
||||
use OCP\Search\SearchResultEntry;
|
||||
|
||||
class Provider implements IProvider {
|
||||
|
||||
/** @var IL10N */
|
||||
private IL10N $l10n;
|
||||
|
||||
/** @var IURLGenerator */
|
||||
private IURLGenerator $urlGenerator;
|
||||
|
||||
public function __construct(IL10N $l10n, IURLGenerator $urlGenerator) {
|
||||
$this->l10n = $l10n;
|
||||
$this->urlGenerator = $urlGenerator;
|
||||
}
|
||||
|
||||
public function getId(): string {
|
||||
return Application::APP_ID;
|
||||
}
|
||||
|
||||
public function getName(): string {
|
||||
return $this->l10n->t('Passman');
|
||||
}
|
||||
|
||||
public function getOrder(string $route, array $routeParameters): int {
|
||||
if (strpos($route, Application::APP_ID . '.') === 0) {
|
||||
// Active app, prefer my results
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 25;
|
||||
}
|
||||
|
||||
public function search(IUser $user, ISearchQuery $query): SearchResult {
|
||||
return SearchResult::complete(
|
||||
$this->l10n->t(Application::APP_ID),
|
||||
[
|
||||
new SearchResultEntry(
|
||||
$this->urlGenerator->imagePath(Application::APP_ID, 'app.svg'),
|
||||
$this->l10n->t('Search in current page'),
|
||||
$this->l10n->t('This requires an already unlocked Passman vault'),
|
||||
'#?search=' . $query->getTerm()
|
||||
)
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue