more coach WIP
parent
0e5fe1ddfa
commit
6ba47c7412
|
@ -37,3 +37,6 @@
|
|||
[submodule "public/vendor/flatpickr"]
|
||||
path = public/vendor/flatpickr
|
||||
url = https://github.com/chmln/flatpickr
|
||||
[submodule "public/vendor/bar-rating"]
|
||||
path = public/vendor/bar-rating
|
||||
url = https://github.com/antennaio/jquery-bar-rating
|
||||
|
|
|
@ -22,8 +22,10 @@ object Coach extends LilaController {
|
|||
if (c.coach.isFullyEnabled || ctx.me.??(c.coach.is) || isGranted(_.PreviewCoach))
|
||||
Env.study.api.byIds {
|
||||
c.coach.profile.studyIds.map(_.value)
|
||||
} flatMap Env.study.pager.withChaptersAndLiking(ctx.me) map { studies =>
|
||||
Ok(html.coach.show(c, studies))
|
||||
} flatMap Env.study.pager.withChaptersAndLiking(ctx.me) flatMap { studies =>
|
||||
api.reviews.approvedByCoach(c.coach) map { reviews =>
|
||||
Ok(html.coach.show(c, studies, reviews))
|
||||
}
|
||||
}
|
||||
else notFound
|
||||
}
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
@(c: lila.coach.Coach.WithUser, me: User)(implicit ctx: Context)
|
||||
|
||||
Review form.
|
|
@ -0,0 +1,3 @@
|
|||
@(c: lila.coach.Coach.WithUser, coachReviews: lila.coach.CoachReview.Reviews)(implicit ctx: Context)
|
||||
|
||||
Reviews list.
|
|
@ -1,10 +1,25 @@
|
|||
@(c: lila.coach.Coach.WithUser, studies: Seq[lila.study.Study.WithChaptersAndLiked])(implicit ctx: Context)
|
||||
@(c: lila.coach.Coach.WithUser, coachReviews: lila.coach.CoachReview.Reviews, studies: Seq[lila.study.Study.WithChaptersAndLiked])(implicit ctx: Context)
|
||||
|
||||
@moreCss = {
|
||||
@if(studies.nonEmpty) { @cssTag("studyList.css") }
|
||||
@cssAt("vendor/bar-rating/dist/themes/fontawesome-stars.css")
|
||||
}
|
||||
|
||||
@layout(title = c.user.titleUsername, evenMoreCss = moreCss) {
|
||||
@moreJs = {
|
||||
@jsAt("vendor/bar-rating/dist/jquery.barrating.min.js")
|
||||
@jsTag("coach.js")
|
||||
}
|
||||
|
||||
@side = {
|
||||
@ctx.me.map { me =>
|
||||
@reviewForm(c, me)
|
||||
}
|
||||
@reviews(c, coachReviews)
|
||||
}
|
||||
|
||||
@layout(title = c.user.titleUsername,
|
||||
side = side.some,
|
||||
evenMoreCss = moreCss) {
|
||||
<div class="content_box no_padding coach">
|
||||
<div class="top">
|
||||
@pic(c, 250)
|
||||
|
|
|
@ -15,4 +15,6 @@ private[coach] object BsonHandlers {
|
|||
implicit val CoachProfileBSONHandler = Macros.handler[CoachProfile]
|
||||
|
||||
implicit val CoachBSONHandler = lila.db.BSON.LoggingHandler(logger)(Macros.handler[Coach])
|
||||
|
||||
implicit val CoachReviewBSONHandler = lila.db.BSON.LoggingHandler(logger)(Macros.handler[CoachReview])
|
||||
}
|
||||
|
|
|
@ -73,4 +73,17 @@ final class CoachApi(
|
|||
|
||||
private def withUser(user: User)(coach: Coach): Coach.WithUser =
|
||||
Coach.WithUser(coach, user)
|
||||
|
||||
object reviews {
|
||||
|
||||
def approvedByCoach(c: Coach): Fu[List[CoachReview]] =
|
||||
reviewColl.find(
|
||||
$doc("coachId" -> c.id.value, "approved" -> true)
|
||||
).sort($sort desc "createdAt").list[CoachReview](100)
|
||||
|
||||
def allByCoach(c: Coach): Fu[List[CoachReview]] =
|
||||
reviewColl.find(
|
||||
$doc("coachId" -> c.id.value)
|
||||
).sort($sort desc "createdAt").list[CoachReview](100)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,5 +11,22 @@ case class CoachReview(
|
|||
rating: Int,
|
||||
title: String,
|
||||
text: String,
|
||||
approved: Boolean,
|
||||
createdAt: DateTime,
|
||||
updatedAt: DateTime)
|
||||
|
||||
object CoachReview {
|
||||
|
||||
case class Score(value: Double) extends AnyVal {
|
||||
|
||||
}
|
||||
|
||||
case class Reviews(list: List[CoachReview]) {
|
||||
|
||||
def approved = list.filter(_.approved)
|
||||
|
||||
lazy val averageScore: Option[Score] = approved.nonEmpty option {
|
||||
Score(approved.map(_.rating).sum.toDouble / list.size)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
$(function() {
|
||||
$(".bar-rating").barrating({
|
||||
theme: 'fontawesome-stars'
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue