mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-08 14:35:52 +01:00
Improve issue pagination.
This commit is contained in:
50
src/main/scala/view/Pagination.scala
Normal file
50
src/main/scala/view/Pagination.scala
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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>◀</span></li>
|
|
||||||
} else {
|
|
||||||
<li><a href="@condition.toURL&page=@(page - 1)">◀</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>…</span></li>
|
|
||||||
<li><a href="#">7</a></li>
|
|
||||||
*@
|
|
||||||
@if(page == (count - 1) / service.IssuesService.IssueLimit + 1){
|
|
||||||
<li class="disabled"><span>▶</span></li>
|
|
||||||
} else {
|
|
||||||
<li><a href="@condition.toURL&page=@(page + 1)">▶</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>
|
||||||
}
|
}
|
||||||
|
|||||||
34
src/main/twirl/paginator.scala.html
Normal file
34
src/main/twirl/paginator.scala.html
Normal 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>◀</span></li>
|
||||||
|
} else {
|
||||||
|
<li><a href="@baseURL&page=@(page - 1)">◀</a></li>
|
||||||
|
}
|
||||||
|
@for(i <- 1 to p.max){
|
||||||
|
@if(i == p.max && p.omitRight){
|
||||||
|
<li><span>…</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>…</span></li>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@if(page == p.max){
|
||||||
|
<li class="disabled"><span>▶</span></li>
|
||||||
|
} else {
|
||||||
|
<li><a href="@baseURL&page=@(page + 1)">▶</a></li>
|
||||||
|
}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user