Skip to content

Commit 11bd0ea

Browse files
committed
improvements
1 parent 7a1cc34 commit 11bd0ea

File tree

9 files changed

+50
-45
lines changed

9 files changed

+50
-45
lines changed

models/activities/notification.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package activities
66
import (
77
"context"
88
"fmt"
9+
"html/template"
910
"net/url"
1011
"strconv"
1112

@@ -16,6 +17,7 @@ import (
1617
"code.gitea.io/gitea/modules/git"
1718
"code.gitea.io/gitea/modules/gitrepo"
1819
"code.gitea.io/gitea/modules/setting"
20+
"code.gitea.io/gitea/modules/svg"
1921
"code.gitea.io/gitea/modules/timeutil"
2022

2123
"xorm.io/builder"
@@ -379,6 +381,22 @@ func (n *Notification) Link(ctx context.Context) string {
379381
return ""
380382
}
381383

384+
func (n *Notification) IconHTML(ctx context.Context) template.HTML {
385+
switch n.Source {
386+
case NotificationSourceIssue, NotificationSourcePullRequest:
387+
// n.Issue should be loaded before calling this method
388+
return n.Issue.IconHTML(ctx)
389+
case NotificationSourceCommit:
390+
return svg.RenderHTML("octicon-commit", 16, "text grey")
391+
case NotificationSourceRepository:
392+
return svg.RenderHTML("octicon-repo", 16, "text grey")
393+
case NotificationSourceRelease:
394+
return svg.RenderHTML("octicon-tag", 16, "text grey")
395+
default:
396+
return ""
397+
}
398+
}
399+
382400
// APIURL formats a URL-string to the notification
383401
func (n *Notification) APIURL() string {
384402
return setting.AppURL + "api/v1/notifications/threads/" + strconv.FormatInt(n.ID, 10)

models/issues/issue.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"code.gitea.io/gitea/modules/optional"
2222
"code.gitea.io/gitea/modules/setting"
2323
api "code.gitea.io/gitea/modules/structs"
24+
"code.gitea.io/gitea/modules/svg"
2425
"code.gitea.io/gitea/modules/timeutil"
2526
"code.gitea.io/gitea/modules/util"
2627

@@ -442,6 +443,30 @@ func (issue *Issue) PatchURL() string {
442443
return ""
443444
}
444445

446+
/* the logic should be kept the same as getIssueIcon/getIssueColor in TS code */
447+
func (issue *Issue) IconHTML(ctx context.Context) template.HTML {
448+
if issue.IsPull {
449+
if issue.PullRequest == nil { // pull request should be loaded before calling this function
450+
return template.HTML("No PullRequest")
451+
}
452+
if issue.IsClosed {
453+
if issue.PullRequest.HasMerged {
454+
return svg.RenderHTML("octicon-git-merge", 16, "text purple")
455+
}
456+
return svg.RenderHTML("octicon-git-pull-request-closed", 16, "text red")
457+
}
458+
if issue.PullRequest.IsWorkInProgress(ctx) {
459+
return svg.RenderHTML("octicon-git-pull-request-draft", 16, "text grey")
460+
}
461+
return svg.RenderHTML("octicon-git-pull-request", 16, "text green")
462+
}
463+
464+
if issue.IsClosed {
465+
return svg.RenderHTML("octicon-issue-closed", 16, "text red")
466+
}
467+
return svg.RenderHTML("octicon-issue-opened", 16, "text green")
468+
}
469+
445470
// State returns string representation of issue status.
446471
func (issue *Issue) State() api.StateType {
447472
if issue.IsClosed {

services/markup/renderhelper_issueicontitle.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,6 @@ func renderRepoIssueIconTitle(ctx context.Context, opts markup.RenderIssueIconTi
5858
}
5959
}
6060

61-
htmlIcon, err := webCtx.RenderToHTML("shared/issueicon", issue)
62-
if err != nil {
63-
return "", err
64-
}
65-
66-
return htmlutil.HTMLFormat(`<a href="%s">%s %s %s</a>`, opts.LinkHref, htmlIcon, issue.Title, textIssueIndex), nil
61+
return htmlutil.HTMLFormat(`<a href="%s">%s %s %s</a>`, opts.LinkHref,
62+
issue.IconHTML(ctx), issue.Title, textIssueIndex), nil
6763
}

templates/repo/diff/compare.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@
187187
{{end}}
188188
{{if .HasPullRequest}}
189189
<div class="ui segment flex-text-block tw-gap-4">
190-
{{template "shared/issueicon" .}}
190+
{{.IconHTML ctx}}
191191
<div class="issue-title tw-break-anywhere">
192192
{{ctx.RenderUtils.RenderIssueTitle .PullRequest.Issue.Title $.Repository}}
193193
<span class="index">#{{.PullRequest.Issue.Index}}</span>

templates/repo/issue/card.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<div class="content tw-w-full">
1313
<div class="tw-flex tw-items-start tw-gap-[5px]">
1414
<div class="issue-card-icon">
15-
{{template "shared/issueicon" .}}
15+
{{.IconHTML ctx}}
1616
</div>
1717
<a class="issue-card-title muted issue-title tw-break-anywhere" href="{{.Link}}">{{.Title | ctx.RenderUtils.RenderIssueSimpleTitle}}</a>
1818
{{if and $.isPinnedIssueCard $.Page.IsRepoAdmin}}

templates/shared/issueicon.tmpl

Lines changed: 0 additions & 26 deletions
This file was deleted.

templates/shared/issuelist.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
{{if $.CanWriteIssuesOrPulls}}
88
<input type="checkbox" autocomplete="off" class="issue-checkbox tw-mr-4" data-issue-id={{.ID}} aria-label="{{ctx.Locale.Tr "repo.issues.action_check"}} &quot;{{.Title}}&quot;">
99
{{end}}
10-
{{template "shared/issueicon" .}}
10+
{{.IconHTML ctx}}
1111
</div>
1212

1313
<div class="flex-item-main">

templates/user/notification/notification_div.tmpl

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,7 @@
3737
{{range $notification := .Notifications}}
3838
<div class="notifications-item tw-flex tw-items-center tw-flex-wrap tw-gap-2 tw-p-2" id="notification_{{.ID}}" data-status="{{.Status}}">
3939
<div class="notifications-icon tw-ml-2 tw-mr-1 tw-self-start tw-mt-1">
40-
{{if .Issue}}
41-
{{template "shared/issueicon" .Issue}}
42-
{{else if .Release}}
43-
{{svg "octicon-tag" 16 "text grey"}}
44-
{{else if .Commit}}
45-
{{svg "octicon-git-commit" 16 "text grey"}}
46-
{{else}}
47-
{{svg "octicon-repo" 16 "text grey"}}
48-
{{end}}
40+
{{.IconHTML ctx}}
4941
</div>
5042
<a class="notifications-link tw-flex tw-flex-1 tw-flex-col silenced" href="{{.Link ctx}}">
5143
<div class="notifications-top-row tw-text-13 tw-break-anywhere">

web_src/js/features/issue.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type {Issue} from '../types.ts';
22

3-
// the getIssueIcon/getIssueColor logic should be kept the same as "templates/shared/issueicon.tmpl"
3+
// the getIssueIcon/getIssueColor logic should be kept the same as "models/activities/issue.IconHTML"
44

55
export function getIssueIcon(issue: Issue) {
66
if (issue.pull_request) {

0 commit comments

Comments
 (0)