more coach WIP

pull/2224/head
Thibault Duplessis 2016-08-31 14:20:52 +02:00
parent 0e5fe1ddfa
commit 6ba47c7412
9 changed files with 67 additions and 4 deletions

3
.gitmodules vendored
View File

@ -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

View File

@ -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
}

View File

@ -0,0 +1,3 @@
@(c: lila.coach.Coach.WithUser, me: User)(implicit ctx: Context)
Review form.

View File

@ -0,0 +1,3 @@
@(c: lila.coach.Coach.WithUser, coachReviews: lila.coach.CoachReview.Reviews)(implicit ctx: Context)
Reviews list.

View File

@ -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)

View File

@ -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])
}

View File

@ -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)
}
}

View File

@ -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)
}
}
}

View File

@ -0,0 +1,5 @@
$(function() {
$(".bar-rating").barrating({
theme: 'fontawesome-stars'
});
});