Skip to content

Commit 7327a97

Browse files
committed
refactor
1 parent bad8f07 commit 7327a97

File tree

3 files changed

+21
-30
lines changed

3 files changed

+21
-30
lines changed

models/project/project.go

-17
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@ package project
66
import (
77
"context"
88
"fmt"
9-
"html"
109

1110
"code.gitea.io/gitea/models/db"
1211
repo_model "code.gitea.io/gitea/models/repo"
1312
user_model "code.gitea.io/gitea/models/user"
1413
"code.gitea.io/gitea/modules/log"
1514
"code.gitea.io/gitea/modules/setting"
1615
"code.gitea.io/gitea/modules/timeutil"
17-
"code.gitea.io/gitea/modules/translation"
1816
"code.gitea.io/gitea/modules/util"
1917

2018
"xorm.io/builder"
@@ -161,21 +159,6 @@ func (p *Project) IsRepositoryProject() bool {
161159
return p.Type == TypeRepository
162160
}
163161

164-
func (p *Project) DisplayTitleWithTooltip(locale translation.Locale) string {
165-
var typeDispalyName string
166-
switch p.Type {
167-
case TypeIndividual:
168-
typeDispalyName = locale.Tr("projects.type.individual.displayname")
169-
case TypeRepository:
170-
typeDispalyName = locale.Tr("projects.type.repository.displayname")
171-
case TypeOrganization:
172-
typeDispalyName = locale.Tr("projects.type.organization.displayname")
173-
default:
174-
typeDispalyName = fmt.Sprintf("Unknown project type id: %d", p.Type)
175-
}
176-
return fmt.Sprintf(`<span data-tooltip-content="%s"><b>%s</b></span>`, typeDispalyName, html.EscapeString(p.Title))
177-
}
178-
179162
func init() {
180163
db.RegisterModel(new(Project))
181164
}

options/locale/locale_en-US.ini

+6-6
Original file line numberDiff line numberDiff line change
@@ -1328,11 +1328,11 @@ issues.remove_label = removed the %s label %s
13281328
issues.remove_labels = removed the %s labels %s
13291329
issues.add_remove_labels = added %s and removed %s labels %s
13301330
issues.add_milestone_at = `added this to the <b>%s</b> milestone %s`
1331-
issues.add_project_at = `added this to the %s project %s`
1331+
issues.add_project_at = `added this to the <b>%s</b> project %s`
13321332
issues.change_milestone_at = `modified the milestone from <b>%s</b> to <b>%s</b> %s`
1333-
issues.change_project_at = `modified the project from %s to %s %s`
1333+
issues.change_project_at = `modified the project from <b>%s</b> to <b>%s</b> %s`
13341334
issues.remove_milestone_at = `removed this from the <b>%s</b> milestone %s`
1335-
issues.remove_project_at = `removed this from the %s project %s`
1335+
issues.remove_project_at = `removed this from the <b>%s</b> project %s`
13361336
issues.deleted_milestone = `(deleted)`
13371337
issues.deleted_project = `(deleted)`
13381338
issues.self_assign_at = `self-assigned this %s`
@@ -3416,6 +3416,6 @@ runs.no_matching_runner_helper = No matching runner: %s
34163416
need_approval_desc = Need approval to run workflows for fork pull request.
34173417
34183418
[projects]
3419-
type.individual.displayname = Individual Project
3420-
type.repository.displayname = Repository Project
3421-
type.organization.displayname = Organization Project
3419+
type-1.display_name = Individual Project
3420+
type-2.display_name = Repository Project
3421+
type-3.display_name = Organization Project

templates/repo/issue/view_content/comments.tmpl

+15-7
Original file line numberDiff line numberDiff line change
@@ -732,14 +732,22 @@
732732
{{template "shared/user/avatarlink" dict "Context" $.Context "user" .Poster}}
733733
<span class="text grey muted-links">
734734
{{template "shared/user/authorlink" .Poster}}
735-
{{if gt .OldProjectID 0}}
736-
{{if gt .ProjectID 0}}
737-
{{$.locale.Tr "repo.issues.change_project_at" (.OldProject.DisplayTitleWithTooltip $.locale) (.Project.DisplayTitleWithTooltip $.locale) $createdStr | Safe}}
738-
{{else}}
739-
{{$.locale.Tr "repo.issues.remove_project_at" (.OldProject.DisplayTitleWithTooltip $.locale) $createdStr | Safe}}
740-
{{end}}
735+
{{$oldProjectDisplayHtml := "Unknown Project"}}
736+
{{if .OldProject}}
737+
{{$trKey := printf "projects.type-%d.display_name" .OldProject.Type}}
738+
{{$oldProjectDisplayHtml = printf `<span data-tooltip-content="%s">%s</span>` ($.locale.Tr $trKey | Escape) (.OldProject.Title | Escape)}}
739+
{{end}}
740+
{{$newProjectDisplayHtml := "Unknown Project"}}
741+
{{if .Project}}
742+
{{$trKey := printf "projects.type-%d.display_name" .Project.Type}}
743+
{{$newProjectDisplayHtml = printf `<span data-tooltip-content="%s">%s</span>` ($.locale.Tr $trKey | Escape) (.Project.Title | Escape)}}
744+
{{end}}
745+
{{if and (gt .OldProjectID 0) (gt .ProjectID 0)}}
746+
{{$.locale.Tr "repo.issues.change_project_at" $oldProjectDisplayHtml $newProjectDisplayHtml $createdStr | Safe}}
747+
{{else if gt .OldProjectID 0}}
748+
{{$.locale.Tr "repo.issues.remove_project_at" $oldProjectDisplayHtml $createdStr | Safe}}
741749
{{else if gt .ProjectID 0}}
742-
{{$.locale.Tr "repo.issues.add_project_at" (.Project.DisplayTitleWithTooltip $.locale) $createdStr | Safe}}
750+
{{$.locale.Tr "repo.issues.add_project_at" $newProjectDisplayHtml $createdStr | Safe}}
743751
{{end}}
744752
</span>
745753
</div>

0 commit comments

Comments
 (0)