Skip to content

Commit dc79591

Browse files
authored
Merge pull request #43963 from nextcloud/42915-search-in-folder
feat: allow limit unified search to folder
2 parents 35ab489 + 108e694 commit dc79591

37 files changed

Lines changed: 243 additions & 40 deletions

apps/files/composer/composer/autoload_classmap.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,11 @@
5454
'OCA\\Files\\Db\\TransferOwnershipMapper' => $baseDir . '/../lib/Db/TransferOwnershipMapper.php',
5555
'OCA\\Files\\DirectEditingCapabilities' => $baseDir . '/../lib/DirectEditingCapabilities.php',
5656
'OCA\\Files\\Event\\LoadAdditionalScriptsEvent' => $baseDir . '/../lib/Event/LoadAdditionalScriptsEvent.php',
57+
'OCA\\Files\\Event\\LoadSearchPlugins' => $baseDir . '/../lib/Event/LoadSearchPlugins.php',
5758
'OCA\\Files\\Event\\LoadSidebar' => $baseDir . '/../lib/Event/LoadSidebar.php',
5859
'OCA\\Files\\Exception\\TransferOwnershipException' => $baseDir . '/../lib/Exception/TransferOwnershipException.php',
5960
'OCA\\Files\\Helper' => $baseDir . '/../lib/Helper.php',
61+
'OCA\\Files\\Listener\\LoadSearchPluginsListener' => $baseDir . '/../lib/Listener/LoadSearchPluginsListener.php',
6062
'OCA\\Files\\Listener\\LoadSidebarListener' => $baseDir . '/../lib/Listener/LoadSidebarListener.php',
6163
'OCA\\Files\\Listener\\RenderReferenceEventListener' => $baseDir . '/../lib/Listener/RenderReferenceEventListener.php',
6264
'OCA\\Files\\Listener\\SyncLivePhotosListener' => $baseDir . '/../lib/Listener/SyncLivePhotosListener.php',

apps/files/composer/composer/autoload_static.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,11 @@ class ComposerStaticInitFiles
6969
'OCA\\Files\\Db\\TransferOwnershipMapper' => __DIR__ . '/..' . '/../lib/Db/TransferOwnershipMapper.php',
7070
'OCA\\Files\\DirectEditingCapabilities' => __DIR__ . '/..' . '/../lib/DirectEditingCapabilities.php',
7171
'OCA\\Files\\Event\\LoadAdditionalScriptsEvent' => __DIR__ . '/..' . '/../lib/Event/LoadAdditionalScriptsEvent.php',
72+
'OCA\\Files\\Event\\LoadSearchPlugins' => __DIR__ . '/..' . '/../lib/Event/LoadSearchPlugins.php',
7273
'OCA\\Files\\Event\\LoadSidebar' => __DIR__ . '/..' . '/../lib/Event/LoadSidebar.php',
7374
'OCA\\Files\\Exception\\TransferOwnershipException' => __DIR__ . '/..' . '/../lib/Exception/TransferOwnershipException.php',
7475
'OCA\\Files\\Helper' => __DIR__ . '/..' . '/../lib/Helper.php',
76+
'OCA\\Files\\Listener\\LoadSearchPluginsListener' => __DIR__ . '/..' . '/../lib/Listener/LoadSearchPluginsListener.php',
7577
'OCA\\Files\\Listener\\LoadSidebarListener' => __DIR__ . '/..' . '/../lib/Listener/LoadSidebarListener.php',
7678
'OCA\\Files\\Listener\\RenderReferenceEventListener' => __DIR__ . '/..' . '/../lib/Listener/RenderReferenceEventListener.php',
7779
'OCA\\Files\\Listener\\SyncLivePhotosListener' => __DIR__ . '/..' . '/../lib/Listener/SyncLivePhotosListener.php',

