From 66b673a90af97e343ac272be95870dced2d6a0ab Mon Sep 17 00:00:00 2001 From: Thibault Duplessis Date: Thu, 30 Jan 2020 15:43:50 -0600 Subject: [PATCH] class news for students --- app/controllers/Clas.scala | 53 ++++++++++++++++----------- app/views/clas/studentDashboard.scala | 2 + app/views/clas/wall.scala | 18 +++++++-- ui/site/css/_clas.scss | 13 ++++++- ui/site/css/build/_clas.scss | 1 + 5 files changed, 61 insertions(+), 26 deletions(-) diff --git a/app/controllers/Clas.scala b/app/controllers/Clas.scala index a9ab247a22..591a58d074 100644 --- a/app/controllers/Clas.scala +++ b/app/controllers/Clas.scala @@ -67,37 +67,48 @@ final class Clas( env.user.lightUserApi.preloadUsers(students.map(_.user)) def show(id: String) = Auth { implicit ctx => me => - isGranted(_.Teacher).??(env.clas.api.clas.isTeacherOf(me, lila.clas.Clas.Id(id))) flatMap { - case true => - WithClass(me, id) { _ => clas => - env.clas.api.student.activeWithUsers(clas) map { students => - preloadStudentUsers(students) - views.html.clas.teacherDashboard.overview(clas, students) - } + WithClassAny(id, me)( + forTeacher = WithClass(me, id) { _ => clas => + env.clas.api.student.activeWithUsers(clas) map { students => + preloadStudentUsers(students) + views.html.clas.teacherDashboard.overview(clas, students) } + }, + forStudent = (clas, students) => + env.clas.api.teacher.of(clas) map { teachers => + preloadStudentUsers(students) + val wall = scalatags.Text.all.raw(env.clas.markup(clas.wall)) + Ok(views.html.clas.studentDashboard(clas, wall, teachers, students)) + } + ) + } + + private def WithClassAny(id: String, me: lila.user.User)( + forTeacher: => Fu[Result], + forStudent: (lila.clas.Clas, List[lila.clas.Student.WithUser]) => Fu[Result] + )(implicit ctx: Context): Fu[Result] = + isGranted(_.Teacher).??(env.clas.api.clas.isTeacherOf(me, lila.clas.Clas.Id(id))) flatMap { + case true => forTeacher case _ => env.clas.api.clas.byId(lila.clas.Clas.Id(id)) flatMap { _ ?? { clas => - 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 - } + env.clas.api.student.activeWithUsers(clas) flatMap { students => + students.exists(_.student is me) ?? forStudent(clas, students) } } } } - } def wall(id: String) = Secure(_.Teacher) { implicit ctx => me => - WithClass(me, id) { _ => clas => - env.clas.api.student.allWithUsers(clas) map { students => - val wall = scalatags.Text.all.raw(env.clas.markup(clas.wall)) - views.html.clas.wall.show(clas, wall, students) - } - } + WithClassAny(id, me)( + forTeacher = WithClass(me, id) { _ => clas => + env.clas.api.student.allWithUsers(clas) map { students => + val wall = scalatags.Text.all.raw(env.clas.markup(clas.wall)) + views.html.clas.wall.show(clas, wall, students) + } + }, + forStudent = (clas, _) => Redirect(routes.Clas.show(clas.id.value)).fuccess + ) } def wallEdit(id: String) = Secure(_.Teacher) { implicit ctx => me => diff --git a/app/views/clas/studentDashboard.scala b/app/views/clas/studentDashboard.scala index 0478ca7604..3d31d6ec79 100644 --- a/app/views/clas/studentDashboard.scala +++ b/app/views/clas/studentDashboard.scala @@ -13,6 +13,7 @@ object studentDashboard { def apply( c: Clas, + wall: Frag, teachers: List[Teacher.WithUser], students: List[Student.WithUser] )(implicit ctx: Context) = @@ -59,6 +60,7 @@ object studentDashboard { } ) ), + if (c.wall.nonEmpty) div(cls := "box__pad clas-wall")(wall), div(cls := "students")(studentList(students)) ) diff --git a/app/views/clas/wall.scala b/app/views/clas/wall.scala index e01f722c4e..064c8a1797 100644 --- a/app/views/clas/wall.scala +++ b/app/views/clas/wall.scala @@ -31,13 +31,25 @@ object wall { form: Form[_] )(implicit ctx: Context) = teacherDashboard.layout(c, students, "wall")( - div(cls := "box-pad")( + div(cls := "box-pad clas-wall__edit")( + p( + strong("All class news in a single field."), + ul( + li("Add the recent news at the top. Don't delete previous news."), + li("Separate news with --- it will display a horizontal line."), + li( + a(href := "https://guides.github.com/features/mastering-markdown/", target := "_blank")( + "Markdown" + ), + " is available for more advanced syntax." + ) + ) + ), postForm(cls := "form3", action := routes.Clas.wallUpdate(c.id.value))( form3.globalError(form), form3.group( form("wall"), - frag("Class news"), - help = frag("Add the most recent news at the top.").some + frag("Class news") )(form3.textarea(_)(rows := 20)), form3.actions( a(href := routes.Clas.wall(c.id.value))(trans.cancel()), diff --git a/ui/site/css/_clas.scss b/ui/site/css/_clas.scss index 55fb7afaf8..2315402ca1 100644 --- a/ui/site/css/_clas.scss +++ b/ui/site/css/_clas.scss @@ -129,10 +129,9 @@ $c-bg-clas-over-dim: mix($c-bg-clas-over, $c-bg-clas, 80%); .dashboard { .flash { - margin: 0; + margin: 2em 2em 0 2em; &__content { padding: 2em var(--box-padding); - border-radius: 0; } } @@ -214,6 +213,10 @@ $c-bg-clas-over-dim: mix($c-bg-clas-over, $c-bg-clas, 80%); .teachers { margin-bottom: 2em; } + .clas-wall { + max-height: 50vh; + overflow-y: auto; + } } &-teacher { @@ -286,6 +289,12 @@ $c-bg-clas-over-dim: mix($c-bg-clas-over, $c-bg-clas, 80%); justify-content: center; margin-top: 4em; } + .clas-wall__edit { + li { + list-style: disc outside; + margin: .5em 0 0 1.5em; + } + } } } } diff --git a/ui/site/css/build/_clas.scss b/ui/site/css/build/_clas.scss index 06d366c73f..833e16f927 100644 --- a/ui/site/css/build/_clas.scss +++ b/ui/site/css/build/_clas.scss @@ -2,5 +2,6 @@ @import '../../../common/css/form/form3'; @import '../../../common/css/component/slist'; @import '../../../common/css/component/tablesort'; +@import '../../../common/css/base/scrollbar'; @import '../user/activity'; @import '../clas';