diff --git a/routes/serve-routes.js b/routes/serve-routes.js index 30e0e913..6a862c71 100644 --- a/routes/serve-routes.js +++ b/routes/serve-routes.js @@ -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; } diff --git a/views/channel.handlebars b/views/channel.handlebars index 8d77935b..785e3e63 100644 --- a/views/channel.handlebars +++ b/views/channel.handlebars @@ -3,7 +3,7 @@
Total Pages: {{this.totalPages}}, Total Files: {{this.totalResults}}
+Page {{this.currentPage}} / {{this.totalPages}}, Total Files: {{this.totalResults}}