mirror of
https://github.com/nextcloud/server.git
synced 2026-06-12 02:00:51 -04:00
The client-side plugin `in-folder` uses the `files` provider, this makes it
overlap with the main files provider itself.
This change follows eecda06f1a after it was discovered
that some apps/providers like `dav` use providers from another app like `contacts`
Signed-off-by: nfebe <fenn25.fn@gmail.com>
Signed-off-by: nextcloud-command <nextcloud-command@users.noreply.github.com>
58 lines
1.7 KiB
TypeScript
58 lines
1.7 KiB
TypeScript
/**
|
|
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
*/
|
|
|
|
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'
|
|
|
|
/**
|
|
* 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: 'in-folder',
|
|
appId: 'files',
|
|
searchFrom: 'files',
|
|
label: t('files', 'In folder'),
|
|
icon: imagePath('files', 'app.svg'),
|
|
callback: (showFilePicker: boolean = true) => {
|
|
if (showFilePicker) {
|
|
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: 'in-folder',
|
|
appId: 'files',
|
|
searchFrom: 'files',
|
|
payload: folder,
|
|
filterUpdateText: t('files', 'Search in folder: {folder}', { folder: folder.basename }),
|
|
filterParams: { path: folder.path },
|
|
})
|
|
},
|
|
})
|
|
.build()
|
|
filepicker.pick()
|
|
} else {
|
|
logger.debug('Folder search callback was handled without showing the file picker, it might already be open')
|
|
}
|
|
},
|
|
})
|
|
}
|
|
|
|
document.addEventListener('DOMContentLoaded', init)
|