fixed zero base pagination

This commit is contained in:
bill bittner 2017-10-12 19:08:04 -07:00
parent 6b761c3e71
commit 76a38878ba
2 changed files with 22 additions and 13 deletions

View file

@ -38,13 +38,13 @@ function getPage (query) {
if (query.p) {
return parseInt(query.p);
}
return 0;
return 1;
}
function extractPageFromClaims (claims, pageNumber) {
logger.debug('claims is array?', Array.isArray(claims));
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);
const claimEndIndex = claimStartIndex + 10;
console.log('claim end index:', claimEndIndex);
@ -55,29 +55,29 @@ function extractPageFromClaims (claims, pageNumber) {
function determineTotalPages (totalClaims) {
if (totalClaims === 0) {
return -1;
return 0;
}
if (totalClaims < CLAIMS_PER_PAGE) {
return 0;
return 1;
}
const fullPages = Math.floor(totalClaims / CLAIMS_PER_PAGE);
const remainder = totalClaims % CLAIMS_PER_PAGE;
if (remainder === 0) {
return fullPages - 1;
return fullPages;
}
return fullPages;
return fullPages + 1;
}
function determinePreviousPage (currentPage) {
if (currentPage === 0) {
return 0;
if (currentPage === 1) {
return null;
}
return currentPage - 1;
}
function determineNextPage (totalPages, currentPage) {
if (currentPage === totalPages) {
return currentPage;
return null;
}
return currentPage + 1;
}

View file

@ -3,7 +3,7 @@
<h2>{{this.channelName}}<span class="h2--secondary">:{{this.longChannelId}}</span></h2>
</div>
<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 class="row">
{{#each this.claims}}
@ -12,10 +12,19 @@
</div>
<div class="row">
<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">
<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>
{{#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>
{{else}}
<a disabled>Next Page</a>
{{/if}}
</div><div class="column column--3 align-content-right">
<a href="/{{this.channelName}}:{{this.longChannelId}}?p={{this.totalPages}}">Last Page [{{this.totalPages}}]</a>
</div>