Skip to content

Commit 092b7fd

Browse files
committed
improve repo/icon template, extract js function
1 parent a7e54b7 commit 092b7fd

File tree

8 files changed

+40
-53
lines changed

8 files changed

+40
-53
lines changed

routers/web/repo/view.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,6 @@ func Forks(ctx *context.Context) {
412412
}
413413

414414
pager := context.NewPagination(int(total), pageSize, page, 5)
415-
ctx.Data["ShowRepoOwnerAvatar"] = true
416415
ctx.Data["ShowRepoOwnerOnList"] = true
417416
ctx.Data["Page"] = pager
418417
ctx.Data["Repos"] = forks

templates/org/team/repositories.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
{{range $.TeamRepos}}
3131
<div class="flex-item tw-items-center">
3232
<div class="flex-item-leading">
33-
{{template "repo/icon" .}}
33+
{{template "repo/icon" (dict "Repo" . "Size" 24)}}
3434
</div>
3535
<div class="flex-item-main">
3636
<a class="flex-item-title text primary" href="{{$.Org.HomeLink}}/{{.Name | PathEscape}}">

templates/repo/header.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<div class="repo-header">
55
<div class="flex-item tw-items-center">
66
<div class="flex-item-leading">
7-
{{template "repo/icon" .}}
7+
{{template "repo/icon" (dict "Repo" . "EnableRepoAvatar" "true" "Size" 24)}}
88
</div>
99
<div class="flex-item-main">
1010
<div class="flex-item-title tw-text-18">

templates/repo/icon.tmpl

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
1-
{{$avatarLink := (.RelAvatarLink ctx)}}
2-
{{if $avatarLink}}
3-
<img class="ui avatar tw-align-middle" src="{{$avatarLink}}" width="24" height="24" alt aria-hidden="true">
4-
{{else if $.IsMirror}}
5-
{{svg "octicon-mirror" 24}}
6-
{{else if $.IsFork}}
7-
{{svg "octicon-repo-forked" 24}}
8-
{{else if $.IsPrivate}}
9-
{{svg "octicon-repo-locked" 24}}
1+
{{/* Template Attributes:
2+
* Repo: The repo
3+
* EnableRepoAvatar: Enable repo avatars when non-nil
4+
* Size: Icon size in pixels, default is 16
5+
*
6+
* Note: Keep the icon logic in sync with web_src/js/utils/mappings.ts
7+
*/}}
8+
{{$size := or .Size 16}}
9+
{{$avatarLink := (.Repo.RelAvatarLink ctx)}}
10+
{{if and $avatarLink .EnableRepoAvatar}}
11+
<img class="ui avatar tw-align-middle" src="{{$avatarLink}}" width="{{$size}}" height="{{$size}}" alt aria-hidden="true">
12+
{{else if .Repo.IsMirror}}
13+
{{svg "octicon-mirror" $size}}
14+
{{else if .Repo.IsPrivate}}
15+
{{svg "octicon-repo-locked" $size}}
16+
{{else if .Repo.IsTemplate}}
17+
{{svg "octicon-repo-template" $size}}
18+
{{else if .Repo.IsFork}}
19+
{{svg "octicon-repo-forked" $size}}
1020
{{else}}
11-
{{svg "octicon-repo" 24}}
21+
{{svg "octicon-repo" $size}}
1222
{{end}}

templates/shared/repo/list.tmpl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22
{{range .Repos}}
33
<div class="flex-item">
44
<div class="flex-item-leading">
5-
{{if $.ShowRepoOwnerAvatar}}
6-
{{ctx.AvatarUtils.Avatar .Owner 24}}
7-
{{else}}
8-
{{template "repo/icon" .}}
9-
{{end}}
5+
{{template "repo/icon" (dict "Repo" . "Size" 24 "EnableRepoAvatar" "true")}}
106
</div>
117
<div class="flex-item-main">
128
<div class="flex-item-header">

