Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions routers/web/org/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"code.gitea.io/gitea/modules/markup"
"code.gitea.io/gitea/modules/markup/markdown"
"code.gitea.io/gitea/modules/setting"
shared_user "code.gitea.io/gitea/routers/web/shared/user"
)

const (
Expand Down Expand Up @@ -158,6 +159,12 @@ func Home(ctx *context.Context) {
ctx.Data["PageIsViewRepositories"] = true
ctx.Data["IsFollowing"] = isFollowing

err = shared_user.LoadHeaderCount(ctx)
if err != nil {
ctx.ServerError("LoadHeaderCount", err)
return
}

pager := context.NewPagination(int(count), setting.UI.User.RepoPagingNum, page, 5)
pager.SetDefaultParams(ctx)
pager.AddParam(ctx, "language", "Language")
Expand Down
25 changes: 25 additions & 0 deletions routers/web/org/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ func Projects(ctx *context.Context) {
project.RenderedContent = project.Description
}

err = shared_user.LoadHeaderCount(ctx)
if err != nil {
ctx.ServerError("LoadHeaderCount", err)
return
}

numPages := 0
if total > 0 {
numPages = (int(total) - 1/setting.UI.IssuePagingNum)
Expand Down Expand Up @@ -135,6 +141,13 @@ func RenderNewProject(ctx *context.Context) {
ctx.Data["HomeLink"] = ctx.ContextUser.HomeLink()
ctx.Data["CancelLink"] = ctx.ContextUser.HomeLink() + "/-/projects"
shared_user.RenderUserHeader(ctx)

err := shared_user.LoadHeaderCount(ctx)
if err != nil {
ctx.ServerError("LoadHeaderCount", err)
return
}

ctx.HTML(http.StatusOK, tplProjectsNew)
}

Expand Down Expand Up @@ -270,6 +283,12 @@ func EditProjectPost(ctx *context.Context) {

shared_user.RenderUserHeader(ctx)

err := shared_user.LoadHeaderCount(ctx)
if err != nil {
ctx.ServerError("LoadHeaderCount", err)
return
}

if ctx.HasError() {
ctx.HTML(http.StatusOK, tplProjectsNew)
return
Expand Down Expand Up @@ -379,6 +398,12 @@ func ViewProject(ctx *context.Context) {
ctx.Data["Boards"] = boards
shared_user.RenderUserHeader(ctx)

err = shared_user.LoadHeaderCount(ctx)
if err != nil {
ctx.ServerError("LoadHeaderCount", err)
return
}

ctx.HTML(http.StatusOK, tplProjectsView)
}

Expand Down
19 changes: 19 additions & 0 deletions routers/web/shared/user/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"code.gitea.io/gitea/modules/markup"
"code.gitea.io/gitea/modules/markup/markdown"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
)

// prepareContextForCommonProfile store some common data into context data for user's profile related pages (including the nav menu)
Expand Down Expand Up @@ -110,3 +111,21 @@ func RenderUserHeader(ctx *context.Context) {
defer profileClose()
ctx.Data["HasProfileReadme"] = profileReadmeBlob != nil
}

func LoadHeaderCount(ctx *context.Context) error {
prepareContextForCommonProfile(ctx)

_, repoCount, err := repo_model.SearchRepository(ctx, &repo_model.SearchRepoOptions{
Actor: ctx.Doer,
OwnerID: ctx.ContextUser.ID,
Private: ctx.IsSigned,
Collaborate: util.OptionalBoolFalse,
IncludeDescription: setting.UI.SearchRepoDescription,
})
if err != nil {
return err
}
ctx.Data["RepoCount"] = repoCount

return nil
}
18 changes: 18 additions & 0 deletions routers/web/user/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ func ListPackages(ctx *context.Context) {
ctx.Data["Total"] = total
ctx.Data["RepositoryAccessMap"] = repositoryAccessMap

err = shared_user.LoadHeaderCount(ctx)
if err != nil {
ctx.ServerError("LoadHeaderCount", err)
return
}

// TODO: context/org -> HandleOrgAssignment() can not be used
if ctx.ContextUser.IsOrganization() {
org := org_model.OrgFromUser(ctx.ContextUser)
Expand Down Expand Up @@ -255,6 +261,12 @@ func ViewPackageVersion(ctx *context.Context) {
}
ctx.Data["HasRepositoryAccess"] = hasRepositoryAccess

err = shared_user.LoadHeaderCount(ctx)
if err != nil {
ctx.ServerError("LoadHeaderCount", err)
return
}

ctx.HTML(http.StatusOK, tplPackagesView)
}

Expand Down Expand Up @@ -346,6 +358,12 @@ func ListPackageVersions(ctx *context.Context) {

ctx.Data["Total"] = total

err = shared_user.LoadHeaderCount(ctx)
if err != nil {
ctx.ServerError("LoadHeaderCount", err)
return
}

pager := context.NewPagination(int(total), setting.UI.PackagesPagingNum, page, 5)
for k, v := range pagerParams {
pager.AddParamString(k, v)
Expand Down
6 changes: 6 additions & 0 deletions routers/web/user/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,12 @@ func prepareUserProfileTabData(ctx *context.Context, showPrivate bool, profileGi
ctx.Data["Repos"] = repos
ctx.Data["Total"] = total

err = shared_user.LoadHeaderCount(ctx)
if err != nil {
ctx.ServerError("LoadHeaderCount", err)
return
}

pager := context.NewPagination(total, pagingNum, page, 5)
pager.SetDefaultParams(ctx)
pager.AddParam(ctx, "tab", "TabName")
Expand Down
4 changes: 2 additions & 2 deletions templates/org/menu.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<div class="ui secondary stackable pointing menu">
<a class="{{if .PageIsViewRepositories}}active {{end}}item" href="{{$.Org.HomeLink}}">
{{svg "octicon-repo"}} {{.locale.Tr "user.repositories"}}
{{if .ContextUser.NumRepos}}
<div class="ui small label">{{.ContextUser.NumRepos}}</div>
{{if .RepoCount}}
<div class="ui small label">{{.RepoCount}}</div>
{{end}}
</a>
{{if .CanReadProjects}}
Expand Down
4 changes: 2 additions & 2 deletions templates/user/overview/header.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
{{end}}
<a class="{{if eq .TabName "repositories"}}active {{end}} item" href="{{.ContextUser.HomeLink}}?tab=repositories">
{{svg "octicon-repo"}} {{.locale.Tr "user.repositories"}}
{{if .ContextUser.NumRepos}}
<div class="ui small label">{{.ContextUser.NumRepos}}</div>
{{if .RepoCount}}
<div class="ui small label">{{.RepoCount}}</div>
{{end}}
</a>
{{if or .ContextUser.IsIndividual (and .ContextUser.IsOrganization .CanReadProjects)}}
Expand Down