Skip to content

Commit 7bb7ba1

Browse files
yp05327wxiaoguang
andauthored
Add show more organizations icon in user's profile (#32986)
Close #32952 # ⚠️ Doc update is required ![image](https://github.com/user-attachments/assets/296c5109-8fc1-43ea-b7dc-e79919cc1f9a) ![image](https://github.com/user-attachments/assets/d30980f6-22e4-4b97-9143-c750dc399da6) ------ ⚠️This PR refuses to be cherry-picked by any forked projects without any mentions. --------- Co-authored-by: wxiaoguang <[email protected]>
1 parent 550abdb commit 7bb7ba1

File tree

7 files changed

+38
-25
lines changed

7 files changed

+38
-25
lines changed

custom/conf/app.example.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,6 +1339,9 @@ LEVEL = Info
13391339
;; Number of repos that are displayed on one page
13401340
;REPO_PAGING_NUM = 15
13411341

1342+
;; Number of orgs that are displayed on profile page
1343+
;ORG_PAGING_NUM = 15
1344+
13421345
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13431346
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13441347
;[ui.meta]

modules/setting/ui.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ var UI = struct {
6363
} `ini:"ui.admin"`
6464
User struct {
6565
RepoPagingNum int
66+
OrgPagingNum int
6667
} `ini:"ui.user"`
6768
Meta struct {
6869
Author string
@@ -127,8 +128,10 @@ var UI = struct {
127128
},
128129
User: struct {
129130
RepoPagingNum int
131+
OrgPagingNum int
130132
}{
131133
RepoPagingNum: 15,
134+
OrgPagingNum: 15,
132135
},
133136
Meta: struct {
134137
Author string

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,7 @@ joined_on = Joined on %s
649649
repositories = Repositories
650650
activity = Public Activity
651651
followers = Followers
652+
show_more = Show More
652653
starred = Starred Repositories
653654
watched = Watched Repositories
654655
code = Code

routers/web/shared/user/header.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,20 @@ func PrepareContextForProfileBigAvatar(ctx *context.Context) {
6161
orgs, err := db.Find[organization.Organization](ctx, organization.FindOrgOptions{
6262
UserID: ctx.ContextUser.ID,
6363
IncludePrivate: showPrivate,
64+
ListOptions: db.ListOptions{
65+
Page: 1,
66+
// query one more results (without a separate counting) to see whether we need to add the "show more orgs" link
67+
PageSize: setting.UI.User.OrgPagingNum + 1,
68+
},
6469
})
6570
if err != nil {
6671
ctx.ServerError("FindOrgs", err)
6772
return
6873
}
74+
if len(orgs) > setting.UI.User.OrgPagingNum {
75+
orgs = orgs[:setting.UI.User.OrgPagingNum]
76+
ctx.Data["ShowMoreOrgs"] = true
77+
}
6978
ctx.Data["Orgs"] = orgs
7079
ctx.Data["HasOrgsVisible"] = organization.HasOrgsVisible(ctx, orgs, ctx.Doer)
7180

routers/web/user/profile.go

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
activities_model "code.gitea.io/gitea/models/activities"
1414
"code.gitea.io/gitea/models/db"
15+
"code.gitea.io/gitea/models/organization"
1516
"code.gitea.io/gitea/models/renderhelper"
1617
repo_model "code.gitea.io/gitea/models/repo"
1718
user_model "code.gitea.io/gitea/models/user"
@@ -256,6 +257,21 @@ func prepareUserProfileTabData(ctx *context.Context, showPrivate bool, profileDb
256257
ctx.Data["ProfileReadme"] = profileContent
257258
}
258259
}
260+
case "organizations":
261+
orgs, count, err := db.FindAndCount[organization.Organization](ctx, organization.FindOrgOptions{
262+
UserID: ctx.ContextUser.ID,
263+
IncludePrivate: showPrivate,
264+
ListOptions: db.ListOptions{
265+
Page: page,
266+
PageSize: pagingNum,
267+
},
268+
})
269+
if err != nil {
270+
ctx.ServerError("GetUserOrganizations", err)
271+
return
272+
}
273+
ctx.Data["Cards"] = orgs
274+
total = int(count)
259275
default: // default to "repositories"
260276
repos, count, err = repo_model.SearchRepository(ctx, &repo_model.SearchRepoOptions{
261277
ListOptions: db.ListOptions{
@@ -294,31 +310,7 @@ func prepareUserProfileTabData(ctx *context.Context, showPrivate bool, profileDb
294310
}
295311

296312
pager := context.NewPagination(total, pagingNum, page, 5)
297-
pager.SetDefaultParams(ctx)
298-
pager.AddParamString("tab", tab)
299-
if tab != "followers" && tab != "following" && tab != "activity" && tab != "projects" {
300-
pager.AddParamString("language", language)
301-
}
302-
if tab == "activity" {
303-
if ctx.Data["Date"] != nil {
304-
pager.AddParamString("date", fmt.Sprint(ctx.Data["Date"]))
305-
}
306-
}
307-
if archived.Has() {
308-
pager.AddParamString("archived", fmt.Sprint(archived.Value()))
309-
}
310-
if fork.Has() {
311-
pager.AddParamString("fork", fmt.Sprint(fork.Value()))
312-
}
313-
if mirror.Has() {
314-
pager.AddParamString("mirror", fmt.Sprint(mirror.Value()))
315-
}
316-
if template.Has() {
317-
pager.AddParamString("template", fmt.Sprint(template.Value()))
318-
}
319-
if private.Has() {
320-
pager.AddParamString("private", fmt.Sprint(private.Value()))
321-
}
313+
pager.AddParamFromRequest(ctx.Req)
322314
ctx.Data["Page"] = pager
323315
}
324316

templates/shared/user/profile_big_avatar.tmpl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@
9292
</li>
9393
{{end}}
9494
{{end}}
95+
{{if .ShowMoreOrgs}}
96+
<li><a class="tw-align-center" href="{{.ContextUser.HomeLink}}?tab=organizations" data-tooltip-content="{{ctx.Locale.Tr "user.show_more"}}">{{svg "octicon-kebab-horizontal" 28 "icon tw-p-1"}}</a></li>
97+
{{end}}
9598
</ul>
9699
</li>
97100
{{end}}

templates/user/profile.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
{{template "repo/user_cards" .}}
2828
{{else if eq .TabName "overview"}}
2929
<div id="readme_profile" class="markup">{{.ProfileReadme}}</div>
30+
{{else if eq .TabName "organizations"}}
31+
{{template "repo/user_cards" .}}
3032
{{else}}
3133
{{template "shared/repo_search" .}}
3234
{{template "explore/repo_list" .}}

0 commit comments

Comments
 (0)