templates/user/settings/repos.tmpl

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,7 @@
1212
<div class="item {{if not $repo}}tw-py-1{{end}}">{{/* if not repo, then there are "adapt" buttons, so the padding shouldn't be that default large*/}}
1313
<div class="content">
1414
{{if $repo}}
15-
{{if $repo.IsPrivate}}
16-
<span class="icon">{{svg "octicon-repo-locked"}}</span>
17-
{{else if $repo.IsFork}}
18-
<span class="icon">{{svg "octicon-repo-forked"}}</span>
19-
{{else if $repo.IsMirror}}
20-
<span class="icon">{{svg "octicon-mirror"}}</span>
21-
{{else if $repo.IsTemplate}}
22-
<span class="icon">{{svg "octicon-repo-template"}}</span>
23-
{{else}}
24-
<span class="icon">{{svg "octicon-repo"}}</span>
25-
{{end}}
15+
{{template "repo/icon" (dict "Repo" $repo "Size" 16)}}
2616
<a class="muted name" href="{{$repo.Link}}">{{$repo.OwnerName}}/{{$repo.Name}}</a>
2717
<span class="text light-3" {{if not (eq $repo.Size 0)}} data-tooltip-content="{{$repo.SizeDetailsString}}"{{end}}>{{FileSize $repo.Size}}</span>
2818
{{if $repo.IsFork}}
@@ -85,17 +75,7 @@
8575
{{range .Repos}}
8676
<div class="item">
8777
<div class="content flex-text-block">
88-
{{if .IsPrivate}}
89-
{{svg "octicon-lock"}}
90-
{{else if .IsFork}}
91-
{{svg "octicon-repo-forked"}}
92-
{{else if .IsMirror}}
93-
{{svg "octicon-mirror"}}
94-
{{else if .IsTemplate}}
95-
{{svg "octicon-repo-template"}}
96-
{{else}}
97-
{{svg "octicon-repo"}}
98-
{{end}}
78+
{{template "repo/icon" (dict "Repo" . "Size" 16)}}
9979
<a class="name" href="{{.Link}}">{{.OwnerName}}/{{.Name}}</a>
10080
<span>{{FileSize .Size}}</span>
10181
{{if .IsFork}}

web_src/js/components/DashboardRepoList.vue

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {nextTick, defineComponent} from 'vue';
33
import {SvgIcon} from '../svg.ts';
44
import {GET} from '../modules/fetch.ts';
55
import {fomanticQuery} from '../modules/fomantic/base.ts';
6+
import {getRepoIcon} from '../utils/mappings.ts';
67
78
const {appSubUrl, assetUrlPrefix, pageData} = window.config;
89
@@ -283,19 +284,8 @@ export default defineComponent({
283284
}
284285
},
285286
286-
repoIcon(repo: any) {
287-
if (repo.fork) {
288-
return 'octicon-repo-forked';
289-
} else if (repo.mirror) {
290-
return 'octicon-mirror';
291-
} else if (repo.template) {
292-
return `octicon-repo-template`;
293-
} else if (repo.private) {
294-
return 'octicon-repo-locked';
295-
} else if (repo.internal) {
296-
return 'octicon-repo';
297-
}
298-
return 'octicon-repo';
287+
repoIcon(repo: Record<string, any>) {
288+
return getRepoIcon(repo);
299289
},
300290
301291
statusIcon(status: CommitStatus) {

web_src/js/utils/mappings.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export function getRepoIcon(repo: Record<string, any>) {
2+
if (repo.mirror) {
3+
return 'octicon-mirror';
4+
} else if (repo.fork) {
5+
return 'octicon-repo-forked';
6+
} else if (repo.private) {
7+
return 'octicon-repo-locked';
8+
} else if (repo.template) {
9+
return `octicon-repo-template`;
10+
}
11+
return 'octicon-repo';
12+
}

0 commit comments

Comments
 (0)