From 1a9a0b3394c84387d7dde93c3ffbbb10f95dd37b Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Sat, 1 Jul 2023 19:53:10 +0200 Subject: [PATCH] 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 --- .../src/main/kotlin/suwayomi/tachidesk/manga/impl/Category.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/Category.kt b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/Category.kt index 94fb5069..f222a235 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/Category.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/Category.kt @@ -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() } }