Commit 44b2ab40 authored by Ubbo Veentjer's avatar Ubbo Veentjer
Browse files

caclulate result end. fixes #37

parent 8d0f8094
Pipeline #135130 passed with stages
in 9 minutes and 12 seconds
......@@ -3,20 +3,25 @@ package info.textgrid.rep.shared;
public class Pager {
private int hits, limit, start, currentPage, totalPages;
private int hits, limit, start, end, currentPage, totalPages;
private int pageRange = 8; // Default page range (max amount of page links to be displayed at once).
private Integer[] pages;
public void calculatePages() {
// Set currentPage, totalPages and pages.
currentPage = (hits / limit) - ((hits - start) / limit) + 1;
totalPages = (hits / limit) + ((hits % limit != 0) ? 1 : 0);
int pagesLength = Math.min(pageRange, totalPages);
pages = new Integer[pagesLength];
if(start + limit <= hits) {
end = start + limit;
} else {
end = hits;
}
// firstPage must be greater than 0 and lesser than totalPages-pageLength.
int firstPage = Math.min(Math.max(0, currentPage - (pageRange / 2)), totalPages - pagesLength);
......@@ -59,4 +64,8 @@ public class Pager {
return totalPages;
}
public int getEnd() {
return end;
}
}
......@@ -3,7 +3,7 @@
<header class="tgrep header">
<div class="tgrep header_info">
${i18n['displaying-results']} <span class="tgrep header_count -current">${pager.start + 1}&#8211;${pager.start + pager.limit}</span> ${i18n['of']}
${i18n['displaying-results']} <span class="tgrep header_count -current">${pager.start + 1}&#8211;${pager.end}</span> ${i18n['of']}
<span class="tgrep header_count -total">${pager.hits}</span>
<div class="tg dropdown" role="group">
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment