<commit_before>package views.html

import play.api.libs.json.Json

import lila.api.Context
import lila.app.templating.Environment._
import lila.app.ui.ScalatagsTemplate._
import lila.common.String.html.safeJsonValue
import lila.user.User

import controllers.routes

object insight {

  def index(
      u: User,
      cache: lila.insight.InsightUser,
      prefId: Int,
      ui: play.api.libs.json.JsObject,
      question: play.api.libs.json.JsObject,
      stale: Boolean
  )(implicit ctx: Context) =
    views.html.base.layout(
      title = s"${u.username}'s chess insights",
      moreJs = frag(
        highchartsLatestTag,
        jsAt("javascripts/vendor/jquery.min.js"),
        jsAt("javascripts/vendor/multiple-select.min.js"),
        jsModule("insight"),
        jsTag("insight-refresh.js"),
        embedJsUnsafeLoadThen(
          s"""lichess.insight=LichessInsight(document.getElementById('insight'), ${safeJsonValue(
            Json.obj(
              "ui"              -> ui,
              "initialQuestion" -> question,
              "i18n"            -> Json.obj(),
              "myUserId"        -> ctx.userId,
              "user" -> (lila.common.LightUser.lightUserWrites.writes(u.light) ++ Json.obj(
                "nbGames" -> cache.count,
                "stale"   -> stale,
                "shareId" -> prefId
              )),
              "pageUrl" -> routes.Insight.index(u.username).url,
              "postUrl" -> routes.Insight.json(u.username).url
            )
          )})"""
        )
      ),
      moreCss = cssTag("insight")
    )(
      frag(main(id := "insight"))
    )

  def empty(u: User)(implicit ctx: Context) =
    views.html.base.layout(
      title = s"${u.username}'s chess insights",
      moreJs = jsTag("insight-refresh.js"),
      moreCss = cssTag("insight")
    )(
      main(cls := "box box-pad page-small")(
        h1(cls := "text", dataIcon := "")(u.username, " chess insights"),
        p(userLink(u), " has no chess insights yet!"),
        refreshForm(u, s"Generate ${u.username}'s chess insights")
      )
    )

  def forbidden(u: User)(implicit ctx: Context) =
    views.html.site.message(
      title = s"${u.username}'s chess insights are protected",
      back = routes.User.show(u.id).url.some
    )(
      p("Sorry, you cannot see ", userLink(u), "'s chess insights."),
      br,
      p(
        "Maybe ask them to change their ",
        a(cls := "button", href := routes.Pref.form("privacy"))("privacy settings"),
        " ?"
      )
    )

  def refreshForm(u: User, action: String) =
    postForm(cls := "insight-refresh", st.action := routes.Insight.refresh(u.username))(
      button(dataIcon := "", cls := "button text")(action),
      div(cls := "crunching none")(
        spinner,
        br,
        p(strong("Now crunching data just for you!"))
      )
    )
}
<commit_msg>fix insights settings URL - closes #10329<commit_after>package views.html

import play.api.libs.json.Json

import lila.api.Context
import lila.app.templating.Environment._
import lila.app.ui.ScalatagsTemplate._
import lila.common.String.html.safeJsonValue
import lila.user.User

import controllers.routes

object insight {

  def index(
      u: User,
      cache: lila.insight.InsightUser,
      prefId: Int,
      ui: play.api.libs.json.JsObject,
      question: play.api.libs.json.JsObject,
      stale: Boolean
  )(implicit ctx: Context) =
    views.html.base.layout(
      title = s"${u.username}'s chess insights",
      moreJs = frag(
        highchartsLatestTag,
        jsAt("javascripts/vendor/jquery.min.js"),
        jsAt("javascripts/vendor/multiple-select.min.js"),
        jsModule("insight"),
        jsTag("insight-refresh.js"),
        embedJsUnsafeLoadThen(
          s"""lichess.insight=LichessInsight(document.getElementById('insight'), ${safeJsonValue(
            Json.obj(
              "ui"              -> ui,
              "initialQuestion" -> question,
              "i18n"            -> Json.obj(),
              "myUserId"        -> ctx.userId,
              "user" -> (lila.common.LightUser.lightUserWrites.writes(u.light) ++ Json.obj(
                "nbGames" -> cache.count,
                "stale"   -> stale,
                "shareId" -> prefId
              )),
              "pageUrl" -> routes.Insight.index(u.username).url,
              "postUrl" -> routes.Insight.json(u.username).url
            )
          )})"""
        )
      ),
      moreCss = cssTag("insight")
    )(
      frag(main(id := "insight"))
    )

  def empty(u: User)(implicit ctx: Context) =
    views.html.base.layout(
      title = s"${u.username}'s chess insights",
      moreJs = jsTag("insight-refresh.js"),
      moreCss = cssTag("insight")
    )(
      main(cls := "box box-pad page-small")(
        h1(cls := "text", dataIcon := "")(u.username, " chess insights"),
        p(userLink(u), " has no chess insights yet!"),
        refreshForm(u, s"Generate ${u.username}'s chess insights")
      )
    )

  def forbidden(u: User)(implicit ctx: Context) =
    views.html.site.message(
      title = s"${u.username}'s chess insights are protected",
      back = routes.User.show(u.id).url.some
    )(
      p("Sorry, you cannot see ", userLink(u), "'s chess insights."),
      br,
      p(
        "Maybe ask them to change their ",
        a(cls := "button", href := routes.Pref.form("site"))("insights settings"),
        " ?"
      )
    )

  def refreshForm(u: User, action: String) =
    postForm(cls := "insight-refresh", st.action := routes.Insight.refresh(u.username))(
      button(dataIcon := "", cls := "button text")(action),
      div(cls := "crunching none")(
        spinner,
        br,
        p(strong("Now crunching data just for you!"))
      )
    )
}

{'fraction_non_alphanumeric': 0.15253648366921474, 'fraction_numerical': 0.001911049339819319, 'mean_word_length': 2.152792990142388, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3791747', 'n_tokens_mistral': 1878, 'n_tokens_neox': 1823, 'n_words': 349}