resume practice study on next unplayed chapter
This commit is contained in:
parent
97bdaf31a7
commit
9bd649aa6c
|
@ -21,25 +21,23 @@ object Practice extends LilaController {
|
|||
}
|
||||
|
||||
def show(sectionId: String, studySlug: String, studyId: String) = Open { implicit ctx =>
|
||||
OptionFuResult(env.api.getStudy(ctx.me, studyId)) {
|
||||
case us@lila.practice.UserStudy(up, practiceStudy, WithChapter(study, chapter)) =>
|
||||
studyEnv.chapterRepo.orderedMetadataByStudy(study.id) flatMap { chapters =>
|
||||
studyEnv.api.resetIfOld(study, chapters) flatMap { study =>
|
||||
val setup = chapter.setup
|
||||
val pov = UserAnalysis.makePov(chapter.root.fen.value.some, setup.variant)
|
||||
Env.round.jsonView.userAnalysisJson(pov, ctx.pref, setup.orientation, owner = false) zip
|
||||
studyEnv.jsonView(study, chapters, chapter, ctx.me) map {
|
||||
case (baseData, studyJson) =>
|
||||
import lila.tree.Node.partitionTreeJsonWriter
|
||||
val analysis = baseData ++ Json.obj(
|
||||
"treeParts" -> partitionTreeJsonWriter.writes(lila.study.TreeBuilder(chapter.root)))
|
||||
val data = lila.practice.JsonView.JsData(
|
||||
study = studyJson,
|
||||
analysis = analysis,
|
||||
practice = lila.practice.JsonView(us))
|
||||
Ok(html.practice.show(us, data))
|
||||
}
|
||||
}
|
||||
OptionFuResult(env.api.getStudyWithFirstOngoingChapter(ctx.me, studyId)) {
|
||||
case us@lila.practice.UserStudy(up, practiceStudy, chapters, WithChapter(study, chapter)) =>
|
||||
studyEnv.api.resetIfOld(study, chapters) flatMap { study =>
|
||||
val setup = chapter.setup
|
||||
val pov = UserAnalysis.makePov(chapter.root.fen.value.some, setup.variant)
|
||||
Env.round.jsonView.userAnalysisJson(pov, ctx.pref, setup.orientation, owner = false) zip
|
||||
studyEnv.jsonView(study, chapters, chapter, ctx.me) map {
|
||||
case (baseData, studyJson) =>
|
||||
import lila.tree.Node.partitionTreeJsonWriter
|
||||
val analysis = baseData ++ Json.obj(
|
||||
"treeParts" -> partitionTreeJsonWriter.writes(lila.study.TreeBuilder(chapter.root)))
|
||||
val data = lila.practice.JsonView.JsData(
|
||||
study = studyJson,
|
||||
analysis = analysis,
|
||||
practice = lila.practice.JsonView(us))
|
||||
Ok(html.practice.show(us, data))
|
||||
}
|
||||
}
|
||||
} map NoCache
|
||||
}
|
||||
|
|
|
@ -19,14 +19,17 @@ final class PracticeApi(
|
|||
prog <- user.fold(fuccess(PracticeProgress.anon))(progress.get)
|
||||
} yield UserPractice(struct, prog)
|
||||
|
||||
def getStudy(user: Option[User], studyId: Study.Id): Fu[Option[UserStudy]] = for {
|
||||
def getStudyWithFirstOngoingChapter(user: Option[User], studyId: Study.Id): Fu[Option[UserStudy]] = for {
|
||||
up <- get(user)
|
||||
studyOption <- studyApi byIdWithFirstChapter studyId
|
||||
} yield studyOption.flatMap { sc =>
|
||||
up.structure study studyId map { struct =>
|
||||
UserStudy(up, struct, sc.copy(study = sc.study.withoutMembers))
|
||||
chapters <- studyApi.chapterMetadatas(studyId)
|
||||
chapterId = up.progress firstOngoingIn chapters.map(_.id)
|
||||
studyOption <- chapterId.fold(studyApi byIdWithFirstChapter studyId) {
|
||||
studyApi.byIdWithChapter(studyId, _)
|
||||
}
|
||||
}
|
||||
} yield for {
|
||||
sc <- studyOption
|
||||
practiceStudy <- up.structure study studyId
|
||||
} yield UserStudy(up, practiceStudy, chapters, sc.copy(study = sc.study.withoutMembers))
|
||||
|
||||
object config {
|
||||
def get = configStore.get map (_ | PracticeConfig.empty)
|
||||
|
|
|
@ -25,6 +25,9 @@ case class PracticeProgress(
|
|||
|
||||
def countDone(chapterIds: List[Chapter.Id]): Int =
|
||||
chapterIds count chapters.contains
|
||||
|
||||
def firstOngoingIn(chapterIds: List[Chapter.Id]): Option[Chapter.Id] =
|
||||
chapterIds.find(c => !chapters.contains(c)) orElse chapterIds.headOption
|
||||
}
|
||||
|
||||
object PracticeProgress {
|
||||
|
|
|
@ -19,6 +19,7 @@ case class UserPractice(
|
|||
case class UserStudy(
|
||||
practice: UserPractice,
|
||||
practiceStudy: PracticeStudy,
|
||||
chapters: List[Chapter.Metadata],
|
||||
study: Study.WithChapter)
|
||||
|
||||
case class Completion(done: Int, total: Int) {
|
||||
|
|
|
@ -421,6 +421,8 @@ final class StudyApi(
|
|||
def chapterIdNames(studyIds: List[Study.Id]): Fu[Map[Study.Id, Vector[Chapter.IdName]]] =
|
||||
chapterRepo.idNamesByStudyIds(studyIds)
|
||||
|
||||
def chapterMetadatas = chapterRepo.orderedMetadataByStudy _
|
||||
|
||||
private def indexStudy(study: Study) = indexer ! actorApi.SaveStudy(study)
|
||||
|
||||
private def reloadUid(study: Study, uid: Uid) =
|
||||
|
|
Loading…
Reference in a new issue