Use `project.IconName` instead of repeated unreadable `if-else` chains (#23538)

The project type will be changed in
https://github.com/go-gitea/gitea/pull/23353, so the old fix
https://github.com/go-gitea/gitea/pull/23325 will not work as well.

And I also found that there were some problems in the old fix....

---------

Co-authored-by: Lauris BH <lauris@nix.lv>
This commit is contained in:
yp05327 2023-03-19 21:44:48 +09:00 committed by GitHub
parent 0206882e8a
commit 1a4efa0ee9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 24 additions and 23 deletions

View File

@ -144,10 +144,21 @@ func (p *Project) Link() string {
return "" return ""
} }
func (p *Project) IconName() string {
if p.IsRepositoryProject() {
return "octicon-project"
}
return "octicon-project-symlink"
}
func (p *Project) IsOrganizationProject() bool { func (p *Project) IsOrganizationProject() bool {
return p.Type == TypeOrganization return p.Type == TypeOrganization
} }
func (p *Project) IsRepositoryProject() bool {
return p.Type == TypeRepository
}
func init() { func init() {
db.RegisterModel(new(Project)) db.RegisterModel(new(Project))
} }

View File

@ -38,7 +38,7 @@
<div class="milestone list"> <div class="milestone list">
{{range .Projects}} {{range .Projects}}
<li class="item"> <li class="item">
{{svg "octicon-project-symlink"}} <a href="{{.Link}}">{{.Title}}</a> {{svg .IconName}} <a href="{{.Link}}">{{.Title}}</a>
<div class="meta"> <div class="meta">
{{$closedDate:= TimeSinceUnix .ClosedDateUnix $.locale}} {{$closedDate:= TimeSinceUnix .ClosedDateUnix $.locale}}
{{if .IsClosed}} {{if .IsClosed}}

View File

@ -100,8 +100,7 @@
</div> </div>
{{range .OpenProjects}} {{range .OpenProjects}}
<a class="{{if $.ProjectID}}{{if eq $.ProjectID .ID}}active selected{{end}}{{end}} item" href="{{$.Link}}?type={{$.ViewType}}&sort={{$.SortType}}&state={{$.State}}&labels={{$.SelectLabels}}&milestone={{$.MilestoneID}}&project={{.ID}}&assignee={{$.AssigneeID}}&poster={{$.PosterID}}"> <a class="{{if $.ProjectID}}{{if eq $.ProjectID .ID}}active selected{{end}}{{end}} item" href="{{$.Link}}?type={{$.ViewType}}&sort={{$.SortType}}&state={{$.State}}&labels={{$.SelectLabels}}&milestone={{$.MilestoneID}}&project={{.ID}}&assignee={{$.AssigneeID}}&poster={{$.PosterID}}">
{{if .IsOrganizationProject}}{{svg "octicon-project-symlink" 18 "gt-mr-3"}}{{else}}{{svg "octicon-project" 18 "gt-mr-3"}}{{end}} {{svg .IconName 18 "gt-mr-3"}}{{.Title}}
{{.Title}}
</a> </a>
{{end}} {{end}}
{{end}} {{end}}
@ -112,8 +111,7 @@
</div> </div>
{{range .ClosedProjects}} {{range .ClosedProjects}}
<a class="{{if $.ProjectID}}{{if eq $.ProjectID .ID}}active selected{{end}}{{end}} item" href="{{$.Link}}?type={{$.ViewType}}&sort={{$.SortType}}&state={{$.State}}&labels={{$.SelectLabels}}&milestone={{$.MilestoneID}}&project={{.ID}}&assignee={{$.AssigneeID}}&poster={{$.PosterID}}"> <a class="{{if $.ProjectID}}{{if eq $.ProjectID .ID}}active selected{{end}}{{end}} item" href="{{$.Link}}?type={{$.ViewType}}&sort={{$.SortType}}&state={{$.State}}&labels={{$.SelectLabels}}&milestone={{$.MilestoneID}}&project={{.ID}}&assignee={{$.AssigneeID}}&poster={{$.PosterID}}">
{{if .IsOrganizationProject}}{{svg "octicon-project-symlink" 18 "gt-mr-3"}}{{else}}{{svg "octicon-project" 18 "gt-mr-3"}}{{end}} {{svg .IconName 18 "gt-mr-3"}}{{.Title}}
{{.Title}}
</a> </a>
{{end}} {{end}}
{{end}} {{end}}
@ -273,8 +271,7 @@
</div> </div>
{{range .OpenProjects}} {{range .OpenProjects}}
<div class="item issue-action" data-element-id="{{.ID}}" data-url="{{$.RepoLink}}/issues/projects"> <div class="item issue-action" data-element-id="{{.ID}}" data-url="{{$.RepoLink}}/issues/projects">
{{if .IsOrganizationProject}}{{svg "octicon-project-symlink" 18 "gt-mr-3"}}{{else}}{{svg "octicon-project" 18 "gt-mr-3"}}{{end}} {{svg .IconName 18 "gt-mr-3"}}{{.Title}}
{{.Title}}
</div> </div>
{{end}} {{end}}
{{end}} {{end}}
@ -285,8 +282,7 @@
</div> </div>
{{range .ClosedProjects}} {{range .ClosedProjects}}
<div class="item issue-action" data-element-id="{{.ID}}" data-url="{{$.RepoLink}}/issues/projects"> <div class="item issue-action" data-element-id="{{.ID}}" data-url="{{$.RepoLink}}/issues/projects">
{{if .IsOrganizationProject}}{{svg "octicon-project-symlink" 18 "gt-mr-3"}}{{else}}{{svg "octicon-project" 18 "gt-mr-3"}}{{end}} {{svg .IconName 18 "gt-mr-3"}}{{.Title}}
{{.Title}}
</div> </div>
{{end}} {{end}}
{{end}} {{end}}

