From 2f6b39533444eca4666d5cf17c988fd26c592e81 Mon Sep 17 00:00:00 2001 From: kolaente Date: Sat, 6 Apr 2024 14:35:05 +0200 Subject: [PATCH] feat(kanban): set task position to 0 (top) when it is moved into the done bucket automatically after marking it done --- pkg/models/tasks.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkg/models/tasks.go b/pkg/models/tasks.go index 463f57e01..f6e69fe5a 100644 --- a/pkg/models/tasks.go +++ b/pkg/models/tasks.go @@ -672,9 +672,21 @@ func setTaskBucket(s *xorm.Session, task *Task, originalTask *Task, view *Projec return } + // If the task was marked as done and the view has a done bucket, move the task to the done bucket if task.Done && originalTask != nil && (!originalTask.Done || task.ProjectID != originalTask.ProjectID) { targetBucket.BucketID = view.DoneBucketID + // …and also reset the position so that it shows up at the top + // Note: this might result in an "off-looking" position when there is already a task with position 0. + // This is done by design, because recalculating all positions is really costly and will happen + // later anyway. + _, err = s. + Where("task_id = ? AND project_view_id = ?", task.ID, view.ID). + Cols("position"). + Update(&TaskPosition{Position: 0}) + if err != nil { + return + } } if targetBucket.BucketID == 0 && oldTaskBucket.BucketID != 0 {