Merge branch 'v2' of github.com:ornicar/lila into v2
* 'v2' of github.com:ornicar/lila: element option of startEmbeddedAnalyse is ignored more json cleanup, remove JsonHelperpull/5007/head^2
commit
2dc3b973ce
|
@ -9,7 +9,6 @@ import lila.app.ui.ScalatagsTemplate._
|
|||
object Environment
|
||||
extends lila.Lilaisms
|
||||
with StringHelper
|
||||
with JsonHelper
|
||||
with AssetHelper
|
||||
with DateHelper
|
||||
with NumberHelper
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
package lila.app
|
||||
package templating
|
||||
|
||||
import play.api.libs.json._
|
||||
import lila.app.ui.ScalatagsTemplate._
|
||||
|
||||
import lila.api.Context
|
||||
|
||||
trait JsonHelper {
|
||||
|
||||
def toJsonString[A: Writes](a: A): String = lila.common.String.html.safeJsonValue(Json toJson a)
|
||||
|
||||
def jsOrNull[A: Writes](a: Option[A]): String = a.fold("null")(x => toJsonString(x))
|
||||
|
||||
def jsUserIdString(implicit ctx: Context) = ctx.userId.fold("null")(id => s""""$id"""")
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package views.html.analyse
|
||||
|
||||
import play.api.libs.json.JsObject
|
||||
import play.api.libs.json.{ Json, JsObject }
|
||||
import play.api.mvc.RequestHeader
|
||||
|
||||
import lila.app.templating.Environment._
|
||||
|
@ -49,11 +49,13 @@ object embed {
|
|||
jsAt("compiled/trans.js"),
|
||||
jsAt("compiled/embed-analyse.js"),
|
||||
analyseTag,
|
||||
embedJsUnsafe(s"""lichess.startEmbeddedAnalyse({
|
||||
data: ${safeJsonValue(data)},
|
||||
embed: true,
|
||||
i18n: ${views.html.board.userAnalysisI18n(withCeval = false, withExplorer = false)}
|
||||
});""", config.nonce)
|
||||
embedJsUnsafe(s"""lichess.startEmbeddedAnalyse(${
|
||||
safeJsonValue(Json.obj(
|
||||
"data" -> data,
|
||||
"embed" -> true,
|
||||
"i18n" -> views.html.board.userAnalysisI18n(withCeval = false, withExplorer = false)
|
||||
))
|
||||
})""", config.nonce)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
|
|
@ -2,14 +2,11 @@ package views.html.analyse
|
|||
|
||||
import lila.api.Context
|
||||
import lila.app.templating.Environment._
|
||||
import lila.common.String.html.safeJsonValue
|
||||
import lila.i18n.{ I18nKeys => trans }
|
||||
|
||||
private object jsI18n {
|
||||
|
||||
def json()(implicit ctx: Context) = i18nJsObject(translations)
|
||||
|
||||
def apply()(implicit ctx: Context) = safeJsonValue(json)
|
||||
def apply()(implicit ctx: Context) = i18nJsObject(translations)
|
||||
|
||||
private val translations = List(
|
||||
trans.flipBoard,
|
||||
|
|
|
@ -58,7 +58,7 @@ object replay {
|
|||
embedJsUnsafe(s"""lichess=lichess||{};lichess.analyse=${
|
||||
safeJsonValue(Json.obj(
|
||||
"data" -> data,
|
||||
"i18n" -> jsI18n.json(),
|
||||
"i18n" -> jsI18n(),
|
||||
"userId" -> ctx.userId,
|
||||
"chat" -> chatJson,
|
||||
"explorer" -> Json.obj(
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package views.html.board
|
||||
|
||||
import play.api.libs.json.JsObject
|
||||
import play.api.libs.json.{ Json, JsObject }
|
||||
|
||||
import chess.variant.Crazyhouse
|
||||
|
||||
|
@ -25,11 +25,18 @@ object userAnalysis {
|
|||
moreJs = frag(
|
||||
analyseTag,
|
||||
analyseNvuiTag,
|
||||
embedJsUnsafe(s"""lichess=lichess||{};lichess.user_analysis={data:${safeJsonValue(data)},i18n:${
|
||||
userAnalysisI18n(
|
||||
withForecast = !pov.game.synthetic && pov.game.playable && ctx.me.flatMap(pov.game.player).isDefined
|
||||
)
|
||||
},explorer:{endpoint:"$explorerEndpoint",tablebaseEndpoint:"$tablebaseEndpoint"}};""")
|
||||
embedJsUnsafe(s"""lichess=lichess||{};lichess.user_analysis=${
|
||||
safeJsonValue(Json.obj(
|
||||
"data" -> data,
|
||||
"i18n" -> userAnalysisI18n(
|
||||
withForecast = !pov.game.synthetic && pov.game.playable && ctx.me.flatMap(pov.game.player).isDefined
|
||||
),
|
||||
"explorer" -> Json.obj(
|
||||
"endpoint" -> explorerEndpoint,
|
||||
"tablebaseEndpoint" -> tablebaseEndpoint
|
||||
)
|
||||
))
|
||||
}""")
|
||||
),
|
||||
chessground = false,
|
||||
openGraph = lila.app.ui.OpenGraph(
|
||||
|
|
|
@ -2,7 +2,6 @@ package views.html.board
|
|||
|
||||
import lila.api.Context
|
||||
import lila.app.templating.Environment._
|
||||
import lila.common.String.html.safeJsonValue
|
||||
import lila.common.Lang
|
||||
import lila.i18n.{ I18nKeys => trans }
|
||||
|
||||
|
@ -12,7 +11,7 @@ object userAnalysisI18n {
|
|||
withCeval: Boolean = true,
|
||||
withExplorer: Boolean = true,
|
||||
withForecast: Boolean = false
|
||||
)(implicit lang: Lang) = safeJsonValue(i18nJsObject(
|
||||
)(implicit lang: Lang) = i18nJsObject(
|
||||
baseTranslations ++ {
|
||||
withCeval ?? cevalTranslations
|
||||
} ++ {
|
||||
|
@ -20,7 +19,7 @@ object userAnalysisI18n {
|
|||
} ++ {
|
||||
withForecast ?? forecastTranslations
|
||||
}
|
||||
))
|
||||
)
|
||||
|
||||
private val baseTranslations = Vector(
|
||||
trans.analysis,
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package views.html.challenge
|
||||
|
||||
import play.api.libs.json.Json
|
||||
|
||||
import lila.api.Context
|
||||
import lila.app.templating.Environment._
|
||||
import lila.app.ui.ScalatagsTemplate._
|
||||
|
@ -13,12 +15,14 @@ object bits {
|
|||
def js(c: Challenge, json: play.api.libs.json.JsObject, owner: Boolean)(implicit ctx: Context) =
|
||||
frag(
|
||||
jsTag("challenge.js", defer = true),
|
||||
embedJsUnsafe(s"""lichess=window.lichess||{};customWs=true;lichess_challenge = {
|
||||
socketUrl: '${routes.Challenge.websocket(c.id, apiVersion.value)}',
|
||||
xhrUrl: '${routes.Challenge.show(c.id)}',
|
||||
owner: $owner,
|
||||
data: ${safeJsonValue(json)}
|
||||
};""")
|
||||
embedJsUnsafe(s"""lichess=window.lichess||{};customWs=true;lichess_challenge = ${
|
||||
safeJsonValue(Json.obj(
|
||||
"socketUrl" -> routes.Challenge.websocket(c.id, apiVersion.value).url,
|
||||
"xhrUrl" -> routes.Challenge.show(c.id).url,
|
||||
"owner" -> owner,
|
||||
"data" -> json
|
||||
))
|
||||
}""")
|
||||
)
|
||||
|
||||
def details(c: Challenge)(implicit ctx: Context) = div(cls := "details")(
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package views.html
|
||||
|
||||
import play.api.libs.json.Json
|
||||
|
||||
import lila.api.Context
|
||||
import lila.app.templating.Environment._
|
||||
import lila.app.ui.ScalatagsTemplate._
|
||||
|
@ -29,16 +31,23 @@ object insight {
|
|||
embedJsUnsafe(s"""
|
||||
$$(function() {
|
||||
lichess = lichess || {};
|
||||
lichess.insight = LichessInsight(document.getElementById('insight'), {
|
||||
ui: ${safeJsonValue(ui)},
|
||||
initialQuestion: ${safeJsonValue(question)},
|
||||
i18n: {},
|
||||
myUserId: $jsUserIdString,
|
||||
user: { id: "${u.id}", name: "${u.username}", nbGames: ${cache.count}, stale: ${stale}, shareId: ${prefId} },
|
||||
pageUrl: "${routes.Insight.index(u.username)}",
|
||||
postUrl: "${routes.Insight.json(u.username)}"
|
||||
});
|
||||
});""")
|
||||
lichess.insight = LichessInsight(document.getElementById('insight'), ${
|
||||
safeJsonValue(Json.obj(
|
||||
"ui" -> ui,
|
||||
"initialQuestion" -> question,
|
||||
"i18n" -> Json.obj(),
|
||||
"myUserId" -> ctx.userId,
|
||||
"user" -> Json.obj(
|
||||
"id" -> u.id,
|
||||
"name" -> u.username,
|
||||
"nbGames" -> cache.count,
|
||||
"stale" -> stale,
|
||||
"shareId" -> prefId
|
||||
),
|
||||
"pageUrl" -> routes.Insight.index(u.username).url,
|
||||
"postUrl" -> routes.Insight.json(u.username).url
|
||||
))
|
||||
})""")
|
||||
),
|
||||
moreCss = cssTag("insight")
|
||||
)(frag(
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package views.html.learn
|
||||
|
||||
import play.api.libs.json.JsObject
|
||||
import play.api.libs.json.Json
|
||||
|
||||
import lila.api.Context
|
||||
import lila.app.templating.Environment._
|
||||
|
@ -16,9 +16,12 @@ object index {
|
|||
moreJs = frag(
|
||||
jsAt(s"compiled/lichess.learn${isProd ?? (".min")}.js"),
|
||||
embedJsUnsafe(s"""$$(function() {
|
||||
LichessLearn(document.getElementById('learn-app'), {
|
||||
data: ${data.fold("null")(safeJsonValue)},
|
||||
i18n: ${safeJsonValue(i18nFullDbJsObject(lila.i18n.I18nDb.Learn))}});});""")
|
||||
LichessLearn(document.getElementById('learn-app'), ${
|
||||
safeJsonValue(Json.obj(
|
||||
"data" -> data,
|
||||
"i18n" -> i18nFullDbJsObject(lila.i18n.I18nDb.Learn)
|
||||
))
|
||||
})})""")
|
||||
),
|
||||
moreCss = cssTag("learn"),
|
||||
chessground = false,
|
||||
|
|
|
@ -34,11 +34,20 @@ object home {
|
|||
fullTitle = Some("lichess.org • " + trans.freeOnlineChess.txt()),
|
||||
moreJs = frag(
|
||||
jsAt(s"compiled/lichess.lobby${isProd ?? (".min")}.js", defer = true),
|
||||
embedJsUnsafe {
|
||||
val playbanJs = playban.fold("null")(pb => safeJsonValue(Json.obj("minutes" -> pb.mins, "remainingSeconds" -> (pb.remainingSeconds + 3))))
|
||||
val transJs = safeJsonValue(i18nJsObject(translations))
|
||||
s"""lichess=window.lichess||{};customWS=true;lichess_lobby={data:${safeJsonValue(data)},playban:$playbanJs,i18n:$transJs}"""
|
||||
}
|
||||
embedJsUnsafe(
|
||||
s"""lichess=window.lichess||{};customWS=true;lichess_lobby=${
|
||||
safeJsonValue(Json.obj(
|
||||
"data" -> data,
|
||||
"playban" -> playban.map { pb =>
|
||||
Json.obj(
|
||||
"minutes" -> pb.mins,
|
||||
"remainingSeconds" -> (pb.remainingSeconds + 3)
|
||||
)
|
||||
},
|
||||
"i18n" -> i18nJsObject(translations)
|
||||
))
|
||||
}"""
|
||||
)
|
||||
),
|
||||
moreCss = cssTag("lobby"),
|
||||
chessground = false,
|
||||
|
|
|
@ -4,7 +4,6 @@ package practice
|
|||
import lila.api.Context
|
||||
import lila.app.templating.Environment._
|
||||
import lila.app.ui.ScalatagsTemplate._
|
||||
import lila.common.String.html.safeJsonValue
|
||||
|
||||
import controllers.routes
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package views.html
|
||||
package practice
|
||||
|
||||
import play.api.libs.json.Json
|
||||
|
||||
import lila.api.Context
|
||||
import lila.app.templating.Environment._
|
||||
import lila.app.ui.ScalatagsTemplate._
|
||||
|
@ -19,15 +21,18 @@ object show {
|
|||
moreJs = frag(
|
||||
analyseTag,
|
||||
analyseNvuiTag,
|
||||
embedJsUnsafe(s"""lichess=window.lichess||{};lichess.practice={
|
||||
practice: ${safeJsonValue(data.practice)},
|
||||
study: ${safeJsonValue(data.study)},
|
||||
data: ${safeJsonValue(data.analysis)},
|
||||
i18n: ${board.userAnalysisI18n()},
|
||||
explorer: {
|
||||
endpoint: "$explorerEndpoint",
|
||||
tablebaseEndpoint: "$tablebaseEndpoint"
|
||||
}};""")
|
||||
embedJsUnsafe(s"""lichess=window.lichess||{};lichess.practice=${
|
||||
safeJsonValue(Json.obj(
|
||||
"practice" -> data.practice,
|
||||
"study" -> data.study,
|
||||
"data" -> data.analysis,
|
||||
"i18n" -> board.userAnalysisI18n(),
|
||||
"explorer" -> Json.obj(
|
||||
"endpoint" -> explorerEndpoint,
|
||||
"tablebaseEndpoint" -> tablebaseEndpoint
|
||||
)
|
||||
))
|
||||
}""")
|
||||
),
|
||||
chessground = false,
|
||||
zoomable = true
|
||||
|
|
|
@ -3,7 +3,6 @@ package html.puzzle
|
|||
|
||||
import lila.api.Context
|
||||
import lila.app.templating.Environment._
|
||||
import lila.common.String.html.safeJsonValue
|
||||
import lila.app.ui.ScalatagsTemplate._
|
||||
|
||||
import controllers.routes
|
||||
|
@ -20,7 +19,7 @@ object bits {
|
|||
dataLastmove := lastMove
|
||||
)(div(cls := "cg-board"))
|
||||
|
||||
def jsI18n(implicit ctx: Context) = safeJsonValue(i18nJsObject(translations))
|
||||
def jsI18n()(implicit ctx: Context) = i18nJsObject(translations)
|
||||
|
||||
private val translations = List(
|
||||
trans.training,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package views.html.puzzle
|
||||
|
||||
import play.api.libs.json.JsObject
|
||||
import play.api.libs.json.{ Json, JsObject }
|
||||
|
||||
import lila.api.Context
|
||||
import lila.app.templating.Environment._
|
||||
|
@ -20,7 +20,13 @@ object show {
|
|||
jsAt(s"compiled/lichess.puzzle${isProd ?? (".min")}.js"),
|
||||
embedJsUnsafe(s"""
|
||||
lichess = lichess || {};
|
||||
lichess.puzzle = { data: ${safeJsonValue(data)}, pref: ${safeJsonValue(pref)}, i18n: ${bits.jsI18n} };""")
|
||||
lichess.puzzle = ${
|
||||
safeJsonValue(Json.obj(
|
||||
"data" -> data,
|
||||
"pref" -> pref,
|
||||
"i18n" -> bits.jsI18n()
|
||||
))
|
||||
}""")
|
||||
),
|
||||
chessground = false,
|
||||
openGraph = lila.app.ui.OpenGraph(
|
||||
|
|
|
@ -5,7 +5,6 @@ import play.api.data.Form
|
|||
import lila.api.Context
|
||||
import lila.app.templating.Environment._
|
||||
import lila.app.ui.ScalatagsTemplate._
|
||||
import lila.common.String.html.safeJsonValue
|
||||
|
||||
import controllers.routes
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package views.html
|
||||
package relay
|
||||
|
||||
import play.api.libs.json.Json
|
||||
|
||||
import lila.api.Context
|
||||
import lila.app.templating.Environment._
|
||||
import lila.app.ui.ScalatagsTemplate._
|
||||
|
@ -24,30 +26,30 @@ object show {
|
|||
moreJs = frag(
|
||||
analyseTag,
|
||||
analyseNvuiTag,
|
||||
embedJsUnsafe(s"""lichess=window.lichess||{};lichess.relay={
|
||||
relay: ${safeJsonValue(data.relay)},
|
||||
study: ${safeJsonValue(data.study)},
|
||||
data: ${safeJsonValue(data.analysis)},
|
||||
i18n: ${board.userAnalysisI18n()},
|
||||
tagTypes: '${lila.study.PgnTags.typesToString}',
|
||||
userId: $jsUserIdString,
|
||||
chat: ${
|
||||
chatOption.fold("null")(c => safeJsonValue(chat.json(
|
||||
c.chat,
|
||||
name = trans.chatRoom.txt(),
|
||||
timeout = c.timeout,
|
||||
writeable = ctx.userId.??(s.canChat),
|
||||
public = false,
|
||||
localMod = ctx.userId.??(s.canContribute)
|
||||
)))
|
||||
},
|
||||
explorer: {
|
||||
endpoint: "$explorerEndpoint",
|
||||
tablebaseEndpoint: "$tablebaseEndpoint"
|
||||
},
|
||||
socketUrl: "${routes.Relay.websocket(s.id.value, apiVersion.value)}",
|
||||
socketVersion: $socketVersion
|
||||
};""")
|
||||
embedJsUnsafe(s"""lichess=window.lichess||{};lichess.relay=${
|
||||
safeJsonValue(Json.obj(
|
||||
"relay" -> data.relay,
|
||||
"study" -> data.study,
|
||||
"data" -> data.analysis,
|
||||
"i18n" -> board.userAnalysisI18n(),
|
||||
"tagTypes" -> lila.study.PgnTags.typesToString,
|
||||
"userId" -> ctx.userId,
|
||||
"chat" -> chatOption.map(c => chat.json(
|
||||
c.chat,
|
||||
name = trans.chatRoom.txt(),
|
||||
timeout = c.timeout,
|
||||
writeable = ctx.userId.??(s.canChat),
|
||||
public = false,
|
||||
localMod = ctx.userId.??(s.canContribute)
|
||||
)),
|
||||
"explorer" -> Json.obj(
|
||||
"endpoint" -> explorerEndpoint,
|
||||
"tablebaseEndpoint" -> tablebaseEndpoint
|
||||
),
|
||||
"socketUrl" -> routes.Relay.websocket(s.id.value, apiVersion.value).url,
|
||||
"socketVersion" -> socketVersion.value
|
||||
))
|
||||
}""")
|
||||
),
|
||||
chessground = false,
|
||||
zoomable = true,
|
||||
|
|
|
@ -2,12 +2,11 @@ package views.html.round
|
|||
|
||||
import lila.api.Context
|
||||
import lila.app.templating.Environment._
|
||||
import lila.common.String.html.safeJsonValue
|
||||
import lila.i18n.{ I18nKeys => trans }
|
||||
|
||||
object jsI18n {
|
||||
|
||||
def apply(g: lila.game.Game)(implicit ctx: Context): String = safeJsonValue(i18nJsObject {
|
||||
def apply(g: lila.game.Game)(implicit ctx: Context) = i18nJsObject {
|
||||
baseTranslations ++ {
|
||||
if (g.isCorrespondence) correspondenceTranslations
|
||||
else realtimeTranslations
|
||||
|
@ -16,7 +15,7 @@ object jsI18n {
|
|||
} ++ {
|
||||
g.isTournament ?? tournamentTranslations
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private val correspondenceTranslations = Vector(
|
||||
trans.oneDay,
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package views.html
|
||||
package round
|
||||
|
||||
import play.api.libs.json.Json
|
||||
|
||||
import lila.api.Context
|
||||
import lila.app.templating.Environment._
|
||||
import lila.app.ui.ScalatagsTemplate._
|
||||
|
@ -35,9 +37,16 @@ object player {
|
|||
roundNvuiTag,
|
||||
roundTag,
|
||||
embedJsUnsafe(s"""lichess=window.lichess||{};customWS=true;onload=function(){
|
||||
LichessRound.boot({data:${safeJsonValue(data)},i18n:${jsI18n(pov.game)},userId:$jsUserIdString,chat:${jsOrNull(chatJson)}
|
||||
${tour.flatMap(_.top).??(top => s",tour:${safeJsonValue(lila.tournament.JsonView.top(top, lightUser))}")}
|
||||
})}""")
|
||||
LichessRound.boot(${
|
||||
safeJsonValue(Json.obj(
|
||||
"data" -> data,
|
||||
"i18n" -> jsI18n(pov.game),
|
||||
"userId" -> ctx.userId,
|
||||
"chat" -> chatJson
|
||||
) ++ tour.flatMap(_.top).??(top => Json.obj(
|
||||
"tour" -> lila.tournament.JsonView.top(top, lightUser)
|
||||
)))
|
||||
})}""")
|
||||
),
|
||||
openGraph = povOpenGraph(pov).some,
|
||||
chessground = false,
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package views.html
|
||||
package round
|
||||
|
||||
import play.api.libs.json.Json
|
||||
|
||||
import lila.api.Context
|
||||
import lila.app.templating.Environment._
|
||||
import lila.app.ui.ScalatagsTemplate._
|
||||
|
@ -34,7 +36,13 @@ object watcher {
|
|||
roundNvuiTag,
|
||||
roundTag,
|
||||
embedJsUnsafe(s"""lichess=window.lichess||{};customWS=true;onload=function(){
|
||||
LichessRound.boot({data:${safeJsonValue(data)},i18n:${jsI18n(pov.game)},chat:${jsOrNull(chatJson)}})}""")
|
||||
LichessRound.boot(${
|
||||
safeJsonValue(Json.obj(
|
||||
"data" -> data,
|
||||
"i18n" -> jsI18n(pov.game),
|
||||
"chat" -> chatJson
|
||||
))
|
||||
})}""")
|
||||
),
|
||||
openGraph = povOpenGraph(pov).some,
|
||||
chessground = false
|
||||
|
|
|
@ -5,7 +5,6 @@ import play.api.libs.json.Json
|
|||
import lila.api.Context
|
||||
import lila.app.templating.Environment._
|
||||
import lila.app.ui.ScalatagsTemplate._
|
||||
import lila.common.String.html.safeJsonValue
|
||||
|
||||
import controllers.routes
|
||||
|
||||
|
@ -14,7 +13,7 @@ object bits {
|
|||
def link(simulId: lila.simul.Simul.ID): Frag =
|
||||
a(href := routes.Simul.show(simulId))("Simultaneous exhibition")
|
||||
|
||||
def jsI18n()(implicit ctx: Context) = safeJsonValue(i18nJsObject(baseTranslations))
|
||||
def jsI18n()(implicit ctx: Context) = i18nJsObject(baseTranslations)
|
||||
|
||||
def notFound()(implicit ctx: Context) =
|
||||
views.html.base.layout(
|
||||
|
|
|
@ -22,12 +22,17 @@ object show {
|
|||
title = sim.fullName,
|
||||
moreJs = frag(
|
||||
jsAt(s"compiled/lichess.simul${isProd ?? (".min")}.js"),
|
||||
embedJsUnsafe(s"""lichess.simul={
|
||||
data:${safeJsonValue(data)},
|
||||
i18n:${bits.jsI18n()},
|
||||
socketVersion:${socketVersion.value},
|
||||
userId: $jsUserIdString,
|
||||
chat: ${chatOption.fold("null")(c => safeJsonValue(views.html.chat.json(c.chat, name = trans.chatRoom.txt(), timeout = c.timeout, public = true)))}}""")
|
||||
embedJsUnsafe(s"""lichess.simul=${
|
||||
safeJsonValue(Json.obj(
|
||||
"data" -> data,
|
||||
"i18n" -> bits.jsI18n(),
|
||||
"socketVersion" -> socketVersion.value,
|
||||
"userId" -> ctx.userId,
|
||||
"chat" -> chatOption.map { c =>
|
||||
views.html.chat.json(c.chat, name = trans.chatRoom.txt(), timeout = c.timeout, public = true)
|
||||
}
|
||||
))
|
||||
}""")
|
||||
)
|
||||
) {
|
||||
main(cls := "simul")(
|
||||
|
|
|
@ -4,7 +4,6 @@ package study
|
|||
import lila.api.Context
|
||||
import lila.app.templating.Environment._
|
||||
import lila.app.ui.ScalatagsTemplate._
|
||||
import lila.common.String.html.safeJsonValue
|
||||
import lila.user.User
|
||||
|
||||
import controllers.routes
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package views.html.study
|
||||
|
||||
import play.api.libs.json.Json
|
||||
|
||||
import lila.api.Context
|
||||
import lila.app.templating.Environment._
|
||||
import lila.app.ui.ScalatagsTemplate._
|
||||
|
|
|
@ -5,7 +5,6 @@ import play.api.libs.json.Json
|
|||
import lila.api.Context
|
||||
import lila.app.templating.Environment._
|
||||
import lila.app.ui.ScalatagsTemplate._
|
||||
import lila.common.String.html.safeJsonValue
|
||||
import lila.study.Study
|
||||
|
||||
import controllers.routes
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package views.html.study
|
||||
|
||||
import play.api.libs.json.Json
|
||||
import play.api.mvc.RequestHeader
|
||||
|
||||
import lila.app.templating.Environment._
|
||||
|
@ -48,14 +49,15 @@ object embed {
|
|||
jsAt("compiled/trans.js"),
|
||||
jsAt("compiled/embed-analyse.js"),
|
||||
analyseTag,
|
||||
embedJsUnsafe(s"""lichess.startEmbeddedAnalyse({
|
||||
element: document.querySelector('.embedded_study'),
|
||||
study: ${safeJsonValue(data.study)},
|
||||
data: ${safeJsonValue(data.analysis)},
|
||||
embed: true,
|
||||
i18n: ${views.html.board.userAnalysisI18n()},
|
||||
userId: null
|
||||
});""", config.nonce)
|
||||
embedJsUnsafe(s"""lichess.startEmbeddedAnalyse(${
|
||||
safeJsonValue(Json.obj(
|
||||
"study" -> data.study,
|
||||
"data" -> data.analysis,
|
||||
"embed" -> true,
|
||||
"i18n" -> views.html.board.userAnalysisI18n(),
|
||||
"userId" -> none[String]
|
||||
))
|
||||
})""", config.nonce)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
|
|
@ -7,7 +7,6 @@ import lila.api.Context
|
|||
import lila.app.templating.Environment._
|
||||
import lila.app.ui.ScalatagsTemplate._
|
||||
import lila.common.paginator.Paginator
|
||||
import lila.common.String.html.safeJsonValue
|
||||
import lila.study.Order
|
||||
import lila.study.Study.WithChaptersAndLiked
|
||||
import lila.user.User
|
||||
|
|
|
@ -23,29 +23,31 @@ object show {
|
|||
moreJs = frag(
|
||||
analyseTag,
|
||||
analyseNvuiTag,
|
||||
embedJsUnsafe(s"""lichess=window.lichess||{};lichess.study={
|
||||
study: ${safeJsonValue(data.study)},
|
||||
data: ${safeJsonValue(data.analysis)},
|
||||
i18n: ${views.html.board.userAnalysisI18n()},
|
||||
tagTypes: '${lila.study.PgnTags.typesToString}',
|
||||
userId: $jsUserIdString,
|
||||
chat: ${
|
||||
chatOption.fold("null")(c => safeJsonValue(views.html.chat.json(
|
||||
c.chat,
|
||||
name = trans.chatRoom.txt(),
|
||||
timeout = c.timeout,
|
||||
writeable = ctx.userId.??(s.canChat),
|
||||
public = false,
|
||||
localMod = ctx.userId.??(s.canContribute)
|
||||
)))
|
||||
},
|
||||
explorer: {
|
||||
endpoint: "$explorerEndpoint",
|
||||
tablebaseEndpoint: "$tablebaseEndpoint"
|
||||
},
|
||||
socketUrl: "${routes.Study.websocket(s.id.value, apiVersion.value)}",
|
||||
socketVersion: $socketVersion
|
||||
};""")
|
||||
embedJsUnsafe(s"""lichess=window.lichess||{};lichess.study=${
|
||||
safeJsonValue(Json.obj(
|
||||
"study" -> data.study,
|
||||
"data" -> data.analysis,
|
||||
"i18n" -> views.html.board.userAnalysisI18n(),
|
||||
"tagTypes" -> lila.study.PgnTags.typesToString,
|
||||
"userId" -> ctx.userId,
|
||||
"chat" -> chatOption.map { c =>
|
||||
views.html.chat.json(
|
||||
c.chat,
|
||||
name = trans.chatRoom.txt(),
|
||||
timeout = c.timeout,
|
||||
writeable = ctx.userId.??(s.canChat),
|
||||
public = false,
|
||||
localMod = ctx.userId.??(s.canContribute)
|
||||
)
|
||||
},
|
||||
"explorer" -> Json.obj(
|
||||
"endpoint" -> explorerEndpoint,
|
||||
"tablebaseEndpoint" -> tablebaseEndpoint
|
||||
),
|
||||
"socketUrl" -> routes.Study.websocket(s.id.value, apiVersion.value).url,
|
||||
"socketVersion" -> socketVersion.value
|
||||
))
|
||||
}""")
|
||||
),
|
||||
robots = s.isPublic,
|
||||
chessground = false,
|
||||
|
|
|
@ -3,7 +3,6 @@ package views.html.tournament
|
|||
import lila.api.Context
|
||||
import lila.app.templating.Environment._
|
||||
import lila.app.ui.ScalatagsTemplate._
|
||||
import lila.common.String.html.safeJsonValue
|
||||
import lila.i18n.{ I18nKeys => trans }
|
||||
|
||||
import controllers.routes
|
||||
|
@ -51,7 +50,7 @@ object bits {
|
|||
}
|
||||
)
|
||||
|
||||
def jsI18n()(implicit ctx: Context) = safeJsonValue(i18nJsObject(translations))
|
||||
def jsI18n()(implicit ctx: Context) = i18nJsObject(translations)
|
||||
|
||||
private val translations = List(
|
||||
trans.standing,
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package views.html.tournament
|
||||
|
||||
import play.api.libs.json.Json
|
||||
|
||||
import lila.api.Context
|
||||
import lila.app.templating.Environment._
|
||||
import lila.app.ui.ScalatagsTemplate._
|
||||
|
@ -13,10 +15,12 @@ object calendar {
|
|||
title = "Tournament calendar",
|
||||
moreJs = frag(
|
||||
jsAt(s"compiled/lichess.tournamentCalendar${isProd ?? (".min")}.js"),
|
||||
embedJsUnsafe(s"""LichessTournamentCalendar.app(document.getElementById('tournament-calendar'), {
|
||||
data: ${safeJsonValue(json)},
|
||||
i18n: ${bits.jsI18n()}
|
||||
});""")
|
||||
embedJsUnsafe(s"""LichessTournamentCalendar.app(document.getElementById('tournament-calendar'), ${
|
||||
safeJsonValue(Json.obj(
|
||||
"data" -> json,
|
||||
"i18n" -> bits.jsI18n()
|
||||
))
|
||||
})""")
|
||||
),
|
||||
moreCss = cssTag("tournament.calendar")
|
||||
) {
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package views.html.tournament
|
||||
|
||||
import play.api.libs.json.Json
|
||||
|
||||
import lila.api.Context
|
||||
import lila.app.templating.Environment._
|
||||
import lila.app.ui.ScalatagsTemplate._
|
||||
|
@ -23,10 +25,12 @@ object home {
|
|||
moreJs = frag(
|
||||
infiniteScrollTag,
|
||||
jsAt(s"compiled/lichess.tournamentSchedule${isProd ?? (".min")}.js"),
|
||||
embedJsUnsafe(s"""var app=LichessTournamentSchedule.app(document.querySelector('.tour-chart'), {
|
||||
data: ${safeJsonValue(json)},
|
||||
i18n: ${bits.jsI18n()}
|
||||
});
|
||||
embedJsUnsafe(s"""var app=LichessTournamentSchedule.app(document.querySelector('.tour-chart'), ${
|
||||
safeJsonValue(Json.obj(
|
||||
"data" -> json,
|
||||
"i18n" -> bits.jsI18n()
|
||||
))
|
||||
});
|
||||
var d=lichess.StrongSocket.defaults;d.params.flag="tournament";d.events.reload=app.update;""")
|
||||
),
|
||||
openGraph = lila.app.ui.OpenGraph(
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package views.html
|
||||
package tournament
|
||||
|
||||
import play.api.libs.json.Json
|
||||
|
||||
import lila.api.Context
|
||||
import lila.app.templating.Environment._
|
||||
import lila.app.ui.ScalatagsTemplate._
|
||||
|
@ -22,14 +24,16 @@ object show {
|
|||
title = s"${tour.fullName} #${tour.id}",
|
||||
moreJs = frag(
|
||||
jsAt(s"compiled/lichess.tournament${isProd ?? (".min")}.js"),
|
||||
embedJsUnsafe(s"""lichess=lichess||{};lichess.tournament={
|
||||
data:${safeJsonValue(data)},
|
||||
i18n:${bits.jsI18n()},
|
||||
userId:${jsUserIdString},
|
||||
chat:${
|
||||
chatOption.fold("null")(c =>
|
||||
safeJsonValue(chat.json(c.chat, name = trans.chatRoom.txt(), timeout = c.timeout, public = true)))
|
||||
}};""")
|
||||
embedJsUnsafe(s"""lichess=lichess||{};lichess.tournament=${
|
||||
safeJsonValue(Json.obj(
|
||||
"data" -> data,
|
||||
"i18n" -> bits.jsI18n(),
|
||||
"userId" -> ctx.userId,
|
||||
"chat" -> chatOption.map { c =>
|
||||
chat.json(c.chat, name = trans.chatRoom.txt(), timeout = c.timeout, public = true)
|
||||
}
|
||||
))
|
||||
}""")
|
||||
),
|
||||
moreCss = cssTag("tournament.show"),
|
||||
chessground = false,
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package views.html
|
||||
package tv
|
||||
|
||||
import play.api.libs.json.Json
|
||||
|
||||
import lila.api.Context
|
||||
import lila.app.templating.Environment._
|
||||
import lila.app.ui.ScalatagsTemplate._
|
||||
|
@ -24,11 +26,14 @@ object index {
|
|||
title = s"${channel.name} TV: ${playerText(pov.player)} vs ${playerText(pov.opponent)}",
|
||||
moreJs = frag(
|
||||
roundTag,
|
||||
embedJsUnsafe {
|
||||
val transJs = views.html.round.jsI18n(pov.game)
|
||||
s"""lichess=window.lichess||{};customWS=true;
|
||||
onload=function(){LichessRound.boot({data:${safeJsonValue(data)},i18n:$transJs})}"""
|
||||
}
|
||||
embedJsUnsafe(
|
||||
s"""lichess=window.lichess||{};customWS=true;onload=function(){LichessRound.boot(${
|
||||
safeJsonValue(Json.obj(
|
||||
"data" -> data,
|
||||
"i18n" -> views.html.round.jsI18n(pov.game)
|
||||
))
|
||||
})}"""
|
||||
)
|
||||
),
|
||||
moreCss = cssTag("tv.single"),
|
||||
chessground = false,
|
||||
|
|
|
@ -3,7 +3,6 @@ package views.html.tv
|
|||
import lila.api.Context
|
||||
import lila.app.templating.Environment._
|
||||
import lila.app.ui.ScalatagsTemplate._
|
||||
import lila.common.String.html.safeJsonValue
|
||||
|
||||
import controllers.routes
|
||||
|
||||
|
|
|
@ -86,8 +86,6 @@ final object String {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
def safeJsonHtml(jsValue: JsValue): Frag = raw(safeJsonValue(jsValue))
|
||||
}
|
||||
|
||||
object frag {
|
||||
|
|
Loading…
Reference in New Issue