From 57e5d10eee4c45a04e9e1aaeaf41dd44eb8ce788 Mon Sep 17 00:00:00 2001 From: kolaente Date: Sun, 14 Nov 2021 21:03:55 +0100 Subject: [PATCH] fix: sorting for saved filters resolves #786 --- pkg/models/task_collection.go | 5 +++++ pkg/models/task_collection_test.go | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/pkg/models/task_collection.go b/pkg/models/task_collection.go index ec2bf0a5ca..70be8d744b 100644 --- a/pkg/models/task_collection.go +++ b/pkg/models/task_collection.go @@ -149,6 +149,11 @@ func (tf *TaskCollection) ReadAll(s *xorm.Session, a web.Auth, search string, pa return nil, 0, 0, err } + sf.Filters.SortByArr = tf.SortByArr + sf.Filters.SortBy = tf.SortBy + sf.Filters.OrderByArr = tf.OrderByArr + sf.Filters.OrderBy = tf.OrderBy + return sf.getTaskCollection().ReadAll(s, a, search, page, perPage) } diff --git a/pkg/models/task_collection_test.go b/pkg/models/task_collection_test.go index 8452892695..fa21f6aadd 100644 --- a/pkg/models/task_collection_test.go +++ b/pkg/models/task_collection_test.go @@ -1081,6 +1081,24 @@ func TestTaskCollection_ReadAll(t *testing.T) { task2, }, }, + { + name: "saved filter with sort order", + fields: fields{ + ListID: -2, + SortBy: []string{"title", "id"}, + OrderBy: []string{"desc", "asc"}, + }, + args: args{ + a: &user.User{ID: 1}, + }, + want: []*Task{ + task9, + task8, + task7, + task6, + task5, + }, + }, } for _, tt := range tests {