From 22393964b462d13abeeaccdc5ffd690443b9b9af Mon Sep 17 00:00:00 2001 From: Alexis Hernandez Date: Thu, 12 Apr 2018 22:48:04 -0500 Subject: [PATCH] web-ui: Add pagination to the richest addresses view --- .../richest-addresses.component.html | 54 +++++++++---------- .../richest-addresses.component.ts | 37 ++++++------- 2 files changed, 45 insertions(+), 46 deletions(-) diff --git a/web-ui/src/app/components/richest-addresses/richest-addresses.component.html b/web-ui/src/app/components/richest-addresses/richest-addresses.component.html index 54df896..fb76ae6 100644 --- a/web-ui/src/app/components/richest-addresses/richest-addresses.component.html +++ b/web-ui/src/app/components/richest-addresses/richest-addresses.component.html @@ -1,36 +1,34 @@
-
- {{'message.loadingRichestAddresses' | translate}} +
+

{{'label.richestAddresses' | translate}}

-
-
-

{{'label.richestAddresses' | translate}}

-
+
+
+ + + + + + + + + -
-
-
{{'label.address' | translate}}{{'label.available' | translate}}{{'label.received' | translate}}{{'label.spent' | translate}}
- - - - - - - - + + + + + + + + +
{{'label.address' | translate}}{{'label.available' | translate}}{{'label.received' | translate}}{{'label.spent' | translate}}
+ {{item.address}} + {{item.available}} {{'label.coinName' | translate}}{{item.received}} {{'label.coinName' | translate}}{{item.spent}} {{'label.coinName' | translate}}
- - - - {{item.address}} - - {{item.available}} {{'label.coinName' | translate}} - {{item.received}} {{'label.coinName' | translate}} - {{item.spent}} {{'label.coinName' | translate}} - - - +
+
diff --git a/web-ui/src/app/components/richest-addresses/richest-addresses.component.ts b/web-ui/src/app/components/richest-addresses/richest-addresses.component.ts index 6003055..73bc086 100644 --- a/web-ui/src/app/components/richest-addresses/richest-addresses.component.ts +++ b/web-ui/src/app/components/richest-addresses/richest-addresses.component.ts @@ -1,10 +1,14 @@ import { Component, OnInit, OnDestroy } from '@angular/core'; +import { Observable } from 'rxjs/Observable'; + +import 'rxjs/add/operator/do'; +import 'rxjs/add/operator/map'; + import { Balance } from '../../models/balance'; import { BalancesService } from '../../services/balances.service'; import { ErrorService } from '../../services/error.service'; -import { PaginatedResult } from '../../models/paginated-result'; @Component({ selector: 'app-richest-addresses', @@ -13,31 +17,28 @@ import { PaginatedResult } from '../../models/paginated-result'; }) export class RichestAddressesComponent implements OnInit { - balances: Balance[]; + // pagination + total = 0; + currentPage = 1; + pageSize = 10; + asyncItems: Observable; constructor( private balancesService: BalancesService, private errorService: ErrorService) { } ngOnInit() { - this.balances = []; - this.updateBalances(); + this.getPage(this.currentPage); } - private updateBalances() { - this.balancesService - .getRichest() - .subscribe( - response => this.onBalancesRetrieved(response), - response => this.onError(response) - ); - } - - private onBalancesRetrieved(response: PaginatedResult) { - this.balances = response.data; - } + getPage(page: number) { + const offset = (page - 1) * this.pageSize; + const limit = this.pageSize; - private onError(response: any) { - this.errorService.renderServerErrors(null, response); + this.asyncItems = this.balancesService + .getRichest(offset, limit) + .do(response => this.total = response.total) + .do(response => this.currentPage = 1 + (response.offset / this.pageSize)) + .map(response => response.data); } }