diff options
author | yp05327 <576951401@qq.com> | 2024-12-27 03:49:50 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-27 02:49:50 +0800 |
commit | 7bb7ba1b5b70eb9ad984eaeeabecc1dcc2a26eb9 (patch) | |
tree | de08464d806d2a968d69a9b7eb8feaa1083e18c1 | |
parent | 550abdbc2443209d6b2f4801c6e3c180b48d73bb (diff) | |
download | gitea-7bb7ba1b5b70eb9ad984eaeeabecc1dcc2a26eb9.tar.gz gitea-7bb7ba1b5b70eb9ad984eaeeabecc1dcc2a26eb9.zip |
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 <wxiaoguang@gmail.com>
-rw-r--r-- | custom/conf/app.example.ini | 3 | ||||
-rw-r--r-- | modules/setting/ui.go | 3 | ||||
-rw-r--r-- | options/locale/locale_en-US.ini | 1 | ||||
-rw-r--r-- | routers/web/shared/user/header.go | 9 | ||||
-rw-r--r-- | routers/web/user/profile.go | 42 | ||||
-rw-r--r-- | templates/shared/user/profile_big_avatar.tmpl | 3 | ||||
-rw-r--r-- | templates/user/profile.tmpl | 2 |
7 files changed, 38 insertions, 25 deletions
diff --git a/custom/conf/app.example.ini b/custom/conf/app.example.ini index 6377ebf9d2..d819b55d28 100644 --- a/custom/conf/app.example.ini +++ b/custom/conf/app.example.ini @@ -1339,6 +1339,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 db0fe9ef79..20fc612b43 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 ea4d36fb1c..16d894aa26 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 4cb0592b4b..d388d2b5d9 100644 --- a/routers/web/shared/user/header.go +++ b/routers/web/shared/user/header.go @@ -61,11 +61,20 @@ func PrepareContextForProfileBigAvatar(ctx *context.Context) { orgs, err := db.Find[organization.Organization](ctx, organization.FindOrgOptions{ UserID: ctx.ContextUser.ID, 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, + }, }) 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["HasOrgsVisible"] = organization.HasOrgsVisible(ctx, orgs, ctx.Doer) diff --git a/routers/web/user/profile.go b/routers/web/user/profile.go index 44824de752..9c014bffdb 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{ @@ -294,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 } diff --git a/templates/shared/user/profile_big_avatar.tmpl b/templates/shared/user/profile_big_avatar.tmpl index f04f1ef6c4..91f04e0b53 100644 --- a/templates/shared/user/profile_big_avatar.tmpl +++ b/templates/shared/user/profile_big_avatar.tmpl @@ -92,6 +92,9 @@ </li> {{end}} {{end}} + {{if .ShowMoreOrgs}} + <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> + {{end}} </ul> </li> {{end}} diff --git a/templates/user/profile.tmpl b/templates/user/profile.tmpl index cf61bb906a..2c83ce97cd 100644 --- a/templates/user/profile.tmpl +++ b/templates/user/profile.tmpl @@ -27,6 +27,8 @@ {{template "repo/user_cards" .}} {{else if eq .TabName "overview"}} <div id="readme_profile" class="markup">{{.ProfileReadme}}</div> + {{else if eq .TabName "organizations"}} + {{template "repo/user_cards" .}} {{else}} {{template "shared/repo_search" .}} {{template "explore/repo_list" .}} |