2019-04-14 03:01:00 -06:00
|
|
|
package views.html
|
|
|
|
package tournament
|
|
|
|
|
|
|
|
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
|
|
|
|
import lila.tournament.{ DataForm, Tournament }
|
2019-04-14 03:01:00 -06:00
|
|
|
|
|
|
|
import controllers.routes
|
|
|
|
|
|
|
|
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(
|
|
|
|
flatpickrTag,
|
2020-01-04 17:36:02 -07:00
|
|
|
delayFlatpickrStartUTC,
|
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"),
|
2020-06-03 20:18:45 -06:00
|
|
|
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(
|
2020-02-14 09:49:53 -07:00
|
|
|
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(
|
2020-02-14 09:49:53 -07:00
|
|
|
a(href := routes.Tournament.show(tour.id))(tour.name()),
|
2019-12-13 07:30:20 -07:00
|
|
|
" ",
|
|
|
|
span("Created by ", usernameOrId(tour.createdBy), " on ", showDate(tour.createdAt))
|
|
|
|
),
|
|
|
|
st.form(
|
|
|
|
cls := "box__top__actions",
|
|
|
|
action := routes.TournamentCrud.cloneT(tour.id),
|
|
|
|
method := "get"
|
|
|
|
)(
|
|
|
|
form3.submit("Clone", "g".some, klass = "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(
|
|
|
|
form3.group(form("date"), frag("Start date ", strong(utcLink)), half = true)(form3.flatpickr(_)),
|
|
|
|
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)(
|
|
|
|
form3.select(_, DataForm.clockTimeChoices)
|
|
|
|
),
|
|
|
|
form3.group(form("clockIncrement"), raw("Clock increment"), half = true)(
|
|
|
|
form3.select(_, DataForm.clockIncrementChoices)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
form3.split(
|
|
|
|
form3.group(form("position"), trans.startPosition(), half = true)(
|
|
|
|
tournament.form.startingPosition(_)
|
|
|
|
),
|
|
|
|
form3.checkbox(
|
|
|
|
form("teamBattle"),
|
|
|
|
raw("Team battle"),
|
|
|
|
half = true
|
|
|
|
)
|
|
|
|
),
|
|
|
|
h2("Entry requirements"),
|
2020-06-03 20:18:45 -06:00
|
|
|
tournament.form.condition(form, new TourFields(form), 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 := "O")
|
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
|
|
|
),
|
|
|
|
tbody(cls := "infinitescroll")(
|
|
|
|
tours.nextPage.map { n =>
|
|
|
|
frag(
|
|
|
|
tr(
|
|
|
|
th(cls := "pager none")(
|
|
|
|
a(rel := "next", href := routes.TournamentCrud.index(n))("Next")
|
|
|
|
)
|
|
|
|
),
|
|
|
|
tr()
|
|
|
|
)
|
|
|
|
},
|
|
|
|
tours.currentPageResults.map { tour =>
|
|
|
|
tr(cls := "paginated")(
|
|
|
|
td(
|
|
|
|
a(href := routes.TournamentCrud.edit(tour.id))(
|
2020-02-14 09:49:53 -07:00
|
|
|
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"),
|
|
|
|
td(showDateTimeUTC(tour.startsAt), " ", momentFromNow(tour.startsAt)),
|
|
|
|
td(a(href := routes.Tournament.show(tour.id), dataIcon := "v", title := "View on site"))
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
2019-04-14 03:01:00 -06:00
|
|
|
)
|
|
|
|
)
|
2019-12-13 07:30:20 -07:00
|
|
|
}
|
2019-04-14 03:01:00 -06:00
|
|
|
}
|