lila/app/controllers/Dasher.scala

90 lines
2.3 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._
2017-05-26 09:15:15 -06:00
import lila.i18n.I18nKeys
2017-05-03 08:22:50 -06:00
object Dasher extends LilaController {
2017-05-05 04:04:25 -06:00
private def translations(implicit ctx: Context) = Env.i18n.jsDump.keysToObject(
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.boardGeometry,
I18nKeys.boardTheme,
I18nKeys.boardSize,
I18nKeys.pieceSet
2017-05-26 09:15:15 -06:00
), ctx.lang
2017-05-05 04:04:25 -06:00
)
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,
2017-05-26 11:16:30 -06:00
"accepted" -> lila.i18n.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),
"i18n" -> translations
)
} fuccess
2017-05-03 08:22:50 -06:00
)
}
}