feat(files): add "search everywhere" button within the filters row
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>pull/53820/head
parent
b8d3e64205
commit
69275cbda5
@ -0,0 +1,47 @@
|
||||
<!--
|
||||
- SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
|
||||
- SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
-->
|
||||
|
||||
<template>
|
||||
<NcButton v-show="isVisible" @click="onClick">
|
||||
{{ t('files', 'Search everywhere') }}
|
||||
</NcButton>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { t } from '@nextcloud/l10n'
|
||||
import { ref } from 'vue'
|
||||
import NcButton from '@nextcloud/vue/components/NcButton'
|
||||
import { getPinia } from '../../store/index.ts'
|
||||
import { useSearchStore } from '../../store/search.ts'
|
||||
|
||||
const isVisible = ref(false)
|
||||
|
||||
defineExpose({
|
||||
hideButton,
|
||||
showButton,
|
||||
})
|
||||
|
||||
/**
|
||||
* Hide the button - called by the filter class
|
||||
*/
|
||||
function hideButton() {
|
||||
isVisible.value = false
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the button - called by the filter class
|
||||
*/
|
||||
function showButton() {
|
||||
isVisible.value = true
|
||||
}
|
||||
|
||||
/**
|
||||
* Button click handler to make the filtering a global search.
|
||||
*/
|
||||
function onClick() {
|
||||
const searchStore = useSearchStore(getPinia())
|
||||
searchStore.scope = 'globally'
|
||||
}
|
||||
</script>
|
||||
@ -0,0 +1,49 @@
|
||||
/*!
|
||||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
import type { INode } from '@nextcloud/files'
|
||||
import type { ComponentPublicInstance } from 'vue'
|
||||
|
||||
import { subscribe } from '@nextcloud/event-bus'
|
||||
import { FileListFilter, registerFileListFilter } from '@nextcloud/files'
|
||||
import Vue from 'vue'
|
||||
import FileListFilterToSearch from '../components/FileListFilter/FileListFilterToSearch.vue'
|
||||
|
||||
class SearchFilter extends FileListFilter {
|
||||
|
||||
private currentInstance?: ComponentPublicInstance<typeof FileListFilterToSearch>
|
||||
|
||||
constructor() {
|
||||
super('files:filter-to-search', 999)
|
||||
subscribe('files:search:updated', ({ query, scope }) => {
|
||||
if (query && scope === 'filter') {
|
||||
this.currentInstance?.showButton()
|
||||
} else {
|
||||
this.currentInstance?.hideButton()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
public mount(el: HTMLElement) {
|
||||
if (this.currentInstance) {
|
||||
this.currentInstance.$destroy()
|
||||
}
|
||||
|
||||
const View = Vue.extend(FileListFilterToSearch)
|
||||
this.currentInstance = new View().$mount(el) as unknown as ComponentPublicInstance<typeof FileListFilterToSearch>
|
||||
}
|
||||
|
||||
public filter(nodes: INode[]): INode[] {
|
||||
return nodes
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a file list filter to only show hidden files if enabled by user config
|
||||
*/
|
||||
export function registerFilterToSearchToggle() {
|
||||
registerFileListFilter(new SearchFilter())
|
||||
}
|
||||
Loading…
Reference in New Issue