Skip to content

Commit

Permalink
Use project.IconName instead of repeated unreadable if-else chains (
Browse files Browse the repository at this point in the history
#23538)

The project type will be changed in
#23353, so the old fix
#23325 will not work as well.

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

---------

Co-authored-by: Lauris BH <[email protected]>
  • Loading branch information
yp05327 and lafriks authored Mar 19, 2023
1 parent 0206882 commit 1a4efa0
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 23 deletions.
11 changes: 11 additions & 0 deletions models/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
2 changes: 1 addition & 1 deletion templates/projects/list.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down
12 changes: 4 additions & 8 deletions templates/repo/issue/list.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand All @@ -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}}
Expand Down Expand Up @@ -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}}
Expand All @@ -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}}
Expand Down
9 changes: 3 additions & 6 deletions templates/repo/issue/new_form.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand All @@ -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}}
Expand All @@ -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>
Expand Down
9 changes: 3 additions & 6 deletions templates/repo/issue/view_content/sidebar.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand All @@ -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}}
Expand All @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion templates/repo/projects/list.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down
2 changes: 1 addition & 1 deletion templates/shared/issuelist.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down

0 comments on commit 1a4efa0

Please sign in to comment.