2013-02-27 17:12:13 -07:00
|
|
|
package lila.app
|
2013-05-10 15:45:59 -06:00
|
|
|
package templating
|
2012-09-09 14:04:52 -06:00
|
|
|
|
2020-02-14 09:49:53 -07:00
|
|
|
import play.api.i18n.Lang
|
|
|
|
import play.api.libs.json.Json
|
|
|
|
|
2014-04-12 11:32:28 -06:00
|
|
|
import controllers.routes
|
2019-04-09 03:46:13 -06:00
|
|
|
import lila.app.ui.ScalatagsTemplate._
|
2020-02-14 09:49:53 -07:00
|
|
|
import lila.rating.PerfType
|
2019-12-13 07:30:20 -07:00
|
|
|
import lila.tournament.{ Schedule, Tournament }
|
2019-12-08 11:12:00 -07:00
|
|
|
import lila.user.User
|
2012-09-09 14:04:52 -06:00
|
|
|
|
2015-06-29 07:08:16 -06:00
|
|
|
trait TournamentHelper { self: I18nHelper with DateHelper with UserHelper =>
|
|
|
|
|
|
|
|
def netBaseUrl: String
|
2012-09-09 14:04:52 -06:00
|
|
|
|
2014-04-12 11:32:28 -06:00
|
|
|
def tournamentJsData(tour: Tournament, version: Int, user: Option[User]) = {
|
2012-09-09 14:04:52 -06:00
|
|
|
|
2012-11-29 15:31:53 -07:00
|
|
|
val data = Json.obj(
|
|
|
|
"tournament" -> Json.obj("id" -> tour.id),
|
2019-12-13 07:30:20 -07:00
|
|
|
"version" -> version
|
2012-11-29 15:31:53 -07:00
|
|
|
)
|
|
|
|
Json stringify {
|
2019-12-13 07:30:20 -07:00
|
|
|
user.fold(data) { u =>
|
|
|
|
data ++ Json.obj("username" -> u.username)
|
|
|
|
}
|
2012-09-09 15:35:47 -06:00
|
|
|
}
|
2012-09-09 14:04:52 -06:00
|
|
|
}
|
2014-04-12 11:32:28 -06:00
|
|
|
|
2020-02-14 09:49:53 -07:00
|
|
|
def tournamentLink(tour: Tournament)(implicit lang: Lang): Frag =
|
2019-12-13 07:30:20 -07:00
|
|
|
a(
|
|
|
|
dataIcon := "g",
|
|
|
|
cls := (if (tour.isScheduled) "text is-gold" else "text"),
|
|
|
|
href := routes.Tournament.show(tour.id).url
|
2020-02-14 09:49:53 -07:00
|
|
|
)(tour.name())
|
2014-07-04 09:01:06 -06:00
|
|
|
|
2020-02-14 09:49:53 -07:00
|
|
|
def tournamentLink(tourId: String)(implicit lang: Lang): Frag =
|
2019-12-13 07:30:20 -07:00
|
|
|
a(
|
|
|
|
dataIcon := "g",
|
|
|
|
cls := "text",
|
|
|
|
href := routes.Tournament.show(tourId).url
|
|
|
|
)(tournamentIdToName(tourId))
|
2014-08-02 10:24:10 -06:00
|
|
|
|
2020-02-14 09:49:53 -07:00
|
|
|
def tournamentIdToName(id: String)(implicit lang: Lang) =
|
|
|
|
env.tournament.getTourName get id getOrElse "Tournament"
|
2014-08-02 10:24:10 -06:00
|
|
|
|
2016-10-17 09:35:24 -06:00
|
|
|
object scheduledTournamentNameShortHtml {
|
|
|
|
private def icon(c: Char) = s"""<span data-icon="$c"></span>"""
|
|
|
|
private val replacements = List(
|
2019-12-13 07:30:20 -07:00
|
|
|
"Lichess " -> "",
|
|
|
|
"Marathon" -> icon('\\'),
|
2020-02-13 11:20:19 -07:00
|
|
|
"HyperBullet" -> s"H${icon(PerfType.Bullet.iconChar)}",
|
|
|
|
"SuperBlitz" -> s"S${icon(PerfType.Blitz.iconChar)}"
|
|
|
|
) ::: PerfType.leaderboardable.filterNot(PerfType.translated.contains).map { pt =>
|
2020-02-15 09:27:34 -07:00
|
|
|
pt.trans(lila.i18n.defaultLang) -> icon(pt.iconChar)
|
2019-12-13 07:30:20 -07:00
|
|
|
}
|
2020-02-13 11:20:19 -07:00
|
|
|
|
2020-05-05 22:11:15 -06:00
|
|
|
def apply(name: String): Frag =
|
|
|
|
raw {
|
|
|
|
replacements.foldLeft(name) {
|
|
|
|
case (n, (from, to)) => n.replace(from, to)
|
|
|
|
}
|
2016-10-17 09:35:24 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-05 22:11:15 -06:00
|
|
|
def tournamentIconChar(tour: Tournament): String =
|
|
|
|
tour.schedule.map(_.freq) match {
|
|
|
|
case Some(Schedule.Freq.Marathon | Schedule.Freq.ExperimentalMarathon) => "\\"
|
|
|
|
case _ => tour.spotlight.flatMap(_.iconFont) | tour.perfType.fold('g')(_.iconChar).toString
|
|
|
|
}
|
2012-09-09 14:04:52 -06:00
|
|
|
}
|