fix tourney creation form for web/mobile/oauth
parent
d67aaa0996
commit
c4404dc5e0
|
@ -3,6 +3,7 @@ package controllers
|
|||
import lila.api._
|
||||
import lila.socket.Socket.Uid
|
||||
import lila.user.UserContext
|
||||
import lila.common.Form.trueish
|
||||
|
||||
import play.api.mvc.RequestHeader
|
||||
|
||||
|
@ -39,6 +40,4 @@ trait RequestGetter {
|
|||
|
||||
protected def getBoolOpt(name: String, req: RequestHeader) =
|
||||
(getInt(name, req) map (trueish)) orElse (get(name, req) map trueish)
|
||||
|
||||
private def trueish(v: Any) = v == 1 || v == "true"
|
||||
}
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
|
||||
<label>
|
||||
@text
|
||||
<input type="checkbox" id="@field.id" name="@field.name" value="@value" @((field.value == Some(value.toString)).fold("checked", "")) />
|
||||
<input type="checkbox" id="@field.id" name="@field.name" value="@value" @if(field.value.has(value.toString)){"checked"} />
|
||||
</label>
|
||||
|
|
|
@ -26,7 +26,7 @@ moreJs = moreJs) {
|
|||
<tbody>
|
||||
<tr>
|
||||
<th><label for="isprivate">@trans.isPrivate()</label></th>
|
||||
<td><input type="checkbox" name="private" id="isprivate" @if(form("private").value.isDefined) { checked } /></td>
|
||||
<td><input type="checkbox" name="private" id="isprivate" @if(form("private").value.exists(lila.common.Form.trueish)) { checked } /></td>
|
||||
</tr>
|
||||
<tr class="password">
|
||||
<th><label for="@form("password").id">@trans.password()</label></th>
|
||||
|
|
|
@ -496,7 +496,7 @@ GET /api/game/:id controllers.Api.game(id: String)
|
|||
GET /api/games/team/:teamId controllers.Api.gamesVsTeam(teamId: String)
|
||||
GET /api/tournament controllers.Api.currentTournaments
|
||||
GET /api/tournament/:id controllers.Api.tournament(id: String)
|
||||
POST /api/tournament/new controllers.Tournament.apiCreate
|
||||
POST /api/tournament controllers.Tournament.apiCreate
|
||||
GET /api/status controllers.Api.status
|
||||
GET /api/socket controllers.Main.apiWebsocket
|
||||
GET /api/users/status controllers.Api.usersStatus
|
||||
|
|
|
@ -32,9 +32,13 @@ object Form {
|
|||
def stringIn(choices: Iterable[(String, String)]) =
|
||||
text.verifying(hasKey(choices, _))
|
||||
|
||||
def tolerantBoolean = of[Boolean](formatter.tolerantBooleanFormatter)
|
||||
|
||||
def hasKey[A](choices: Iterable[(A, _)], key: A) =
|
||||
choices.map(_._1).toList contains key
|
||||
|
||||
def trueish(v: Any) = v == 1 || v == "1" || v == "true" || v == "on" || v == "yes"
|
||||
|
||||
private def pluralize(pattern: String, nb: Int) =
|
||||
pattern.replace("{s}", (nb != 1).fold("s", ""))
|
||||
|
||||
|
@ -47,6 +51,14 @@ object Form {
|
|||
def bind(key: String, data: Map[String, String]) = intFormat.bind(key, data).right map to
|
||||
def unbind(key: String, value: A) = intFormat.unbind(key, from(value))
|
||||
}
|
||||
val tolerantBooleanFormatter: Formatter[Boolean] = new Formatter[Boolean] {
|
||||
override val format = Some(("format.boolean", Nil))
|
||||
def bind(key: String, data: Map[String, String]) =
|
||||
Right(data.get(key).getOrElse("false")).right.flatMap { v =>
|
||||
Right(trueish(v))
|
||||
}
|
||||
def unbind(key: String, value: Boolean) = Map(key -> value.toString)
|
||||
}
|
||||
}
|
||||
|
||||
object UTCDate {
|
||||
|
|
|
@ -21,7 +21,7 @@ final class DataForm {
|
|||
waitMinutes = waitMinuteDefault,
|
||||
variant = chess.variant.Standard.key,
|
||||
position = StartingPosition.initial.fen,
|
||||
`private` = None,
|
||||
`private` = false,
|
||||
password = None,
|
||||
mode = Mode.Rated.id.some,
|
||||
conditionsOption = Condition.DataForm.AllSetup.default.some,
|
||||
|
@ -46,7 +46,7 @@ final class DataForm {
|
|||
"variant" -> nonEmptyText.verifying(v => guessVariant(v).isDefined),
|
||||
"position" -> nonEmptyText,
|
||||
"mode" -> optional(number.verifying(Mode.all map (_.id) contains _)),
|
||||
"private" -> optional(text.verifying("on" == _)),
|
||||
"private" -> tolerantBoolean,
|
||||
"password" -> optional(nonEmptyText),
|
||||
"conditions" -> optional(Condition.DataForm.all),
|
||||
"berserkable" -> boolean
|
||||
|
@ -117,7 +117,7 @@ private[tournament] case class TournamentSetup(
|
|||
variant: String,
|
||||
position: String,
|
||||
mode: Option[Int],
|
||||
`private`: Option[String],
|
||||
`private`: Boolean,
|
||||
password: Option[String],
|
||||
conditionsOption: Option[Condition.DataForm.AllSetup],
|
||||
berserkable: Boolean
|
||||
|
@ -129,7 +129,7 @@ private[tournament] case class TournamentSetup(
|
|||
|
||||
def validTiming = (minutes * 60) >= (3 * estimatedGameDuration)
|
||||
|
||||
def validPublic = isPrivate || {
|
||||
def validPublic = `private` || {
|
||||
DataForm.clockTimes.contains(clockTime) &&
|
||||
DataForm.clockIncrements.contains(clockIncrement) &&
|
||||
DataForm.minutes.contains(minutes)
|
||||
|
@ -145,7 +145,5 @@ private[tournament] case class TournamentSetup(
|
|||
realMode == Mode.Casual ||
|
||||
lila.game.Game.allowRated(realVariant, clockConfig)
|
||||
|
||||
def isPrivate = `private`.isDefined
|
||||
|
||||
private def estimatedGameDuration = 60 * clockTime + 30 * clockIncrement
|
||||
}
|
||||
|
|
|
@ -52,8 +52,8 @@ final class TournamentApi(
|
|||
minutes = setup.minutes,
|
||||
waitMinutes = setup.waitMinutes,
|
||||
mode = setup.realMode,
|
||||
`private` = setup.isPrivate,
|
||||
password = setup.password.ifTrue(setup.isPrivate),
|
||||
`private` = setup.`private`,
|
||||
password = setup.password ifTrue setup.`private`,
|
||||
system = System.Arena,
|
||||
variant = setup.realVariant,
|
||||
position = DataForm.startingPosition(setup.position, setup.realVariant),
|
||||
|
|
Loading…
Reference in New Issue