mirror of
https://github.com/Suwayomi/Tachidesk.git
synced 2025-12-23 13:02:34 +01:00
Exclude "default" category from reordering (#586)
* Exclude "default" category from reordering Due to the "default" category having been added to the database, the index based approach to reorder the categories didn't work anymore. In case one tried to move a category to or from pos 1, the default category was selected due to being at index 0 * Normalize categories after reordering Makes sure that the ordering is correct. E.g. "default" category should always be at position 0
This commit is contained in:
@@ -65,13 +65,14 @@ object Category {
|
||||
fun reorderCategory(from: Int, to: Int) {
|
||||
if (from == 0 || to == 0) return
|
||||
transaction {
|
||||
val categories = CategoryTable.selectAll().orderBy(CategoryTable.order to SortOrder.ASC).toMutableList()
|
||||
val categories = CategoryTable.select { CategoryTable.id neq DEFAULT_CATEGORY_ID }.orderBy(CategoryTable.order to SortOrder.ASC).toMutableList()
|
||||
categories.add(to - 1, categories.removeAt(from - 1))
|
||||
categories.forEachIndexed { index, cat ->
|
||||
CategoryTable.update({ CategoryTable.id eq cat[CategoryTable.id].value }) {
|
||||
it[CategoryTable.order] = index + 1
|
||||
}
|
||||
}
|
||||
normalizeCategories()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user