From 08896cd9f657c3697af0ed2415a8461080a0eb0a Mon Sep 17 00:00:00 2001 From: silverwind Date: Mon, 7 Oct 2019 06:59:17 +0200 Subject: [PATCH] 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: https://github.com/go-gitea/gitea/issues/8170 --- options/locale/locale_en-US.ini | 1 + public/css/index.css | 5 +- public/less/_repository.less | 20 +++++++- routers/repo/view.go | 2 + templates/repo/view_file.tmpl | 84 +++++++++++++++++---------------- 5 files changed, 69 insertions(+), 43 deletions(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index c8be059b7..d9d27af26 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -681,6 +681,7 @@ stored_lfs = Stored with Git LFS commit_graph = Commit Graph blame = Blame normal_view = Normal View +lines = lines editor.new_file = New File editor.upload_file = Upload File diff --git a/public/css/index.css b/public/css/index.css index 496194dec..0efd78712 100644 --- a/public/css/index.css +++ b/public/css/index.css @@ -494,7 +494,7 @@ footer .ui.left,footer .ui.right{line-height:40px} .repository.file.list #repo-files-table tr:hover{background-color:#ffe} .repository.file.list #repo-files-table .jumpable-path{color:#888} .repository.file.list .non-diff-file-content .header .icon{font-size:1em} -.repository.file.list .non-diff-file-content .header .file-actions{margin-top:0;margin-bottom:-5px;padding-left:20px} +.repository.file.list .non-diff-file-content .header .file-actions{margin-bottom:-5px} .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} .repository.file.list .non-diff-file-content .header .file-actions .btn-octicon:hover{color:#4078c0} .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} .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} .repo-buttons .ui.labeled.button>.label{border-left:0!important;margin:0!important} .tag-code,.tag-code td{background-color:#f0f0f0!important;border-color:#d3cfcf!important;padding-top:8px;padding-bottom:8px} +.file-header{display:flex;justify-content:space-between;align-items:center;padding:8px 12px!important} +.file-info{display:flex;align-items:center} +.file-info-entry+.file-info-entry{border-left:1px solid currentColor;margin-left:8px;padding-left:8px} .CodeMirror{font:14px 'SF Mono',Consolas,Menlo,'Liberation Mono',Monaco,'Lucida Console',monospace} .CodeMirror.cm-s-default{border-radius:3px;padding:0!important} .CodeMirror .cm-comment{background:inherit!important} diff --git a/public/less/_repository.less b/public/less/_repository.less index ade3477cc..0527759ed 100644 --- a/public/less/_repository.less +++ b/public/less/_repository.less @@ -371,9 +371,7 @@ } .file-actions { - margin-top: 0; margin-bottom: -5px; - padding-left: 20px; .btn-octicon { display: inline-block; @@ -2385,3 +2383,21 @@ tbody.commit-list { padding-top: 8px; padding-bottom: 8px; } + +.file-header { + display: flex; + justify-content: space-between; + align-items: center; + padding: 8px 12px !important; +} + +.file-info { + display: flex; + align-items: center; +} + +.file-info-entry + .file-info-entry { + border-left: 1px solid currentColor; + margin-left: 8px; + padding-left: 8px; +} diff --git a/routers/repo/view.go b/routers/repo/view.go index 00790a4ef..1967b511c 100644 --- a/routers/repo/view.go +++ b/routers/repo/view.go @@ -304,6 +304,8 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st var output bytes.Buffer lines := strings.Split(fileContent, "\n") + ctx.Data["NumLines"] = len(lines) + //Remove blank line at the end of file if len(lines) > 0 && lines[len(lines)-1] == "" { lines = lines[:len(lines)-1] diff --git a/templates/repo/view_file.tmpl b/templates/repo/view_file.tmpl index 50e4c3394..71607bd1f 100644 --- a/templates/repo/view_file.tmpl +++ b/templates/repo/view_file.tmpl @@ -1,48 +1,52 @@
-

-
-
- {{if .ReadmeExist}} - - {{if .ReadmeInList}} - {{.FileName}} - {{else}} - {{.FileName}} {{FileSize .FileSize}}{{if .IsLFSFile}} ({{.i18n.Tr "repo.stored_lfs"}}){{end}} - {{end}} - {{else}} - - {{.FileName}} {{FileSize .FileSize}}{{if .IsLFSFile}} ({{.i18n.Tr "repo.stored_lfs"}}){{end}} - {{end}} -
-
- {{if not .ReadmeInList}} -
-
- {{.i18n.Tr "repo.file_raw"}} - {{if not .IsViewCommit}} - {{.i18n.Tr "repo.file_permalink"}} - {{end}} - {{if .IsTextFile}} - {{.i18n.Tr "repo.blame"}} - {{end}} - {{.i18n.Tr "repo.file_history"}} +

+
+ {{if .ReadmeInList}} + + {{.FileName}} + {{else}} +
+ {{if .NumLines}} +
+ {{.NumLines}} {{.i18n.Tr "repo.lines"}}
- {{if .Repository.CanEnableEditor}} - {{if .CanEditFile}} - - {{else}} - - {{end}} - {{if .CanDeleteFile}} - - {{else}} - - {{end}} - {{end}} -
+ {{end}} + {{if .FileSize}} +
+ {{FileSize .FileSize}}{{if .IsLFSFile}} ({{.i18n.Tr "repo.stored_lfs"}}){{end}} +
+ {{end}} +
+ {{end}} +

+ {{if not .ReadmeInList}} +
+
+
+ {{.i18n.Tr "repo.file_raw"}} + {{if not .IsViewCommit}} + {{.i18n.Tr "repo.file_permalink"}} + {{end}} + {{if .IsTextFile}} + {{.i18n.Tr "repo.blame"}} + {{end}} + {{.i18n.Tr "repo.file_history"}} +
+ {{if .Repository.CanEnableEditor}} + {{if .CanEditFile}} + + {{else}} + + {{end}} + {{if .CanDeleteFile}} + + {{else}} + + {{end}} {{end}}
+ {{end}}