Skip to content

Commit

Permalink
remind players about running tournament
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Oct 26, 2012
1 parent bd7ffe3 commit 02686fc
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 76 deletions.
3 changes: 2 additions & 1 deletion app/round/RoundHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ trait RoundHelper { self: ConfigHelper ⇒
"ai" -> opponent.isAi
),
"possible_moves" -> possibleMoves(pov),
"animation_delay" -> animationDelay(pov)
"animation_delay" -> animationDelay(pov),
"tournament_id" -> game.tournamentId
)
}

Expand Down
2 changes: 1 addition & 1 deletion app/templating/AssetHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import play.api.templates.Html

trait AssetHelper {

val assetVersion = 9
val assetVersion = 10

def cssTag(name: String) = css("stylesheets/" + name)

Expand Down
5 changes: 2 additions & 3 deletions app/tournament/Organizer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ private[tournament] final class Organizer(
api: TournamentApi,
repo: TournamentRepo,
reminder: ActorRef,
register: ActorRef,
hubMaster: ActorRef) extends Actor {

implicit val timeout = Timeout(1 second)
Expand Down Expand Up @@ -47,7 +46,7 @@ private[tournament] final class Organizer(

def createdTournament(tour: Created) {
if (tour.isEmpty) (api wipeEmpty tour).unsafePerformIO
else if (tour.readyToStart) api start tour map (_.unsafePerformIO) foreach { reminder ! _ }
else if (tour.readyToStart) api start tour map (_.unsafePerformIO)
else (hubMaster ? GetTournamentUsernames(tour.id)).mapTo[Iterable[String]] onSuccess {
case usernames (tour.userIds diff usernames.toList.map(_.toLowerCase)) |> { leavers
leavers.map(u api.withdraw(tour, u)).sequence.unsafePerformIO
Expand All @@ -58,7 +57,7 @@ private[tournament] final class Organizer(
def startedTournaments {
repo.started.unsafePerformIO ~ { tours
tours foreach startedTournament
register ! SetTournaments(tours)
reminder ! RemindTournaments(tours)
}
}

Expand Down
23 changes: 0 additions & 23 deletions app/tournament/Register.scala

This file was deleted.

10 changes: 7 additions & 3 deletions app/tournament/Reminder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ private[tournament] final class Reminder(hubNames: List[String]) extends Actor {
implicit val timeout = Timeout(1 second)

def receive = {
case tour: Started {
val msg = SendTos(tour.userIds.toSet, JsObject(Seq(

case RemindTournaments(tours) tours foreach { tour =>
val msg = SendTos(tour.activeUserIds.toSet, JsObject(Seq(
"t" -> JsString("tournamentReminder"),
"d" -> JsString(views.html.tournament.reminder(tour).toString)
"d" -> JsObject(Seq(
"id" -> JsString(tour.id),
"html" -> JsString(views.html.tournament.reminder(tour).toString)
))
)))
hubRefs foreach { _ ! msg }
}
Expand Down
4 changes: 2 additions & 2 deletions app/tournament/TournamentApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ private[tournament] final class TournamentApi(
_ lobbyReload
} yield created

def start(created: Created): Option[IO[Started]] = created.start map { started
def start(created: Created): Option[IO[Unit]] = created.start map { started
for {
_ repo saveIO started
_ socket reload started.id
_ reloadSiteSocket
_ lobbyReload
} yield started
} yield ()
}

def wipeEmpty(created: Created): IO[Unit] = (for {
Expand Down
3 changes: 0 additions & 3 deletions app/tournament/TournamentEnv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,12 @@ final class TournamentEnv(
repo = repo,
api = api,
reminder = reminder,
register = register,
hubMaster = hubMaster
)), name = ActorTournamentOrganizer)

lazy val reminder = Akka.system.actorOf(Props(new Reminder(List(
ActorLobbyHub, ActorSiteHub, ActorRoundHubMaster, ActorTournamentHubMaster
))), name = ActorTournamentReminder)

lazy val register = Akka.system.actorOf(Props(new Register), name = ActorTournamentRegister)

private lazy val joiner = new GameJoiner(
gameRepo = gameRepo,
Expand Down
3 changes: 1 addition & 2 deletions app/tournament/actorApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,4 @@ case class StartedTournament(tour: Started)
case object StartPairings
case class StartPairing(tour: Started)
case class GetTournamentUsernames(tournamentId: String)
case class GetUserTournament(userId: String)
case class SetTournaments(tours: List[Tournament])
case class RemindTournaments(tours: List[Started])
12 changes: 5 additions & 7 deletions app/views/base/layout.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
<div class="themes dropdown" data-href="@routes.Setting.set("theme")">
@themeList.map { theme =>
<div class="theme" data-theme="@theme.name"><div class="inner">
<div class="lcs black @theme.name"></div>
<div class="lcs white @theme.name"></div>
<div class="lcs black @theme.name"></div>
<div class="lcs white @theme.name"></div>
</div></div>
}
</div>
Expand All @@ -61,11 +61,9 @@
<span></span>
</a>
</div>
<div class="notifications">
<div id="tournament_reminder">
</div>
@ctx.me.map(notifications(_))
</div>
@ctx.me.map { me =>
<div class="notifications">@notifications(me)</div>
}
<div class="content">
<div class="header">
<h1>
Expand Down
4 changes: 3 additions & 1 deletion app/views/notification/view.scala.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
@(id: String, from: Option[String] = None)(html: Html)
@(id: String, from: Option[String] = None, closable: Boolean = true)(html: Html)

<div id="@id" class="notification">
@if(closable) {
<a class="close" href="@routes.Notification.remove(id)">X</a>
}
@from.map { user =>
@userIdLink(user, none)
}
Expand Down
10 changes: 3 additions & 7 deletions app/views/tournament/reminder.scala.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
@(tour: lila.tournament.Tournament)

@notification.view("tournament_reminder") {
@notification.view("tournament_reminder", closable = false) {
@linkTo(tour) in progress!
<form action="@routes.Tournament.join(tour.id)" method="POST">
<input type="submit" class="submit button" value="Join" />
</form>
<form action="@routes.Tournament.withdraw(tour.id)" method="POST">
<input type="submit" class="submit button strong" value="Withdraw" />
</form>
<a class="action withdraw" href="@routes.Tournament.withdraw(tour.id)">Withdraw</a>
<a class="action" href="@routes.Tournament.show(tour.id)">Join</a>
}
36 changes: 14 additions & 22 deletions public/javascripts/big.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,14 @@ var lichess = {
nbm: function(e) {
$('#nb_messages').text(e || "0").toggleClass("unread", e > 0);
},
notificationAdd: function(html) {
$('div.notifications').prepend(html);
},
notificationRemove: function(id) {
$('#' + id).remove();
},
tournamentReminder: function(html) {
$('#tournament_reminder').html(html).show();
tournamentReminder: function(data) {
if (!$('#tournament_reminder').length && $('body').data("tournament-id") != data.id) {
$('div.notifications').append(data.html).find("a.withdraw").click(function() {
$.post($(this).attr("href"));
$('#tournament_reminder').remove();
return false;
});
}
},
analysisAvailable: function() {
$("div.game_analysis.status").remove();
Expand Down Expand Up @@ -405,20 +405,6 @@ $(function() {
return false;
});

$("div.notifications").on("click", "div.notification a", function(e) {
var $a = $(this);
var $notif = $a.closest("div.notification");
var follow = !$a.hasClass("close");
$.ajax($notif.find("a.close").attr("href"), {
type: "delete",
success: function() {
if (follow) location.href = $a.attr("href");
}
});
$notif.remove();
return false;
});

$("form.request_analysis a").click(function() {
$(this).parent().submit();
});
Expand Down Expand Up @@ -525,6 +511,10 @@ $.widget("lichess.game", {
$(this).clock({time: $(this).data("time")}).clock("start");
});

if (self.options.tournament_id) {
$('body').data('tournament-id', self.options.tournament_id);
}

if (self.options.game.started) {
self.indicateTurn();
self.initSquaresAndPieces();
Expand Down Expand Up @@ -1714,6 +1704,8 @@ $(function() {
return;
}

$('body').data('tournament-id', _ld_.tournament.id);

var $chat = $("div.lichess_chat");
var $chatToggle = $chat.find('input.toggle_chat');
var chatExists = $chat.length > 0;
Expand Down
4 changes: 3 additions & 1 deletion public/stylesheets/common.css
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,8 @@ div.notifications > div a.close {
div.notifications > div a.close:hover {
font-weight: bold;
}
div.notifications > div form {
#tournament_reminder .action {
float: right;
display: block;
margin-left: 8px;
}

0 comments on commit 02686fc

Please sign in to comment.