lila/app/controllers/Dasher.scala

102 lines
2.9 KiB
Scala
Raw Normal View History

2017-05-03 08:22:50 -06:00
package controllers
2017-05-05 04:04:25 -06:00
import play.api.libs.json._
2017-05-03 08:22:50 -06:00
import play.api.mvc._
import scala.collection.breakOut
2017-05-03 08:22:50 -06:00
import lila.api.Context
import lila.app._
2017-05-05 04:04:25 -06:00
import lila.common.LightUser.lightUserWrites
2017-05-03 08:22:50 -06:00
import lila.pref.JsonView._
import lila.i18n.{ I18nKeys, I18nLangPicker, enLang }
2017-05-03 08:22:50 -06:00
object Dasher extends LilaController {
private def translations(implicit ctx: Context) = lila.i18n.JsDump.keysToObject(
2017-05-05 04:04:25 -06:00
ctx.isAnon.fold(
List(
2017-05-26 09:15:15 -06:00
I18nKeys.signIn,
I18nKeys.signUp
2017-05-05 04:04:25 -06:00
),
List(
2017-05-26 09:15:15 -06:00
I18nKeys.profile,
I18nKeys.inbox,
I18nKeys.preferences,
I18nKeys.logOut
2017-05-05 04:04:25 -06:00
)
) ::: List(
2017-05-26 09:15:15 -06:00
I18nKeys.networkLagBetweenYouAndLichess,
I18nKeys.timeToProcessAMoveOnLichessServer,
2017-05-28 10:58:54 -06:00
I18nKeys.sound,
I18nKeys.background,
I18nKeys.light,
I18nKeys.dark,
I18nKeys.transparent,
I18nKeys.backgroundImageUrl,
2017-05-28 10:58:54 -06:00
I18nKeys.boardGeometry,
I18nKeys.boardTheme,
I18nKeys.boardSize,
2017-07-16 05:18:13 -06:00
I18nKeys.pieceSet,
I18nKeys.zenMode
2017-07-15 16:40:00 -06:00
), lila.i18n.I18nDb.Site, ctx.lang
) ++ lila.i18n.JsDump.keysToObject(
// the language settings should never be in a totally foreign language
List(I18nKeys.language),
2017-07-15 16:40:00 -06:00
lila.i18n.I18nDb.Site,
if (I18nLangPicker.allFromRequestHeaders(ctx.req).has(ctx.lang)) ctx.lang
else I18nLangPicker.bestFromRequestHeaders(ctx.req) | enLang
)
2017-05-03 08:22:50 -06:00
def get = Open { implicit ctx =>
negotiate(
html = notFound,
2017-05-05 04:04:25 -06:00
api = _ => Ok {
Json.obj(
"user" -> ctx.me.map(_.light),
"lang" -> Json.obj(
2017-05-26 09:15:15 -06:00
"current" -> ctx.lang.code,
"accepted" -> I18nLangPicker.allFromRequestHeaders(ctx.req).map(_.code)
2017-05-05 04:04:25 -06:00
),
"sound" -> Json.obj(
"list" -> lila.pref.SoundSet.list.map { set =>
s"${set.key} ${set.name}"
}
),
"background" -> Json.obj(
"current" -> ctx.currentBg,
2017-05-06 01:25:17 -06:00
"image" -> ctx.pref.bgImgOrDefault
2017-05-05 04:04:25 -06:00
),
"board" -> Json.obj(
2017-05-05 04:39:04 -06:00
"is3d" -> ctx.pref.is3d,
2017-05-05 04:04:25 -06:00
"zoom" -> ctx.zoom
),
"theme" -> Json.obj(
"d2" -> Json.obj(
"current" -> ctx.currentTheme.name,
2017-05-06 03:04:10 -06:00
"list" -> lila.pref.Theme.all.map(_.name)
2017-05-05 04:04:25 -06:00
),
"d3" -> Json.obj(
"current" -> ctx.currentTheme3d.name,
2017-05-06 03:04:10 -06:00
"list" -> lila.pref.Theme3d.all.map(_.name)
2017-05-05 04:04:25 -06:00
)
),
"piece" -> Json.obj(
"d2" -> Json.obj(
"current" -> ctx.currentPieceSet.name,
2017-05-06 03:04:10 -06:00
"list" -> lila.pref.PieceSet.all.map(_.name)
2017-05-05 04:04:25 -06:00
),
"d3" -> Json.obj(
"current" -> ctx.currentPieceSet3d.name,
2017-05-06 03:04:10 -06:00
"list" -> lila.pref.PieceSet3d.all.map(_.name)
2017-05-03 08:22:50 -06:00
)
2017-05-05 04:04:25 -06:00
),
"kid" -> ctx.me ?? (_.kid),
"coach" -> isGranted(_.Coach),
2017-07-15 02:44:58 -06:00
"zen" -> ctx.pref.zen,
2017-05-05 04:04:25 -06:00
"i18n" -> translations
)
} fuccess
2017-05-03 08:22:50 -06:00
)
}
}