From 4dffbbef60903601b163460671a617817535aec3 Mon Sep 17 00:00:00 2001
From: yp05327 <576951401@qq.com>
Date: Wed, 15 Nov 2023 08:40:41 +0000
Subject: [PATCH] fix
---
routers/web/shared/user/header.go | 17 +++++++++++++++++
templates/org/menu.tmpl | 3 +++
templates/user/overview/header.tmpl | 3 +++
3 files changed, 23 insertions(+)
diff --git a/routers/web/shared/user/header.go b/routers/web/shared/user/header.go
index 3a83722ef767d..998a0c896b768 100644
--- a/routers/web/shared/user/header.go
+++ b/routers/web/shared/user/header.go
@@ -7,6 +7,7 @@ import (
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/organization"
access_model "code.gitea.io/gitea/models/perm/access"
+ project_model "code.gitea.io/gitea/models/project"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unit"
user_model "code.gitea.io/gitea/models/user"
@@ -134,5 +135,21 @@ func LoadHeaderCount(ctx *context.Context) error {
}
ctx.Data["RepoCount"] = repoCount
+ var projectType project_model.Type
+ if ctx.ContextUser.IsOrganization() {
+ projectType = project_model.TypeOrganization
+ } else {
+ projectType = project_model.TypeIndividual
+ }
+ projectCount, err := project_model.CountProjects(ctx, project_model.SearchOptions{
+ OwnerID: ctx.ContextUser.ID,
+ IsClosed: util.OptionalBoolOf(false),
+ Type: projectType,
+ })
+ if err != nil {
+ return err
+ }
+ ctx.Data["ProjectCount"] = projectCount
+
return nil
}
diff --git a/templates/org/menu.tmpl b/templates/org/menu.tmpl
index c3ec142e9c24f..8a97711ce2876 100644
--- a/templates/org/menu.tmpl
+++ b/templates/org/menu.tmpl
@@ -9,6 +9,9 @@
{{if .CanReadProjects}}
{{svg "octicon-project-symlink"}} {{ctx.Locale.Tr "user.projects"}}
+ {{if .ProjectCount}}
+ {{.ProjectCount}}
+ {{end}}
{{end}}
{{if and .IsPackageEnabled .CanReadPackages}}
diff --git a/templates/user/overview/header.tmpl b/templates/user/overview/header.tmpl
index 94d06234faa1e..c0cbe2561c558 100644
--- a/templates/user/overview/header.tmpl
+++ b/templates/user/overview/header.tmpl
@@ -13,6 +13,9 @@
{{if or .ContextUser.IsIndividual (and .ContextUser.IsOrganization .CanReadProjects)}}
{{svg "octicon-project-symlink"}} {{ctx.Locale.Tr "user.projects"}}
+ {{if .ProjectCount}}
+ {{.ProjectCount}}
+ {{end}}
{{end}}
{{if and .IsPackageEnabled (or .ContextUser.IsIndividual (and .ContextUser.IsOrganization .CanReadPackages))}}