Show deleted notes count

This commit is contained in:
Hubert Van De Walle 2020-08-19 00:16:00 +02:00
parent a98d6e8e64
commit 8ccd7f6058
3 changed files with 5 additions and 2 deletions

View File

@ -48,7 +48,8 @@ class NoteController(
val currentPage = request.query("page")?.toIntOrNull()?.let(::abs) ?: 1 val currentPage = request.query("page")?.toIntOrNull()?.let(::abs) ?: 1
val tag = request.query("tag") val tag = request.query("tag")
val (pages, notes) = noteService.paginatedNotes(jwtPayload.userId, currentPage, tag = tag) val (pages, notes) = noteService.paginatedNotes(jwtPayload.userId, currentPage, tag = tag)
return Response(OK).html(view.notes(jwtPayload, notes, currentPage, pages, tag = tag)) val deletedCount = noteService.countDeleted(jwtPayload.userId)
return Response(OK).html(view.notes(jwtPayload, notes, currentPage, pages, deletedCount, tag = tag))
} }
fun note(request: Request, jwtPayload: JwtPayload): Response { fun note(request: Request, jwtPayload: JwtPayload): Response {

View File

@ -51,6 +51,7 @@ class NoteView(staticFileResolver: StaticFileResolver) : View(staticFileResolver
notes: List<PersistedNoteMetadata>, notes: List<PersistedNoteMetadata>,
currentPage: Int, currentPage: Int,
numberOfPages: Int, numberOfPages: Int,
numberOfDeletedNotes: Int,
tag: String?, tag: String?,
) = renderPage(title = "Notes", jwtPayload = jwtPayload) { ) = renderPage(title = "Notes", jwtPayload = jwtPayload) {
div("container mx-auto p-4") { div("container mx-auto p-4") {
@ -60,7 +61,7 @@ class NoteView(staticFileResolver: StaticFileResolver) : View(staticFileResolver
a( a(
href = "/notes/trash", href = "/notes/trash",
classes = "underline font-semibold" classes = "underline font-semibold"
) { +"Trash" } ) { +"Trash ($numberOfDeletedNotes)" }
a( a(
href = "/notes/new", href = "/notes/new",
classes = "ml-2 btn btn-green" classes = "ml-2 btn btn-green"

View File

@ -47,6 +47,7 @@ class NoteService(
fun trash(userId: Int, uuid: UUID) = noteRepository.delete(userId, uuid, permanent = false) fun trash(userId: Int, uuid: UUID) = noteRepository.delete(userId, uuid, permanent = false)
fun restore(userId: Int, uuid: UUID) = noteRepository.restore(userId, uuid) fun restore(userId: Int, uuid: UUID) = noteRepository.restore(userId, uuid)
fun delete(userId: Int, uuid: UUID) = noteRepository.delete(userId, uuid, permanent = true) fun delete(userId: Int, uuid: UUID) = noteRepository.delete(userId, uuid, permanent = true)
fun countDeleted(userId: Int) = noteRepository.count(userId, deleted = true)
} }