generic flash messages and various code tweaks
parent
e0d39cdb97
commit
8f6deba831
|
@ -282,7 +282,8 @@ final class Account(
|
|||
FormFuResult(form) { err =>
|
||||
fuccess(html.account.kid(me, err))
|
||||
} { _ =>
|
||||
env.user.repo.setKid(me, getBool("v")) inject Redirect(routes.Account.kid)
|
||||
env.user.repo.setKid(me, getBool("v")) inject
|
||||
Redirect(routes.Account.kid).flashSuccess
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ final class Clas(
|
|||
def index = Secure(_.Teacher) { implicit ctx => me =>
|
||||
WithTeacher(me) { t =>
|
||||
env.clas.api.clas.of(t.teacher) map { classes =>
|
||||
Ok(views.html.clas.clas.index(classes, t))
|
||||
Ok(views.html.clas.clas.index(classes))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -37,9 +37,9 @@ final class Clas(
|
|||
|
||||
def show(id: String) = Auth { implicit ctx => me =>
|
||||
if (isGranted(_.Teacher))
|
||||
WithClass(me, lila.clas.Clas.Id(id)) { t => clas =>
|
||||
WithClass(me, lila.clas.Clas.Id(id)) { _ => clas =>
|
||||
env.clas.api.student.of(clas) map { students =>
|
||||
views.html.clas.clas.showToTeacher(clas, t, students)
|
||||
views.html.clas.clas.showToTeacher(clas, students)
|
||||
}
|
||||
} else
|
||||
env.clas.api.clas.byId(lila.clas.Clas.Id(id)) flatMap {
|
||||
|
@ -130,8 +130,7 @@ final class Clas(
|
|||
env.user.repo named username flatMap {
|
||||
_ ?? { user =>
|
||||
env.clas.api.student.invite(clas, user, t) inject
|
||||
Redirect(routes.Clas.studentForm(clas.id.value))
|
||||
.flashing("success" -> s"${user.username} has been invited")
|
||||
Redirect(routes.Clas.studentForm(clas.id.value)).flashSuccess
|
||||
}
|
||||
}
|
||||
)
|
||||
|
|
|
@ -30,7 +30,11 @@ abstract private[controllers] class LilaController(val env: Env)
|
|||
implicit protected val LilaResultZero = Zero.instance[Result](Results.NotFound)
|
||||
|
||||
implicit final protected class LilaPimpedResult(result: Result) {
|
||||
def fuccess = scala.concurrent.Future successful result
|
||||
def fuccess = scala.concurrent.Future successful result
|
||||
def flashSuccess(msg: String): Result = result.flashing("success" -> msg)
|
||||
def flashSuccess: Result = flashSuccess("")
|
||||
def flashFailure(msg: String): Result = result.flashing("failure" -> msg)
|
||||
def flashFailure: Result = flashFailure("")
|
||||
}
|
||||
|
||||
implicit protected def LilaFragToResult(frag: Frag): Result = Ok(frag)
|
||||
|
|
|
@ -23,6 +23,7 @@ object Environment
|
|||
with SecurityHelper
|
||||
with TeamHelper
|
||||
with TournamentHelper
|
||||
with FlashHelper
|
||||
with ChessgroundHelper {
|
||||
|
||||
// #TODO holy shit fix me
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package lila.app
|
||||
package templating
|
||||
|
||||
import lila.api.Context
|
||||
import lila.app.ui.ScalatagsTemplate._
|
||||
|
||||
trait FlashHelper { self: I18nHelper =>
|
||||
|
||||
def standardFlash(implicit ctx: Context): Option[Frag] =
|
||||
successFlash orElse failureFlash
|
||||
|
||||
def successFlash(implicit ctx: Context): Option[Frag] =
|
||||
ctx.flash("success").map { msg =>
|
||||
div(cls := "flash flash-success")(
|
||||
if (msg.isEmpty) trans.success()
|
||||
else msg
|
||||
)
|
||||
}
|
||||
|
||||
def failureFlash(implicit ctx: Context): Option[Frag] =
|
||||
ctx.flash("failure").map { msg =>
|
||||
div(cls := "flash flash-failure")(
|
||||
if (msg.isEmpty) "Failure"
|
||||
else msg
|
||||
)
|
||||
}
|
||||
}
|
|
@ -21,7 +21,7 @@ object close {
|
|||
div(cls := "form-group")(
|
||||
"You will not be allowed to open a new account with the same name, even if the case is different."
|
||||
),
|
||||
form3.passwordModified(form("passwd"), trans.password())(autocomplete := "off"),
|
||||
form3.passwordModified(form("passwd"), trans.password())(autofocus, autocomplete := "off"),
|
||||
form3.actions(
|
||||
frag(
|
||||
a(href := routes.User.show(u.username))(trans.changedMindDoNotCloseAccount()),
|
||||
|
|
|
@ -16,12 +16,13 @@ object kid {
|
|||
) {
|
||||
div(cls := "account box box-pad")(
|
||||
h1(trans.kidMode()),
|
||||
standardFlash,
|
||||
p(trans.kidModeExplanation()),
|
||||
br,
|
||||
br,
|
||||
br,
|
||||
postForm(action := s"${routes.Account.kidPost}?v=${!u.kid}")(
|
||||
form3.passwordModified(form("passwd"), trans.password())(autocomplete := "off"),
|
||||
postForm(cls := "form3", action := s"${routes.Account.kidPost}?v=${!u.kid}")(
|
||||
form3.passwordModified(form("passwd"), trans.password())(autofocus, autocomplete := "off"),
|
||||
submitButton(
|
||||
cls := List(
|
||||
"button" -> true,
|
||||
|
|
|
@ -3,7 +3,7 @@ package views.html.clas
|
|||
import lila.api.Context
|
||||
import lila.app.templating.Environment._
|
||||
import lila.app.ui.ScalatagsTemplate._
|
||||
import lila.clas.{ Clas, Student, Teacher }
|
||||
import lila.clas.Clas
|
||||
import controllers.routes
|
||||
|
||||
object bits {
|
||||
|
|
|
@ -5,16 +5,13 @@ import play.api.data.Form
|
|||
import lila.api.Context
|
||||
import lila.app.templating.Environment._
|
||||
import lila.app.ui.ScalatagsTemplate._
|
||||
import lila.clas.{ Clas, Student, Teacher }
|
||||
import lila.clas.{ Clas, Student }
|
||||
import lila.clas.ClasForm.Data
|
||||
import controllers.routes
|
||||
|
||||
object clas {
|
||||
|
||||
def index(
|
||||
classes: List[Clas],
|
||||
teacher: Teacher.WithUser
|
||||
)(implicit ctx: Context) =
|
||||
def index(classes: List[Clas])(implicit ctx: Context) =
|
||||
bits.layout("Lichess Classes", Right("classes"))(
|
||||
cls := "clas-index",
|
||||
div(cls := "box__top")(
|
||||
|
@ -44,7 +41,6 @@ object clas {
|
|||
|
||||
def showToTeacher(
|
||||
clas: Clas,
|
||||
teacher: Teacher.WithUser,
|
||||
students: List[Student.WithUser]
|
||||
)(implicit ctx: Context) =
|
||||
bits.layout(clas.name, Left(clas))(
|
||||
|
|
|
@ -89,9 +89,7 @@ object student {
|
|||
"To ",
|
||||
a(href := routes.Clas.show(c.id.value))(c.name)
|
||||
),
|
||||
ctx.flash("success") map { msg =>
|
||||
div(cls := "flash-success")(msg)
|
||||
},
|
||||
standardFlash,
|
||||
div(cls := "student-add__choice")(
|
||||
div(cls := "info")(
|
||||
h2("Invite a Lichess account"),
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
.flash {
|
||||
@extend %box-radius;
|
||||
padding: 1em 2em;
|
||||
margin: 2em 0;
|
||||
background: $c-good;
|
||||
color: $c-good-over;
|
||||
|
||||
&::before {
|
||||
@extend %data-icon;
|
||||
content: 'E';
|
||||
margin-right: 1em;
|
||||
font-size: 1.5em;
|
||||
}
|
||||
|
||||
&-failure {
|
||||
background: $c-bad;
|
||||
color: $c-bad-over;
|
||||
&::before {
|
||||
@extend %data-icon;
|
||||
content: 'j';
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
@import 'cmn-toggle';
|
||||
@import '../component/flash';
|
||||
|
||||
.form-group {
|
||||
margin-bottom: 2rem;
|
||||
|
|
|
@ -102,20 +102,6 @@
|
|||
|
||||
.student-add {
|
||||
|
||||
.flash-success {
|
||||
@extend %box-radius;
|
||||
padding: 1em 2em;
|
||||
margin: 2em 0;
|
||||
background: $c-good;
|
||||
color: $c-good-over;
|
||||
&::before {
|
||||
@extend %data-icon;
|
||||
content: 'E';
|
||||
margin-right: 1em;
|
||||
font-size: 1.5em;
|
||||
}
|
||||
}
|
||||
|
||||
&__choice {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(20em, 1fr));
|
||||
|
|
Loading…
Reference in New Issue