withdraw tournament from round

This commit is contained in:
Thibault Duplessis 2015-01-18 18:40:22 +01:00
parent ccfe527c32
commit c171f6f5b7
5 changed files with 18 additions and 12 deletions

View file

@ -7,6 +7,7 @@ import play.api.mvc._
import lila.api.Context
import lila.app._
import lila.game.{ Pov, GameRepo }
import lila.common.HTTPRequest
import lila.tournament.{ System, TournamentRepo, Created, Started, Finished, Tournament => Tourney }
import lila.user.UserRepo
import views._
@ -78,7 +79,8 @@ object Tournament extends LilaController {
me =>
OptionResult(repo byId id) { tour =>
env.api.withdraw(tour, me.id)
Ok(Json.obj("ok" -> true)) as JSON
if (HTTPRequest.isXhr(ctx.req)) Ok(Json.obj("ok" -> true)) as JSON
else Redirect(routes.Tournament.show(tour.id).url)
}
}

View file

@ -37,6 +37,7 @@ trans.playingRightNow,
trans.whiteIsVictorious,
trans.blackIsVictorious,
trans.backToTournament,
trans.withdraw,
trans.joinTheGame,
trans.playWithTheSameOpponentAgain,
trans.declineInvitation,

View file

@ -59,13 +59,10 @@ private[tournament] final class Organizer(
private def startPairing(tour: Started) {
if (!tour.isAlmostFinished) {
withUserIds(tour.id) { ids =>
(tour.activeUserIds intersect ids) |> { users =>
tour.system.pairingSystem.createPairings(tour, users) onSuccess {
case (pairings, events) =>
pairings.toNel foreach { pairings =>
api.makePairings(tour, pairings, events)
}
}
val users = tour.activeUserIds intersect ids
tour.system.pairingSystem.createPairings(tour, users) onSuccess {
case (pairings, events) =>
pairings.toNel foreach { api.makePairings(tour, _, events) }
}
}
}

View file

@ -203,7 +203,7 @@ case class Started(
((finishedAt.getMillis - nowMillis) / 1000).toFloat
)
def isAlmostFinished = remainingSeconds < math.max(60, math.min(clock.limit / 2, 120))
def isAlmostFinished = remainingSeconds < math.max(40, math.min(clock.limit / 2, 120))
def clockStatus = remainingSeconds.toInt |> { s =>
"%02d:%02d".format(s / 60, s % 60)

View file

@ -129,9 +129,15 @@ module.exports = {
];
},
backToTournament: function(ctrl) {
if (ctrl.data.tournament && ctrl.data.tournament.running) return m('a.text[data-icon=G].button.strong.glowing', {
href: '/tournament/' + ctrl.data.tournament.id
}, ctrl.trans('backToTournament'));
if (ctrl.data.tournament && ctrl.data.tournament.running) return [
m('a.text[data-icon=G].button.strong.glowing', {
href: '/tournament/' + ctrl.data.tournament.id
}, ctrl.trans('backToTournament')),
m('form', {
method: 'post',
action: '/tournament/' + ctrl.data.tournament.id + '/withdraw'
}, m('button.text.button[data-icon=b]', ctrl.trans('withdraw')))
];
},
viewTournament: function(ctrl) {
if (ctrl.data.tournament) return m('a.viewTournament.button', {