improve class student dashboard
parent
1cd41801ea
commit
0769a7b446
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
)
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue