Skip to content

Commit 474a907

Browse files
lukasaceArt-GmbH
lukas
authored andcommitted
Display project in issue list
1 parent 690272d commit 474a907

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

models/issues/issue_list.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"fmt"
1010

1111
"code.gitea.io/gitea/models/db"
12+
project_model "code.gitea.io/gitea/models/project"
1213
repo_model "code.gitea.io/gitea/models/repo"
1314
user_model "code.gitea.io/gitea/models/user"
1415
"code.gitea.io/gitea/modules/container"
@@ -222,6 +223,46 @@ func (issues IssueList) loadMilestones(ctx context.Context) error {
222223
return nil
223224
}
224225

226+
func (issues IssueList) getProjectIDs() []int64 {
227+
ids := make(map[int64]struct{}, len(issues))
228+
for _, issue := range issues {
229+
projectID := issue.ProjectID()
230+
if _, ok := ids[projectID]; !ok {
231+
ids[projectID] = struct{}{}
232+
}
233+
}
234+
return container.KeysInt64(ids)
235+
}
236+
237+
func (issues IssueList) loadProjects(ctx context.Context) error {
238+
projectIDs := issues.getProjectIDs()
239+
if len(projectIDs) == 0 {
240+
return nil
241+
}
242+
243+
projectMaps := make(map[int64]*project_model.Project, len(projectIDs))
244+
left := len(projectIDs)
245+
for left > 0 {
246+
limit := db.DefaultMaxInSize
247+
if left < limit {
248+
limit = left
249+
}
250+
err := db.GetEngine(ctx).
251+
In("id", projectIDs[:limit]).
252+
Find(&projectMaps)
253+
if err != nil {
254+
return err
255+
}
256+
left -= limit
257+
projectIDs = projectIDs[limit:]
258+
}
259+
260+
for _, issue := range issues {
261+
issue.Project = projectMaps[issue.ProjectID()]
262+
}
263+
return nil
264+
}
265+
225266
func (issues IssueList) loadAssignees(ctx context.Context) error {
226267
if len(issues) == 0 {
227268
return nil
@@ -495,6 +536,10 @@ func (issues IssueList) loadAttributes(ctx context.Context) error {
495536
return fmt.Errorf("issue.loadAttributes: loadMilestones: %v", err)
496537
}
497538

539+
if err := issues.loadProjects(ctx); err != nil {
540+
return fmt.Errorf("issue.loadAttributes: loadProjects: %v", err)
541+
}
542+
498543
if err := issues.loadAssignees(ctx); err != nil {
499544
return fmt.Errorf("issue.loadAttributes: loadAssignees: %v", err)
500545
}

templates/shared/issuelist.tmpl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@
8989
{{svg "octicon-milestone" 14 "mr-2"}}{{.Milestone.Name}}
9090
</a>
9191
{{end}}
92+
{{if .Project}}
93+
<a class="project" {{if $.RepoLink}}href="{{$.RepoLink}}/projects/{{.Project.ID}}"{{else}}href="{{.Repo.Link}}/projects/{{.Project.ID}}"{{end}}>
94+
{{svg "octicon-project" 14 "mr-2"}}{{.Project.Title}}
95+
</a>
96+
{{end}}
9297
{{if .Ref}}
9398
<a class="ref" {{if $.RepoLink}}href="{{index $.IssueRefURLs .ID}}"{{else}}href="{{.Repo.Link}}{{index $.IssueRefURLs .ID}}"{{end}}>
9499
{{svg "octicon-git-branch" 14 "mr-2"}}{{index $.IssueRefEndNames .ID}}

web_src/less/shared/issuelist.less

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@
101101
padding-left: 5px;
102102
}
103103

104-
a.milestone {
104+
a.milestone,
105+
a.project {
105106
margin-left: 5px;
106107
}
107108

0 commit comments

Comments
 (0)