From 830a357d24979063ab863aaa45ad75bef2e7edca Mon Sep 17 00:00:00 2001 From: Thibault Duplessis Date: Sat, 21 Dec 2013 21:39:31 +0100 Subject: [PATCH] show leaderboard on homepage --- app/Env.scala | 1 + app/controllers/Lobby.scala | 4 ++-- app/mashup/Preload.scala | 8 ++++--- app/views/lobby/buttons.scala.html | 23 +++++++++++++++++- app/views/lobby/home.scala.html | 4 ++-- app/views/user/list.scala.html | 36 ++++++++--------------------- app/views/user/top.scala.html | 2 +- app/views/user/topLeader.scala.html | 5 ++++ public/stylesheets/board.css | 11 +++++++-- 9 files changed, 56 insertions(+), 38 deletions(-) create mode 100644 app/views/user/topLeader.scala.html diff --git a/app/Env.scala b/app/Env.scala index a47d12b5a0..a8181b167d 100644 --- a/app/Env.scala +++ b/app/Env.scala @@ -24,6 +24,7 @@ final class Env( history = Env.lobby.history, featured = Env.game.featured, relations = Env.relation.api, + leaderboard = Env.user.cached.topRatingDay.apply, recentGames = () ⇒ Env.timeline.getter.recentGames, timelineEntries = Env.timeline.getter.userEntries _) diff --git a/app/controllers/Lobby.scala b/app/controllers/Lobby.scala index 4f3c705728..d553ab8fa9 100644 --- a/app/controllers/Lobby.scala +++ b/app/controllers/Lobby.scala @@ -27,8 +27,8 @@ object Lobby extends LilaController { tours = TournamentRepo.createdUnprotected, filter = Env.setup.filter ).map(_.fold(Redirect(_), { - case (preload, entries, gameEntries, posts, tours, featured) ⇒ status(html.lobby.home( - Json stringify preload, entries, gameEntries, posts, tours, featured)) |> { response ⇒ + case (preload, entries, gameEntries, posts, tours, featured, leaderboard) ⇒ status(html.lobby.home( + Json stringify preload, entries, gameEntries, posts, tours, featured, leaderboard)) |> { response ⇒ ctx.req.session.data.contains(LilaCookie.sessionId).fold( response, response withCookies LilaCookie.makeSessionId(ctx.req) diff --git a/app/mashup/Preload.scala b/app/mashup/Preload.scala index 0672fd3944..17c6499792 100644 --- a/app/mashup/Preload.scala +++ b/app/mashup/Preload.scala @@ -24,10 +24,11 @@ final class Preload( history: History, featured: Featured, relations: RelationApi, + leaderboard: Int => Fu[List[User]], recentGames: () ⇒ Fu[List[GameEntry]], timelineEntries: String ⇒ Fu[List[Entry]]) { - private type RightResponse = (JsObject, List[Entry], List[GameEntry], List[PostLiteView], List[Created], Option[Game]) + private type RightResponse = (JsObject, List[Entry], List[GameEntry], List[PostLiteView], List[Created], Option[Game], List[User]) private type Response = Either[Call, RightResponse] def apply( @@ -41,13 +42,14 @@ final class Preload( featured.one zip (ctx.userId ?? relations.blocks) zip (ctx.userId ?? timelineEntries) zip + leaderboard(10) zip filter map { - case (((((((hooks, gameEntries), posts), tours), feat), blocks), entries), filter) ⇒ + case ((((((((hooks, gameEntries), posts), tours), feat), blocks), entries), leaderboard), filter) ⇒ (Right((Json.obj( "version" -> history.version, "pool" -> JsArray(hooks map (_.render)), "filter" -> filter.render, "blocks" -> blocks - ), entries, gameEntries, posts, tours, feat))) + ), entries, gameEntries, posts, tours, feat, leaderboard))) } } diff --git a/app/views/lobby/buttons.scala.html b/app/views/lobby/buttons.scala.html index 12062a9569..12eacf504d 100644 --- a/app/views/lobby/buttons.scala.html +++ b/app/views/lobby/buttons.scala.html @@ -1,4 +1,4 @@ -@()(implicit ctx: Context) +@(leaderboard: List[User])(implicit ctx: Context)
@@ -6,4 +6,25 @@ @b.name() }
+
+
+
+ @trans.more() » + Today's Leaders +
+
+ + + @leaderboard.map { u => + + + + + + } + +
@userLink(u, withRating = false, cssClass="revert-underline".some)@u.rating@showProgress(u.progress)
+
+
+
diff --git a/app/views/lobby/home.scala.html b/app/views/lobby/home.scala.html index de85148344..d663c9ffed 100644 --- a/app/views/lobby/home.scala.html +++ b/app/views/lobby/home.scala.html @@ -1,4 +1,4 @@ -@(preload: String, userTimeline: List[lila.timeline.Entry], gameTimeline: List[lila.timeline.GameEntry], forumRecent: List[lila.forum.PostLiteView], tours: List[lila.tournament.Created], featured: Option[Game])(implicit ctx: Context) +@(preload: String, userTimeline: List[lila.timeline.Entry], gameTimeline: List[lila.timeline.GameEntry], forumRecent: List[lila.forum.PostLiteView], tours: List[lila.tournament.Created], featured: Option[Game], leaderboard: List[User])(implicit ctx: Context) @underchat = { Watch Lichess TV @@ -70,7 +70,7 @@ underchat = underchat.some) {
- @lobby.buttons() + @lobby.buttons(leaderboard) @lobby.undertable(gameTimeline, forumRecent, tours) } diff --git a/app/views/user/list.scala.html b/app/views/user/list.scala.html index 0a7e2fca57..ec63137f71 100644 --- a/app/views/user/list.scala.html +++ b/app/views/user/list.scala.html @@ -19,39 +19,21 @@ @user.layout(trans.chessPlayers.str(), goodies = goodies.some) {
- @user.top(progressDay, "Progress today") { u => - @u.rating - @showProgress(u.progress) - } - @user.top(ratingDay, "Leaderboard today") { u => - @u.rating - @showProgress(u.progress) - } + @user.topLeader(progressDay, "Progress today") + @user.topLeader(ratingDay, "Leaderboard today") @user.topActive(nbDay, "Active today", true) - @user.top(progressWeek, "Progress this week") { u => - @u.rating - @showProgress(u.progress) - } - @user.top(ratingWeek, "Leaderboard this week") { u => - @u.rating - @showProgress(u.progress) - } + @user.topLeader(progressWeek, "Progress this week") + @user.topLeader(ratingWeek, "Leaderboard this week") @user.topActive(nbWeek, "Active this week", true) - @user.top(progressMonth, "Progress this month") { u => - @u.rating - @showProgress(u.progress) - } - @user.top(rating, "Leaderboard") { u => - @u.rating - @showProgress(u.progress) - } + @user.topLeader(progressMonth, "Progress this month") + @user.topLeader(rating, "Leaderboard") @user.topActive(nb, "Active players", true) - @user.top(bullet, "Best bullet players")(_.perfs.bullet.glicko.intRating) - @user.top(blitz, "Best blitz players")(_.perfs.blitz.glicko.intRating) - @user.top(slow, "Best slow players", true)(_.perfs.slow.glicko.intRating) + @user.top(bullet, "Best bullet players")(u => Html(s"${u.perfs.bullet.glicko.intRating}")) + @user.top(blitz, "Best blitz players")(u => Html(s"${u.perfs.blitz.glicko.intRating}")) + @user.top(slow, "Best slow players", true)(u => Html(s"${u.perfs.slow.glicko.intRating}"))
} diff --git a/app/views/user/top.scala.html b/app/views/user/top.scala.html index 8010c464f8..8e1695afb4 100644 --- a/app/views/user/top.scala.html +++ b/app/views/user/top.scala.html @@ -7,7 +7,7 @@ @users.map { u => @userLink(u, withRating = false, cssClass="revert-underline".some) - @f(u) + @f(u) } diff --git a/app/views/user/topLeader.scala.html b/app/views/user/topLeader.scala.html new file mode 100644 index 0000000000..9810239b8c --- /dev/null +++ b/app/views/user/topLeader.scala.html @@ -0,0 +1,5 @@ +@(users: List[User], title: Any, last: Boolean = false)(implicit ctx: Context) +@user.top(users, title) { u => +@u.rating +@showProgress(u.progress) +} diff --git a/public/stylesheets/board.css b/public/stylesheets/board.css index c9bf500121..d9d141bc3f 100644 --- a/public/stylesheets/board.css +++ b/public/stylesheets/board.css @@ -263,13 +263,20 @@ div.lichess_table.spectator { } div.lichess_table_not_started { position: absolute; - top: 176px; + top: 100px; left: 0px; width: 242px; box-shadow: none; border: none; padding: 0; - top: 100px; +} +div.lichess_homepage div.leaderboard { + position: absolute; + top: 514px; + width: 242px; +} +div.lichess_homepage div.leaderboard div.undertable_inner { + height: auto; } div.lichess_table div.username { padding-left: 16px;