implemented pagination for address transactions
This commit is contained in:
parent
be2a458db7
commit
09924dc667
4 changed files with 100 additions and 2 deletions
|
@ -55,6 +55,7 @@ Router::scope('/', function (RouteBuilder $routes) {
|
||||||
|
|
||||||
$routes->connect('/api/v1/address/:addr/tag', ['controller' => 'Main', 'action' => 'apiaddrtag'], ['addr' => '[A-Za-z0-9,]+', 'pass' => ['addr']]);
|
$routes->connect('/api/v1/address/:addr/tag', ['controller' => 'Main', 'action' => 'apiaddrtag'], ['addr' => '[A-Za-z0-9,]+', 'pass' => ['addr']]);
|
||||||
$routes->connect('/api/v1/address/:addr/utxo', ['controller' => 'Main', 'action' => 'apiaddrutxo'], ['addr' => '[A-Za-z0-9,]+', 'pass' => ['addr']]);
|
$routes->connect('/api/v1/address/:addr/utxo', ['controller' => 'Main', 'action' => 'apiaddrutxo'], ['addr' => '[A-Za-z0-9,]+', 'pass' => ['addr']]);
|
||||||
|
$routes->connect('/api/v1/address/:addr/transactions', ['controller' => 'Main', 'action' => 'apiaddrtx'], ['addr' => '[A-Za-z0-9,]+', 'pass' => ['addr']]);
|
||||||
|
|
||||||
$routes->connect('/api/v1/realtime/blocks', ['controller' => 'Main', 'action' => 'apirealtimeblocks']);
|
$routes->connect('/api/v1/realtime/blocks', ['controller' => 'Main', 'action' => 'apirealtimeblocks']);
|
||||||
$routes->connect('/api/v1/realtime/tx', ['controller' => 'Main', 'action' => 'apirealtimetx']);
|
$routes->connect('/api/v1/realtime/tx', ['controller' => 'Main', 'action' => 'apirealtimetx']);
|
||||||
|
|
|
@ -406,6 +406,11 @@ class MainController extends AppController {
|
||||||
return $this->redirect('/');
|
return $this->redirect('/');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$offset = 0;
|
||||||
|
$pageLimit = 50;
|
||||||
|
$numTransactions = 0;
|
||||||
|
$page = intval($this->request->query('page'));
|
||||||
|
|
||||||
$canTag = false;
|
$canTag = false;
|
||||||
$totalRecvAmount = 0;
|
$totalRecvAmount = 0;
|
||||||
$totalSentAmount = 0;
|
$totalSentAmount = 0;
|
||||||
|
@ -420,6 +425,7 @@ class MainController extends AppController {
|
||||||
$tagRequestAmount = '25.' . rand(11111111, 99999999);
|
$tagRequestAmount = '25.' . rand(11111111, 99999999);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$address = $this->Addresses->find()->where(['Address' => $addr])->first();
|
$address = $this->Addresses->find()->where(['Address' => $addr])->first();
|
||||||
if (!$address) {
|
if (!$address) {
|
||||||
if (strlen($addr) === 34) {
|
if (strlen($addr) === 34) {
|
||||||
|
@ -434,16 +440,28 @@ class MainController extends AppController {
|
||||||
$canTag = true;
|
$canTag = true;
|
||||||
$addressId = $address->Id;
|
$addressId = $address->Id;
|
||||||
|
|
||||||
|
$stmt = $conn->execute('SELECT COUNT(TransactionId) AS Total FROM TransactionsAddresses WHERE AddressId = ?', [$addressId]);
|
||||||
|
$count = $stmt->fetch(\PDO::FETCH_OBJ);
|
||||||
|
$numTransactions = $count->Total;
|
||||||
|
$numPages = ceil($numTransactions / $pageLimit);
|
||||||
|
if ($page < 1) {
|
||||||
|
$page = 1;
|
||||||
|
}
|
||||||
|
if ($page > $numPages) {
|
||||||
|
$page = $numPages;
|
||||||
|
}
|
||||||
|
|
||||||
|
$offset = ($page - 1) * $pageLimit;
|
||||||
$stmt = $conn->execute('SELECT A.TotalReceived, A.TotalSent FROM Addresses A WHERE A.Id = ?', [$address->Id]);
|
$stmt = $conn->execute('SELECT A.TotalReceived, A.TotalSent FROM Addresses A WHERE A.Id = ?', [$address->Id]);
|
||||||
$totals = $stmt->fetch(\PDO::FETCH_OBJ);
|
$totals = $stmt->fetch(\PDO::FETCH_OBJ);
|
||||||
|
|
||||||
$stmt = $conn->execute('SELECT T.Id, T.Hash, T.InputCount, T.OutputCount, T.Value, ' .
|
$stmt = $conn->execute(sprintf('SELECT T.Id, T.Hash, T.InputCount, T.OutputCount, T.Value, ' .
|
||||||
'TA.DebitAmount, TA.CreditAmount, ' .
|
'TA.DebitAmount, TA.CreditAmount, ' .
|
||||||
'B.Height, B.Confirmations, IFNULL(T.TransactionTime, T.CreatedTime) AS TxTime ' .
|
'B.Height, B.Confirmations, IFNULL(T.TransactionTime, T.CreatedTime) AS TxTime ' .
|
||||||
'FROM Transactions T ' .
|
'FROM Transactions T ' .
|
||||||
'LEFT JOIN Blocks B ON T.BlockHash = B.Hash ' .
|
'LEFT JOIN Blocks B ON T.BlockHash = B.Hash ' .
|
||||||
'RIGHT JOIN (SELECT TransactionId, DebitAmount, CreditAmount FROM TransactionsAddresses ' .
|
'RIGHT JOIN (SELECT TransactionId, DebitAmount, CreditAmount FROM TransactionsAddresses ' .
|
||||||
' WHERE AddressId = ? ORDER BY TransactionTime DESC LIMIT 0, 20) TA ON TA.TransactionId = T.Id', [$addressId]);
|
' WHERE AddressId = ? ORDER BY TransactionTime DESC LIMIT %d, %d) TA ON TA.TransactionId = T.Id', $offset, $pageLimit), [$addressId]);
|
||||||
$recentTxs = $stmt->fetchAll(\PDO::FETCH_OBJ);
|
$recentTxs = $stmt->fetchAll(\PDO::FETCH_OBJ);
|
||||||
|
|
||||||
$totalRecvAmount = $totals->TotalReceived == 0 ? '0' : $totals->TotalReceived + 0;
|
$totalRecvAmount = $totals->TotalReceived == 0 ? '0' : $totals->TotalReceived + 0;
|
||||||
|
@ -451,6 +469,7 @@ class MainController extends AppController {
|
||||||
$balanceAmount = bcsub($totalRecvAmount, $totalSentAmount, 8) + 0;
|
$balanceAmount = bcsub($totalRecvAmount, $totalSentAmount, 8) + 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->set('offset', $offset);
|
||||||
$this->set('canTag', $canTag);
|
$this->set('canTag', $canTag);
|
||||||
$this->set('pending', $pending);
|
$this->set('pending', $pending);
|
||||||
$this->set('tagRequestAmount', $tagRequestAmount);
|
$this->set('tagRequestAmount', $tagRequestAmount);
|
||||||
|
@ -459,6 +478,9 @@ class MainController extends AppController {
|
||||||
$this->set('totalSent', $totalSentAmount);
|
$this->set('totalSent', $totalSentAmount);
|
||||||
$this->set('balanceAmount', $balanceAmount);
|
$this->set('balanceAmount', $balanceAmount);
|
||||||
$this->set('recentTxs', $recentTxs);
|
$this->set('recentTxs', $recentTxs);
|
||||||
|
$this->set('numTransactions', $numTransactions);
|
||||||
|
$this->set('numPages', $numPages);
|
||||||
|
$this->set('currentPage', $page);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function qr($data = null) {
|
public function qr($data = null) {
|
||||||
|
|
|
@ -148,6 +148,14 @@
|
||||||
|
|
||||||
<div class="recent-transactions">
|
<div class="recent-transactions">
|
||||||
<h3>Recent Transactions</h3>
|
<h3>Recent Transactions</h3>
|
||||||
|
<div class="results-meta">
|
||||||
|
<?php if ($numTransactions > 0):
|
||||||
|
$begin = ($currentPage - 1) * 50 + 1;
|
||||||
|
?>
|
||||||
|
Showing <?php echo number_format($begin, 0, '', ',') ?> - <?php echo number_format(min($numTransactions, $begin + 50), 0, '', ','); ?> of <?php echo number_format($numTransactions, 0, '', ','); ?> result<?php echo $numTransactions == 1 ? '' : 's' ?>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
<table class="table tx-table">
|
<table class="table tx-table">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -189,3 +197,62 @@
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<?php if ($numPages > 1): ?>
|
||||||
|
<div class="pagination">
|
||||||
|
<div class="prev">
|
||||||
|
|
||||||
|
<?php if ($currentPage > 1): ?>
|
||||||
|
<a href="?page=<?php echo $currentPage - 1 ?>">Previous</a>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
<div class="pages">
|
||||||
|
<?php if ($numTransactions > 0):
|
||||||
|
|
||||||
|
$start = $numPages > 1 ? 1 : 0;
|
||||||
|
$end = $numPages > 1 ? 10 : 0;
|
||||||
|
// use currentPage as the starting point
|
||||||
|
if ($numPages > 10) {
|
||||||
|
if ($currentPage > 5) {
|
||||||
|
$start = $currentPage < 10 ? 1 : $currentPage - 5;
|
||||||
|
$end = ($currentPage > ($numPages - 10) && $start > 5) ? $numPages : min($currentPage + 5, $numPages);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
<?php if ($start >= 5): ?>
|
||||||
|
<div class="page-number"><a href="?page=1">1</a></div>
|
||||||
|
<div class="page-number">...</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
if ($start > 0):
|
||||||
|
for ($i = $start; $i <= $end; $i++):
|
||||||
|
?>
|
||||||
|
<div class="page-number">
|
||||||
|
<?php if ($currentPage == $i): echo $i; else: ?>
|
||||||
|
<a href="?page=<?php echo $i ?>"><?php echo $i ?></a>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
endfor;
|
||||||
|
endif;
|
||||||
|
?>
|
||||||
|
<?php if ($end < $numPages - 1): ?>
|
||||||
|
<div class="page-number">...</div>
|
||||||
|
<div class="page-number">
|
||||||
|
<a href="?page=<?php echo $numPages ?>"><?php echo $numPages ?></a>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php
|
||||||
|
endif; ?>
|
||||||
|
</div>
|
||||||
|
<div class="next">
|
||||||
|
|
||||||
|
<?php if ($currentPage < $numPages): ?>
|
||||||
|
<a href="?page=<?php echo $currentPage + 1 ?>">Next</a>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
<div class="clear"></div>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
|
@ -247,12 +247,20 @@ footer .content .page-time { position: absolute; right: 12px; bottom: 0px; paddi
|
||||||
.address-summary .box .value { font-size: 180%; font-weight: 300; margin-top: 8px }
|
.address-summary .box .value { font-size: 180%; font-weight: 300; margin-top: 8px }
|
||||||
.address-summary .box.last { border-color: transparent }
|
.address-summary .box.last { border-color: transparent }
|
||||||
|
|
||||||
|
.recent-transactions { position: relative }
|
||||||
.recent-transactions h3 { font-weight: 300; margin: 0; margin-bottom: 12px }
|
.recent-transactions h3 { font-weight: 300; margin: 0; margin-bottom: 12px }
|
||||||
.recent-transactions { width: 1200px; margin: 48px auto 0 auto; box-shadow: 0 2px 6px rgba(0,0,0,.175); border: 1px solid rgba(0,0,0,.15); padding: 36px; cursor: default }
|
.recent-transactions { width: 1200px; margin: 48px auto 0 auto; box-shadow: 0 2px 6px rgba(0,0,0,.175); border: 1px solid rgba(0,0,0,.15); padding: 36px; cursor: default }
|
||||||
|
.recent-transactions .results-meta { position: absolute; right: 36px; top: 44px; font-size: 75%; color: #aaa }
|
||||||
|
|
||||||
.tx-table td { vertical-align: top; line-height: 24px }
|
.tx-table td { vertical-align: top; line-height: 24px }
|
||||||
.tx-table td.credit, .tx-table td div.credit { color: #00e676 }
|
.tx-table td.credit, .tx-table td div.credit { color: #00e676 }
|
||||||
.tx-table td.debit, .tx-table td div.debit { color: #ff0000 }
|
.tx-table td.debit, .tx-table td div.debit { color: #ff0000 }
|
||||||
.tx-table td div.debit { padding-top: 8px }
|
.tx-table td div.debit { padding-top: 8px }
|
||||||
|
|
||||||
|
.pagination { width: 1200px; margin: 36px auto 0 auto; cursor: default }
|
||||||
|
.pagination .prev { float: left; width: 20%; font-size: 75% }
|
||||||
|
.pagination .next { float: left; width: 20%; text-align: right; font-size: 75% }
|
||||||
|
.pagination .pages { float: left; width: 60%; text-align: center }
|
||||||
|
.pagination .pages .page-number { display: inline-block; width: 28px; height: 28px; line-height: 24px; text-align: center; font-size: 75% }
|
||||||
|
|
||||||
.clear { clear: both }
|
.clear { clear: both }
|
||||||
|
|
Loading…
Reference in a new issue