Skip to content

Commit

Permalink
Exclude "default" category from reordering (#586)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
schroda committed Jul 1, 2023
1 parent 890920a commit 1a9a0b3
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down

0 comments on commit 1a9a0b3

Please sign in to comment.