From 0769a7b4462c1abce8b96161d6ecca26334b4fbe Mon Sep 17 00:00:00 2001 From: Thibault Duplessis Date: Sun, 19 Jan 2020 12:23:42 -0600 Subject: [PATCH] improve class student dashboard --- app/controllers/Clas.scala | 12 ++--- app/views/clas/studentDashboard.scala | 63 +++++++++++++++++++++------ modules/clas/src/main/ClasApi.scala | 14 +++++- ui/site/css/_clas.scss | 20 +++++---- 4 files changed, 80 insertions(+), 29 deletions(-) diff --git a/app/controllers/Clas.scala b/app/controllers/Clas.scala index 89773403f4..f5d3d5a21b 100644 --- a/app/controllers/Clas.scala +++ b/app/controllers/Clas.scala @@ -60,11 +60,13 @@ final class Clas( case _ => env.clas.api.clas.byId(lila.clas.Clas.Id(id)) flatMap { _ ?? { clas => - env.clas.api.student.activeWithUsers(clas) flatMap { students => - if (students.exists(_.student is me)) { - preloadStudentUsers(students) - Ok(views.html.clas.studentDashboard(clas, students)).fuccess - } else notFound + env.clas.api.teacher.of(clas) flatMap { teachers => + env.clas.api.student.activeWithUsers(clas) flatMap { students => + if (students.exists(_.student is me)) { + preloadStudentUsers(students) + Ok(views.html.clas.studentDashboard(clas, teachers, students)).fuccess + } else notFound + } } } } diff --git a/app/views/clas/studentDashboard.scala b/app/views/clas/studentDashboard.scala index e4a1515a01..2c2d8ec7a4 100644 --- a/app/views/clas/studentDashboard.scala +++ b/app/views/clas/studentDashboard.scala @@ -4,13 +4,14 @@ import controllers.routes import lila.api.Context import lila.app.templating.Environment._ import lila.app.ui.ScalatagsTemplate._ -import lila.clas.{ Clas, Student } +import lila.clas.{ Clas, Student, Teacher } import lila.common.String.html.richText object studentDashboard { def apply( c: Clas, + teachers: List[Teacher.WithUser], students: List[Student.WithUser] )(implicit ctx: Context) = bits.layout(c.name, Left(c withStudents Nil))( @@ -18,12 +19,43 @@ object studentDashboard { div(cls := "box__top")( h1(dataIcon := "f", cls := "text")(c.name) ), - div(cls := "box__pad")( - c.desc.nonEmpty option div(cls := "clas-desc")(richText(c.desc)), - c.archived map { archived => + c.archived map { archived => + div(cls := "box__pad")( div(cls := "clas-show__archived archived")(bits.showArchived(archived)) - }, - clas.teachers(c) + ) + }, + c.desc.trim.nonEmpty option div(cls := "clas-show__overview")(richText(c.desc)), + table(cls := "slist slist-pad teachers")( + thead( + tr( + th("Teachers"), + th, + th + ) + ), + tbody( + teachers.map { + case Teacher.WithUser(_, user) => + tr( + td( + userLink( + user, + name = span( + strong(user.username), + user.profile.flatMap(_.nonEmptyRealName) map { em(_) } + ).some, + withTitle = false + ) + ), + td( + user.seenAt.map { seen => + trans.lastSeenActive(momentFromNow(seen)) + } + ), + challengeTd(user) + ) + } + ) ), div(cls := "students")(studentList(students)) ) @@ -55,16 +87,19 @@ object studentDashboard { td(cls := "rating")(user.best3Perfs.map { showPerfRating(user, _) }), td(user.count.game.localize), td(user.perfs.puzzle.nb.localize), - td( - a( - dataIcon := "U", - cls := "button button-empty", - title := trans.challengeToPlay.txt(), - href := s"${routes.Lobby.home()}?user=${user.username}#friend" - ) - ) + challengeTd(user) ) } ) ) + + private def challengeTd(user: lila.user.User)(implicit ctx: Context) = + td( + a( + dataIcon := "U", + cls := "button button-empty", + title := trans.challengeToPlay.txt(), + href := s"${routes.Lobby.home()}?user=${user.username}#friend" + ) + ) } diff --git a/modules/clas/src/main/ClasApi.scala b/modules/clas/src/main/ClasApi.scala index cd6ec6736c..50f1fe5a77 100644 --- a/modules/clas/src/main/ClasApi.scala +++ b/modules/clas/src/main/ClasApi.scala @@ -34,8 +34,18 @@ final class ClasApi( coll.insert.one(teacher) inject Teacher.WithUser(teacher, user) } - // def of(clas: Clas): Fu[List[Teacher]] = - // coll.ext.byOrderedIds[Teacher, Teacher.Id](clas.teacherIds)(_.id) + def of(clas: Clas): Fu[List[Teacher.WithUser]] = + coll.ext.byOrderedIds[Teacher, Teacher.Id](clas.teachers.toList)(_.id) flatMap withUsers + + def withUsers(teachers: List[Teacher]): Fu[List[Teacher.WithUser]] = + userRepo.coll.idsMap[User, User.ID]( + teachers.map(_.userId), + ReadPreference.secondaryPreferred + )(_.id) map { users => + teachers.flatMap { s => + users.get(s.userId) map { Teacher.WithUser(s, _) } + } + } } object clas { diff --git a/ui/site/css/_clas.scss b/ui/site/css/_clas.scss index 9a2609831f..6ae643e66d 100644 --- a/ui/site/css/_clas.scss +++ b/ui/site/css/_clas.scss @@ -91,9 +91,6 @@ $clas-color: rgb(127, 90, 240); &__overview { @extend %box-padding; background: $c-bg-zebra; - .clas-desc { - margin-bottom: 2em; - } } &__archived { @@ -113,10 +110,13 @@ $clas-color: rgb(127, 90, 240); } } - .students { + .students, .teachers { th:first-child { font-weight: bold; } + .button { + font-size: 1.2em; + } .user-link { @extend %flex-center; span { @@ -130,6 +130,8 @@ $clas-color: rgb(127, 90, 240); display: block; } } + } + .students { .rating { font-weight: bold; span { @@ -142,15 +144,17 @@ $clas-color: rgb(127, 90, 240); } &-student { - .students { - .button { - font-size: 1.2em; - } + .teachers { + margin-bottom: 2em; } } &-teacher { + .clas-desc { + margin-bottom: 2em; + } + .progress { @extend %box-padding; background: $c-bg-zebra;