Start http round

This commit is contained in:
Thibault Duplessis 2012-05-16 01:31:57 +02:00
parent 701e4fc78a
commit 1ed5d6b560
8 changed files with 41 additions and 19 deletions

View file

@ -1,7 +1,7 @@
package controllers
import lila._
import user.{ User => UserModel }
import user.{ User UserModel }
import security.{ AuthConfigImpl, Anonymous }
import http.{ Context, BodyContext, HttpEnvironment }
import core.Global
@ -29,10 +29,10 @@ trait LilaController
implicit val current = env.app
override implicit def lang(implicit req: RequestHeader) =
override implicit def lang(implicit req: RequestHeader) =
env.i18n.pool.lang(req)
def toJson(map: Map[String, Any]) = Json generate map
def toJson(map: Map[String, Any]) = Json generate map
def Open(f: Context Result): Action[AnyContent] =
Open(BodyParsers.parse.anyContent)(f)
@ -80,11 +80,14 @@ trait LilaController
data ValidIOk(op(data))
)
def IOk[A](op: IO[A])(implicit writer: Writeable[A], ctype: ContentTypeOf[A]) =
def IOk[A](op: IO[A])(implicit writer: Writeable[A], ctype: ContentTypeOf[A]) =
Ok(op.unsafePerformIO)
def IORedirect(op: IO[Call]) = Redirect(op.unsafePerformIO)
def IOption[A, B](ioa: IO[Option[A]])(op: A B)(implicit writer: Writeable[B], ctype: ContentTypeOf[B]) =
ioa.unsafePerformIO.fold(a Ok(op(a)), NotFound)
// I like Unit requests.
implicit def wUnit: Writeable[Unit] =
Writeable[Unit](_ Codec toUTF8 "ok")

View file

@ -3,7 +3,13 @@ package controllers
import lila._
import views._
import play.api.mvc._
object Round extends LilaController {
def player(playerId: String) = TODO
val gameRepo = env.game.gameRepo
def player(id: String) = Open { implicit ctx
IOption(gameRepo pov id) { html.round.player(_) }
}
}

View file

@ -19,7 +19,7 @@ object Setup extends LilaController {
_ Redirect(routes.Lobby.home),
config IORedirect(
processor ai config map { pov
routes.Round.player(pov.playerId)
routes.Round.player(pov.playerFullId)
}
)
)

View file

@ -9,6 +9,8 @@ case class Pov(game: DbGame, color: Color) {
def playerId = player.id
def playerFullId = game fullIdOf color
def opponent = game player !color
def isPlayerFullId(fullId: Option[String]): Boolean =

View file

@ -0,0 +1,3 @@
@(chat: Option[Html] = None)(body: Html)(implicit ctx: Context)
@base.layout(active = siteMenu.play.some, chat = chat)(body)

View file

@ -0,0 +1,8 @@
@(pov: Pov)(implicit ctx: Context)
@chat = {
}
@round.layout(chat = chat.some) {
@pov
}

View file

@ -2,7 +2,7 @@
GET /games controllers.Game.list
# Round
GET /playerId controllers.Round.player(playerId: String)
GET /$id<[\w\-]{12}> controllers.Round.player(id: String)
# Setting
POST /setting/color controllers.Setting.color

View file

@ -61,20 +61,20 @@ object ApplicationBuild extends Build with Resolvers with Dependencies {
auth,
plugins),
templatesImport ++= Seq(
"lila.game.{ DbGame, DbPlayer }",
"lila.game.{ DbGame, DbPlayer, Pov }",
"lila.user.User",
"lila.templating.Environment._",
"lila.ui.SiteMenu",
"lila.http.Context"),
incrementalAssetsCompilation := true,
javascriptEntryPoints <<= (sourceDirectory in Compile)(base
((base / "assets" / "javascripts" ** "*.js")
--- (base / "assets" / "javascripts" ** "_*")
--- (base / "assets" / "javascripts" / "vendor" ** "*.js")
--- (base / "assets" / "javascripts" ** "*.min.js")
).get
),
lessEntryPoints <<= baseDirectory(_ / "app" / "assets" / "stylesheets" ** "*.less")
"lila.http.Context")
//incrementalAssetsCompilation := true,
//javascriptEntryPoints <<= (sourceDirectory in Compile)(base
//((base / "assets" / "javascripts" ** "*.js")
//--- (base / "assets" / "javascripts" ** "_*")
//--- (base / "assets" / "javascripts" / "vendor" ** "*.js")
//--- (base / "assets" / "javascripts" ** "*.min.js")
//).get
//),
//lessEntryPoints <<= baseDirectory(_ / "app" / "assets" / "stylesheets" ** "*.less")
) dependsOn chess
lazy val cli = Project("cli", file("cli"), settings = buildSettings).settings(