complete homepage game list implementation

pull/138/head
Thibault Duplessis 2014-12-03 00:41:39 +01:00
parent 278b9ce3da
commit a70a88b722
9 changed files with 49 additions and 25 deletions

View File

@ -43,6 +43,13 @@ object Lobby extends LilaController {
)
}
def playing = Auth { implicit ctx =>
me =>
lila.game.GameRepo nowPlaying me map { povs =>
html.lobby.playing(povs)
}
}
def socket(apiVersion: Int) = Socket[JsValue] { implicit ctx =>
get("sri") ?? { uid =>
Env.lobby.socketHandler(uid = uid, user = ctx.me)

View File

@ -47,20 +47,8 @@ openGraph = Map(
<span data-icon="D"> @trans.filterGames()</span>
<span class="number">(0)</span>
</a>
<div id="now_playing" class="tab now_playing none">
@nowPlaying.sortBy(pov => pov.remainingSeconds | (Int.MaxValue - pov.isMyTurn.fold(1, 0))).map { pov =>
<a href="@routes.Round.player(pov.fullId)" class="@if(pov.isMyTurn){my_turn}">
@gameFen(pov.game, pov.color, withLink = false, withTitle = false)
<span class="meta">
@playerLink(pov.opponent, withRating = false)
<span class="indicator">
@if(pov.isMyTurn) {
@pov.remainingSeconds.fold(trans.yourTurn())(secondsFromNow)
} else {&nbsp;}
</span>
</span>
</a>
}
<div id="now_playing" class="tab now_playing none" data-href="@routes.Lobby.playing">
@playing(nowPlaying)
</div>
<div id="hooks_chart" class="tab graph none"><div class="canvas"></div></div>
<div id="hooks_list" class="tab list none">

View File

@ -0,0 +1,16 @@
@(povs: List[Pov])(implicit ctx: Context)
@povs.sortBy(pov => pov.remainingSeconds | (99999999 - pov.isMyTurn.fold(1, 0))).map { pov =>
<a href="@routes.Round.player(pov.fullId)" class="@if(pov.isMyTurn){my_turn}">
@gameFen(pov.game, pov.color, withLink = false, withTitle = false)
<span class="meta">
@playerText(pov.opponent, withRating = false)
<span class="indicator">
@if(pov.isMyTurn) {
@pov.remainingSeconds.fold(trans.yourTurn())(secondsFromNow)
} else {&nbsp;}
</span>
</span>
</a>
}

View File

@ -6,6 +6,7 @@ GET / controllers.Lobby.home
GET /lobby/socket/v:apiVersion controllers.Lobby.socket(apiVersion: Int)
GET /timeline controllers.Lobby.timeline
GET /timeline/more controllers.Lobby.timelineMore
GET /lobby/playing controllers.Lobby.playing
# TV
GET /tv controllers.Tv.index

View File

@ -363,7 +363,7 @@ case class Game(
0
)
def isBeingPlayed = !isPgnImport && !finishedOrAborted && !olderThan(60)
def isBeingPlayed = !isPgnImport && !finishedOrAborted
def olderThan(seconds: Int) = updatedAt.??(_ isBefore DateTime.now.minusSeconds(seconds))

View File

@ -1046,8 +1046,8 @@ var storage = {
function startWatching() {
if (!socketOpened) return;
var ids = [];
$('a.mini_board.live').removeClass("live").each(function() {
ids.push($(this).data("live"));
$('.mini_board.live').removeClass("live").each(function() {
ids.push(this.getAttribute("data-live"));
});
if (ids.length > 0) {
lichess.socket.send("startWatching", ids.join(" "));
@ -1396,6 +1396,7 @@ var storage = {
if (!lichess.StrongSocket.available) return;
var socketUrl = $wrap.data('socket-url');
var $nowPlaying = $('#now_playing');
var $timeline = $("#timeline");
var $newposts = $("div.new_posts");
var $canvas = $wrap.find('.canvas');
@ -1590,6 +1591,18 @@ var storage = {
}, Math.round(it * interv));
});
}
},
// override fen event to reload playing games list
fen: function(e) {
lichess.StrongSocket.defaults.events.fen(e);
if ($nowPlaying.find('.live_' + e.id).length) $.ajax({
url: $nowPlaying.data('href'),
success: function(html) {
$nowPlaying.html(html);
$('body').trigger('lichess.content_loaded');
$wrap.find('.tabs .now_playing').toggleClass('hilight', $nowPlaying.find('.my_turn').length);
}
});
}
},
options: {

View File

@ -32,7 +32,7 @@ lichess.StrongSocket.sri = Math.random().toString(36).substring(2);
lichess.StrongSocket.defaults = {
events: {
fen: function(e) {
$('a.live_' + e.id).each(function() {
$('.live_' + e.id).each(function() {
parseFen($(this).data("fen", e.fen).data("lastmove", e.lm));
});
}

View File

@ -188,14 +188,16 @@ body.dark div.table .loader:before,
body.dark div.table .loader:after {
background-color: #262626;
}
body.dark #hooks_list table td {
body.dark #hooks_list table td,
body.dark #now_playing > a {
background: rgba(40, 40, 40, 0.6);
border-color: #242424;
}
body.dark #hooks_list table tr.cancel td {
background: rgba(0, 80, 0, 0.7);
}
body.dark #hooks_list table tr:hover td {
body.dark #hooks_list table tr:hover td,
body.dark #now_playing > a:hover {
background: rgba(27, 51, 68, 0.7);
}
body.dark #hook_filter {

View File

@ -623,6 +623,7 @@ div.game_config div.color_submits button.random span {
}
#now_playing {
margin: 5px 0 0 5px;
overflow: hidden;
}
#now_playing > a {
float: left;
@ -630,21 +631,18 @@ div.game_config div.color_submits button.random span {
text-decoration: none;
text-align: center;
transition: background-color 0.13s;
background: rgba(255, 255, 255, 0.6);
}
#now_playing > a:hover {
margin: -5px;
padding: 10px;
background: rgba(191, 231, 255, 0.7);
}
#now_playing .meta {
display: block;
text-align: center;
background: rgba(255, 255, 255, 0.6);
width: 157px;
overflow: hidden;
}
#now_playing .indicator {
font-weight: bold;
color: #d85000;
margin-top: -3px;
display: block;
@ -652,7 +650,6 @@ div.game_config div.color_submits button.random span {
#now_playing .mini_board .cg-board-wrap {
width: 157px;
height: 157px;
box-shadow: 0 0 3px #888;
}
body.is3d #now_playing .mini_board .cg-board-wrap {
margin-top: 5.6px;