Skip to content

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

routers/web/shared/user/header.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"code.gitea.io/gitea/models/db"
88
"code.gitea.io/gitea/models/organization"
99
access_model "code.gitea.io/gitea/models/perm/access"
10+
project_model "code.gitea.io/gitea/models/project"
1011
repo_model "code.gitea.io/gitea/models/repo"
1112
"code.gitea.io/gitea/models/unit"
1213
user_model "code.gitea.io/gitea/models/user"
@@ -134,5 +135,21 @@ func LoadHeaderCount(ctx *context.Context) error {
134135
}
135136
ctx.Data["RepoCount"] = repoCount
136137

138+
var projectType project_model.Type
139+
if ctx.ContextUser.IsOrganization() {
140+
projectType = project_model.TypeOrganization
141+
} else {
142+
projectType = project_model.TypeIndividual
143+
}
144+
projectCount, err := project_model.CountProjects(ctx, project_model.SearchOptions{
145+
OwnerID: ctx.ContextUser.ID,
146+
IsClosed: util.OptionalBoolOf(false),
147+
Type: projectType,
148+
})
149+
if err != nil {
150+
return err
151+
}
152+
ctx.Data["ProjectCount"] = projectCount
153+
137154
return nil
138155
}

templates/org/menu.tmpl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
{{if .CanReadProjects}}
1010
<a class="{{if .PageIsViewProjects}}active {{end}}item" href="{{$.Org.HomeLink}}/-/projects">
1111
{{svg "octicon-project-symlink"}} {{ctx.Locale.Tr "user.projects"}}
12+
{{if .ProjectCount}}
13+
<div class="ui small label">{{.ProjectCount}}</div>
14+
{{end}}
1215
</a>
1316
{{end}}
1417
{{if and .IsPackageEnabled .CanReadPackages}}

templates/user/overview/header.tmpl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
{{if or .ContextUser.IsIndividual (and .ContextUser.IsOrganization .CanReadProjects)}}
1414
<a href="{{.ContextUser.HomeLink}}/-/projects" class="{{if .PageIsViewProjects}}active {{end}}item">
1515
{{svg "octicon-project-symlink"}} {{ctx.Locale.Tr "user.projects"}}
16+
{{if .ProjectCount}}
17+
<div class="ui small label">{{.ProjectCount}}</div>
18+
{{end}}
1619
</a>
1720
{{end}}
1821
{{if and .IsPackageEnabled (or .ContextUser.IsIndividual (and .ContextUser.IsOrganization .CanReadPackages))}}

0 commit comments

Comments
 (0)