reload tournament player info automatically - fixes #1109
This commit is contained in:
parent
9c79958d71
commit
b5d5ee2cb4
|
@ -42,14 +42,18 @@ object Tournament extends LilaController {
|
|||
negotiate(
|
||||
html = repo byId id flatMap {
|
||||
_.fold(tournamentNotFound.fuccess) { tour =>
|
||||
env.version(tour.id) zip env.jsonView(tour, page, ctx.userId) zip chatOf(tour) map {
|
||||
env.version(tour.id) zip env.jsonView(tour, page, ctx.userId, none) zip chatOf(tour) map {
|
||||
case ((version, data), chat) => html.tournament.show(tour, version, data, chat)
|
||||
}
|
||||
}
|
||||
},
|
||||
api = _ => repo byId id flatMap {
|
||||
case None => NotFound(Json.obj("error" -> "No such tournament")).fuccess
|
||||
case Some(tour) => env.jsonView(tour, page, ctx.userId) map { Ok(_) }
|
||||
case None => NotFound(Json.obj("error" -> "No such tournament")).fuccess
|
||||
case Some(tour) => get("playerInfo") ?? {
|
||||
env.api.playerInfo(tour.id, _)
|
||||
} flatMap { playerInfoExt =>
|
||||
env.jsonView(tour, page, ctx.userId, playerInfoExt)
|
||||
} map { Ok(_) }
|
||||
} map (_ as JSON)
|
||||
) map NoCache
|
||||
}
|
||||
|
@ -91,8 +95,8 @@ object Tournament extends LilaController {
|
|||
}
|
||||
|
||||
def player(id: String, userId: String) = Open { implicit ctx =>
|
||||
JsonOptionFuOk(UserRepo byId userId) { user =>
|
||||
env.api.playerInfo(id, user) flatMap {
|
||||
JsonOk {
|
||||
env.api.playerInfo(id, userId) flatMap {
|
||||
_ ?? env.jsonView.playerInfo
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,11 @@ final class JsonView(
|
|||
|
||||
private case class CachableData(pairings: JsArray, games: JsArray, podium: Option[JsArray])
|
||||
|
||||
def apply(tour: Tournament, page: Option[Int], me: Option[String]): Fu[JsObject] = for {
|
||||
def apply(
|
||||
tour: Tournament,
|
||||
page: Option[Int],
|
||||
me: Option[String],
|
||||
playerInfoExt: Option[PlayerInfoExt]): Fu[JsObject] = for {
|
||||
data <- cachableData(tour.id)
|
||||
myInfo <- me ?? { PlayerRepo.playerInfo(tour.id, _) }
|
||||
stand <- (myInfo, page) match {
|
||||
|
@ -23,6 +27,9 @@ final class JsonView(
|
|||
case (Some(i), _) => standing(tour, i.page)
|
||||
case _ => standing(tour, 1)
|
||||
}
|
||||
playerInfoJson <- playerInfoExt ?? { pie =>
|
||||
playerInfo(pie).map(_.some)
|
||||
}
|
||||
} yield Json.obj(
|
||||
"id" -> tour.id,
|
||||
"createdBy" -> tour.createdBy,
|
||||
|
@ -45,7 +52,8 @@ final class JsonView(
|
|||
"lastGames" -> data.games,
|
||||
"standing" -> stand,
|
||||
"me" -> myInfo.map(myInfoJson),
|
||||
"podium" -> data.podium
|
||||
"podium" -> data.podium,
|
||||
"playerInfo" -> playerInfoJson
|
||||
).noNull
|
||||
|
||||
def standing(tour: Tournament, page: Int): Fu[JsObject] =
|
||||
|
|
|
@ -256,13 +256,17 @@ private[tournament] final class TournamentApi(
|
|||
VisibleTournaments(created, started, finished)
|
||||
}
|
||||
|
||||
def playerInfo(tourId: String, user: User): Fu[Option[PlayerInfoExt]] =
|
||||
TournamentRepo byId tourId flatMap {
|
||||
_ ?? { tour =>
|
||||
PlayerRepo.find(tour.id, user.id) flatMap {
|
||||
_ ?? { player =>
|
||||
playerPovs(tour.id, user.id, 50) map { povs =>
|
||||
PlayerInfoExt(tour, user, player, povs).some
|
||||
def playerInfo(tourId: String, userId: String): Fu[Option[PlayerInfoExt]] =
|
||||
UserRepo named userId flatMap {
|
||||
_ ?? { user =>
|
||||
TournamentRepo byId tourId flatMap {
|
||||
_ ?? { tour =>
|
||||
PlayerRepo.find(tour.id, user.id) flatMap {
|
||||
_ ?? { player =>
|
||||
playerPovs(tour.id, user.id, 50) map { povs =>
|
||||
PlayerInfoExt(tour, user, player, povs).some
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,6 +28,8 @@ module.exports = function(env) {
|
|||
this.reload = function(data) {
|
||||
if (this.data.isStarted !== data.isStarted) m.redraw.strategy('all');
|
||||
this.data = data;
|
||||
if (data.playerInfo && data.playerInfo.player.id === this.vm.playerInfo.id)
|
||||
this.vm.playerInfo.data = data.playerInfo;
|
||||
this.loadPage(data.standing);
|
||||
if (this.vm.focusOnMe) this.scrollToMe();
|
||||
startWatching();
|
||||
|
|
|
@ -27,7 +27,10 @@ module.exports = function(ctrl) {
|
|||
if (!isUpdate) $('body').trigger('lichess.content_loaded');
|
||||
}
|
||||
}, [
|
||||
m('h2', [m('span.rank', data.player.rank + '. '), util.player(data.player)]),
|
||||
m('h2', [
|
||||
data.player.withdraw ? m('span.text[data-icon=b]') : m('span.rank', data.player.rank + '. '),
|
||||
util.player(data.player)
|
||||
]),
|
||||
m('div.stats', m('table', [
|
||||
m('tr', [m('th', 'Games played'), m('td', nb.game)]),
|
||||
nb.game ? [
|
||||
|
|
|
@ -34,7 +34,8 @@ function reloadTournament(ctrl) {
|
|||
url: '/tournament/' + ctrl.data.id,
|
||||
config: xhrConfig,
|
||||
data: {
|
||||
page: ctrl.vm.focusOnMe ? null : ctrl.vm.page
|
||||
page: ctrl.vm.focusOnMe ? null : ctrl.vm.page,
|
||||
playerInfo: ctrl.vm.playerInfo.id
|
||||
}
|
||||
}).then(ctrl.reload, reloadPage);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue