more work on featured events
parent
67cb7bed3f
commit
ea8a5892a8
|
@ -5,15 +5,20 @@ import play.api.mvc._
|
|||
import lila.app._
|
||||
import views._
|
||||
|
||||
object EventCrud extends LilaController {
|
||||
object Event extends LilaController {
|
||||
|
||||
private def env = Env.event
|
||||
private def api = env.api
|
||||
private def api = Env.event.api
|
||||
|
||||
def index = Secure(_.ManageEvent) { implicit ctx =>
|
||||
def index = Open { implicit ctx =>
|
||||
api.list.map { events =>
|
||||
Ok(html.event.index(events))
|
||||
}
|
||||
}
|
||||
|
||||
def manager = Secure(_.ManageEvent) { implicit ctx =>
|
||||
me =>
|
||||
api.list map { events =>
|
||||
html.event.index(events)
|
||||
html.event.manager(events)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -30,7 +35,7 @@ object EventCrud extends LilaController {
|
|||
implicit val req = ctx.body
|
||||
api.editForm(event).bindFromRequest.fold(
|
||||
err => BadRequest(html.event.edit(event, err)).fuccess,
|
||||
data => api.update(event, data) inject Redirect(routes.EventCrud.edit(id))
|
||||
data => api.update(event, data) inject Redirect(routes.Event.edit(id))
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -46,7 +51,7 @@ object EventCrud extends LilaController {
|
|||
api.createForm.bindFromRequest.fold(
|
||||
err => BadRequest(html.event.create(err)).fuccess,
|
||||
data => api.create(data, me.id) map { event =>
|
||||
Redirect(routes.EventCrud.edit(event.id))
|
||||
Redirect(routes.Event.edit(event.id))
|
||||
}
|
||||
)
|
||||
}
|
|
@ -3,7 +3,7 @@
|
|||
@layout(title = "New event", active = "form") {
|
||||
<div class="event_crud content_box small_box no_padding">
|
||||
<h1 class="lichess_title">New event</h1>
|
||||
<form class="content_box_content material form" action="@routes.EventCrud.create" method="POST">
|
||||
<form class="content_box_content material form" action="@routes.Event.create" method="POST">
|
||||
@inForm(form)
|
||||
</form>
|
||||
</div>
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
@event.title
|
||||
<span>Created by @usernameOrId(event.createdBy.value) on @showDate(event.createdAt)</span>
|
||||
</h1>
|
||||
<form class="content_box_content material form" action="@routes.EventCrud.update(event.id)" method="POST">
|
||||
<form class="content_box_content material form" action="@routes.Event.update(event.id)" method="POST">
|
||||
@inForm(form)
|
||||
</form>
|
||||
</div>
|
||||
|
|
|
@ -1,35 +1,31 @@
|
|||
@(events: List[lila.event.Event])(implicit ctx: Context)
|
||||
|
||||
@title = {Event manager}
|
||||
|
||||
@layout(title = title.body, active = "index") {
|
||||
<div class="event_crud content_box no_padding">
|
||||
<h1 class="lichess_title">@title</h1>
|
||||
<table class="slist">
|
||||
<thead>
|
||||
@base.layout(title = "All lichess public events") {
|
||||
<style type="text/css">
|
||||
#events td {
|
||||
padding: 1em 25px;
|
||||
}
|
||||
#events time {
|
||||
font-size: 0.8em;
|
||||
}
|
||||
#events a {
|
||||
font-weight: bold;
|
||||
text-decoration: none;
|
||||
}
|
||||
#events a.user_link {
|
||||
background: none;
|
||||
padding-left: 0;
|
||||
display: inline-block;
|
||||
}
|
||||
</style>
|
||||
<div id="events" class="content_box small_box no_padding">
|
||||
<h1>All public events</h1>
|
||||
<table class="datatable"><tbody>
|
||||
@events.map { e =>
|
||||
<tr>
|
||||
<th></th>
|
||||
<th>UTC start</th>
|
||||
<th>UTC end</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@events.map { event =>
|
||||
<tr>
|
||||
<td><a href="@routes.EventCrud.edit(event.id)">@event.title</a></td>
|
||||
<td>
|
||||
@showDateTimeUTC(event.startsAt)
|
||||
@momentFromNow(event.startsAt)
|
||||
</td>
|
||||
<td>
|
||||
@showDateTimeUTC(event.finishesAt)
|
||||
@momentFromNow(event.finishesAt)
|
||||
</td>
|
||||
<td><a class="text"href="@event.url" data-icon="v">URL</a></td>
|
||||
<td>@e.title</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</tbody></table>
|
||||
</div>
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
@(title: String, active: String = "")(body: Html)(implicit ctx: Context)
|
||||
|
||||
@menu = {
|
||||
<a class="@active.active("index")" href="@routes.EventCrud.index">Recent events</a>
|
||||
<a class="@active.active("form")" href="@routes.EventCrud.form">Create an event</a>
|
||||
<a class="@active.active("index")" href="@routes.Event.index">Recent events</a>
|
||||
<a class="@active.active("form")" href="@routes.Event.form">Create an event</a>
|
||||
}
|
||||
|
||||
@moreCss = {
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
@(events: List[lila.event.Event])(implicit ctx: Context)
|
||||
|
||||
@title = {Event manager}
|
||||
|
||||
@layout(title = title.body, active = "index") {
|
||||
<div class="event_crud content_box no_padding">
|
||||
<h1 class="lichess_title">@title</h1>
|
||||
<table class="slist">
|
||||
<thead>
|
||||
<tr>
|
||||
<th></th>
|
||||
<th>UTC start</th>
|
||||
<th>UTC end</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@events.map { event =>
|
||||
<tr>
|
||||
<td><a href="@routes.Event.edit(event.id)">@event.title</a></td>
|
||||
<td>
|
||||
@showDateTimeUTC(event.startsAt)
|
||||
@momentFromNow(event.startsAt)
|
||||
</td>
|
||||
<td>
|
||||
@showDateTimeUTC(event.finishesAt)
|
||||
@momentFromNow(event.finishesAt)
|
||||
</td>
|
||||
<td><a class="text"href="@event.url" data-icon="v">URL</a></td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
}
|
|
@ -16,7 +16,7 @@
|
|||
<a class="@active.active("tour")" href="@routes.TournamentCrud.index">Manage tournaments</a>
|
||||
}
|
||||
@if(isGranted(_.ManageEvent)) {
|
||||
<a class="@active.active("event")" href="@routes.EventCrud.index">Manage events</a>
|
||||
<a class="@active.active("event")" href="@routes.Event.index">Manage events</a>
|
||||
}
|
||||
@if(isGranted(_.SeeReport)) {
|
||||
<a class="@active.active("log")" href="@routes.Mod.log">Mod log</a>
|
||||
|
|
|
@ -10,7 +10,7 @@ net {
|
|||
ip = "5.196.91.160"
|
||||
asset {
|
||||
domain = ${net.domain}
|
||||
version = 1081
|
||||
version = 1082
|
||||
}
|
||||
}
|
||||
forcedev = false
|
||||
|
|
11
conf/routes
11
conf/routes
|
@ -431,11 +431,12 @@ GET /api/tournament/:id controllers.Api.tournament(id: String)
|
|||
GET /api/status controllers.Api.status
|
||||
|
||||
# Events
|
||||
GET /event/manager controllers.EventCrud.index
|
||||
GET /event/manager/$id<\w{8}> controllers.EventCrud.edit(id: String)
|
||||
POST /event/manager/$id<\w{8}> controllers.EventCrud.update(id: String)
|
||||
GET /event/manager/new controllers.EventCrud.form
|
||||
POST /event/manager controllers.EventCrud.create
|
||||
GET /event controllers.Event.index
|
||||
GET /event/manager controllers.Event.manager
|
||||
GET /event/manager/$id<\w{8}> controllers.Event.edit(id: String)
|
||||
POST /event/manager/$id<\w{8}> controllers.Event.update(id: String)
|
||||
GET /event/manager/new controllers.Event.form
|
||||
POST /event/manager controllers.Event.create
|
||||
|
||||
# Misc
|
||||
POST /cli controllers.Cli.command
|
||||
|
|
|
@ -16,6 +16,10 @@ case class Event(
|
|||
startsAt: DateTime,
|
||||
finishesAt: DateTime) {
|
||||
|
||||
def featureSince = startsAt minusHours homepageHours
|
||||
|
||||
def isNow = featureSince.isBefore(DateTime.now) && finishesAt.isAfter(DateTime.now)
|
||||
|
||||
def id = _id
|
||||
}
|
||||
|
||||
|
|
|
@ -10,12 +10,14 @@ final class EventApi(coll: Coll) {
|
|||
|
||||
import BsonHandlers._
|
||||
|
||||
val promotable = AsyncCache.single(fetchPromotable, timeToLive = 1 minute)
|
||||
val promotable = AsyncCache.single(fetchPromotable, timeToLive = 5 minutes)
|
||||
|
||||
def fetchPromotable: Fu[List[Event]] = coll.find($doc(
|
||||
"enabled" -> true,
|
||||
"startsAt" $gt DateTime.now $lt DateTime.now.plusDays(1)
|
||||
)).sort($doc("startsAt" -> 1)).list[Event](2)
|
||||
"startsAt" $gt DateTime.now.minusDays(1) $lt DateTime.now.plusDays(1)
|
||||
)).sort($doc("startsAt" -> 1)).list[Event](5).map {
|
||||
_.filter(_.isNow)
|
||||
}
|
||||
|
||||
def list = coll.find($empty).sort($doc("startsAt" -> -1)).list[Event](50)
|
||||
|
||||
|
|
Loading…
Reference in New Issue