progress on scheduling tournaments
This commit is contained in:
parent
fae86ffb20
commit
0fc5b60e86
|
@ -29,7 +29,7 @@ object Lobby extends LilaController {
|
|||
def renderHome[A](status: Results.Status)(implicit ctx: Context): Fu[SimpleResult] =
|
||||
Env.current.preloader(
|
||||
posts = Env.forum.recent(ctx.me, Env.team.cached.teamIds.apply),
|
||||
tours = TournamentRepo.createdUnprotected,
|
||||
tours = TournamentRepo.enterable,
|
||||
filter = Env.setup.filter
|
||||
).map(_.fold(Redirect(_), {
|
||||
case (preload, entries, posts, tours, featured, leaderboard, progress, puzzle) =>
|
||||
|
|
|
@ -1,5 +1,15 @@
|
|||
@(forumRecent: List[lila.forum.PostLiteView], tours: List[lila.tournament.Created], leaderboard: List[User], progress: List[User])(implicit ctx: Context)
|
||||
|
||||
@if(tours.exists(_.scheduled)) {
|
||||
<div class="open_tournaments undertable">
|
||||
<div class="undertable_inner">
|
||||
<table class="scheduled tournaments">
|
||||
@tournament.createdTable(tours.filter(_.scheduled))
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="open_tournaments undertable">
|
||||
<div class="undertable_top">
|
||||
<a class="more" title="See all tournaments" href="@routes.Tournament.home()">@trans.more() »</a>
|
||||
|
@ -7,7 +17,7 @@
|
|||
</div>
|
||||
<div class="undertable_inner">
|
||||
<table class="tournaments">
|
||||
@tournament.createdTable(tours)
|
||||
@tournament.createdTable(tours.filterNot(_.scheduled))
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -24,6 +24,7 @@ final class Env(
|
|||
private val settings = new {
|
||||
val CollectionTournament = config getString "collection.tournament"
|
||||
val MessageTtl = config duration "message.ttl"
|
||||
val EnterableCacheTtl = config duration "enterable.cache.ttl"
|
||||
val UidTimeout = config duration "uid.timeout"
|
||||
val SocketTimeout = config duration "socket.timeout"
|
||||
val SocketName = config getString "socket.name"
|
||||
|
@ -50,13 +51,11 @@ final class Env(
|
|||
chat = hub.actor.chat,
|
||||
flood = flood)
|
||||
|
||||
private lazy val history = () => new History(ttl = MessageTtl)
|
||||
|
||||
private val socketHub = system.actorOf(
|
||||
Props(new lila.socket.SocketHubActor.Default[Socket] {
|
||||
def mkActor(tournamentId: String) = new Socket(
|
||||
tournamentId = tournamentId,
|
||||
history = history(),
|
||||
history = new History(ttl = MessageTtl),
|
||||
uidTimeout = UidTimeout,
|
||||
socketTimeout = SocketTimeout,
|
||||
getUsername = getUsername)
|
||||
|
@ -75,6 +74,9 @@ final class Env(
|
|||
def version(tourId: String): Fu[Int] =
|
||||
socketHub ? Ask(tourId, GetVersion) mapTo manifest[Int]
|
||||
|
||||
private val enterable =
|
||||
lila.memo.AsyncCache.single(TournamentRepo.enterable, timeToLive = EnterableCacheTtl)
|
||||
|
||||
def cli = new lila.common.Cli {
|
||||
import tube.tournamentTube
|
||||
def process = {
|
||||
|
|
|
@ -155,8 +155,14 @@ case class Created(
|
|||
def startIfReady = enoughPlayersToStart option start
|
||||
|
||||
def start = Started(id, data, DateTime.now, players, Nil)
|
||||
|
||||
def asScheduled = schedule map { Scheduled(this, _) }
|
||||
}
|
||||
|
||||
case class Scheduled(tour: Created, schedule: Schedule)
|
||||
|
||||
case class Enterable(tours: List[Created], scheduled: List[Created])
|
||||
|
||||
case class Started(
|
||||
id: String,
|
||||
data: Data,
|
||||
|
|
|
@ -2,6 +2,7 @@ package lila.tournament
|
|||
|
||||
import com.github.nscala_time.time.Imports._
|
||||
import play.api.libs.json._
|
||||
import reactivemongo.bson.BSONDocument
|
||||
|
||||
import lila.db.api._
|
||||
import lila.db.Implicits._
|
||||
|
@ -50,18 +51,24 @@ object TournamentRepo {
|
|||
limit
|
||||
) map { _.map(asFinished).flatten }
|
||||
|
||||
def createdUnprotected: Fu[List[Created]] = $find(
|
||||
def enterable: Fu[List[Created]] = $find(
|
||||
$query(Json.obj(
|
||||
"status" -> Status.Created.id,
|
||||
"password" -> $exists(false)
|
||||
)) sort $sort.createdDesc
|
||||
) ++ $or(Seq(
|
||||
Json.obj("schedule" -> $exists(false)),
|
||||
Json.obj("schedule.at" -> $lt($date(DateTime.now plusMinutes 15)))
|
||||
))) sort BSONDocument(
|
||||
"schedule.at" -> 1,
|
||||
"createdAt" -> 1
|
||||
)
|
||||
) map { _.map(asCreated).flatten }
|
||||
|
||||
def scheduled: Fu[List[Created]] = $find(
|
||||
$query(Json.obj(
|
||||
"status" -> Status.Created.id,
|
||||
"schedule" -> $exists(true)
|
||||
)) sort $sort.desc("schedule.at")
|
||||
))
|
||||
) map { _.map(asCreated).flatten }
|
||||
|
||||
def withdraw(userId: String): Fu[List[String]] = for {
|
||||
|
|
|
@ -134,7 +134,7 @@ object ApplicationBuild extends Build {
|
|||
)
|
||||
|
||||
lazy val tournament = project("tournament", Seq(
|
||||
common, hub, socket, chess, game, round, setup, security, chat)).settings(
|
||||
common, hub, socket, chess, game, round, setup, security, chat, memo)).settings(
|
||||
libraryDependencies ++= provided(play.api, RM, PRM)
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in a new issue