Merge pull request #10151 from stseng110499/feature/import-existing-study-hide-ratings
Hide ratings when importing game to existing study if option selecteddeepcrayonfish^2
commit
238cb7fd49
|
@ -328,7 +328,8 @@ final class Study(
|
|||
env.study.api.importPgns(
|
||||
StudyModel.Id(id),
|
||||
data.toChapterDatas,
|
||||
sticky = data.sticky
|
||||
sticky = data.sticky,
|
||||
ctx.pref.showRatings
|
||||
)(Who(me.id, lila.socket.Socket.Sri(sri)))
|
||||
)
|
||||
}
|
||||
|
|
|
@ -19,14 +19,14 @@ final private class ChapterMaker(
|
|||
|
||||
import ChapterMaker._
|
||||
|
||||
def apply(study: Study, data: Data, order: Int, userId: User.ID): Fu[Chapter] =
|
||||
def apply(study: Study, data: Data, order: Int, userId: User.ID, withRatings: Boolean): Fu[Chapter] =
|
||||
data.game.??(parseGame) flatMap {
|
||||
case None =>
|
||||
data.game ?? pgnFetch.fromUrl flatMap {
|
||||
case Some(pgn) => fromFenOrPgnOrBlank(study, data.copy(pgn = pgn.some), order, userId)
|
||||
case _ => fromFenOrPgnOrBlank(study, data, order, userId)
|
||||
}
|
||||
case Some(game) => fromGame(study, game, data, order, userId)
|
||||
case Some(game) => fromGame(study, game, data, order, userId, withRatings)
|
||||
} map { (c: Chapter) =>
|
||||
if (c.name.value.isEmpty) c.copy(name = Chapter defaultName order) else c
|
||||
}
|
||||
|
@ -125,14 +125,15 @@ final private class ChapterMaker(
|
|||
data: Data,
|
||||
order: Int,
|
||||
userId: User.ID,
|
||||
withRatings: Boolean,
|
||||
initialFen: Option[FEN] = None
|
||||
): Fu[Chapter] =
|
||||
for {
|
||||
root <- game2root(game, initialFen)
|
||||
tags <- pgnDump.tags(game, initialFen, none, withOpening = true, withRating = true)
|
||||
tags <- pgnDump.tags(game, initialFen, none, withOpening = true, withRatings)
|
||||
name <- {
|
||||
if (data.isDefaultName)
|
||||
Namer.gameVsText(game, withRatings = false)(lightUser.async) dmap Chapter.Name.apply
|
||||
Namer.gameVsText(game, withRatings)(lightUser.async) dmap Chapter.Name.apply
|
||||
else fuccess(data.name)
|
||||
}
|
||||
_ = notifyChat(study, game, userId)
|
||||
|
|
|
@ -132,7 +132,8 @@ final class StudyApi(
|
|||
addChapter(
|
||||
studyId = study.id,
|
||||
data = data.form.toChapterData,
|
||||
sticky = study.settings.sticky
|
||||
sticky = study.settings.sticky,
|
||||
withRatings
|
||||
)(Who(user.id, Sri(""))) >> byIdWithLastChapter(studyId)
|
||||
case _ => fuccess(none)
|
||||
} orElse importGame(data.copy(form = data.form.copy(asStr = none)), user, withRatings)
|
||||
|
@ -587,11 +588,13 @@ final class StudyApi(
|
|||
}
|
||||
}
|
||||
|
||||
def addChapter(studyId: Study.Id, data: ChapterMaker.Data, sticky: Boolean)(who: Who): Funit =
|
||||
def addChapter(studyId: Study.Id, data: ChapterMaker.Data, sticky: Boolean, withRatings: Boolean)(
|
||||
who: Who
|
||||
): Funit =
|
||||
data.manyGames match {
|
||||
case Some(datas) =>
|
||||
lila.common.Future.applySequentially(datas) { data =>
|
||||
addChapter(studyId, data, sticky)(who)
|
||||
addChapter(studyId, data, sticky, withRatings)(who)
|
||||
}
|
||||
case _ =>
|
||||
sequenceStudy(studyId) { study =>
|
||||
|
@ -605,7 +608,7 @@ final class StudyApi(
|
|||
}
|
||||
} >>
|
||||
chapterRepo.nextOrderByStudy(study.id) flatMap { order =>
|
||||
chapterMaker(study, data, order, who.u) flatMap { chapter =>
|
||||
chapterMaker(study, data, order, who.u, withRatings) flatMap { chapter =>
|
||||
doAddChapter(study, chapter, sticky, who)
|
||||
} addFailureEffect {
|
||||
case ChapterMaker.ValidationException(error) =>
|
||||
|
@ -624,9 +627,11 @@ final class StudyApi(
|
|||
studyRepo.updateSomeFields(study) >>- indexStudy(study)
|
||||
}
|
||||
|
||||
def importPgns(studyId: Study.Id, datas: List[ChapterMaker.Data], sticky: Boolean)(who: Who) =
|
||||
def importPgns(studyId: Study.Id, datas: List[ChapterMaker.Data], sticky: Boolean, withRatings: Boolean)(
|
||||
who: Who
|
||||
) =
|
||||
lila.common.Future.applySequentially(datas) { data =>
|
||||
addChapter(studyId, data, sticky)(who)
|
||||
addChapter(studyId, data, sticky, withRatings)(who)
|
||||
}
|
||||
|
||||
def doAddChapter(study: Study, chapter: Chapter, sticky: Boolean, who: Who) =
|
||||
|
@ -731,7 +736,13 @@ final class StudyApi(
|
|||
chapterRepo.orderedMetadataByStudy(studyId).flatMap { chaps =>
|
||||
// deleting the only chapter? Automatically create an empty one
|
||||
if (chaps.sizeIs < 2) {
|
||||
chapterMaker(study, ChapterMaker.Data(Chapter.Name("Chapter 1")), 1, who.u) flatMap { c =>
|
||||
chapterMaker(
|
||||
study,
|
||||
ChapterMaker.Data(Chapter.Name("Chapter 1")),
|
||||
1,
|
||||
who.u,
|
||||
withRatings = true
|
||||
) flatMap { c =>
|
||||
doAddChapter(study, c, sticky = true, who) >> doSetChapter(study, c.id, who)
|
||||
}
|
||||
} // deleting the current chapter? Automatically move to another one
|
||||
|
|
|
@ -124,7 +124,7 @@ final private class StudySocket(
|
|||
case "addChapter" =>
|
||||
reading[ChapterMaker.Data](o) { data =>
|
||||
val sticky = o.obj("d").flatMap(_.boolean("sticky")) | true
|
||||
who foreach api.addChapter(studyId, data, sticky = sticky)
|
||||
who foreach api.addChapter(studyId, data, sticky = sticky, withRatings = true)
|
||||
}
|
||||
case "setChapter" =>
|
||||
o.get[Chapter.Id]("d") foreach { chapterId =>
|
||||
|
|
Loading…
Reference in New Issue