18
18
:label =" t('core', 'Search apps, files, tags, messages') + '...'"
19
19
@update:value =" debouncedFind" />
20
20
<div class =" unified-search-modal__filters" >
21
- <NcActions :menu-name =" t('core', 'Apps and Settings ')" :open.sync =" providerActionMenuIsOpen" >
21
+ <NcActions :menu-name =" t('core', 'Places ')" :open.sync =" providerActionMenuIsOpen" >
22
22
<template #icon >
23
23
<ListBox :size =" 20" />
24
24
</template >
25
+ <!-- Provider id's may be duplicated since, plugin filters could depend on a provider that is already in the defaults.
26
+ provider.id concatenated to provider.name is used to create the item id, if same then, there should be an issue. -->
25
27
<NcActionButton v-for =" provider in providers"
26
- :key =" provider.id"
28
+ :key =" `${ provider.id}-${provider.name.replace(/\s/g, '')}` "
27
29
@click =" addProviderFilter(provider)" >
28
30
<template #icon >
29
31
<img :src =" provider.icon" class =" filter-button__icon" alt =" " >
@@ -150,8 +152,9 @@ import SearchableList from '../components/UnifiedSearch/SearchableList.vue'
150
152
import SearchResult from ' ../components/UnifiedSearch/SearchResult.vue'
151
153
152
154
import debounce from ' debounce'
153
- import { emit } from ' @nextcloud/event-bus'
155
+ import { emit , subscribe } from ' @nextcloud/event-bus'
154
156
import { useBrowserLocation } from ' @vueuse/core'
157
+ import { mapState } from ' vuex'
155
158
import { getProviders , search as unifiedSearch , getContacts } from ' ../services/UnifiedSearchService.js'
156
159
157
160
export default {
@@ -193,6 +196,7 @@ export default {
193
196
},
194
197
data () {
195
198
return {
199
+ searchScope: ' everywhere' ,
196
200
providers: [],
197
201
providerActionMenuIsOpen: false ,
198
202
dateActionMenuIsOpen: false ,
@@ -217,6 +221,9 @@ export default {
217
221
},
218
222
219
223
computed: {
224
+ ... mapState ({
225
+ externalFilters : state => state .search .externalFilters ,
226
+ }),
220
227
userContacts () {
221
228
return this .contacts
222
229
},
@@ -250,8 +257,12 @@ export default {
250
257
251
258
},
252
259
mounted () {
260
+ subscribe (' nextcloud:unified-search:conversation' , this .handlePluginFilter )
253
261
getProviders ().then ((providers ) => {
254
262
this .providers = providers
263
+ this .externalFilters .forEach (filter => {
264
+ this .providers .push (filter)
265
+ })
255
266
console .debug (' Search providers' , this .providers )
256
267
})
257
268
getContacts ({ searchTerm: ' ' }).then ((contacts ) => {
@@ -267,7 +278,6 @@ export default {
267
278
this .searching = false
268
279
return
269
280
}
270
- // Event should probably be refactored at some point to used nextcloud:unified-search.search
271
281
emit (' nextcloud:unified-search.search' , { query })
272
282
const newResults = []
273
283
const providersToSearch = this .filteredProviders .length > 0 ? this .filteredProviders : this .providers
@@ -276,6 +286,7 @@ export default {
276
286
type: provider .id ,
277
287
query,
278
288
cursor: null ,
289
+ extraQueries: provider .extraParams ,
279
290
}
280
291
281
292
if (filters .dateFilterIsApplied ) {
@@ -404,12 +415,27 @@ export default {
404
415
},
405
416
addProviderFilter (providerFilter , loadMoreResultsForProvider = false ) {
406
417
if (! providerFilter .id ) return
418
+ if (providerFilter .isPluginFilter ) {
419
+ providerFilter .callback ()
420
+ }
407
421
this .providerResultLimit = loadMoreResultsForProvider ? this .providerResultLimit : 5
408
422
this .providerActionMenuIsOpen = false
409
- const existingFilter = this .filteredProviders .find (existing => existing .id === providerFilter .id )
410
- if (! existingFilter) {
411
- this .filteredProviders .push ({ id: providerFilter .id , name: providerFilter .name , icon: providerFilter .icon , type: ' provider' , filters: providerFilter .filters })
423
+ // With the possibility for other apps to add new filters
424
+ // Resulting in a possible id/provider collision
425
+ // If a user tries to apply a filter that seems to already exist, we remove the current one and add the new one.
426
+ const existingFilterIndex = this .filteredProviders .findIndex (existing => existing .id === providerFilter .id )
427
+ if (existingFilterIndex > - 1 ) {
428
+ this .filteredProviders .splice (existingFilterIndex, 1 )
429
+ this .filters = this .syncProviderFilters (this .filters , this .filteredProviders )
412
430
}
431
+ this .filteredProviders .push ({
432
+ id: providerFilter .id ,
433
+ name: providerFilter .name ,
434
+ icon: providerFilter .icon ,
435
+ type: providerFilter .type || ' provider' ,
436
+ filters: providerFilter .filters ,
437
+ isPluginFilter: providerFilter .isPluginFilter || false ,
438
+ })
413
439
this .filters = this .syncProviderFilters (this .filters , this .filteredProviders )
414
440
console .debug (' Search filters (newly added)' , this .filters )
415
441
this .debouncedFind (this .searchQuery )
@@ -527,6 +553,23 @@ export default {
527
553
this .dateFilter .text = t (' core' , ` Between ${ this .dateFilter .startFrom .toLocaleDateString ()} and ${ this .dateFilter .endAt .toLocaleDateString ()} ` )
528
554
this .updateDateFilter ()
529
555
},
556
+ handlePluginFilter (addFilterEvent ) {
557
+ for (const provider of this .filteredProviders ) {
558
+ if (provider .id === addFilterEvent .id ) {
559
+ provider .name = addFilterEvent .filterUpdateText
560
+ // Filters attached may only make sense with certain providers,
561
+ // So, find the provider attached, add apply the exta parameters to those providers only
562
+ const compatibleProviderIndex = this .providers .findIndex (provider => provider .id === addFilterEvent .provider )
563
+ if (compatibleProviderIndex > - 1 ) {
564
+ provider .id = addFilterEvent .id
565
+ provider .extraParams = addFilterEvent .filterParams
566
+ }
567
+ break
568
+ }
569
+ }
570
+ console .debug (' Search scope set to conversation' , addFilterEvent)
571
+ this .debouncedFind (this .searchQuery )
572
+ },
530
573
focusInput () {
531
574
this .$refs .searchInput .$el .children [0 ].children [0 ].focus ()
532
575
},
@@ -549,7 +592,7 @@ export default {
549
592
padding- block: 10px 0 ;
550
593
551
594
// inline padding on direct children to make sure the scrollbar is on the modal container
552
- > * {
595
+ > * {
553
596
padding- inline: 20px ;
554
597
}
555
598
0 commit comments