show the computer analysis link to the players and watchers

This commit is contained in:
Thibault Duplessis 2012-07-07 14:58:48 +02:00
parent 928890a441
commit 3702cd488c
6 changed files with 18 additions and 8 deletions

View file

@ -20,6 +20,8 @@ final class Analyser(
def get(id: String): IO[Option[Analysis]] = analysisRepo byId id
def has(id: String): IO[Boolean] = analysisRepo isDone id
def getOrGenerate(id: String, userId: String): Future[Valid[Analysis]] =
getOrGenerateIO(id, userId)

View file

@ -42,4 +42,8 @@ final class AnalysisRepo(val collection: MongoCollection) {
} yield decoded
} yield Analysis(infos | Nil, done, fail)
}
def isDone(id: String): IO[Boolean] = io {
collection.count(DBObject("_id" -> id, "done" -> true)) > 0
}
}

View file

@ -23,6 +23,7 @@ object Round extends LilaController with TheftPrevention {
def joiner = env.setup.friendJoiner
def bookmarkApi = env.bookmark.api
def userRepo = env.user.userRepo
def analyser = env.analyse.analyser
def websocketWatcher(gameId: String, color: String) = WebSocket.async[JsValue] { req
implicit val ctx = reqToCtx(req)
@ -47,13 +48,15 @@ object Round extends LilaController with TheftPrevention {
engine pov.opponent.userId.fold(
u userRepo isEngine u,
io(false))
analysed analyser has pov.gameId
} yield PreventTheft(pov) {
Ok(html.round.player(
pov,
version(pov.gameId),
engine,
roomHtml map { Html(_) },
bookmarkers))
bookmarkers,
analysed))
},
io(Redirect(routes.Setup.await(fullId)))
)
@ -72,7 +75,8 @@ object Round extends LilaController with TheftPrevention {
io(Nil)
)
roomHtml messenger renderWatcher pov.game
} yield Ok(html.round.watcher(pov, version(pov.gameId), Html(roomHtml), bookmarkers))
analysed analyser has pov.gameId
} yield Ok(html.round.watcher(pov, version(pov.gameId), Html(roomHtml), bookmarkers, analysed))
private def join(pov: Pov)(implicit ctx: Context): IO[Result] =
joiner(pov.game, ctx.me).fold(

View file

@ -1,5 +1,5 @@
@(pov: Pov)(implicit ctx: Context)
@(pov: Pov, visible: Boolean = false)(implicit ctx: Context)
<div class="undergame_box game_analysis none">
<div class="undergame_box game_analysis @visible.fold("", "none")">
<a href="@routes.Analyse.replay(pov.gameId, pov.color.name)">View the computer analysis</a>
</div>

View file

@ -1,4 +1,4 @@
@(pov: Pov, version: Int, engine: Boolean, roomHtml: Option[Html], bookmarkers: List[User])(implicit ctx: Context)
@(pov: Pov, version: Int, engine: Boolean, roomHtml: Option[Html], bookmarkers: List[User], analysed: Boolean)(implicit ctx: Context)
@import pov._
@ -50,7 +50,7 @@ underchat = underchat.some) {
</div>
</div>
<script type="text/javascript">var lichess_data = @Html(roundPlayerJsData(pov, version))</script>
@analyse.link(pov)
@analyse.link(pov, analysed)
@views.html.game.more(pov, bookmarkers) {
<nav>
<a href="@routes.Analyse.replay(gameId, color.name)">@trans.replayAndAnalyse()</a>

View file

@ -1,4 +1,4 @@
@(pov: Pov, version: Int, roomHtml: Html, bookmarkers: List[User])(implicit ctx: Context)
@(pov: Pov, version: Int, roomHtml: Html, bookmarkers: List[User], analysed: Boolean)(implicit ctx: Context)
@import pov._
@ -54,7 +54,7 @@ underchat = underchat.some) {
</div>
</div>
<script type="text/javascript">var lichess_data = @Html(roundWatcherJsData(pov, version))</script>
@analyse.link(pov)
@analyse.link(pov, analysed)
@views.html.game.more(pov, bookmarkers) {
<nav>
<a href="@routes.Analyse.replay(gameId, color.name)">@trans.replayAndAnalyse()</a>