diff --git a/src/main/scala/view/Pagination.scala b/src/main/scala/view/Pagination.scala new file mode 100644 index 0000000..8f2b62d --- /dev/null +++ b/src/main/scala/view/Pagination.scala @@ -0,0 +1,50 @@ +package view + +/** + * Provides control information for pagination. + * This class is used by paginator.scala.html. + * + * @param page the current page number + * @param count the total record count + * @param limit the limit record count per one page + * @param width the width (number of cells) of the paginator + */ +case class Pagination(page: Int, count: Int, limit: Int, width: Int){ + + /** + * max page number + */ + val max = (count - 1) / limit + 1 + + /** + * whether to omit the left side + */ + val omitLeft = width / 2 < page + + /** + * whether to omit the right side + */ + val omitRight = max - width / 2 > page + + /** + * Returns true if given page number is visible. + */ + def visibleFor(i: Int): Boolean = { + if(i == 1 || i == max){ + true + } else { + val leftRange = page - width / 2 + (if(omitLeft) 2 else 0) + val rightRange = page + width / 2 - (if(omitRight) 2 else 0) + + val fixedRange = if(leftRange < 1){ + (1, rightRange + (leftRange * -1) + 1) + } else if(rightRange > max){ + (leftRange - (rightRange - max), max) + } else { + (leftRange, rightRange) + } + + (i >= fixedRange._1 && i <= fixedRange._2) + } + } +} diff --git a/src/main/twirl/issues/issues.scala.html b/src/main/twirl/issues/issues.scala.html index 3797fa1..95afbfc 100644 --- a/src/main/twirl/issues/issues.scala.html +++ b/src/main/twirl/issues/issues.scala.html @@ -80,38 +80,9 @@ Clear milestone and label filters } - @defining(if(condition.state == "open") openCount else closedCount){ count => - @if(count > service.IssuesService.IssueLimit){ - - } - } +
+ @html.paginator(page, (if(condition.state == "open") openCount else closedCount), service.IssuesService.IssueLimit, 7, condition.toURL) +
@openCount Open @closedCount Closed @@ -163,6 +134,9 @@ } +
+ @html.paginator(page, (if(condition.state == "open") openCount else closedCount), service.IssuesService.IssueLimit, 10, condition.toURL) +
} diff --git a/src/main/twirl/paginator.scala.html b/src/main/twirl/paginator.scala.html new file mode 100644 index 0000000..4a37d81 --- /dev/null +++ b/src/main/twirl/paginator.scala.html @@ -0,0 +1,34 @@ +@(page: Int, count: Int, limit: Int, width: Int, baseURL: String) +@defining(view.Pagination(page, count, service.IssuesService.IssueLimit, width)){ p => + @if(p.count > p.limit){ + + } +}