Fix filters not working
This commit is contained in:
parent
ff0f0f6989
commit
e739b83f45
|
@ -127,18 +127,37 @@ func (b *Bucket) ReadAll(s *xorm.Session, auth web.Auth, search string, page int
|
|||
|
||||
tasks := []*Task{}
|
||||
|
||||
for id, bucket := range bucketMap {
|
||||
ts, _, _, err := getRawTasksForLists(s, []*List{{ID: bucket.ListID}}, auth, &taskOptions{
|
||||
page: 1,
|
||||
perPage: perPage,
|
||||
filters: []*taskFilter{
|
||||
{
|
||||
field: "bucket_id",
|
||||
value: id,
|
||||
comparator: taskFilterComparatorEquals,
|
||||
},
|
||||
},
|
||||
opts, err := getTaskFilterOptsFromCollection(&b.TaskCollection)
|
||||
if err != nil {
|
||||
return nil, 0, 0, err
|
||||
}
|
||||
|
||||
opts.page = page
|
||||
opts.perPage = perPage
|
||||
opts.search = search
|
||||
|
||||
var bucketFilterIndex int
|
||||
for i, filter := range opts.filters {
|
||||
if filter.field == "bucket_id" {
|
||||
bucketFilterIndex = i
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if bucketFilterIndex == 0 {
|
||||
opts.filters = append(opts.filters, &taskFilter{
|
||||
field: "bucket_id",
|
||||
value: 0,
|
||||
comparator: taskFilterComparatorEquals,
|
||||
})
|
||||
bucketFilterIndex = len(opts.filters) - 1
|
||||
}
|
||||
|
||||
for id, bucket := range bucketMap {
|
||||
|
||||
opts.filters[bucketFilterIndex].value = id
|
||||
|
||||
ts, _, _, err := getRawTasksForLists(s, []*List{{ID: bucket.ListID}}, auth, opts)
|
||||
if err != nil {
|
||||
return nil, 0, 0, err
|
||||
}
|
||||
|
|
|
@ -79,6 +79,44 @@ func validateTaskField(fieldName string) error {
|
|||
|
||||
}
|
||||
|
||||
func getTaskFilterOptsFromCollection(tf *TaskCollection) (opts *taskOptions, err error) {
|
||||
if len(tf.SortByArr) > 0 {
|
||||
tf.SortBy = append(tf.SortBy, tf.SortByArr...)
|
||||
}
|
||||
|
||||
if len(tf.OrderByArr) > 0 {
|
||||
tf.OrderBy = append(tf.OrderBy, tf.OrderByArr...)
|
||||
}
|
||||
|
||||
var sort = make([]*sortParam, 0, len(tf.SortBy))
|
||||
for i, s := range tf.SortBy {
|
||||
param := &sortParam{
|
||||
sortBy: s,
|
||||
orderBy: orderAscending,
|
||||
}
|
||||
// This checks if tf.OrderBy has an entry with the same index as the current entry from tf.SortBy
|
||||
// Taken from https://stackoverflow.com/a/27252199/10924593
|
||||
if len(tf.OrderBy) > i {
|
||||
param.orderBy = getSortOrderFromString(tf.OrderBy[i])
|
||||
}
|
||||
|
||||
// Param validation
|
||||
if err := param.validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
sort = append(sort, param)
|
||||
}
|
||||
|
||||
opts = &taskOptions{
|
||||
sortby: sort,
|
||||
filterConcat: taskFilterConcatinator(tf.FilterConcat),
|
||||
filterIncludeNulls: tf.FilterIncludeNulls,
|
||||
}
|
||||
|
||||
opts.filters, err = getTaskFiltersByCollections(tf)
|
||||
return opts, err
|
||||
}
|
||||
|
||||
// ReadAll gets all tasks for a collection
|
||||
// @Summary Get tasks in a list
|
||||
// @Description Returns all tasks for the current list.
|
||||
|
@ -113,47 +151,15 @@ func (tf *TaskCollection) ReadAll(s *xorm.Session, a web.Auth, search string, pa
|
|||
return sf.getTaskCollection().ReadAll(s, a, search, page, perPage)
|
||||
}
|
||||
|
||||
if len(tf.SortByArr) > 0 {
|
||||
tf.SortBy = append(tf.SortBy, tf.SortByArr...)
|
||||
}
|
||||
|
||||
if len(tf.OrderByArr) > 0 {
|
||||
tf.OrderBy = append(tf.OrderBy, tf.OrderByArr...)
|
||||
}
|
||||
|
||||
var sort = make([]*sortParam, 0, len(tf.SortBy))
|
||||
for i, s := range tf.SortBy {
|
||||
param := &sortParam{
|
||||
sortBy: s,
|
||||
orderBy: orderAscending,
|
||||
}
|
||||
// This checks if tf.OrderBy has an entry with the same index as the current entry from tf.SortBy
|
||||
// Taken from https://stackoverflow.com/a/27252199/10924593
|
||||
if len(tf.OrderBy) > i {
|
||||
param.orderBy = getSortOrderFromString(tf.OrderBy[i])
|
||||
}
|
||||
|
||||
// Param validation
|
||||
if err := param.validate(); err != nil {
|
||||
return nil, 0, 0, err
|
||||
}
|
||||
sort = append(sort, param)
|
||||
}
|
||||
|
||||
taskopts := &taskOptions{
|
||||
search: search,
|
||||
page: page,
|
||||
perPage: perPage,
|
||||
sortby: sort,
|
||||
filterConcat: taskFilterConcatinator(tf.FilterConcat),
|
||||
filterIncludeNulls: tf.FilterIncludeNulls,
|
||||
}
|
||||
|
||||
taskopts.filters, err = getTaskFiltersByCollections(tf)
|
||||
taskopts, err := getTaskFilterOptsFromCollection(tf)
|
||||
if err != nil {
|
||||
return
|
||||
return nil, 0, 0, err
|
||||
}
|
||||
|
||||
taskopts.search = search
|
||||
taskopts.page = page
|
||||
taskopts.perPage = perPage
|
||||
|
||||
shareAuth, is := a.(*LinkSharing)
|
||||
if is {
|
||||
list, err := GetListSimpleByID(s, shareAuth.ListID)
|
||||
|
|
|
@ -306,7 +306,7 @@ func getRawTasksForLists(s *xorm.Session, lists []*List, a web.Auth, opts *taskO
|
|||
continue
|
||||
}
|
||||
|
||||
if f.field == "assignees" {
|
||||
if f.field == "assignees" || f.field == "user_id" {
|
||||
f.field = "user_id"
|
||||
filter, err := getFilterCond(f, opts.filterIncludeNulls)
|
||||
if err != nil {
|
||||
|
@ -316,7 +316,7 @@ func getRawTasksForLists(s *xorm.Session, lists []*List, a web.Auth, opts *taskO
|
|||
continue
|
||||
}
|
||||
|
||||
if f.field == "labels" {
|
||||
if f.field == "labels" || f.field == "label_id" {
|
||||
f.field = "label_id"
|
||||
filter, err := getFilterCond(f, opts.filterIncludeNulls)
|
||||
if err != nil {
|
||||
|
@ -326,7 +326,7 @@ func getRawTasksForLists(s *xorm.Session, lists []*List, a web.Auth, opts *taskO
|
|||
continue
|
||||
}
|
||||
|
||||
if f.field == "namespace" {
|
||||
if f.field == "namespace" || f.field == "namespace_id" {
|
||||
f.field = "namespace_id"
|
||||
filter, err := getFilterCond(f, opts.filterIncludeNulls)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue