1
0

fix(task): specify task index when creating multiple tasks at once

This change allows to specify the task index when creating a task, which will then be checked to avoid duplicates and used. This allows us to calculate the indexes for all tasks beforehand when creating them at once using quick add magic.
The method is not bulletproof, but already fixes a problem where multiple tasks would have the same index when created that way.

Resolves https://community.vikunja.io/t/add-multiple-tasks-at-once/333/16

(cherry picked from commit 55dd7d298187dcc8393ae67340117d66d45dc4ef)
This commit is contained in:
kolaente
2024-09-11 17:58:42 +02:00
parent ac87035742
commit 5bfd99dd77
4 changed files with 66 additions and 9 deletions

View File

@ -738,10 +738,25 @@ func createTask(s *xorm.Session, t *Task, a web.Auth, updateAssignees bool, setB
t.UID = uuid.NewString()
}
// Get the index for this task
t.Index, err = getNextTaskIndex(s, t.ProjectID)
if err != nil {
return err
// Check if an index was provided, otherwise calculate a new one
if t.Index == 0 {
t.Index, err = getNextTaskIndex(s, t.ProjectID)
if err != nil {
return err
}
} else {
// Check if the provided index is already taken
exists, err := s.Where("project_id = ? AND `index` = ?", t.ProjectID, t.Index).Exist(&Task{})
if err != nil {
return err
}
if exists {
// If the index is taken, calculate a new one
t.Index, err = getNextTaskIndex(s, t.ProjectID)
if err != nil {
return err
}
}
}
t.HexColor = utils.NormalizeHex(t.HexColor)