rewrite oauth app templates

This commit is contained in:
Thibault Duplessis 2019-04-16 16:03:05 +07:00
parent 8a0567285d
commit 8ed7c30811
7 changed files with 120 additions and 104 deletions

View file

@ -19,13 +19,13 @@ object OAuthApp extends LilaController {
}
def create = Auth { implicit ctx => me =>
Ok(html.oAuth.app.create(env.forms.app.create)).fuccess
Ok(html.oAuth.app.form.create(env.forms.app.create)).fuccess
}
def createApply = AuthBody { implicit ctx => me =>
implicit val req = ctx.body
env.forms.app.create.bindFromRequest.fold(
err => BadRequest(html.oAuth.app.create(err)).fuccess,
err => BadRequest(html.oAuth.app.form.create(err)).fuccess,
setup => {
val app = setup make me
env.appApi.create(app) inject Redirect(routes.OAuthApp.edit(app.clientId.value))
@ -35,7 +35,7 @@ object OAuthApp extends LilaController {
def edit(id: String) = Auth { implicit ctx => me =>
OptionFuResult(env.appApi.findBy(App.Id(id), me)) { app =>
Ok(html.oAuth.app.edit(app, env.forms.app.edit(app))).fuccess
Ok(html.oAuth.app.form.edit(app, env.forms.app.edit(app))).fuccess
}
}
@ -43,7 +43,7 @@ object OAuthApp extends LilaController {
OptionFuResult(env.appApi.findBy(App.Id(id), me)) { app =>
implicit val req = ctx.body
env.forms.app.edit(app).bindFromRequest.fold(
err => BadRequest(html.oAuth.app.edit(app, err)).fuccess,
err => BadRequest(html.oAuth.app.form.edit(app, err)).fuccess,
data => env.appApi.update(app) { data.update(_) } map { r => Redirect(routes.OAuthApp.edit(app.clientId.value)) }
)
}

View file

@ -1,18 +0,0 @@
@(form: Form[_])(implicit ctx: Context)
@title = @{ "New OAuth App" }
@account.layout(
title = title,
active = "oauth.app"
) {
<div class="account oauth box box-pad">
<h1>@title</h1>
<form class="form3" action="@routes.OAuthApp.create" method="POST">
<div class="form-group">
Want to build something that integrates with and extends Lichess? Register a new OAuth App to get started developing on the Lichess API.
</div>
@inForm(form)
</form>
</div>
}.toHtml

View file

@ -1,26 +0,0 @@
@(app: lila.oauth.OAuthApp, form: Form[_])(implicit ctx: Context)
@title = @{ s"Edit ${app.name}" }
@account.layout(
title = title,
active = "oauth.app"
) {
<div class="account oauth box box-pad">
<h1>@title</h1>
<table class="codes">
<tbody>
<tr><th>Client ID</th><td>@app.clientId.value</td></tr>
<tr><th>Client Secret</th><td>@app.clientSecret.value</td></tr>
</tbody>
</table>
<br><br>
<form class="form3" action="@routes.OAuthApp.update(app.clientId.value)" method="POST">
<div class="form-group">
Here's a <a class="blue" href="https://github.com/lichess-org/api/tree/master/example/oauth-authorization-code">lichess OAuth app example</a>,
and the <a class="blue" href="@routes.Api.index">API documentation</a>.
</div>
@inForm(form)
</form>
</div>
}.toHtml

View file

@ -0,0 +1,67 @@
package views.html.oAuth.app
import play.api.data.Form
import lila.api.Context
import lila.app.templating.Environment._
import lila.app.ui.ScalatagsTemplate._
import controllers.routes
object form {
def create(form: Form[_])(implicit ctx: Context) = {
val title = "New OAuth App"
views.html.account.layout(title = title, active = "oauth.app") {
div(cls := "account oauth box box-pad")(
h1(title),
st.form(cls := "form3", action := routes.OAuthApp.create, method := "POST")(
div(cls := "form-group")(
"Want to build something that integrates with and extends Lichess? Register a new OAuth App to get started developing on the Lichess API."
),
inner(form)
)
)
}
}
def edit(app: lila.oauth.OAuthApp, form: Form[_])(implicit ctx: Context) = {
val title = s"Edit ${app.name}"
views.html.account.layout(title = title, active = "oauth.app") {
div(cls := "account oauth box box-pad")(
h1(title),
table(cls := "codes")(
tbody(
tr(th("Client ID"), td(app.clientId.value)),
tr(th("Client Secret"), td(app.clientSecret.value))
)
),
br, br,
st.form(cls := "form3", action := routes.OAuthApp.update(app.clientId.value), method := "POST")(
div(cls := "form-group")(
"Here's a ",
a(href := "https://github.com/lichess-org/api/tree/master/example/oauth-authorization-code")(
"lichess OAuth app example"
),
", and the ", a(href := routes.Api.index)("API documentation"), "."
),
inner(form)
)
)
}
}
private def inner(form: Form[_])(implicit ctx: Context) = frag(
errMsg(form),
form3.group(form("name"), raw("App name"))(form3.input(_)),
form3.group(form("description"), raw("App description"))(form3.textarea(_)()),
form3.split(
form3.group(form("homepageUri"), raw("Homepage URL"), half = true)(form3.input(_, typ = "url")),
form3.group(form("redirectUri"), raw("Callback URL"), half = true, help = frag("It must match the URL in your code").some)(form3.input(_, typ = "url"))
),
form3.actions(
a(href := routes.OAuthApp.index)("Cancel"),
form3.submit(trans.apply.frag())
)
)
}

View file

@ -1,13 +0,0 @@
@(form: Form[_])(implicit ctx: Context)
@import lila.app.ui.ScalatagsTwirlForm._
@form3.group(form("name"), raw("App name"))(form3.input(_))
@form3.group(form("description"), raw("App description"))(form3.textarea(_)())
@form3.split {
@form3.group(form("homepageUri"), raw("Homepage URL"), half = true)(form3.input(_, typ = "url"))
@form3.group(form("redirectUri"), raw("Callback URL"), half = true, help = frag("It must match the URL in your code").some)(form3.input(_, typ = "url"))
}
@form3.actions {
<a href="@routes.OAuthApp.index">Cancel</a>
@form3.submit(trans.apply.frag())
}.toHtml

View file

@ -0,0 +1,49 @@
package views.html.oAuth.app
import lila.api.Context
import lila.app.templating.Environment._
import lila.app.ui.ScalatagsTemplate._
import controllers.routes
object index {
def apply(apps: List[lila.oauth.OAuthApp])(implicit ctx: Context) =
views.html.account.layout(title = "OAuth Apps", active = "oauth.app")(
div(cls := "account oauth box")(
div(cls := "box__top")(
h1("OAuth Apps"),
st.form(cls := "box__top__actions", action := routes.OAuthApp.create)(
button(tpe := "submit", cls := "button button-fat button-empty", title := "New app", dataIcon := "O")
)
),
p(cls := "box__pad")(
"Want to build something that integrates with and extends Lichess? Register a new OAuth App to get started developing on the Lichess API.",
br, br,
"Here's a ",
a(href := "https://github.com/lichess-org/api/tree/master/example/oauth-authorization-code")("lichess OAuth app example"),
", and the ", a(href := routes.Api.index)("API documentation"), "."
),
table(cls := "slist slist-pad")(
apps.map { t =>
tr(
td(
strong(t.name), br,
t.description.map { em(_) }
),
td(cls := "date")(
t.homepageUri, br,
"Created ", momentFromNow(t.createdAt)
),
td(cls := "action")(
a(href := routes.OAuthApp.edit(t.clientId.value), cls := "button", title := "Edit this app", dataIcon := "m"),
st.form(action := routes.OAuthApp.delete(t.clientId.value), method := "POST")(
button(tpe := "submit", cls := "button button-empty button-red confirm", title := "Delete this app", dataIcon := "q")
)
)
)
}
)
)
)
}

View file

@ -1,43 +0,0 @@
@(apps: List[lila.oauth.OAuthApp])(implicit ctx: Context)
@title = @{ "OAuth Apps" }
@account.layout(title = title, active = "oauth.app") {
<div class="account oauth box">
<div class="box__top">
<h1>@title</h1>
<form class="box__top__actions" action="@routes.OAuthApp.create">
<button type="submit" class="button frameless" title="New app" data-icon="O"></button>
</form>
</div>
<p class="box__pad">
Want to build something that integrates with and extends Lichess? Register a new OAuth App to get started developing on the Lichess API.<br />
<br />
Here's a <a class="blue" href="https://github.com/lichess-org/api/tree/master/example/oauth-authorization-code">lichess OAuth app example</a>,
and the <a class="blue" href="@routes.Api.index">API documentation</a>.
</p>
<table class="slist slist-pad">
@apps.map { t =>
<tr>
<td>
<strong>@t.name</strong><br />
@t.description.map { desc =>
<em>@desc</em>
}
</td>
<td class="date">
@t.homepageUri<br />
Created @momentFromNow(t.createdAt).toHtml
</td>
<td class="action">
<a href="@routes.OAuthApp.edit(t.clientId.value)" class="button" title="Edit this app" data-icon="m"></a>
<form action="@routes.OAuthApp.delete(t.clientId.value)" method="POST">
<button type="submit" class="button button-empty button-red confirm" title="Delete this app" data-icon="q"></button>
</form>
</td>
</tr>
}
</table>
</div>
}.toHtml