2024-01-23 23:58:04 +00:00
|
|
|
package board
|
|
|
|
|
|
|
|
// moveAndShuffle creates a new list where the element specified at the index of the current
|
|
|
|
// position is moved to the index of the target position. Elements within the range of the
|
|
|
|
// old and new positions will then shuffle forwards or backwards in the list depending on the
|
|
|
|
// direction of the move.
|
|
|
|
// This is currently used to move specified columns forwards or backwards on the Kanban board.
|
|
|
|
// When a column changes position the other columns shuffle forward or backwards as required.
|
2024-01-24 18:31:41 +00:00
|
|
|
func moveAndShuffle(input []Status, oldIndex, newIndex int) []Status {
|
|
|
|
if newIndex == oldIndex {
|
|
|
|
return input
|
2024-01-23 23:58:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
output := make([]Status, len(input))
|
|
|
|
|
2024-01-24 18:31:41 +00:00
|
|
|
// copy the original slice and assign the target element to the
|
|
|
|
// new index.
|
|
|
|
copy(output, input)
|
|
|
|
|
|
|
|
output[newIndex] = input[oldIndex]
|
|
|
|
|
|
|
|
// shuffle the elements in range down the slice if the target element moves
|
|
|
|
// up the list.
|
|
|
|
if newIndex < oldIndex {
|
|
|
|
for index := newIndex; index <= oldIndex; index++ {
|
|
|
|
if index == oldIndex {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
output[index+1] = input[index]
|
2024-01-23 23:58:04 +00:00
|
|
|
}
|
2024-01-24 18:31:41 +00:00
|
|
|
|
|
|
|
return output
|
|
|
|
}
|
|
|
|
|
|
|
|
// shuffle the elements in range up the slice if the target element moves
|
|
|
|
// down the list.
|
|
|
|
for index := oldIndex; index <= newIndex; index++ {
|
|
|
|
if index == oldIndex {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
output[index-1] = input[index]
|
2024-01-23 23:58:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return output
|
|
|
|
}
|