fixed zero base pagination
This commit is contained in:
parent
6b761c3e71
commit
76a38878ba
2 changed files with 22 additions and 13 deletions
|
@ -38,13 +38,13 @@ function getPage (query) {
|
||||||
if (query.p) {
|
if (query.p) {
|
||||||
return parseInt(query.p);
|
return parseInt(query.p);
|
||||||
}
|
}
|
||||||
return 0;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
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 ${pageNumber} is number?`, Number.isInteger(pageNumber));
|
logger.debug(`pageNumber ${pageNumber} is number?`, Number.isInteger(pageNumber));
|
||||||
const claimStartIndex = pageNumber * CLAIMS_PER_PAGE;
|
const claimStartIndex = (pageNumber - 1) * CLAIMS_PER_PAGE;
|
||||||
console.log('claim start index:', claimStartIndex);
|
console.log('claim start index:', claimStartIndex);
|
||||||
const claimEndIndex = claimStartIndex + 10;
|
const claimEndIndex = claimStartIndex + 10;
|
||||||
console.log('claim end index:', claimEndIndex);
|
console.log('claim end index:', claimEndIndex);
|
||||||
|
@ -55,29 +55,29 @@ function extractPageFromClaims (claims, pageNumber) {
|
||||||
|
|
||||||
function determineTotalPages (totalClaims) {
|
function determineTotalPages (totalClaims) {
|
||||||
if (totalClaims === 0) {
|
if (totalClaims === 0) {
|
||||||
return -1;
|
return 0;
|
||||||
}
|
}
|
||||||
if (totalClaims < CLAIMS_PER_PAGE) {
|
if (totalClaims < CLAIMS_PER_PAGE) {
|
||||||
return 0;
|
return 1;
|
||||||
}
|
}
|
||||||
const fullPages = Math.floor(totalClaims / CLAIMS_PER_PAGE);
|
const fullPages = Math.floor(totalClaims / CLAIMS_PER_PAGE);
|
||||||
const remainder = totalClaims % CLAIMS_PER_PAGE;
|
const remainder = totalClaims % CLAIMS_PER_PAGE;
|
||||||
if (remainder === 0) {
|
if (remainder === 0) {
|
||||||
return fullPages - 1;
|
|
||||||
}
|
|
||||||
return fullPages;
|
return fullPages;
|
||||||
}
|
}
|
||||||
|
return fullPages + 1;
|
||||||
|
}
|
||||||
|
|
||||||
function determinePreviousPage (currentPage) {
|
function determinePreviousPage (currentPage) {
|
||||||
if (currentPage === 0) {
|
if (currentPage === 1) {
|
||||||
return 0;
|
return null;
|
||||||
}
|
}
|
||||||
return currentPage - 1;
|
return currentPage - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
function determineNextPage (totalPages, currentPage) {
|
function determineNextPage (totalPages, currentPage) {
|
||||||
if (currentPage === totalPages) {
|
if (currentPage === totalPages) {
|
||||||
return currentPage;
|
return null;
|
||||||
}
|
}
|
||||||
return currentPage + 1;
|
return currentPage + 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
<h2>{{this.channelName}}<span class="h2--secondary">:{{this.longChannelId}}</span></h2>
|
<h2>{{this.channelName}}<span class="h2--secondary">:{{this.longChannelId}}</span></h2>
|
||||||
</div>
|
</div>
|
||||||
<div class="column column--10 align-content-center">
|
<div class="column column--10 align-content-center">
|
||||||
<p>Total Pages: {{this.totalPages}}, Total Files: {{this.totalResults}}</p>
|
<p>Page {{this.currentPage}} / {{this.totalPages}}, Total Files: {{this.totalResults}}</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
{{#each this.claims}}
|
{{#each this.claims}}
|
||||||
|
@ -12,10 +12,19 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="column column--3 align-content--left">
|
<div class="column column--3 align-content--left">
|
||||||
<a href="/{{this.channelName}}:{{this.longChannelId}}?p=0">First Page [0]</a>
|
<a href="/{{this.channelName}}:{{this.longChannelId}}?p=1">First Page [1]</a>
|
||||||
</div><div class="column column--4 align-content-center">
|
</div><div class="column column--4 align-content-center">
|
||||||
<a href="/{{this.channelName}}:{{this.longChannelId}}?p={{this.previousPage}}">Previous Page [{{this.previousPage}}]</a> |
|
{{#if this.previousPage}}
|
||||||
|
<a href="/{{this.channelName}}:{{this.longChannelId}}?p={{this.previousPage}}">Previous Page [{{this.previousPage}}]</a>
|
||||||
|
{{else}}
|
||||||
|
<a disabled>Previous Page</a>
|
||||||
|
{{/if}}
|
||||||
|
|
|
||||||
|
{{#if this.nextPage}}
|
||||||
<a href="/{{this.channelName}}:{{this.longChannelId}}?p={{this.nextPage}}">Next Page [{{this.nextPage}}]</a>
|
<a href="/{{this.channelName}}:{{this.longChannelId}}?p={{this.nextPage}}">Next Page [{{this.nextPage}}]</a>
|
||||||
|
{{else}}
|
||||||
|
<a disabled>Next Page</a>
|
||||||
|
{{/if}}
|
||||||
</div><div class="column column--3 align-content-right">
|
</div><div class="column column--3 align-content-right">
|
||||||
<a href="/{{this.channelName}}:{{this.longChannelId}}?p={{this.totalPages}}">Last Page [{{this.totalPages}}]</a>
|
<a href="/{{this.channelName}}:{{this.longChannelId}}?p={{this.totalPages}}">Last Page [{{this.totalPages}}]</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue