|
| 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); |
0 commit comments