Improve issue pagination.

This commit is contained in:
takezoe
2013-06-26 19:54:39 +09:00
parent 808478ac43
commit a48206278b
3 changed files with 90 additions and 32 deletions

View File

@@ -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)
}
}
}

View File

@@ -80,38 +80,9 @@
<i class="icon-remove-circle"></i> Clear milestone and label filters <i class="icon-remove-circle"></i> Clear milestone and label filters
</a> </a>
} }
@defining(if(condition.state == "open") openCount else closedCount){ count => <div class="pull-right">
@if(count > service.IssuesService.IssueLimit){ @html.paginator(page, (if(condition.state == "open") openCount else closedCount), service.IssuesService.IssueLimit, 7, condition.toURL)
<div class="pagination pull-right">
<ul>
@if(page == 1){
<li class="disabled"><span>&#9664;</span></li>
} else {
<li><a href="@condition.toURL&page=@(page - 1)">&#9664;</a></li>
}
@for(i <- 1 to (count - 1) / service.IssuesService.IssueLimit + 1){
@if(i == page){
<li class="active"><span>@i</span></li>
} else {
<li><a href="@condition.toURL&page=@i">@i</a></li>
}
}
@*
<li class="active"><span>1</span></li>
<li><a href="#">2</a></li>
<li><a href="#">3</a></li>
<li><span>&hellip;</span></li>
<li><a href="#">7</a></li>
*@
@if(page == (count - 1) / service.IssuesService.IssueLimit + 1){
<li class="disabled"><span>&#9654;</span></li>
} else {
<li><a href="@condition.toURL&page=@(page + 1)">&#9654;</a></li>
}
</ul>
</div> </div>
}
}
<div class="btn-group"> <div class="btn-group">
<a class="btn@if(condition.state == "open"){ active}" href="@condition.copy(state = "open").toURL">@openCount Open</a> <a class="btn@if(condition.state == "open"){ active}" href="@condition.copy(state = "open").toURL">@openCount Open</a>
<a class="btn@if(condition.state == "closed"){ active}" href="@condition.copy(state = "closed").toURL">@closedCount Closed</a> <a class="btn@if(condition.state == "closed"){ active}" href="@condition.copy(state = "closed").toURL">@closedCount Closed</a>
@@ -163,6 +134,9 @@
</tr> </tr>
} }
</table> </table>
<div class="pull-right">
@html.paginator(page, (if(condition.state == "open") openCount else closedCount), service.IssuesService.IssueLimit, 10, condition.toURL)
</div>
</div> </div>
</div> </div>
} }

View File

@@ -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){
<div class="pagination">
<ul>
@if(page == 1){
<li class="disabled"><span>&#9664;</span></li>
} else {
<li><a href="@baseURL&page=@(page - 1)">&#9664;</a></li>
}
@for(i <- 1 to p.max){
@if(i == p.max && p.omitRight){
<li><span>&hellip;</span></li>
}
@if(i == page){
<li class="active"><span>@i</span></li>
} else {
@if(p.visibleFor(i)){
<li><a href="@baseURL&page=@i">@i</a></li>
}
}
@if(i == 1 && p.omitLeft){
<li><span>&hellip;</span></li>
}
}
@if(page == p.max){
<li class="disabled"><span>&#9654;</span></li>
} else {
<li><a href="@baseURL&page=@(page + 1)">&#9654;</a></li>
}
</ul>
</div>
}
}