diff --git a/pkg/models/export.go b/pkg/models/export.go index 05fe5a178..99a1d88c2 100644 --- a/pkg/models/export.go +++ b/pkg/models/export.go @@ -158,7 +158,7 @@ func exportProjectsAndTasks(s *xorm.Session, u *user.User, wr *zip.Writer) (task tasks, _, _, err := getTasksForProjects(s, rawProjects, u, &taskSearchOptions{ page: 0, perPage: -1, - }) + }, nil) if err != nil { return taskIDs, err } diff --git a/pkg/models/kanban.go b/pkg/models/kanban.go index dc9d38a13..371cc5b09 100644 --- a/pkg/models/kanban.go +++ b/pkg/models/kanban.go @@ -274,7 +274,7 @@ func GetTasksInBucketsForView(s *xorm.Session, view *ProjectView, opts *taskSear taskMap[t.ID] = t } - err = addMoreInfoToTasks(s, taskMap, auth) + err = addMoreInfoToTasks(s, taskMap, auth, view) if err != nil { return nil, err } diff --git a/pkg/models/project_duplicate.go b/pkg/models/project_duplicate.go index ee6882b63..03062f9f8 100644 --- a/pkg/models/project_duplicate.go +++ b/pkg/models/project_duplicate.go @@ -223,7 +223,7 @@ func duplicateProjectBackground(s *xorm.Session, pd *ProjectDuplicate, doer web. func duplicateTasks(s *xorm.Session, doer web.Auth, ld *ProjectDuplicate, bucketMap map[int64]int64) (err error) { // Get all tasks + all task details - tasks, _, _, err := getTasksForProjects(s, []*Project{{ID: ld.ProjectID}}, doer, &taskSearchOptions{}) + tasks, _, _, err := getTasksForProjects(s, []*Project{{ID: ld.ProjectID}}, doer, &taskSearchOptions{}, nil) if err != nil { return err } diff --git a/pkg/models/task_collection.go b/pkg/models/task_collection.go index f71b203e5..3573c5dc4 100644 --- a/pkg/models/task_collection.go +++ b/pkg/models/task_collection.go @@ -213,7 +213,7 @@ func (tf *TaskCollection) ReadAll(s *xorm.Session, a web.Auth, search string, pa if err != nil { return nil, 0, 0, err } - return getTasksForProjects(s, []*Project{project}, a, opts) + return getTasksForProjects(s, []*Project{project}, a, opts, view) } // If the project ID is not set, we get all tasks for the user. @@ -253,5 +253,5 @@ func (tf *TaskCollection) ReadAll(s *xorm.Session, a web.Auth, search string, pa } } - return getTasksForProjects(s, projects, a, opts) + return getTasksForProjects(s, projects, a, opts, view) } diff --git a/pkg/models/task_position.go b/pkg/models/task_position.go index 1994e0f3a..2c0a3a8de 100644 --- a/pkg/models/task_position.go +++ b/pkg/models/task_position.go @@ -134,3 +134,11 @@ func RecalculateTaskPositions(s *xorm.Session, view *ProjectView) (err error) { _, err = s.Insert(newPositions) return } + +func getPositionsForView(s *xorm.Session, view *ProjectView) (positions []*TaskPosition, err error) { + positions = []*TaskPosition{} + err = s. + Where("project_view_id = ?", view.ID). + Find(&positions) + return +} diff --git a/pkg/models/tasks.go b/pkg/models/tasks.go index 7dbd88f6a..b9fca067f 100644 --- a/pkg/models/tasks.go +++ b/pkg/models/tasks.go @@ -303,7 +303,7 @@ func getRawTasksForProjects(s *xorm.Session, projects []*Project, a web.Auth, op return tasks, len(tasks), totalItems, err } -func getTasksForProjects(s *xorm.Session, projects []*Project, a web.Auth, opts *taskSearchOptions) (tasks []*Task, resultCount int, totalItems int64, err error) { +func getTasksForProjects(s *xorm.Session, projects []*Project, a web.Auth, opts *taskSearchOptions, view *ProjectView) (tasks []*Task, resultCount int, totalItems int64, err error) { tasks, resultCount, totalItems, err = getRawTasksForProjects(s, projects, a, opts) if err != nil { @@ -315,7 +315,7 @@ func getTasksForProjects(s *xorm.Session, projects []*Project, a web.Auth, opts taskMap[t.ID] = t } - err = addMoreInfoToTasks(s, taskMap, a) + err = addMoreInfoToTasks(s, taskMap, a, view) if err != nil { return nil, 0, 0, err } @@ -392,7 +392,7 @@ func GetTasksByUIDs(s *xorm.Session, uids []string, a web.Auth) (tasks []*Task, taskMap[t.ID] = t } - err = addMoreInfoToTasks(s, taskMap, a) + err = addMoreInfoToTasks(s, taskMap, a, nil) return } @@ -533,7 +533,7 @@ func addRelatedTasksToTasks(s *xorm.Session, taskIDs []int64, taskMap map[int64] // This function takes a map with pointers and returns a slice with pointers to tasks // It adds more stuff like assignees/labels/etc to a bunch of tasks -func addMoreInfoToTasks(s *xorm.Session, taskMap map[int64]*Task, a web.Auth) (err error) { +func addMoreInfoToTasks(s *xorm.Session, taskMap map[int64]*Task, a web.Auth, view *ProjectView) (err error) { // No need to iterate over users and stuff if the project doesn't have tasks if len(taskMap) == 0 { @@ -591,6 +591,17 @@ func addMoreInfoToTasks(s *xorm.Session, taskMap map[int64]*Task, a web.Auth) (e return } + var positionsMap = make(map[int64]*TaskPosition) + if view != nil { + positions, err := getPositionsForView(s, view) + if err != nil { + return err + } + for _, position := range positions { + positionsMap[position.TaskID] = position + } + } + // Add all objects to their tasks for _, task := range taskMap { @@ -612,6 +623,11 @@ func addMoreInfoToTasks(s *xorm.Session, taskMap map[int64]*Task, a web.Auth) (e if has { task.Reactions = r } + + p, has := positionsMap[task.ID] + if has { + task.Position = p.Position + } } // Get all related tasks @@ -1487,7 +1503,7 @@ func (t *Task) ReadOne(s *xorm.Session, a web.Auth) (err error) { taskMap := make(map[int64]*Task, 1) taskMap[t.ID] = t - err = addMoreInfoToTasks(s, taskMap, a) + err = addMoreInfoToTasks(s, taskMap, a, nil) if err != nil { return } diff --git a/pkg/models/typesense.go b/pkg/models/typesense.go index 6f9097cd5..b876ff9cc 100644 --- a/pkg/models/typesense.go +++ b/pkg/models/typesense.go @@ -291,7 +291,7 @@ func reindexTasksInTypesense(s *xorm.Session, tasks map[int64]*Task) (err error) return } - err = addMoreInfoToTasks(s, tasks, &user.User{ID: 1}) + err = addMoreInfoToTasks(s, tasks, &user.User{ID: 1}, nil) if err != nil { return fmt.Errorf("could not fetch more task info: %s", err.Error()) }