Import feature

This commit is contained in:
2023-05-09 22:41:03 +02:00
parent 724fa0483e
commit 195c7c10ac
11 changed files with 128 additions and 24 deletions
+40 -16
View File
@@ -6,10 +6,13 @@ import be.simplenotes.views.components.alert
import be.simplenotes.views.components.input
import be.simplenotes.views.extensions.summary
import io.konform.validation.ValidationError
import kotlinx.html.*
import kotlinx.html.ButtonType.submit
import jakarta.inject.Named
import jakarta.inject.Singleton
import kotlinx.html.*
import kotlinx.html.ButtonType.submit
import kotlinx.html.FormEncType.multipartFormData
import kotlinx.html.FormMethod.post
import kotlinx.html.InputType.file
@Singleton
class SettingView(@Named("styles") styles: String) : View(styles) {
@@ -28,34 +31,55 @@ class SettingView(@Named("styles") styles: String) : View(styles) {
}
section("m-4 p-2 bg-gray-800 rounded flex flex-wrap justify-around items-end") {
form(classes = "m-2", method = FormMethod.post, action = "/export") {
form(classes = "m-2 flex-1", method = post, action = "/export") {
button(
name = "display",
classes = "inline btn btn-teal block",
classes = "btn btn-teal block",
type = submit,
) { +"Display my data" }
}
form(classes = "m-2", method = FormMethod.post, action = "/export") {
form(classes = "m-2 flex-1", method = post, action = "/export") {
div {
listOf("json", "zip").forEach { format ->
radioInput(name = "format") {
id = format
attributes["value"] = format
if (format == "json") attributes["checked"] = ""
else attributes["class"] = "ml-4"
}
label(classes = "ml-2") {
attributes["for"] = format
+format
div("px-2") {
radioInput(
name = "format",
classes =
"checked:bg-blue-500 bg-gray-200 appearance-none rounded-full border-2 h-5 w-5",
) {
id = format
attributes["value"] = format
if (format == "json") attributes["checked"] = ""
}
label(classes = "ml-2") {
attributes["for"] = format
+format
}
}
}
}
button(name = "download", classes = "inline btn btn-green block mt-2", type = submit) {
button(name = "download", classes = "btn btn-green block mt-2", type = submit) {
+"Download my data"
}
}
form(classes = "m-2 flex-1", method = post, encType = multipartFormData, action = "/import") {
input(
file,
classes = "file:hidden mb-4",
name = "file",
) {
attributes["accept"] = ".json,application/json"
attributes["required"] = ""
}
button(
name = "import",
classes = "btn btn-teal block",
type = submit,
) { +"Import" }
}
}
section(classes = "m-4 p-4 bg-gray-800 rounded") {
@@ -77,7 +101,7 @@ class SettingView(@Named("styles") styles: String) : View(styles) {
}
}
form(classes = "mt-4", method = FormMethod.post) {
form(classes = "mt-4", method = post) {
input(
id = "password",
placeholder = "Password",