diff --git a/.gitmodules b/.gitmodules index 3c1f5aa420..66b7eadf20 100644 --- a/.gitmodules +++ b/.gitmodules @@ -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 diff --git a/app/controllers/Coach.scala b/app/controllers/Coach.scala index 7383244ecb..08fa019bb2 100644 --- a/app/controllers/Coach.scala +++ b/app/controllers/Coach.scala @@ -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 } diff --git a/app/views/coach/reviewForm.scala.html b/app/views/coach/reviewForm.scala.html new file mode 100644 index 0000000000..93e191d1f9 --- /dev/null +++ b/app/views/coach/reviewForm.scala.html @@ -0,0 +1,3 @@ +@(c: lila.coach.Coach.WithUser, me: User)(implicit ctx: Context) + +Review form. diff --git a/app/views/coach/reviews.scala.html b/app/views/coach/reviews.scala.html new file mode 100644 index 0000000000..61790401f9 --- /dev/null +++ b/app/views/coach/reviews.scala.html @@ -0,0 +1,3 @@ +@(c: lila.coach.Coach.WithUser, coachReviews: lila.coach.CoachReview.Reviews)(implicit ctx: Context) + +Reviews list. diff --git a/app/views/coach/show.scala.html b/app/views/coach/show.scala.html index a48e3d3117..28b1fac79d 100644 --- a/app/views/coach/show.scala.html +++ b/app/views/coach/show.scala.html @@ -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) {
@pic(c, 250) diff --git a/modules/coach/src/main/BsonHandlers.scala b/modules/coach/src/main/BsonHandlers.scala index dcb8c0ab7e..f14d32a977 100644 --- a/modules/coach/src/main/BsonHandlers.scala +++ b/modules/coach/src/main/BsonHandlers.scala @@ -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]) } diff --git a/modules/coach/src/main/CoachApi.scala b/modules/coach/src/main/CoachApi.scala index cbbc94bc5f..6cdbf9a87e 100644 --- a/modules/coach/src/main/CoachApi.scala +++ b/modules/coach/src/main/CoachApi.scala @@ -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) + } } diff --git a/modules/coach/src/main/CoachReview.scala b/modules/coach/src/main/CoachReview.scala index 3913db457e..bd86dc0b19 100644 --- a/modules/coach/src/main/CoachReview.scala +++ b/modules/coach/src/main/CoachReview.scala @@ -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) + } + } +} diff --git a/public/javascripts/coach.js b/public/javascripts/coach.js new file mode 100644 index 0000000000..fe3310fe71 --- /dev/null +++ b/public/javascripts/coach.js @@ -0,0 +1,5 @@ +$(function() { + $(".bar-rating").barrating({ + theme: 'fontawesome-stars' + }); +});