From e5ad9999e128ef644587cab33d6de59c957745b3 Mon Sep 17 00:00:00 2001 From: Thibault Duplessis Date: Sat, 18 Jan 2020 10:18:48 -0600 Subject: [PATCH] class student creation UX --- app/controllers/Clas.scala | 39 ++++++++++++----------- app/views/clas/student.scala | 12 ++++--- modules/clas/src/main/ClasForm.scala | 4 +-- modules/clas/src/main/NameGenerator.scala | 2 -- ui/site/src/clas.js | 5 ++- 5 files changed, 34 insertions(+), 28 deletions(-) diff --git a/app/controllers/Clas.scala b/app/controllers/Clas.scala index 25a2f4e6e6..dac45ca83d 100644 --- a/app/controllers/Clas.scala +++ b/app/controllers/Clas.scala @@ -88,27 +88,30 @@ final class Clas( } def studentForm(id: String) = Secure(_.Teacher) { implicit ctx => me => - WithClassAndStudents(me, id) { _ => (clas, students) => - ctx.req.flash.get("created").map(_ split ' ').?? { - case Array(userId, password) => - env.clas.api.student - .get(clas, userId) - .map2(lila.clas.Student.WithPassword(_, lila.user.User.ClearPassword(password))) - case _ => fuccess(none) - } flatMap { created => - env.clas.forms.student.generate map { createForm => - Ok( - html.clas.student.form( - clas, - students, - env.clas.forms.student.invite, - createForm, - created + if (getBool("gen")) env.clas.nameGenerator() map { + Ok(_) + } else + WithClassAndStudents(me, id) { _ => (clas, students) => + ctx.req.flash.get("created").map(_ split ' ').?? { + case Array(userId, password) => + env.clas.api.student + .get(clas, userId) + .map2(lila.clas.Student.WithPassword(_, lila.user.User.ClearPassword(password))) + case _ => fuccess(none) + } flatMap { created => + env.clas.forms.student.generate map { createForm => + Ok( + html.clas.student.form( + clas, + students, + env.clas.forms.student.invite, + createForm, + created + ) ) - ) + } } } - } } def studentCreate(id: String) = SecureBody(_.Teacher) { implicit ctx => me => diff --git a/app/views/clas/student.scala b/app/views/clas/student.scala index cfadc9d8be..0f14fe3107 100644 --- a/app/views/clas/student.scala +++ b/app/views/clas/student.scala @@ -140,9 +140,9 @@ object student { ) ) - private def realNameField(form: Form[_])(implicit ctx: Context) = + private def realNameField(form: Form[_], fieldName: String = "realName")(implicit ctx: Context) = form3.group( - form("realName"), + form(fieldName), frag("Real name"), help = frag("Private. Will never be shown to anyone else. Helps you remember who that student is.").some )(form3.input(_)) @@ -216,13 +216,15 @@ Password: ${password.value}""") ), postForm(cls := "form3", action := routes.Clas.studentCreate(c.id.value))( form3.group( - create("username"), + create("create-username"), frag("Lichess username"), - help = a(cls := "name-regen")("Generate a new name").some + help = a(cls := "name-regen", href := s"${routes.Clas.studentForm(c.id.value)}?gen=1")( + "Generate a new username" + ).some )( form3.input(_)(created.isDefined option autofocus) ), - realNameField(create), + realNameField(create, "create-realName"), form3.submit(trans.signUp(), icon = none) ) ) diff --git a/modules/clas/src/main/ClasForm.scala b/modules/clas/src/main/ClasForm.scala index 7ed60695d3..df4c535977 100644 --- a/modules/clas/src/main/ClasForm.scala +++ b/modules/clas/src/main/ClasForm.scala @@ -31,8 +31,8 @@ final class ClasForm( def create: Form[NewStudent] = Form( mapping( - "username" -> securityForms.signup.username, - "realName" -> nonEmptyText(maxLength = 100) + "create-username" -> securityForms.signup.username, + "create-realName" -> nonEmptyText(maxLength = 100) )(NewStudent.apply)(NewStudent.unapply) ) diff --git a/modules/clas/src/main/NameGenerator.scala b/modules/clas/src/main/NameGenerator.scala index c497cdf788..3da21bd935 100644 --- a/modules/clas/src/main/NameGenerator.scala +++ b/modules/clas/src/main/NameGenerator.scala @@ -81,7 +81,6 @@ final class NameGenerator(userRepo: lila.user.UserRepo)(implicit ec: ExecutionCo "Carabao", "Cariboo", "Cat", - "Cattle", "Cheetah", "Chicken", "Chimpanzee", @@ -127,7 +126,6 @@ final class NameGenerator(userRepo: lila.user.UserRepo)(implicit ec: ExecutionCo "Hornet", "Horse", "Hound", - "Human", "Hyena", "Impala", "Insect", diff --git a/ui/site/src/clas.js b/ui/site/src/clas.js index cebafbbb6d..bc27c40318 100644 --- a/ui/site/src/clas.js +++ b/ui/site/src/clas.js @@ -4,5 +4,8 @@ $(function() { $('table.sortable').each(function() { tablesort(this, {}); }); - $('.name-regen').click(() => location.reload()); + $('.name-regen').click(function() { + $.get($(this).attr('href'), name => $('#form3-create-username').val(name)); + return false; + }); });