userAnalysisJson no longer needs to be a future
parent
a48d8bada0
commit
aa1a8aea78
|
@ -70,11 +70,10 @@ object Practice extends LilaController {
|
|||
|
||||
private def analysisJson(us: UserStudy)(implicit ctx: Context): Fu[(JsObject, JsObject)] = us match {
|
||||
case UserStudy(_, _, chapters, WithChapter(study, chapter), _) =>
|
||||
studyEnv.jsonView(study, chapters, chapter, ctx.me) map { studyJson =>
|
||||
val initialFen = chapter.root.fen.value.some
|
||||
val pov = UserAnalysis.makePov(initialFen, chapter.setup.variant)
|
||||
Env.round.jsonView.userAnalysisJson(pov, ctx.pref, initialFen, chapter.setup.orientation, owner = false, me = ctx.me) zip
|
||||
studyEnv.jsonView(study, chapters, chapter, ctx.me) map {
|
||||
case (baseData, studyJson) =>
|
||||
val baseData = Env.round.jsonView.userAnalysisJson(pov, ctx.pref, initialFen, chapter.setup.orientation, owner = false, me = ctx.me)
|
||||
val analysis = baseData ++ Json.obj(
|
||||
"treeParts" -> partitionTreeJsonWriter.writes {
|
||||
lila.study.TreeBuilder(chapter.root, chapter.setup.variant)
|
||||
|
|
|
@ -94,7 +94,7 @@ object Study extends LilaController {
|
|||
_ = if (HTTPRequest isSynchronousHttp ctx.req) env.studyRepo.incViews(study)
|
||||
initialFen = chapter.root.fen.value.some
|
||||
pov = UserAnalysis.makePov(initialFen, chapter.setup.variant)
|
||||
baseData <- Env.round.jsonView.userAnalysisJson(pov, ctx.pref, initialFen, chapter.setup.orientation, owner = false, me = ctx.me)
|
||||
baseData = Env.round.jsonView.userAnalysisJson(pov, ctx.pref, initialFen, chapter.setup.orientation, owner = false, me = ctx.me)
|
||||
studyJson <- env.jsonView(study, chapters, chapter, ctx.me)
|
||||
data = lila.study.JsonView.JsData(
|
||||
study = studyJson,
|
||||
|
@ -196,14 +196,13 @@ object Study extends LilaController {
|
|||
env.api.byIdWithChapter(id, chapterId) flatMap {
|
||||
_.fold(embedNotFound) {
|
||||
case WithChapter(study, chapter) => CanViewResult(study) {
|
||||
env.jsonView(study.copy(
|
||||
members = lila.study.StudyMembers(Map.empty) // don't need no members
|
||||
), List(chapter.metadata), chapter, ctx.me) flatMap { studyJson =>
|
||||
val setup = chapter.setup
|
||||
val initialFen = chapter.root.fen.value.some
|
||||
val pov = UserAnalysis.makePov(initialFen, setup.variant)
|
||||
Env.round.jsonView.userAnalysisJson(pov, ctx.pref, initialFen, setup.orientation, owner = false, me = ctx.me) zip
|
||||
env.jsonView(study.copy(
|
||||
members = lila.study.StudyMembers(Map.empty) // don't need no members
|
||||
), List(chapter.metadata), chapter, ctx.me) flatMap {
|
||||
case (baseData, studyJson) =>
|
||||
val baseData = Env.round.jsonView.userAnalysisJson(pov, ctx.pref, initialFen, setup.orientation, owner = false, me = ctx.me)
|
||||
import lila.tree.Node.partitionTreeJsonWriter
|
||||
val analysis = baseData ++ Json.obj(
|
||||
"treeParts" -> partitionTreeJsonWriter.writes {
|
||||
|
@ -216,10 +215,7 @@ object Study extends LilaController {
|
|||
)
|
||||
negotiate(
|
||||
html = Ok(html.study.embed(study, chapter, data)).fuccess,
|
||||
api = _ => Ok(Json.obj(
|
||||
"study" -> data.study,
|
||||
"analysis" -> data.analysis
|
||||
)).fuccess
|
||||
api = _ => Ok(Json.obj("study" -> data.study, "analysis" -> data.analysis)).fuccess
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -93,15 +93,18 @@ private[api] final class RoundApi(
|
|||
}
|
||||
|
||||
def userAnalysisJson(pov: Pov, pref: Pref, initialFen: Option[String], orientation: chess.Color, owner: Boolean, me: Option[User]) =
|
||||
owner.??(forecastApi loadForDisplay pov).flatMap { fco =>
|
||||
jsonView.userAnalysisJson(pov, pref, initialFen, orientation, owner = owner, me = me) map
|
||||
withTree(pov, analysis = none, initialFen, WithFlags(opening = true))_ map
|
||||
withForecast(pov, owner, fco)_
|
||||
owner.??(forecastApi loadForDisplay pov).map { fco =>
|
||||
withForecast(pov, owner, fco)(
|
||||
withTree(pov, analysis = none, initialFen, WithFlags(opening = true))(
|
||||
jsonView.userAnalysisJson(pov, pref, initialFen, orientation, owner = owner, me = me)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
def freeStudyJson(pov: Pov, pref: Pref, initialFen: Option[String], orientation: chess.Color, me: Option[User]) =
|
||||
jsonView.userAnalysisJson(pov, pref, initialFen, orientation, owner = false, me = me) map
|
||||
withTree(pov, analysis = none, initialFen, WithFlags(opening = true))_
|
||||
withTree(pov, analysis = none, initialFen, WithFlags(opening = true))(
|
||||
jsonView.userAnalysisJson(pov, pref, initialFen, orientation, owner = false, me = me)
|
||||
)
|
||||
|
||||
private def withTree(pov: Pov, analysis: Option[Analysis], initialFen: Option[String], withFlags: WithFlags)(obj: JsObject) =
|
||||
obj + ("treeParts" -> partitionTreeJsonWriter.writes(lila.round.TreeBuilder(
|
||||
|
|
|
@ -56,7 +56,7 @@ private[api] final class RoundApiBalancer(
|
|||
case UserAnalysis(pov, pref, initialFen, orientation, owner, me) =>
|
||||
api.userAnalysisJson(pov, pref, initialFen, orientation, owner, me)
|
||||
case FreeStudy(pov, pref, initialFen, orientation, me) =>
|
||||
api.freeStudyJson(pov, pref, initialFen, orientation, me)
|
||||
fuccess(api.freeStudyJson(pov, pref, initialFen, orientation, me))
|
||||
}
|
||||
})), "api.round.router"
|
||||
)
|
||||
|
|
|
@ -221,8 +221,7 @@ final class JsonView(
|
|||
orientation: chess.Color,
|
||||
owner: Boolean,
|
||||
me: Option[User]
|
||||
) =
|
||||
fuccess {
|
||||
) = {
|
||||
import pov._
|
||||
val fen = Forsyth >> game.toChess
|
||||
Json.obj(
|
||||
|
|
Loading…
Reference in New Issue