Skip to content
This repository was archived by the owner on Dec 5, 2025. It is now read-only.

Commit 92b7dec

Browse files
authored
Merge pull request #222 from kodadot/201-group-by
201 same images are grouped
2 parents 3778151 + e9b8471 commit 92b7dec

File tree

5 files changed

+45
-8
lines changed

5 files changed

+45
-8
lines changed

dashboard/src/components/rmrk/Create/CreateCollection.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
<b-field :label="$i18n.t('Description')">
4040
<b-input
4141
v-model="meta.description"
42-
maxlength="200"
42+
maxlength="500"
4343
type="textarea"
4444
></b-input>
4545
</b-field>

dashboard/src/components/rmrk/Gallery/Gallery.vue

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<b-image
3030
v-if="!isLoading"
3131
:src="nft.image"
32-
:src-fallback="require('@/utils/placeholder.png')"
32+
:src-fallback="require('@/assets/kodadot_logo_v1_transparent_400px.png')"
3333
alt="Simple image"
3434
ratio="1by1"
3535
></b-image>
@@ -47,9 +47,12 @@
4747
<p
4848
v-if="!isLoading"
4949
class="title is-4 has-text-centered">
50-
<router-link :to="{ name: 'nftDetail', params: { id: nft.id }}">
50+
<router-link v-if="nft.count < 2" :to="{ name: 'nftDetail', params: { id: nft.id }}">
5151
{{ nft.name }}
5252
</router-link>
53+
<router-link v-else :to="{ name: 'collectionDetail', params: { id: nft.collection }}">
54+
{{ nft.name }} 「{{ nft.count }}」
55+
</router-link>
5356
</p>
5457
<b-skeleton
5558
:active="isLoading">
@@ -70,7 +73,7 @@ import { NFTWithMeta, NFT } from '../service/scheme';
7073
import { defaultSortBy, sanitizeObjectArray } from '../utils';
7174
import GalleryCardList from './GalleryCardList.vue'
7275
import Search from './Search/SearchBar.vue'
73-
import { basicFilter } from './Search/query'
76+
import { basicFilter, basicAggQuery } from './Search/query'
7477
7578
type NFTType = NFTWithMeta;
7679
const components = { GalleryCardList, Search }
@@ -102,10 +105,10 @@ export default class Gallery extends Vue {
102105
103106
get results() {
104107
if (this.searchQuery) {
105-
return basicFilter(this.searchQuery, this.nfts)
108+
return basicAggQuery(basicFilter(this.searchQuery, this.nfts))
106109
}
107110
108-
return this.nfts
111+
return basicAggQuery(this.nfts)
109112
}
110113
111114
}

dashboard/src/components/rmrk/Gallery/GalleryRare.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<b-image
2929
v-if="!isLoading"
3030
:src="nft.image"
31-
:src-fallback="require('@/utils/placeholder.png')"
31+
:src-fallback="require('@/assets/kodadot_logo_v1_transparent_400px.png')"
3232
alt="NFT multimedia craft"
3333
ratio="1by1"
3434
></b-image>

dashboard/src/components/rmrk/Gallery/Search/query.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import M, { Query } from 'mingo'
1+
import M, { Query, Aggregator } from 'mingo'
2+
import { Collection as Aggregation } from 'mingo/core'
23
import { NFTWithMeta } from '../../service/scheme'
34

5+
46
type QueryType = Record<string, unknown>
57

68
export const basicFilterQuery = (value: string): Query => {
@@ -20,9 +22,32 @@ export const basicFilterQuery = (value: string): Query => {
2022
return new Query(criteria)
2123
}
2224

25+
export const basicAggregation = (): Aggregator => {
26+
const agg: Aggregation = [
27+
{
28+
$group: {
29+
_id: '$image',
30+
ids: { $push: '$id' },
31+
collection: { $first: '$collection' },
32+
name: { $first: '$name' },
33+
id: { $first: '$id' },
34+
image: { $first: '$image' },
35+
count: { $sum: 1 }
36+
}
37+
}
38+
]
39+
40+
return new Aggregator(agg);
41+
}
42+
2343
export const basicFilter = (value: string, ntfs: NFTWithMeta[]): any[] => {
2444
const query = basicFilterQuery(value)
2545
return query.find(ntfs).all()
2646
}
2747

2848

49+
export const basicAggQuery = (ntfs: NFTWithMeta[]) => {
50+
const query = basicAggregation()
51+
return query.run(ntfs)
52+
}
53+

dashboard/src/main.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ import i18n from './i18n'
2626
import mingo from 'mingo'
2727
import api from './fetch'
2828

29+
import { useOperators, OperatorType } from 'mingo/core'
30+
import { $match, $group, $project } from 'mingo/operators/pipeline'
31+
import { $sum, $first, $push } from 'mingo/operators/accumulator'
32+
33+
// ensure the required operators are preloaded prior to using them.
34+
type OperatorMap = Record<string, any> ;
35+
useOperators(OperatorType.PIPELINE, { $match, $group, $project } as OperatorMap)
36+
useOperators(OperatorType.ACCUMULATOR, { $sum, $first, $push } as OperatorMap)
37+
2938
Vue.filter('shortAddress', shortAddress);
3039

3140
(window as any).C = Connector;

0 commit comments

Comments
 (0)