Skip to content

Commit ec7922e

Browse files
committed
Simplified code
1 parent 755a004 commit ec7922e

File tree

1 file changed

+34
-18
lines changed

1 file changed

+34
-18
lines changed

core/src/main/scala/org/apache/spark/deploy/history/HistoryPage.scala

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import org.apache.spark.ui.{WebUIPage, UIUtils}
2626
private[spark] class HistoryPage(parent: HistoryServer) extends WebUIPage("") {
2727

2828
private val pageSize = 20
29-
private val maxNumIndices = 4
29+
private val maxNumIndices = 2
3030

3131
def render(request: HttpServletRequest): Seq[Node] = {
3232
val requestedPage = Option(request.getParameter("page")).getOrElse("1").toInt
@@ -52,23 +52,7 @@ private[spark] class HistoryPage(parent: HistoryServer) extends WebUIPage("") {
5252
if (allApps.size > 0) {
5353
<h4>
5454
Showing {actualFirst + 1}-{last + 1} of {allApps.size}
55-
<span style="float: right">
56-
{if (actualPage > 1) <a href={"/?page=" + (actualPage - 1)}>&lt; </a>}
57-
{if (actualPage > 1) <a href={"/?page=1"}>1</a>}
58-
{if (actualPage - maxNumIndices > 2) " ... " }
59-
{(1 to maxNumIndices).reverse.filter(actualPage - _ > 1).map {offset =>
60-
val nextPage = actualPage - offset
61-
<a href={"/?page=" + (nextPage)}> {nextPage} </a>
62-
}}
63-
{actualPage}
64-
{(1 to maxNumIndices).filter(actualPage + _ < pageCount).map{offset =>
65-
val nextPage = actualPage + offset
66-
<a href={"/?page=" + nextPage}> {nextPage} </a>
67-
}}
68-
{if (actualPage + maxNumIndices < pageCount - 1) " ... " }
69-
{if (actualPage < pageCount) <a href={"/?page=" + pageCount}>{pageCount}</a>}
70-
{if (actualPage < pageCount) <a href={"/?page=" + (actualPage + 1)}> &gt;</a>}
71-
</span>
55+
{pageIndices(pageCount, actualPage)}
7256
</h4> ++
7357
appTable
7458
} else {
@@ -89,6 +73,38 @@ private[spark] class HistoryPage(parent: HistoryServer) extends WebUIPage("") {
8973
"Spark User",
9074
"Last Updated")
9175

76+
private def pageIndices(pageCount: Int, actualPage: Int): Seq[Node] = {
77+
78+
def rangeIndices(range: Seq[Int], condition: Int => Boolean): Seq[Node] = {
79+
range.filter(condition).map(nextPage => <a href={"/?page=" + nextPage}> {nextPage} </a>)
80+
}
81+
82+
val littlerSideIndices =
83+
rangeIndices(actualPage-maxNumIndices until actualPage, 1 < _)
84+
val greaterSideIndices =
85+
rangeIndices(actualPage+1 to actualPage+maxNumIndices, _ < pageCount)
86+
87+
<span style="float: right">
88+
{
89+
if (actualPage > 1) {
90+
<a href={"/?page=" + (actualPage - 1)}>&lt; </a>
91+
<a href={"/?page=1"}>1</a>
92+
}
93+
}
94+
{if (actualPage - maxNumIndices > 2) " ... "}
95+
{littlerSideIndices}
96+
{actualPage}
97+
{greaterSideIndices}
98+
{if (actualPage + maxNumIndices < pageCount - 1) " ... "}
99+
{
100+
if (actualPage < pageCount) {
101+
<a href={"/?page=" + pageCount}>{pageCount}</a>
102+
<a href={"/?page=" + (actualPage + 1)}> &gt;</a>
103+
}
104+
}
105+
</span>
106+
}
107+
92108
private def appRow(info: ApplicationHistoryInfo): Seq[Node] = {
93109
val uiAddress = HistoryServer.UI_PATH_PREFIX + s"/${info.id}"
94110
val startTime = UIUtils.formatDate(info.startTime)

0 commit comments

Comments
 (0)