View File

@ -134,8 +134,7 @@
</div> </div>
{{range .OpenProjects}} {{range .OpenProjects}}
<a class="item muted sidebar-item-link" data-id="{{.ID}}" data-href="{{.Link}}"> <a class="item muted sidebar-item-link" data-id="{{.ID}}" data-href="{{.Link}}">
{{if .IsOrganizationProject}}{{svg "octicon-project-symlink" 18 "gt-mr-3"}}{{else}}{{svg "octicon-project" 18 "gt-mr-3"}}{{end}} {{svg .IconName 18 "gt-mr-3"}}{{.Title}}
{{.Title}}
</a> </a>
{{end}} {{end}}
{{end}} {{end}}
@ -146,8 +145,7 @@
</div> </div>
{{range .ClosedProjects}} {{range .ClosedProjects}}
<a class="item muted sidebar-item-link" data-id="{{.ID}}" data-href="{{.Link}}"> <a class="item muted sidebar-item-link" data-id="{{.ID}}" data-href="{{.Link}}">
{{if .IsOrganizationProject}}{{svg "octicon-project-symlink" 18 "gt-mr-3"}}{{else}}{{svg "octicon-project" 18 "gt-mr-3"}}{{end}} {{svg .IconName 18 "gt-mr-3"}}{{.Title}}
{{.Title}}
</a> </a>
{{end}} {{end}}
{{end}} {{end}}
@ -159,8 +157,7 @@
<div class="selected"> <div class="selected">
{{if .Project}} {{if .Project}}
<a class="item muted sidebar-item-link" href="{{.Project.Link}}"> <a class="item muted sidebar-item-link" href="{{.Project.Link}}">
{{if .IsOrganizationProject}}{{svg "octicon-project-symlink" 18 "gt-mr-3"}}{{else}}{{svg "octicon-project" 18 "gt-mr-3"}}{{end}} {{svg .Project.IconName 18 "gt-mr-3"}}{{.Project.Title}}
{{.Project.Title}}
</a> </a>
{{end}} {{end}}
</div> </div>

View File

@ -196,8 +196,7 @@
</div> </div>
{{range .OpenProjects}} {{range .OpenProjects}}
<a class="item muted sidebar-item-link" data-id="{{.ID}}" data-href="{{.Link}}"> <a class="item muted sidebar-item-link" data-id="{{.ID}}" data-href="{{.Link}}">
{{if .IsOrganizationProject}}{{svg "octicon-project-symlink" 18 "gt-mr-3"}}{{else}}{{svg "octicon-project" 18 "gt-mr-3"}}{{end}} {{svg .IconName 18 "gt-mr-3"}}{{.Title}}
{{.Title}}
</a> </a>
{{end}} {{end}}
{{end}} {{end}}
@ -208,8 +207,7 @@
</div> </div>
{{range .ClosedProjects}} {{range .ClosedProjects}}
<a class="item muted sidebar-item-link" data-id="{{.ID}}" data-href="{{.Link}}"> <a class="item muted sidebar-item-link" data-id="{{.ID}}" data-href="{{.Link}}">
{{if .IsOrganizationProject}}{{svg "octicon-project-symlink" 18 "gt-mr-3"}}{{else}}{{svg "octicon-project" 18 "gt-mr-3"}}{{end}} {{svg .IconName 18 "gt-mr-3"}}{{.Title}}
{{.Title}}
</a> </a>
{{end}} {{end}}
{{end}} {{end}}
@ -220,8 +218,7 @@
<div class="selected"> <div class="selected">
{{if .Issue.ProjectID}} {{if .Issue.ProjectID}}
<a class="item muted sidebar-item-link" href="{{.Issue.Project.Link}}"> <a class="item muted sidebar-item-link" href="{{.Issue.Project.Link}}">
{{if .IsOrganizationProject}}{{svg "octicon-project-symlink" 18 "gt-mr-3"}}{{else}}{{svg "octicon-project" 18 "gt-mr-3"}}{{end}} {{svg .Issue.Project.IconName 18 "gt-mr-3"}}{{.Issue.Project.Title}}
{{.Issue.Project.Title}}
</a> </a>
{{end}} {{end}}
</div> </div>

View File

@ -40,7 +40,7 @@
<div class="milestone list"> <div class="milestone list">
{{range .Projects}} {{range .Projects}}
<li class="item"> <li class="item">
{{svg "octicon-project"}} <a href="{{.Link}}">{{.Title}}</a> {{svg .IconName}} <a href="{{.Link}}">{{.Title}}</a>
<div class="meta"> <div class="meta">
{{$closedDate:= TimeSinceUnix .ClosedDateUnix $.locale}} {{$closedDate:= TimeSinceUnix .ClosedDateUnix $.locale}}
{{if .IsClosed}} {{if .IsClosed}}

View File

@ -88,7 +88,7 @@
{{end}} {{end}}
{{if .Project}} {{if .Project}}
<a class="project" href="{{.Project.Link}}"> <a class="project" href="{{.Project.Link}}">
{{if .Project.IsOrganizationProject}}{{svg "octicon-project-symlink" 14 "gt-mr-2"}}{{else}}{{svg "octicon-project" 14 "gt-mr-2"}}{{end}}{{.Project.Title}} {{svg .Project.IconName 14 "gt-mr-2"}}{{.Project.Title}}
</a> </a>
{{end}} {{end}}
{{if .Ref}} {{if .Ref}}