lila/app/views/tournament/crud.scala

172 lines
5.6 KiB
Scala
Raw Normal View History

2019-04-14 03:01:00 -06:00
package views.html
package tournament
2020-09-11 10:12:24 -06:00
import controllers.routes
2019-04-14 03:01:00 -06:00
import play.api.data.Form
import lila.api.Context
import lila.app.templating.Environment._
import lila.app.ui.ScalatagsTemplate._
import lila.common.paginator.Paginator
2019-08-21 11:32:50 -06:00
import lila.tournament.crud.CrudForm
2020-09-07 01:56:30 -06:00
import lila.tournament.{ Tournament, TournamentForm }
2019-04-14 03:01:00 -06:00
object crud {
2019-12-13 07:30:20 -07:00
private def layout(title: String, evenMoreJs: Frag = emptyFrag, css: String = "mod.misc")(
body: Frag
)(implicit ctx: Context) =
2019-04-14 03:01:00 -06:00
views.html.base.layout(
title = title,
2019-04-21 08:33:50 -06:00
moreCss = cssTag(css),
2019-04-14 03:01:00 -06:00
moreJs = frag(
2020-09-12 04:30:40 -06:00
jsModule("flatpickr"),
2019-04-14 03:01:00 -06:00
evenMoreJs
)
) {
2019-12-13 07:30:20 -07:00
main(cls := "page-menu")(
views.html.mod.menu("tour"),
body
)
}
2019-04-14 03:01:00 -06:00
2019-12-13 07:30:20 -07:00
def create(form: Form[_])(implicit ctx: Context) =
layout(
title = "New tournament",
css = "mod.form"
) {
div(cls := "crud page-menu__content box box-pad")(
h1("New tournament"),
postForm(cls := "form3", action := routes.TournamentCrud.create)(inForm(form, none))
2019-12-13 07:30:20 -07:00
)
}
2019-04-14 03:01:00 -06:00
2019-12-13 07:30:20 -07:00
def edit(tour: Tournament, form: Form[_])(implicit ctx: Context) =
layout(
title = tour.name(),
2019-12-13 07:30:20 -07:00
css = "mod.form"
) {
div(cls := "crud edit page-menu__content box box-pad")(
div(cls := "box__top")(
h1(
a(href := routes.Tournament.show(tour.id))(tour.name()),
2019-12-13 07:30:20 -07:00
" ",
2021-09-01 03:56:19 -06:00
span("Created by ", titleNameOrId(tour.createdBy), " on ", showDate(tour.createdAt))
2019-12-13 07:30:20 -07:00
),
st.form(
cls := "box__top__actions",
action := routes.TournamentCrud.cloneT(tour.id),
method := "get"
2021-06-21 11:40:09 -06:00
)(form3.submit("Clone", "".some)(cls := "button-green"))
2019-08-21 11:32:50 -06:00
),
2020-01-17 13:05:42 -07:00
standardFlash(),
2020-06-03 20:18:45 -06:00
postForm(cls := "form3", action := routes.TournamentCrud.update(tour.id))(inForm(form, tour.some))
2019-12-13 07:30:20 -07:00
)
}
2019-04-14 03:01:00 -06:00
2020-06-03 20:18:45 -06:00
private def inForm(form: Form[_], tour: Option[Tournament])(implicit ctx: Context) =
2020-05-05 22:11:15 -06:00
frag(
form3.split(
2020-09-12 04:30:40 -06:00
form3.group(form("date"), frag("Start date ", strong(utcLink)), half = true)(
form3.flatpickr(_, utc = true)
),
2020-05-05 22:11:15 -06:00
form3.group(
form("name"),
raw("Name"),
help = raw("Keep it VERY short, so it fits on homepage").some,
half = true
)(form3.input(_))
),
form3.split(
form3.group(
form("homepageHours"),
raw(s"Hours on homepage (0 to ${CrudForm.maxHomepageHours})"),
half = true,
help = raw("Ask on slack first").some
)(form3.input(_, typ = "number")),
form3.group(form("image"), raw("Custom icon"), half = true)(form3.select(_, CrudForm.imageChoices))
),
2019-12-13 07:30:20 -07:00
form3.group(
2020-05-05 22:11:15 -06:00
form("headline"),
raw("Homepage headline"),
help = raw("Keep it VERY short, so it fits on homepage").some
)(form3.input(_)),
form3.group(form("description"), raw("Full description"), help = raw("Link: [text](url)").some)(
form3.textarea(_)(rows := 6)
2019-12-13 07:30:20 -07:00
),
2020-05-05 22:11:15 -06:00
form3.split(
form3.group(form("variant"), raw("Variant"), half = true) { f =>
form3.select(f, translatedVariantChoicesWithVariants.map(x => x._1 -> x._2))
},
form3.group(form("minutes"), raw("Duration in minutes"), half = true)(form3.input(_, typ = "number"))
),
form3.split(
form3.group(form("clockTime"), raw("Clock time"), half = true)(
2020-08-21 14:40:37 -06:00
form3.select(_, TournamentForm.clockTimeChoices)
2020-05-05 22:11:15 -06:00
),
form3.group(form("clockIncrement"), raw("Clock increment"), half = true)(
2020-08-21 14:40:37 -06:00
form3.select(_, TournamentForm.clockIncrementChoices)
2020-05-05 22:11:15 -06:00
)
),
form3.split(
form3.group(form("position"), trans.startPosition(), half = true)(
2020-06-19 04:53:17 -06:00
tournament.form.startingPosition(_, tour)
2020-05-05 22:11:15 -06:00
),
form3.checkbox(
form("teamBattle"),
raw("Team battle"),
half = true
)
),
h2("Entry requirements"),
2020-06-19 04:53:17 -06:00
tournament.form.condition(form, new TourFields(form, tour), auto = false, Nil, tour),
2020-05-05 22:11:15 -06:00
form3.action(form3.submit(trans.apply()))
)
2019-04-14 03:01:00 -06:00
2019-12-13 07:30:20 -07:00
def index(tours: Paginator[Tournament])(implicit ctx: Context) =
layout(
title = "Tournament manager",
evenMoreJs = infiniteScrollTag
) {
div(cls := "crud page-menu__content box")(
div(cls := "box__top")(
h1("Tournament manager"),
div(cls := "box__top__actions")(
a(cls := "button button-green", href := routes.TournamentCrud.form, dataIcon := "")
2019-04-14 03:01:00 -06:00
)
),
2019-12-13 07:30:20 -07:00
table(cls := "slist slist-pad")(
thead(
tr(
th(),
th("Variant"),
th("Clock"),
th("Duration"),
th(utcLink, " Date"),
th()
2019-04-14 03:01:00 -06:00
)
2019-12-13 07:30:20 -07:00
),
2020-09-11 10:12:24 -06:00
tbody(cls := "infinite-scroll")(
2019-12-13 07:30:20 -07:00
tours.currentPageResults.map { tour =>
tr(cls := "paginated")(
td(
a(href := routes.TournamentCrud.edit(tour.id))(
strong(tour.name()),
2019-12-13 07:30:20 -07:00
" ",
em(tour.spotlight.map(_.headline))
)
),
td(tour.variant.name),
td(tour.clock.toString),
td(tour.minutes, "m"),
2020-10-10 03:21:30 -06:00
td(showDateTimeUTC(tour.startsAt), " ", momentFromNow(tour.startsAt, alwaysRelative = true)),
td(a(href := routes.Tournament.show(tour.id), dataIcon := "", title := "View on site"))
2019-12-13 07:30:20 -07:00
)
2020-09-11 10:12:24 -06:00
},
pagerNextTable(tours, np => routes.TournamentCrud.index(np).url)
2019-12-13 07:30:20 -07:00
)
2019-04-14 03:01:00 -06:00
)
)
2019-12-13 07:30:20 -07:00
}
2019-04-14 03:01:00 -06:00
}