From b6a98d1ffa1969c3ff9705e785ffdccbe6878600 Mon Sep 17 00:00:00 2001 From: Mario Mejia Date: Mon, 23 Jul 2018 14:09:35 -0500 Subject: [PATCH] web-ui: improvements on block details view (#19) transactions for the block are now retrieved separately, the transactions table is paginated and shows more info and finally the view now is mobile friendly --- .../block-details.component.html | 510 +++++++++--------- .../block-details/block-details.component.ts | 35 +- web-ui/src/app/services/blocks.service.ts | 7 + 3 files changed, 309 insertions(+), 243 deletions(-) diff --git a/web-ui/src/app/components/block-details/block-details.component.html b/web-ui/src/app/components/block-details/block-details.component.html index b598835..388f84d 100644 --- a/web-ui/src/app/components/block-details/block-details.component.html +++ b/web-ui/src/app/components/block-details/block-details.component.html @@ -4,260 +4,288 @@
-

{{'label.block' | translate}} #{{blockDetails.block.height}}

-
+

{{'label.block' | translate}} #{{blockDetails.block.height}}

-
- - - - - - - +
+
+
{{'label.summary' | translate}}
+ + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
{{'label.summary' | translate}}
{{'label.blockType' | translate}}{{getBlockType(blockDetails)}}
{{'label.tposContract' | translate}}{{blockDetails.block.tposContract}}
{{'label.blockhash' | translate}}{{blockDetails.block.hash}}
{{'label.merkleRoot' | translate}}{{blockDetails.block.merkleRoot}}
{{'label.confirmations' | translate}}{{blockDetails.block.confirmations}}
{{'label.size' | translate}}{{blockDetails.block.size}} bytes
{{'label.version' | translate}}{{blockDetails.block.version}}
{{'label.nonce' | translate}}{{blockDetails.block.nonce}}
{{'label.bits' | translate}}{{blockDetails.block.bits}}
{{'label.chainwork' | translate}}{{blockDetails.block.chainwork}}
{{'label.difficulty' | translate}}{{blockDetails.block.difficulty}}
{{'label.blocktime' | translate}}{{blockDetails.block.time * 1000 | explorerDatetime}}
{{'label.medianTime' | translate}}{{blockDetails.block.medianTime * 1000 | explorerDatetime}}
- - {{'label.previous' | translate}} ({{blockDetails.block.height - 1}}) - - - - {{'label.next' | translate}} ({{blockDetails.block.height + 1}}) - -
-
+ + + + {{'label.blockType' | translate}} + {{getBlockType(blockDetails)}} + + + {{'label.tposContract' | translate}} + + {{blockDetails.block.tposContract}} + + + + {{'label.blockhash' | translate}} + {{blockDetails.block.hash}} + + + {{'label.merkleRoot' | translate}} + {{blockDetails.block.merkleRoot}} + + + {{'label.confirmations' | translate}} + {{blockDetails.block.confirmations}} + + + {{'label.size' | translate}} + {{blockDetails.block.size}} bytes + + + {{'label.version' | translate}} + {{blockDetails.block.version}} + + + {{'label.nonce' | translate}} + {{blockDetails.block.nonce}} + + + {{'label.bits' | translate}} + {{blockDetails.block.bits}} + + + {{'label.chainwork' | translate}} + {{blockDetails.block.chainwork}} + + + {{'label.difficulty' | translate}} + {{blockDetails.block.difficulty}} + + + {{'label.blocktime' | translate}} + {{blockDetails.block.time * 1000 | explorerDatetime}} + + + {{'label.medianTime' | translate}} + {{blockDetails.block.medianTime * 1000 | explorerDatetime}} + + + + + + + + + {{'label.previous' | translate}} ({{blockDetails.block.height - 1}}) + + + + + {{'label.next' | translate}} ({{blockDetails.block.height + 1}}) + + + + + +
+ - -
+ +
+
+ +
+ + + + + + + - -
-
{{'label.blockReward' | translate}}{{blockDetails.rewards.reward.value}} {{'label.coinName' | translate}}
- - - - - - + + + + + + +
{{'label.blockReward' | translate}}{{blockDetails.rewards.reward.value}} {{'label.coinName' | translate}}
{{'label.address' | translate}} + {{blockDetails.rewards.reward.address}} +
+
- - - {{'label.address' | translate}} - {{blockDetails.rewards.reward.address}} - - - -
+ +
+ + + + + + + - -
-
{{'label.rewards' | translate}}{{getPoSTotalReward(blockDetails)}} {{'label.coinName' | translate}}
- - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
{{'label.rewards' | translate}}{{getPoSTotalReward(blockDetails)}} {{'label.coinName' | translate}}
+ {{'label.coinstake' | translate}} +
{{'label.amount' | translate}}{{blockDetails.rewards.coinstake.value}} {{'label.coinName' | translate}}
{{'label.address' | translate}} + {{blockDetails.rewards.coinstake.address}} +
+ {{'label.masternode' | translate}} +
{{'label.amount' | translate}}{{blockDetails.rewards.masternode.value}} {{'label.coinName' | translate}}
{{'label.address' | translate}} + {{blockDetails.rewards.masternode.address}} +
+
- - - - - - - {{'label.coinstake' | translate}} - - - - {{'label.amount' | translate}} - {{blockDetails.rewards.coinstake.value}} {{'label.coinName' | translate}} - - - {{'label.address' | translate}} - - {{blockDetails.rewards.coinstake.address}} - - - - - - - - {{'label.masternode' | translate}} - - - - {{'label.amount' | translate}} - {{blockDetails.rewards.masternode.value}} {{'label.coinName' | translate}} - - - {{'label.address' | translate}} - - {{blockDetails.rewards.masternode.address}} - - - - -
+ +
+ + + + + + + - -
-
{{'label.rewards' | translate}}{{getTPoSTotalReward(blockDetails)}} {{'label.coinName' | translate}}
- - - - - - + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
{{'label.rewards' | translate}}{{getTPoSTotalReward(blockDetails)}} {{'label.coinName' | translate}}
+ {{'label.owner' | translate}} +
{{'label.amount' | translate}}{{blockDetails.rewards.owner.value}} {{'label.coinName' | translate}}
{{'label.address' | translate}} + {{blockDetails.rewards.owner.address}} +
- {{'label.owner' | translate}} -
{{'label.amount' | translate}}{{blockDetails.rewards.owner.value}} {{'label.coinName' | translate}}
{{'label.address' | translate}} - {{blockDetails.rewards.owner.address}} -
+ {{'label.merchant' | translate}} +
{{'label.amount' | translate}}{{blockDetails.rewards.merchant.value}} {{'label.coinName' | translate}}
{{'label.address' | translate}} + {{blockDetails.rewards.merchant.address}} +
- {{'label.merchant' | translate}} -
{{'label.amount' | translate}}{{blockDetails.rewards.merchant.value}} {{'label.coinName' | translate}}
{{'label.address' | translate}} - {{blockDetails.rewards.merchant.address}} -
- {{'label.masternode' | translate}} -
{{'label.amount' | translate}}{{blockDetails.rewards.masternode.value}} {{'label.coinName' | translate}}
{{'label.address' | translate}} - {{blockDetails.rewards.masternode.address}} -
+ + + + + + + {{'label.masternode' | translate}} + + + + + {{'label.amount' | translate}} + {{blockDetails.rewards.masternode.value}} {{'label.coinName' | translate}} + + + {{'label.address' | translate}} + + {{blockDetails.rewards.masternode.address}} + + + + +
+
- - -
- - - - - - + +
+
+
{{'label.transactions' | translate}}
+ + + + + + + + + - - - - - -
#{{'label.transaction' | translate}}{{'label.date' | translate}}{{'label.value' | translate}}{{'label.size' | translate}}
- {{item}} -
+ + + {{(currentPage - 1) * pageSize + index + 1}} + + {{item.id | slice:0:35}}... + + {{item.time * 1000 | explorerDatetime}} + {{item.sent}} {{'label.coinName' | translate}} + {{item.size}} bytes + + + +
+ +
+
+ + +
+
+ diff --git a/web-ui/src/app/components/block-details/block-details.component.ts b/web-ui/src/app/components/block-details/block-details.component.ts index ad79a56..ad08e15 100644 --- a/web-ui/src/app/components/block-details/block-details.component.ts +++ b/web-ui/src/app/components/block-details/block-details.component.ts @@ -1,9 +1,10 @@ import { Component, OnInit } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; -import { TranslateService } from '@ngx-translate/core'; +import { Observable } from 'rxjs/Observable'; import { BlockDetails } from '../../models/block'; +import { Transaction } from '../../models/transaction'; import { BlocksService } from '../../services/blocks.service'; import { ErrorService } from '../../services/error.service'; @@ -16,8 +17,15 @@ import { NavigatorService } from '../../services/navigator.service'; }) export class BlockDetailsComponent implements OnInit { + blockhash: string; blockDetails: BlockDetails; + // pagination + total = 0; + currentPage = 1; + pageSize = 10; + asyncItems: Observable; + constructor( private route: ActivatedRoute, private router: Router, @@ -30,17 +38,40 @@ export class BlockDetailsComponent implements OnInit { } private onBlockhash(blockhash: string) { - this.blockDetails = null; + this.clearCurrentValues(); + this.blockhash = blockhash; this.blocksService.get(blockhash).subscribe( response => this.onBlockRetrieved(response), response => this.onError(response) ); + this.getPage(this.currentPage); + } + + private clearCurrentValues() { + this.blockhash = null; + this.blockDetails = null; + this.total = 0; + this.currentPage = 1; + this.pageSize = 10; + this.asyncItems = null; } private onBlockRetrieved(response: BlockDetails) { this.blockDetails = response; } + getPage(page: number) { + const offset = (page - 1) * this.pageSize; + const limit = this.pageSize; + const order = 'time:desc'; + + this.asyncItems = this.blocksService + .getTransactions(this.blockhash, offset, limit, order) + .do(response => this.total = response.total) + .do(response => this.currentPage = 1 + (response.offset / this.pageSize)) + .map(response => response.data) + } + private onError(response: any) { this.errorService.renderServerErrors(null, response); } diff --git a/web-ui/src/app/services/blocks.service.ts b/web-ui/src/app/services/blocks.service.ts index 327227c..8ed21d3 100644 --- a/web-ui/src/app/services/blocks.service.ts +++ b/web-ui/src/app/services/blocks.service.ts @@ -5,6 +5,8 @@ import { Observable } from 'rxjs/Observable'; import { environment } from '../../environments/environment'; import { Block, BlockDetails } from '../models/block'; +import { PaginatedResult } from '../models/paginated-result'; +import { Transaction } from '../models/transaction'; const httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json' }) @@ -27,6 +29,11 @@ export class BlocksService { return this.http.get(url); } + getTransactions(hash: string, offset: number = 0, limit: number = 10, orderBy: string = ''): Observable> { + const url = `${this.baseUrl}/${hash}/transactions?offset=${offset}&limit=${limit}&orderBy=${orderBy}`; + return this.http.get>(url); + } + getLatest(): Observable { return this.http.get(this.baseUrl); }