<commit_before>package views.html
package tournament

import controllers.routes
import play.api.data.Form

import lila.api.Context
import lila.app.templating.Environment._
import lila.app.ui.ScalatagsTemplate._
import lila.common.paginator.Paginator
import lila.tournament.crud.CrudForm
import lila.tournament.{ Tournament, TournamentForm }

object crud {

  private def layout(title: String, evenMoreJs: Frag = emptyFrag, css: String = "mod.misc")(
      body: Frag
  )(implicit ctx: Context) =
    views.html.base.layout(
      title = title,
      moreCss = cssTag(css),
      moreJs = frag(
        jsModule("flatpickr"),
        evenMoreJs
      )
    ) {
      main(cls := "page-menu")(
        views.html.mod.menu("tour"),
        body
      )
    }

  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))
      )
    }

  def edit(tour: Tournament, form: Form[_])(implicit ctx: Context) =
    layout(
      title = tour.name(),
      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()),
            " ",
            span("Created by ", titleNameOrId(tour.createdBy), " on ", showDate(tour.createdAt))
          ),
          st.form(
            cls                                 := "box__top__actions",
            action                              := routes.TournamentCrud.cloneT(tour.id),
            method                              := "get"
          )(form3.submit("Clone", "".some)(cls := "button-green button-empty"))
        ),
        standardFlash(),
        postForm(cls := "form3", action := routes.TournamentCrud.update(tour.id))(inForm(form, tour.some))
      )
    }

  private def inForm(form: Form[_], tour: Option[Tournament])(implicit ctx: Context) =
    frag(
      form3.split(
        form3.group(form("date"), frag("Start date ", strong(utcLink)), half = true)(
          form3.flatpickr(_, utc = true)
        ),
        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))
      ),
      form3.split(
        form3.group(
          form("headline"),
          raw("Homepage headline"),
          help = raw("Keep it VERY short, so it fits on homepage").some,
          half = true
        )(form3.input(_)),
        form3.group(
          form("id"),
          raw("Tournament ID (in the URL)"),
          help =
            raw("An 8-letter unique tournament ID, can't be changed after the tournament is created.").some,
          half = true
        )(f => form3.input(f)(tour.isDefined.option(disabled := true)))
      ),
      form3.group(form("description"), raw("Full description"), help = raw("Link: [text](url)").some)(
        form3.textarea(_)(rows := 6)
      ),
      form3.split(<commit_msg>fix updating official tournament with custom ID<commit_after>package views.html
package tournament

import controllers.routes
import play.api.data.Form

import lila.api.Context
import lila.app.templating.Environment._
import lila.app.ui.ScalatagsTemplate._
import lila.common.paginator.Paginator
import lila.tournament.crud.CrudForm
import lila.tournament.{ Tournament, TournamentForm }

object crud {

  private def layout(title: String, evenMoreJs: Frag = emptyFrag, css: String = "mod.misc")(
      body: Frag
  )(implicit ctx: Context) =
    views.html.base.layout(
      title = title,
      moreCss = cssTag(css),
      moreJs = frag(
        jsModule("flatpickr"),
        evenMoreJs
      )
    ) {
      main(cls := "page-menu")(
        views.html.mod.menu("tour"),
        body
      )
    }

  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))
      )
    }

  def edit(tour: Tournament, form: Form[_])(implicit ctx: Context) =
    layout(
      title = tour.name(),
      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()),
            " ",
            span("Created by ", titleNameOrId(tour.createdBy), " on ", showDate(tour.createdAt))
          ),
          st.form(
            cls                                 := "box__top__actions",
            action                              := routes.TournamentCrud.cloneT(tour.id),
            method                              := "get"
          )(form3.submit("Clone", "".some)(cls := "button-green button-empty"))
        ),
        standardFlash(),
        postForm(cls := "form3", action := routes.TournamentCrud.update(tour.id))(inForm(form, tour.some))
      )
    }

  private def inForm(form: Form[_], tour: Option[Tournament])(implicit ctx: Context) =
    frag(
      form3.split(
        form3.group(form("date"), frag("Start date ", strong(utcLink)), half = true)(
          form3.flatpickr(_, utc = true)
        ),
        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))
      ),
      form3.split(
        form3.group(
          form("headline"),
          raw("Homepage headline"),
          help = raw("Keep it VERY short, so it fits on homepage").some,
          half = true
        )(form3.input(_)),
        form3.group(
          form("id"),
          raw("Tournament ID (in the URL)"),
          help =
            raw("An 8-letter unique tournament ID, can't be changed after the tournament is created.").some,
          half = true
        )(f => form3.input(f)(tour.isDefined.option(readonly := true)))
      ),
      form3.group(form("description"), raw("Full description"), help = raw("Link: [text](url)").some)(
        form3.textarea(_)(rows := 6)
      ),
      form3.split(
{'fraction_non_alphanumeric': 0.14653964695993277, 'fraction_numerical': 0.007284953768562623, 'mean_word_length': 2.094495015171218, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1339928', 'n_tokens_mistral': 2252, 'n_tokens_neox': 2161, 'n_words': 471}