From 213ca945ac90c4dc6ea1b4560dd7f756719c7ffe Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Fri, 23 Sep 2016 14:33:46 +0200 Subject: [PATCH] Step 13.20: Add reactive search by location --- client/imports/app/parties/parties-list.component.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/client/imports/app/parties/parties-list.component.ts b/client/imports/app/parties/parties-list.component.ts index 1a3201cbc..f94da32df 100644 --- a/client/imports/app/parties/parties-list.component.ts +++ b/client/imports/app/parties/parties-list.component.ts @@ -35,6 +35,7 @@ export class PartiesListComponent implements OnInit, OnDestroy { optionsSub: Subscription; partiesSize: number = 0; autorunSub: Subscription; + location: Subject = new Subject(); constructor( private paginationService: PaginationService @@ -44,8 +45,9 @@ export class PartiesListComponent implements OnInit, OnDestroy { this.optionsSub = Observable.combineLatest( this.pageSize, this.curPage, - this.nameOrder - ).subscribe(([pageSize, curPage, nameOrder]) => { + this.nameOrder, + this.location + ).subscribe(([pageSize, curPage, nameOrder, location]) => { const options: Options = { limit: pageSize as number, skip: ((curPage as number) - 1) * (pageSize as number), @@ -58,7 +60,7 @@ export class PartiesListComponent implements OnInit, OnDestroy { this.partiesSub.unsubscribe(); } - this.partiesSub = MeteorObservable.subscribe('parties', options).subscribe(() => { + this.partiesSub = MeteorObservable.subscribe('parties', options, location).subscribe(() => { this.parties = Parties.find({}, { sort: { name: nameOrder @@ -77,6 +79,7 @@ export class PartiesListComponent implements OnInit, OnDestroy { this.pageSize.next(10); this.curPage.next(1); this.nameOrder.next(1); + this.location.next(''); this.autorunSub = MeteorObservable.autorun().subscribe(() => { this.partiesSize = Counts.get('numberOfParties'); @@ -89,7 +92,8 @@ export class PartiesListComponent implements OnInit, OnDestroy { } search(value: string): void { - this.parties = Parties.find(value ? { location: value } : {}).zone(); + this.curPage.next(1); + this.location.next(value); } onPageChanged(page: number): void {