1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-12-21 00:33:10 +00:00

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 ""
}
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))
}

View file

@ -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}}

View file

@ -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}}

View file

@ -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>

View file

@ -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>

View file

@ -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}}

View file

@ -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}}