@@ -26,7 +26,7 @@ import org.apache.spark.ui.{WebUIPage, UIUtils}
2626private [spark] class HistoryPage (parent : HistoryServer ) extends WebUIPage (" " ) {
2727
2828 private val pageSize = 20
29- private val maxNumIndices = 2
29+ private val plusOrMinus = 2
3030
3131 def render (request : HttpServletRequest ): Seq [Node ] = {
3232 val requestedPage = Option (request.getParameter(" page" )).getOrElse(" 1" ).toInt
@@ -40,6 +40,9 @@ private[spark] class HistoryPage(parent: HistoryServer) extends WebUIPage("") {
4040 val last = Math .min(actualFirst + pageSize, allApps.size) - 1
4141 val pageCount = allApps.size / pageSize + (if (allApps.size % pageSize > 0 ) 1 else 0 )
4242
43+ val secondPageFromLeft = 2
44+ val secondPageFromRight = pageCount - 1
45+
4346 val appTable = UIUtils .listingTable(appHeader, appRow, apps)
4447 val providerConfig = parent.getProviderConfig()
4548 val content =
@@ -49,10 +52,40 @@ private[spark] class HistoryPage(parent: HistoryServer) extends WebUIPage("") {
4952 {providerConfig.map { case (k, v) => <li ><strong >{k}:</ strong> {v}</li > }}
5053 </ul >
5154 {
55+ // This displays the indices of pages that are within
56+ // `plusOrMinus` pages of the current page.
57+ // Regardless of where the current page is,
58+ // this also links to the first and last page.
59+ // If the current page +/- `plusOrMinux` is greater than the 2nd page
60+ // from the first page or littler than the 2nd page from the last page,
61+ // `...` will be displayed.
5262 if (allApps.size > 0 ) {
63+ val leftSideIndices =
64+ rangeIndices(actualPage - plusOrMinus until actualPage, 1 < _)
65+ val rightSideIndices =
66+ rangeIndices(actualPage + 1 to actualPage + plusOrMinus, _ < pageCount)
67+
5368 <h4 >
5469 Showing {actualFirst + 1 }- {last + 1 } of {allApps.size}
55- {pageIndices(pageCount, actualPage)}
70+ <span style =" float: right" >
71+ {
72+ if (actualPage > 1 ) {
73+ <a href ={" /?page=" + (actualPage - 1 )}>< </a >
74+ <a href ={" /?page=1" }>1 </a >
75+ }
76+ }
77+ {if (actualPage - plusOrMinus > secondPageFromLeft) " ... " }
78+ {leftSideIndices}
79+ {actualPage}
80+ {rightSideIndices}
81+ {if (actualPage + plusOrMinus < secondPageFromRight) " ... " }
82+ {
83+ if (actualPage < pageCount) {
84+ <a href ={" /?page=" + pageCount}>{pageCount}</a >
85+ <a href ={" /?page=" + (actualPage + 1 )}> > </a >
86+ }
87+ }
88+ </span >
5689 </h4 > ++
5790 appTable
5891 } else {
@@ -79,36 +112,8 @@ private[spark] class HistoryPage(parent: HistoryServer) extends WebUIPage("") {
79112 " Spark User" ,
80113 " Last Updated" )
81114
82- private def pageIndices (pageCount : Int , actualPage : Int ): Seq [Node ] = {
83-
84- def rangeIndices (range : Seq [Int ], condition : Int => Boolean ): Seq [Node ] = {
85- range.filter(condition).map(nextPage => <a href ={" /?page=" + nextPage}> {nextPage} </a >)
86- }
87-
88- val littlerSideIndices =
89- rangeIndices(actualPage - maxNumIndices until actualPage, 1 < _)
90- val greaterSideIndices =
91- rangeIndices(actualPage + 1 to actualPage + maxNumIndices, _ < pageCount)
92-
93- <span style =" float: right" >
94- {
95- if (actualPage > 1 ) {
96- <a href ={" /?page=" + (actualPage - 1 )}>< </a >
97- <a href ={" /?page=1" }>1 </a >
98- }
99- }
100- {if (actualPage - maxNumIndices > 2 ) " ... " }
101- {littlerSideIndices}
102- {actualPage}
103- {greaterSideIndices}
104- {if (actualPage + maxNumIndices < pageCount - 1 ) " ... " }
105- {
106- if (actualPage < pageCount) {
107- <a href ={" /?page=" + pageCount}>{pageCount}</a >
108- <a href ={" /?page=" + (actualPage + 1 )}> > </a >
109- }
110- }
111- </span >
115+ private def rangeIndices (range : Seq [Int ], condition : Int => Boolean ): Seq [Node ] = {
116+ range.filter(condition).map(nextPage => <a href ={" /?page=" + nextPage}> {nextPage} </a >)
112117 }
113118
114119 private def appRow (info : ApplicationHistoryInfo ): Seq [Node ] = {
0 commit comments