Skip to content

Commit

Permalink
Show search result count in badge
Browse files Browse the repository at this point in the history
  • Loading branch information
m-mohr committed Aug 17, 2023
1 parent 2dd68a0 commit a602de4
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
21 changes: 17 additions & 4 deletions src/components/Catalogs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
<section class="catalogs mb-4">
<header>
<h2 class="title mr-2">{{ title }}</h2>
<b-badge v-if="isComplete" pill variant="secondary" class="mr-4">
<template v-if="catalogs.length !== catalogView.length">{{ catalogView.length }}/{{ catalogs.length }}</template>
<template v-else>{{ catalogs.length }}</template>
</b-badge>
<b-badge v-if="catalogCount !== null" pill variant="secondary" class="mr-4">{{ catalogCount }}</b-badge>
<ViewButtons class="mr-2" v-model="view" />
<SortButtons v-if="isComplete && catalogs.length > 1" v-model="sort" />
</header>
Expand Down Expand Up @@ -67,6 +64,10 @@ export default {
pagination: {
type: Object,
default: () => ({})
},
count: {
type: Number,
default: null
}
},
data() {
Expand All @@ -78,6 +79,18 @@ export default {
computed: {
...mapState(['cardViewSort', 'uiLanguage']),
...mapGetters(['getStac']),
catalogCount() {
if (this.catalogs.length !== this.catalogView.length) {
return this.catalogView.length + '/' + this.catalogs.length;
}
else if (this.count !== null) {
return this.count;
}
else if (this.isComplete) {
return this.catalogs.length;
}
return null;
},
title() {
if (this.collectionsOnly) {
return this.$tc('stacCollection', this.catalogs.length );
Expand Down
15 changes: 14 additions & 1 deletion src/components/Items.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<section class="items mb-4">
<header>
<h2 class="title mr-2">{{ $tc('stacItem', items.length ) }}</h2>
<b-badge v-if="!api && items.length > 0" pill variant="secondary" class="mr-4">{{ items.length }}</b-badge>
<b-badge v-if="itemCount !== null" pill variant="secondary" class="mr-4">{{ itemCount }}</b-badge>
<SortButtons v-if="!api && items.length > 1" v-model="sort" />
</header>

Expand Down Expand Up @@ -92,6 +92,10 @@ export default {
chunkSize: {
type: Number,
default: 90
},
count: {
type: Number,
default: null
}
},
data() {
Expand All @@ -103,6 +107,15 @@ export default {
},
computed: {
...mapState(['cardViewSort', 'uiLanguage']),
itemCount() {
if (this.count !== null) {
return this.count;
}
else if (!this.api && this.items.length > 0) {
return this.items.length;
}
return null;
},
hasMore() {
return this.items.length > this.shownItems;
},
Expand Down
8 changes: 8 additions & 0 deletions src/views/Search.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<Catalogs
v-if="isCollectionSearch" :catalogs="results" collectionsOnly
:pagination="pagination" :loading="loading" @paginate="loadResults"
:count="totalCount"
>
<template #catalogFooter="slot">
<b-button-group v-if="canSearchItems || canFilterItems(slot.data)" vertical size="sm">
Expand All @@ -47,6 +48,7 @@
v-else
:stac="stac" :items="results" :api="true" :allowFilter="false"
:pagination="pagination" :loading="loading" @paginate="loadResults"
:count="totalCount"
/>
</template>
</b-col>
Expand Down Expand Up @@ -109,6 +111,12 @@ export default {
selectedCollectionCount() {
return Utils.size(this.selectedCollections);
},
totalCount() {
if (typeof this.data.numberMatched === 'number') {
return this.data.numberMatched;
}
return null;
},
stac() {
if (this.parent instanceof STAC) {
return this.parent;
Expand Down

0 comments on commit a602de4

Please sign in to comment.