From ec6deb9e1dccd3474d2709e019836943b045f932 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Mon, 13 Mar 2023 07:15:05 +0000 Subject: [PATCH 1/8] add project icons to comments --- models/project/project.go | 12 ++++++++++++ options/locale/locale_en-US.ini | 6 +++--- templates/repo/issue/view_content/comments.tmpl | 6 +++--- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/models/project/project.go b/models/project/project.go index f3ed723030cdb..895d21cdce4eb 100644 --- a/models/project/project.go +++ b/models/project/project.go @@ -144,10 +144,22 @@ func (p *Project) Link() string { return "" } +func (p *Project) Icon() string { + if p.IsRepositoryProject() { + return "octicon-project" + } else { + return "octicon-project-symlink" + } +} + func (p *Project) IsOrganizationProject() bool { return p.Type == TypeOrganization } +func (p *Project) IsRepositoryProject() bool { + return p.Type == TypeRepository +} + func init() { db.RegisterModel(new(Project)) } diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 3695bd0384aa9..c129b5231ddf7 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1289,11 +1289,11 @@ issues.remove_label = removed the %s label %s issues.remove_labels = removed the %s labels %s issues.add_remove_labels = added %s and removed %s labels %s issues.add_milestone_at = `added this to the %s milestone %s` -issues.add_project_at = `added this to the %s project %s` +issues.add_project_at = `added this to the %s%s project %s` issues.change_milestone_at = `modified the milestone from %s to %s %s` -issues.change_project_at = `modified the project from %s to %s %s` +issues.change_project_at = `modified the project from %s%s to %s%s %s` issues.remove_milestone_at = `removed this from the %s milestone %s` -issues.remove_project_at = `removed this from the %s project %s` +issues.remove_project_at = `removed this from the %s%s project %s` issues.deleted_milestone = `(deleted)` issues.deleted_project = `(deleted)` issues.self_assign_at = `self-assigned this %s` diff --git a/templates/repo/issue/view_content/comments.tmpl b/templates/repo/issue/view_content/comments.tmpl index 9f2b7ec2d0cd1..1d4bd9117d09c 100644 --- a/templates/repo/issue/view_content/comments.tmpl +++ b/templates/repo/issue/view_content/comments.tmpl @@ -729,12 +729,12 @@ {{template "shared/user/authorlink" .Poster}} {{if gt .OldProjectID 0}} {{if gt .ProjectID 0}} - {{$.locale.Tr "repo.issues.change_project_at" (.OldProject.Title|Escape) (.Project.Title|Escape) $createdStr | Safe}} + {{$.locale.Tr "repo.issues.change_project_at" (svg .OldProject.Icon 16 "gt-mr-2") (.OldProject.Title|Escape) (svg .Project.Icon 16 "gt-mr-2") (.Project.Title|Escape) $createdStr | Safe}} {{else}} - {{$.locale.Tr "repo.issues.remove_project_at" (.OldProject.Title|Escape) $createdStr | Safe}} + {{$.locale.Tr "repo.issues.remove_project_at" (svg .OldProject.Icon 16 "gt-mr-2") (.OldProject.Title|Escape) $createdStr | Safe}} {{end}} {{else if gt .ProjectID 0}} - {{$.locale.Tr "repo.issues.add_project_at" (.Project.Title|Escape) $createdStr | Safe}} + {{$.locale.Tr "repo.issues.add_project_at" (svg .Project.Icon 16 "gt-mr-2") (.Project.Title|Escape) $createdStr | Safe}} {{end}} From 1de990756b930c53202b312e356069ba49181785 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Mon, 13 Mar 2023 07:18:56 +0000 Subject: [PATCH 2/8] improve project icons --- templates/projects/list.tmpl | 2 +- templates/repo/issue/list.tmpl | 8 ++++---- templates/repo/issue/new_form.tmpl | 6 +++--- templates/repo/issue/view_content/sidebar.tmpl | 6 +++--- templates/shared/issuelist.tmpl | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/templates/projects/list.tmpl b/templates/projects/list.tmpl index 489189ec45a1c..d7e90835e88c3 100644 --- a/templates/projects/list.tmpl +++ b/templates/projects/list.tmpl @@ -38,7 +38,7 @@
{{range .Projects}}
  • - {{svg "octicon-project-symlink"}} {{.Title}} + {{svg .Icon}} {{.Title}}
    {{$closedDate:= TimeSinceUnix .ClosedDateUnix $.locale}} {{if .IsClosed}} diff --git a/templates/repo/issue/list.tmpl b/templates/repo/issue/list.tmpl index ca05264e77b62..b785566ee0774 100644 --- a/templates/repo/issue/list.tmpl +++ b/templates/repo/issue/list.tmpl @@ -100,7 +100,7 @@
    {{range .OpenProjects}} - {{if .IsOrganizationProject}}{{svg "octicon-project-symlink" 18 "gt-mr-3"}}{{else}}{{svg "octicon-project" 18 "gt-mr-3"}}{{end}} + {{svg .Icon 18 "gt-mr-3"}} {{.Title}} {{end}} @@ -112,7 +112,7 @@
  • {{range .ClosedProjects}} - {{if .IsOrganizationProject}}{{svg "octicon-project-symlink" 18 "gt-mr-3"}}{{else}}{{svg "octicon-project" 18 "gt-mr-3"}}{{end}} + {{svg .Icon 18 "gt-mr-3"}} {{.Title}} {{end}} @@ -273,7 +273,7 @@ {{range .OpenProjects}}
    - {{if .IsOrganizationProject}}{{svg "octicon-project-symlink" 18 "gt-mr-3"}}{{else}}{{svg "octicon-project" 18 "gt-mr-3"}}{{end}} + {{svg .Icon 18 "gt-mr-3"}} {{.Title}}
    {{end}} @@ -285,7 +285,7 @@ {{range .ClosedProjects}}
    - {{if .IsOrganizationProject}}{{svg "octicon-project-symlink" 18 "gt-mr-3"}}{{else}}{{svg "octicon-project" 18 "gt-mr-3"}}{{end}} + {{svg .Icon 18 "gt-mr-3"}} {{.Title}}
    {{end}} diff --git a/templates/repo/issue/new_form.tmpl b/templates/repo/issue/new_form.tmpl index 9fd6c99a5b3f0..2efd4aecb0681 100644 --- a/templates/repo/issue/new_form.tmpl +++ b/templates/repo/issue/new_form.tmpl @@ -177,7 +177,7 @@ {{range .OpenProjects}} - {{if .IsOrganizationProject}}{{svg "octicon-project-symlink" 18 "gt-mr-3"}}{{else}}{{svg "octicon-project" 18 "gt-mr-3"}}{{end}} + {{svg .Icon 18 "gt-mr-3"}} {{.Title}} {{end}} @@ -189,7 +189,7 @@ {{range .ClosedProjects}} - {{if .IsOrganizationProject}}{{svg "octicon-project-symlink" 18 "gt-mr-3"}}{{else}}{{svg "octicon-project" 18 "gt-mr-3"}}{{end}} + {{svg .Icon 18 "gt-mr-3"}} {{.Title}} {{end}} @@ -202,7 +202,7 @@
    {{if .Project}} - {{if .IsOrganizationProject}}{{svg "octicon-project-symlink" 18 "gt-mr-3"}}{{else}}{{svg "octicon-project" 18 "gt-mr-3"}}{{end}} + {{svg .Project.Icon 18 "gt-mr-3"}} {{.Project.Title}} {{end}} diff --git a/templates/repo/issue/view_content/sidebar.tmpl b/templates/repo/issue/view_content/sidebar.tmpl index 29bfac7c27ea2..170b83f62a435 100644 --- a/templates/repo/issue/view_content/sidebar.tmpl +++ b/templates/repo/issue/view_content/sidebar.tmpl @@ -239,7 +239,7 @@
    {{range .OpenProjects}} - {{if .IsOrganizationProject}}{{svg "octicon-project-symlink" 18 "gt-mr-3"}}{{else}}{{svg "octicon-project" 18 "gt-mr-3"}}{{end}} + {{svg .Icon 18 "gt-mr-3"}} {{.Title}} {{end}} @@ -251,7 +251,7 @@ {{range .ClosedProjects}} - {{if .IsOrganizationProject}}{{svg "octicon-project-symlink" 18 "gt-mr-3"}}{{else}}{{svg "octicon-project" 18 "gt-mr-3"}}{{end}} + {{svg .Icon 18 "gt-mr-3"}} {{.Title}} {{end}} @@ -263,7 +263,7 @@
    {{if .Issue.ProjectID}} - {{if .IsOrganizationProject}}{{svg "octicon-project-symlink" 18 "gt-mr-3"}}{{else}}{{svg "octicon-project" 18 "gt-mr-3"}}{{end}} + {{svg .Issue.Project.Icon 18 "gt-mr-3"}} {{.Issue.Project.Title}} {{end}} diff --git a/templates/shared/issuelist.tmpl b/templates/shared/issuelist.tmpl index 16bb3c1ec7fea..6ddb322a16f39 100644 --- a/templates/shared/issuelist.tmpl +++ b/templates/shared/issuelist.tmpl @@ -88,7 +88,7 @@ {{end}} {{if .Project}} - {{if .Project.IsOrganizationProject}}{{svg "octicon-project-symlink" 14 "gt-mr-2"}}{{else}}{{svg "octicon-project" 14 "gt-mr-2"}}{{end}}{{.Project.Title}} + {{svg .Project.Icon 14 "gt-mr-2"}}{{.Project.Title}} {{end}} {{if .Ref}} From 81635fcb88b39dd34cee4a03617011dd3619be37 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Mon, 13 Mar 2023 07:34:53 +0000 Subject: [PATCH 3/8] fix lint --- models/project/project.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/models/project/project.go b/models/project/project.go index 895d21cdce4eb..27cbd397f1de0 100644 --- a/models/project/project.go +++ b/models/project/project.go @@ -147,9 +147,8 @@ func (p *Project) Link() string { func (p *Project) Icon() string { if p.IsRepositoryProject() { return "octicon-project" - } else { - return "octicon-project-symlink" } + return "octicon-project-symlink" } func (p *Project) IsOrganizationProject() bool { From 47f09bd6ae4f8e4ccac610e8528cf11f14f05682 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Tue, 14 Mar 2023 00:29:37 +0000 Subject: [PATCH 4/8] rename project.icon to iconname --- models/project/project.go | 2 +- templates/projects/list.tmpl | 2 +- templates/repo/issue/list.tmpl | 8 ++++---- templates/repo/issue/new_form.tmpl | 6 +++--- templates/repo/issue/view_content/comments.tmpl | 6 +++--- templates/repo/issue/view_content/sidebar.tmpl | 6 +++--- templates/shared/issuelist.tmpl | 2 +- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/models/project/project.go b/models/project/project.go index 27cbd397f1de0..8699a4536a36c 100644 --- a/models/project/project.go +++ b/models/project/project.go @@ -144,7 +144,7 @@ func (p *Project) Link() string { return "" } -func (p *Project) Icon() string { +func (p *Project) IconName() string { if p.IsRepositoryProject() { return "octicon-project" } diff --git a/templates/projects/list.tmpl b/templates/projects/list.tmpl index d7e90835e88c3..7f897e38cd284 100644 --- a/templates/projects/list.tmpl +++ b/templates/projects/list.tmpl @@ -38,7 +38,7 @@
    {{range .Projects}}
  • - {{svg .Icon}} {{.Title}} + {{svg .IconName}} {{.Title}}
    {{$closedDate:= TimeSinceUnix .ClosedDateUnix $.locale}} {{if .IsClosed}} diff --git a/templates/repo/issue/list.tmpl b/templates/repo/issue/list.tmpl index b785566ee0774..36e63ee5de72a 100644 --- a/templates/repo/issue/list.tmpl +++ b/templates/repo/issue/list.tmpl @@ -100,7 +100,7 @@
    {{range .OpenProjects}} - {{svg .Icon 18 "gt-mr-3"}} + {{svg .IconName 18 "gt-mr-3"}} {{.Title}} {{end}} @@ -112,7 +112,7 @@
  • {{range .ClosedProjects}} - {{svg .Icon 18 "gt-mr-3"}} + {{svg .IconName 18 "gt-mr-3"}} {{.Title}} {{end}} @@ -273,7 +273,7 @@
    {{range .OpenProjects}}
    - {{svg .Icon 18 "gt-mr-3"}} + {{svg .IconName 18 "gt-mr-3"}} {{.Title}}
    {{end}} @@ -285,7 +285,7 @@ {{range .ClosedProjects}}
    - {{svg .Icon 18 "gt-mr-3"}} + {{svg .IconName 18 "gt-mr-3"}} {{.Title}}
    {{end}} diff --git a/templates/repo/issue/new_form.tmpl b/templates/repo/issue/new_form.tmpl index 2efd4aecb0681..ab00a97fa1779 100644 --- a/templates/repo/issue/new_form.tmpl +++ b/templates/repo/issue/new_form.tmpl @@ -177,7 +177,7 @@ {{range .OpenProjects}} - {{svg .Icon 18 "gt-mr-3"}} + {{svg .IconName 18 "gt-mr-3"}} {{.Title}} {{end}} @@ -189,7 +189,7 @@ {{range .ClosedProjects}} - {{svg .Icon 18 "gt-mr-3"}} + {{svg .IconName 18 "gt-mr-3"}} {{.Title}} {{end}} @@ -202,7 +202,7 @@
    {{if .Project}} - {{svg .Project.Icon 18 "gt-mr-3"}} + {{svg .Project.IconName 18 "gt-mr-3"}} {{.Project.Title}} {{end}} diff --git a/templates/repo/issue/view_content/comments.tmpl b/templates/repo/issue/view_content/comments.tmpl index 1d4bd9117d09c..152c2bc6b77a0 100644 --- a/templates/repo/issue/view_content/comments.tmpl +++ b/templates/repo/issue/view_content/comments.tmpl @@ -729,12 +729,12 @@ {{template "shared/user/authorlink" .Poster}} {{if gt .OldProjectID 0}} {{if gt .ProjectID 0}} - {{$.locale.Tr "repo.issues.change_project_at" (svg .OldProject.Icon 16 "gt-mr-2") (.OldProject.Title|Escape) (svg .Project.Icon 16 "gt-mr-2") (.Project.Title|Escape) $createdStr | Safe}} + {{$.locale.Tr "repo.issues.change_project_at" (svg .OldProject.IconName 16 "gt-mr-2") (.OldProject.Title|Escape) (svg .Project.IconName 16 "gt-mr-2") (.Project.Title|Escape) $createdStr | Safe}} {{else}} - {{$.locale.Tr "repo.issues.remove_project_at" (svg .OldProject.Icon 16 "gt-mr-2") (.OldProject.Title|Escape) $createdStr | Safe}} + {{$.locale.Tr "repo.issues.remove_project_at" (svg .OldProject.IconName 16 "gt-mr-2") (.OldProject.Title|Escape) $createdStr | Safe}} {{end}} {{else if gt .ProjectID 0}} - {{$.locale.Tr "repo.issues.add_project_at" (svg .Project.Icon 16 "gt-mr-2") (.Project.Title|Escape) $createdStr | Safe}} + {{$.locale.Tr "repo.issues.add_project_at" (svg .Project.IconName 16 "gt-mr-2") (.Project.Title|Escape) $createdStr | Safe}} {{end}}
    diff --git a/templates/repo/issue/view_content/sidebar.tmpl b/templates/repo/issue/view_content/sidebar.tmpl index 170b83f62a435..e3e771101f18b 100644 --- a/templates/repo/issue/view_content/sidebar.tmpl +++ b/templates/repo/issue/view_content/sidebar.tmpl @@ -239,7 +239,7 @@ {{range .OpenProjects}} - {{svg .Icon 18 "gt-mr-3"}} + {{svg .IconName 18 "gt-mr-3"}} {{.Title}} {{end}} @@ -251,7 +251,7 @@ {{range .ClosedProjects}} - {{svg .Icon 18 "gt-mr-3"}} + {{svg .IconName 18 "gt-mr-3"}} {{.Title}} {{end}} @@ -263,7 +263,7 @@
    {{if .Issue.ProjectID}} - {{svg .Issue.Project.Icon 18 "gt-mr-3"}} + {{svg .Issue.Project.IconName 18 "gt-mr-3"}} {{.Issue.Project.Title}} {{end}} diff --git a/templates/shared/issuelist.tmpl b/templates/shared/issuelist.tmpl index 6ddb322a16f39..c07089246b865 100644 --- a/templates/shared/issuelist.tmpl +++ b/templates/shared/issuelist.tmpl @@ -88,7 +88,7 @@ {{end}} {{if .Project}} - {{svg .Project.Icon 14 "gt-mr-2"}}{{.Project.Title}} + {{svg .Project.IconName 14 "gt-mr-2"}}{{.Project.Title}} {{end}} {{if .Ref}} From 0757d69f27f50019ec1b1e58634751afbf4b9f5b Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Tue, 14 Mar 2023 07:12:59 +0000 Subject: [PATCH 5/8] use tooltips instead of icon --- models/project/project.go | 13 +++++++++++++ options/locale/locale_en-US.ini | 11 ++++++++--- templates/repo/issue/view_content/comments.tmpl | 6 +++--- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/models/project/project.go b/models/project/project.go index 8699a4536a36c..338adbcc4ff57 100644 --- a/models/project/project.go +++ b/models/project/project.go @@ -13,6 +13,7 @@ import ( "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/timeutil" + "code.gitea.io/gitea/modules/translation" "code.gitea.io/gitea/modules/util" "xorm.io/builder" @@ -46,6 +47,18 @@ const ( TypeOrganization ) +func (p Type) DisplayName(locale translation.Locale) string { + switch p { + case TypeIndividual: + return locale.Tr("projects.type.individual.displayname") + case TypeRepository: + return locale.Tr("projects.type.repository.displayname") + case TypeOrganization: + return locale.Tr("projects.type.organization.displayname") + } + return fmt.Sprintf("Unknown Type %d", p) +} + // ErrProjectNotExist represents a "ProjectNotExist" kind of error. type ErrProjectNotExist struct { ID int64 diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index c129b5231ddf7..9cad422c7ccd3 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1289,11 +1289,11 @@ issues.remove_label = removed the %s label %s issues.remove_labels = removed the %s labels %s issues.add_remove_labels = added %s and removed %s labels %s issues.add_milestone_at = `added this to the %s milestone %s` -issues.add_project_at = `added this to the %s%s project %s` +issues.add_project_at = `added this to the %s project %s` issues.change_milestone_at = `modified the milestone from %s to %s %s` -issues.change_project_at = `modified the project from %s%s to %s%s %s` +issues.change_project_at = `modified the project from %s to %s %s` issues.remove_milestone_at = `removed this from the %s milestone %s` -issues.remove_project_at = `removed this from the %s%s project %s` +issues.remove_project_at = `removed this from the %s project %s` issues.deleted_milestone = `(deleted)` issues.deleted_project = `(deleted)` issues.self_assign_at = `self-assigned this %s` @@ -3350,3 +3350,8 @@ runs.commit = Commit runs.pushed_by = Pushed by need_approval_desc = Need approval to run workflows for fork pull request. + +[projects] +type.individual.displayname = Individual Project +type.repository.displayname = Repository Project +type.organization.displayname = Organization Project \ No newline at end of file diff --git a/templates/repo/issue/view_content/comments.tmpl b/templates/repo/issue/view_content/comments.tmpl index 152c2bc6b77a0..1ba42ba521246 100644 --- a/templates/repo/issue/view_content/comments.tmpl +++ b/templates/repo/issue/view_content/comments.tmpl @@ -729,12 +729,12 @@ {{template "shared/user/authorlink" .Poster}} {{if gt .OldProjectID 0}} {{if gt .ProjectID 0}} - {{$.locale.Tr "repo.issues.change_project_at" (svg .OldProject.IconName 16 "gt-mr-2") (.OldProject.Title|Escape) (svg .Project.IconName 16 "gt-mr-2") (.Project.Title|Escape) $createdStr | Safe}} + {{$.locale.Tr "repo.issues.change_project_at" (.OldProject.Type.DisplayName $.locale) (.OldProject.Title|Escape) (.Project.Type.DisplayName $.locale) (.Project.Title|Escape) $createdStr | Safe}} {{else}} - {{$.locale.Tr "repo.issues.remove_project_at" (svg .OldProject.IconName 16 "gt-mr-2") (.OldProject.Title|Escape) $createdStr | Safe}} + {{$.locale.Tr "repo.issues.remove_project_at" (.OldProject.Type.DisplayName $.locale) (.OldProject.Title|Escape) $createdStr | Safe}} {{end}} {{else if gt .ProjectID 0}} - {{$.locale.Tr "repo.issues.add_project_at" (svg .Project.IconName 16 "gt-mr-2") (.Project.Title|Escape) $createdStr | Safe}} + {{$.locale.Tr "repo.issues.add_project_at" (.Project.Type.DisplayName $.locale) (.Project.Title|Escape) $createdStr | Safe}} {{end}}
    From c0d6f116376dddd847550fc6e63d92327e3cd8f4 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Fri, 14 Apr 2023 00:22:14 +0000 Subject: [PATCH 6/8] fix --- models/project/project.go | 27 ++++++++++--------- options/locale/locale_en-US.ini | 6 ++--- .../repo/issue/view_content/comments.tmpl | 6 ++--- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/models/project/project.go b/models/project/project.go index e92153065c53d..601be3f32c6bf 100644 --- a/models/project/project.go +++ b/models/project/project.go @@ -47,18 +47,6 @@ const ( TypeOrganization ) -func (p Type) DisplayName(locale translation.Locale) string { - switch p { - case TypeIndividual: - return locale.Tr("projects.type.individual.displayname") - case TypeRepository: - return locale.Tr("projects.type.repository.displayname") - case TypeOrganization: - return locale.Tr("projects.type.organization.displayname") - } - return fmt.Sprintf("Unknown Type %d", p) -} - // ErrProjectNotExist represents a "ProjectNotExist" kind of error. type ErrProjectNotExist struct { ID int64 @@ -172,6 +160,21 @@ func (p *Project) IsRepositoryProject() bool { return p.Type == TypeRepository } +func (p *Project) DisplayTitleWithTooltip(locale translation.Locale) string { + var typeDispalyName string + switch p.Type { + case TypeIndividual: + typeDispalyName = locale.Tr("projects.type.individual.displayname") + case TypeRepository: + typeDispalyName = locale.Tr("projects.type.repository.displayname") + case TypeOrganization: + typeDispalyName = locale.Tr("projects.type.organization.displayname") + default: + typeDispalyName = fmt.Sprintf("Unknown project type id: %d", p.Type) + } + return fmt.Sprintf(`%s`, typeDispalyName, p.Title) +} + func init() { db.RegisterModel(new(Project)) } diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index e13af5da542ca..e9d2a976c7082 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1320,11 +1320,11 @@ issues.remove_label = removed the %s label %s issues.remove_labels = removed the %s labels %s issues.add_remove_labels = added %s and removed %s labels %s issues.add_milestone_at = `added this to the %s milestone %s` -issues.add_project_at = `added this to the %s project %s` +issues.add_project_at = `added this to the %s project %s` issues.change_milestone_at = `modified the milestone from %s to %s %s` -issues.change_project_at = `modified the project from %s to %s %s` +issues.change_project_at = `modified the project from %s to %s %s` issues.remove_milestone_at = `removed this from the %s milestone %s` -issues.remove_project_at = `removed this from the %s project %s` +issues.remove_project_at = `removed this from the %s project %s` issues.deleted_milestone = `(deleted)` issues.deleted_project = `(deleted)` issues.self_assign_at = `self-assigned this %s` diff --git a/templates/repo/issue/view_content/comments.tmpl b/templates/repo/issue/view_content/comments.tmpl index 949027288bb17..09145cfb3c664 100644 --- a/templates/repo/issue/view_content/comments.tmpl +++ b/templates/repo/issue/view_content/comments.tmpl @@ -729,12 +729,12 @@ {{template "shared/user/authorlink" .Poster}} {{if gt .OldProjectID 0}} {{if gt .ProjectID 0}} - {{$.locale.Tr "repo.issues.change_project_at" (.OldProject.Type.DisplayName $.locale) (.OldProject.Title|Escape) (.Project.Type.DisplayName $.locale) (.Project.Title|Escape) $createdStr | Safe}} + {{$.locale.Tr "repo.issues.change_project_at" (.OldProject.DisplayTitleWithTooltip $.locale) (.Project.DisplayTitleWithTooltip $.locale) $createdStr | Safe}} {{else}} - {{$.locale.Tr "repo.issues.remove_project_at" (.OldProject.Type.DisplayName $.locale) (.OldProject.Title|Escape) $createdStr | Safe}} + {{$.locale.Tr "repo.issues.remove_project_at" (.OldProject.DisplayTitleWithTooltip $.locale) $createdStr | Safe}} {{end}} {{else if gt .ProjectID 0}} - {{$.locale.Tr "repo.issues.add_project_at" (.Project.Type.DisplayName $.locale) (.Project.Title|Escape) $createdStr | Safe}} + {{$.locale.Tr "repo.issues.add_project_at" (.Project.DisplayTitleWithTooltip $.locale) $createdStr | Safe}} {{end}} From 37c80ab837d36147a22e74b4fb61d091772d3322 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Fri, 14 Apr 2023 00:23:28 +0000 Subject: [PATCH 7/8] add escape --- models/project/project.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/models/project/project.go b/models/project/project.go index 601be3f32c6bf..e39c0568857cd 100644 --- a/models/project/project.go +++ b/models/project/project.go @@ -6,6 +6,7 @@ package project import ( "context" "fmt" + "html" "code.gitea.io/gitea/models/db" repo_model "code.gitea.io/gitea/models/repo" @@ -172,7 +173,7 @@ func (p *Project) DisplayTitleWithTooltip(locale translation.Locale) string { default: typeDispalyName = fmt.Sprintf("Unknown project type id: %d", p.Type) } - return fmt.Sprintf(`%s`, typeDispalyName, p.Title) + return fmt.Sprintf(`%s`, typeDispalyName, html.EscapeString(p.Title)) } func init() { From 7327a97f8321915b3d6a8ce8ccdc9c2e71ca34a0 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Thu, 20 Apr 2023 17:55:11 +0800 Subject: [PATCH 8/8] refactor --- models/project/project.go | 17 -------------- options/locale/locale_en-US.ini | 12 +++++----- .../repo/issue/view_content/comments.tmpl | 22 +++++++++++++------ 3 files changed, 21 insertions(+), 30 deletions(-) diff --git a/models/project/project.go b/models/project/project.go index e39c0568857cd..44609e60b2ea0 100644 --- a/models/project/project.go +++ b/models/project/project.go @@ -6,7 +6,6 @@ package project import ( "context" "fmt" - "html" "code.gitea.io/gitea/models/db" repo_model "code.gitea.io/gitea/models/repo" @@ -14,7 +13,6 @@ import ( "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/timeutil" - "code.gitea.io/gitea/modules/translation" "code.gitea.io/gitea/modules/util" "xorm.io/builder" @@ -161,21 +159,6 @@ func (p *Project) IsRepositoryProject() bool { return p.Type == TypeRepository } -func (p *Project) DisplayTitleWithTooltip(locale translation.Locale) string { - var typeDispalyName string - switch p.Type { - case TypeIndividual: - typeDispalyName = locale.Tr("projects.type.individual.displayname") - case TypeRepository: - typeDispalyName = locale.Tr("projects.type.repository.displayname") - case TypeOrganization: - typeDispalyName = locale.Tr("projects.type.organization.displayname") - default: - typeDispalyName = fmt.Sprintf("Unknown project type id: %d", p.Type) - } - return fmt.Sprintf(`%s`, typeDispalyName, html.EscapeString(p.Title)) -} - func init() { db.RegisterModel(new(Project)) } diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index b0d91232e5c58..c0e94d3b87903 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1328,11 +1328,11 @@ issues.remove_label = removed the %s label %s issues.remove_labels = removed the %s labels %s issues.add_remove_labels = added %s and removed %s labels %s issues.add_milestone_at = `added this to the %s milestone %s` -issues.add_project_at = `added this to the %s project %s` +issues.add_project_at = `added this to the %s project %s` issues.change_milestone_at = `modified the milestone from %s to %s %s` -issues.change_project_at = `modified the project from %s to %s %s` +issues.change_project_at = `modified the project from %s to %s %s` issues.remove_milestone_at = `removed this from the %s milestone %s` -issues.remove_project_at = `removed this from the %s project %s` +issues.remove_project_at = `removed this from the %s project %s` issues.deleted_milestone = `(deleted)` issues.deleted_project = `(deleted)` issues.self_assign_at = `self-assigned this %s` @@ -3416,6 +3416,6 @@ runs.no_matching_runner_helper = No matching runner: %s need_approval_desc = Need approval to run workflows for fork pull request. [projects] -type.individual.displayname = Individual Project -type.repository.displayname = Repository Project -type.organization.displayname = Organization Project \ No newline at end of file +type-1.display_name = Individual Project +type-2.display_name = Repository Project +type-3.display_name = Organization Project diff --git a/templates/repo/issue/view_content/comments.tmpl b/templates/repo/issue/view_content/comments.tmpl index 9e094551b931e..45077e91ba12e 100644 --- a/templates/repo/issue/view_content/comments.tmpl +++ b/templates/repo/issue/view_content/comments.tmpl @@ -732,14 +732,22 @@ {{template "shared/user/avatarlink" dict "Context" $.Context "user" .Poster}} {{template "shared/user/authorlink" .Poster}} - {{if gt .OldProjectID 0}} - {{if gt .ProjectID 0}} - {{$.locale.Tr "repo.issues.change_project_at" (.OldProject.DisplayTitleWithTooltip $.locale) (.Project.DisplayTitleWithTooltip $.locale) $createdStr | Safe}} - {{else}} - {{$.locale.Tr "repo.issues.remove_project_at" (.OldProject.DisplayTitleWithTooltip $.locale) $createdStr | Safe}} - {{end}} + {{$oldProjectDisplayHtml := "Unknown Project"}} + {{if .OldProject}} + {{$trKey := printf "projects.type-%d.display_name" .OldProject.Type}} + {{$oldProjectDisplayHtml = printf `%s` ($.locale.Tr $trKey | Escape) (.OldProject.Title | Escape)}} + {{end}} + {{$newProjectDisplayHtml := "Unknown Project"}} + {{if .Project}} + {{$trKey := printf "projects.type-%d.display_name" .Project.Type}} + {{$newProjectDisplayHtml = printf `%s` ($.locale.Tr $trKey | Escape) (.Project.Title | Escape)}} + {{end}} + {{if and (gt .OldProjectID 0) (gt .ProjectID 0)}} + {{$.locale.Tr "repo.issues.change_project_at" $oldProjectDisplayHtml $newProjectDisplayHtml $createdStr | Safe}} + {{else if gt .OldProjectID 0}} + {{$.locale.Tr "repo.issues.remove_project_at" $oldProjectDisplayHtml $createdStr | Safe}} {{else if gt .ProjectID 0}} - {{$.locale.Tr "repo.issues.add_project_at" (.Project.DisplayTitleWithTooltip $.locale) $createdStr | Safe}} + {{$.locale.Tr "repo.issues.add_project_at" $newProjectDisplayHtml $createdStr | Safe}} {{end}}