lila/app/views/swiss/show.scala

111 lines
3.7 KiB
Scala
Raw Normal View History

2020-04-29 12:57:13 -06:00
package views.html
package swiss
2020-10-05 06:39:25 -06:00
import controllers.routes
2020-04-29 12:57:13 -06:00
import play.api.libs.json.Json
import lila.api.Context
import lila.app.templating.Environment._
import lila.app.ui.ScalatagsTemplate._
import lila.common.String.html.safeJsonValue
2020-10-05 06:39:25 -06:00
import lila.swiss.{ Swiss, SwissCondition }
import lila.swiss.SwissRound
import lila.common.paginator.Paginator
import lila.swiss.SwissPairing
2020-04-29 12:57:13 -06:00
object show {
private def fullName(s: Swiss) = s"${s.name} by ${teamIdToName(s.teamId)}"
2020-04-29 12:57:13 -06:00
def apply(
2020-04-29 15:46:31 -06:00
s: Swiss,
2020-10-05 06:39:25 -06:00
verdicts: SwissCondition.All.WithVerdicts,
2020-04-29 12:57:13 -06:00
data: play.api.libs.json.JsObject,
chatOption: Option[lila.chat.UserChat.Mine],
2021-01-20 14:50:11 -07:00
streamers: List[lila.user.User.ID],
isLocalMod: Boolean
2020-05-15 12:15:14 -06:00
)(implicit ctx: Context): Frag = {
val isDirector = ctx.userId.has(s.createdBy)
val hasScheduleInput = isDirector && s.settings.manualRounds && s.isNotFinished
2020-04-29 15:46:31 -06:00
views.html.base.layout(
title = fullName(s),
2020-04-29 15:46:31 -06:00
moreJs = frag(
2020-07-31 05:52:49 -06:00
jsModule("swiss"),
2020-09-12 04:30:40 -06:00
hasScheduleInput option jsModule("flatpickr"),
2020-09-04 08:10:30 -06:00
embedJsUnsafeLoadThen(s"""LichessSwiss.start(${safeJsonValue(
2020-05-15 12:15:14 -06:00
Json
.obj(
"data" -> data,
"i18n" -> bits.jsI18n,
"userId" -> ctx.userId,
"chat" -> chatOption.map { c =>
chat.json(
c.chat,
name = trans.chatRoom.txt(),
timeout = c.timeout,
public = true,
resourceId = lila.chat.Chat.ResourceId(s"swiss/${c.chat.id}"),
localMod = isLocalMod
2020-05-15 12:15:14 -06:00
)
2021-10-21 04:41:58 -06:00
},
"showRatings" -> ctx.pref.showRatings
2020-05-15 12:15:14 -06:00
)
.add("schedule" -> hasScheduleInput)
2020-04-29 15:46:31 -06:00
)})""")
),
2020-05-15 12:15:14 -06:00
moreCss = frag(
cssTag("swiss.show"),
hasScheduleInput option cssTag("flatpickr")
),
2020-04-29 15:46:31 -06:00
chessground = false,
openGraph = lila.app.ui
.OpenGraph(
title = s"${fullName(s)}: ${s.variant.name} ${s.clock.show} #${s.id}",
2020-04-29 15:46:31 -06:00
url = s"$netBaseUrl${routes.Swiss.show(s.id.value).url}",
2020-05-05 22:11:15 -06:00
description =
s"${s.nbPlayers} players compete in the ${showEnglishDate(s.startsAt)} ${s.name} swiss tournament " +
s"organized by ${teamIdToName(s.teamId)}. " +
s.winnerId.fold("Winner is not yet decided.") { winnerId =>
2021-09-01 03:56:19 -06:00
s"${titleNameOrId(winnerId)} takes the prize home!"
2020-05-05 22:11:15 -06:00
}
2020-04-29 15:46:31 -06:00
)
.some
)(
main(cls := "swiss")(
st.aside(cls := "swiss__side")(
2021-01-20 14:50:11 -07:00
swiss.side(s, verdicts, streamers, chatOption.isDefined)
2020-04-29 15:46:31 -06:00
),
div(cls := "swiss__main")(div(cls := "box"))
)
)
2020-05-15 12:15:14 -06:00
}
def round(s: Swiss, r: SwissRound.Number, pairings: Paginator[SwissPairing])(implicit ctx: Context) =
views.html.base.layout(
title = s"${fullName(s)} • Round $r/${s.round}",
moreCss = cssTag("swiss.show")
) {
val pager = views.html.base.bits
.pagination(p => routes.Swiss.round(s.id.value, p).url, r.value, s.round.value, showPost = true)
main(cls := "box swiss__round")(
h1(
a(href := routes.Swiss.show(s.id.value))(s.name),
s" • Round $r/${s.round}"
),
pager(cls := "pagination--top"),
table(cls := "slist slist-pad")(
pairings.currentPageResults map { p =>
tr(cls := "paginated")(
td(a(href := routes.Round.watcher(p.gameId, "white"), cls := "glpt")(s"#${p.gameId}")),
td(userIdLink(p.white.some)),
td(p strResultOf chess.White),
td(p strResultOf chess.Black),
td(userIdLink(p.black.some))
)
}
),
pager(cls := "pagination--bottom")
)
}
2020-04-29 12:57:13 -06:00
}