class news for students
This commit is contained in:
parent
1b13ee35a9
commit
66b673a90a
|
@ -67,37 +67,48 @@ final class Clas(
|
||||||
env.user.lightUserApi.preloadUsers(students.map(_.user))
|
env.user.lightUserApi.preloadUsers(students.map(_.user))
|
||||||
|
|
||||||
def show(id: String) = Auth { implicit ctx => me =>
|
def show(id: String) = Auth { implicit ctx => me =>
|
||||||
isGranted(_.Teacher).??(env.clas.api.clas.isTeacherOf(me, lila.clas.Clas.Id(id))) flatMap {
|
WithClassAny(id, me)(
|
||||||
case true =>
|
forTeacher = WithClass(me, id) { _ => clas =>
|
||||||
WithClass(me, id) { _ => clas =>
|
env.clas.api.student.activeWithUsers(clas) map { students =>
|
||||||
env.clas.api.student.activeWithUsers(clas) map { students =>
|
preloadStudentUsers(students)
|
||||||
preloadStudentUsers(students)
|
views.html.clas.teacherDashboard.overview(clas, 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 _ =>
|
case _ =>
|
||||||
env.clas.api.clas.byId(lila.clas.Clas.Id(id)) flatMap {
|
env.clas.api.clas.byId(lila.clas.Clas.Id(id)) flatMap {
|
||||||
_ ?? { clas =>
|
_ ?? { clas =>
|
||||||
env.clas.api.teacher.of(clas) flatMap { teachers =>
|
env.clas.api.student.activeWithUsers(clas) flatMap { students =>
|
||||||
env.clas.api.student.activeWithUsers(clas) flatMap { students =>
|
students.exists(_.student is me) ?? forStudent(clas, students)
|
||||||
if (students.exists(_.student is me)) {
|
|
||||||
preloadStudentUsers(students)
|
|
||||||
Ok(views.html.clas.studentDashboard(clas, teachers, students)).fuccess
|
|
||||||
} else notFound
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
def wall(id: String) = Secure(_.Teacher) { implicit ctx => me =>
|
def wall(id: String) = Secure(_.Teacher) { implicit ctx => me =>
|
||||||
WithClass(me, id) { _ => clas =>
|
WithClassAny(id, me)(
|
||||||
env.clas.api.student.allWithUsers(clas) map { students =>
|
forTeacher = WithClass(me, id) { _ => clas =>
|
||||||
val wall = scalatags.Text.all.raw(env.clas.markup(clas.wall))
|
env.clas.api.student.allWithUsers(clas) map { students =>
|
||||||
views.html.clas.wall.show(clas, wall, 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 =>
|
def wallEdit(id: String) = Secure(_.Teacher) { implicit ctx => me =>
|
||||||
|
|
|
@ -13,6 +13,7 @@ object studentDashboard {
|
||||||
|
|
||||||
def apply(
|
def apply(
|
||||||
c: Clas,
|
c: Clas,
|
||||||
|
wall: Frag,
|
||||||
teachers: List[Teacher.WithUser],
|
teachers: List[Teacher.WithUser],
|
||||||
students: List[Student.WithUser]
|
students: List[Student.WithUser]
|
||||||
)(implicit ctx: Context) =
|
)(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))
|
div(cls := "students")(studentList(students))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -31,13 +31,25 @@ object wall {
|
||||||
form: Form[_]
|
form: Form[_]
|
||||||
)(implicit ctx: Context) =
|
)(implicit ctx: Context) =
|
||||||
teacherDashboard.layout(c, students, "wall")(
|
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))(
|
postForm(cls := "form3", action := routes.Clas.wallUpdate(c.id.value))(
|
||||||
form3.globalError(form),
|
form3.globalError(form),
|
||||||
form3.group(
|
form3.group(
|
||||||
form("wall"),
|
form("wall"),
|
||||||
frag("Class news"),
|
frag("Class news")
|
||||||
help = frag("Add the most recent news at the top.").some
|
|
||||||
)(form3.textarea(_)(rows := 20)),
|
)(form3.textarea(_)(rows := 20)),
|
||||||
form3.actions(
|
form3.actions(
|
||||||
a(href := routes.Clas.wall(c.id.value))(trans.cancel()),
|
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 {
|
.dashboard {
|
||||||
|
|
||||||
.flash {
|
.flash {
|
||||||
margin: 0;
|
margin: 2em 2em 0 2em;
|
||||||
&__content {
|
&__content {
|
||||||
padding: 2em var(--box-padding);
|
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 {
|
.teachers {
|
||||||
margin-bottom: 2em;
|
margin-bottom: 2em;
|
||||||
}
|
}
|
||||||
|
.clas-wall {
|
||||||
|
max-height: 50vh;
|
||||||
|
overflow-y: auto;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&-teacher {
|
&-teacher {
|
||||||
|
@ -286,6 +289,12 @@ $c-bg-clas-over-dim: mix($c-bg-clas-over, $c-bg-clas, 80%);
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
margin-top: 4em;
|
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/form/form3';
|
||||||
@import '../../../common/css/component/slist';
|
@import '../../../common/css/component/slist';
|
||||||
@import '../../../common/css/component/tablesort';
|
@import '../../../common/css/component/tablesort';
|
||||||
|
@import '../../../common/css/base/scrollbar';
|
||||||
@import '../user/activity';
|
@import '../user/activity';
|
||||||
@import '../clas';
|
@import '../clas';
|
||||||
|
|
Loading…
Reference in a new issue