broadcast tournament/round WIP
parent
af408f6288
commit
978a64bffc
|
@ -34,15 +34,16 @@ final class RelayRound(
|
|||
me =>
|
||||
NoLameOrBot {
|
||||
WithTourAndRounds(tourId) { trs =>
|
||||
trs.tour.ownedBy(me) ?? {
|
||||
val tour = trs.tour
|
||||
tour.ownedBy(me) ?? {
|
||||
env.relay.roundForm
|
||||
.create(trs)
|
||||
.bindFromRequest()(ctx.body, formBinding)
|
||||
.fold(
|
||||
err => BadRequest(html.relay.roundForm.create(err, trs.tour)).fuccess,
|
||||
err => BadRequest(html.relay.roundForm.create(err, tour)).fuccess,
|
||||
setup =>
|
||||
env.relay.api.create(setup, me, trs.tour) map { relay =>
|
||||
Redirect(routes.RelayRound.form(trs.tour.id.value))
|
||||
env.relay.api.create(setup, me, tour) map { round =>
|
||||
Redirect(routes.RelayRound.show(tour.slug, round.slug, round.id.value))
|
||||
}
|
||||
)
|
||||
}
|
||||
|
|
|
@ -14,8 +14,6 @@ object tour {
|
|||
|
||||
import trans.broadcast._
|
||||
|
||||
// def url(t: RelayTour) = routes.RelayTour.show(t.slug, t.id.value)
|
||||
|
||||
def index(
|
||||
active: List[RelayTour.ActiveWithNextRound],
|
||||
pager: Paginator[RelayTour.WithLastRound]
|
||||
|
@ -45,6 +43,7 @@ object tour {
|
|||
p(tr.tour.description),
|
||||
p(
|
||||
strong(tr.round.name),
|
||||
br,
|
||||
if (tr.ongoing) trans.playingRightNow()
|
||||
else tr.round.startsAt.map(momentFromNow(_))
|
||||
)
|
||||
|
|
|
@ -61,6 +61,11 @@ final class RelayApi(
|
|||
|
||||
def withRounds(tour: RelayTour) = roundRepo.byTour(tour).dmap(tour.withRounds)
|
||||
|
||||
def denormalizeTourActive(tourId: RelayTour.Id): Funit =
|
||||
roundRepo.coll.exists(roundRepo.selectors.tour(tourId) ++ $doc("finished" -> false)) flatMap {
|
||||
tourRepo.setActive(tourId, _)
|
||||
}
|
||||
|
||||
private val nextRoundSort = $doc(
|
||||
"startedAt" -> 1,
|
||||
"startsAt" -> 1,
|
||||
|
@ -166,6 +171,7 @@ final class RelayApi(
|
|||
),
|
||||
user
|
||||
) >>
|
||||
tourRepo.setActive(tour.id, true) >>
|
||||
studyApi.addTopics(relay.studyId, List("Broadcast")) inject relay
|
||||
}
|
||||
|
||||
|
@ -188,6 +194,8 @@ final class RelayApi(
|
|||
(round.sync.playing != from.sync.playing) ?? tourById(round.tourId).flatMap {
|
||||
_.map(round.withTour).map(jsonView.admin) ?? { sendToContributors(round.id, "relayData", _) }
|
||||
}
|
||||
} >> {
|
||||
(round.finished != from.finished) ?? denormalizeTourActive(round.tourId)
|
||||
} >>- {
|
||||
round.sync.log.events.lastOption.ifTrue(round.sync.log != from.sync.log).foreach { event =>
|
||||
sendToContributors(round.id, "relayLog", JsonView.syncLogEventWrites writes event)
|
||||
|
@ -210,7 +218,8 @@ final class RelayApi(
|
|||
def deleteRound(roundId: RelayRound.Id): Fu[Option[RelayTour]] =
|
||||
byIdWithTour(roundId) flatMap {
|
||||
_ ?? { rt =>
|
||||
roundRepo.coll.delete.one($id(rt.round.id)) inject rt.tour.some
|
||||
roundRepo.coll.delete.one($id(rt.round.id)) >>
|
||||
denormalizeTourActive(rt.tour.id) inject rt.tour.some
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,8 @@ import lila.study._
|
|||
|
||||
final private class RelaySync(
|
||||
studyApi: StudyApi,
|
||||
chapterRepo: ChapterRepo
|
||||
chapterRepo: ChapterRepo,
|
||||
tourRepo: RelayTourRepo
|
||||
)(implicit ec: scala.concurrent.ExecutionContext) {
|
||||
|
||||
private type NbMoves = Int
|
||||
|
@ -31,7 +32,9 @@ final private class RelaySync(
|
|||
} inject chapter.root.mainline.size
|
||||
}
|
||||
}
|
||||
} map { _.sum } dmap { SyncResult.Ok(_, games) }
|
||||
} map { _.sum } flatMap { moves =>
|
||||
tourRepo.setSyncedNow(rt.tour) inject SyncResult.Ok(moves, games)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,12 @@ final private class RelayTourRepo(val coll: Coll)(implicit ec: scala.concurrent.
|
|||
|
||||
import BSONHandlers._
|
||||
|
||||
def setSyncedNow(tour: RelayTour): Funit =
|
||||
coll.updateField($id(tour.id), "syncedAt", DateTime.now).void
|
||||
|
||||
def setActive(tourId: RelayTour.Id, active: Boolean): Funit =
|
||||
coll.updateField($id(tourId), "active", active).void
|
||||
|
||||
def lookup(local: String) = $lookup.simple(coll, "tour", local, "_id")
|
||||
|
||||
private[relay] object selectors {
|
||||
|
|
Loading…
Reference in New Issue