forked from lichess-org/lila
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
170 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
@(settings: List[lila.memo.SettingStore[_]])(implicit ctx: Context) | ||
|
||
@title = @{ "Settings" } | ||
|
||
@mod.layout(title = title, active = "setting") { | ||
|
||
<style type="text/css"> | ||
#settings form { | ||
margin-top: 10px; | ||
border-top: 1px solid rgba(120, 120, 120, 0.3); | ||
padding-top: 10px; | ||
} | ||
#settings form label p { | ||
width: 50%; | ||
text-align: right; | ||
display: inline-block; | ||
vertical-align: middle; | ||
margin-right: 10px; | ||
} | ||
</style> | ||
|
||
<div id="settings" class="content_box"> | ||
<h1 data-icon="%" class="text">@title</h1> | ||
<br /><br /> | ||
<p> | ||
Tread lightly. | ||
</p> | ||
@settings.map { s => | ||
<form action="@routes.Dev.settingsPost(s.id)" method="POST"> | ||
<label> | ||
<p>@s.text.getOrElse(s.id)</p> | ||
<input name="v" value="@s.get()" /> | ||
</label> | ||
<button type="submit" class="submit button text" data-icon="E"></button> | ||
</form> | ||
} | ||
</div> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package lila.memo | ||
|
||
import lila.db.dsl._ | ||
import play.api.data._, Forms._ | ||
|
||
final class SettingStore[A: BSONValueHandler: SettingStore.StringReader] private ( | ||
coll: Coll, | ||
val id: String, | ||
val default: A, | ||
val text: Option[String] | ||
) { | ||
|
||
import SettingStore.dbField | ||
|
||
private var value: A = default | ||
|
||
def get(): A = value | ||
|
||
def set(v: A): Funit = { | ||
value = v | ||
coll.updateField(dbId, dbField, v).void | ||
} | ||
|
||
def form: Option[Form[_]] = SettingStore formOf this | ||
|
||
def setString(str: String): Funit = (implicitly[SettingStore.StringReader[A]] read str) ?? set | ||
|
||
override def toString = s"SettingStore(id: $id, default: $default, value: $value)" | ||
|
||
private val dbId = $id(id) | ||
|
||
coll.primitiveOne[A](dbId, dbField) map2 { (v: A) => | ||
value = v | ||
} | ||
} | ||
|
||
object SettingStore { | ||
|
||
final class Builder(coll: Coll) { | ||
def apply[A: BSONValueHandler: StringReader]( | ||
id: String, | ||
default: A, | ||
text: Option[String] = None | ||
) = new SettingStore[A](coll, id, default, text) | ||
} | ||
|
||
private final class StringReader[A](val read: String => Option[A]) | ||
|
||
private object StringReader { | ||
implicit val booleanReader = new StringReader[Boolean](v => | ||
if (Set("on", "yes", "true", "1")(v)) true.some | ||
else if (Set("off", "no", "false", "0")(v)) false.some | ||
else none) | ||
implicit val intReader = new StringReader[Int](parseIntOption) | ||
implicit val stringReader = new StringReader[String](some) | ||
} | ||
|
||
def formOf(s: SettingStore[_]): Option[Form[_]] = s.value match { | ||
case v: Boolean => Form(single("v" -> boolean)) fill v some | ||
case v: Int => Form(single("v" -> number)) fill v some | ||
case v: String => Form(single("v" -> text)) fill v some | ||
case _ => none | ||
} | ||
|
||
private val dbField = "setting" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.