From b001522c29571f9660bdf0080b3b1ac67f26ceee Mon Sep 17 00:00:00 2001 From: Viki Val Date: Wed, 24 Mar 2021 11:26:27 +0100 Subject: [PATCH 1/3] 201 same images are grouped --- .../src/components/rmrk/Gallery/Gallery.vue | 13 +++++---- .../components/rmrk/Gallery/GalleryRare.vue | 2 +- .../components/rmrk/Gallery/Search/query.ts | 28 ++++++++++++++++++- dashboard/src/main.ts | 9 ++++++ 4 files changed, 45 insertions(+), 7 deletions(-) diff --git a/dashboard/src/components/rmrk/Gallery/Gallery.vue b/dashboard/src/components/rmrk/Gallery/Gallery.vue index fa4014fc54..956faf72f1 100644 --- a/dashboard/src/components/rmrk/Gallery/Gallery.vue +++ b/dashboard/src/components/rmrk/Gallery/Gallery.vue @@ -29,7 +29,7 @@ @@ -47,9 +47,12 @@

- + {{ nft.name }} + + {{ nft.name }} 「{{ nft.count }}」 +

@@ -70,7 +73,7 @@ import { NFTWithMeta, NFT } from '../service/scheme'; import { defaultSortBy, sanitizeObjectArray } from '../utils'; import GalleryCardList from './GalleryCardList.vue' import Search from './Search/SearchBar.vue' -import { basicFilter } from './Search/query' +import { basicFilter, basicAggQuery } from './Search/query' type NFTType = NFTWithMeta; const components = { GalleryCardList, Search } @@ -102,10 +105,10 @@ export default class Gallery extends Vue { get results() { if (this.searchQuery) { - return basicFilter(this.searchQuery, this.nfts) + return basicAggQuery(basicFilter(this.searchQuery, this.nfts)) } - return this.nfts + return basicAggQuery(this.nfts) } } diff --git a/dashboard/src/components/rmrk/Gallery/GalleryRare.vue b/dashboard/src/components/rmrk/Gallery/GalleryRare.vue index 418622f209..6591469bd8 100644 --- a/dashboard/src/components/rmrk/Gallery/GalleryRare.vue +++ b/dashboard/src/components/rmrk/Gallery/GalleryRare.vue @@ -28,7 +28,7 @@ diff --git a/dashboard/src/components/rmrk/Gallery/Search/query.ts b/dashboard/src/components/rmrk/Gallery/Search/query.ts index 66f9fc5631..0b75858840 100644 --- a/dashboard/src/components/rmrk/Gallery/Search/query.ts +++ b/dashboard/src/components/rmrk/Gallery/Search/query.ts @@ -1,6 +1,8 @@ -import M, { Query } from 'mingo' +import M, { Query, Aggregator } from 'mingo' +import { Collection as Aggregation } from 'mingo/core' import { NFTWithMeta } from '../../service/scheme' + type QueryType = Record export const basicFilterQuery = (value: string): Query => { @@ -20,9 +22,33 @@ export const basicFilterQuery = (value: string): Query => { return new Query(criteria) } +export const basicAggregation = (): Aggregator => { + const agg: Aggregation = [ + { + $group: { + _id: "$image", + ids: { $push: "$id" }, + collection: { $first: "$collection" }, + name: { $first: "$name" }, + id: { $first: "$id" }, + image: { $first: "$image" }, + count: { $sum: 1 } + } + } + + ] + + return new Aggregator(agg) +} + export const basicFilter = (value: string, ntfs: NFTWithMeta[]): any[] => { const query = basicFilterQuery(value) return query.find(ntfs).all() } +export const basicAggQuery = (ntfs: NFTWithMeta[]) => { + const query = basicAggregation() + return query.run(ntfs) +} + diff --git a/dashboard/src/main.ts b/dashboard/src/main.ts index e717fbf5ce..b46ff87471 100644 --- a/dashboard/src/main.ts +++ b/dashboard/src/main.ts @@ -26,6 +26,15 @@ import i18n from './i18n' import mingo from 'mingo' import api from './fetch' +import { useOperators, OperatorType } from 'mingo/core' +import { $match, $group, $project } from 'mingo/operators/pipeline' +import { $sum, $first, $push } from 'mingo/operators/accumulator' + +// ensure the required operators are preloaded prior to using them. +type OperatorMap = Record ; +useOperators(OperatorType.PIPELINE, { $match, $group, $project } as OperatorMap) +useOperators(OperatorType.ACCUMULATOR, { $sum, $first, $push } as OperatorMap) + Vue.filter('shortAddress', shortAddress); (window as any).C = Connector; From 1a8d8231d551964fd4352f8bbf9975db754c7d27 Mon Sep 17 00:00:00 2001 From: Viki Val Date: Wed, 24 Mar 2021 11:28:09 +0100 Subject: [PATCH 2/3] 201 Lint --- .../src/components/rmrk/Gallery/Search/query.ts | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/dashboard/src/components/rmrk/Gallery/Search/query.ts b/dashboard/src/components/rmrk/Gallery/Search/query.ts index 0b75858840..86ba0d651f 100644 --- a/dashboard/src/components/rmrk/Gallery/Search/query.ts +++ b/dashboard/src/components/rmrk/Gallery/Search/query.ts @@ -26,19 +26,18 @@ export const basicAggregation = (): Aggregator => { const agg: Aggregation = [ { $group: { - _id: "$image", - ids: { $push: "$id" }, - collection: { $first: "$collection" }, - name: { $first: "$name" }, - id: { $first: "$id" }, - image: { $first: "$image" }, - count: { $sum: 1 } + _id: '$image', + ids: { $push: '$id' }, + collection: { $first: '$collection' }, + name: { $first: '$name' }, + id: { $first: '$id' }, + image: { $first: '$image' }, + count: { $sum: 1 } } } - ] - return new Aggregator(agg) + return new Aggregator(agg); } export const basicFilter = (value: string, ntfs: NFTWithMeta[]): any[] => { From e9b8471127117c09d81f2257b10ae2fc8e87fccc Mon Sep 17 00:00:00 2001 From: Viki Val Date: Wed, 24 Mar 2021 13:34:18 +0100 Subject: [PATCH 3/3] 201 updated description length for collection --- dashboard/src/components/rmrk/Create/CreateCollection.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dashboard/src/components/rmrk/Create/CreateCollection.vue b/dashboard/src/components/rmrk/Create/CreateCollection.vue index 9689922353..8c764069e5 100644 --- a/dashboard/src/components/rmrk/Create/CreateCollection.vue +++ b/dashboard/src/components/rmrk/Create/CreateCollection.vue @@ -39,7 +39,7 @@