Browse Source

web-ui: Add pagination to the richest addresses view

scalafmt-draft
Alexis Hernandez 7 years ago
parent
commit
22393964b4
  1. 54
      web-ui/src/app/components/richest-addresses/richest-addresses.component.html
  2. 37
      web-ui/src/app/components/richest-addresses/richest-addresses.component.ts

54
web-ui/src/app/components/richest-addresses/richest-addresses.component.html

@ -1,36 +1,34 @@
<div> <div>
<div [hidden]="balances != null"> <div class="row">
<alert>{{'message.loadingRichestAddresses' | translate}}</alert> <h2 class="col-xs-12 col-sm-12 col-md-offset-1 col-md-10 col-lg-offset-1 col-lg-1'">{{'label.richestAddresses' | translate}}</h2>
</div> </div>
<div *ngIf="balances != null"> <div class="row">
<div class="row"> <div class="col-xs-12 col-sm-12 col-md-offset-1 col-md-10 col-lg-offset-1 col-lg-10">
<h2 class="col-xs-12 col-sm-12 col-md-offset-1 col-md-10 col-lg-offset-1 col-lg-1'">{{'label.richestAddresses' | translate}}</h2> <table class="table table-condensed table-bordered table-striped table-hover">
</div> <thead>
<tr>
<th class="col-xs-2 col-sm-2 col-md-1 col-lg-1">{{'label.address' | translate}}</th>
<th class="col-xs-2 col-sm-2 col-md-1 col-lg-1">{{'label.available' | translate}}</th>
<th class="col-xs-2 col-sm-2 col-md-1 col-lg-1">{{'label.received' | translate}}</th>
<th class="col-xs-2 col-sm-2 col-md-1 col-lg-1">{{'label.spent' | translate}}</th>
</tr>
</thead>
<div class="row"> <tbody>
<div class="col-xs-12 col-sm-12 col-md-offset-1 col-md-10 col-lg-offset-1 col-lg-10"> <tr *ngFor="let item of asyncItems | async | paginate: { id: 'richestAddresses', itemsPerPage: pageSize, currentPage: currentPage, totalItems: total }">
<table class="table table-condensed table-bordered table-striped table-hover"> <td>
<thead> <a routerLink="/addresses/{{item.address}}">{{item.address}}</a>
<tr> </td>
<th class="col-xs-2 col-sm-2 col-md-1 col-lg-1">{{'label.address' | translate}}</th> <td>{{item.available}} {{'label.coinName' | translate}}</td>
<th class="col-xs-2 col-sm-2 col-md-1 col-lg-1">{{'label.available' | translate}}</th> <td>{{item.received}} {{'label.coinName' | translate}}</td>
<th class="col-xs-2 col-sm-2 col-md-1 col-lg-1">{{'label.received' | translate}}</th> <td>{{item.spent}} {{'label.coinName' | translate}}</td>
<th class="col-xs-2 col-sm-2 col-md-1 col-lg-1">{{'label.spent' | translate}}</th> </tr>
</tr> </tbody>
</thead> </table>
<tbody> <div class="has-text-centered">
<tr *ngFor="let item of balances"> <pagination-controls (pageChange)="getPage($event)" id="richestAddresses"></pagination-controls>
<td>
<a routerLink="/addresses/{{item.address}}">{{item.address}}</a>
</td>
<td>{{item.available}} {{'label.coinName' | translate}}</td>
<td>{{item.received}} {{'label.coinName' | translate}}</td>
<td>{{item.spent}} {{'label.coinName' | translate}}</td>
</tr>
</tbody>
</table>
</div> </div>
</div> </div>
</div> </div>

37
web-ui/src/app/components/richest-addresses/richest-addresses.component.ts

@ -1,10 +1,14 @@
import { Component, OnInit, OnDestroy } from '@angular/core'; 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 { Balance } from '../../models/balance';
import { BalancesService } from '../../services/balances.service'; import { BalancesService } from '../../services/balances.service';
import { ErrorService } from '../../services/error.service'; import { ErrorService } from '../../services/error.service';
import { PaginatedResult } from '../../models/paginated-result';
@Component({ @Component({
selector: 'app-richest-addresses', selector: 'app-richest-addresses',
@ -13,31 +17,28 @@ import { PaginatedResult } from '../../models/paginated-result';
}) })
export class RichestAddressesComponent implements OnInit { export class RichestAddressesComponent implements OnInit {
balances: Balance[]; // pagination
total = 0;
currentPage = 1;
pageSize = 10;
asyncItems: Observable<Balance[]>;
constructor( constructor(
private balancesService: BalancesService, private balancesService: BalancesService,
private errorService: ErrorService) { } private errorService: ErrorService) { }
ngOnInit() { ngOnInit() {
this.balances = []; this.getPage(this.currentPage);
this.updateBalances();
} }
private updateBalances() { getPage(page: number) {
this.balancesService const offset = (page - 1) * this.pageSize;
.getRichest() const limit = this.pageSize;
.subscribe(
response => this.onBalancesRetrieved(response),
response => this.onError(response)
);
}
private onBalancesRetrieved(response: PaginatedResult<Balance>) {
this.balances = response.data;
}
private onError(response: any) { this.asyncItems = this.balancesService
this.errorService.renderServerErrors(null, response); .getRichest(offset, limit)
.do(response => this.total = response.total)
.do(response => this.currentPage = 1 + (response.offset / this.pageSize))
.map(response => response.data);
} }
} }

Loading…
Cancel
Save