forked from lichess-org/lila
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
40 changed files
with
893 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package controllers | ||
|
||
import play.api.data.Form | ||
import play.api.libs.json._ | ||
import play.api.mvc._ | ||
|
||
import lila.api.Context | ||
import lila.app._ | ||
import lila.relay.{ Relay => RelayModel } | ||
import views._ | ||
|
||
object Relay extends LilaController { | ||
|
||
private def env = Env.relay | ||
|
||
private def relayNotFound(implicit ctx: Context) = NotFound(html.relay.notFound()) | ||
|
||
val index = Open { implicit ctx => | ||
env.repo recent 30 map { relays => | ||
Ok(html.relay.home(relays)) | ||
} | ||
} | ||
|
||
def show(id: String, slug: String) = Open { implicit ctx => | ||
env.repo byId id flatMap { | ||
_.fold(relayNotFound.fuccess) { relay => | ||
if (relay.slug != slug) Redirect(routes.Relay.show(id, relay.slug)).fuccess | ||
else env.version(relay.id) zip env.jsonView(relay) zip chatOf(relay) map { | ||
case ((version, data), chat) => html.relay.show(relay, version, data, chat) | ||
} | ||
} map NoCache | ||
} | ||
} | ||
|
||
def websocket(id: String, apiVersion: Int) = SocketOption[JsValue] { implicit ctx => | ||
(getInt("version") |@| get("sri")).tupled ?? { | ||
case (version, uid) => env.socketHandler.join(id, version, uid, ctx.me) | ||
} | ||
} | ||
|
||
private def chatOf(relay: RelayModel)(implicit ctx: Context) = | ||
ctx.isAuth ?? { | ||
Env.chat.api.userChat find relay.id map (_.forUser(ctx.me).some) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package lila.app | ||
package templating | ||
|
||
import controllers.routes | ||
import lila.api.Context | ||
import lila.relay.Relay | ||
import lila.user.{ User, UserContext } | ||
import lila.relay.Env.{ current => relayEnv } | ||
|
||
import play.api.libs.json.Json | ||
import play.twirl.api.Html | ||
|
||
trait RelayHelper { self: I18nHelper => | ||
|
||
def relayLink(relay: Relay): Html = Html { | ||
val url = routes.Relay.show(relay.id, relay.slug) | ||
s"""<a class="text" data-icon="n" href="$url">${relay.name}</a>""" | ||
} | ||
|
||
def relayIdToName(id: String) = relayEnv.cached name id getOrElse "Chess event" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
@(relays: List[lila.relay.Relay])(implicit ctx: Context) | ||
|
||
@relay.layout( | ||
title = "Watch Chess events", | ||
side = none) { | ||
<div id="relay_list"> | ||
<div class="content_box simul_box no_padding"> | ||
<h1>Watch Chess events</h1> | ||
<table class="slist"> | ||
<thead> | ||
<tr> | ||
<th>Date</th> | ||
<th>Event</th> | ||
<th>Status</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
@relays.map { rel => | ||
<tr class="scheduled"> | ||
<td>@showDate(rel.date)</td> | ||
<td><a href="@routes.Relay.show(rel.id, rel.slug)">@rel.name</a></td> | ||
<td>@rel.status</td> | ||
</tr> | ||
} | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
@()(implicit ctx: Context) | ||
@Html(J.stringify(i18nJsObject( | ||
trans.finished | ||
))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
@(title: String, moreJs: Html = Html(""), side: Option[Html] = None, chat: Option[Html] = None, underchat: Option[Html] = None, chessground: Boolean = true)(body: Html)(implicit ctx: Context) | ||
|
||
@moreCss = { | ||
@cssTag("relay.css") | ||
} | ||
|
||
@base.layout( | ||
title = title, | ||
moreJs = moreJs, | ||
moreCss = moreCss, | ||
side = side, | ||
chat = chat, | ||
underchat = underchat, | ||
chessground = chessground) { | ||
@body | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
@()(implicit ctx: Context) | ||
|
||
@relay.layout(title = "Event not found") { | ||
<div id="relay"> | ||
<div class="content_box small_box faq_page"> | ||
<h1>Event not found</h1><br /><br /> | ||
This event does not exist.<br /> | ||
It may have been canceled. | ||
<br /> | ||
<br /> | ||
<a href="@routes.Relay.index">Return to events homepage</a> | ||
</div> | ||
</div> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
@(rel: lila.relay.Relay, socketVersion: Int, data: play.api.libs.json.JsObject, chat: Option[lila.chat.UserChat])(implicit ctx: Context) | ||
|
||
@underchat = { | ||
<div class="watchers" data-icon="v"> | ||
<span class="list inline_userlist"></span> | ||
</div> | ||
} | ||
|
||
@moreJs = { | ||
@jsAt(s"compiled/lichess.relay${isProd??(".min")}.js") | ||
@embedJs { | ||
lichess = lichess || {}; | ||
lichess.relay = LichessRelay(document.getElementById('relay'), { | ||
data: @Html(J.stringify(data)), | ||
i18n: @jsI18n(), | ||
socketVersion: @socketVersion | ||
}); | ||
} | ||
} | ||
|
||
@relay.layout( | ||
title = rel.name, | ||
side = relay.side(rel).some, | ||
chat = chat.map(c => base.chat(c, trans.chatRoom.str())), | ||
underchat = underchat.some, | ||
moreJs = moreJs, | ||
chessground = false) { | ||
<div id="relay"></div> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
@(rel: lila.relay.Relay)(implicit ctx: Context) | ||
|
||
<div class="side_box padded"> | ||
@rel.name | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package lila.relay | ||
|
||
import scala.concurrent.duration._ | ||
|
||
private[relay] final class Cached(repo: RelayRepo) { | ||
|
||
private val nameCache = lila.memo.MixedCache[String, Option[String]]( | ||
((id: String) => repo byId id map2 { (relay: Relay) => relay.name }), | ||
timeToLive = 6 hours, | ||
default = _ => none) | ||
|
||
def name(id: String) = nameCache get id | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package lila.relay | ||
|
||
import play.api.libs.json._ | ||
|
||
import lila.game.{ Game, GameRepo } | ||
|
||
final class JsonView { | ||
|
||
def apply(relay: Relay): Fu[JsObject] = | ||
GameRepo.games(relay.gameIds) map { games => | ||
Json.obj( | ||
"id" -> relay.id, | ||
"name" -> relay.name, | ||
"status" -> relay.status.id, | ||
"games" -> games.map(gameJson) | ||
) | ||
} | ||
|
||
private def gameJson(g: Game) = Json.obj( | ||
"id" -> g.id, | ||
"status" -> g.status.id, | ||
"fen" -> (chess.format.Forsyth exportBoard g.toChess.board), | ||
"lastMove" -> ~g.castleLastMoveTime.lastMoveString, | ||
"orient" -> g.firstPlayer.color.name) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.