mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-07-19 04:14:40 +00:00
Merge pull request #6018 from dcecile/develop
Issue #2606 - Verify/fix indices during sortTask
This commit is contained in:
commit
20415da586
2 changed files with 13 additions and 3 deletions
|
|
@ -186,6 +186,13 @@ preenHistory = (history) ->
|
|||
|
||||
newHistory
|
||||
|
||||
|
||||
###
|
||||
Preen 3-day past-completed To-Dos from Angular & mobile app
|
||||
###
|
||||
api.preenTodos = (tasks) ->
|
||||
_.where(tasks, (t) -> !t.completed || (t.challenge && t.challenge.id) || moment(t.dateCompleted).isAfter(moment().subtract({days:3})))
|
||||
|
||||
###
|
||||
Update the in-browser store with new gear. FIXME this was in user.fns, but it was causing strange issues there
|
||||
###
|
||||
|
|
@ -613,6 +620,11 @@ api.wrap = (user, main=true) ->
|
|||
return cb?({code:404, message: i18n.t('messageTaskNotFound', req.language)}) unless task
|
||||
return cb?('?to=__&from=__ are required') unless to? and from?
|
||||
tasks = user["#{task.type}s"]
|
||||
if task.type is 'todo' and tasks[from] isnt task # client indices don't match because of preened tasks
|
||||
preenedTasks = api.preenTodos(tasks);
|
||||
to = tasks.indexOf(preenedTasks[to]) unless to == -1 # Push To Bottom doesn't require readjustment
|
||||
from = tasks.indexOf(preenedTasks[from])
|
||||
return cb?({code:404, message: i18n.t('messageTaskNotFound', req.language)}) unless tasks[from] is task
|
||||
movedTask = tasks.splice(from, 1)[0]
|
||||
if to == -1 # we've used the Push To Bottom feature
|
||||
tasks.push(movedTask)
|
||||
|
|
|
|||
|
|
@ -635,9 +635,7 @@ api.batchUpdate = function(req, res, next) {
|
|||
// Fetch full user object
|
||||
} else if (response.wasModified){
|
||||
// Preen 3-day past-completed To-Dos from Angular & mobile app
|
||||
response.todos = _.where(response.todos, function(t) {
|
||||
return !t.completed || (t.challenge && t.challenge.id) || moment(t.dateCompleted).isAfter(moment().subtract({days:3}));
|
||||
});
|
||||
response.todos = shared.preenTodos(response.todos);
|
||||
res.json(200, response);
|
||||
|
||||
// return only the version number
|
||||
|
|
|
|||
Loading…
Reference in a new issue