mirror of
https://github.com/Suwayomi/Tachidesk.git
synced 2026-02-01 08:24:19 +01:00
add size field to Category data class (#519)
Makes it possible to display the size of a category to the user
This commit is contained in:
@@ -18,7 +18,6 @@ import org.jetbrains.exposed.sql.selectAll
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
import org.jetbrains.exposed.sql.update
|
||||
import suwayomi.tachidesk.manga.impl.CategoryManga.removeMangaFromCategory
|
||||
import suwayomi.tachidesk.manga.impl.util.lang.isNotEmpty
|
||||
import suwayomi.tachidesk.manga.model.dataclass.CategoryDataClass
|
||||
import suwayomi.tachidesk.manga.model.table.CategoryMangaTable
|
||||
import suwayomi.tachidesk.manga.model.table.CategoryMetaTable
|
||||
@@ -98,12 +97,14 @@ object Category {
|
||||
|
||||
const val DEFAULT_CATEGORY_ID = 0
|
||||
const val DEFAULT_CATEGORY_NAME = "Default"
|
||||
private fun addDefaultIfNecessary(categories: List<CategoryDataClass>): List<CategoryDataClass> =
|
||||
if (MangaTable.select { (MangaTable.inLibrary eq true) and (MangaTable.defaultCategory eq true) }.isNotEmpty()) {
|
||||
listOf(CategoryDataClass(DEFAULT_CATEGORY_ID, 0, DEFAULT_CATEGORY_NAME, true)) + categories
|
||||
private fun addDefaultIfNecessary(categories: List<CategoryDataClass>): List<CategoryDataClass> {
|
||||
val defaultCategorySize = MangaTable.select { (MangaTable.inLibrary eq true) and (MangaTable.defaultCategory eq true) }.count().toInt()
|
||||
return if (defaultCategorySize > 0) {
|
||||
listOf(CategoryDataClass(DEFAULT_CATEGORY_ID, 0, DEFAULT_CATEGORY_NAME, true, defaultCategorySize)) + categories
|
||||
} else {
|
||||
categories
|
||||
}
|
||||
}
|
||||
|
||||
fun getCategoryList(): List<CategoryDataClass> {
|
||||
return transaction {
|
||||
@@ -123,6 +124,14 @@ object Category {
|
||||
}
|
||||
}
|
||||
|
||||
fun getCategorySize(categoryId: Int): Int {
|
||||
return transaction {
|
||||
CategoryMangaTable.select {
|
||||
CategoryMangaTable.category eq categoryId
|
||||
}.count().toInt()
|
||||
}
|
||||
}
|
||||
|
||||
fun getCategoryMetaMap(categoryId: Int): Map<String, String> {
|
||||
return transaction {
|
||||
CategoryMetaTable.select { CategoryMetaTable.ref eq categoryId }
|
||||
|
||||
@@ -12,5 +12,6 @@ data class CategoryDataClass(
|
||||
val order: Int,
|
||||
val name: String,
|
||||
val default: Boolean,
|
||||
val size: Int,
|
||||
val meta: Map<String, String> = emptyMap()
|
||||
)
|
||||
|
||||
@@ -23,5 +23,6 @@ fun CategoryTable.toDataClass(categoryEntry: ResultRow) = CategoryDataClass(
|
||||
categoryEntry[order],
|
||||
categoryEntry[name],
|
||||
categoryEntry[isDefault],
|
||||
Category.getCategorySize(categoryEntry[id].value),
|
||||
Category.getCategoryMetaMap(categoryEntry[id].value)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user