lila/app/views/storm.scala

176 lines
5.0 KiB
Scala
Raw Normal View History

2021-01-22 11:37:49 -07:00
package views.html
2021-01-25 14:30:03 -07:00
import controllers.routes
2021-01-26 03:54:35 -07:00
import play.api.i18n.Lang
2021-01-22 11:37:49 -07:00
import play.api.libs.json._
import lila.api.Context
import lila.app.templating.Environment._
import lila.app.ui.ScalatagsTemplate._
2021-01-25 14:30:03 -07:00
import lila.common.paginator.Paginator
2021-01-22 11:37:49 -07:00
import lila.common.String.html.safeJsonValue
2021-01-25 14:30:03 -07:00
import lila.storm.{ StormDay, StormHigh }
import lila.user.User
2021-01-22 11:37:49 -07:00
object storm {
2021-01-26 03:54:35 -07:00
def home(data: JsObject, pref: JsObject, high: Option[StormHigh])(implicit ctx: Context) =
2021-01-22 11:37:49 -07:00
views.html.base.layout(
moreCss = frag(cssTag("storm")),
moreJs = frag(
jsModule("storm"),
embedJsUnsafeLoadThen(
2021-01-22 14:43:49 -07:00
s"""LichessStorm.start(${safeJsonValue(
2021-01-22 11:37:49 -07:00
Json.obj(
2021-01-23 02:42:29 -07:00
"data" -> data,
"pref" -> pref,
2021-01-25 14:30:03 -07:00
"i18n" -> i18nJsObject(i18nKeys)
2021-01-22 11:37:49 -07:00
)
)})"""
)
),
2021-01-23 02:42:29 -07:00
title = "Puzzle Storm",
2021-01-27 06:11:14 -07:00
zoomable = true,
2021-06-29 04:50:10 -06:00
playing = true,
2021-01-27 06:11:14 -07:00
chessground = false
2021-01-22 11:37:49 -07:00
) {
2021-01-25 14:30:03 -07:00
main(
2021-01-28 01:07:33 -07:00
div(cls := "storm storm-app storm--play")(
div(cls := "storm__board main-board"),
div(cls := "storm__side")
),
2021-01-26 03:54:35 -07:00
high map { h =>
frag(
div(cls := "storm-play-scores")(
2021-01-28 01:13:44 -07:00
span(trans.storm.highscores()),
a(href := routes.Storm.dashboard())(trans.storm.viewBestRuns(), " »")
2021-01-26 03:54:35 -07:00
),
div(cls := "storm-dashboard__high__periods")(
renderHigh(h)
)
)
2021-01-26 10:54:31 -07:00
},
div(cls := "storm__about__link")(
2021-03-25 01:12:03 -06:00
a(href := routes.Page.loneBookmark("storm"))(trans.aboutX("Puzzle Storm"))
2021-01-26 10:54:31 -07:00
)
2021-01-25 14:30:03 -07:00
)
2021-01-22 11:37:49 -07:00
}
2021-01-26 03:54:35 -07:00
private def renderHigh(high: StormHigh)(implicit lang: Lang) =
frag(
List(
2021-10-15 20:47:39 -06:00
(high.allTime, trans.storm.allTime),
(high.month, trans.storm.thisMonth),
(high.week, trans.storm.thisWeek),
(high.day, trans.today)
2021-01-26 03:54:35 -07:00
).map { case (value, name) =>
div(cls := "storm-dashboard__high__period")(
strong(value),
2021-10-15 20:47:39 -06:00
span(name())
2021-01-26 03:54:35 -07:00
)
}
)
private val numberTag = tag("number")
2021-01-25 14:30:03 -07:00
def dashboard(user: User, history: Paginator[StormDay], high: StormHigh)(implicit ctx: Context) =
views.html.base.layout(
title = s"${user.username} Puzzle Storm",
2021-01-25 14:30:03 -07:00
moreCss = frag(cssTag("storm.dashboard")),
moreJs = infiniteScrollTag
2021-01-25 14:30:03 -07:00
)(
main(cls := "storm-dashboard page-small")(
div(cls := "storm-dashboard__high box box-pad")(
2021-01-28 02:15:10 -07:00
h1(
!ctx.is(user) option frag(
userLink(user),
" • "
),
"Puzzle Storm • ",
trans.storm.highscores()
),
2021-01-26 03:54:35 -07:00
div(cls := "storm-dashboard__high__periods highlight-alltime")(
renderHigh(high)
2021-01-25 14:30:03 -07:00
)
),
a(cls := "storm-play-again button", href := routes.Storm.home)(trans.storm.playAgain()),
2021-01-25 14:30:03 -07:00
div(cls := "storm-dashboard__history box")(
table(cls := "slist slist-pad")(
thead(
tr(
th(trans.storm.bestRunOfDay()),
th(trans.storm.score()),
th(trans.storm.moves()),
th(trans.storm.accuracy()),
th(trans.storm.combo()),
th(trans.storm.time()),
th(trans.storm.highestSolved()),
th(trans.storm.runs())
2021-01-25 14:30:03 -07:00
)
),
tbody(cls := "infinite-scroll")(
2021-01-25 14:30:03 -07:00
history.currentPageResults.map { day =>
tr(
td(showDate(day._id.day.toDate)),
td(numberTag(cls := "score")(day.score)),
td(numberTag(day.moves)),
td(numberTag(f"${day.accuracyPercent}%1.1f"), "%"),
td(numberTag(day.combo)),
td(numberTag(day.time), "s"),
td(numberTag(day.highest)),
td(numberTag(day.runs))
2021-01-25 14:30:03 -07:00
)
},
2021-01-28 02:15:10 -07:00
pagerNextTable(
history,
np =>
addQueryParameter(
if (ctx is user) routes.Storm.dashboard().url
else routes.Storm.dashboardOf(user.username).url,
"page",
np
)
)
2021-01-25 14:30:03 -07:00
)
)
)
)
)
2021-01-22 11:37:49 -07:00
2021-01-24 11:40:50 -07:00
private val i18nKeys = {
2021-05-19 10:03:19 -06:00
import lila.i18n.{ I18nKeys => trans }
2021-03-04 04:41:21 -07:00
import lila.i18n.I18nKeys.{ storm => s }
2021-01-24 11:40:50 -07:00
List(
2021-03-04 04:41:21 -07:00
s.moveToStart,
s.puzzlesSolved,
s.newDailyHighscore,
s.newWeeklyHighscore,
s.newMonthlyHighscore,
s.newAllTimeHighscore,
s.previousHighscoreWasX,
s.playAgain,
s.score,
s.moves,
s.accuracy,
s.combo,
s.time,
s.timePerMove,
s.highestSolved,
s.puzzlesPlayed,
s.newRun,
s.endRun,
s.youPlayTheWhitePiecesInAllPuzzles,
2021-05-19 10:03:19 -06:00
s.youPlayTheBlackPiecesInAllPuzzles,
s.failedPuzzles,
s.slowPuzzles,
2021-10-15 20:47:39 -06:00
s.thisWeek,
s.thisMonth,
s.allTime,
s.clickToReload,
s.thisRunHasExpired,
s.thisRunWasOpenedInAnotherTab,
2021-05-19 10:03:19 -06:00
trans.flipBoard
2021-01-24 11:40:50 -07:00
).map(_.key)
}
2021-01-22 11:37:49 -07:00
}