class news for students
parent
1b13ee35a9
commit
66b673a90a
|
@ -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 =>
|
||||
|
|
|
@ -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))
|
||||
)
|
||||
|
||||
|
|
|
@ -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()),
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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';
|
||||
|
|
Loading…
Reference in New Issue