Dan Anglin
e99c8cd877
Add backend support for repositioning statuses on the Kanban board. Part of apollo/pelican#27
26 lines
679 B
Go
26 lines
679 B
Go
package board
|
|
|
|
// shuffle takes a list of Statuses and swaps its position with the Status closer to its desired
|
|
// position until it reaches it.
|
|
//
|
|
// 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.
|
|
func shuffle(list []Status, oldIndex, newIndex int) []Status {
|
|
if newIndex == oldIndex {
|
|
return list
|
|
}
|
|
|
|
if newIndex < oldIndex {
|
|
for i := oldIndex; i > newIndex; i-- {
|
|
list[i], list[i-1] = list[i-1], list[i]
|
|
}
|
|
|
|
return list
|
|
}
|
|
|
|
for i := oldIndex; i < newIndex; i++ {
|
|
list[i], list[i+1] = list[i+1], list[i]
|
|
}
|
|
|
|
return list
|
|
}
|