configure clock tenths of seconds in user preferences
This commit is contained in:
parent
fa4b11f0a1
commit
5f65df4620
|
@ -20,6 +20,9 @@
|
|||
<p class="help">Automatic promotion or manual choice?</p>
|
||||
</li>
|
||||
<li>
|
||||
@base.checkbox(form("clockTenths"), "Chess clock: show tenths of seconds", 1)
|
||||
<p class="help">Only visible under 10 seconds.</p>
|
||||
<li>
|
||||
<input type="submit" class="submit button" value="@trans.apply()" />
|
||||
</li>
|
||||
</ul>
|
||||
|
|
|
@ -8,20 +8,24 @@ import lila.user.User
|
|||
private[pref] final class DataForm(api: PrefApi) {
|
||||
|
||||
val pref = Form(mapping(
|
||||
"autoQueen" -> number.verifying(Pref.AutoQueen.choices.toMap contains _)
|
||||
"autoQueen" -> number.verifying(Pref.AutoQueen.choices.toMap contains _),
|
||||
"clockTenths" -> optional(number)
|
||||
)(PrefData.apply)(PrefData.unapply))
|
||||
|
||||
case class PrefData(
|
||||
autoQueen: Int) {
|
||||
autoQueen: Int,
|
||||
clockTenths: Option[Int]) {
|
||||
|
||||
def apply(pref: Pref) = pref.copy(
|
||||
autoQueen = autoQueen)
|
||||
autoQueen = autoQueen,
|
||||
clockTenths = clockTenths.isDefined)
|
||||
}
|
||||
|
||||
object PrefData {
|
||||
|
||||
def apply(pref: Pref): PrefData = PrefData(
|
||||
autoQueen = pref.autoQueen)
|
||||
autoQueen = pref.autoQueen,
|
||||
clockTenths = pref.clockTenths option 1)
|
||||
}
|
||||
|
||||
def prefOf(user: User): Fu[Form[PrefData]] = api getPref user map { p ⇒
|
||||
|
|
|
@ -6,18 +6,12 @@ case class Pref(
|
|||
id: String, // user id
|
||||
dark: Boolean,
|
||||
theme: String,
|
||||
autoQueen: Int) {
|
||||
autoQueen: Int,
|
||||
clockTenths: Boolean) {
|
||||
|
||||
def realTheme = Theme(theme)
|
||||
def toggleDark = copy(dark = !dark)
|
||||
|
||||
def get(name: String): Option[String] = name match {
|
||||
case "dark" ⇒ dark.toString.some
|
||||
case "theme" ⇒ theme.some
|
||||
case _ ⇒ none
|
||||
}
|
||||
def set(name: String, value: String): Option[Pref] = name match {
|
||||
case "dark" ⇒ Pref.booleans get value map { b ⇒ copy(dark = b) }
|
||||
case "bg" ⇒ Pref.bgs get value map { b ⇒ copy(dark = b) }
|
||||
case "theme" ⇒ Theme.allByName get value map { t ⇒ copy(theme = t.name) }
|
||||
case _ ⇒ none
|
||||
|
@ -41,7 +35,8 @@ object Pref {
|
|||
id = id,
|
||||
dark = false,
|
||||
theme = Theme.default.name,
|
||||
autoQueen = AutoQueen.PREMOVE)
|
||||
autoQueen = AutoQueen.PREMOVE,
|
||||
clockTenths = true)
|
||||
|
||||
val default = create("")
|
||||
|
||||
|
@ -60,5 +55,6 @@ object Pref {
|
|||
private def defaults = Json.obj(
|
||||
"dark" -> default.dark,
|
||||
"theme" -> default.theme,
|
||||
"autoQueen" -> default.autoQueen)
|
||||
"autoQueen" -> default.autoQueen,
|
||||
"clockTenths" -> true)
|
||||
}
|
||||
|
|
|
@ -11,9 +11,6 @@ final class PrefApi {
|
|||
|
||||
def getPref[A](user: User, pref: Pref ⇒ A): Fu[A] = getPref(user) map pref
|
||||
|
||||
def getPrefString(user: User, name: String): Fu[Option[String]] =
|
||||
getPref(user) map (_ get name)
|
||||
|
||||
def setPref(pref: Pref): Funit = $save(pref)
|
||||
|
||||
def setPref(user: User, change: Pref ⇒ Pref): Funit =
|
||||
|
|
|
@ -5,15 +5,9 @@ import lila.user.Context
|
|||
|
||||
trait PrefHelper {
|
||||
|
||||
private def get(name: String)(implicit ctx: Context): Option[String] =
|
||||
ctx.req.session get name orElse {
|
||||
ctx.me ?? { env.api.getPrefString(_, name) }
|
||||
}.await
|
||||
def currentTheme(implicit ctx: Context) = userPref.realTheme
|
||||
|
||||
def currentTheme(implicit ctx: Context): Theme = Theme(~get("theme"))
|
||||
|
||||
def currentBg(implicit ctx: Context): String =
|
||||
if (get("dark") == Some("true")) "dark" else "light"
|
||||
def currentBg(implicit ctx: Context) = userPref.dark.fold("dark", "light")
|
||||
|
||||
def userPref(implicit ctx: Context): Pref = {
|
||||
ctx.me.fold(fuccess(Pref.default))(env.api.getPref)
|
||||
|
|
|
@ -17,6 +17,7 @@ trait RoundHelper { self: PrefHelper ⇒
|
|||
|
||||
def roundPlayerJsData(pov: Pov, version: Int)(implicit ctx: Context) = {
|
||||
import pov._
|
||||
val pref = userPref
|
||||
Json.obj(
|
||||
"game" -> Json.obj(
|
||||
"id" -> gameId,
|
||||
|
@ -39,13 +40,15 @@ trait RoundHelper { self: PrefHelper ⇒
|
|||
),
|
||||
"possible_moves" -> possibleMoves(pov),
|
||||
"animation_delay" -> animationDelay(pov),
|
||||
"autoQueen" -> userPref.autoQueen,
|
||||
"autoQueen" -> pref.autoQueen,
|
||||
"clockTenths" -> pref.clockTenths,
|
||||
"tournament_id" -> game.tournamentId
|
||||
)
|
||||
}
|
||||
|
||||
def roundWatcherJsData(pov: Pov, version: Int, tv: Boolean) = {
|
||||
def roundWatcherJsData(pov: Pov, version: Int, tv: Boolean)(implicit ctx: Context) = {
|
||||
import pov._
|
||||
val pref = userPref
|
||||
Json.obj(
|
||||
"game" -> Json.obj(
|
||||
"id" -> gameId,
|
||||
|
@ -68,6 +71,7 @@ trait RoundHelper { self: PrefHelper ⇒
|
|||
),
|
||||
"possible_moves" -> possibleMoves(pov),
|
||||
"animation_delay" -> animationDelay(pov),
|
||||
"clockTenths" -> pref.clockTenths,
|
||||
"tv" -> tv
|
||||
)
|
||||
}
|
||||
|
|
|
@ -799,7 +799,8 @@ var storage = {
|
|||
|
||||
$("div.game_tournament .clock").each(function() {
|
||||
$(this).clock({
|
||||
time: $(this).data("time")
|
||||
time: $(this).data("time"),
|
||||
showTenths: self.options.clockTenths
|
||||
}).clock("start");
|
||||
});
|
||||
|
||||
|
@ -1405,6 +1406,7 @@ var storage = {
|
|||
var self = this;
|
||||
self.$table.find('div.clock').each(function() {
|
||||
$(this).clock({
|
||||
showTenths: self.options.clockTenths,
|
||||
time: $(this).attr('data-time'),
|
||||
emerg: $(this).attr('data-emerg'),
|
||||
buzzer: function() {
|
||||
|
@ -1687,7 +1689,7 @@ var storage = {
|
|||
_formatDate: function(date) {
|
||||
minutes = this._prefixInteger(date.getUTCMinutes(), 2);
|
||||
seconds = this._prefixInteger(date.getSeconds(), 2);
|
||||
if (this.options.time < 10 * 1000) {
|
||||
if (this.options.showTenths && this.options.time < 10000) {
|
||||
tenths = Math.floor(date.getMilliseconds() / 100);
|
||||
return minutes + ':' + seconds + '<span>.' + tenths + '</span>';
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue