mirror of
https://github.com/go-gitea/gitea.git
synced 2025-08-14 08:30:53 +00:00
improvements
This commit is contained in:
parent
7a1cc340b8
commit
11bd0eaad4
@ -6,6 +6,7 @@ package activities
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
@ -16,6 +17,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/gitrepo"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/svg"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
|
||||
"xorm.io/builder"
|
||||
@ -379,6 +381,22 @@ func (n *Notification) Link(ctx context.Context) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (n *Notification) IconHTML(ctx context.Context) template.HTML {
|
||||
switch n.Source {
|
||||
case NotificationSourceIssue, NotificationSourcePullRequest:
|
||||
// n.Issue should be loaded before calling this method
|
||||
return n.Issue.IconHTML(ctx)
|
||||
case NotificationSourceCommit:
|
||||
return svg.RenderHTML("octicon-commit", 16, "text grey")
|
||||
case NotificationSourceRepository:
|
||||
return svg.RenderHTML("octicon-repo", 16, "text grey")
|
||||
case NotificationSourceRelease:
|
||||
return svg.RenderHTML("octicon-tag", 16, "text grey")
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
// APIURL formats a URL-string to the notification
|
||||
func (n *Notification) APIURL() string {
|
||||
return setting.AppURL + "api/v1/notifications/threads/" + strconv.FormatInt(n.ID, 10)
|
||||
|
@ -21,6 +21,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/optional"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/svg"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
|
||||
@ -442,6 +443,30 @@ func (issue *Issue) PatchURL() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
/* the logic should be kept the same as getIssueIcon/getIssueColor in TS code */
|
||||
func (issue *Issue) IconHTML(ctx context.Context) template.HTML {
|
||||
if issue.IsPull {
|
||||
if issue.PullRequest == nil { // pull request should be loaded before calling this function
|
||||
return template.HTML("No PullRequest")
|
||||
}
|
||||
if issue.IsClosed {
|
||||
if issue.PullRequest.HasMerged {
|
||||
return svg.RenderHTML("octicon-git-merge", 16, "text purple")
|
||||
}
|
||||
return svg.RenderHTML("octicon-git-pull-request-closed", 16, "text red")
|
||||
}
|
||||
if issue.PullRequest.IsWorkInProgress(ctx) {
|
||||
return svg.RenderHTML("octicon-git-pull-request-draft", 16, "text grey")
|
||||
}
|
||||
return svg.RenderHTML("octicon-git-pull-request", 16, "text green")
|
||||
}
|
||||
|
||||
if issue.IsClosed {
|
||||
return svg.RenderHTML("octicon-issue-closed", 16, "text red")
|
||||
}
|
||||
return svg.RenderHTML("octicon-issue-opened", 16, "text green")
|
||||
}
|
||||
|
||||
// State returns string representation of issue status.
|
||||
func (issue *Issue) State() api.StateType {
|
||||
if issue.IsClosed {
|
||||
|
@ -58,10 +58,6 @@ func renderRepoIssueIconTitle(ctx context.Context, opts markup.RenderIssueIconTi
|
||||
}
|
||||
}
|
||||
|
||||
htmlIcon, err := webCtx.RenderToHTML("shared/issueicon", issue)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return htmlutil.HTMLFormat(`<a href="%s">%s %s %s</a>`, opts.LinkHref, htmlIcon, issue.Title, textIssueIndex), nil
|
||||
return htmlutil.HTMLFormat(`<a href="%s">%s %s %s</a>`, opts.LinkHref,
|
||||
issue.IconHTML(ctx), issue.Title, textIssueIndex), nil
|
||||
}
|
||||
|
@ -187,7 +187,7 @@
|
||||
{{end}}
|
||||
{{if .HasPullRequest}}
|
||||
<div class="ui segment flex-text-block tw-gap-4">
|
||||
{{template "shared/issueicon" .}}
|
||||
{{.IconHTML ctx}}
|
||||
<div class="issue-title tw-break-anywhere">
|
||||
{{ctx.RenderUtils.RenderIssueTitle .PullRequest.Issue.Title $.Repository}}
|
||||
<span class="index">#{{.PullRequest.Issue.Index}}</span>
|
||||
|
@ -12,7 +12,7 @@
|
||||
<div class="content tw-w-full">
|
||||
<div class="tw-flex tw-items-start tw-gap-[5px]">
|
||||
<div class="issue-card-icon">
|
||||
{{template "shared/issueicon" .}}
|
||||
{{.IconHTML ctx}}
|
||||
</div>
|
||||
<a class="issue-card-title muted issue-title tw-break-anywhere" href="{{.Link}}">{{.Title | ctx.RenderUtils.RenderIssueSimpleTitle}}</a>
|
||||
{{if and $.isPinnedIssueCard $.Page.IsRepoAdmin}}
|
||||
|
@ -1,26 +0,0 @@
|
||||
{{/* the logic should be kept the same as getIssueIcon/getIssueColor in JS code */}}
|
||||
{{- if .IsPull -}}
|
||||
{{- if not .PullRequest -}}
|
||||
No PullRequest
|
||||
{{- else -}}
|
||||
{{- if .IsClosed -}}
|
||||
{{- if .PullRequest.HasMerged -}}
|
||||
{{- svg "octicon-git-merge" 16 "text purple" -}}
|
||||
{{- else -}}
|
||||
{{- svg "octicon-git-pull-request-closed" 16 "text red" -}}
|
||||
{{- end -}}
|
||||
{{- else -}}
|
||||
{{- if .PullRequest.IsWorkInProgress ctx -}}
|
||||
{{- svg "octicon-git-pull-request-draft" 16 "text grey" -}}
|
||||
{{- else -}}
|
||||
{{- svg "octicon-git-pull-request" 16 "text green" -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- else -}}
|
||||
{{- if .IsClosed -}}
|
||||
{{- svg "octicon-issue-closed" 16 "text red" -}}
|
||||
{{- else -}}
|
||||
{{- svg "octicon-issue-opened" 16 "text green" -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
@ -7,7 +7,7 @@
|
||||
{{if $.CanWriteIssuesOrPulls}}
|
||||
<input type="checkbox" autocomplete="off" class="issue-checkbox tw-mr-4" data-issue-id={{.ID}} aria-label="{{ctx.Locale.Tr "repo.issues.action_check"}} "{{.Title}}"">
|
||||
{{end}}
|
||||
{{template "shared/issueicon" .}}
|
||||
{{.IconHTML ctx}}
|
||||
</div>
|
||||
|
||||
<div class="flex-item-main">
|
||||
|
@ -37,15 +37,7 @@
|
||||
{{range $notification := .Notifications}}
|
||||
<div class="notifications-item tw-flex tw-items-center tw-flex-wrap tw-gap-2 tw-p-2" id="notification_{{.ID}}" data-status="{{.Status}}">
|
||||
<div class="notifications-icon tw-ml-2 tw-mr-1 tw-self-start tw-mt-1">
|
||||
{{if .Issue}}
|
||||
{{template "shared/issueicon" .Issue}}
|
||||
{{else if .Release}}
|
||||
{{svg "octicon-tag" 16 "text grey"}}
|
||||
{{else if .Commit}}
|
||||
{{svg "octicon-git-commit" 16 "text grey"}}
|
||||
{{else}}
|
||||
{{svg "octicon-repo" 16 "text grey"}}
|
||||
{{end}}
|
||||
{{.IconHTML ctx}}
|
||||
</div>
|
||||
<a class="notifications-link tw-flex tw-flex-1 tw-flex-col silenced" href="{{.Link ctx}}">
|
||||
<div class="notifications-top-row tw-text-13 tw-break-anywhere">
|
||||
|
@ -1,6 +1,6 @@
|
||||
import type {Issue} from '../types.ts';
|
||||
|
||||
// the getIssueIcon/getIssueColor logic should be kept the same as "templates/shared/issueicon.tmpl"
|
||||
// the getIssueIcon/getIssueColor logic should be kept the same as "models/activities/issue.IconHTML"
|
||||
|
||||
export function getIssueIcon(issue: Issue) {
|
||||
if (issue.pull_request) {
|
||||
|
Loading…
Reference in New Issue
Block a user