This commit is contained in:
2020-08-14 15:35:45 +02:00
parent 1b79635ffa
commit b90df61020
12 changed files with 29 additions and 35 deletions
-1
View File
@@ -45,5 +45,4 @@ object Config {
host = value("host"),
port = value("port").toInt(),
)
}
-1
View File
@@ -23,7 +23,6 @@ import org.koin.dsl.module
import org.slf4j.LoggerFactory
import be.simplenotes.shared.config.ServerConfig as SimpleNotesServeConfig
fun main() {
val koin = startKoin {
modules(
@@ -29,16 +29,19 @@ class NoteController(
val markdownForm = request.form("markdown") ?: ""
return noteService.create(jwtPayload.userId, markdownForm).fold({
val html = when (it) {
MissingMeta -> view.noteEditor(jwtPayload, error = "Missing note metadata", textarea = markdownForm)
InvalidMeta -> view.noteEditor(jwtPayload, error = "Invalid note metadata", textarea = markdownForm)
is ValidationError -> view.noteEditor(jwtPayload, validationErrors = it.validationErrors, textarea = markdownForm)
return noteService.create(jwtPayload.userId, markdownForm).fold(
{
val html = when (it) {
MissingMeta -> view.noteEditor(jwtPayload, error = "Missing note metadata", textarea = markdownForm)
InvalidMeta -> view.noteEditor(jwtPayload, error = "Invalid note metadata", textarea = markdownForm)
is ValidationError -> view.noteEditor(jwtPayload, validationErrors = it.validationErrors, textarea = markdownForm)
}
Response(BAD_REQUEST).html(html)
},
{
Response.redirect("/notes/${it.uuid}")
}
Response(BAD_REQUEST).html(html)
}, {
Response.redirect("/notes/${it.uuid}")
})
)
}
fun list(request: Request, jwtPayload: JwtPayload): Response {
@@ -71,17 +74,19 @@ class NoteController(
val markdownForm = request.form("markdown") ?: ""
return noteService.update(jwtPayload.userId, note.uuid, markdownForm).fold({
val html = when (it) {
MissingMeta -> view.noteEditor(jwtPayload, error = "Missing note metadata", textarea = markdownForm)
InvalidMeta -> view.noteEditor(jwtPayload, error = "Invalid note metadata", textarea = markdownForm)
is ValidationError -> view.noteEditor(jwtPayload, validationErrors = it.validationErrors, textarea = markdownForm)
return noteService.update(jwtPayload.userId, note.uuid, markdownForm).fold(
{
val html = when (it) {
MissingMeta -> view.noteEditor(jwtPayload, error = "Missing note metadata", textarea = markdownForm)
InvalidMeta -> view.noteEditor(jwtPayload, error = "Invalid note metadata", textarea = markdownForm)
is ValidationError -> view.noteEditor(jwtPayload, validationErrors = it.validationErrors, textarea = markdownForm)
}
Response(BAD_REQUEST).html(html)
},
{
Response.redirect("/notes/${note.uuid}")
}
Response(BAD_REQUEST).html(html)
}, {
Response.redirect("/notes/${note.uuid}")
})
)
}
private fun Request.uuidPath(): UUID? {
@@ -92,5 +97,4 @@ class NoteController(
null
}
}
}
@@ -110,5 +110,4 @@ class UserController(
fun logout(@Suppress("UNUSED_PARAMETER") request: Request) = Response.redirect("/")
.invalidateCookie("Authorization")
}
+3 -3
View File
@@ -64,7 +64,7 @@ class NoteView(staticFileResolver: StaticFileResolver) : View(staticFileResolver
ul {
notes.forEach { (title, tags, _, uuid) ->
li("flex justify-between") {
a(classes = "text-blue-200 text-xl hover:underline", href = "/notes/${uuid}") {
a(classes = "text-blue-200 text-xl hover:underline", href = "/notes/$uuid") {
+title
}
span {
@@ -84,9 +84,9 @@ class NoteView(staticFileResolver: StaticFileResolver) : View(staticFileResolver
private fun DIV.pagination(currentPage: Int, numberOfPages: Int) {
val links = mutableListOf<Pair<String, String>>()
//if (currentPage > 1) links += "Previous" to "?page=${currentPage - 1}"
// if (currentPage > 1) links += "Previous" to "?page=${currentPage - 1}"
links += (1..numberOfPages).map { "$it" to "?page=$it" }
//if (currentPage < numberOfPages) links += "Next" to "?page=${currentPage + 1}"
// if (currentPage < numberOfPages) links += "Next" to "?page=${currentPage + 1}"
nav("pages") {
links.forEach { (name, href) ->
+1 -1
View File
@@ -25,7 +25,7 @@ abstract class View(private val staticFileResolver: StaticFileResolver) {
title("$title - SimpleNotes")
description?.let { meta(name = "description", content = it) }
link(rel = "stylesheet", href = styles)
link(rel = "shortcut icon", href="/favicon.ico", type = "image/x-icon")
link(rel = "shortcut icon", href = "/favicon.ico", type = "image/x-icon")
}
body("bg-gray-900 text-white") {
navbar(jwtPayload)