aboutsummaryrefslogtreecommitdiffstats
path: root/routers/web/shared
diff options
context:
space:
mode:
authorLauris BH <lauris@nix.lv>2024-09-12 06:53:40 +0300
committerGitHub <noreply@github.com>2024-09-12 03:53:40 +0000
commit4ab6fc62d23bcef060cb98c60cfc29aa286a02d1 (patch)
tree281291164aca9c1d08f37ad6e40e7245bd828929 /routers/web/shared
parent20d7707124c2b4b9616526c6b242660729028ae7 (diff)
downloadgitea-4ab6fc62d23bcef060cb98c60cfc29aa286a02d1.tar.gz
gitea-4ab6fc62d23bcef060cb98c60cfc29aa286a02d1.zip
Add option to filter board cards by labels and assignees (#31999)
Works in both organization and repository project boards Fixes #21846 Replaces #21963 Replaces #27117 ![image](https://github.com/user-attachments/assets/1837ace8-3de2-444f-a153-e166bd0da2c0) **Note** that implementation was made intentionally to work same as in issue list so that URL can be bookmarked for quick access with predefined filters in URL
Diffstat (limited to 'routers/web/shared')
-rw-r--r--routers/web/shared/user/helper.go22
-rw-r--r--routers/web/shared/user/helper_test.go26
2 files changed, 48 insertions, 0 deletions
diff --git a/routers/web/shared/user/helper.go b/routers/web/shared/user/helper.go
new file mode 100644
index 0000000000..6186b9b9ff
--- /dev/null
+++ b/routers/web/shared/user/helper.go
@@ -0,0 +1,22 @@
+// Copyright 2023 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package user
+
+import (
+ "sort"
+
+ "code.gitea.io/gitea/models/user"
+)
+
+func MakeSelfOnTop(doer *user.User, users []*user.User) []*user.User {
+ if doer != nil {
+ sort.Slice(users, func(i, j int) bool {
+ if users[i].ID == users[j].ID {
+ return false
+ }
+ return users[i].ID == doer.ID // if users[i] is self, put it before others, so less=true
+ })
+ }
+ return users
+}
diff --git a/routers/web/shared/user/helper_test.go b/routers/web/shared/user/helper_test.go
new file mode 100644
index 0000000000..ccdf536c13
--- /dev/null
+++ b/routers/web/shared/user/helper_test.go
@@ -0,0 +1,26 @@
+// Copyright 2023 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package user
+
+import (
+ "testing"
+
+ "code.gitea.io/gitea/models/user"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestMakeSelfOnTop(t *testing.T) {
+ users := MakeSelfOnTop(nil, []*user.User{{ID: 2}, {ID: 1}})
+ assert.Len(t, users, 2)
+ assert.EqualValues(t, 2, users[0].ID)
+
+ users = MakeSelfOnTop(&user.User{ID: 1}, []*user.User{{ID: 2}, {ID: 1}})
+ assert.Len(t, users, 2)
+ assert.EqualValues(t, 1, users[0].ID)
+
+ users = MakeSelfOnTop(&user.User{ID: 2}, []*user.User{{ID: 2}, {ID: 1}})
+ assert.Len(t, users, 2)
+ assert.EqualValues(t, 2, users[0].ID)
+}