-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
While api not implemented on our Reva banckend
- Loading branch information
Showing
8 changed files
with
161 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { Registry } from '../services' | ||
import { mapMutations } from 'vuex' | ||
import { onBeforeUnmount } from 'vue' | ||
|
||
export default { | ||
mounted() { | ||
const { filterSearch } = Registry | ||
|
||
if (!filterSearch || !filterSearch.available) { | ||
return | ||
} | ||
|
||
const resetEventToken = filterSearch.subscribe('reset', () => { | ||
this.CLEAR_FILES_SEARCHED() | ||
}) | ||
|
||
const updateTermEventToken = filterSearch.subscribe('updateTerm', (term) => { | ||
if (!term) { | ||
this.CLEAR_FILES_SEARCHED() | ||
} | ||
}) | ||
|
||
const activateEventToken = filterSearch.subscribe('activate', ({ resources }) => { | ||
this.LOAD_FILES_SEARCHED(resources) | ||
}) | ||
|
||
onBeforeUnmount(() => { | ||
filterSearch.unsubscribe('reset', resetEventToken) | ||
filterSearch.unsubscribe('updateTerm', updateTermEventToken) | ||
filterSearch.unsubscribe('activate', activateEventToken) | ||
}) | ||
}, | ||
watch: { | ||
$route: { | ||
handler: function (to, from) { | ||
if (to.name === from?.name && to.params?.item === from?.params?.item) { | ||
return | ||
} | ||
|
||
this.CLEAR_FILES_SEARCHED() | ||
}, | ||
immediate: true | ||
} | ||
}, | ||
methods: { | ||
...mapMutations('Files', ['CLEAR_FILES_SEARCHED', 'LOAD_FILES_SEARCHED']) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { SearchProvider, SearchList, SearchPreview } from 'web-app-search/src/types' | ||
import Preview from './preview' | ||
import { EventBus } from 'web-pkg/src/services/eventBus' | ||
import { filterResources } from '../../helpers/resource' | ||
import { Store } from 'vuex' | ||
import { Router } from 'vue-router' | ||
import { isLocationSpacesActive } from '../../router' | ||
|
||
function $gettext(msg) { | ||
return msg | ||
} | ||
export default class Provider extends EventBus implements SearchProvider { | ||
public readonly id: string | ||
public readonly displayName: string | ||
public readonly previewSearch: SearchPreview | ||
public readonly listSearch: SearchList | ||
private readonly store: Store<any> | ||
private readonly router: Router | ||
|
||
constructor(store: Store<any>, router: Router) { | ||
super() | ||
|
||
this.id = 'files.filter' | ||
this.displayName = $gettext('In this folder') | ||
this.store = store | ||
this.router = router | ||
this.previewSearch = new Preview(store, router) | ||
} | ||
|
||
public activate(term: string): void { | ||
if (!term) { | ||
return | ||
} | ||
|
||
const resources = filterResources(this.store.getters['Files/files'], term) | ||
this.publish('activate', { term, resources }) | ||
} | ||
|
||
public reset(): void { | ||
this.publish('reset') | ||
} | ||
|
||
public updateTerm(term: string): void { | ||
this.publish('updateTerm', term) | ||
} | ||
|
||
public get available(): boolean { | ||
return ( | ||
isLocationSpacesActive(this.router, 'files-spaces-generic') && | ||
!isLocationSpacesActive(this.router, 'files-spaces-projects') | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { SearchPreview, SearchResult } from 'web-app-search/src/types' | ||
import PreviewComponent from '../../components/Search/Preview.vue' | ||
import { filterResources } from '../../helpers/resource' | ||
import { Store } from 'vuex' | ||
import { Component, unref } from 'vue' | ||
import { Router } from 'vue-router' | ||
|
||
export default class Preview implements SearchPreview { | ||
public readonly component: Component | ||
private readonly router: Router | ||
private readonly store: Store<any> | ||
|
||
constructor(store: Store<any>, router: Router) { | ||
this.component = PreviewComponent | ||
this.router = router | ||
this.store = store | ||
} | ||
|
||
public search(term: string): Promise<SearchResult> { | ||
if (!term) { | ||
return Promise.resolve({ | ||
totalResults: null, | ||
values: [] | ||
}) | ||
} | ||
// no cache required, the filtering is client only and fast enough to recalculate the set | ||
// of results every time on the fly | ||
const resources: any[] = filterResources(this.store.getters['Files/files'], term, 5) | ||
const areHiddenFilesShown = this.store.state.Files?.areHiddenFilesShown | ||
|
||
const searchResult = resources.reduce((acc, resource) => { | ||
// filter results if hidden files shouldn't be shown due to settings | ||
if (!resource.name.startsWith('.') || areHiddenFilesShown) { | ||
acc.push({ id: resource.id, data: { ...resource, storageId: 'eos' } }) | ||
} | ||
|
||
return acc | ||
}, []) | ||
|
||
return Promise.resolve({ totalResults: searchResult.length, values: searchResult }) | ||
} | ||
|
||
public get available(): boolean { | ||
return unref(this.router.currentRoute).name !== 'search-provider-list' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export { default as SDKSearch } from './sdk' | ||
export { default as FilterSearch } from './filter' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import { SDKSearch } from '../search' | ||
import { FilterSearch, SDKSearch } from '../search' | ||
|
||
export default class Registry { | ||
static filterSearch: FilterSearch | ||
static sdkSearch: SDKSearch | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters