Fix updating the index when moving a task

This commit is contained in:
kolaente 2020-07-01 16:54:18 +02:00
parent 556ccd68c1
commit f57b7e989f
No known key found for this signature in database
GPG key ID: F40E70337AB24C9B

View file

@ -693,13 +693,41 @@ func (t *Task) Update() (err error) {
return
}
// If the task is being moved between lists, make sure to move the bucket as well
// All columns to update in a separate variable to be able to add to them
colsToUpdate := []string{
"title",
"description",
"done",
"due_date",
"repeat_after",
"priority",
"start_date",
"end_date",
"hex_color",
"done_at",
"percent_done",
"list_id",
"bucket_id",
"position",
"repeat_from_current_date",
}
// If the task is being moved between lists, make sure to move the bucket + index as well
if t.ListID != 0 && ot.ListID != t.ListID {
b, err := getDefaultBucket(t.ListID)
if err != nil {
return err
}
t.BucketID = b.ID
latestTask := &Task{}
_, err = x.Where("list_id = ?", t.ListID).OrderBy("id desc").Get(latestTask)
if err != nil {
return err
}
t.Index = latestTask.Index + 1
colsToUpdate = append(colsToUpdate, "index")
}
// Update the labels
@ -776,22 +804,7 @@ func (t *Task) Update() (err error) {
}
_, err = x.ID(t.ID).
Cols("title",
"description",
"done",
"due_date",
"repeat_after",
"priority",
"start_date",
"end_date",
"hex_color",
"done_at",
"percent_done",
"list_id",
"bucket_id",
"position",
"repeat_from_current_date",
).
Cols(colsToUpdate...).
Update(ot)
*t = ot
if err != nil {