113 lines
4.2 KiB
Kotlin
113 lines
4.2 KiB
Kotlin
package net.keinekekse.app.books.ui
|
|
|
|
import kotlinx.coroutines.runBlocking
|
|
import kotlinx.html.*
|
|
import net.keinekekse.app.books.db.BookRepository
|
|
import net.keinekekse.app.books.model.Book
|
|
|
|
fun HTML.booksPage(booksRepo: BookRepository) {
|
|
booksPage("Books-DB", mapOf(Pair(navBooks.first, ""))) {
|
|
// content left
|
|
div(classes = "basis-64 px-1 py-2 text-center $bgLeftColumn") {
|
|
div {
|
|
+"some content on the left "
|
|
}
|
|
|
|
}
|
|
// content right
|
|
div(classes = "flex flex-auto $bgBody") {
|
|
div(classes = "flex flex-col flex-auto") {
|
|
// div {
|
|
// +"some heading"
|
|
// }
|
|
booksTable(booksRepo)
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fun FlowContent.booksTable(booksRepo: BookRepository) {
|
|
val books: List<Book> = runBlocking {
|
|
booksRepo.allBooks()
|
|
}
|
|
|
|
div(classes = "flex-auto overflow-auto px-1 pb-1 w-0 min-w-1/1") {
|
|
table {
|
|
id = "bookstable"
|
|
thead(classes = "$cssFixedTHead ") {
|
|
tr {
|
|
th(classes = "py-3 px-2") { +"Titel" }
|
|
th(classes = "py-3 px-2") { +"Autor(en)" }
|
|
th(classes = "py-3 px-2") { +"Serie" }
|
|
th(classes = "py-3 px-2") { +"Sprache" }
|
|
th(classes = "py-3 px-2") { +"Jahr" }
|
|
th(classes = "py-3 px-2") { +"Typ" }
|
|
th(classes = "py-3 px-2") { +"Gelesen" }
|
|
th(classes = "py-3 px-2") {
|
|
a {
|
|
href = navBooksNew.second
|
|
title = navBooksNew.first
|
|
materialSymbolButton(
|
|
"auto_stories",
|
|
"font-weight: bold; font-size: 2em"
|
|
)
|
|
// library_add
|
|
}
|
|
}
|
|
}
|
|
}
|
|
tbody {
|
|
for (book in books) {
|
|
tr {
|
|
td(classes = "border-t-1 $borderTable px-2 py-1") {
|
|
+book.title
|
|
}
|
|
td(classes = "border-t-1 $borderTable px-2 py-1") {
|
|
+artistsString(book, 40)
|
|
}
|
|
td(classes = "border-t-1 $borderTable px-2 py-1") {
|
|
+(book.series?.name ?: "") // TODO add index
|
|
}
|
|
td(classes = "border-t-1 $borderTable px-2 py-1") {
|
|
+book.language.name
|
|
}
|
|
td(classes = "border-t-1 $borderTable px-2 py-1") {
|
|
+book.year.toString()
|
|
}
|
|
td(classes = "border-t-1 $borderTable px-2 py-1") {
|
|
+book.type.name
|
|
}
|
|
td(classes = "border-t-1 $borderTable px-2 py-1 text-center text-slate-400") {
|
|
title = if (book.read) "gelesen" else "ungelesen"
|
|
if (book.read) materialSymbol("check_small") //check_small || check_circle
|
|
else materialSymbol("close_small") //cancel || close || block
|
|
}
|
|
td(classes = "border-t-1 $borderTable px-2 py-1 text-nowrap") {
|
|
a {
|
|
title = if (book.read) "ungelesen" else "gelesen"
|
|
materialSymbolButton("published_with_changes")
|
|
}
|
|
a {
|
|
href = "${navBooksEdit.second}/${book.id}"
|
|
materialSymbolButton("Edit")
|
|
}
|
|
materialSymbolButton("Delete")
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
fun artistsString(book: Book, len: Int = 0): String {
|
|
val rc = book.artists.joinToString(" & ") { it.artist.toString() }
|
|
return if (rc.length > len) rc.slice(0..len) else rc
|
|
}
|