lila/app/views/user/bots.scala

100 lines
2.9 KiB
Scala
Raw Normal View History

2020-01-30 09:24:12 -07:00
package views.html
package user
import controllers.routes
2020-01-30 09:24:12 -07:00
import lila.api.Context
import lila.app.templating.Environment._
import lila.app.ui.ScalatagsTemplate._
import lila.user.User
object bots {
def apply(users: List[User])(implicit ctx: Context) = {
2020-01-31 07:48:49 -07:00
val title = s"${users.size} Online bots"
2020-01-30 09:24:12 -07:00
val sorted = users.sortBy { -_.playTime.??(_.total) }
2020-01-30 09:24:12 -07:00
views.html.base.layout(
title = title,
moreCss = frag(cssTag("slist"), cssTag("user.list")),
wrapClass = "full-screen-force"
)(
main(cls := "page-menu bots")(
user.bits.communityMenu("bots"),
sorted.partition(_.isVerified) match {
case (featured, all) =>
div(cls := "bots page-menu__content")(
div(cls := "box bots__featured")(
div(cls := "box__top")(h1("Featured bots")),
botTable(featured)
),
div(cls := "box")(
2021-01-29 10:07:20 -07:00
div(cls := "box__top")(
h1("Community bots"),
a(
cls := "bots__about",
href := "https://lichess.org/blog/WvDNticAAMu_mHKP/welcome-lichess-bots"
)(
"About Lichess Bots"
)
),
botTable(all)
)
2020-01-30 09:24:12 -07:00
)
}
2020-01-30 09:24:12 -07:00
)
)
}
private def botTable(users: List[User])(implicit ctx: Context) = table(cls := "slist slist-pad")(
tbody(
users.sortBy { u =>
(if (u.isVerified) -1 else 1, -u.playTime.??(_.total))
} map { u =>
tr(
td(userLink(u)),
u.profile
.ifTrue(ctx.noKid)
.ifTrue(!u.marks.troll || ctx.is(u))
.flatMap(_.nonEmptyBio)
.map { bio =>
td(shorten(bio, 400))
} | td,
2021-10-21 04:08:11 -06:00
ctx.pref.showRatings option td(cls := "rating")(u.best3Perfs.map {
showPerfRating(u, _)
}),
u.playTime.fold(td) { playTime =>
td(
p(
cls := "text",
dataIcon := "",
st.title := trans.tpTimeSpentPlaying.txt(showPeriod(playTime.totalPeriod))
)(showPeriod(playTime.totalPeriod)),
playTime.nonEmptyTvPeriod.map { tvPeriod =>
p(
cls := "text",
dataIcon := "",
st.title := trans.tpTimeSpentOnTV.txt(showPeriod(tvPeriod))
)(showPeriod(tvPeriod))
}
)
},
if (ctx is u) td
else {
td(
a(
dataIcon := "",
cls := List("button button-empty text" -> true),
st.title := trans.challenge.challengeToPlay.txt(),
href := s"${routes.Lobby.home}?user=${u.username}#friend"
)(trans.play())
)
}
)
}
)
)
2020-01-30 09:24:12 -07:00
}