Add task filter for labels
This commit is contained in:
parent
18325e964d
commit
6ce9527e3a
|
@ -62,6 +62,15 @@ func TestTaskCollection_ReadAll(t *testing.T) {
|
||||||
|
|
||||||
loc := config.GetTimeZone()
|
loc := config.GetTimeZone()
|
||||||
|
|
||||||
|
label4 := &Label{
|
||||||
|
ID: 4,
|
||||||
|
Title: "Label #4 - visible via other task",
|
||||||
|
CreatedByID: 2,
|
||||||
|
CreatedBy: user2,
|
||||||
|
Created: testCreatedTime,
|
||||||
|
Updated: testUpdatedTime,
|
||||||
|
}
|
||||||
|
|
||||||
// We use individual variables for the tasks here to be able to rearrange or remove ones more easily
|
// We use individual variables for the tasks here to be able to rearrange or remove ones more easily
|
||||||
task1 := &Task{
|
task1 := &Task{
|
||||||
ID: 1,
|
ID: 1,
|
||||||
|
@ -75,14 +84,7 @@ func TestTaskCollection_ReadAll(t *testing.T) {
|
||||||
BucketID: 1,
|
BucketID: 1,
|
||||||
IsFavorite: true,
|
IsFavorite: true,
|
||||||
Labels: []*Label{
|
Labels: []*Label{
|
||||||
{
|
label4,
|
||||||
ID: 4,
|
|
||||||
Title: "Label #4 - visible via other task",
|
|
||||||
CreatedByID: 2,
|
|
||||||
CreatedBy: user2,
|
|
||||||
Created: testCreatedTime,
|
|
||||||
Updated: testUpdatedTime,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
RelatedTasks: map[RelationKind][]*Task{
|
RelatedTasks: map[RelationKind][]*Task{
|
||||||
RelationKindSubtask: {
|
RelationKindSubtask: {
|
||||||
|
@ -137,14 +139,7 @@ func TestTaskCollection_ReadAll(t *testing.T) {
|
||||||
ListID: 1,
|
ListID: 1,
|
||||||
BucketID: 1,
|
BucketID: 1,
|
||||||
Labels: []*Label{
|
Labels: []*Label{
|
||||||
{
|
label4,
|
||||||
ID: 4,
|
|
||||||
Title: "Label #4 - visible via other task",
|
|
||||||
CreatedByID: 2,
|
|
||||||
CreatedBy: user2,
|
|
||||||
Created: testCreatedTime,
|
|
||||||
Updated: testUpdatedTime,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
RelatedTasks: map[RelationKind][]*Task{},
|
RelatedTasks: map[RelationKind][]*Task{},
|
||||||
Created: time.Unix(1543626724, 0).In(loc),
|
Created: time.Unix(1543626724, 0).In(loc),
|
||||||
|
@ -932,6 +927,20 @@ func TestTaskCollection_ReadAll(t *testing.T) {
|
||||||
},
|
},
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "filter labels",
|
||||||
|
fields: fields{
|
||||||
|
FilterBy: []string{"labels"},
|
||||||
|
FilterValue: []string{"4"},
|
||||||
|
FilterComparator: []string{"equals"},
|
||||||
|
},
|
||||||
|
args: defaultArgs,
|
||||||
|
want: []*Task{
|
||||||
|
task1,
|
||||||
|
task2,
|
||||||
|
},
|
||||||
|
wantErr: false,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
|
|
|
@ -270,6 +270,7 @@ func getRawTasksForLists(lists []*List, a web.Auth, opts *taskOptions) (tasks []
|
||||||
// Some filters need a special treatment since they are in a separate table
|
// Some filters need a special treatment since they are in a separate table
|
||||||
reminderFilters := []builder.Cond{}
|
reminderFilters := []builder.Cond{}
|
||||||
assigneeFilters := []builder.Cond{}
|
assigneeFilters := []builder.Cond{}
|
||||||
|
labelFilters := []builder.Cond{}
|
||||||
|
|
||||||
var filters = make([]builder.Cond, 0, len(opts.filters))
|
var filters = make([]builder.Cond, 0, len(opts.filters))
|
||||||
// To still find tasks with nil values, we exclude 0s when comparing with >/< values.
|
// To still find tasks with nil values, we exclude 0s when comparing with >/< values.
|
||||||
|
@ -294,6 +295,16 @@ func getRawTasksForLists(lists []*List, a web.Auth, opts *taskOptions) (tasks []
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if f.field == "labels" {
|
||||||
|
f.field = "label_id"
|
||||||
|
filter, err := getFilterCond(f, opts.filterIncludeNulls)
|
||||||
|
if err != nil {
|
||||||
|
return nil, 0, 0, err
|
||||||
|
}
|
||||||
|
labelFilters = append(labelFilters, filter)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
filter, err := getFilterCond(f, opts.filterIncludeNulls)
|
filter, err := getFilterCond(f, opts.filterIncludeNulls)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, 0, err
|
return nil, 0, 0, err
|
||||||
|
@ -354,6 +365,10 @@ func getRawTasksForLists(lists []*List, a web.Auth, opts *taskOptions) (tasks []
|
||||||
filters = append(filters, getFilterCondForSeparateTable("task_assignees", opts.filterConcat, assigneeFilters))
|
filters = append(filters, getFilterCondForSeparateTable("task_assignees", opts.filterConcat, assigneeFilters))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(labelFilters) > 0 {
|
||||||
|
filters = append(filters, getFilterCondForSeparateTable("label_task", opts.filterConcat, labelFilters))
|
||||||
|
}
|
||||||
|
|
||||||
query = query.Where(listCond)
|
query = query.Where(listCond)
|
||||||
queryCount = queryCount.Where(listCond)
|
queryCount = queryCount.Where(listCond)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue