From 9e03ecc873d6223599d5eeb7f922ac183870ccc7 Mon Sep 17 00:00:00 2001 From: Matthias Mohr Date: Fri, 8 Mar 2024 00:20:53 +0100 Subject: [PATCH] Add filter for keywords in catalog overview --- src/components/Catalogs.vue | 92 +++++++++++++++++++++++++++------ src/components/SearchBox.vue | 10 ++-- src/components/SearchFilter.vue | 54 ++----------------- src/locales/de/texts.json | 3 +- src/locales/en/texts.json | 1 + src/theme/page.scss | 55 +++++++++++++++++++- 6 files changed, 142 insertions(+), 73 deletions(-) diff --git a/src/components/Catalogs.vue b/src/components/Catalogs.vue index ae00e108d..0adeb4bfd 100644 --- a/src/components/Catalogs.vue +++ b/src/components/Catalogs.vue @@ -6,9 +6,19 @@ - +
+ + +
- {{ $t('catalogs.noMatches') }} + {{ $t('catalogs.noMatches') }}
@@ -39,7 +49,8 @@ export default { Loading, Pagination: () => import('./Pagination.vue'), SearchBox: () => import('./SearchBox.vue'), - SortButtons: () => import('./SortButtons.vue') + SortButtons: () => import('./SortButtons.vue'), + Multiselect: () => import('vue-multiselect') }, mixins: [ ViewMixin @@ -73,7 +84,8 @@ export default { data() { return { searchTerm: '', - sort: 0 + sort: 0, + selectedKeywords: [] }; }, computed: { @@ -109,25 +121,40 @@ export default { // Check whether any pagination links are available return Object.values(this.pagination).some(link => !!link); }, + allCatalogs() { + return this.catalogs.map(catalog => { + let stac = this.getStac(catalog); + return stac ? stac : catalog; + }); + }, + hasSearchCritera() { + return this.searchTerm || this.selectedKeywords.length > 0; + }, catalogView() { if (this.hasMore) { return this.catalogs; } - let catalogs = this.catalogs.map(catalog => { - let stac = this.getStac(catalog); - return stac ? stac : catalog; - }); // Filter - if (this.searchTerm) { + let catalogs = this.allCatalogs; + if (this.hasSearchCritera) { catalogs = catalogs.filter(catalog => { - let haystack = [ catalog.title ]; - if (catalog instanceof STAC && this.isComplete) { - haystack.push(catalog.id); - if (Array.isArray(catalog.keywords)) { - haystack = haystack.concat(catalog.keywords); + if (this.selectedKeywords.length > 0 && catalog instanceof STAC && Array.isArray(catalog.keywords)) { + let hasKeywords = this.selectedKeywords.every(keyword => catalog.keywords.includes(keyword)); + if (!hasKeywords) { + return false; + } + } + if (this.searchTerm) { + let haystack = [ catalog.title ]; + if (catalog instanceof STAC && this.isComplete) { + haystack.push(catalog.id); + if (Array.isArray(catalog.keywords)) { + haystack = haystack.concat(catalog.keywords); + } } + return Utils.search(this.searchTerm, haystack); } - return Utils.search(this.searchTerm, haystack); + return true; }); } // Sort @@ -138,6 +165,22 @@ export default { } } return catalogs; + }, + allKeywords() { + if (!this.isComplete) { + return []; + } + let keywords = []; + for(let catalog of this.allCatalogs) { + if (catalog instanceof STAC && Array.isArray(catalog.keywords)) { + for(let keyword of catalog.keywords) { + if (!keywords.includes(keyword)) { + keywords.push(keyword); + } + } + } + } + return keywords.sort(); } }, created() { @@ -157,7 +200,26 @@ export default { Utils.scrollTo(this.$refs.topPagination.$el); } this.$emit('paginate', link); + }, + limitText(count) { + return this.$t("multiselect.andMore", {count}); } } }; + + diff --git a/src/components/SearchBox.vue b/src/components/SearchBox.vue index 51fcf53dd..63aeb067c 100644 --- a/src/components/SearchBox.vue +++ b/src/components/SearchBox.vue @@ -42,13 +42,14 @@ export default { \ No newline at end of file + diff --git a/src/components/SearchFilter.vue b/src/components/SearchFilter.vue index c359eb8bc..9fa4a3eed 100644 --- a/src/components/SearchFilter.vue +++ b/src/components/SearchFilter.vue @@ -580,8 +580,6 @@ export default { }; - -