apps/files/composer/composer/installed.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
'name' => '__root__',
44
'pretty_version' => 'dev-master',
55
'version' => 'dev-master',
6-
'reference' => 'ba1af2b22e5409c62ea2bdf7eb0e13c282ed70e8',
6+
'reference' => '696a068b89cffe10c6c4eb8db9eba9ad66e342f7',
77
'type' => 'library',
88
'install_path' => __DIR__ . '/../',
99
'aliases' => array(),
@@ -13,7 +13,7 @@
1313
'__root__' => array(
1414
'pretty_version' => 'dev-master',
1515
'version' => 'dev-master',
16-
'reference' => 'ba1af2b22e5409c62ea2bdf7eb0e13c282ed70e8',
16+
'reference' => '696a068b89cffe10c6c4eb8db9eba9ad66e342f7',
1717
'type' => 'library',
1818
'install_path' => __DIR__ . '/../',
1919
'aliases' => array(),

apps/files/lib/AppInfo/Application.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@
4040
use OCA\Files\Collaboration\Resources\ResourceProvider;
4141
use OCA\Files\Controller\ApiController;
4242
use OCA\Files\DirectEditingCapabilities;
43+
use OCA\Files\Event\LoadSearchPlugins;
4344
use OCA\Files\Event\LoadSidebar;
45+
use OCA\Files\Listener\LoadSearchPluginsListener;
4446
use OCA\Files\Listener\LoadSidebarListener;
4547
use OCA\Files\Listener\RenderReferenceEventListener;
4648
use OCA\Files\Listener\SyncLivePhotosListener;
@@ -129,6 +131,7 @@ public function register(IRegistrationContext $context): void {
129131
$context->registerEventListener(BeforeNodeDeletedEvent::class, SyncLivePhotosListener::class);
130132
$context->registerEventListener(BeforeNodeRestoredEvent::class, SyncLivePhotosListener::class);
131133
$context->registerEventListener(CacheEntryRemovedEvent::class, SyncLivePhotosListener::class);
134+
$context->registerEventListener(LoadSearchPlugins::class, LoadSearchPluginsListener::class);
132135

133136
$context->registerSearchProvider(FilesSearchProvider::class);
134137

apps/files/lib/Controller/ViewController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
use OCA\Files\Activity\Helper;
3939
use OCA\Files\AppInfo\Application;
4040
use OCA\Files\Event\LoadAdditionalScriptsEvent;
41+
use OCA\Files\Event\LoadSearchPlugins;
4142
use OCA\Files\Event\LoadSidebar;
4243
use OCA\Files\Service\UserConfig;
4344
use OCA\Files\Service\ViewConfig;
@@ -260,6 +261,7 @@ public function index($dir = '', $view = '', $fileid = null, $fileNotFound = fal
260261
$this->eventDispatcher->dispatchTyped($event);
261262
$this->eventDispatcher->dispatchTyped(new ResourcesLoadAdditionalScriptsEvent());
262263
$this->eventDispatcher->dispatchTyped(new LoadSidebar());
264+
$this->eventDispatcher->dispatchTyped(new LoadSearchPlugins());
263265
// Load Viewer scripts
264266
if (class_exists(LoadViewer::class)) {
265267
$this->eventDispatcher->dispatchTyped(new LoadViewer());
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright Copyright (c) 2024, Fon E. Noel NFEBE <opensource@nfebe.com>
7+
*
8+
*
9+
* @license GNU AGPL version 3 or any later version
10+
*
11+
* This program is free software: you can redistribute it and/or modify
12+
* it under the terms of the GNU Affero General Public License as
13+
* published by the Free Software Foundation, either version 3 of the
14+
* License, or (at your option) any later version.
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU Affero General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU Affero General Public License
22+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
23+
*
24+
*/
25+
namespace OCA\Files\Event;
26+
27+
use OCP\EventDispatcher\Event;
28+
29+
class LoadSearchPlugins extends Event {
30+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* @copyright Copyright (c) 2024 Fon E. Noel NFEBE <opensource@nfebe.com>
6+
*
7+
* @author Fon E. Noel NFEBE <opensource@nfebe.com>
8+
*
9+
* @license GNU AGPL version 3 or any later version
10+
*
11+
* This program is free software: you can redistribute it and/or modify
12+
* it under the terms of the GNU Affero General Public License as
13+
* published by the Free Software Foundation, either version 3 of the
14+
* License, or (at your option) any later version.
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU Affero General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU Affero General Public License
22+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
23+
*/
24+
25+
namespace OCA\Files\Listener;
26+
27+
use OCA\Files\Event\LoadSearchPlugins;
28+
use OCP\EventDispatcher\Event;
29+
use OCP\EventDispatcher\IEventListener;
30+
31+
/** @template-implements IEventListener<LoadSearchPlugins> */
32+
class LoadSearchPluginsListener implements IEventListener {
33+
public function handle(Event $event): void {
34+
if (!$event instanceof LoadSearchPlugins) {
35+
return;
36+
}
37+
38+
\OCP\Util::addScript('files', 'search');
39+
}
40+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/**
2+
* @copyright Copyright (c) 2024 Fon E. Noel NFEBE <opensource@nfebe.com>
3+
*
4+
* @author Fon E. Noel NFEBE <opensource@nfebe.com>
5+
*
6+
* @license GNU AGPL version 3 or any later version
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU Affero General Public License as
10+
* published by the Free Software Foundation, either version 3 of the
11+
* License, or (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU Affero General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Affero General Public License
19+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20+
*/
21+
22+
import type { Node } from '@nextcloud/files'
23+
import { emit } from '@nextcloud/event-bus'
24+
import { getFilePickerBuilder } from '@nextcloud/dialogs';
25+
import { imagePath } from '@nextcloud/router'
26+
import { translate as t } from '@nextcloud/l10n'
27+
import logger from '../../logger'
28+
import '@nextcloud/dialogs/style.css'
29+
30+
/**
31+
* Initialize the unified search plugin.
32+
*/
33+
function init() {
34+
const OCA = window.OCA
35+
if (!OCA.UnifiedSearch) {
36+
return;
37+
}
38+
39+
logger.info('Initializing unified search plugin: folder search from files app');
40+
OCA.UnifiedSearch.registerFilterAction({
41+
id: 'files',
42+
appId: 'files',
43+
label: t('files', 'In folder'),
44+
icon: imagePath('files', 'app.svg'),
45+
callback: () => {
46+
const filepicker = getFilePickerBuilder('Pick plain text files')
47+
.addMimeTypeFilter('httpd/unix-directory')
48+
.allowDirectories(true)
49+
.addButton({
50+
label: 'Pick',
51+
callback: (nodes: Node[]) => {
52+
logger.info('Folder picked', { folder: nodes[0] })
53+
const folder = nodes[0]
54+
emit('nextcloud:unified-search:add-filter', {
55+
id: 'files',
56+
payload: folder,
57+
filterUpdateText: t('files', 'Search in folder: {folder}', { folder: folder.basename }),
58+
filterParams: { path: folder.path },
59+
})
60+
},
61+
})
62+
.build()
63+
filepicker.pick()
64+
},
65+
})
66+
}
67+
68+
document.addEventListener('DOMContentLoaded', init);
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,19 @@ Vue.mixin({
4949
},
5050
})
5151

52+
// Define type structure for unified searc action
53+
interface UnifiedSearchAction {
54+
id: string;
55+
appId: string;
56+
label: string;
57+
icon: string;
58+
callback: () => void;
59+
}
60+
5261
// Register the add/register filter action API globally
5362
window.OCA = window.OCA || {}
5463
window.OCA.UnifiedSearch = {
55-
registerFilterAction: ({ id, appId, label, callback, icon }) => {
64+
registerFilterAction: ({ id, appId, label, callback, icon }: UnifiedSearchAction) => {
5665
const searchStore = useSearchStore()
5766
searchStore.registerExternalFilter({ id, appId, label, callback, icon })
5867
},

dist/core-common.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)