send featured game through websockets
parent
2c3a253c89
commit
ac48dae13d
|
@ -48,10 +48,4 @@ object Game extends LilaController with BaseGame {
|
|||
Ok(html.game.analysed(analysePaginator games page, makeListMenu))
|
||||
}
|
||||
}
|
||||
|
||||
def featuredJs(id: String) = Open { implicit ctx ⇒
|
||||
IOk(gameRepo game id map { gameOption =>
|
||||
html.game.featuredJs(gameOption)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,12 +35,11 @@ final class Featured(
|
|||
}
|
||||
|
||||
private def getOne = oneId flatMap fetch filter valid orElse {
|
||||
feature ~ { o ⇒
|
||||
val newOneId = o map (_.id)
|
||||
newOneId foreach { newId ⇒
|
||||
lobbyRef ! ChangeFeatured(oneId, newId)
|
||||
feature ~ { newOne ⇒
|
||||
oneId = newOne map (_.id)
|
||||
newOne foreach { game ⇒
|
||||
lobbyRef ! ChangeFeatured(views.html.game.featuredJsNoCtx(game).toString)
|
||||
}
|
||||
oneId = newOneId
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -101,4 +101,15 @@ trait GameHelper { self: I18nHelper with UserHelper with StringHelper with AiHel
|
|||
Forsyth exportBoard game.toChess.board,
|
||||
game.lastMove | "")
|
||||
}
|
||||
|
||||
def gameFenNoCtx(game: DbGame, color: Color) = Html {
|
||||
var live = game.isBeingPlayed
|
||||
"""<a href="%s" class="mini_board parse_fen %s" data-live="%s" data-color="%s" data-fen="%s" data-lastmove="%s"></a>""".format(
|
||||
routes.Round.watcher(game.id, color.name),
|
||||
live.fold("live live_" + game.id, ""),
|
||||
live.fold(game.id, ""),
|
||||
color.name,
|
||||
Forsyth exportBoard game.toChess.board,
|
||||
game.lastMove | "")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,13 +61,11 @@ final class Hub(
|
|||
members.values filter (_ ownsHook hook) foreach fn
|
||||
}
|
||||
|
||||
case ChangeFeatured(oldId, newId) ⇒ notifyFeatured(oldId, newId)
|
||||
case ChangeFeatured(html) ⇒ notifyFeatured(html)
|
||||
}
|
||||
|
||||
def notifyFeatured(oldId: Option[String], newId: String) {
|
||||
val msg = makeMessage("featured", JsObject(Seq(
|
||||
"oldId" -> oldId.fold(JsString(_), JsNull),
|
||||
"newId" -> JsString(newId))))
|
||||
def notifyFeatured(html: String) {
|
||||
val msg = makeMessage("featured", JsString(html))
|
||||
members.values foreach (_.channel push msg)
|
||||
}
|
||||
|
||||
|
|
|
@ -28,5 +28,5 @@ case class Quit(uid: String)
|
|||
case class SendTo(userId: String, message: JsObject)
|
||||
case class Fen(gameId: String, fen: String, lastMove: Option[String])
|
||||
case class LiveGames(uid: String, gameIds: List[String])
|
||||
case class ChangeFeatured(oldId: Option[String], newId: String)
|
||||
case class ChangeFeatured(html: String)
|
||||
case class Resync(uid: String)
|
||||
|
|
|
@ -1,10 +1,3 @@
|
|||
@(gameOption: Option[DbGame])(implicit ctx: Context)
|
||||
|
||||
<div class="featured_game" data-href="@routes.Game.featuredJs("")">
|
||||
@gameOption.map { game =>
|
||||
@gameFen(game, game.creator.color)
|
||||
<div class="vstext">
|
||||
@usernameWithElo(game.creator) - @usernameWithElo(game.invited)<br />
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
@(g: DbGame)(implicit ctx: Context)
|
||||
@gameFen(g, g.creator.color)
|
||||
<div class="vstext">@usernameWithElo(g.creator) - @usernameWithElo(g.invited)</div>
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
@(g: DbGame)
|
||||
@gameFenNoCtx(g, g.creator.color)
|
||||
<div class="vstext">@usernameWithElo(g.creator) - @usernameWithElo(g.invited)</div>
|
|
@ -26,7 +26,11 @@
|
|||
}
|
||||
|
||||
@underchat = {
|
||||
@game.featuredJs(featured)
|
||||
<div id="featured_game">
|
||||
@featured.map { g =>
|
||||
@game.featuredJs(g)
|
||||
}
|
||||
</div>
|
||||
}
|
||||
|
||||
@baseline = {
|
||||
|
|
|
@ -8,7 +8,6 @@ GET /games/checkmate controllers.Game.checkmate(page: Int ?= 1)
|
|||
GET /games/bookmark controllers.Game.bookmark(page: Int ?= 1)
|
||||
GET /games/popular controllers.Game.popular(page: Int ?= 1)
|
||||
GET /games/analysed controllers.Game.analysed(page: Int ?= 1)
|
||||
GET /games/featured/js controllers.Game.featuredJs(id: String ?= "")
|
||||
|
||||
# Search
|
||||
GET /games/search controllers.Search.form(page: Int ?= 1)
|
||||
|
|
|
@ -233,18 +233,9 @@ $(function() {
|
|||
$("table.tournaments").html(data);
|
||||
}
|
||||
|
||||
function changeFeatured(data) {
|
||||
$('div.featured_game').each(function() {
|
||||
var $featured = $(this);
|
||||
$.get(
|
||||
$featured.data("href"),
|
||||
{ id: data.newId },
|
||||
function(html) {
|
||||
$featured.replaceWith(html);
|
||||
$('body').trigger('lichess.content_loaded');
|
||||
}
|
||||
);
|
||||
});
|
||||
function changeFeatured(html) {
|
||||
$('#featured_game').html(html);
|
||||
$('body').trigger('lichess.content_loaded');
|
||||
}
|
||||
|
||||
function renderTimeline(data) {
|
||||
|
|
|
@ -184,7 +184,7 @@ div.hooks a.user_link {
|
|||
padding-left: 0;
|
||||
}
|
||||
|
||||
div.featured_game div.vstext {
|
||||
#featured_game div.vstext {
|
||||
margin-top: 0.7em;
|
||||
text-align: center;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue