get it to compile with latest play
This commit is contained in:
parent
3fb4072e56
commit
c0f410fdd5
|
@ -26,7 +26,7 @@ private[analyse] final class PgnDump(
|
|||
pgn2 = (~fenSituation.map(_.situation.color.black)).fold(".. " + pgn, pgn)
|
||||
pgnObj = Pgn(ts, turns(pgn2, fenSituation.map(_.fullMoveNumber) | 1))
|
||||
analysis ← analyser get game.id
|
||||
} yield analysis.fold(pgnObj)(Annotator(pgnObj, _))
|
||||
} yield analysis.fold(pgnObj)(annotator(pgnObj, _))
|
||||
|
||||
def filename(game: DbGame): IO[String] = for {
|
||||
whiteUser ← user(game.whitePlayer)
|
||||
|
|
|
@ -17,9 +17,9 @@ final class BookmarkApi(
|
|||
gameOption ← gameRepo game gameId
|
||||
_ ← ~gameOption.map(game =>
|
||||
for {
|
||||
bookmarked ← bookmarkRepo.toggle(game.id, user.id)
|
||||
_ ← gameRepo.incBookmarks(game.id, bookmarked.fold(1, -1))
|
||||
_ ← io(cached invalidateUserId user.id)
|
||||
bookmarked ← bookmarkRepo.toggle(gameId, userId)
|
||||
_ ← gameRepo.incBookmarks(gameId, bookmarked.fold(1, -1))
|
||||
_ ← io(cached invalidateUserId userId)
|
||||
} yield ()
|
||||
)
|
||||
} yield ()
|
||||
|
|
|
@ -30,20 +30,18 @@ private[cli] case class Teams(env: TeamEnv, userRepo: UserRepo) {
|
|||
|
||||
private def perform(teamId: String)(op: Team ⇒ IO[Unit]) = for {
|
||||
teamOption ← teamRepo byId teamId
|
||||
res ← teamOption.fold(
|
||||
u ⇒ op(u) inject "Success",
|
||||
io("Team not found")
|
||||
)
|
||||
res ← teamOption.fold(io("Team not found")) { u ⇒
|
||||
op(u) inject "Success"
|
||||
}
|
||||
} yield res
|
||||
|
||||
private def perform2(teamId: String, userIds: List[String])(op: (Team, String) ⇒ IO[Unit]) = for {
|
||||
teamOption ← teamRepo byId teamId
|
||||
res ← teamOption.fold(
|
||||
team ⇒ for {
|
||||
res ← teamOption.fold(io("Team not found")) { team ⇒
|
||||
for {
|
||||
users ← userRepo byIds userIds
|
||||
_ ← users.map(user ⇒ putStrLn(user.username) >> op(team, user.id)).sequence
|
||||
} yield "Success",
|
||||
io("Team not found")
|
||||
)
|
||||
} yield "Success"
|
||||
}
|
||||
} yield res
|
||||
}
|
||||
|
|
|
@ -14,11 +14,10 @@ private[cli] case class Users(userEnv: UserEnv, deleteUsername: String ⇒ IO[Un
|
|||
|
||||
def roles(username: String): IO[String] = for {
|
||||
userOption ← userRepo byId username
|
||||
} yield userOption.fold(_.roles mkString " ", "User not found")
|
||||
} yield userOption.fold("User not found")(_.roles mkString " ")
|
||||
|
||||
def grant(username: String, roles: List[String]): IO[String] =
|
||||
perform(username, { user ⇒
|
||||
userRepo.setRoles(user, roles map (_.toUpperCase))
|
||||
def grant(username: String, roles: List[String]): IO[String] = perform(username, { user ⇒ userRepo.setRoles(user, roles map
|
||||
(_.toUpperCase))
|
||||
})
|
||||
|
||||
def enable(username: String): IO[String] =
|
||||
|
@ -41,9 +40,6 @@ private[cli] case class Users(userEnv: UserEnv, deleteUsername: String ⇒ IO[Un
|
|||
|
||||
private def perform(username: String, op: User ⇒ IO[Unit]): IO[String] = for {
|
||||
userOption ← userRepo byId username
|
||||
res ← userOption.fold(
|
||||
u ⇒ op(u) inject "Success",
|
||||
io("User not found")
|
||||
)
|
||||
res ← userOption.fold(io("User not found")) { u ⇒ op(u) inject "Success" }
|
||||
} yield res
|
||||
}
|
||||
|
|
|
@ -74,8 +74,8 @@ object Analyse extends LilaController {
|
|||
gameOption ← gameRepo game id
|
||||
res ← gameOption.fold(io(NotFound("No such game"))) { game ⇒
|
||||
for {
|
||||
pgnString ← game.pgnImport.map(_.pgn).fold(io(_), pgnRepo get id)
|
||||
content ← game.pgnImport.map(_.pgn).fold(io(_), pgnDump(game, pgnString) map (_.toString))
|
||||
pgnString ← game.pgnImport.map(_.pgn).fold(pgnRepo get id)(io(_))
|
||||
content ← game.pgnImport.map(_.pgn).fold(pgnDump(game, pgnString) map (_.toString))(io(_))
|
||||
filename ← pgnDump filename game
|
||||
} yield Ok(content).withHeaders(
|
||||
CONTENT_LENGTH -> content.size.toString,
|
||||
|
|
|
@ -7,6 +7,7 @@ import http.Context
|
|||
import play.api.mvc.Result
|
||||
import play.api.libs.concurrent._
|
||||
import play.api.Play.current
|
||||
import play.api.libs.concurrent.Execution.Implicits._
|
||||
|
||||
object Importer extends LilaController with BaseGame {
|
||||
|
||||
|
@ -25,11 +26,10 @@ object Importer extends LilaController with BaseGame {
|
|||
Ok(html.game.importGame(makeListMenu, failure))
|
||||
},
|
||||
data ⇒ (importer(data, ctx.userId) map {
|
||||
_.fold(
|
||||
game ⇒ Redirect(routes.Analyse.replay(game.id, "white")),
|
||||
Redirect(routes.Importer.importGame)
|
||||
)
|
||||
}).asPromise
|
||||
_.fold(Redirect(routes.Importer.importGame)) { game =>
|
||||
Redirect(routes.Analyse.replay(game.id, "white"))
|
||||
}
|
||||
})
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -78,12 +78,10 @@ trait LilaController
|
|||
protected def NoEngine[A <: Result](a: ⇒ A)(implicit ctx: Context): Result =
|
||||
ctx.me.fold(false)(_.engine).fold(Forbidden(views.html.site.noEngine()), a)
|
||||
|
||||
protected def JsonOk[A: WritesJson](data: A) = Ok(Json toJson data) as JSON
|
||||
protected def JsonOk[A: WritesJson](data: A) = Ok(toJson(data)) as JSON
|
||||
|
||||
protected def JsonIOk[A: WritesJson](data: IO[A]) = JsonOk(data.unsafePerformIO)
|
||||
|
||||
protected def JsonIOk(map: IO[Map[String, Any]]) = JsonOk(map.unsafePerformIO)
|
||||
|
||||
protected def JsIOk(js: IO[String], headers: (String, String)*) =
|
||||
JsOk(js.unsafePerformIO, headers: _*)
|
||||
|
||||
|
@ -163,7 +161,7 @@ trait LilaController
|
|||
|
||||
protected def IOptionIORedirectUrl[A](ioa: IO[Option[A]])(op: A ⇒ IO[String])(implicit ctx: Context) =
|
||||
(ioa flatMap {
|
||||
_.fold(a ⇒ op(a) map { b ⇒ Redirect(b) }, io(notFound(ctx)))
|
||||
_.fold(io(notFound(ctx)))(a ⇒ op(a) map { b ⇒ Redirect(b) })
|
||||
}: IO[Result]).unsafePerformIO
|
||||
|
||||
protected def IOptionResult[A](ioa: IO[Option[A]])(op: A ⇒ Result)(implicit ctx: Context) =
|
||||
|
|
|
@ -5,7 +5,7 @@ import views._
|
|||
import http.{ Context, BodyContext, Setting ⇒ HttpSetting }
|
||||
|
||||
import play.api.data.Form
|
||||
import play.api.mvc.Cookie
|
||||
import play.api.mvc.{ Result, Cookie }
|
||||
import scalaz.effects._
|
||||
|
||||
object Setting extends LilaController {
|
||||
|
@ -15,7 +15,7 @@ object Setting extends LilaController {
|
|||
|
||||
def set(name: String) = OpenBody { implicit ctx ⇒
|
||||
implicit val req = ctx.body
|
||||
(setters get name).fold(NotFound) {
|
||||
(setters get name).fold(NotFound: Result) {
|
||||
case (form, process) ⇒
|
||||
FormResult(form) { value ⇒
|
||||
Ok() withCookies process(HttpSetting(ctx), value).unsafePerformIO
|
||||
|
|
|
@ -5,7 +5,7 @@ import views._
|
|||
import setup._
|
||||
import http.{ Context, BodyContext }
|
||||
|
||||
import play.api.mvc.Call
|
||||
import play.api.mvc.{ Result, Call }
|
||||
import play.api.data.Form
|
||||
|
||||
import scalaz.effects._
|
||||
|
@ -119,7 +119,7 @@ object Setup extends LilaController with TheftPrevention with RoundEventPerforme
|
|||
if (parsed.situation playable strict)
|
||||
validated = chess.format.Forsyth >> parsed
|
||||
} yield html.game.miniBoard(validated, parsed.situation.color.name)
|
||||
} fold (Ok(_), BadRequest)
|
||||
}.fold(BadRequest: Result)(Ok(_))
|
||||
}
|
||||
|
||||
private def process[A](form: Context ⇒ Form[A])(op: A ⇒ BodyContext ⇒ IO[Call]) =
|
||||
|
|
|
@ -96,10 +96,9 @@ object Team extends LilaController {
|
|||
implicit val req = ctx.body
|
||||
forms.create.bindFromRequest.fold(
|
||||
err ⇒ io(BadRequest(html.team.form(err, forms.captchaCreate))),
|
||||
data ⇒ api.create(data, me).fold(
|
||||
_ map { team ⇒ Redirect(routes.Team.show(team.id)) },
|
||||
io(notFound)
|
||||
)
|
||||
data ⇒ api.create(data, me).fold(io(notFound)) {
|
||||
_ map { team ⇒ Redirect(routes.Team.show(team.id)) }
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import play.api.libs.json._
|
|||
import play.api.libs.iteratee._
|
||||
import play.api.libs.concurrent._
|
||||
import play.api.templates.Html
|
||||
import play.api.libs.concurrent.Execution.Implicits._
|
||||
|
||||
object Tournament extends LilaController {
|
||||
|
||||
|
@ -29,7 +30,7 @@ object Tournament extends LilaController {
|
|||
futureTournaments zip userRepo.sortedByToints(10).toFuture map {
|
||||
case (((created, started), finished), leaderboard) ⇒
|
||||
Ok(html.tournament.home(created, started, finished, leaderboard))
|
||||
} asPromise
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -40,7 +41,7 @@ object Tournament extends LilaController {
|
|||
futureTournaments map {
|
||||
case ((created, started), finished) ⇒
|
||||
Ok(html.tournament.homeInner(created, started, finished))
|
||||
} asPromise
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ trait ForumGranter {
|
|||
|
||||
def isGrantedWrite(categSlug: String)(implicit ctx: Context): Boolean = categSlug match {
|
||||
case StaffSlug ⇒ ctx.me exists { u ⇒ Granter(Permission.StaffForum)(u) }
|
||||
case TeamSlugPattern(teamId) ⇒ ctx.me.fold(me ⇒ userBelongsToTeam(teamId, me.id), false)
|
||||
case TeamSlugPattern(teamId) ⇒ ~ctx.me.map(me ⇒ userBelongsToTeam(teamId, me.id))
|
||||
case _ ⇒ true
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ package forum
|
|||
import search.{ ElasticSearch, TypeIndexer }
|
||||
|
||||
import scalaz.effects._
|
||||
import com.codahale.jerkson.Json
|
||||
|
||||
import org.elasticsearch.action.search.SearchResponse
|
||||
import org.elasticsearch.index.query._, QueryBuilders._
|
||||
|
@ -12,6 +11,8 @@ import org.elasticsearch.index.query._, QueryBuilders._
|
|||
import scalastic.elasticsearch.{ Indexer ⇒ EsIndexer }
|
||||
import com.mongodb.casbah.query.Imports._
|
||||
|
||||
import play.api.libs.json._
|
||||
|
||||
private[forum] final class SearchIndexer(
|
||||
es: EsIndexer,
|
||||
postApi: PostApi,
|
||||
|
|
|
@ -2,6 +2,7 @@ package lila
|
|||
package forum
|
||||
|
||||
import search.ElasticSearch._
|
||||
import play.api.libs.json._
|
||||
|
||||
private[forum] object SearchMapping {
|
||||
|
||||
|
@ -15,18 +16,18 @@ private[forum] object SearchMapping {
|
|||
import fields._
|
||||
import Mapping._
|
||||
|
||||
def mapping = Map(
|
||||
"properties" -> List(
|
||||
def mapping = Json.obj(
|
||||
"properties" -> Json.toJson(List(
|
||||
boost(body, "string", 2),
|
||||
boost(topic, "string", 4),
|
||||
boost(author, "string"),
|
||||
field(topicId, "string"),
|
||||
field(staff, "boolean")
|
||||
).toMap,
|
||||
"analyzer" -> "snowball"
|
||||
).toMap),
|
||||
"analyzer" -> Json.toJson("snowball")
|
||||
)
|
||||
|
||||
def apply(view: PostLiteView): Pair[String, Map[String, Any]] = view.post.id -> Map(
|
||||
def apply(view: PostLiteView): Pair[String, JsObject] = view.post.id -> Json.obj(
|
||||
body -> view.post.text,
|
||||
topic -> view.topic.name,
|
||||
author -> ~(view.post.userId orElse view.post.author),
|
||||
|
|
|
@ -130,14 +130,15 @@ case class DbGame(
|
|||
def copyPlayer(player: DbPlayer) = player.copy(
|
||||
ps = player encodePieces game.allPieces,
|
||||
blurs = player.blurs + (blur && move.color == player.color).fold(1, 0),
|
||||
moveTimes = ((!isPgnImport) && (move.color == player.color)).fold(player.moveTimes) {
|
||||
lastMoveTime.fold("") { lmt ⇒
|
||||
moveTimes = ((!isPgnImport) && (move.color == player.color)).fold(
|
||||
lastMoveTime.fold("") { lmt ⇒
|
||||
(nowSeconds - lmt) |> { mt ⇒
|
||||
val encoded = MoveTime encode mt
|
||||
player.moveTimes.isEmpty.fold(encoded.toString, player.moveTimes + encoded)
|
||||
}
|
||||
}
|
||||
}
|
||||
}, player.moveTimes
|
||||
)
|
||||
)
|
||||
|
||||
val updated = copy(
|
||||
whitePlayer = copyPlayer(whitePlayer),
|
||||
|
@ -358,7 +359,7 @@ case class DbGame(
|
|||
|
||||
def source = metadata map (_.source)
|
||||
|
||||
def pgnImport = metadata flatMap(_.pgnImport)
|
||||
def pgnImport = metadata flatMap (_.pgnImport)
|
||||
|
||||
def isPgnImport = pgnImport.isDefined
|
||||
|
||||
|
|
|
@ -45,9 +45,9 @@ final class Export(user: User, gameRepo: GameRepo, netBaseUrl: String) {
|
|||
(player flatMap (_.eloDiff)).fold("?")(showEloDiff),
|
||||
(player map game.opponent flatMap (_.elo)).fold("?")(_.toString),
|
||||
(player map game.opponent flatMap (_.eloDiff)).fold("?")(showEloDiff),
|
||||
baseUrl + routes.Round.watcher(game.id, player.fold("white")(_.color.name)),
|
||||
baseUrl + routes.Analyse.replay(game.id, player.fold("white")(_.color.name)),
|
||||
baseUrl + routes.Analyse.pgn(game.id)
|
||||
netBaseUrl + routes.Round.watcher(game.id, player.fold("white")(_.color.name)),
|
||||
netBaseUrl + routes.Analyse.replay(game.id, player.fold("white")(_.color.name)),
|
||||
netBaseUrl + routes.Analyse.pgn(game.id)
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -13,12 +13,10 @@ final class Rewind {
|
|||
initialFen: Option[String]): Valid[(Progress, String)] = chessPgn.Reader.withSans(
|
||||
pgn = pgn,
|
||||
op = _.init,
|
||||
tags = initialFen.fold(
|
||||
fen ⇒ List(
|
||||
chessPgn.Tag(_.FEN, fen),
|
||||
chessPgn.Tag(_.Variant, game.variant.name)
|
||||
),
|
||||
Nil)
|
||||
tags = ~initialFen.map(fen ⇒ List(
|
||||
chessPgn.Tag(_.FEN, fen),
|
||||
chessPgn.Tag(_.Variant, game.variant.name)
|
||||
))
|
||||
) map { replay ⇒
|
||||
val rewindedGame = replay.game
|
||||
val rewindedHistory = rewindedGame.board.history
|
||||
|
|
|
@ -44,8 +44,9 @@ case class ImportData(pgn: String) {
|
|||
|
||||
val date = tag(_.Date)
|
||||
|
||||
def name(whichName: TagPicker, whichElo: TagPicker): String =
|
||||
tag(whichName).fold(n ⇒ n.value + tag(whichElo).fold(e ⇒ " (%s)" format e, ""), "?")
|
||||
def name(whichName: TagPicker, whichElo: TagPicker): String = tag(whichName).fold("?") { n ⇒
|
||||
n.value + ~tag(whichElo).map(e ⇒ " (%s)" format e)
|
||||
}
|
||||
|
||||
val dbGame = DbGame(
|
||||
game = Game(board = initBoard | (Board init variant)),
|
||||
|
|
|
@ -7,7 +7,7 @@ import game.{ DbGame, GameRepo, PovRef }
|
|||
import round.{ Hand, Finisher }
|
||||
|
||||
import scalaz.effects._
|
||||
import akka.dispatch.Future
|
||||
import scala.concurrent.Future
|
||||
|
||||
final class Importer(
|
||||
gameRepo: GameRepo,
|
||||
|
@ -38,7 +38,7 @@ final class Importer(
|
|||
|
||||
private def gameExists(pgn: String)(processing: ⇒ Future[Option[DbGame]]): Future[Option[DbGame]] =
|
||||
gameRepo.game(game.Query pgnImport pgn).toFuture flatMap {
|
||||
_.fold(game ⇒ Future(game.some), processing)
|
||||
_.fold(processing)(game ⇒ Future(game.some))
|
||||
}
|
||||
|
||||
private def finish(game: DbGame, result: Result): Future[Unit] = result match {
|
||||
|
|
|
@ -49,7 +49,7 @@ case class Hook(
|
|||
"engine" -> engine
|
||||
)
|
||||
|
||||
def clockOrUnlimited = clockOption.fold(c ⇒ renderClock(c.limit, c.increment), "Unlimited")
|
||||
def clockOrUnlimited = clockOption.fold("Unlimited")(c ⇒ renderClock(c.limit, c.increment))
|
||||
|
||||
private def clockOption = (time filter (_ ⇒ hasClock)) |@| increment apply Clock.apply
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ private[lobby] final class Preload(
|
|||
|
||||
private implicit val executor = Akka.system.dispatcher
|
||||
private implicit val timeout = Timeout(1 second)
|
||||
private type RightResponse = (JsObject, List[PostView], List[Created], Option[DbGame])
|
||||
private type RightResponse = (JsObject, List[PostLiteView], List[Created], Option[DbGame])
|
||||
private type Response = Either[Call, RightResponse]
|
||||
|
||||
def apply(
|
||||
|
|
|
@ -34,8 +34,8 @@ final class Api(
|
|||
val thread = Thread.make(
|
||||
name = data.subject,
|
||||
text = data.text,
|
||||
creator = me.id,
|
||||
invited = data.user.id)
|
||||
creatorId = me.id,
|
||||
invitedId = data.user.id)
|
||||
(threadRepo saveIO thread) >> updateUser(data.user.id) inject thread
|
||||
}
|
||||
|
||||
|
|
|
@ -6,10 +6,10 @@ case class LichessThread(
|
|||
subject: String,
|
||||
message: String) {
|
||||
|
||||
def toThread: Thread = Thread(
|
||||
def toThread: Thread = Thread.make(
|
||||
name = subject,
|
||||
text = message,
|
||||
creator = "lichess",
|
||||
invited = to
|
||||
creatorId = "lichess",
|
||||
invitedId = to
|
||||
)
|
||||
}
|
||||
|
|
|
@ -53,8 +53,8 @@ object Thread {
|
|||
def make(
|
||||
name: String,
|
||||
text: String,
|
||||
creator: String,
|
||||
invited: String): Thread = Thread(
|
||||
creatorId: String,
|
||||
invitedId: String): Thread = Thread(
|
||||
id = Random nextString idSize,
|
||||
name = name,
|
||||
createdAt = DateTime.now,
|
||||
|
@ -63,9 +63,9 @@ object Thread {
|
|||
text = text,
|
||||
isByCreator = true
|
||||
)),
|
||||
creatorId = creator,
|
||||
invitedId = invited,
|
||||
visibleByUserIds = List(creator.id, invited.id))
|
||||
creatorId = creatorId,
|
||||
invitedId = invitedId,
|
||||
visibleByUserIds = List(creatorId, invitedId))
|
||||
|
||||
import play.api.libs.json._
|
||||
import play.api.libs.functional.syntax._
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package lila
|
||||
package search
|
||||
|
||||
import play.api.libs.json._
|
||||
|
||||
object ElasticSearch {
|
||||
|
||||
object Date {
|
||||
|
@ -14,17 +16,17 @@ object ElasticSearch {
|
|||
|
||||
object Mapping {
|
||||
|
||||
def field(name: String, typ: String, analyzed: Boolean = false, attrs: Map[String, Any] = Map.empty) =
|
||||
name -> (Map(
|
||||
def field(name: String, typ: String, analyzed: Boolean = false, attrs: JsObject = Json.obj()) =
|
||||
name -> (Json.obj(
|
||||
"type" -> typ,
|
||||
"index" -> analyzed.fold("analyzed", "not_analyzed")
|
||||
) ++ attrs)
|
||||
|
||||
def boost(name: String, typ: String, b: Int = 1, attrs: Map[String, Any] = Map.empty) =
|
||||
field(name, typ, true, Map("boost" -> b) ++ attrs)
|
||||
def boost(name: String, typ: String, b: Int = 1, attrs: JsObject = Json.obj()) =
|
||||
field(name, typ, true, Json.obj("boost" -> b) ++ attrs)
|
||||
|
||||
def obj(name: String, properties: Map[String, Any]) =
|
||||
name -> Map("type" -> "object", "properties" -> properties)
|
||||
def obj(name: String, properties: JsObject) =
|
||||
name -> Json.obj("type" -> "object", "properties" -> properties)
|
||||
}
|
||||
|
||||
object Request {
|
||||
|
|
|
@ -7,7 +7,6 @@ import chess.{ OpeningExplorer, Status }
|
|||
|
||||
import play.api.libs.json.{ Json, JsObject, JsString, JsNumber }
|
||||
|
||||
object Game {
|
||||
private[search] object Game {
|
||||
|
||||
object fields {
|
||||
|
|
|
@ -5,12 +5,12 @@ import ElasticSearch.Request
|
|||
import game.{ GameRepo, PgnRepo, DbGame, Query ⇒ GameQuery }
|
||||
|
||||
import scalaz.effects._
|
||||
import com.codahale.jerkson.Json
|
||||
|
||||
import org.elasticsearch.action.search.SearchResponse
|
||||
|
||||
import scalastic.elasticsearch.{ Indexer ⇒ EsIndexer }
|
||||
import com.mongodb.casbah.query.Imports._
|
||||
import play.api.libs.json.Json
|
||||
|
||||
final class GameIndexer(
|
||||
es: EsIndexer,
|
||||
|
@ -21,7 +21,7 @@ final class GameIndexer(
|
|||
val indexName = "lila"
|
||||
val typeName = "game"
|
||||
|
||||
private val indexer = new TypeIndexer(es, typeName, Game.mapping, indexQuery)
|
||||
private val indexer = new TypeIndexer(es, typeName, Game.jsonMapping, indexQuery)
|
||||
|
||||
val rebuildAll = indexer.rebuildAll
|
||||
|
||||
|
@ -51,7 +51,7 @@ final class GameIndexer(
|
|||
case (game, pgn) ⇒ game.decode map Game.from(pgn)
|
||||
} collect {
|
||||
case Some((id, doc)) ⇒
|
||||
es.index_prepare(indexName, typeName, id, Json generate doc).request
|
||||
es.index_prepare(indexName, typeName, id, Json stringify doc).request
|
||||
}
|
||||
if (actions.nonEmpty) {
|
||||
es bulk actions
|
||||
|
|
|
@ -2,7 +2,6 @@ package lila
|
|||
package search
|
||||
|
||||
import scalaz.effects._
|
||||
import com.codahale.jerkson.Json
|
||||
|
||||
import org.elasticsearch.action.search.SearchResponse
|
||||
|
||||
|
@ -10,17 +9,18 @@ import scalastic.elasticsearch.{ Indexer ⇒ EsIndexer }
|
|||
import com.mongodb.casbah.query.Imports._
|
||||
|
||||
import akka.actor._
|
||||
import akka.util.duration._
|
||||
import akka.util.Timeout
|
||||
import akka.pattern.{ ask, pipe }
|
||||
import akka.dispatch.{ Future, Promise }
|
||||
import scala.concurrent.duration._
|
||||
import scala.concurrent.{ Future, Promise }
|
||||
import play.api.libs.concurrent._
|
||||
import play.api.libs.json._
|
||||
import play.api.Play.current
|
||||
|
||||
final class TypeIndexer(
|
||||
es: EsIndexer,
|
||||
typeName: String,
|
||||
mapping: Map[String, Any],
|
||||
mapping: JsObject,
|
||||
indexQuery: DBObject ⇒ Unit) {
|
||||
|
||||
private val indexName = "lila"
|
||||
|
@ -35,17 +35,17 @@ final class TypeIndexer(
|
|||
|
||||
val clear: IO[Unit] = io { actor ! Clear }
|
||||
|
||||
def insertOne(id: String, doc: Map[String, Any]) = io { actor ! InsertOne(id, doc) }
|
||||
def insertOne(id: String, doc: JsObject) = io { actor ! InsertOne(id, doc) }
|
||||
|
||||
def insertMany(list: Map[String, Map[String, Any]]) = io { actor ! InsertMany(list) }
|
||||
def insertMany(list: Map[String, JsObject]) = io { actor ! InsertMany(list) }
|
||||
|
||||
def removeOne(id: String) = io { actor ! RemoveOne(id) }
|
||||
|
||||
private case object Clear
|
||||
private case object RebuildAll
|
||||
private case object Optimize
|
||||
private case class InsertOne(id: String, doc: Map[String, Any])
|
||||
private case class InsertMany(list: Map[String, Map[String, Any]])
|
||||
private case class InsertOne(id: String, doc: JsObject)
|
||||
private case class InsertMany(list: Map[String, JsObject])
|
||||
private case class RemoveOne(id: String)
|
||||
|
||||
private lazy val actor = Akka.system.actorOf(Props(new Actor {
|
||||
|
@ -61,11 +61,11 @@ final class TypeIndexer(
|
|||
|
||||
case Optimize ⇒ es.optimize(Seq(indexName))
|
||||
|
||||
case InsertOne(id, doc) ⇒ es.index(indexName, typeName, id, Json generate doc)
|
||||
case InsertOne(id, doc) ⇒ es.index(indexName, typeName, id, Json stringify doc)
|
||||
|
||||
case InsertMany(list) ⇒ es bulk {
|
||||
list map {
|
||||
case (id, doc) ⇒ es.index_prepare(indexName, typeName, id, Json generate doc).request
|
||||
case (id, doc) ⇒ es.index_prepare(indexName, typeName, id, Json stringify doc).request
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -77,7 +77,7 @@ final class TypeIndexer(
|
|||
es.createIndex(indexName, settings = Map())
|
||||
}
|
||||
catch {
|
||||
case e: org.elasticsearch.indices.IndexAlreadyExistsException ⇒
|
||||
case e: org.elasticsearch.indices.IndexAlreadyExistsException ⇒
|
||||
}
|
||||
try {
|
||||
es.deleteByQuery(Seq(indexName), Seq(typeName))
|
||||
|
@ -85,9 +85,9 @@ final class TypeIndexer(
|
|||
es.deleteMapping(indexName :: Nil, typeName.some)
|
||||
}
|
||||
catch {
|
||||
case e: org.elasticsearch.indices.TypeMissingException ⇒
|
||||
case e: org.elasticsearch.indices.TypeMissingException ⇒
|
||||
}
|
||||
es.putMapping(indexName, typeName, Json generate Map(typeName -> mapping))
|
||||
es.putMapping(indexName, typeName, Json stringify Json.obj(typeName -> mapping))
|
||||
es.refresh()
|
||||
}
|
||||
}))
|
||||
|
|
|
@ -46,17 +46,17 @@ trait Positional { self: Config ⇒
|
|||
|
||||
def fenDbGame(builder: Game ⇒ DbGame): DbGame = {
|
||||
val state = fen filter (_ ⇒ variant == Variant.FromPosition) flatMap Forsyth.<<<
|
||||
val chessGame = state.fold({
|
||||
val chessGame = state.fold(makeGame) {
|
||||
case sit @ SituationPlus(Situation(board, color), _) ⇒
|
||||
Game(board = board, player = color, turns = sit.turns)
|
||||
}, makeGame)
|
||||
}
|
||||
val dbGame = builder(chessGame)
|
||||
state.fold({
|
||||
state.fold(dbGame) {
|
||||
case sit @ SituationPlus(Situation(board, _), _) ⇒ dbGame.copy(
|
||||
variant = Variant.FromPosition,
|
||||
castles = board.history.castleNotation,
|
||||
turns = sit.turns)
|
||||
}, dbGame)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package lila
|
|||
package setup
|
||||
|
||||
import chess.{ Variant, Mode, Speed }
|
||||
import play.api.libs.json._
|
||||
|
||||
case class FilterConfig(
|
||||
variant: Option[Variant],
|
||||
|
@ -25,7 +26,7 @@ case class FilterConfig(
|
|||
eloDiff.some
|
||||
).some
|
||||
|
||||
def render = Map(
|
||||
def render = Json.obj(
|
||||
"variant" -> variant.map(_.toString),
|
||||
"mode" -> mode.map(_.toString),
|
||||
"speed" -> speed.map(_.id),
|
||||
|
|
|
@ -33,10 +33,9 @@ private[setup] final class FormFactory(
|
|||
|
||||
def aiFilled(fen: Option[String])(implicit ctx: Context): IO[Form[AiConfig]] =
|
||||
aiConfig map { config ⇒
|
||||
ai(ctx) fill fen.fold(
|
||||
f ⇒ config.copy(fen = f.some, variant = Variant.FromPosition),
|
||||
config
|
||||
)
|
||||
ai(ctx) fill fen.fold(config) { f ⇒
|
||||
config.copy(fen = f.some, variant = Variant.FromPosition)
|
||||
}
|
||||
}
|
||||
|
||||
def ai(ctx: Context) = Form(
|
||||
|
@ -55,10 +54,9 @@ private[setup] final class FormFactory(
|
|||
|
||||
def friendFilled(fen: Option[String])(implicit ctx: Context): IO[Form[FriendConfig]] =
|
||||
friendConfig map { config ⇒
|
||||
friend(ctx) fill fen.fold(
|
||||
f ⇒ config.copy(fen = f.some, variant = Variant.FromPosition),
|
||||
config
|
||||
)
|
||||
friend(ctx) fill fen.fold(config) { f ⇒
|
||||
config.copy(fen = f.some, variant = Variant.FromPosition)
|
||||
}
|
||||
}
|
||||
|
||||
def friend(ctx: Context) = Form(
|
||||
|
|
|
@ -65,8 +65,6 @@ final class SetupEnv(
|
|||
timelinePush = timelinePush,
|
||||
messenger = roundMessenger)
|
||||
|
||||
def filter(implicit ctx: http.Context): IO[FilterConfig] = ctx.me.fold(
|
||||
userConfigRepo.filter,
|
||||
anonConfigRepo filter ctx.req
|
||||
)
|
||||
def filter(implicit ctx: http.Context): IO[FilterConfig] =
|
||||
ctx.me.fold(anonConfigRepo filter ctx.req)(userConfigRepo.filter)
|
||||
}
|
||||
|
|
|
@ -92,7 +92,9 @@ abstract class HubActor[M <: SocketMember](uidTimeout: Int) extends Actor {
|
|||
protected def resync(member: M) {
|
||||
import play.api.libs.concurrent._
|
||||
import play.api.Play.current
|
||||
import akka.util.duration._
|
||||
import scala.concurrent.duration._
|
||||
import play.api.libs.concurrent.Execution.Implicits._
|
||||
|
||||
Akka.system.scheduler.scheduleOnce((Random nextInt 4).seconds) {
|
||||
member.channel push resyncMessage
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ package team
|
|||
import search.{ ElasticSearch, TypeIndexer }
|
||||
|
||||
import scalaz.effects._
|
||||
import com.codahale.jerkson.Json
|
||||
import play.api.libs.json._
|
||||
|
||||
import org.elasticsearch.action.search.SearchResponse
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package lila
|
|||
package team
|
||||
|
||||
import search.ElasticSearch._
|
||||
import play.api.libs.json._
|
||||
|
||||
private[team] object SearchMapping {
|
||||
|
||||
|
@ -14,17 +15,17 @@ private[team] object SearchMapping {
|
|||
import fields._
|
||||
import Mapping._
|
||||
|
||||
def mapping = Map(
|
||||
"properties" -> List(
|
||||
def mapping = Json.obj(
|
||||
"properties" -> Json.toJson(List(
|
||||
boost(name, "string", 3),
|
||||
boost(description, "string"),
|
||||
boost(location, "string"),
|
||||
field(nbMembers, "short")
|
||||
).toMap,
|
||||
"analyzer" -> "snowball"
|
||||
).toMap),
|
||||
"analyzer" -> Json.toJson("snowball")
|
||||
)
|
||||
|
||||
def apply(team: Team): Pair[String, Map[String, Any]] = team.id -> Map(
|
||||
def apply(team: Team): Pair[String, JsObject] = team.id -> Json.obj(
|
||||
name -> team.name,
|
||||
description -> team.description,
|
||||
location -> ~team.location,
|
||||
|
|
|
@ -22,7 +22,7 @@ trait TeamHelper {
|
|||
|
||||
def teamLink(id: String, cssClass: Option[String] = None): Html = Html {
|
||||
"""<a class="%s" href="%s">%s</a>""".format(
|
||||
cssClass.fold(" " + _, ""),
|
||||
~cssClass.map(" " + _),
|
||||
routes.Team.show(id),
|
||||
teamIdToName(id))
|
||||
}
|
||||
|
|
|
@ -61,9 +61,9 @@ final class TeamRepo(collection: MongoCollection)
|
|||
update(selectId(teamId), $inc("nbMembers" -> by))
|
||||
}
|
||||
|
||||
def enable(team: Team) = updateIO(team)($set("enabled" -> true))
|
||||
def enable(team: Team) = updateIO(team)($set(Seq("enabled" -> true)))
|
||||
|
||||
def disable(team: Team) = updateIO(team)($set("enabled" -> false))
|
||||
def disable(team: Team) = updateIO(team)($set(Seq("enabled" -> false)))
|
||||
|
||||
def updateIO(teamId: String)(op: Team ⇒ DBObject): IO[Unit] = for {
|
||||
teamOption ← byId(teamId)
|
||||
|
@ -77,7 +77,7 @@ final class TeamRepo(collection: MongoCollection)
|
|||
def addRequest(teamId: String, request: Request): IO[Unit] = io {
|
||||
update(
|
||||
selectId(teamId) ++ ("requests.user" $ne request.user),
|
||||
$push("requests" -> request.user))
|
||||
$push(Seq("requests" -> request.user)))
|
||||
}
|
||||
|
||||
def selectId(id: String): DBObject = DBObject("_id" -> id)
|
||||
|
|
|
@ -89,22 +89,15 @@ private[tournament] final class TournamentApi(
|
|||
|
||||
def withdraw(tour: Tournament, userId: String): IO[Unit] = tour match {
|
||||
case created: Created ⇒ (created withdraw userId).fold(
|
||||
err ⇒ putStrLn(err.shows) inject tour,
|
||||
tour2 ⇒ for {
|
||||
_ ← repo saveIO tour2
|
||||
_ ← socket reload tour2.id
|
||||
_ ← reloadSiteSocket
|
||||
_ ← lobbyReload
|
||||
} yield ()
|
||||
err ⇒ putStrLn(err.shows),
|
||||
tour2 ⇒ (repo saveIO tour2) >> (socket reload tour2.id) >> reloadSiteSocket >> lobbyReload
|
||||
)
|
||||
case started: Started ⇒ (started withdraw userId).fold(
|
||||
err ⇒ putStrLn(err.shows),
|
||||
tour2 ⇒ for {
|
||||
_ ← repo saveIO tour2
|
||||
_ ← ~(tour2 userCurrentPov userId map roundMeddler.resign)
|
||||
_ ← socket reload tour2.id
|
||||
_ ← reloadSiteSocket
|
||||
} yield ()
|
||||
tour2 ⇒ (repo saveIO tour2) >>
|
||||
~(tour2 userCurrentPov userId map roundMeddler.resign) >>
|
||||
(socket reload tour2.id) >>
|
||||
reloadSiteSocket
|
||||
)
|
||||
case finished: Finished ⇒ putStrLn("Cannot withdraw from finished tournament " + finished.id)
|
||||
}
|
||||
|
|
|
@ -17,10 +17,13 @@ final class EloChart(rawElos: List[(Int, Int, Option[Int])]) {
|
|||
|
||||
def columns = EloChart.columns
|
||||
|
||||
<<<<<<< HEAD
|
||||
def rows = Json toJson {
|
||||
withMedian(reduce(rawElos)) map {
|
||||
case (ts, elo, op, med) ⇒ List(date(ts), elo, op, med)
|
||||
case (ts, elo, op, med) ⇒ Json toJson List(
|
||||
Json toJson date(ts),
|
||||
Json toJson elo,
|
||||
Json toJson op,
|
||||
Json toJson med)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,10 +14,9 @@ final class HistoryRepo(collection: MongoCollection) {
|
|||
def addEntry(userId: String, elo: Int, opponentElo: Option[Int]): IO[Unit] = io {
|
||||
collection.update(
|
||||
DBObject("_id" -> userId),
|
||||
$push("entries" -> opponentElo.fold(
|
||||
DBList(DateTime.now.getSeconds.toInt, elo, _),
|
||||
DBList(DateTime.now.getSeconds.toInt, elo))
|
||||
),
|
||||
$push(Seq("entries" -> opponentElo.fold(DBList(DateTime.now.getSeconds.toInt, elo)) {
|
||||
DBList(DateTime.now.getSeconds.toInt, elo, _)
|
||||
})),
|
||||
multi = false,
|
||||
upsert = true)
|
||||
}
|
||||
|
@ -53,10 +52,9 @@ final class HistoryRepo(collection: MongoCollection) {
|
|||
ts ← elem.getAs[Double](0)
|
||||
elo ← elem.getAs[Double](1)
|
||||
op = if (elem.size > 2) elem.getAs[Double](2) else None
|
||||
} yield op.fold(
|
||||
o ⇒ List(ts.toInt, elo.toInt, o.toInt),
|
||||
List(ts.toInt, elo.toInt)
|
||||
)
|
||||
} yield op.fold(List(ts.toInt, elo.toInt)) { o ⇒
|
||||
List(ts.toInt, elo.toInt, o.toInt)
|
||||
}
|
||||
}
|
||||
catch {
|
||||
case (err: Exception) ⇒
|
||||
|
@ -64,18 +62,15 @@ final class HistoryRepo(collection: MongoCollection) {
|
|||
ts ← elem.getAs[Int](0)
|
||||
elo ← elem.getAs[Int](1)
|
||||
op = if (elem.size > 2) elem.getAs[Int](2) else None
|
||||
} yield op.fold(
|
||||
o ⇒ List(ts, elo, o),
|
||||
List(ts, elo)
|
||||
)
|
||||
} yield op.fold(List(ts, elo)) { o ⇒ List(ts, elo, o) }
|
||||
}
|
||||
}).flatten sortBy (_.head)
|
||||
val id = history.as[String]("_id")
|
||||
println("%s: %d -> %d".format(id, initEntries.size, entries.size))
|
||||
collection.update(
|
||||
DBObject("_id" -> id),
|
||||
$set("entries" -> entries)
|
||||
$set(Seq("entries" -> entries))
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -213,7 +213,9 @@ class UserRepo(collection: MongoCollection)
|
|||
collection.find(byIdQuery(username) ++ DBObject("engine" -> true)).size != 0
|
||||
}
|
||||
|
||||
def setRoles(user: User, roles: List[String]) = updateIO(user)($set("roles" -> roles))
|
||||
def setRoles(user: User, roles: List[String]) = updateIO(user)($set(Seq(
|
||||
"roles" -> roles
|
||||
)))
|
||||
|
||||
def setBio(user: User, bio: String) = updateIO(user)($set(Seq("bio" -> bio)))
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
<td>@showDate(request.date)</td>
|
||||
<td class="process">
|
||||
<form class="process-request" action="@routes.Team.requestProcess(request.id)" method="post">
|
||||
<input type="hidden" name="url" value="@t.fold(te => routes.Team.show(te.id), routes.Team.requests())" />
|
||||
<input type="hidden" name="url" value="@t.fold(routes.Team.requests())(te => routes.Team.show(te.id))" />
|
||||
<button name="process" class="submit button small" value="accept">@trans.accept()</button>
|
||||
<button name="process" class="submit button" value="decline">@trans.decline()</button>
|
||||
</form>
|
||||
|
|
|
@ -13,12 +13,13 @@ trait Resolvers {
|
|||
val jgitMaven = "jgit-maven" at "http://download.eclipse.org/jgit/maven"
|
||||
val christophs = "Christophs Maven Repo" at "http://maven.henkelmann.eu/"
|
||||
val sgodbillon = "sgodbillon" at "https://bitbucket.org/sgodbillon/repository/raw/master/snapshots/"
|
||||
val awesomepom = "awesomepom" at "https://raw.github.com/jibs/maven-repo-scala/master"
|
||||
}
|
||||
|
||||
trait Dependencies {
|
||||
val scalaz = "org.scalaz" %% "scalaz-core" % "6.0.4"
|
||||
val salat = "com.novus" % "salat-core_2.9.2" % "1.9.1"
|
||||
val scalalib = "com.github.ornicar" %% "scalalib" % "3.1"
|
||||
val scalalib = "com.github.ornicar" %% "scalalib" % "3.3"
|
||||
val config = "com.typesafe" % "config" % "1.0.0"
|
||||
val guava = "com.google.guava" % "guava" % "13.0.1"
|
||||
val apache = "org.apache.commons" % "commons-lang3" % "3.1"
|
||||
|
@ -27,7 +28,7 @@ trait Dependencies {
|
|||
val paginator = "com.github.ornicar" % "paginator-core_2.9.1" % "1.6"
|
||||
val paginatorSalat = "com.github.ornicar" % "paginator-salat-adapter_2.9.1" % "1.5"
|
||||
val csv = "com.github.tototoshi" % "scala-csv_2.9.1" % "0.3"
|
||||
val hasher = "com.roundeights" % "hasher" % "0.3" from "http://cloud.github.com/downloads/Nycto/Hasher/hasher_2.9.1-0.3.jar"
|
||||
val hasher = "hasher" %% "hasher" % "0.3.1"
|
||||
val jgit = "org.eclipse.jgit" % "org.eclipse.jgit" % "1.3.0.201202151440-r"
|
||||
val actuarius = "eu.henkelmann" % "actuarius_2.9.2" % "0.2.4"
|
||||
val jodaTime = "joda-time" % "joda-time" % "2.1"
|
||||
|
@ -40,7 +41,6 @@ trait Dependencies {
|
|||
|
||||
object ApplicationBuild extends Build with Resolvers with Dependencies {
|
||||
|
||||
// private val buildSettings = Project.defaultSettings ++ Seq(
|
||||
private val buildSettings = Seq(
|
||||
shellPrompt := {
|
||||
(state: State) ⇒ "%s> ".format(Project.extract(state).currentProject.id)
|
||||
|
@ -49,7 +49,8 @@ object ApplicationBuild extends Build with Resolvers with Dependencies {
|
|||
"-deprecation",
|
||||
"-unchecked",
|
||||
"-feature",
|
||||
"-language:_")
|
||||
"-language:_",
|
||||
"-Dscalac.patmat.analysisBudget=512")
|
||||
)
|
||||
|
||||
lazy val lila = play.Project("lila", "3", Seq(
|
||||
|
@ -66,11 +67,11 @@ object ApplicationBuild extends Build with Resolvers with Dependencies {
|
|||
"lila.ui",
|
||||
"lila.http.Context",
|
||||
"com.github.ornicar.paginator.Paginator"),
|
||||
resolvers ++= Seq(sgodbillon, iliaz, sonatype, sonatypeS, typesafe, t2v, guice, jgitMaven, christophs)
|
||||
resolvers ++= Seq(awesomepom, sgodbillon, iliaz, sonatype, sonatypeS, typesafe, t2v, guice, jgitMaven, christophs)
|
||||
) dependsOn scalachess aggregate scalachess
|
||||
|
||||
lazy val scalachess = Project("scalachess", file("scalachess"), settings = Project.defaultSettings ++ buildSettings).settings(
|
||||
resolvers := Seq(iliaz, sonatype),
|
||||
resolvers := Seq(iliaz, sonatype, awesomepom),
|
||||
scalaVersion := "2.10.0",
|
||||
libraryDependencies := Seq(scalaz, scalalib, hasher, jodaTime, jodaConvert)
|
||||
)
|
||||
|
|
|
@ -1 +1 @@
|
|||
sbt.version=0.12.1
|
||||
sbt.version=0.12.2
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 9833c9a5400b91a113054a3b7429a56279f308ff
|
||||
Subproject commit 41f8602283b4c59215dbd7ab6ce9a68dcfea83bd
|
Loading…
Reference in a new issue