feat(UI): add links to icons in repository file list

This commit is contained in:
Robert Wolff 2024-08-01 13:32:01 +02:00
parent 3d3ddd7704
commit b7f2739dfe
2 changed files with 14 additions and 15 deletions

View file

@ -14,7 +14,7 @@
<tbody>
{{if .HasParentPath}}
<tr class="has-parent">
<td colspan="3">{{svg "octicon-reply"}}<a class="muted" href="{{.BranchLink}}{{if .ParentPath}}{{PathEscapeSegments .ParentPath}}{{end}}">..</a></td>
<td colspan="3"><a class="muted" href="{{.BranchLink}}{{if .ParentPath}}{{PathEscapeSegments .ParentPath}}{{end}}">{{svg "octicon-reply" 16 "tw-mr-2"}}..</a></td>
</tr>
{{end}}
{{range $item := .Files}}
@ -25,30 +25,29 @@
<td class="name four wide">
<span class="truncate">
{{if $entry.IsSubModule}}
{{svg "octicon-file-submodule"}}
{{$refURL := $subModuleFile.RefURL AppUrl $.Repository.FullName $.SSHDomain}} {{/* FIXME: the usage of AppUrl seems incorrect, it would be fixed in the future, use AppSubUrl instead */}}
{{$icon := (svg "octicon-file-submodule" 16 "tw-mr-2")}}
{{if $refURL}}
<a class="muted" href="{{$refURL}}">{{$entry.Name}}</a><span class="at">@</span><a href="{{$refURL}}/commit/{{PathEscape $subModuleFile.RefID}}">{{ShortSha $subModuleFile.RefID}}</a>
<a class="muted" href="{{$refURL}}">{{$icon}}{{$entry.Name}}</a><span class="at">@</span><a href="{{$refURL}}/commit/{{PathEscape $subModuleFile.RefID}}">{{ShortSha $subModuleFile.RefID}}</a>
{{else}}
{{$entry.Name}}<span class="at">@</span>{{ShortSha $subModuleFile.RefID}}
{{$icon}}{{$entry.Name}}<span class="at">@</span>{{ShortSha $subModuleFile.RefID}}
{{end}}
{{else}}
{{if $entry.IsDir}}
{{$subJumpablePathName := $entry.GetSubJumpablePathName}}
{{svg "octicon-file-directory-fill"}}
<a class="muted" href="{{$.TreeLink}}/{{PathEscapeSegments $subJumpablePathName}}" title="{{$subJumpablePathName}}">
{{$subJumpablePathFields := StringUtils.Split $subJumpablePathName "/"}}
{{$subJumpablePathFieldLast := (Eval (len $subJumpablePathFields) "-" 1)}}
{{if eq $subJumpablePathFieldLast 0}}
{{svg "octicon-file-directory-fill" 16 "tw-mr-2" -}}
{{if eq $subJumpablePathFieldLast 0 -}}
{{$subJumpablePathName}}
{{else}}
{{$subJumpablePathPrefixes := slice $subJumpablePathFields 0 $subJumpablePathFieldLast}}
{{else -}}
{{$subJumpablePathPrefixes := slice $subJumpablePathFields 0 $subJumpablePathFieldLast -}}
<span class="text light-2">{{StringUtils.Join $subJumpablePathPrefixes "/"}}</span>/{{index $subJumpablePathFields $subJumpablePathFieldLast}}
{{end}}
</a>
{{else}}
{{svg (printf "octicon-%s" (EntryIcon $entry))}}
<a class="muted" href="{{$.TreeLink}}/{{PathEscapeSegments $entry.Name}}" title="{{$entry.Name}}">{{$entry.Name}}</a>
<a class="muted" href="{{$.TreeLink}}/{{PathEscapeSegments $entry.Name}}" title="{{$entry.Name}}">{{svg (printf "octicon-%s" (EntryIcon $entry)) 16 "tw-mr-2"}}{{$entry.Name}}</a>
{{end}}
{{end}}
</span>

View file

@ -181,11 +181,11 @@ func TestViewRepoWithSymlinks(t *testing.T) {
return fmt.Sprintf("%s: %s", file, cls)
})
assert.Len(t, items, 5)
assert.Equal(t, "a: svg octicon-file-directory-fill", items[0])
assert.Equal(t, "link_b: svg octicon-file-directory-symlink", items[1])
assert.Equal(t, "link_d: svg octicon-file-symlink-file", items[2])
assert.Equal(t, "link_hi: svg octicon-file-symlink-file", items[3])
assert.Equal(t, "link_link: svg octicon-file-symlink-file", items[4])
assert.Equal(t, "a: tw-mr-2 svg octicon-file-directory-fill", items[0])
assert.Equal(t, "link_b: tw-mr-2 svg octicon-file-directory-symlink", items[1])
assert.Equal(t, "link_d: tw-mr-2 svg octicon-file-symlink-file", items[2])
assert.Equal(t, "link_hi: tw-mr-2 svg octicon-file-symlink-file", items[3])
assert.Equal(t, "link_link: tw-mr-2 svg octicon-file-symlink-file", items[4])
}
// TestViewAsRepoAdmin tests PR #2167