aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfenn-cs <fenn25.fn@gmail.com>2024-03-03 13:28:40 +0100
committerfenn-cs <fenn25.fn@gmail.com>2024-03-07 21:10:54 +0100
commit035a2c706223475d9ea95430ddeae85645d03102 (patch)
treeaddbc688fab8a3d37430d50f1c4fd85e6e09c029
parent0fd31cdb4c1fb26bf5cd7645d4a187237687049d (diff)
downloadnextcloud-server-035a2c706223475d9ea95430ddeae85645d03102.tar.gz
nextcloud-server-035a2c706223475d9ea95430ddeae85645d03102.zip
feat(files): add search plugin to search in specified folder exclusively
Signed-off-by: fenn-cs <fenn25.fn@gmail.com>
-rw-r--r--apps/files/composer/composer/autoload_static.php2
-rw-r--r--apps/files/lib/AppInfo/Application.php3
-rw-r--r--apps/files/lib/Controller/ViewController.php2
-rw-r--r--apps/files/lib/Event/LoadSearchPlugins.php30
-rw-r--r--apps/files/lib/Listener/LoadSearchPluginsListener.php40
-rw-r--r--apps/files/src/plugins/search/folderSearch.ts68
-rw-r--r--webpack.modules.js1
7 files changed, 146 insertions, 0 deletions
diff --git a/apps/files/composer/composer/autoload_static.php b/apps/files/composer/composer/autoload_static.php
index d5b1947c1cc..1762b70d00c 100644
--- a/apps/files/composer/composer/autoload_static.php
+++ b/apps/files/composer/composer/autoload_static.php
@@ -70,11 +70,13 @@ class ComposerStaticInitFiles
'OCA\\Files\\DirectEditingCapabilities' => __DIR__ . '/..' . '/../lib/DirectEditingCapabilities.php',
'OCA\\Files\\Event\\LoadAdditionalScriptsEvent' => __DIR__ . '/..' . '/../lib/Event/LoadAdditionalScriptsEvent.php',
'OCA\\Files\\Event\\LoadSidebar' => __DIR__ . '/..' . '/../lib/Event/LoadSidebar.php',
+ 'OCA\\Files\\Event\\LoadSearchPlugins' => __DIR__ . '/..' . '/../lib/Event/LoadSearchPlugins.php',
'OCA\\Files\\Exception\\TransferOwnershipException' => __DIR__ . '/..' . '/../lib/Exception/TransferOwnershipException.php',
'OCA\\Files\\Helper' => __DIR__ . '/..' . '/../lib/Helper.php',
'OCA\\Files\\Listener\\LoadSidebarListener' => __DIR__ . '/..' . '/../lib/Listener/LoadSidebarListener.php',
'OCA\\Files\\Listener\\RenderReferenceEventListener' => __DIR__ . '/..' . '/../lib/Listener/RenderReferenceEventListener.php',
'OCA\\Files\\Listener\\SyncLivePhotosListener' => __DIR__ . '/..' . '/../lib/Listener/SyncLivePhotosListener.php',
+ 'OCA\\Files\\Listener\\LoadSearchPluginsListener' => __DIR__ . '/..' . '/../lib/Listener/LoadSearchPluginsListener.php',
'OCA\\Files\\Migration\\Version11301Date20191205150729' => __DIR__ . '/..' . '/../lib/Migration/Version11301Date20191205150729.php',
'OCA\\Files\\Migration\\Version12101Date20221011153334' => __DIR__ . '/..' . '/../lib/Migration/Version12101Date20221011153334.php',
'OCA\\Files\\Notification\\Notifier' => __DIR__ . '/..' . '/../lib/Notification/Notifier.php',
diff --git a/apps/files/lib/AppInfo/Application.php b/apps/files/lib/AppInfo/Application.php
index 41423a65ca7..85af06d4ca1 100644
--- a/apps/files/lib/AppInfo/Application.php
+++ b/apps/files/lib/AppInfo/Application.php
@@ -40,7 +40,9 @@ use OCA\Files\Collaboration\Resources\Listener;
use OCA\Files\Collaboration\Resources\ResourceProvider;
use OCA\Files\Controller\ApiController;
use OCA\Files\DirectEditingCapabilities;
+use OCA\Files\Event\LoadSearchPlugins;
use OCA\Files\Event\LoadSidebar;
+use OCA\Files\Listener\LoadSearchPluginsListener;
use OCA\Files\Listener\LoadSidebarListener;
use OCA\Files\Listener\RenderReferenceEventListener;
use OCA\Files\Listener\SyncLivePhotosListener;
@@ -129,6 +131,7 @@ class Application extends App implements IBootstrap {
$context->registerEventListener(BeforeNodeDeletedEvent::class, SyncLivePhotosListener::class);
$context->registerEventListener(BeforeNodeRestoredEvent::class, SyncLivePhotosListener::class);
$context->registerEventListener(CacheEntryRemovedEvent::class, SyncLivePhotosListener::class);
+ $context->registerEventListener(LoadSearchPlugins::class, LoadSearchPluginsListener::class);
$context->registerSearchProvider(FilesSearchProvider::class);
diff --git a/apps/files/lib/Controller/ViewController.php b/apps/files/lib/Controller/ViewController.php
index 12de4e1f6a2..2934ac06704 100644
--- a/apps/files/lib/Controller/ViewController.php
+++ b/apps/files/lib/Controller/ViewController.php
@@ -38,6 +38,7 @@ namespace OCA\Files\Controller;
use OCA\Files\Activity\Helper;
use OCA\Files\AppInfo\Application;
use OCA\Files\Event\LoadAdditionalScriptsEvent;
+use OCA\Files\Event\LoadSearchPlugins;
use OCA\Files\Event\LoadSidebar;
use OCA\Files\Service\UserConfig;
use OCA\Files\Service\ViewConfig;
@@ -260,6 +261,7 @@ class ViewController extends Controller {
$this->eventDispatcher->dispatchTyped($event);
$this->eventDispatcher->dispatchTyped(new ResourcesLoadAdditionalScriptsEvent());
$this->eventDispatcher->dispatchTyped(new LoadSidebar());
+ $this->eventDispatcher->dispatchTyped(new LoadSearchPlugins());
// Load Viewer scripts
if (class_exists(LoadViewer::class)) {
$this->eventDispatcher->dispatchTyped(new LoadViewer());
diff --git a/apps/files/lib/Event/LoadSearchPlugins.php b/apps/files/lib/Event/LoadSearchPlugins.php
new file mode 100644
index 00000000000..f1f5d6851af
--- /dev/null
+++ b/apps/files/lib/Event/LoadSearchPlugins.php
@@ -0,0 +1,30 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright Copyright (c) 2024, Fon E. Noel NFEBE <opensource@nfebe.com>
+ *
+ *
+ * @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\Files\Event;
+
+use OCP\EventDispatcher\Event;
+
+class LoadSearchPlugins extends Event {
+}
diff --git a/apps/files/lib/Listener/LoadSearchPluginsListener.php b/apps/files/lib/Listener/LoadSearchPluginsListener.php
new file mode 100644
index 00000000000..94529987290
--- /dev/null
+++ b/apps/files/lib/Listener/LoadSearchPluginsListener.php
@@ -0,0 +1,40 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2024 Fon E. Noel NFEBE <opensource@nfebe.com>
+ *
+ * @author Fon E. Noel NFEBE <opensource@nfebe.com>
+ *
+ * @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\Files\Listener;
+
+use OCA\Files\Event\LoadSearchPlugins;
+use OCP\EventDispatcher\Event;
+use OCP\EventDispatcher\IEventListener;
+
+/** @template-implements IEventListener<LoadSearchPlugins> */
+class LoadSearchPluginsListener implements IEventListener {
+ public function handle(Event $event): void {
+ if (!$event instanceof LoadSearchPlugins) {
+ return;
+ }
+
+ \OCP\Util::addScript('files', 'search');
+ }
+}
diff --git a/apps/files/src/plugins/search/folderSearch.ts b/apps/files/src/plugins/search/folderSearch.ts
new file mode 100644
index 00000000000..d5f164abb8f
--- /dev/null
+++ b/apps/files/src/plugins/search/folderSearch.ts
@@ -0,0 +1,68 @@
+/**
+ * @copyright Copyright (c) 2024 Fon E. Noel NFEBE <opensource@nfebe.com>
+ *
+ * @author Fon E. Noel NFEBE <opensource@nfebe.com>
+ *
+ * @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/>.
+ */
+
+import type { Node } from '@nextcloud/files'
+import { emit } from '@nextcloud/event-bus'
+import { getFilePickerBuilder } from '@nextcloud/dialogs';
+import { imagePath } from '@nextcloud/router'
+import { translate as t } from '@nextcloud/l10n'
+import logger from '../../logger'
+import '@nextcloud/dialogs/style.css'
+
+/**
+ * Initialize the unified search plugin.
+ */
+function init() {
+ const OCA = window.OCA
+ if (!OCA.UnifiedSearch) {
+ return;
+ }
+
+ logger.info('Initializing unified search plugin: folder search from files app');
+ OCA.UnifiedSearch.registerFilterAction({
+ id: 'files',
+ appId: 'files',
+ label: t('files', 'In folder'),
+ icon: imagePath('files', 'app.svg'),
+ callback: () => {
+ const filepicker = getFilePickerBuilder('Pick plain text files')
+ .addMimeTypeFilter('httpd/unix-directory')
+ .allowDirectories(true)
+ .addButton({
+ label: 'Pick',
+ callback: (nodes: Node[]) => {
+ logger.info('Folder picked', { folder: nodes[0] })
+ const folder = nodes[0]
+ emit('nextcloud:unified-search:add-filter', {
+ id: 'files',
+ payload: folder,
+ filterUpdateText: t('files', 'Search in folder: {folder}', { folder: folder.basename }),
+ filterParams: { path: folder.path },
+ })
+ },
+ })
+ .build()
+ filepicker.pick()
+ },
+ })
+}
+
+document.addEventListener('DOMContentLoaded', init);
diff --git a/webpack.modules.js b/webpack.modules.js
index 2ef663376c5..4b258c58ac2 100644
--- a/webpack.modules.js
+++ b/webpack.modules.js
@@ -53,6 +53,7 @@ module.exports = {
sidebar: path.join(__dirname, 'apps/files/src', 'sidebar.js'),
main: path.join(__dirname, 'apps/files/src', 'main.ts'),
init: path.join(__dirname, 'apps/files/src', 'init.ts'),
+ search: path.join(__dirname, 'apps/files/src/plugins/search', 'folderSearch.ts'),
'personal-settings': path.join(__dirname, 'apps/files/src', 'main-personal-settings.js'),
'reference-files': path.join(__dirname, 'apps/files/src', 'reference-files.ts'),
},