Items position is nullable.
This commit is contained in:
parent
30dd0fcea9
commit
4ba070d513
@ -101,17 +101,19 @@ class DB {
|
||||
|
||||
}
|
||||
|
||||
private fun reorderElements(listId: Int, position: Int, itemId: Int? = null) {
|
||||
private fun reorderElements(listId: Int, position: Int?, itemId: Int? = null) {
|
||||
transaction {
|
||||
var i = 0
|
||||
ItemV2.find { ItemsV2.list eq listId and (ItemsV2.id neq itemId and (ItemsV2.checked eq false)) }
|
||||
.sortedBy { it.position }
|
||||
.forEach {
|
||||
if (i == position) {
|
||||
if (position != null && i == position) {
|
||||
i++
|
||||
}
|
||||
if (it.position != null) {
|
||||
it.position = i
|
||||
i++
|
||||
}
|
||||
it.position = i
|
||||
i++
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -156,6 +158,7 @@ class DB {
|
||||
(ItemV2.find { ItemsV2.list eq listId and (ItemsV2.checked eq false) }.count() + 1).toInt()
|
||||
}
|
||||
item.position = p
|
||||
reorderElements(listId, p, itemId)
|
||||
item.checked = body.checked
|
||||
}
|
||||
if (body.content != null) {
|
||||
|
Loading…
Reference in New Issue
Block a user