generic flash messages and various code tweaks

pull/5932/head
Thibault Duplessis 2020-01-17 09:52:31 -06:00
parent e0d39cdb97
commit 8f6deba831
13 changed files with 71 additions and 34 deletions

View File

@ -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
}
}
}

View File

@ -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
}
}
)

View File

@ -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)

View File

@ -23,6 +23,7 @@ object Environment
with SecurityHelper
with TeamHelper
with TournamentHelper
with FlashHelper
with ChessgroundHelper {
// #TODO holy shit fix me

View File

@ -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
)
}
}

View File

@ -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()),

View File

@ -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,

View File

@ -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 {

View File

@ -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))(

View File

@ -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"),

View File

@ -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';
}
}
}

View File

@ -1,4 +1,5 @@
@import 'cmn-toggle';
@import '../component/flash';
.form-group {
margin-bottom: 2rem;

View File

@ -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));