Skip to content

Commit

Permalink
complete modlog implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Jul 21, 2012
1 parent d9be9c4 commit eb195eb
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 15 deletions.
6 changes: 6 additions & 0 deletions app/controllers/Mod.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import scalaz.effects._
object Mod extends LilaController {

def modApi = env.mod.api
def modLogApi = env.mod.logApi

def engine(username: String) = Secure(Permission.MarkEngine) { _
me
Expand All @@ -33,4 +34,9 @@ object Mod extends LilaController {
modApi.ipban(me, username) map { _ routes.User show username }
}
}

val log = Auth { implicit ctx
me =>
IOk(modLogApi.recent map { html.mod.log(_) })
}
}
22 changes: 15 additions & 7 deletions app/mod/Modlog.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,25 @@ import org.joda.time.DateTime
import org.scala_tools.time.Imports._

case class Modlog(
mod: String,
user: Option[String],
action: String,
date: DateTime = DateTime.now)
mod: String,
user: Option[String],
action: String,
date: DateTime = DateTime.now) {

def showAction = action match {
case Modlog.engine "mark as engine"
case Modlog.unengine "un-mark as engine"
case Modlog.deletePost "delete forum post"
case a a
}
}

object Modlog {

val engine = "engine"
val unengine = "un-engine"
val unengine = "unengine"
val mute = "mute"
val unmute = "un-mute"
val unmute = "unmute"
val ipban = "ipban"
val deletePost = "remove post"
val deletePost = "deletePost"
}
2 changes: 2 additions & 0 deletions app/mod/ModlogApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ final class ModlogApi(repo: ModlogRepo) {
Modlog(mod.id, user.id.some, Modlog.ipban)
}

def recent = repo recent 200

private def add(modLog: Modlog): IO[Unit] = repo saveIO modLog
}
4 changes: 4 additions & 0 deletions app/mod/ModlogRepo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ class ModlogRepo(collection: MongoCollection)
def saveIO(modlog: Modlog): IO[Unit] = io {
save(modlog)
}

def recent(nb: Int): IO[List[Modlog]] = io {
find(DBObject()).sort(DBObject("$natural" -> -1)).limit(nb).toList
}
}
8 changes: 1 addition & 7 deletions app/views/lobby/log.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,11 @@
@base.layout(title = title) {

<style type="text/css">
table td {
padding: 5px 10px 5px 10px;
}
table tr:nth-child(odd) {
background: #f7f7f7;
}
</style>
<div class="content_box">
<h1>@title</h1>
<br /><br />
<table><tbody>
<table class="datatable"><tbody>
@messages.map { message =>
<tr>
<td>@showDate(message.createdAt)</td>
Expand Down
26 changes: 26 additions & 0 deletions app/views/mod/log.scala.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
@(logs: List[lila.mod.Modlog])(implicit ctx: Context)

@title = @{ "Mod logs" }

@base.layout(title = title) {

<style type="text/css">
table td {
padding: 5px 10px 5px 10px;
}
</style>
<div class="content_box">
<h1>@title</h1>
<br /><br />
<table class="datatable"><tbody>
@logs.map { log =>
<tr>
<td>@showDate(log.date)</td>
<td>@userIdLink(log.mod.some)</td>
<td>@log.showAction.capitalize</td>
<td>@userIdLink(log.user)</td>
</tr>
}
</tbody></table>
</div>
}
1 change: 1 addition & 0 deletions conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ POST /account/closeConfirm controllers.User.closeConfirm
POST /mod/:username/engine controllers.Mod.engine(username: String)
POST /mod/:username/mute controllers.Mod.mute(username: String)
POST /mod/:username/ban controllers.Mod.ban(username: String)
GET /mod/log controllers.Mod.log

# Wiki
GET /wiki controllers.Wiki.home
Expand Down
7 changes: 7 additions & 0 deletions public/stylesheets/common.css
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,13 @@ div.content_box .lichess_title {
margin-bottom: 0.5em;
}

div.content_box table.datatable td {
padding: 5px 10px 5px 10px;
}
div.content_box table.datatable tr:nth-child(odd) {
background: #f7f7f7;
}

div.lichess_goodies div.box {
margin-top: 1em;
margin-left: -30px;
Expand Down
3 changes: 2 additions & 1 deletion public/stylesheets/dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ body.dark div.user_show .elo_with_me,
body.dark div.content_box_inter,
body.dark #GameText tr:nth-child(even),
body.dark table.translations tbody tr:nth-child(even),
body.dark form.translation_form div.message:nth-child(even)
body.dark form.translation_form div.message:nth-child(even),
body.dark div.content_box table.datatable tr:nth-child(odd)
{
background: #343434;
}
Expand Down

0 comments on commit eb195eb

Please sign in to comment.