mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-15 21:57:22 +01:00
Group plans reorder tasks (#8358)
* Added move route for group tasks * Added group task reorder to front end * Added syncing with group task order * Fixed linting issues * Added missing exec and abstracted move code * Added unit test for moveTask
This commit is contained in:
committed by
Matteo Pagliazzi
parent
2690caed35
commit
1590d955cd
@@ -188,3 +188,32 @@ export function syncableAttrs (task) {
|
||||
if (t.type !== 'reward') omitAttrs.push('value');
|
||||
return _.omit(t, omitAttrs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves a task to a specified position.
|
||||
*
|
||||
* @param order The list of ordered tasks
|
||||
* @param taskId The Task._id of the task to move
|
||||
* @param to A integer specifiying the index to move the task to
|
||||
*
|
||||
* @return Empty
|
||||
*/
|
||||
export function moveTask (order, taskId, to) {
|
||||
let currentIndex = order.indexOf(taskId);
|
||||
|
||||
// If for some reason the task isn't ordered (should never happen), push it in the new position
|
||||
// if the task is moved to a non existing position
|
||||
// or if the task is moved to position -1 (push to bottom)
|
||||
// -> push task at end of list
|
||||
if (!order[to] && to !== -1) {
|
||||
order.push(taskId);
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentIndex !== -1) order.splice(currentIndex, 1);
|
||||
if (to === -1) {
|
||||
order.push(taskId);
|
||||
} else {
|
||||
order.splice(to, 0, taskId);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user