Find notes by tags in notes list

This commit is contained in:
2020-08-17 17:09:48 +02:00
parent 8021814c31
commit 5295e32d86
5 changed files with 28 additions and 13 deletions
@@ -46,8 +46,9 @@ class NoteController(
fun list(request: Request, jwtPayload: JwtPayload): Response {
val currentPage = request.query("page")?.toIntOrNull()?.let(::abs) ?: 1
val (pages, notes) = noteService.paginatedNotes(jwtPayload.userId, currentPage)
return Response(OK).html(view.notes(jwtPayload, notes, currentPage, pages))
val tag = request.query("tag")
val (pages, notes) = noteService.paginatedNotes(jwtPayload.userId, currentPage, tag = tag)
return Response(OK).html(view.notes(jwtPayload, notes, currentPage, pages, tag = tag))
}
fun note(request: Request, jwtPayload: JwtPayload): Response {
+16 -6
View File
@@ -48,7 +48,13 @@ class NoteView(staticFileResolver: StaticFileResolver) : View(staticFileResolver
}
}
fun notes(jwtPayload: JwtPayload, notes: List<PersistedNoteMetadata>, currentPage: Int, numberOfPages: Int) =
fun notes(
jwtPayload: JwtPayload,
notes: List<PersistedNoteMetadata>,
currentPage: Int,
numberOfPages: Int,
tag: String?
) =
renderPage(title = "Notes", jwtPayload = jwtPayload) {
div("container mx-auto p-4") {
div("flex justify-between mb-4") {
@@ -66,25 +72,29 @@ class NoteView(staticFileResolver: StaticFileResolver) : View(staticFileResolver
a(classes = "text-blue-200 text-xl hover:underline", href = "/notes/$uuid") {
+title
}
span {
span("space-x-2") {
tags.forEach {
span("tag ml-2") { +"#$it" }
a(href = "?tag=$it", classes = "tag") {
span { +"#$it" }
}
}
}
}
}
}
if (numberOfPages > 1)
pagination(currentPage, numberOfPages)
pagination(currentPage, numberOfPages, tag)
} else
span { +"No notes yet" } // FIXME if too far in pagination, it it displayed
}
}
private fun DIV.pagination(currentPage: Int, numberOfPages: Int) {
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}"
links += (1..numberOfPages).map { "$it" to "?page=$it" }
links += (1..numberOfPages).map { page ->
"$page" to (tag?.let { "?page=$page&tag=$it" } ?: "?page=$page")
}
// if (currentPage < numberOfPages) links += "Next" to "?page=${currentPage + 1}"
nav("pages") {