From 8c0b45b0aaf83d0274402f31507108f8c6b43001 Mon Sep 17 00:00:00 2001
From: yp05327 <576951401@qq.com>
Date: Thu, 26 Dec 2024 03:56:12 +0000
Subject: [PATCH 1/6] add
---
custom/conf/app.example.ini | 3 +++
modules/setting/ui.go | 3 +++
options/locale/locale_en-US.ini | 1 +
routers/web/shared/user/header.go | 7 ++++++-
routers/web/user/profile.go | 16 ++++++++++++++++
templates/shared/user/profile_big_avatar.tmpl | 3 +++
templates/user/profile.tmpl | 2 ++
7 files changed, 34 insertions(+), 1 deletion(-)
diff --git a/custom/conf/app.example.ini b/custom/conf/app.example.ini
index 5c23f70d7ca7a..13fb0b838950d 100644
--- a/custom/conf/app.example.ini
+++ b/custom/conf/app.example.ini
@@ -1335,6 +1335,9 @@ LEVEL = Info
;; Number of repos that are displayed on one page
;REPO_PAGING_NUM = 15
+;; Number of orgs that are displayed on profile page
+;ORG_PAGING_NUM = 15
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;[ui.meta]
diff --git a/modules/setting/ui.go b/modules/setting/ui.go
index db0fe9ef79ac0..20fc612b43afe 100644
--- a/modules/setting/ui.go
+++ b/modules/setting/ui.go
@@ -63,6 +63,7 @@ var UI = struct {
} `ini:"ui.admin"`
User struct {
RepoPagingNum int
+ OrgPagingNum int
} `ini:"ui.user"`
Meta struct {
Author string
@@ -127,8 +128,10 @@ var UI = struct {
},
User: struct {
RepoPagingNum int
+ OrgPagingNum int
}{
RepoPagingNum: 15,
+ OrgPagingNum: 15,
},
Meta: struct {
Author string
diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini
index 1c56dce82295b..70aa48364d702 100644
--- a/options/locale/locale_en-US.ini
+++ b/options/locale/locale_en-US.ini
@@ -649,6 +649,7 @@ joined_on = Joined on %s
repositories = Repositories
activity = Public Activity
followers = Followers
+show_more = Show More
starred = Starred Repositories
watched = Watched Repositories
code = Code
diff --git a/routers/web/shared/user/header.go b/routers/web/shared/user/header.go
index 4cb0592b4b782..77a57e8619349 100644
--- a/routers/web/shared/user/header.go
+++ b/routers/web/shared/user/header.go
@@ -58,15 +58,20 @@ func PrepareContextForProfileBigAvatar(ctx *context.Context) {
}
showPrivate := ctx.IsSigned && (ctx.Doer.IsAdmin || ctx.Doer.ID == ctx.ContextUser.ID)
- orgs, err := db.Find[organization.Organization](ctx, organization.FindOrgOptions{
+ orgs, count, err := db.FindAndCount[organization.Organization](ctx, organization.FindOrgOptions{
UserID: ctx.ContextUser.ID,
IncludePrivate: showPrivate,
+ ListOptions: db.ListOptions{
+ Page: 1,
+ PageSize: setting.UI.User.OrgPagingNum,
+ },
})
if err != nil {
ctx.ServerError("FindOrgs", err)
return
}
ctx.Data["Orgs"] = orgs
+ ctx.Data["ShowMoreOrgs"] = int(count) > setting.UI.User.OrgPagingNum
ctx.Data["HasOrgsVisible"] = organization.HasOrgsVisible(ctx, orgs, ctx.Doer)
badges, _, err := user_model.GetUserBadges(ctx, ctx.ContextUser)
diff --git a/routers/web/user/profile.go b/routers/web/user/profile.go
index c41030a5e2515..10f11425fa782 100644
--- a/routers/web/user/profile.go
+++ b/routers/web/user/profile.go
@@ -12,6 +12,7 @@ import (
activities_model "code.gitea.io/gitea/models/activities"
"code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/organization"
"code.gitea.io/gitea/models/renderhelper"
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
@@ -256,6 +257,21 @@ func prepareUserProfileTabData(ctx *context.Context, showPrivate bool, profileDb
ctx.Data["ProfileReadme"] = profileContent
}
}
+ case "organizations":
+ orgs, count, err := db.FindAndCount[organization.Organization](ctx, organization.FindOrgOptions{
+ UserID: ctx.ContextUser.ID,
+ IncludePrivate: showPrivate,
+ ListOptions: db.ListOptions{
+ Page: page,
+ PageSize: pagingNum,
+ },
+ })
+ if err != nil {
+ ctx.ServerError("GetUserOrganizations", err)
+ return
+ }
+ ctx.Data["Cards"] = orgs
+ total = int(count)
default: // default to "repositories"
repos, count, err = repo_model.SearchRepository(ctx, &repo_model.SearchRepoOptions{
ListOptions: db.ListOptions{
diff --git a/templates/shared/user/profile_big_avatar.tmpl b/templates/shared/user/profile_big_avatar.tmpl
index f04f1ef6c411b..52f99e8da969f 100644
--- a/templates/shared/user/profile_big_avatar.tmpl
+++ b/templates/shared/user/profile_big_avatar.tmpl
@@ -92,6 +92,9 @@
{{end}}
{{end}}
+ {{if .ShowMoreOrgs}}
+
{{svg "octicon-kebab-horizontal" 28 "dropdown icon"}}
+ {{end}}
{{end}}
diff --git a/templates/user/profile.tmpl b/templates/user/profile.tmpl
index cf61bb906a172..2c83ce97cd3df 100644
--- a/templates/user/profile.tmpl
+++ b/templates/user/profile.tmpl
@@ -27,6 +27,8 @@
{{template "repo/user_cards" .}}
{{else if eq .TabName "overview"}}
{{.ProfileReadme}}
+ {{else if eq .TabName "organizations"}}
+ {{template "repo/user_cards" .}}
{{else}}
{{template "shared/repo_search" .}}
{{template "explore/repo_list" .}}
From 3b726f934ef055484bbf53fd93d0f8da56f285df Mon Sep 17 00:00:00 2001
From: yp05327 <576951401@qq.com>
Date: Thu, 26 Dec 2024 04:10:24 +0000
Subject: [PATCH 2/6] improve
---
templates/shared/user/profile_big_avatar.tmpl | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/templates/shared/user/profile_big_avatar.tmpl b/templates/shared/user/profile_big_avatar.tmpl
index 52f99e8da969f..91f04e0b53dc6 100644
--- a/templates/shared/user/profile_big_avatar.tmpl
+++ b/templates/shared/user/profile_big_avatar.tmpl
@@ -93,7 +93,7 @@
{{end}}
{{end}}
{{if .ShowMoreOrgs}}
- {{svg "octicon-kebab-horizontal" 28 "dropdown icon"}}
+ {{svg "octicon-kebab-horizontal" 28 "icon tw-p-1"}}
{{end}}
From 74701dcfa17978109a7870982bc342e46943f39d Mon Sep 17 00:00:00 2001
From: yp05327 <576951401@qq.com>
Date: Thu, 26 Dec 2024 06:52:48 +0000
Subject: [PATCH 3/6] improve
---
routers/web/shared/user/header.go | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/routers/web/shared/user/header.go b/routers/web/shared/user/header.go
index 77a57e8619349..4c32e3f8e0ad0 100644
--- a/routers/web/shared/user/header.go
+++ b/routers/web/shared/user/header.go
@@ -58,20 +58,23 @@ func PrepareContextForProfileBigAvatar(ctx *context.Context) {
}
showPrivate := ctx.IsSigned && (ctx.Doer.IsAdmin || ctx.Doer.ID == ctx.ContextUser.ID)
- orgs, count, err := db.FindAndCount[organization.Organization](ctx, organization.FindOrgOptions{
+ orgs, err := db.Find[organization.Organization](ctx, organization.FindOrgOptions{
UserID: ctx.ContextUser.ID,
IncludePrivate: showPrivate,
ListOptions: db.ListOptions{
Page: 1,
- PageSize: setting.UI.User.OrgPagingNum,
+ PageSize: setting.UI.User.OrgPagingNum + 1,
},
})
if err != nil {
ctx.ServerError("FindOrgs", err)
return
}
+ if len(orgs) > setting.UI.User.OrgPagingNum {
+ orgs = orgs[:setting.UI.User.OrgPagingNum]
+ ctx.Data["ShowMoreOrgs"] = true
+ }
ctx.Data["Orgs"] = orgs
- ctx.Data["ShowMoreOrgs"] = int(count) > setting.UI.User.OrgPagingNum
ctx.Data["HasOrgsVisible"] = organization.HasOrgsVisible(ctx, orgs, ctx.Doer)
badges, _, err := user_model.GetUserBadges(ctx, ctx.ContextUser)
From 5d657345aec57cbea438eea8bd62616c447395bf Mon Sep 17 00:00:00 2001
From: yp05327 <576951401@qq.com>
Date: Thu, 26 Dec 2024 06:58:14 +0000
Subject: [PATCH 4/6] use AddParamFromRequest
---
routers/web/user/profile.go | 26 +-------------------------
1 file changed, 1 insertion(+), 25 deletions(-)
diff --git a/routers/web/user/profile.go b/routers/web/user/profile.go
index 69fe3d3a2a24a..9c014bffdb79b 100644
--- a/routers/web/user/profile.go
+++ b/routers/web/user/profile.go
@@ -310,31 +310,7 @@ func prepareUserProfileTabData(ctx *context.Context, showPrivate bool, profileDb
}
pager := context.NewPagination(total, pagingNum, page, 5)
- pager.SetDefaultParams(ctx)
- pager.AddParamString("tab", tab)
- if tab != "followers" && tab != "following" && tab != "activity" && tab != "projects" {
- pager.AddParamString("language", language)
- }
- if tab == "activity" {
- if ctx.Data["Date"] != nil {
- pager.AddParamString("date", fmt.Sprint(ctx.Data["Date"]))
- }
- }
- if archived.Has() {
- pager.AddParamString("archived", fmt.Sprint(archived.Value()))
- }
- if fork.Has() {
- pager.AddParamString("fork", fmt.Sprint(fork.Value()))
- }
- if mirror.Has() {
- pager.AddParamString("mirror", fmt.Sprint(mirror.Value()))
- }
- if template.Has() {
- pager.AddParamString("template", fmt.Sprint(template.Value()))
- }
- if private.Has() {
- pager.AddParamString("private", fmt.Sprint(private.Value()))
- }
+ pager.AddParamFromRequest(ctx.Req)
ctx.Data["Page"] = pager
}
From 57b72a0bb52bb54153ff600a56c8f84adf1a20ca Mon Sep 17 00:00:00 2001
From: wxiaoguang
Date: Thu, 26 Dec 2024 20:11:37 +0800
Subject: [PATCH 5/6] Update routers/web/shared/user/header.go
---
routers/web/shared/user/header.go | 1 +
1 file changed, 1 insertion(+)
diff --git a/routers/web/shared/user/header.go b/routers/web/shared/user/header.go
index 4c32e3f8e0ad0..fab5ab0f9a7f2 100644
--- a/routers/web/shared/user/header.go
+++ b/routers/web/shared/user/header.go
@@ -63,6 +63,7 @@ func PrepareContextForProfileBigAvatar(ctx *context.Context) {
IncludePrivate: showPrivate,
ListOptions: db.ListOptions{
Page: 1,
+ // query one more results (without a separate counting) to see whether we need to add the "show more orgs" link
PageSize: setting.UI.User.OrgPagingNum + 1,
},
})
From 816c0d97268a91c5ec95bbf9b3a5d1e63d8e4ea5 Mon Sep 17 00:00:00 2001
From: wxiaoguang
Date: Thu, 26 Dec 2024 20:17:17 +0800
Subject: [PATCH 6/6] lint
---
routers/web/shared/user/header.go | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/routers/web/shared/user/header.go b/routers/web/shared/user/header.go
index fab5ab0f9a7f2..d388d2b5d9a6c 100644
--- a/routers/web/shared/user/header.go
+++ b/routers/web/shared/user/header.go
@@ -62,7 +62,7 @@ func PrepareContextForProfileBigAvatar(ctx *context.Context) {
UserID: ctx.ContextUser.ID,
IncludePrivate: showPrivate,
ListOptions: db.ListOptions{
- Page: 1,
+ Page: 1,
// query one more results (without a separate counting) to see whether we need to add the "show more orgs" link
PageSize: setting.UI.User.OrgPagingNum + 1,
},