Skip to content

Commit

Permalink
more coach WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Aug 31, 2016
1 parent 0e5fe1d commit 6ba47c7
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 4 additions & 2 deletions app/controllers/Coach.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
3 changes: 3 additions & 0 deletions app/views/coach/reviewForm.scala.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@(c: lila.coach.Coach.WithUser, me: User)(implicit ctx: Context)

Review form.
3 changes: 3 additions & 0 deletions app/views/coach/reviews.scala.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@(c: lila.coach.Coach.WithUser, coachReviews: lila.coach.CoachReview.Reviews)(implicit ctx: Context)

Reviews list.
19 changes: 17 additions & 2 deletions app/views/coach/show.scala.html
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 2 additions & 0 deletions modules/coach/src/main/BsonHandlers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
13 changes: 13 additions & 0 deletions modules/coach/src/main/CoachApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
17 changes: 17 additions & 0 deletions modules/coach/src/main/CoachReview.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
5 changes: 5 additions & 0 deletions public/javascripts/coach.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
$(function() {
$(".bar-rating").barrating({
theme: 'fontawesome-stars'
});
});

0 comments on commit 6ba47c7

Please sign in to comment.