Fix linting warnings

This commit is contained in:
2020-08-22 05:11:59 +02:00
parent bad5322abd
commit eeae982a71
19 changed files with 47 additions and 54 deletions
-1
View File
@@ -18,7 +18,6 @@ import be.simplenotes.persistance.persistanceModule
import be.simplenotes.search.searchModule
import be.simplenotes.shared.config.DataSourceConfig
import be.simplenotes.shared.config.JwtConfig
import org.http4k.core.Filter
import org.http4k.core.RequestContexts
import org.koin.core.context.startKoin
import org.koin.core.qualifier.named
@@ -9,7 +9,6 @@ import be.simplenotes.domain.usecases.NoteService
import be.simplenotes.domain.usecases.markdown.InvalidMeta
import be.simplenotes.domain.usecases.markdown.MissingMeta
import be.simplenotes.domain.usecases.markdown.ValidationError
import be.simplenotes.domain.usecases.search.SearchTerms
import org.http4k.core.Method
import org.http4k.core.Request
import org.http4k.core.Response
@@ -36,9 +35,11 @@ class NoteController(
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,
is ValidationError -> view.noteEditor(
jwtPayload,
validationErrors = it.validationErrors,
textarea = markdownForm)
textarea = markdownForm
)
}
Response(BAD_REQUEST).html(html)
},
@@ -93,9 +94,11 @@ class NoteController(
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,
is ValidationError -> view.noteEditor(
jwtPayload,
validationErrors = it.validationErrors,
textarea = markdownForm)
textarea = markdownForm
)
}
Response(BAD_REQUEST).html(html)
},
@@ -53,8 +53,10 @@ class SettingsController(
val isDownload = request.form("download") != null
val json = userService.export(jwtPayload.userId)
val res = Response(Status.OK).body(json).header("Content-Type", "application/json")
return if (isDownload) res.header("Content-Disposition",
"attachment; filename=\"simplenotes-export-${sanitizeFilename(jwtPayload.username)}.json\"")
return if (isDownload) res.header(
"Content-Disposition",
"attachment; filename=\"simplenotes-export-${sanitizeFilename(jwtPayload.username)}.json\""
)
else res
}
-1
View File
@@ -4,7 +4,6 @@ import be.simplenotes.app.controllers.BaseController
import be.simplenotes.app.controllers.NoteController
import be.simplenotes.app.controllers.SettingsController
import be.simplenotes.app.controllers.UserController
import be.simplenotes.app.filters.ErrorFilter
import be.simplenotes.app.filters.ImmutableFilter
import be.simplenotes.app.filters.SecurityFilter
import be.simplenotes.app.filters.jwtPayload
@@ -2,8 +2,10 @@ package be.simplenotes.app.utils
import be.simplenotes.domain.usecases.search.SearchTerms
private fun innerRegex(name: String) = """$name:['"](.*?)['"]""".toRegex()
private fun outerRegex(name: String) = """($name:['"].*?['"])""".toRegex()
private fun innerRegex(name: String) =
"""$name:['"](.*?)['"]""".toRegex()
private fun outerRegex(name: String) =
"""($name:['"].*?['"])""".toRegex()
private val titleRe = innerRegex("title")
private val outerTitleRe = outerRegex("title")
+5 -4
View File
@@ -10,7 +10,8 @@ class BaseView(staticFileResolver: StaticFileResolver) : View(staticFileResolver
fun renderHome(jwtPayload: JwtPayload?) = renderPage(
title = "Home",
description = "A fast and simple note taking website",
jwtPayload = jwtPayload) {
jwtPayload = jwtPayload
) {
section("text-center my-2 p-2") {
h1("text-5xl") {
span("text-teal-300") { +"Simplenotes " }
@@ -22,7 +23,8 @@ class BaseView(staticFileResolver: StaticFileResolver) : View(staticFileResolver
unsafe {
@Language("html")
val html = """
val html =
"""
<div aria-label="demo" class="md:order-1 order-2 flipped flipped-left p-4 my-10 w-full md:w-1/2">
<div class="flex justify-between mb-4">
<h1 class="text-2xl underline">Notes</h1>
@@ -78,13 +80,12 @@ class BaseView(staticFileResolver: StaticFileResolver) : View(staticFileResolver
</table>
</div>
</div>
""".trimIndent()
""".trimIndent()
+html
}
welcome()
}
}
+4 -4
View File
@@ -3,7 +3,6 @@ package be.simplenotes.app.views
import be.simplenotes.app.utils.StaticFileResolver
import be.simplenotes.app.views.components.Alert
import be.simplenotes.app.views.components.alert
import kotlinx.html.FlowContent
import kotlinx.html.a
import kotlinx.html.div
@@ -18,10 +17,12 @@ class ErrorView(staticFileResolver: StaticFileResolver) : View(staticFileResolve
fun error(errorType: Type) = renderPage(errorType.title, jwtPayload = null) {
div("container mx-auto p-4") {
when (errorType) {
Type.SqlTransientError -> alert(Alert.Warning,
Type.SqlTransientError -> alert(
Alert.Warning,
errorType.title,
"Please try again later",
multiline = true)
multiline = true
)
Type.NotFound -> alert(Alert.Warning, errorType.title, "Page not found", multiline = true)
Type.Other -> alert(Alert.Warning, errorType.title)
}
@@ -30,5 +31,4 @@ class ErrorView(staticFileResolver: StaticFileResolver) : View(staticFileResolve
}
}
}
}
+1 -2
View File
@@ -101,7 +101,6 @@ class NoteView(staticFileResolver: StaticFileResolver) : View(staticFileResolver
}
}
private fun DIV.pagination(currentPage: Int, numberOfPages: Int, tag: String?) {
val links = mutableListOf<Pair<String, String>>()
// if (currentPage > 1) links += "Previous" to "?page=${currentPage - 1}"
@@ -120,7 +119,7 @@ class NoteView(staticFileResolver: StaticFileResolver) : View(staticFileResolver
fun renderedNote(jwtPayload: JwtPayload, note: PersistedNote) = renderPage(
note.meta.title,
jwtPayload = jwtPayload,
scripts = listOf("/highlight.10.1.2.js","/init-highlight.0.0.1.js")
scripts = listOf("/highlight.10.1.2.js", "/init-highlight.0.0.1.js")
) {
div("container mx-auto p-4") {
div("flex items-center justify-between mb-4") {
+3 -2
View File
@@ -33,7 +33,9 @@ class SettingView(staticFileResolver: StaticFileResolver) : View(staticFileResol
form(method = FormMethod.post, action = "/export") {
button(name = "display", classes = "btn btn-teal block", type = submit) { +"Display my data" }
button(name = "download", classes = "btn btn-green block mt-2", type = submit) { +"Download my data" }
button(name = "download", classes = "btn btn-green block mt-2", type = submit) {
+"Download my data"
}
}
}
@@ -72,7 +74,6 @@ class SettingView(staticFileResolver: StaticFileResolver) : View(staticFileResol
attributes["for"] = "checked"
+" Do you want to proceed ?"
}
}
button(
type = submit,
+4 -3
View File
@@ -8,20 +8,21 @@ import be.simplenotes.app.views.components.submitButton
import be.simplenotes.domain.security.JwtPayload
import io.konform.validation.ValidationError
import kotlinx.html.*
import kotlinx.html.ButtonType.submit
class UserView(staticFileResolver: StaticFileResolver) : View(staticFileResolver) {
fun register(
jwtPayload: JwtPayload?,
error: String? = null,
validationErrors: List<ValidationError> = emptyList(),
) = accountForm("Register",
) = accountForm(
"Register",
"Registration page",
jwtPayload,
error,
validationErrors,
"Create an account",
"Register") {
"Register"
) {
+"Already have an account? "
a(href = "/login", classes = "no-underline text-blue-500 font-bold") { +"Sign In" }
}
+1 -1
View File
@@ -6,7 +6,7 @@ import be.simplenotes.domain.security.JwtPayload
import kotlinx.html.*
import kotlinx.html.stream.appendHTML
abstract class View(private val staticFileResolver: StaticFileResolver) {
abstract class View(staticFileResolver: StaticFileResolver) {
private val styles = staticFileResolver.resolve("styles.css")!!