more embed refactor

refactor-site-js
Thibault Duplessis 2020-09-05 15:26:46 +02:00
parent 62ce27a384
commit 31054a1602
6 changed files with 73 additions and 105 deletions

View File

@ -11,23 +11,19 @@ import lila.user.Title
// collection of lila attrs
trait ScalatagsAttrs {
val dataAssetUrl = attr("data-asset-url")
val dataAssetVersion = attr("data-asset-version")
val dataDev = attr("data-dev")
val dataTheme = attr("data-theme")
val dataTag = attr("data-tag")
val dataIcon = attr("data-icon")
val dataHref = attr("data-href")
val dataCount = attr("data-count")
val dataEnableTime = attr("data-enable-time")
val datatime24h = attr("data-time_24h")
val dataColor = attr("data-color")
val dataFen = attr("data-fen")
val dataRel = attr("data-rel")
val novalidate = attr("novalidate").empty
val datetimeAttr = attr("datetime")
val dataBotAttr = attr("data-bot").empty
val deferAttr = attr("defer").empty
val dataTag = attr("data-tag")
val dataIcon = attr("data-icon")
val dataHref = attr("data-href")
val dataCount = attr("data-count")
val dataEnableTime = attr("data-enable-time")
val datatime24h = attr("data-time_24h")
val dataColor = attr("data-color")
val dataFen = attr("data-fen")
val dataRel = attr("data-rel")
val novalidate = attr("novalidate").empty
val datetimeAttr = attr("datetime")
val dataBotAttr = attr("data-bot").empty
val deferAttr = attr("defer").empty
object frame {
val scrolling = attr("scrolling")
val allowfullscreen = attr("allowfullscreen").empty

View File

@ -17,11 +17,6 @@ object embed {
title = replay titleOf pov,
cssModule = "analyse.embed"
)(
cls := s"highlight ${config.bg} ${config.board}",
dataDev := netConfig.minifiedAssets.option("true"),
dataAssetUrl := netConfig.assetBaseUrl,
dataAssetVersion := assetVersion.value,
dataTheme := config.bg,
div(cls := "is2d")(
main(cls := "analyse")
),

View File

@ -21,8 +21,10 @@ object embed {
layout.bits.pieceSprite(lila.pref.PieceSet.default),
cssTagWithTheme(cssModule, config.bg)
),
st.body(cls := s"base ${config.board}")(
st.body(cls := s"base highlight ${config.board}")(
layout.dataSoundSet := SoundSet.default.key,
layout.dataAssetUrl := netConfig.assetBaseUrl,
layout.dataAssetVersion := assetVersion.value,
body
)
)

View File

@ -6,8 +6,8 @@ import play.api.i18n.Lang
import lila.api.{ AnnounceStore, Context }
import lila.app.templating.Environment._
import lila.app.ui.ScalatagsTemplate._
import lila.common.{ ContentSecurityPolicy, Nonce }
import lila.common.String.html.safeJsonValue
import lila.common.{ ContentSecurityPolicy, Nonce }
object layout {
@ -163,11 +163,15 @@ object layout {
private val dataVapid = attr("data-vapid")
private val dataUser = attr("data-user")
val dataSoundSet = attr("data-sound-set")
private val dataSocketDomains = attr("data-socket-domains")
private val dataI18n = attr("data-i18n")
private val dataNonce = attr("data-nonce")
private val dataAnnounce = attr("data-announce")
val dataSoundSet = attr("data-sound-set")
val dataTheme = attr("data-theme")
val dataAssetUrl = attr("data-asset-url")
val dataAssetVersion = attr("data-asset-version")
val dataDev = attr("data-dev")
def apply(
title: String,

View File

@ -1,5 +1,6 @@
package views.html.study
import controllers.routes
import play.api.libs.json.Json
import lila.app.templating.Environment._
@ -7,9 +8,6 @@ import lila.app.ui.EmbedConfig
import lila.app.ui.ScalatagsTemplate._
import lila.common.String.html.safeJsonValue
import lila.i18n.{ I18nKeys => trans }
import views.html.base.layout.{ bits => layout }
import controllers.routes
object embed {
@ -21,89 +19,62 @@ object embed {
chapters: List[lila.study.Chapter.IdName],
data: lila.study.JsonView.JsData
)(implicit config: EmbedConfig) =
frag(
layout.doctype,
layout.htmlTag(config.lang)(
head(
layout.charset,
layout.viewport,
layout.metaCsp(basicCsp withNonce config.nonce),
st.headTitle(s"${s.name} ${chapter.name}"),
layout.pieceSprite(lila.pref.PieceSet.default),
cssTagWithTheme("analyse.embed", config.bg)
),
body(
cls := s"highlight ${config.bg} ${config.board}",
dataDev := netConfig.minifiedAssets.option("true"),
dataAssetUrl := netConfig.assetBaseUrl,
dataAssetVersion := assetVersion.value,
dataTheme := config.bg
)(
div(cls := "is2d")(
main(cls := "analyse")
views.html.base.embed(
title = s"${s.name} ${chapter.name}",
cssModule = "analyse.embed"
)(
div(cls := "is2d")(
main(cls := "analyse")
),
footer {
val url = routes.Study.chapter(s.id.value, chapter.id.value)
frag(
div(cls := "left")(
select(id := "chapter-selector")(chapters.map { c =>
option(
value := c.id.value,
(c.id == chapter.id) option selected
)(c.name.value)
}),
a(target := "_blank", href := url)(h1(s.name.value))
),
footer {
val url = routes.Study.chapter(s.id.value, chapter.id.value)
frag(
div(cls := "left")(
select(id := "chapter-selector")(chapters.map { c =>
option(
value := c.id.value,
(c.id == chapter.id) option selected
)(c.name.value)
}),
a(target := "_blank", href := url)(h1(s.name.value))
),
a(
target := "_blank",
cls := "open",
dataIcon := "=",
href := url,
title := trans.study.open.txt()
)
)
},
jQueryTag,
jsTag("vendor/mousetrap.js"),
jsAt("compiled/util.js"),
jsAt("compiled/trans.js"),
jsAt("compiled/embed-analyse.js"),
analyseTag,
embedJsUnsafeLoadThen(
s"""lichess.startEmbeddedAnalyse(${safeJsonValue(
Json.obj(
"study" -> data.study,
"data" -> data.analysis,
"embed" -> true,
"i18n" -> views.html.board.userAnalysisI18n(),
"userId" -> none[String]
)
)});
document.getElementById('chapter-selector').onchange = function() {
location.href = this.value + location.search;
};""",
config.nonce
a(
target := "_blank",
cls := "open",
dataIcon := "=",
href := url,
title := trans.study.open.txt()
)
)
},
views.html.base.layout.lichessJsObject(config.nonce)(config.lang),
jsModule("deps"),
jsModule("analyse.embed"),
analyseTag,
embedJsUnsafeLoadThen(
s"""analyseEmbed(${safeJsonValue(
Json.obj(
"study" -> data.study,
"data" -> data.analysis,
"embed" -> true,
"i18n" -> views.html.board.userAnalysisI18n(),
"userId" -> none[String]
)
)});
document.getElementById('chapter-selector').onchange = function() {
location.href = this.value + location.search;
}""",
config.nonce
)
)
def notFound(implicit config: EmbedConfig) =
frag(
layout.doctype,
layout.htmlTag(config.lang)(
head(
layout.charset,
layout.viewport,
layout.metaCsp(basicCsp),
st.headTitle(s"404 - ${trans.study.studyNotFound.txt()}"),
cssTagWithTheme("analyse.embed", "dark")
),
body(cls := "dark")(
div(cls := "not-found")(
h1(trans.study.studyNotFound())
)
)
views.html.base.embed(
title = s"404 - ${trans.study.studyNotFound.txt()}",
cssModule = "analyse.embed"
)(
div(cls := "not-found")(
h1(trans.study.studyNotFound())
)
)
}

View File

@ -16,9 +16,9 @@ function startUserAnalysis(cfg) {
function startAnalyse(cfg) {
let analyse;
cfg.socketSend = li.socket.send;
window.lichess.socket = new StrongSocket(cfg.socketUrl || '/analysis/socket/v5', cfg.socketVersion, {
receive: (t: string, d: any) => analyse.socketReceive(t, d)
});
cfg.socketSend = li.socket.send;
analyse = window.LichessAnalyse.start(cfg);
}