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>
pull/23550/head^2
yp05327 2 years ago committed by GitHub
parent 0206882e8a
commit 1a4efa0ee9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      models/project/project.go
  2. 2
      templates/projects/list.tmpl
  3. 12
      templates/repo/issue/list.tmpl
  4. 9
      templates/repo/issue/new_form.tmpl
  5. 9
      templates/repo/issue/view_content/sidebar.tmpl
  6. 2
      templates/repo/projects/list.tmpl
  7. 2
      templates/shared/issuelist.tmpl

@ -144,10 +144,21 @@ func (p *Project) Link() string {
return ""
}
func (p *Project) IconName() string {
if p.IsRepositoryProject() {
return "octicon-project"
}
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))
}

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

@ -100,8 +100,7 @@
</div>
{{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}}">
{{if .IsOrganizationProject}}{{svg "octicon-project-symlink" 18 "gt-mr-3"}}{{else}}{{svg "octicon-project" 18 "gt-mr-3"}}{{end}}
{{.Title}}
{{svg .IconName 18 "gt-mr-3"}}{{.Title}}
</a>
{{end}}
{{end}}
@ -112,8 +111,7 @@
</div>
{{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}}">
{{if .IsOrganizationProject}}{{svg "octicon-project-symlink" 18 "gt-mr-3"}}{{else}}{{svg "octicon-project" 18 "gt-mr-3"}}{{end}}
{{.Title}}
{{svg .IconName 18 "gt-mr-3"}}{{.Title}}
</a>
{{end}}
{{end}}
@ -273,8 +271,7 @@
</div>
{{range .OpenProjects}}
<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}}
{{.Title}}
{{svg .IconName 18 "gt-mr-3"}}{{.Title}}
</div>
{{end}}
{{end}}
@ -285,8 +282,7 @@
</div>
{{range .ClosedProjects}}
<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}}
{{.Title}}
{{svg .IconName 18 "gt-mr-3"}}{{.Title}}
</div>
{{end}}
{{end}}

@ -134,8 +134,7 @@
</div>
{{range .OpenProjects}}
<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}}
{{.Title}}
{{svg .IconName 18 "gt-mr-3"}}{{.Title}}
</a>
{{end}}
{{end}}
@ -146,8 +145,7 @@
</div>
{{range .ClosedProjects}}
<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}}
{{.Title}}
{{svg .IconName 18 "gt-mr-3"}}{{.Title}}
</a>
{{end}}
{{end}}
@ -159,8 +157,7 @@
<div class="selected">
{{if .Project}}
<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}}
{{.Project.Title}}
{{svg .Project.IconName 18 "gt-mr-3"}}{{.Project.Title}}
</a>
{{end}}
</div>

@ -196,8 +196,7 @@
</div>
{{range .OpenProjects}}
<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}}
{{.Title}}
{{svg .IconName 18 "gt-mr-3"}}{{.Title}}
</a>
{{end}}
{{end}}
@ -208,8 +207,7 @@
</div>
{{range .ClosedProjects}}
<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}}
{{.Title}}
{{svg .IconName 18 "gt-mr-3"}}{{.Title}}
</a>
{{end}}
{{end}}
@ -220,8 +218,7 @@
<div class="selected">
{{if .Issue.ProjectID}}
<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}}
{{.Issue.Project.Title}}
{{svg .Issue.Project.IconName 18 "gt-mr-3"}}{{.Issue.Project.Title}}
</a>
{{end}}
</div>

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

@ -88,7 +88,7 @@
{{end}}
{{if .Project}}
<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>
{{end}}
{{if .Ref}}

Loading…
Cancel
Save