mirror of
https://github.com/nextcloud/server.git
synced 2026-06-10 17:23:59 -04:00
We try to use named exports everywhere so also for the logger for consistency. Also the logger is more of a util then a main entry point so moved the implementation to the utils directory. Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
63 lines
1.9 KiB
TypeScript
63 lines
1.9 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 { getFilePickerBuilder } from '@nextcloud/dialogs'
|
|
import { emit } from '@nextcloud/event-bus'
|
|
import { translate as t } from '@nextcloud/l10n'
|
|
import { imagePath } from '@nextcloud/router'
|
|
import { logger } from '../../utils/logger.ts'
|
|
|
|
/**
|
|
* 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(t('files', 'Pick folder to search in'))
|
|
.setNoMenu(true)
|
|
.addMimeTypeFilter('httpd/unix-directory')
|
|
.allowDirectories(true)
|
|
.addButton({
|
|
label: 'Pick',
|
|
callback: (nodes: Node[]) => {
|
|
logger.info('Folder picked', { folder: nodes[0] })
|
|
const folder = nodes[0]
|
|
const filterUpdateText = (folder.root === '/files/' + folder.basename)
|
|
? t('files', 'Search in all files')
|
|
: t('files', 'Search in folder: {folder}', { folder: folder.basename })
|
|
emit('nextcloud:unified-search:add-filter', {
|
|
id: 'in-folder',
|
|
appId: 'files',
|
|
searchFrom: 'files',
|
|
payload: folder,
|
|
filterUpdateText,
|
|
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)
|