Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
wxiaoguang committed Apr 20, 2023
1 parent bad8f07 commit 7327a97
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 30 deletions.
17 changes: 0 additions & 17 deletions models/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@ package project
import (
"context"
"fmt"
"html"

"code.gitea.io/gitea/models/db"
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
"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"
Expand Down Expand Up @@ -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(`<span data-tooltip-content="%s"><b>%s</b></span>`, typeDispalyName, html.EscapeString(p.Title))
}

func init() {
db.RegisterModel(new(Project))
}
Expand Down
12 changes: 6 additions & 6 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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 <b>%s</b> milestone %s`
issues.add_project_at = `added this to the %s project %s`
issues.add_project_at = `added this to the <b>%s</b> project %s`
issues.change_milestone_at = `modified the milestone from <b>%s</b> to <b>%s</b> %s`
issues.change_project_at = `modified the project from %s to %s %s`
issues.change_project_at = `modified the project from <b>%s</b> to <b>%s</b> %s`
issues.remove_milestone_at = `removed this from the <b>%s</b> milestone %s`
issues.remove_project_at = `removed this from the %s project %s`
issues.remove_project_at = `removed this from the <b>%s</b> project %s`
issues.deleted_milestone = `(deleted)`
issues.deleted_project = `(deleted)`
issues.self_assign_at = `self-assigned this %s`
Expand Down Expand Up @@ -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
type-1.display_name = Individual Project
type-2.display_name = Repository Project
type-3.display_name = Organization Project
22 changes: 15 additions & 7 deletions templates/repo/issue/view_content/comments.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -732,14 +732,22 @@
{{template "shared/user/avatarlink" dict "Context" $.Context "user" .Poster}}
<span class="text grey muted-links">
{{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 `<span data-tooltip-content="%s">%s</span>` ($.locale.Tr $trKey | Escape) (.OldProject.Title | Escape)}}
{{end}}
{{$newProjectDisplayHtml := "Unknown Project"}}
{{if .Project}}
{{$trKey := printf "projects.type-%d.display_name" .Project.Type}}
{{$newProjectDisplayHtml = printf `<span data-tooltip-content="%s">%s</span>` ($.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}}
</span>
</div>
Expand Down

0 comments on commit 7327a97

Please sign in to comment.