fix(view): correctly resolve bucket filter when paginating
(cherry picked from commit 45ff5907e69b24f00926841790d0f4f3d11e530a)
This commit is contained in:
parent
6b850c56f7
commit
1049b27d37
@ -17,6 +17,8 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"regexp"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/user"
|
"code.vikunja.io/api/pkg/user"
|
||||||
@ -174,6 +176,28 @@ func getRelevantProjectsFromCollection(s *xorm.Session, a web.Auth, tf *TaskColl
|
|||||||
return []*Project{{ID: tf.ProjectID}}, nil
|
return []*Project{{ID: tf.ProjectID}}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getFilterValueForBucketFilter(filter string, view *ProjectView) (newFilter string, err error) {
|
||||||
|
re := regexp.MustCompile(`bucket_id\s*=\s*(\d+)`)
|
||||||
|
|
||||||
|
match := re.FindStringSubmatch(filter)
|
||||||
|
if len(match) < 2 {
|
||||||
|
return filter, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
bucketID, err := strconv.Atoi(match[1])
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
for id, bucket := range view.BucketConfiguration {
|
||||||
|
if id == bucketID {
|
||||||
|
return re.ReplaceAllString(filter, `(`+bucket.Filter+`)`), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return filter, nil
|
||||||
|
}
|
||||||
|
|
||||||
// ReadAll gets all tasks for a collection
|
// ReadAll gets all tasks for a collection
|
||||||
// @Summary Get tasks in a project
|
// @Summary Get tasks in a project
|
||||||
// @Description Returns all tasks for the current project.
|
// @Description Returns all tasks for the current project.
|
||||||
@ -251,6 +275,13 @@ func (tf *TaskCollection) ReadAll(s *xorm.Session, a web.Auth, search string, pa
|
|||||||
tf.Filter = view.Filter
|
tf.Filter = view.Filter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if view.BucketConfigurationMode == BucketConfigurationModeFilter && strings.Contains(tf.Filter, "bucket_id") {
|
||||||
|
tf.Filter, err = getFilterValueForBucketFilter(tf.Filter, view)
|
||||||
|
if err != nil {
|
||||||
|
return nil, 0, 0, err
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
opts, err := getTaskFilterOptsFromCollection(tf, view)
|
opts, err := getTaskFilterOptsFromCollection(tf, view)
|
||||||
|
@ -325,7 +325,6 @@ func getRawTasksForProjects(s *xorm.Session, projects []*Project, a web.Auth, op
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getTasksForProjects(s *xorm.Session, projects []*Project, a web.Auth, opts *taskSearchOptions, view *ProjectView) (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 {
|
||||||
return nil, 0, 0, err
|
return nil, 0, 0, err
|
||||||
|
Loading…
x
Reference in New Issue
Block a user