mirror of
https://github.com/GOSTSec/gostexplr
synced 2025-01-30 08:24:23 +00:00
Pagination for address page
This commit is contained in:
parent
a2c640b9f7
commit
da522ea7a3
@ -79,3 +79,8 @@ form.search input[type="text"] {
|
||||
.capitalize {
|
||||
text-transform: capitalize;
|
||||
}
|
||||
|
||||
div.pagination {
|
||||
overflow: hidden;
|
||||
margin-top: .5em;
|
||||
}
|
||||
|
@ -3,31 +3,40 @@ var express = require('express');
|
||||
var router = express.Router();
|
||||
|
||||
/* GET home page. */
|
||||
router.get('/:address', async function(req, res, next) {
|
||||
router.get('/:address/:offset*?', async function(req, res, next) {
|
||||
|
||||
const addrss = encodeURI(req.params.address);
|
||||
const limit = 30;
|
||||
const paramPage = parseInt(req.params.offset);
|
||||
const page = isNaN(paramPage) || paramPage < 1 ? 1 : paramPage;
|
||||
const offset = 30 * (page - 1);
|
||||
const txes = await models.sequelize.query(`
|
||||
SELECT txid
|
||||
FROM Transactions as t
|
||||
LEFT JOIN Vouts as v
|
||||
ON v.TransactionId=t.id
|
||||
LEFT JOIN AddressVouts as av
|
||||
ON v.id=av.VoutId
|
||||
LEFT JOIN Addresses as a
|
||||
ON a.id=av.AddressId
|
||||
WHERE a.address='${addrss}'
|
||||
LIMIT 30
|
||||
OFFSET ${offset};
|
||||
`);
|
||||
|
||||
const address = await models.Address.findOne({
|
||||
where: {
|
||||
address: addrss,
|
||||
},
|
||||
include: {
|
||||
model: models.Vout,
|
||||
include: {
|
||||
model: models.Transaction,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (address === null) {
|
||||
if (txes === null) {
|
||||
res.status(404).render('404');
|
||||
return;
|
||||
}
|
||||
const txes = [];
|
||||
address.Vouts.forEach((vout) => txes.push(vout.Transaction.txid));
|
||||
|
||||
const nextpage = txes[0].length === 30 ? page + 1 : null;
|
||||
const prevpage = page > 1 ? page - 1 : null;
|
||||
|
||||
res.render('address', {
|
||||
address: address.address,
|
||||
txes,
|
||||
address: addrss,
|
||||
txes: txes[0],
|
||||
nextpage,
|
||||
prevpage,
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -7,5 +7,9 @@ block content
|
||||
h3 Transactions
|
||||
each val in txes
|
||||
div
|
||||
a(href='/transaction/#{val}/') #{val}
|
||||
|
||||
a(href='/transaction/#{val.txid}/') #{val.txid}
|
||||
div.pagination
|
||||
if prevpage
|
||||
a(href='/address/#{address}/#{prevpage}/', style='float:left') Back
|
||||
if nextpage
|
||||
a(href='/address/#{address}/#{nextpage}/', style='float:right') Next
|
||||
|
Loading…
x
Reference in New Issue
Block a user