Start implementing the forum
This commit is contained in:
parent
8f543118ee
commit
e7833e022b
|
@ -1,74 +0,0 @@
|
|||
package controllers
|
||||
|
||||
import lila._
|
||||
|
||||
import play.api.mvc._
|
||||
import play.api.libs.concurrent._
|
||||
|
||||
object AppApi extends LilaController {
|
||||
|
||||
//private val api = env.appApi
|
||||
|
||||
//def show(fullId: String) = Action {
|
||||
//Async {
|
||||
//(api show fullId).asPromise map { op ⇒
|
||||
//op.unsafePerformIO.fold(e ⇒ BadRequest(e.shows), JsonOk)
|
||||
//}
|
||||
//}
|
||||
//}
|
||||
|
||||
//def reloadTable(gameId: String) = Action {
|
||||
//ValidIOk(api reloadTable gameId)
|
||||
//}
|
||||
|
||||
//def start(gameId: String) = Action { implicit req ⇒
|
||||
//FormValidIOk[EntryData](entryForm)(entryData ⇒ api.start(gameId, entryData))
|
||||
//}
|
||||
|
||||
//def join(fullId: String) = Action { implicit req ⇒
|
||||
//FormValidIOk[JoinData](joinForm) { join ⇒
|
||||
//api.join(fullId, join._1, join._2, join._3)
|
||||
//}
|
||||
//}
|
||||
|
||||
//def activity(gameId: String, color: String) = Action {
|
||||
//Async {
|
||||
//api.isConnected(gameId, color).asPromise map { bool ⇒
|
||||
//Ok(bool.fold(1, 0))
|
||||
//}
|
||||
//}
|
||||
//}
|
||||
|
||||
//def gameVersion(gameId: String) = Action {
|
||||
//Async {
|
||||
//(api gameVersion gameId).asPromise map { Ok(_) }
|
||||
//}
|
||||
//}
|
||||
|
||||
//def gameInfo(gameId: String) = Action {
|
||||
//(api gameInfo gameId).unsafePerformIO.fold(
|
||||
//info ⇒ JsonOk(info.toMap),
|
||||
//BadRequest("No such game")
|
||||
//)
|
||||
//}
|
||||
|
||||
//def rematchAccept(gameId: String, color: String, newGameId: String) = Action { implicit req ⇒
|
||||
//FormValidIOk[RematchData](rematchForm)(r ⇒
|
||||
//api.rematchAccept(gameId, newGameId, color, r._1, r._2, r._3, r._4))
|
||||
//}
|
||||
|
||||
//def adjust(username: String) = Action {
|
||||
//IOk(api adjust username)
|
||||
//}
|
||||
|
||||
//def captcha = Action {
|
||||
//env.site.captcha.create.unsafePerformIO.fold(
|
||||
//err ⇒ BadRequest(err.shows),
|
||||
//data ⇒ JsonOk(Map(
|
||||
//"id" -> data._1,
|
||||
//"fen" -> data._2,
|
||||
//"color" -> data._3.toString
|
||||
//))
|
||||
//)
|
||||
//}
|
||||
}
|
8
app/controllers/Forum.scala
Normal file
8
app/controllers/Forum.scala
Normal file
|
@ -0,0 +1,8 @@
|
|||
package controllers
|
||||
|
||||
import lila._
|
||||
import views._
|
||||
|
||||
object Forum extends LilaController {
|
||||
|
||||
}
|
14
app/controllers/ForumCateg.scala
Normal file
14
app/controllers/ForumCateg.scala
Normal file
|
@ -0,0 +1,14 @@
|
|||
package controllers
|
||||
|
||||
import lila._
|
||||
import views._
|
||||
|
||||
object ForumCateg extends LilaController {
|
||||
|
||||
def api = env.forum.categApi
|
||||
|
||||
val index = Open { implicit ctx ⇒
|
||||
IOk(api.list map { html.forum.categ.index(_) })
|
||||
}
|
||||
|
||||
}
|
|
@ -5,12 +5,8 @@ import http.Context
|
|||
import lobby.Hook
|
||||
import views._
|
||||
|
||||
import play.api._
|
||||
import play.api.mvc._
|
||||
import play.api.libs.concurrent.Akka
|
||||
import play.api.Play.current
|
||||
import play.api.libs.json._
|
||||
import play.api.libs.iteratee._
|
||||
import play.api.libs.json.JsValue
|
||||
import scalaz.effects._
|
||||
|
||||
object Lobby extends LilaController {
|
||||
|
|
|
@ -29,6 +29,11 @@ final class CoreEnv private (application: Application, val settings: Settings) {
|
|||
gameRepo = game.gameRepo,
|
||||
dbRef = namespace ⇒ id ⇒ mongodb.ref(namespace, id))
|
||||
|
||||
lazy val forum = new lila.forum.ForumEnv(
|
||||
settings = settings,
|
||||
mongodb = mongodb.apply _,
|
||||
userRepo = user.userRepo)
|
||||
|
||||
lazy val lobby = new lila.lobby.LobbyEnv(
|
||||
app = app,
|
||||
settings = settings,
|
||||
|
|
|
@ -61,6 +61,9 @@ final class Settings(config: Config) {
|
|||
val MongoCollectionConfig = getString("mongo.collection.config")
|
||||
val MongoCollectionCache = getString("mongo.collection.cache")
|
||||
val MongoCollectionSecurity = getString("mongo.collection.security")
|
||||
val MongoCollectionForumCateg = getString("mongo.collection.forum_categ")
|
||||
val MongoCollectionForumTopic = getString("mongo.collection.forum_topic")
|
||||
val MongoCollectionForumPost = getString("mongo.collection.forum_post")
|
||||
|
||||
val ActorReporting = "reporting"
|
||||
val ActorSiteHub = "site_hub"
|
||||
|
|
10
app/forum/Categ.scala
Normal file
10
app/forum/Categ.scala
Normal file
|
@ -0,0 +1,10 @@
|
|||
package lila
|
||||
package forum
|
||||
|
||||
import com.novus.salat.annotations.Key
|
||||
|
||||
case class Categ(
|
||||
@Key("_id") slug: String,
|
||||
name: String,
|
||||
desc: String) {
|
||||
}
|
14
app/forum/CategApi.scala
Normal file
14
app/forum/CategApi.scala
Normal file
|
@ -0,0 +1,14 @@
|
|||
package lila
|
||||
package forum
|
||||
|
||||
import scalaz.effects._
|
||||
|
||||
final class CategApi(env: ForumEnv) {
|
||||
|
||||
val list: IO[List[CategView]] = for {
|
||||
categs ← env.categRepo.all
|
||||
views ← (categs map { categ ⇒
|
||||
io(CategView(categ))
|
||||
}).sequence
|
||||
} yield views
|
||||
}
|
26
app/forum/CategRepo.scala
Normal file
26
app/forum/CategRepo.scala
Normal file
|
@ -0,0 +1,26 @@
|
|||
package lila
|
||||
package forum
|
||||
|
||||
import com.novus.salat._
|
||||
import com.novus.salat.dao._
|
||||
import com.mongodb.DBRef
|
||||
import com.mongodb.casbah.MongoCollection
|
||||
import com.mongodb.casbah.Imports._
|
||||
import scalaz.effects._
|
||||
|
||||
final class CategRepo(
|
||||
collection: MongoCollection
|
||||
) extends SalatDAO[Categ, String](collection) {
|
||||
|
||||
def categ(slug: String): IO[Option[Categ]] = io {
|
||||
findOneByID(slug)
|
||||
}
|
||||
|
||||
val all: IO[List[Categ]] = io {
|
||||
find(DBObject()).sort(DBObject("pos" -> 1)).toList
|
||||
}
|
||||
|
||||
private def idSelector(categ: Categ) = DBObject("_id" -> categ.slug)
|
||||
|
||||
private def idSelector(slug: String) = DBObject("_id" -> slug)
|
||||
}
|
5
app/forum/CategView.scala
Normal file
5
app/forum/CategView.scala
Normal file
|
@ -0,0 +1,5 @@
|
|||
package lila
|
||||
package forum
|
||||
|
||||
case class CategView(
|
||||
categ: Categ)
|
19
app/forum/ForumEnv.scala
Normal file
19
app/forum/ForumEnv.scala
Normal file
|
@ -0,0 +1,19 @@
|
|||
package lila
|
||||
package forum
|
||||
|
||||
import user.UserRepo
|
||||
import core.Settings
|
||||
|
||||
import com.mongodb.casbah.MongoCollection
|
||||
|
||||
final class ForumEnv(
|
||||
settings: Settings,
|
||||
mongodb: String ⇒ MongoCollection,
|
||||
userRepo: UserRepo) {
|
||||
|
||||
import settings._
|
||||
|
||||
lazy val categRepo = new CategRepo(mongodb(MongoCollectionForumCateg))
|
||||
|
||||
lazy val categApi = new CategApi(this)
|
||||
}
|
7
app/views/forum/categ/index.scala.html
Normal file
7
app/views/forum/categ/index.scala.html
Normal file
|
@ -0,0 +1,7 @@
|
|||
@(categs: List[lila.forum.CategView])(implicit ctx: Context)
|
||||
|
||||
@forum.layout(
|
||||
title = "Forum") {
|
||||
|
||||
categs
|
||||
}
|
15
app/views/forum/layout.scala.html
Normal file
15
app/views/forum/layout.scala.html
Normal file
|
@ -0,0 +1,15 @@
|
|||
@(title: String)(body: Html)(implicit ctx: Context)
|
||||
|
||||
@moreCss = {
|
||||
@cssTag("forum.css")
|
||||
}
|
||||
|
||||
@moreJs = {
|
||||
@jsTag("forum.js")
|
||||
}
|
||||
|
||||
@base.layout(
|
||||
title = title,
|
||||
moreCss = moreCss,
|
||||
moreJs = moreJs,
|
||||
active = siteMenu.forum.some)(body)
|
|
@ -13,6 +13,9 @@ mongo {
|
|||
config = config
|
||||
cache = cache
|
||||
security = security
|
||||
forum_categ = f_categ
|
||||
forum_topic = f_topic
|
||||
forum_post = f_post
|
||||
}
|
||||
connectionsPerHost = 100
|
||||
autoConnectRetry = true
|
||||
|
|
28
conf/routes
28
conf/routes
|
@ -78,35 +78,18 @@ POST /account/closeConfirm controllers.User.closeConfirm
|
|||
# Wiki
|
||||
GET /wiki controllers.Wiki.home
|
||||
|
||||
# AI
|
||||
GET /ai controllers.Ai.run
|
||||
|
||||
# App Private API
|
||||
#POST /api/start/:gameId controllers.AppApi.start(gameId: String)
|
||||
#POST /api/join/$fullId<[\w\-]{12}> controllers.AppApi.join(fullId: String)
|
||||
#POST /api/reload-table/:gameId controllers.AppApi.reloadTable(gameId: String)
|
||||
#POST /api/adjust/:username controllers.AppApi.adjust(username: String)
|
||||
#GET /api/activity/:gameId/:color controllers.AppApi.activity(gameId: String, color: String)
|
||||
#GET /api/game-version/:gameId controllers.AppApi.gameVersion(gameId: String)
|
||||
#GET /api/game-info/:gameId controllers.AppApi.gameInfo(gameId: String)
|
||||
#POST /api/rematch-accept/:gameId/:color/:newGameId controllers.AppApi.rematchAccept(gameId: String, color: String, newGameId: String)
|
||||
#
|
||||
#GET /api/captcha/create controllers.Captcha.create
|
||||
#GET /api/captcha/solve/:gameId controllers.Captcha.solve(gameId: String)
|
||||
|
||||
# Lobby Public API
|
||||
# Lobby
|
||||
GET / controllers.Lobby.home
|
||||
GET /new/$ownerId<[\w\-]{12}> controllers.Lobby.hook(ownerId: String)
|
||||
GET /new/$ownerId<[\w\-]{12}>/cancel controllers.Lobby.cancel(ownerId: String)
|
||||
GET /new/$hookId<[\w\-]{8}>/join controllers.Lobby.join(hookId: String)
|
||||
GET /lobby/socket controllers.Lobby.socket
|
||||
|
||||
# Lobby Private API
|
||||
#POST /api/lobby/join/:gameId/:color controllers.Lobby.join(gameId: String, color: String)
|
||||
#GET /api/lobby/preload controllers.Lobby.preload
|
||||
#POST /api/lobby/create/:hookOwnerId controllers.Lobby.create(hookOwnerId: String)
|
||||
#POST /api/lobby/chat-ban/:username controllers.Lobby.chatBan(username: String)
|
||||
|
||||
GET /assets/*file controllers.Assets.at(path="/public", file)
|
||||
# Forum
|
||||
GET /forum controllers.ForumCateg.index
|
||||
|
||||
# Monitor
|
||||
GET /monitor controllers.Monitor.index
|
||||
|
@ -114,3 +97,6 @@ GET /monitor/stream controllers.Monitor.stream
|
|||
GET /nb-players controllers.Monitor.nbPlayers
|
||||
GET /nb-playing controllers.Monitor.nbPlaying
|
||||
GET /status controllers.Monitor.status
|
||||
|
||||
# Assets
|
||||
GET /assets/*file controllers.Assets.at(path="/public", file)
|
||||
|
|
Loading…
Reference in a new issue