@ -18,12 +18,14 @@
: label = "t('core', 'Search apps, files, tags, messages') + '...'"
@ update : value = "debouncedFind" / >
< div class = "unified-search-modal__filters" >
< NcActions : menu -name = " t ( ' core ' , ' Apps and Setting s' ) " :open.sync ="providerActionMenuIsOpen" >
< NcActions : menu -name = " t ( ' core ' , ' Place s' ) " :open.sync ="providerActionMenuIsOpen" >
< template # icon >
< ListBox :size ="20" / >
< / template >
<!-- Provider id ' s may be duplicated since , plugin filters could depend on a provider that is already in the defaults .
provider . id concatenated to provider . name is used to create the item id , if same then , there should be an issue . -- >
< NcActionButton v -for = " provider in providers "
: key = "provider.id"
: key = " `${ provider.id}-${provider.name.replace(/\s/g, '')}` "
@ click = "addProviderFilter(provider)" >
< template # icon >
< img :src ="provider.icon" class = "filter-button__icon" alt = "" >
@ -150,8 +152,9 @@ import SearchableList from '../components/UnifiedSearch/SearchableList.vue'
import SearchResult from '../components/UnifiedSearch/SearchResult.vue'
import debounce from 'debounce'
import { emit } from '@nextcloud/event-bus'
import { emit , subscribe } from '@nextcloud/event-bus'
import { useBrowserLocation } from '@vueuse/core'
import { mapState } from 'vuex'
import { getProviders , search as unifiedSearch , getContacts } from '../services/UnifiedSearchService.js'
export default {
@ -217,6 +220,9 @@ export default {
} ,
computed : {
... mapState ( {
externalFilters : state => state . search . externalFilters ,
} ) ,
userContacts ( ) {
return this . contacts
} ,
@ -258,8 +264,13 @@ export default {
} ,
mounted ( ) {
subscribe ( 'nextcloud:unified-search:add-filter' , this . handlePluginFilter )
getProviders ( ) . then ( ( providers ) => {
this . providers = providers
this . externalFilters . forEach ( filter => {
this . providers . push ( filter )
} )
this . providers = this . groupProvidersByApp ( this . providers )
console . debug ( 'Search providers' , this . providers )
} )
getContacts ( { searchTerm : '' } ) . then ( ( contacts ) => {
@ -284,6 +295,7 @@ export default {
type : provider . id ,
query ,
cursor : null ,
extraQueries : provider . extraParams ,
}
if ( filters . dateFilterIsApplied ) {
@ -412,12 +424,27 @@ export default {
} ,
addProviderFilter ( providerFilter , loadMoreResultsForProvider = false ) {
if ( ! providerFilter . id ) return
if ( providerFilter . isPluginFilter ) {
providerFilter . callback ( )
}
this . providerResultLimit = loadMoreResultsForProvider ? this . providerResultLimit : 5
this . providerActionMenuIsOpen = false
const existingFilter = this . filteredProviders . find ( existing => existing . id === providerFilter . id )
if ( ! existingFilter ) {
this . filteredProviders . push ( { id : providerFilter . id , name : providerFilter . name , icon : providerFilter . icon , type : 'provider' , filters : providerFilter . filters } )
/ / W i t h t h e p o s s i b i l i t y f o r o t h e r a p p s t o a d d n e w f i l t e r s
/ / R e s u l t i n g i n a p o s s i b l e i d / p r o v i d e r c o l l i s i o n
/ / I f a u s e r t r i e s t o a p p l y a f i l t e r t h a t s e e m s t o a l r e a d y e x i s t , w e r e m o v e t h e c u r r e n t o n e a n d a d d t h e n e w o n e .
const existingFilterIndex = this . filteredProviders . findIndex ( existing => existing . id === providerFilter . id )
if ( existingFilterIndex > - 1 ) {
this . filteredProviders . splice ( existingFilterIndex , 1 )
this . filters = this . syncProviderFilters ( this . filters , this . filteredProviders )
}
this . filteredProviders . push ( {
id : providerFilter . id ,
name : providerFilter . name ,
icon : providerFilter . icon ,
type : providerFilter . type || 'provider' ,
filters : providerFilter . filters ,
isPluginFilter : providerFilter . isPluginFilter || false ,
} )
this . filters = this . syncProviderFilters ( this . filters , this . filteredProviders )
console . debug ( 'Search filters (newly added)' , this . filters )
this . debouncedFind ( this . searchQuery )
@ -535,6 +562,42 @@ export default {
this . dateFilter . text = t ( 'core' , ` Between ${ this . dateFilter . startFrom . toLocaleDateString ( ) } and ${ this . dateFilter . endAt . toLocaleDateString ( ) } ` )
this . updateDateFilter ( )
} ,
handlePluginFilter ( addFilterEvent ) {
for ( let i = 0 ; i < this . filteredProviders . length ; i ++ ) {
const provider = this . filteredProviders [ i ]
if ( provider . id === addFilterEvent . id ) {
provider . name = addFilterEvent . filterUpdateText
/ / F i l t e r s a t t a c h e d m a y o n l y m a k e s e n s e w i t h c e r t a i n p r o v i d e r s ,
/ / S o , f i n d t h e p r o v i d e r a t t a c h e d , a d d a p p l y t h e e x t r a p a r a m e t e r s t o t h o s e p r o v i d e r s o n l y
const compatibleProviderIndex = this . providers . findIndex ( provider => provider . id === addFilterEvent . id )
if ( compatibleProviderIndex > - 1 ) {
provider . extraParams = addFilterEvent . filterParams
this . filteredProviders [ i ] = provider
}
break
}
}
console . debug ( 'Search scope set to conversation' , addFilterEvent )
this . debouncedFind ( this . searchQuery )
} ,
groupProvidersByApp ( filters ) {
const groupedByProviderApp = { }
filters . forEach ( filter => {
const provider = filter . appId ? filter . appId : 'general'
if ( ! groupedByProviderApp [ provider ] ) {
groupedByProviderApp [ provider ] = [ ]
}
groupedByProviderApp [ provider ] . push ( filter )
} )
const flattenedArray = [ ]
Object . values ( groupedByProviderApp ) . forEach ( group => {
flattenedArray . push ( ... group )
} )
return flattenedArray
} ,
focusInput ( ) {
this . $refs . searchInput . $el . children [ 0 ] . children [ 0 ] . focus ( )
} ,
@ -557,7 +620,7 @@ export default {
padding - block : 10 px 0 ;
/ / i n l i n e p a d d i n g o n d i r e c t c h i l d r e n t o m a k e s u r e t h e s c r o l l b a r i s o n t h e m o d a l c o n t a i n e r
> * {
> * {
padding - inline : 20 px ;
}