added channel pagination
This commit is contained in:
parent
219a045779
commit
6b761c3e71
3 changed files with 32 additions and 15 deletions
|
@ -270,7 +270,7 @@ db['getAllChannelClaims'] = (channelId) => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
logger.debug(`finding all claims in channel "${channelId}"`);
|
logger.debug(`finding all claims in channel "${channelId}"`);
|
||||||
db
|
db
|
||||||
.sequelize.query(`SELECT name, claimId, outpoint, height, address, contentType, title, description, license, thumbnail FROM Claim WHERE certificateId = '${channelId}' ORDeR BY height DESC;`, { type: db.sequelize.QueryTypes.SELECT })
|
.sequelize.query(`SELECT name, claimId, outpoint, height, address, contentType, title, description, license, thumbnail FROM Claim WHERE certificateId = '${channelId}' ORDER BY height DESC;`, { type: db.sequelize.QueryTypes.SELECT })
|
||||||
.then(result => {
|
.then(result => {
|
||||||
switch (result.length) {
|
switch (result.length) {
|
||||||
case 0:
|
case 0:
|
||||||
|
|
|
@ -43,8 +43,14 @@ function getPage (query) {
|
||||||
|
|
||||||
function extractPageFromClaims (claims, pageNumber) {
|
function extractPageFromClaims (claims, pageNumber) {
|
||||||
logger.debug('claims is array?', Array.isArray(claims));
|
logger.debug('claims is array?', Array.isArray(claims));
|
||||||
logger.debug('pageNumber is number?', Number.isInteger(pageNumber));
|
logger.debug(`pageNumber ${pageNumber} is number?`, Number.isInteger(pageNumber));
|
||||||
return claims.slice(pageNumber * 10, pageNumber + 10);
|
const claimStartIndex = pageNumber * CLAIMS_PER_PAGE;
|
||||||
|
console.log('claim start index:', claimStartIndex);
|
||||||
|
const claimEndIndex = claimStartIndex + 10;
|
||||||
|
console.log('claim end index:', claimEndIndex);
|
||||||
|
const pageOfClaims = claims.slice(claimStartIndex, claimEndIndex);
|
||||||
|
logger.debug('page of claims:', pageOfClaims);
|
||||||
|
return pageOfClaims;
|
||||||
}
|
}
|
||||||
|
|
||||||
function determineTotalPages (totalClaims) {
|
function determineTotalPages (totalClaims) {
|
||||||
|
@ -183,7 +189,7 @@ module.exports = (app) => {
|
||||||
previousPage : determinePreviousPage(paginationPage),
|
previousPage : determinePreviousPage(paginationPage),
|
||||||
currentPage : paginationPage,
|
currentPage : paginationPage,
|
||||||
nextPage : determineNextPage(totalPages, paginationPage),
|
nextPage : determineNextPage(totalPages, paginationPage),
|
||||||
totalPages,
|
totalPages : totalPages,
|
||||||
totalResults : result.claims.length,
|
totalResults : result.claims.length,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,24 @@
|
||||||
<div class="row row--full-height">
|
<div class="row row--full-height">
|
||||||
<h2>{{this.channelName}}<span class="h2--secondary">:{{this.longChannelId}}</span></h2>
|
<div class="column column--10 align-content-center">
|
||||||
<p>Page: {{this.currentPage}}/{{this.totalPages}}, Total Files: {{this.totalResults}}</p>
|
<h2>{{this.channelName}}<span class="h2--secondary">:{{this.longChannelId}}</span></h2>
|
||||||
<p>
|
</div>
|
||||||
<a href="/{{this.channelName}}:{{this.longChannelId}}?p=0">First Page</a> |
|
<div class="column column--10 align-content-center">
|
||||||
<a href="/{{this.channelName}}:{{this.longChannelId}}?p={{this.previousPage}}">Last Page</a> |
|
<p>Total Pages: {{this.totalPages}}, Total Files: {{this.totalResults}}</p>
|
||||||
<a href="/{{this.channelName}}:{{this.longChannelId}}?p={{this.nextPage}}">Next Page</a> |
|
</div>
|
||||||
<a href="/{{this.channelName}}:{{this.longChannelId}}?p={{this.totalPages}}">Last Page</a>
|
<div class="row">
|
||||||
</p>
|
{{#each this.claims}}
|
||||||
{{#each this.claims}}
|
{{> contentListItem}}
|
||||||
{{> contentListItem}}
|
{{/each}}
|
||||||
{{/each}}
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="column column--3 align-content--left">
|
||||||
|
<a href="/{{this.channelName}}:{{this.longChannelId}}?p=0">First Page [0]</a>
|
||||||
|
</div><div class="column column--4 align-content-center">
|
||||||
|
<a href="/{{this.channelName}}:{{this.longChannelId}}?p={{this.previousPage}}">Previous Page [{{this.previousPage}}]</a> |
|
||||||
|
<a href="/{{this.channelName}}:{{this.longChannelId}}?p={{this.nextPage}}">Next Page [{{this.nextPage}}]</a>
|
||||||
|
</div><div class="column column--3 align-content-right">
|
||||||
|
<a href="/{{this.channelName}}:{{this.longChannelId}}?p={{this.totalPages}}">Last Page [{{this.totalPages}}]</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Add table
Reference in a new issue