display promotable events on homepage - WIP
This commit is contained in:
parent
89df050864
commit
c9fa5cd5d8
|
@ -30,6 +30,7 @@ object Lobby extends LilaController {
|
|||
Env.current.preloader(
|
||||
posts = Env.forum.recent(ctx.me, Env.team.cached.teamIds),
|
||||
tours = Env.tournament.cached promotable true,
|
||||
events = Env.event.api promotable true,
|
||||
simuls = Env.simul allCreatedFeaturable true
|
||||
) map (html.lobby.home.apply _).tupled map { status(_) } map ensureSessionId(ctx.req)
|
||||
}.mon(_.http.response.home)
|
||||
|
|
|
@ -3,6 +3,7 @@ package mashup
|
|||
|
||||
import lila.api.Context
|
||||
import lila.common.LightUser
|
||||
import lila.event.Event
|
||||
import lila.forum.MiniForumPost
|
||||
import lila.game.{ Game, Pov, GameRepo }
|
||||
import lila.playban.TempBan
|
||||
|
@ -26,15 +27,17 @@ final class Preload(
|
|||
getPlayban: String => Fu[Option[TempBan]],
|
||||
lightUser: String => Option[LightUser]) {
|
||||
|
||||
private type Response = (JsObject, List[Entry], List[MiniForumPost], List[Tournament], List[Simul], Option[Game], List[User.LightPerf], List[Winner], Option[lila.puzzle.DailyPuzzle], List[StreamOnAir], List[lila.blog.MiniPost], Option[TempBan], Option[Preload.CurrentGame], Int)
|
||||
private type Response = (JsObject, List[Entry], List[MiniForumPost], List[Tournament], List[Event], List[Simul], Option[Game], List[User.LightPerf], List[Winner], Option[lila.puzzle.DailyPuzzle], List[StreamOnAir], List[lila.blog.MiniPost], Option[TempBan], Option[Preload.CurrentGame], Int)
|
||||
|
||||
def apply(
|
||||
posts: Fu[List[MiniForumPost]],
|
||||
tours: Fu[List[Tournament]],
|
||||
events: Fu[List[Event]],
|
||||
simuls: Fu[List[Simul]])(implicit ctx: Context): Fu[Response] =
|
||||
lobbyApi(ctx) zip
|
||||
posts zip
|
||||
tours zip
|
||||
events zip
|
||||
simuls zip
|
||||
tv.getBestGame zip
|
||||
(ctx.userId ?? timelineEntries) zip
|
||||
|
@ -44,8 +47,8 @@ final class Preload(
|
|||
streamsOnAir() zip
|
||||
(ctx.userId ?? getPlayban) zip
|
||||
(ctx.me ?? Preload.currentGame(lightUser)) map {
|
||||
case ((((((((((((data, posts), tours), simuls), feat), entries), lead), tWinners), puzzle), streams), playban), currentGame)) =>
|
||||
(data, entries, posts, tours, simuls, feat, lead, tWinners, puzzle, streams, Env.blog.lastPostCache.apply, playban, currentGame, countRounds())
|
||||
case (((((((((((((data, posts), tours), events), simuls), feat), entries), lead), tWinners), puzzle), streams), playban), currentGame)) =>
|
||||
(data, entries, posts, tours, events, simuls, feat, lead, tWinners, puzzle, streams, Env.blog.lastPostCache.apply, playban, currentGame, countRounds())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,4 +25,6 @@ trait FormHelper { self: I18nHelper =>
|
|||
s"""<p class="error">$msg</p>"""
|
||||
} mkString
|
||||
}
|
||||
|
||||
val booleanChoices = Seq("true" -> "Yes", "false" -> "No")
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
@(c: lila.coach.Coach.WithUser, form: Form[_])(implicit ctx: Context)
|
||||
|
||||
@import play.api.data.Field
|
||||
@import lila.coach.CoachForm.booleanChoices
|
||||
|
||||
@group(field: Field, name: Html, half: Boolean = false, largeLabel: Boolean = false)(html: Html) = {
|
||||
<div class="form-group@if(half){ half}@if(field.hasErrors){ has-error}@if(largeLabel){ large-label}">
|
||||
|
|
9
app/views/event/homepageSpotlight.scala.html
Normal file
9
app/views/event/homepageSpotlight.scala.html
Normal file
|
@ -0,0 +1,9 @@
|
|||
@(e: lila.event.Event)(implicit ctx: Context)
|
||||
|
||||
<a href="@e.url" class="tour_spotlight event_spotlight id_@e.id">
|
||||
<img class="img icon" src="@staticUrl("images/fire-silhouette.svg")" />
|
||||
<span class="content">
|
||||
<span class="name">@e.title</span>
|
||||
<span class="more">@e.headline</span>
|
||||
</span>
|
||||
</a>
|
|
@ -20,13 +20,16 @@
|
|||
@group(form("headline"), Html("Headline")) {
|
||||
@base.input(form("headline"))
|
||||
}
|
||||
@group(form("url"), Html("External URL")) {
|
||||
@base.input(form("url"))
|
||||
}
|
||||
<div>
|
||||
@group(form("enabled"), Html("Enabled"), half = true) {
|
||||
@base.select(form("enabled"), booleanChoices)
|
||||
}
|
||||
@group(form("homepageHours"), Html("Hours on homepage (0 to 24)"), half = true) {
|
||||
@base.input(form("homepageHours"))
|
||||
}
|
||||
@group(form("url"), Html("External URL"), half = true) {
|
||||
@base.input(form("url"))
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="button-container">
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
@(data: play.api.libs.json.JsObject, userTimeline: List[lila.timeline.Entry], forumRecent: List[lila.forum.MiniForumPost], tours: List[Tournament], simuls: List[lila.simul.Simul], featured: Option[Game], leaderboard: List[User.LightPerf], tournamentWinners: List[lila.tournament.Winner], puzzle: Option[lila.puzzle.DailyPuzzle], streams: List[lila.tv.StreamOnAir], lastPost: List[lila.blog.MiniPost], playban: Option[lila.playban.TempBan], currentGame: Option[lila.app.mashup.Preload.CurrentGame], nbRounds: Int)(implicit ctx: Context)
|
||||
@(data: play.api.libs.json.JsObject, userTimeline: List[lila.timeline.Entry], forumRecent: List[lila.forum.MiniForumPost], tours: List[Tournament], events: List[lila.event.Event], simuls: List[lila.simul.Simul], featured: Option[Game], leaderboard: List[User.LightPerf], tournamentWinners: List[lila.tournament.Winner], puzzle: Option[lila.puzzle.DailyPuzzle], streams: List[lila.tv.StreamOnAir], lastPost: List[lila.blog.MiniPost], playban: Option[lila.playban.TempBan], currentGame: Option[lila.app.mashup.Preload.CurrentGame], nbRounds: Int)(implicit ctx: Context)
|
||||
|
||||
@underchat = {
|
||||
<div id="featured_game">
|
||||
|
@ -13,6 +13,9 @@
|
|||
@NotForKids {
|
||||
<div id="streams_on_air">@tv.streamsOnAir(streams)</div>
|
||||
}
|
||||
@events.map { e =>
|
||||
@event.homepageSpotlight(e)
|
||||
}
|
||||
@lila.tournament.Spotlight.select(tours, ctx.me).map { tour =>
|
||||
@tournament.homepageSpotlight(tour)
|
||||
}
|
||||
|
|
|
@ -32,8 +32,6 @@ object CoachForm {
|
|||
updatedAt = DateTime.now)
|
||||
}
|
||||
|
||||
val booleanChoices = Seq("true" -> "Yes", "false" -> "No")
|
||||
|
||||
private def profileMapping = mapping(
|
||||
"headline" -> optional(nonEmptyText(minLength = 5, maxLength = 140)),
|
||||
"description" -> optional(markdown),
|
||||
|
|
|
@ -10,6 +10,7 @@ case class Event(
|
|||
headline: String,
|
||||
homepageHours: Int,
|
||||
url: String,
|
||||
enabled: Boolean,
|
||||
createdBy: Event.UserId,
|
||||
createdAt: DateTime,
|
||||
startsAt: DateTime,
|
||||
|
|
|
@ -1,13 +1,22 @@
|
|||
package lila.event
|
||||
|
||||
import org.joda.time.{ DateTime, DateTimeZone }
|
||||
import scala.concurrent.duration._
|
||||
|
||||
import lila.db.dsl._
|
||||
import lila.memo._
|
||||
|
||||
final class EventApi(coll: Coll) {
|
||||
|
||||
import BsonHandlers._
|
||||
|
||||
val promotable = AsyncCache.single(fetchPromotable, timeToLive = 1 minute)
|
||||
|
||||
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)
|
||||
|
||||
def list = coll.find($empty).sort($doc("startsAt" -> -1)).list[Event](50)
|
||||
|
||||
def one(id: String) = coll.byId[Event](id)
|
||||
|
@ -17,12 +26,12 @@ final class EventApi(coll: Coll) {
|
|||
}
|
||||
|
||||
def update(old: Event, data: EventForm.Data) =
|
||||
coll.update($id(old.id), data update old).void
|
||||
coll.update($id(old.id), data update old) >> promotable.clear
|
||||
|
||||
def createForm = EventForm.form
|
||||
|
||||
def create(data: EventForm.Data, userId: String): Fu[Event] = {
|
||||
val event = data make userId
|
||||
coll.insert(event) inject event
|
||||
coll.insert(event) >> promotable.clear inject event
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ object EventForm {
|
|||
"headline" -> nonEmptyText(minLength = 5, maxLength = 30),
|
||||
"homepageHours" -> number(min = 0, max = 24),
|
||||
"url" -> nonEmptyText,
|
||||
"enabled" -> boolean,
|
||||
"startsAt" -> utcDate,
|
||||
"finishesAt" -> utcDate
|
||||
)(Data.apply)(Data.unapply))
|
||||
|
@ -26,6 +27,7 @@ object EventForm {
|
|||
headline: String,
|
||||
homepageHours: Int,
|
||||
url: String,
|
||||
enabled: Boolean,
|
||||
startsAt: DateTime,
|
||||
finishesAt: DateTime) {
|
||||
|
||||
|
@ -34,6 +36,7 @@ object EventForm {
|
|||
headline = headline,
|
||||
homepageHours = homepageHours,
|
||||
url = url,
|
||||
enabled = enabled,
|
||||
startsAt = startsAt,
|
||||
finishesAt = finishesAt)
|
||||
|
||||
|
@ -43,6 +46,7 @@ object EventForm {
|
|||
headline = headline,
|
||||
homepageHours = homepageHours,
|
||||
url = url,
|
||||
enabled = enabled,
|
||||
startsAt = startsAt,
|
||||
finishesAt = finishesAt,
|
||||
createdBy = Event.UserId(userId),
|
||||
|
@ -56,6 +60,7 @@ object EventForm {
|
|||
headline = event.headline,
|
||||
homepageHours = event.homepageHours,
|
||||
url = event.url,
|
||||
enabled = event.enabled,
|
||||
startsAt = event.startsAt,
|
||||
finishesAt = event.finishesAt)
|
||||
}
|
||||
|
|
|
@ -156,7 +156,7 @@ object ApplicationBuild extends Build {
|
|||
libraryDependencies ++= provided(play.api, play.test, RM)
|
||||
)
|
||||
|
||||
lazy val event = project("event", Seq(common, db)).settings(
|
||||
lazy val event = project("event", Seq(common, db, memo)).settings(
|
||||
libraryDependencies ++= provided(play.api, play.test, RM)
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in a new issue