More buttons

This commit is contained in:
Hubert Van De Walle 2020-08-22 03:23:24 +02:00
parent 7d833e48e1
commit 2ac02688ab
2 changed files with 9 additions and 2 deletions

View File

@ -50,10 +50,16 @@ class SettingsController(
}
fun export(request: Request, jwtPayload: JwtPayload): Response {
val isDownload = request.form("download") != null
val json = userService.export(jwtPayload.userId)
return Response(Status.OK).body(json).header("Content-Type", "application/json")
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\"")
else res
}
private fun sanitizeFilename(inputName: String): String = inputName.replace("[^a-zA-Z0-9-_.]".toRegex(), "_")
private fun Request.deleteForm(jwtPayload: JwtPayload) =
DeleteForm(jwtPayload.username, form("password"), form("checked") != null)
}

View File

@ -32,7 +32,8 @@ class SettingView(staticFileResolver: StaticFileResolver) : View(staticFileResol
}
form(method = FormMethod.post, action = "/export") {
button(classes = "btn btn-teal block", type = submit) { +"Export my data" }
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" }
}
}