show tournament leaderboard
This commit is contained in:
parent
6b39adb0c4
commit
0405c501d6
|
@ -4,11 +4,13 @@ import lila._
|
|||
import views._
|
||||
import tournament.{ Created, Started, Finished }
|
||||
import http.Context
|
||||
import core.Futuristic.ioToFuture
|
||||
|
||||
import scalaz.effects._
|
||||
import play.api.mvc._
|
||||
import play.api.libs.json._
|
||||
import play.api.libs.iteratee._
|
||||
import play.api.libs.concurrent._
|
||||
import play.api.templates.Html
|
||||
|
||||
object Tournament extends LilaController {
|
||||
|
@ -22,27 +24,28 @@ object Tournament extends LilaController {
|
|||
private def gameRepo = env.game.gameRepo
|
||||
|
||||
val home = Open { implicit ctx ⇒
|
||||
IOk(
|
||||
for {
|
||||
createds ← repo.created
|
||||
starteds ← repo.started
|
||||
finisheds ← repo finished 20
|
||||
} yield html.tournament.home(createds, starteds, finisheds)
|
||||
)
|
||||
Async {
|
||||
futureTournaments zip userRepo.sortedByToints(10).toFuture map {
|
||||
case (((created, started), finished), leaderboard) ⇒
|
||||
Ok(html.tournament.home(created, started, finished, leaderboard))
|
||||
} asPromise
|
||||
}
|
||||
}
|
||||
|
||||
val faq = Open { implicit ctx ⇒ Ok(html.tournament.faqPage()) }
|
||||
|
||||
val homeReload = Open { implicit ctx ⇒
|
||||
IOk(
|
||||
for {
|
||||
createds ← repo.created
|
||||
starteds ← repo.started
|
||||
finisheds ← repo finished 20
|
||||
} yield html.tournament.homeInner(createds, starteds, finisheds)
|
||||
)
|
||||
Async {
|
||||
futureTournaments map {
|
||||
case ((created, started), finished) ⇒
|
||||
Ok(html.tournament.homeInner(created, started, finished))
|
||||
} asPromise
|
||||
}
|
||||
}
|
||||
|
||||
private def futureTournaments =
|
||||
repo.created.toFuture zip repo.started.toFuture zip repo.finished(20).toFuture
|
||||
|
||||
def show(id: String) = Open { implicit ctx ⇒
|
||||
IOptionIOk(repo byId id) {
|
||||
case tour: Created ⇒ showCreated(tour)
|
||||
|
|
|
@ -9,6 +9,8 @@ import akka.util.Duration
|
|||
import akka.util.duration._
|
||||
import scalaz.effects._
|
||||
|
||||
object Futuristic extends Futuristic
|
||||
|
||||
trait Futuristic {
|
||||
|
||||
protected implicit val ttl = 1 minute
|
||||
|
|
|
@ -184,6 +184,7 @@ final class I18nKeys(translator: Translator) {
|
|||
val filterGames = new Key("filterGames")
|
||||
val reset = new Key("reset")
|
||||
val apply = new Key("apply")
|
||||
val leaderboard = new Key("leaderboard")
|
||||
|
||||
def keys = List(playWithAFriend, inviteAFriendToPlayWithYou, playWithTheMachine, challengeTheArtificialIntelligence, toInviteSomeoneToPlayGiveThisUrl, gameOver, waitingForOpponent, waiting, yourTurn, aiNameLevelAiLevel, level, toggleTheChat, toggleSound, chat, resign, checkmate, stalemate, white, black, createAGame, noGameAvailableRightNowCreateOne, whiteIsVictorious, blackIsVictorious, playWithTheSameOpponentAgain, newOpponent, playWithAnotherOpponent, yourOpponentWantsToPlayANewGameWithYou, joinTheGame, whitePlays, blackPlays, theOtherPlayerHasLeftTheGameYouCanForceResignationOrWaitForHim, makeYourOpponentResign, forceResignation, talkInChat, theFirstPersonToComeOnThisUrlWillPlayWithYou, whiteCreatesTheGame, blackCreatesTheGame, whiteJoinsTheGame, blackJoinsTheGame, whiteResigned, blackResigned, whiteLeftTheGame, blackLeftTheGame, shareThisUrlToLetSpectatorsSeeTheGame, youAreViewingThisGameAsASpectator, replayAndAnalyse, viewGameStats, flipBoard, threefoldRepetition, claimADraw, offerDraw, draw, nbConnectedPlayers, talkAboutChessAndDiscussLichessFeaturesInTheForum, seeTheGamesBeingPlayedInRealTime, gamesBeingPlayedRightNow, viewAllNbGames, viewNbCheckmates, nbBookmarks, nbPopularGames, nbAnalysedGames, bookmarkedByNbPlayers, viewInFullSize, logOut, signIn, signUp, people, games, forum, chessPlayers, minutesPerSide, variant, timeControl, start, username, password, haveAnAccount, allYouNeedIsAUsernameAndAPassword, learnMoreAboutLichess, rank, gamesPlayed, declineInvitation, cancel, timeOut, drawOfferSent, drawOfferDeclined, drawOfferAccepted, drawOfferCanceled, yourOpponentOffersADraw, accept, decline, playingRightNow, abortGame, gameAborted, standard, unlimited, mode, casual, rated, thisGameIsRated, rematch, rematchOfferSent, rematchOfferAccepted, rematchOfferCanceled, rematchOfferDeclined, cancelRematchOffer, viewRematch, play, inbox, chatRoom, spectatorRoom, composeMessage, sentMessages, incrementInSeconds, freeOnlineChess, spectators, nbWins, nbLosses, nbDraws, exportGames, color, eloRange, giveNbSeconds, searchAPlayer, whoIsOnline, allPlayers, namedPlayers, premoveEnabledClickAnywhereToCancel, thisPlayerUsesChessComputerAssistance, opening, takeback, proposeATakeback, takebackPropositionSent, takebackPropositionDeclined, takebackPropositionAccepted, takebackPropositionCanceled, yourOpponentProposesATakeback, bookmarkThisGame, toggleBackground, advancedSearch, tournament, freeOnlineChessGamePlayChessNowInACleanInterfaceNoRegistrationNoAdsNoPluginRequiredPlayChessWithComputerFriendsOrRandomOpponents, teams, nbMembers, allTeams, newTeam, myTeams, noTeamFound, joinTeam, quitTeam, anyoneCanJoin, aConfirmationIsRequiredToJoin, joiningPolicy, teamLeader, teamBestPlayers, teamRecentMembers, averageElo, location, settings, filterGames, reset, apply)
|
||||
def keys = List(playWithAFriend, inviteAFriendToPlayWithYou, playWithTheMachine, challengeTheArtificialIntelligence, toInviteSomeoneToPlayGiveThisUrl, gameOver, waitingForOpponent, waiting, yourTurn, aiNameLevelAiLevel, level, toggleTheChat, toggleSound, chat, resign, checkmate, stalemate, white, black, createAGame, noGameAvailableRightNowCreateOne, whiteIsVictorious, blackIsVictorious, playWithTheSameOpponentAgain, newOpponent, playWithAnotherOpponent, yourOpponentWantsToPlayANewGameWithYou, joinTheGame, whitePlays, blackPlays, theOtherPlayerHasLeftTheGameYouCanForceResignationOrWaitForHim, makeYourOpponentResign, forceResignation, talkInChat, theFirstPersonToComeOnThisUrlWillPlayWithYou, whiteCreatesTheGame, blackCreatesTheGame, whiteJoinsTheGame, blackJoinsTheGame, whiteResigned, blackResigned, whiteLeftTheGame, blackLeftTheGame, shareThisUrlToLetSpectatorsSeeTheGame, youAreViewingThisGameAsASpectator, replayAndAnalyse, viewGameStats, flipBoard, threefoldRepetition, claimADraw, offerDraw, draw, nbConnectedPlayers, talkAboutChessAndDiscussLichessFeaturesInTheForum, seeTheGamesBeingPlayedInRealTime, gamesBeingPlayedRightNow, viewAllNbGames, viewNbCheckmates, nbBookmarks, nbPopularGames, nbAnalysedGames, bookmarkedByNbPlayers, viewInFullSize, logOut, signIn, signUp, people, games, forum, chessPlayers, minutesPerSide, variant, timeControl, start, username, password, haveAnAccount, allYouNeedIsAUsernameAndAPassword, learnMoreAboutLichess, rank, gamesPlayed, declineInvitation, cancel, timeOut, drawOfferSent, drawOfferDeclined, drawOfferAccepted, drawOfferCanceled, yourOpponentOffersADraw, accept, decline, playingRightNow, abortGame, gameAborted, standard, unlimited, mode, casual, rated, thisGameIsRated, rematch, rematchOfferSent, rematchOfferAccepted, rematchOfferCanceled, rematchOfferDeclined, cancelRematchOffer, viewRematch, play, inbox, chatRoom, spectatorRoom, composeMessage, sentMessages, incrementInSeconds, freeOnlineChess, spectators, nbWins, nbLosses, nbDraws, exportGames, color, eloRange, giveNbSeconds, searchAPlayer, whoIsOnline, allPlayers, namedPlayers, premoveEnabledClickAnywhereToCancel, thisPlayerUsesChessComputerAssistance, opening, takeback, proposeATakeback, takebackPropositionSent, takebackPropositionDeclined, takebackPropositionAccepted, takebackPropositionCanceled, yourOpponentProposesATakeback, bookmarkThisGame, toggleBackground, advancedSearch, tournament, freeOnlineChessGamePlayChessNowInACleanInterfaceNoRegistrationNoAdsNoPluginRequiredPlayChessWithComputerFriendsOrRandomOpponents, teams, nbMembers, allTeams, newTeam, myTeams, noTeamFound, joinTeam, quitTeam, anyoneCanJoin, aConfirmationIsRequiredToJoin, joiningPolicy, teamLeader, teamBestPlayers, teamRecentMembers, averageElo, location, settings, filterGames, reset, apply, leaderboard)
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import play.api.templates.Html
|
|||
|
||||
trait AssetHelper {
|
||||
|
||||
val assetVersion = 41
|
||||
val assetVersion = 42
|
||||
|
||||
def cssTag(name: String) = css("stylesheets/" + name)
|
||||
|
||||
|
|
|
@ -51,12 +51,17 @@ trait UserHelper {
|
|||
def userLink(
|
||||
user: User,
|
||||
cssClass: Option[String] = None,
|
||||
withElo: Boolean = true) = Html {
|
||||
withElo: Boolean = true,
|
||||
withOnline: Boolean = true,
|
||||
text: Option[String] = None) = Html {
|
||||
"""<a class="user_link%s%s" href="%s">%s</a>""".format(
|
||||
isUsernameOnline(user.id).fold(" online", " offline"),
|
||||
withOnline.fold(
|
||||
isUsernameOnline(user.id).fold(" online", " offline"),
|
||||
""),
|
||||
cssClass.fold(" " + _, ""),
|
||||
routes.User.show(user.username),
|
||||
withElo.fold(user.usernameWithElo, user.username))
|
||||
text | withElo.fold(user.usernameWithElo, user.username)
|
||||
)
|
||||
}
|
||||
|
||||
def userInfosLink(
|
||||
|
|
|
@ -44,6 +44,10 @@ class UserRepo(collection: MongoCollection)
|
|||
.toList
|
||||
}
|
||||
|
||||
def sortedByToints(nb: Int): IO[List[User]] = io {
|
||||
find(DBObject()).sort(DBObject("toints" -> -1)).limit(nb).toList
|
||||
}
|
||||
|
||||
def idsAverageElo(ids: Iterable[String]): IO[Int] = io {
|
||||
val result = collection.mapReduce(
|
||||
mapFunction = """function() { emit("e", this.elo); }""",
|
||||
|
|
|
@ -1,9 +1,15 @@
|
|||
@(createds: List[lila.tournament.Created], starteds: List[lila.tournament.Started], finisheds: List[lila.tournament.Finished])(implicit ctx: Context)
|
||||
@(createds: List[lila.tournament.Created], starteds: List[lila.tournament.Started], finisheds: List[lila.tournament.Finished], leaderboard: List[User])(implicit ctx: Context)
|
||||
|
||||
@goodies = {
|
||||
<div class="tournament_links">
|
||||
<a href="@routes.Tournament.faq()">Tournament FAQ</a>
|
||||
</div>
|
||||
<h2 class="leaderboard_title">@trans.leaderboard()</h2>
|
||||
<ol class="tournament_leaderboard">
|
||||
@leaderboard.map { user =>
|
||||
<li>@userLink(user, withOnline = false, cssClass = "inline".some, text = Some(user.username + " [" + user.toints + "]"))</li>
|
||||
}
|
||||
</ol>
|
||||
}
|
||||
|
||||
@tournament.layout(
|
||||
|
|
|
@ -160,3 +160,4 @@ settings=Settings
|
|||
filterGames=Filter games
|
||||
reset=Reset
|
||||
apply=Apply
|
||||
leaderboard=Leaderboard
|
||||
|
|
|
@ -160,3 +160,4 @@ settings=Paramètres
|
|||
filterGames=Filtrer les parties
|
||||
reset=Réinitialiser
|
||||
apply=Appliquer
|
||||
leaderboard=Classement
|
||||
|
|
|
@ -94,7 +94,8 @@ body.dark form.wide input[type="text"],
|
|||
body.dark form.wide textarea,
|
||||
body.dark #team .team-left,
|
||||
body.dark #team .team-right,
|
||||
body.dark #team h2
|
||||
body.dark #team h2,
|
||||
body.dark .leaderboard_title
|
||||
{
|
||||
border-color: #3e3e3e;
|
||||
}
|
||||
|
|
|
@ -131,5 +131,20 @@ div.faq_box {
|
|||
}
|
||||
|
||||
div.header .tournament_links {
|
||||
margin-top: 2em;
|
||||
margin-top: 30px;
|
||||
}
|
||||
|
||||
.leaderboard_title {
|
||||
font-size: 1.5em;
|
||||
margin-top: 30px;
|
||||
margin-bottom: 6px;
|
||||
border-bottom: 1px solid #ccc;
|
||||
}
|
||||
ol.tournament_leaderboard li {
|
||||
font-size: 1.2em;
|
||||
padding: 5px 0;
|
||||
list-style: decimal-leading-zero inside;
|
||||
}
|
||||
ol.tournament_leaderboard a {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue