Skip to content

Commit 1a4efa0

Browse files
yp05327lafriks
andauthored
Use project.IconName instead of repeated unreadable if-else chains (#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]>
1 parent 0206882 commit 1a4efa0

File tree

7 files changed

+24
-23
lines changed

7 files changed

+24
-23
lines changed

Diff for: models/project/project.go

+11
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,21 @@ func (p *Project) Link() string {
144144
return ""
145145
}
146146

147+
func (p *Project) IconName() string {
148+
if p.IsRepositoryProject() {
149+
return "octicon-project"
150+
}
151+
return "octicon-project-symlink"
152+
}
153+
147154
func (p *Project) IsOrganizationProject() bool {
148155
return p.Type == TypeOrganization
149156
}
150157

158+
func (p *Project) IsRepositoryProject() bool {
159+
return p.Type == TypeRepository
160+
}
161+
151162
func init() {
152163
db.RegisterModel(new(Project))
153164
}

Diff for: templates/projects/list.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
<div class="milestone list">
3939
{{range .Projects}}
4040
<li class="item">
41-
{{svg "octicon-project-symlink"}} <a href="{{.Link}}">{{.Title}}</a>
41+
{{svg .IconName}} <a href="{{.Link}}">{{.Title}}</a>
4242
<div class="meta">
4343
{{$closedDate:= TimeSinceUnix .ClosedDateUnix $.locale}}
4444
{{if .IsClosed}}

Diff for: templates/repo/issue/list.tmpl

+4-8
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,7 @@
100100
</div>
101101
{{range .OpenProjects}}
102102
<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}}">
103-
{{if .IsOrganizationProject}}{{svg "octicon-project-symlink" 18 "gt-mr-3"}}{{else}}{{svg "octicon-project" 18 "gt-mr-3"}}{{end}}
104-
{{.Title}}
103+
{{svg .IconName 18 "gt-mr-3"}}{{.Title}}
105104
</a>
106105
{{end}}
107106
{{end}}
@@ -112,8 +111,7 @@
112111
</div>
113112
{{range .ClosedProjects}}
114113
<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}}">
115-
{{if .IsOrganizationProject}}{{svg "octicon-project-symlink" 18 "gt-mr-3"}}{{else}}{{svg "octicon-project" 18 "gt-mr-3"}}{{end}}
116-
{{.Title}}
114+
{{svg .IconName 18 "gt-mr-3"}}{{.Title}}
117115
</a>
118116
{{end}}
119117
{{end}}
@@ -273,8 +271,7 @@
273271
</div>
274272
{{range .OpenProjects}}
275273
<div class="item issue-action" data-element-id="{{.ID}}" data-url="{{$.RepoLink}}/issues/projects">
276-
{{if .IsOrganizationProject}}{{svg "octicon-project-symlink" 18 "gt-mr-3"}}{{else}}{{svg "octicon-project" 18 "gt-mr-3"}}{{end}}
277-
{{.Title}}
274+
{{svg .IconName 18 "gt-mr-3"}}{{.Title}}
278275
</div>
279276
{{end}}
280277
{{end}}
@@ -285,8 +282,7 @@
285282
</div>
286283
{{range .ClosedProjects}}
287284
<div class="item issue-action" data-element-id="{{.ID}}" data-url="{{$.RepoLink}}/issues/projects">
288-
{{if .IsOrganizationProject}}{{svg "octicon-project-symlink" 18 "gt-mr-3"}}{{else}}{{svg "octicon-project" 18 "gt-mr-3"}}{{end}}
289-
{{.Title}}
285+
{{svg .IconName 18 "gt-mr-3"}}{{.Title}}
290286
</div>
291287
{{end}}
292288
{{end}}

Diff for: templates/repo/issue/new_form.tmpl

+3-6
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,7 @@
134134
</div>
135135
{{range .OpenProjects}}
136136
<a class="item muted sidebar-item-link" data-id="{{.ID}}" data-href="{{.Link}}">
137-
{{if .IsOrganizationProject}}{{svg "octicon-project-symlink" 18 "gt-mr-3"}}{{else}}{{svg "octicon-project" 18 "gt-mr-3"}}{{end}}
138-
{{.Title}}
137+
{{svg .IconName 18 "gt-mr-3"}}{{.Title}}
139138
</a>
140139
{{end}}
141140
{{end}}
@@ -146,8 +145,7 @@
146145
</div>
147146
{{range .ClosedProjects}}
148147
<a class="item muted sidebar-item-link" data-id="{{.ID}}" data-href="{{.Link}}">
149-
{{if .IsOrganizationProject}}{{svg "octicon-project-symlink" 18 "gt-mr-3"}}{{else}}{{svg "octicon-project" 18 "gt-mr-3"}}{{end}}
150-
{{.Title}}
148+
{{svg .IconName 18 "gt-mr-3"}}{{.Title}}
151149
</a>
152150
{{end}}
153151
{{end}}
@@ -159,8 +157,7 @@
159157
<div class="selected">
160158
{{if .Project}}
161159
<a class="item muted sidebar-item-link" href="{{.Project.Link}}">
162-
{{if .IsOrganizationProject}}{{svg "octicon-project-symlink" 18 "gt-mr-3"}}{{else}}{{svg "octicon-project" 18 "gt-mr-3"}}{{end}}
163-
{{.Project.Title}}
160+
{{svg .Project.IconName 18 "gt-mr-3"}}{{.Project.Title}}
164161
</a>
165162
{{end}}
166163
</div>

Diff for: templates/repo/issue/view_content/sidebar.tmpl

+3-6
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,7 @@
196196
</div>
197197
{{range .OpenProjects}}
198198
<a class="item muted sidebar-item-link" data-id="{{.ID}}" data-href="{{.Link}}">
199-
{{if .IsOrganizationProject}}{{svg "octicon-project-symlink" 18 "gt-mr-3"}}{{else}}{{svg "octicon-project" 18 "gt-mr-3"}}{{end}}
200-
{{.Title}}
199+
{{svg .IconName 18 "gt-mr-3"}}{{.Title}}
201200
</a>
202201
{{end}}
203202
{{end}}
@@ -208,8 +207,7 @@
208207
</div>
209208
{{range .ClosedProjects}}
210209
<a class="item muted sidebar-item-link" data-id="{{.ID}}" data-href="{{.Link}}">
211-
{{if .IsOrganizationProject}}{{svg "octicon-project-symlink" 18 "gt-mr-3"}}{{else}}{{svg "octicon-project" 18 "gt-mr-3"}}{{end}}
212-
{{.Title}}
210+
{{svg .IconName 18 "gt-mr-3"}}{{.Title}}
213211
</a>
214212
{{end}}
215213
{{end}}
@@ -220,8 +218,7 @@
220218
<div class="selected">
221219
{{if .Issue.ProjectID}}
222220
<a class="item muted sidebar-item-link" href="{{.Issue.Project.Link}}">
223-
{{if .IsOrganizationProject}}{{svg "octicon-project-symlink" 18 "gt-mr-3"}}{{else}}{{svg "octicon-project" 18 "gt-mr-3"}}{{end}}
224-
{{.Issue.Project.Title}}
221+
{{svg .Issue.Project.IconName 18 "gt-mr-3"}}{{.Issue.Project.Title}}
225222
</a>
226223
{{end}}
227224
</div>

Diff for: templates/repo/projects/list.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
<div class="milestone list">
4141
{{range .Projects}}
4242
<li class="item">
43-
{{svg "octicon-project"}} <a href="{{.Link}}">{{.Title}}</a>
43+
{{svg .IconName}} <a href="{{.Link}}">{{.Title}}</a>
4444
<div class="meta">
4545
{{$closedDate:= TimeSinceUnix .ClosedDateUnix $.locale}}
4646
{{if .IsClosed}}

Diff for: templates/shared/issuelist.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
{{end}}
8989
{{if .Project}}
9090
<a class="project" href="{{.Project.Link}}">
91-
{{if .Project.IsOrganizationProject}}{{svg "octicon-project-symlink" 14 "gt-mr-2"}}{{else}}{{svg "octicon-project" 14 "gt-mr-2"}}{{end}}{{.Project.Title}}
91+
{{svg .Project.IconName 14 "gt-mr-2"}}{{.Project.Title}}
9292
</a>
9393
{{end}}
9494
{{if .Ref}}

0 commit comments

Comments
 (0)