feat(views): return position when retriving tasks
This commit is contained in:
parent
786e67f692
commit
f364f3bec8
@ -158,7 +158,7 @@ func exportProjectsAndTasks(s *xorm.Session, u *user.User, wr *zip.Writer) (task
|
|||||||
tasks, _, _, err := getTasksForProjects(s, rawProjects, u, &taskSearchOptions{
|
tasks, _, _, err := getTasksForProjects(s, rawProjects, u, &taskSearchOptions{
|
||||||
page: 0,
|
page: 0,
|
||||||
perPage: -1,
|
perPage: -1,
|
||||||
})
|
}, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return taskIDs, err
|
return taskIDs, err
|
||||||
}
|
}
|
||||||
|
@ -274,7 +274,7 @@ func GetTasksInBucketsForView(s *xorm.Session, view *ProjectView, opts *taskSear
|
|||||||
taskMap[t.ID] = t
|
taskMap[t.ID] = t
|
||||||
}
|
}
|
||||||
|
|
||||||
err = addMoreInfoToTasks(s, taskMap, auth)
|
err = addMoreInfoToTasks(s, taskMap, auth, view)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -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) {
|
func duplicateTasks(s *xorm.Session, doer web.Auth, ld *ProjectDuplicate, bucketMap map[int64]int64) (err error) {
|
||||||
// Get all tasks + all task details
|
// 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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -213,7 +213,7 @@ func (tf *TaskCollection) ReadAll(s *xorm.Session, a web.Auth, search string, pa
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, 0, err
|
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.
|
// 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)
|
||||||
}
|
}
|
||||||
|
@ -134,3 +134,11 @@ func RecalculateTaskPositions(s *xorm.Session, view *ProjectView) (err error) {
|
|||||||
_, err = s.Insert(newPositions)
|
_, err = s.Insert(newPositions)
|
||||||
return
|
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
|
||||||
|
}
|
||||||
|
@ -303,7 +303,7 @@ func getRawTasksForProjects(s *xorm.Session, projects []*Project, a web.Auth, op
|
|||||||
return tasks, len(tasks), totalItems, err
|
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)
|
tasks, resultCount, totalItems, err = getRawTasksForProjects(s, projects, a, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -315,7 +315,7 @@ func getTasksForProjects(s *xorm.Session, projects []*Project, a web.Auth, opts
|
|||||||
taskMap[t.ID] = t
|
taskMap[t.ID] = t
|
||||||
}
|
}
|
||||||
|
|
||||||
err = addMoreInfoToTasks(s, taskMap, a)
|
err = addMoreInfoToTasks(s, taskMap, a, view)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, 0, err
|
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
|
taskMap[t.ID] = t
|
||||||
}
|
}
|
||||||
|
|
||||||
err = addMoreInfoToTasks(s, taskMap, a)
|
err = addMoreInfoToTasks(s, taskMap, a, nil)
|
||||||
return
|
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
|
// 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
|
// 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
|
// No need to iterate over users and stuff if the project doesn't have tasks
|
||||||
if len(taskMap) == 0 {
|
if len(taskMap) == 0 {
|
||||||
@ -591,6 +591,17 @@ func addMoreInfoToTasks(s *xorm.Session, taskMap map[int64]*Task, a web.Auth) (e
|
|||||||
return
|
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
|
// Add all objects to their tasks
|
||||||
for _, task := range taskMap {
|
for _, task := range taskMap {
|
||||||
|
|
||||||
@ -612,6 +623,11 @@ func addMoreInfoToTasks(s *xorm.Session, taskMap map[int64]*Task, a web.Auth) (e
|
|||||||
if has {
|
if has {
|
||||||
task.Reactions = r
|
task.Reactions = r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p, has := positionsMap[task.ID]
|
||||||
|
if has {
|
||||||
|
task.Position = p.Position
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get all related tasks
|
// 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 := make(map[int64]*Task, 1)
|
||||||
taskMap[t.ID] = t
|
taskMap[t.ID] = t
|
||||||
|
|
||||||
err = addMoreInfoToTasks(s, taskMap, a)
|
err = addMoreInfoToTasks(s, taskMap, a, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -291,7 +291,7 @@ func reindexTasksInTypesense(s *xorm.Session, tasks map[int64]*Task) (err error)
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = addMoreInfoToTasks(s, tasks, &user.User{ID: 1})
|
err = addMoreInfoToTasks(s, tasks, &user.User{ID: 1}, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not fetch more task info: %s", err.Error())
|
return fmt.Errorf("could not fetch more task info: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user