Github user carsonwang commented on a diff in the pull request:
https://github.com/apache/spark/pull/7399#discussion_r34865792
--- Diff: core/src/main/scala/org/apache/spark/ui/PagedTable.scala ---
@@ -0,0 +1,221 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.ui
+
+import scala.xml.{Node, Unparsed}
+
+/**
+ * A data source that provides data for a page.
+ *
+ * @param page the page number
+ * @param pageSize the number of rows in a page
+ */
+private[ui] abstract class PagedDataSource[T](page: Int, pageSize: Int) {
+
+ protected val data: Seq[T]
+
+ /**
+ * Slice the data for this page
+ */
+ def pageData: PageData[T] = {
+ val dataSize = data.size
+ val totalPages = (dataSize + pageSize - 1) / pageSize
+ require(page > 0, "page must be positive")
+ require(page <= totalPages, s"page must not exceed $totalPages")
+ val from = (page - 1) * pageSize
+ val to = dataSize.min(page * pageSize)
+ PageData(page, totalPages, data.slice(from, to))
+ }
+
+}
+
+/**
+ * The data returned by `PagedDataSource.pageData`, including the page
number, the number of total
+ * pages and the data in this page.
+ */
+private[ui] case class PageData[T](page: Int, totalPage: Int, data: Seq[T])
+
+/**
+ * A paged table that will generate a HTML table for a specified page and
also the page navigation.
+ */
+private[ui] trait PagedTable[T] {
+
+ def tableId: String
+
+ def tableCssClass: String
+
+ def dataSource: PagedDataSource[T]
+
+ def headers: Seq[Node]
+
+ def row(t: T): Seq[Node]
+
+ def table: Seq[Node] = {
+ val PageData(page, totalPages, data) = dataSource.pageData
+ <div>
+ {pageNavigation(page, totalPages)}
+ <table class={tableCssClass} id={tableId}>
+ {headers}
+ <tbody>
+ {data.map(row)}
+ </tbody>
+ </table>
+ </div>
+ }
+
+ /**
+ * Return a page navigation.
+ * <ul>
+ * <li>If the totalPages is 1, the page navigation will be empty</li>
+ * <li>
+ * If the totalPages is more than 1, it will create a page
navigation including a group of
+ * page numbers and a form to submit the page number.
+ * </li>
+ * </ul>
+ *
+ * Here are some examples of the page navigation:
+ * {{{
+ * << < 11 12 13* 14 15 16 17 18 19 20 > >>
+ *
+ * This is the first group, so "<<" is hidden.
+ * < 1 2* 3 4 5 6 7 8 9 10 > >>
+ *
+ * This is the first group and the first page, so "<<" and "<" are
hidden.
+ * 1 2* 3 4 5 6 7 8 9 10 > >>
--- End diff --
Is this 1* 2 3 4 ?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]