Skip to content

Commit 08896cd

Browse files
silverwindtechknowlogick
authored andcommitted
add file line count info on UI (#8396)
Also reworked the header to remove the filename (which is redundant with the file path above) and made the header a flexbox with a monospace font. Fixes: #8170
1 parent 51fade4 commit 08896cd

File tree

5 files changed

+68
-42
lines changed

5 files changed

+68
-42
lines changed

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,7 @@ stored_lfs = Stored with Git LFS
681681
commit_graph = Commit Graph
682682
blame = Blame
683683
normal_view = Normal View
684+
lines = lines
684685
685686
editor.new_file = New File
686687
editor.upload_file = Upload File

public/css/index.css

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ footer .ui.left,footer .ui.right{line-height:40px}
494494
.repository.file.list #repo-files-table tr:hover{background-color:#ffe}
495495
.repository.file.list #repo-files-table .jumpable-path{color:#888}
496496
.repository.file.list .non-diff-file-content .header .icon{font-size:1em}
497-
.repository.file.list .non-diff-file-content .header .file-actions{margin-top:0;margin-bottom:-5px;padding-left:20px}
497+
.repository.file.list .non-diff-file-content .header .file-actions{margin-bottom:-5px}
498498
.repository.file.list .non-diff-file-content .header .file-actions .btn-octicon{display:inline-block;padding:5px;margin-left:5px;line-height:1;color:#767676;vertical-align:middle;background:0 0;border:0;outline:0}
499499
.repository.file.list .non-diff-file-content .header .file-actions .btn-octicon:hover{color:#4078c0}
500500
.repository.file.list .non-diff-file-content .header .file-actions .btn-octicon-danger:hover{color:#bd2c00}
@@ -878,6 +878,9 @@ tbody.commit-list{vertical-align:baseline}
878878
.repo-buttons .disabled-repo-button a.button:hover{background:0 0!important;color:rgba(0,0,0,.6)!important;box-shadow:0 0 0 1px rgba(34,36,38,.15) inset!important}
879879
.repo-buttons .ui.labeled.button>.label{border-left:0!important;margin:0!important}
880880
.tag-code,.tag-code td{background-color:#f0f0f0!important;border-color:#d3cfcf!important;padding-top:8px;padding-bottom:8px}
881+
.file-header{display:flex;justify-content:space-between;align-items:center;padding:8px 12px!important}
882+
.file-info{display:flex;align-items:center}
883+
.file-info-entry+.file-info-entry{border-left:1px solid currentColor;margin-left:8px;padding-left:8px}
881884
.CodeMirror{font:14px 'SF Mono',Consolas,Menlo,'Liberation Mono',Monaco,'Lucida Console',monospace}
882885
.CodeMirror.cm-s-default{border-radius:3px;padding:0!important}
883886
.CodeMirror .cm-comment{background:inherit!important}

public/less/_repository.less

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,9 +371,7 @@
371371
}
372372

373373
.file-actions {
374-
margin-top: 0;
375374
margin-bottom: -5px;
376-
padding-left: 20px;
377375

378376
.btn-octicon {
379377
display: inline-block;
@@ -2385,3 +2383,21 @@ tbody.commit-list {
23852383
padding-top: 8px;
23862384
padding-bottom: 8px;
23872385
}
2386+
2387+
.file-header {
2388+
display: flex;
2389+
justify-content: space-between;
2390+
align-items: center;
2391+
padding: 8px 12px !important;
2392+
}
2393+
2394+
.file-info {
2395+
display: flex;
2396+
align-items: center;
2397+
}
2398+
2399+
.file-info-entry + .file-info-entry {
2400+
border-left: 1px solid currentColor;
2401+
margin-left: 8px;
2402+
padding-left: 8px;
2403+
}

routers/repo/view.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,8 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
304304

305305
var output bytes.Buffer
306306
lines := strings.Split(fileContent, "\n")
307+
ctx.Data["NumLines"] = len(lines)
308+
307309
//Remove blank line at the end of file
308310
if len(lines) > 0 && lines[len(lines)-1] == "" {
309311
lines = lines[:len(lines)-1]

templates/repo/view_file.tmpl

Lines changed: 43 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,52 @@
11
<div class="{{TabSizeClass .Editorconfig .FileName}} non-diff-file-content">
2-
<h4 class="ui top attached header" id="{{if .ReadmeExist}}repo-readme{{else}}repo-read-file{{end}}">
3-
<div class="ui stackable grid">
4-
<div class="eight wide column">
5-
{{if .ReadmeExist}}
6-
<i class="book icon ui left"></i>
7-
{{if .ReadmeInList}}
8-
<strong>{{.FileName}}</strong>
9-
{{else}}
10-
<strong>{{.FileName}}</strong> <span class="text grey normal">{{FileSize .FileSize}}{{if .IsLFSFile}} ({{.i18n.Tr "repo.stored_lfs"}}){{end}}</span>
2+
<h4 class="file-header ui top attached header">
3+
<div class="file-header-left">
4+
{{if .ReadmeInList}}
5+
<i class="book icon"></i>
6+
<strong>{{.FileName}}</strong>
7+
{{else}}
8+
<div class="file-info text grey normal mono">
9+
{{if .NumLines}}
10+
<div class="file-info-entry">
11+
{{.NumLines}} {{.i18n.Tr "repo.lines"}}
12+
</div>
1113
{{end}}
12-
{{else}}
13-
<i class="file text outline icon ui left"></i>
14-
<strong>{{.FileName}}</strong> <span class="text grey normal">{{FileSize .FileSize}}{{if .IsLFSFile}} ({{.i18n.Tr "repo.stored_lfs"}}){{end}}</span>
15-
{{end}}
16-
</div>
17-
<div class="eight wide right aligned column">
18-
{{if not .ReadmeInList}}
19-
<div class="ui right file-actions">
20-
<div class="ui buttons">
21-
<a class="ui button" href="{{EscapePound $.RawFileLink}}">{{.i18n.Tr "repo.file_raw"}}</a>
22-
{{if not .IsViewCommit}}
23-
<a class="ui button" href="{{.RepoLink}}/src/commit/{{.CommitID}}/{{EscapePound .TreePath}}">{{.i18n.Tr "repo.file_permalink"}}</a>
24-
{{end}}
25-
{{if .IsTextFile}}
26-
<a class="ui button" href="{{.RepoLink}}/blame/{{EscapePound .BranchNameSubURL}}/{{EscapePound .TreePath}}">{{.i18n.Tr "repo.blame"}}</a>
27-
{{end}}
28-
<a class="ui button" href="{{.RepoLink}}/commits/{{EscapePound .BranchNameSubURL}}/{{EscapePound .TreePath}}">{{.i18n.Tr "repo.file_history"}}</a>
14+
{{if .FileSize}}
15+
<div class="file-info-entry">
16+
{{FileSize .FileSize}}{{if .IsLFSFile}} ({{.i18n.Tr "repo.stored_lfs"}}){{end}}
2917
</div>
30-
{{if .Repository.CanEnableEditor}}
31-
{{if .CanEditFile}}
32-
<a href="{{.RepoLink}}/_edit/{{EscapePound .BranchName}}/{{EscapePound .TreePath}}"><i class="octicon octicon-pencil btn-octicon poping up" data-content="{{.EditFileTooltip}}" data-position="bottom center" data-variation="tiny inverted"></i></a>
33-
{{else}}
34-
<i class="octicon octicon-pencil btn-octicon poping up disabled" data-content="{{.EditFileTooltip}}" data-position="bottom center" data-variation="tiny inverted"></i>
35-
{{end}}
36-
{{if .CanDeleteFile}}
37-
<a href="{{.RepoLink}}/_delete/{{EscapePound .BranchName}}/{{EscapePound .TreePath}}"><i class="octicon octicon-trashcan btn-octicon btn-octicon-danger poping up" data-content="{{.DeleteFileTooltip}}" data-position="bottom center" data-variation="tiny inverted"></i></a>
38-
{{else}}
39-
<i class="octicon octicon-trashcan btn-octicon poping up disabled" data-content="{{.DeleteFileTooltip}}" data-position="bottom center" data-variation="tiny inverted"></i>
40-
{{end}}
41-
{{end}}
42-
</div>
18+
{{end}}
19+
</div>
20+
{{end}}
21+
</div>
22+
{{if not .ReadmeInList}}
23+
<div class="file-header-right">
24+
<div class="ui right file-actions">
25+
<div class="ui buttons">
26+
<a class="ui button" href="{{EscapePound $.RawFileLink}}">{{.i18n.Tr "repo.file_raw"}}</a>
27+
{{if not .IsViewCommit}}
28+
<a class="ui button" href="{{.RepoLink}}/src/commit/{{.CommitID}}/{{EscapePound .TreePath}}">{{.i18n.Tr "repo.file_permalink"}}</a>
29+
{{end}}
30+
{{if .IsTextFile}}
31+
<a class="ui button" href="{{.RepoLink}}/blame/{{EscapePound .BranchNameSubURL}}/{{EscapePound .TreePath}}">{{.i18n.Tr "repo.blame"}}</a>
32+
{{end}}
33+
<a class="ui button" href="{{.RepoLink}}/commits/{{EscapePound .BranchNameSubURL}}/{{EscapePound .TreePath}}">{{.i18n.Tr "repo.file_history"}}</a>
34+
</div>
35+
{{if .Repository.CanEnableEditor}}
36+
{{if .CanEditFile}}
37+
<a href="{{.RepoLink}}/_edit/{{EscapePound .BranchName}}/{{EscapePound .TreePath}}"><i class="octicon octicon-pencil btn-octicon poping up" data-content="{{.EditFileTooltip}}" data-position="bottom center" data-variation="tiny inverted"></i></a>
38+
{{else}}
39+
<i class="octicon octicon-pencil btn-octicon poping up disabled" data-content="{{.EditFileTooltip}}" data-position="bottom center" data-variation="tiny inverted"></i>
40+
{{end}}
41+
{{if .CanDeleteFile}}
42+
<a href="{{.RepoLink}}/_delete/{{EscapePound .BranchName}}/{{EscapePound .TreePath}}"><i class="octicon octicon-trashcan btn-octicon btn-octicon-danger poping up" data-content="{{.DeleteFileTooltip}}" data-position="bottom center" data-variation="tiny inverted"></i></a>
43+
{{else}}
44+
<i class="octicon octicon-trashcan btn-octicon poping up disabled" data-content="{{.DeleteFileTooltip}}" data-position="bottom center" data-variation="tiny inverted"></i>
45+
{{end}}
4346
{{end}}
4447
</div>
4548
</div>
49+
{{end}}
4650
</h4>
4751
<div class="ui attached table unstackable segment">
4852
<div class="file-view {{if .IsMarkup}}{{.MarkupType}} markdown{{else if .IsRenderedHTML}}plain-text{{else if .IsTextFile}}code-view{{end}} has-emoji">

0 commit comments

Comments
 (0)