better simul names, let host cancel simul
parent
a814cca594
commit
31a46b136b
|
@ -54,6 +54,13 @@ object Simul extends LilaController {
|
|||
}
|
||||
}
|
||||
|
||||
def abort(simulId: String) = Open { implicit ctx =>
|
||||
AsHost(simulId) { simul =>
|
||||
env.api abort simul.id
|
||||
Ok(Json.obj("ok" -> true)) as JSON
|
||||
}
|
||||
}
|
||||
|
||||
def accept(simulId: String, userId: String) = Open { implicit ctx =>
|
||||
AsHost(simulId) { simul =>
|
||||
env.api.accept(simul.id, userId, true)
|
||||
|
@ -68,13 +75,10 @@ object Simul extends LilaController {
|
|||
}
|
||||
}
|
||||
|
||||
private def newForm(me: lila.user.User) =
|
||||
env.forms.create(s"${me.username}'s simul")
|
||||
|
||||
def form = Auth { implicit ctx =>
|
||||
me =>
|
||||
NoEngine {
|
||||
Ok(html.simul.form(newForm(me), env.forms)).fuccess
|
||||
Ok(html.simul.form(env.forms.create, env.forms)).fuccess
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -82,7 +86,7 @@ object Simul extends LilaController {
|
|||
implicit me =>
|
||||
NoEngine {
|
||||
implicit val req = ctx.body
|
||||
newForm(me).bindFromRequest.fold(
|
||||
env.forms.create.bindFromRequest.fold(
|
||||
err => BadRequest(html.simul.form(err, env.forms)).fuccess,
|
||||
setup => env.api.create(setup, me) map { simul =>
|
||||
Redirect(routes.Simul.show(simul.id))
|
||||
|
|
|
@ -31,13 +31,6 @@ title = "New simul") {
|
|||
<th><label for="@form("clockExtra").id">Host extra clock time</label></th>
|
||||
<td>@base.select(form("clockExtra"), config.clockExtraChoices)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><label for="@form("name").id">Name</label></th>
|
||||
<td>
|
||||
@base.input(form("name"))
|
||||
@errMsg(form("name"))
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th></th>
|
||||
<td>
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
@simTd(sim: lila.simul.Simul) = {
|
||||
<td class="header">
|
||||
<a href="@routes.Simul.show(sim.id)">
|
||||
<span class="name">@sim.name</span>
|
||||
<span class="name">@sim.fullName</span>
|
||||
@setup(sim)
|
||||
</a>
|
||||
</td>
|
||||
|
|
|
@ -3,5 +3,6 @@
|
|||
trans.finished,
|
||||
trans.withdraw,
|
||||
trans.join,
|
||||
trans.cancel,
|
||||
trans.joinTheGame
|
||||
)))
|
||||
|
|
|
@ -133,9 +133,10 @@ POST /simul/new controllers.Simul.create
|
|||
GET /simul/reload controllers.Simul.homeReload
|
||||
GET /simul/$id<\w{8}> controllers.Simul.show(id: String)
|
||||
GET /simul/$id<\w{8}>/socket/v:apiVersion controllers.Simul.websocket(id: String, apiVersion: Int)
|
||||
POST /simul/$id<\w{8}>/accept/:user controllers.Simul.accept(id: String, user: String)
|
||||
POST /simul/$id<\w{8}>/reject/:user controllers.Simul.reject(id: String, user: String)
|
||||
POST /simul/$id<\w{8}>/start controllers.Simul.start(id: String)
|
||||
POST /simul/$id<\w{8}>/accept/:user controllers.Simul.accept(id: String, user: String)
|
||||
POST /simul/$id<\w{8}>/reject/:user controllers.Simul.reject(id: String, user: String)
|
||||
POST /simul/$id<\w{8}>/start controllers.Simul.start(id: String)
|
||||
POST /simul/$id<\w{8}>/abort controllers.Simul.abort(id: String)
|
||||
POST /simul/$id<\w{8}>/join/:variant controllers.Simul.join(id: String, variant: String)
|
||||
POST /simul/$id<\w{8}>/withdraw controllers.Simul.withdraw(id: String)
|
||||
|
||||
|
|
|
@ -22,9 +22,7 @@ final class DataForm {
|
|||
val clockExtraChoices = options(clockExtras, "%d minute{s}")
|
||||
val clockExtraDefault = 0
|
||||
|
||||
def create(defaultName: String) = Form(mapping(
|
||||
"name" -> text(minLength = 4)
|
||||
.verifying("This name is not acceptable", n => !LameName(n)),
|
||||
def create = Form(mapping(
|
||||
"clockTime" -> numberIn(clockTimeChoices),
|
||||
"clockIncrement" -> numberIn(clockIncrementChoices),
|
||||
"clockExtra" -> numberIn(clockExtraChoices),
|
||||
|
@ -34,7 +32,6 @@ final class DataForm {
|
|||
}.verifying("At least one variant", _.nonEmpty)
|
||||
)(SimulSetup.apply)(SimulSetup.unapply)
|
||||
) fill SimulSetup(
|
||||
name = defaultName,
|
||||
clockTime = clockTimeDefault,
|
||||
clockIncrement = clockIncrementDefault,
|
||||
clockExtra = clockExtraDefault,
|
||||
|
@ -42,7 +39,6 @@ final class DataForm {
|
|||
}
|
||||
|
||||
case class SimulSetup(
|
||||
name: String,
|
||||
clockTime: Int,
|
||||
clockIncrement: Int,
|
||||
clockExtra: Int,
|
||||
|
|
|
@ -23,6 +23,7 @@ final class JsonView(
|
|||
"rating" -> simul.hostRating)
|
||||
},
|
||||
"name" -> simul.name,
|
||||
"fullName" -> simul.fullName,
|
||||
"variants" -> simul.variants.map(variantJson(chess.Speed(simul.clock.chessClock.some))),
|
||||
"applicants" -> simul.applicants.sortBy(-_.player.rating).map(applicantJson),
|
||||
"pairings" -> simul.pairings.sortBy(-_.player.rating).map(pairingJson(games)),
|
||||
|
|
|
@ -21,6 +21,8 @@ case class Simul(
|
|||
|
||||
def id = _id
|
||||
|
||||
def fullName = s"$name simul"
|
||||
|
||||
def isCreated = !isStarted
|
||||
|
||||
def isStarted = startedAt.isDefined
|
||||
|
@ -102,12 +104,11 @@ object Simul {
|
|||
type ID = String
|
||||
|
||||
def make(
|
||||
name: String,
|
||||
host: User,
|
||||
clock: SimulClock,
|
||||
variants: List[Variant]): Simul = Simul(
|
||||
_id = Random nextStringUppercase 8,
|
||||
name = name,
|
||||
name = RandomName(),
|
||||
status = SimulStatus.Created,
|
||||
clock = clock,
|
||||
hostId = host.id,
|
||||
|
|
|
@ -33,7 +33,6 @@ private[simul] final class SimulApi(
|
|||
|
||||
def create(setup: SimulSetup, me: User): Fu[Simul] = {
|
||||
val simul = Simul.make(
|
||||
name = setup.name,
|
||||
clock = SimulClock(
|
||||
limit = setup.clockTime * 60,
|
||||
increment = setup.clockIncrement,
|
||||
|
@ -83,6 +82,16 @@ private[simul] final class SimulApi(
|
|||
}
|
||||
}
|
||||
|
||||
def abort(simulId: Simul.ID) {
|
||||
Sequence(simulId) {
|
||||
repo.findCreated(simulId) flatMap {
|
||||
_ ?? { simul =>
|
||||
(repo remove simul) >>- sendTo(simul.id, actorApi.Aborted) >>- publish()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def finishGame(game: Game) {
|
||||
game.simulId foreach { simulId =>
|
||||
Sequence(simulId) {
|
||||
|
|
|
@ -72,6 +72,9 @@ private[simul] final class SimulRepo(simulColl: Coll) {
|
|||
def update(simul: Simul) =
|
||||
simulColl.update(BSONDocument("_id" -> simul.id), simul).void
|
||||
|
||||
def remove(simul: Simul) =
|
||||
simulColl.remove(BSONDocument("_id" -> simul.id)).void
|
||||
|
||||
def cleanup =
|
||||
simulColl.remove(
|
||||
createdSelect ++ BSONDocument(
|
||||
|
|
|
@ -35,11 +35,13 @@ private[simul] final class Socket(
|
|||
|
||||
def receiveSpecific = {
|
||||
|
||||
case StartGame(game) => redirectPlayer(game, chess.Black)
|
||||
case StartGame(game) => redirectPlayer(game, chess.Black)
|
||||
|
||||
case StartSimul(firstGame) => redirectPlayer(firstGame, chess.White)
|
||||
|
||||
case Reload => notifyReload
|
||||
case Reload => notifyReload
|
||||
|
||||
case Aborted => notifyVersion("aborted", Json.obj(), Messadata())
|
||||
|
||||
case PingVersion(uid, v) => {
|
||||
ping(uid)
|
||||
|
|
|
@ -27,6 +27,7 @@ private[simul] case class Talk(tourId: String, u: String, t: String, troll: Bool
|
|||
private[simul] case class StartGame(game: Game)
|
||||
private[simul] case class StartSimul(firstGame: Game)
|
||||
private[simul] case object Reload
|
||||
private[simul] case object Aborted
|
||||
private[simul] case class Connected(enumerator: JsEnumerator, member: Member)
|
||||
|
||||
private[simul] case object NotifyCrowd
|
||||
|
|
|
@ -2,4 +2,13 @@ package lila
|
|||
|
||||
import lila.socket.WithSocket
|
||||
|
||||
package object simul extends PackageObject with WithPlay with WithSocket
|
||||
package object simul extends PackageObject with WithPlay with WithSocket {
|
||||
|
||||
private[simul] object RandomName {
|
||||
|
||||
private val names = IndexedSeq("Actinium", "Aluminium", "Americium", "Antimony", "Argon", "Arsenic", "Astatine", "Barium", "Berkelium", "Beryllium", "Bismuth", "Bohrium", "Boron", "Bromine", "Cadmium", "Caesium", "Calcium", "Californium", "Carbon", "Cerium", "Chlorine", "Chromium", "Cobalt", "Copernicium", "Copper", "Curium", "Darmstadtium", "Dubnium", "Dysprosium", "Einsteinium", "Erbium", "Europium", "Fermium", "Flerovium", "Fluorine", "Francium", "Gadolinium", "Gallium", "Germanium", "Gold", "Hafnium", "Hassium", "Helium", "Holmium", "Hydrogen", "Indium", "Iodine", "Iridium", "Iron", "Krypton", "Lanthanum", "Lawrencium", "Lead", "Lithium", "Livermorium", "Lutetium", "Magnesium", "Manganese", "Meitnerium", "Mendelevium", "Mercury", "Molybdenum", "Neodymium", "Neon", "Neptunium", "Nickel", "Niobium", "Nitrogen", "Nobelium", "Osmium", "Oxygen", "Palladium", "Phosphorus", "Platinum", "Plutonium", "Polonium", "Potassium", "Praseodymium", "Promethium", "Protactinium", "Radium", "Radon", "Rhenium", "Rhodium", "Roentgenium", "Rubidium", "Ruthenium", "Rutherfordium", "Samarium", "Scandium", "Seaborgium", "Selenium", "Silicon", "Silver", "Sodium", "Strontium", "Sulfur", "Tantalum", "Technetium", "Tellurium", "Terbium", "Thallium", "Thorium", "Thulium", "Titanium", "Tungsten", "Ununoctium", "Ununpentium", "Ununseptium", "Ununtrium", "Uranium", "Vanadium", "Xenon", "Ytterbium", "Yttrium", "Zinc")
|
||||
private val size = names.size
|
||||
|
||||
def apply(): String = names(scala.util.Random nextInt size)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,9 @@ module.exports = function(send, ctrl) {
|
|||
reload: function(data) {
|
||||
ctrl.reload(data);
|
||||
m.redraw();
|
||||
},
|
||||
aborted: function() {
|
||||
location.reload();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -25,7 +25,12 @@ module.exports = function(ctrl) {
|
|||
m('a.button.top_right.text.active', {
|
||||
'data-icon': 'G',
|
||||
onclick: partial(xhr.start, ctrl)
|
||||
}, 'Start') : null
|
||||
}, 'Start') : m('a.button.top_right.text', {
|
||||
'data-icon': 'L',
|
||||
onclick: function() {
|
||||
if (confirm('Delete this simul?')) xhr.abort(ctrl);
|
||||
}
|
||||
}, ctrl.trans('cancel'))
|
||||
) : (
|
||||
simul.containsMe(ctrl) ? m('a.button.top_right', {
|
||||
onclick: partial(xhr.withdraw, ctrl)
|
||||
|
@ -45,7 +50,7 @@ module.exports = function(ctrl) {
|
|||
},
|
||||
ctrl.trans('join'))
|
||||
)) : null,
|
||||
m('h1.text[data-icon=|]', ctrl.data.name),
|
||||
util.title(ctrl),
|
||||
simul.acceptedContainsMe(ctrl) ? m('div.instructions',
|
||||
'You have been selected! Hold still, the simul is about to begin.'
|
||||
) : (
|
||||
|
|
|
@ -8,7 +8,7 @@ module.exports = {
|
|||
}, time.fromNow());
|
||||
},
|
||||
title: function(ctrl) {
|
||||
return m('h1.text[data-icon=|]', ctrl.data.name);
|
||||
return m('h1.text[data-icon=|]', ctrl.data.fullName);
|
||||
},
|
||||
player: function(p) {
|
||||
return {
|
||||
|
|
|
@ -19,6 +19,7 @@ function simulAction(action, ctrl) {
|
|||
|
||||
module.exports = {
|
||||
start: partial(simulAction, 'start'),
|
||||
abort: partial(simulAction, 'abort'),
|
||||
join: function(variantKey) {
|
||||
return partial(simulAction, 'join/' + variantKey);
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue