Display project in issue list (#20583)
Co-authored-by: lukas <lukas.walter@aceart.de> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
parent
a6c2a1a117
commit
07d140625e
|
@ -9,6 +9,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
|
project_model "code.gitea.io/gitea/models/project"
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
"code.gitea.io/gitea/modules/container"
|
"code.gitea.io/gitea/modules/container"
|
||||||
|
@ -222,6 +223,46 @@ func (issues IssueList) loadMilestones(ctx context.Context) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (issues IssueList) getProjectIDs() []int64 {
|
||||||
|
ids := make(map[int64]struct{}, len(issues))
|
||||||
|
for _, issue := range issues {
|
||||||
|
projectID := issue.ProjectID()
|
||||||
|
if _, ok := ids[projectID]; !ok {
|
||||||
|
ids[projectID] = struct{}{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return container.KeysInt64(ids)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (issues IssueList) loadProjects(ctx context.Context) error {
|
||||||
|
projectIDs := issues.getProjectIDs()
|
||||||
|
if len(projectIDs) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
projectMaps := make(map[int64]*project_model.Project, len(projectIDs))
|
||||||
|
left := len(projectIDs)
|
||||||
|
for left > 0 {
|
||||||
|
limit := db.DefaultMaxInSize
|
||||||
|
if left < limit {
|
||||||
|
limit = left
|
||||||
|
}
|
||||||
|
err := db.GetEngine(ctx).
|
||||||
|
In("id", projectIDs[:limit]).
|
||||||
|
Find(&projectMaps)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
left -= limit
|
||||||
|
projectIDs = projectIDs[limit:]
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, issue := range issues {
|
||||||
|
issue.Project = projectMaps[issue.ProjectID()]
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (issues IssueList) loadAssignees(ctx context.Context) error {
|
func (issues IssueList) loadAssignees(ctx context.Context) error {
|
||||||
if len(issues) == 0 {
|
if len(issues) == 0 {
|
||||||
return nil
|
return nil
|
||||||
|
@ -495,6 +536,10 @@ func (issues IssueList) loadAttributes(ctx context.Context) error {
|
||||||
return fmt.Errorf("issue.loadAttributes: loadMilestones: %v", err)
|
return fmt.Errorf("issue.loadAttributes: loadMilestones: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := issues.loadProjects(ctx); err != nil {
|
||||||
|
return fmt.Errorf("issue.loadAttributes: loadProjects: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
if err := issues.loadAssignees(ctx); err != nil {
|
if err := issues.loadAssignees(ctx); err != nil {
|
||||||
return fmt.Errorf("issue.loadAttributes: loadAssignees: %v", err)
|
return fmt.Errorf("issue.loadAttributes: loadAssignees: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,6 +85,11 @@
|
||||||
{{svg "octicon-milestone" 14 "mr-2"}}{{.Milestone.Name}}
|
{{svg "octicon-milestone" 14 "mr-2"}}{{.Milestone.Name}}
|
||||||
</a>
|
</a>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
{{if .Project}}
|
||||||
|
<a class="project" {{if $.RepoLink}}href="{{$.RepoLink}}/projects/{{.Project.ID}}"{{else}}href="{{.Repo.Link}}/projects/{{.Project.ID}}"{{end}}>
|
||||||
|
{{svg "octicon-project" 14 "mr-2"}}{{.Project.Title}}
|
||||||
|
</a>
|
||||||
|
{{end}}
|
||||||
{{if .Ref}}
|
{{if .Ref}}
|
||||||
<a class="ref" {{if $.RepoLink}}href="{{index $.IssueRefURLs .ID}}"{{else}}href="{{.Repo.Link}}{{index $.IssueRefURLs .ID}}"{{end}}>
|
<a class="ref" {{if $.RepoLink}}href="{{index $.IssueRefURLs .ID}}"{{else}}href="{{.Repo.Link}}{{index $.IssueRefURLs .ID}}"{{end}}>
|
||||||
{{svg "octicon-git-branch" 14 "mr-2"}}{{index $.IssueRefEndNames .ID}}
|
{{svg "octicon-git-branch" 14 "mr-2"}}{{index $.IssueRefEndNames .ID}}
|
||||||
|
|
|
@ -101,7 +101,8 @@
|
||||||
padding-left: 5px;
|
padding-left: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
a.milestone {
|
a.milestone,
|
||||||
|
a.project {
|
||||||
margin-left: 5px;
|
margin-left: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue