From 95be5a687adece49d8b232cc5cdd7911a6c3e970 Mon Sep 17 00:00:00 2001 From: CirnoT <1447794+CirnoT@users.noreply.github.com> Date: Sun, 14 Jun 2020 18:58:33 +0200 Subject: [PATCH 1/2] Rework blame template and styling --- routers/repo/blame.go | 4 +- templates/repo/blame.tmpl | 88 +++++++++++++++++------------------ templates/repo/home.tmpl | 2 +- web_src/less/_base.less | 13 ++++-- web_src/less/_repository.less | 8 +++- 5 files changed, 62 insertions(+), 53 deletions(-) diff --git a/routers/repo/blame.go b/routers/repo/blame.go index 00ef9a99eae1f..4a9ce720fa98f 100644 --- a/routers/repo/blame.go +++ b/routers/repo/blame.go @@ -245,9 +245,9 @@ func renderBlame(ctx *context.Context, blameParts []git.BlamePart, commitNames m //Line number if len(part.Lines)-1 == index && len(blameParts)-1 != pi { - lineNumbers.WriteString(fmt.Sprintf(`%d`, i, i)) + lineNumbers.WriteString(fmt.Sprintf(``, i, i)) } else { - lineNumbers.WriteString(fmt.Sprintf(`%d`, i, i)) + lineNumbers.WriteString(fmt.Sprintf(``, i, i)) } //Code line diff --git a/templates/repo/blame.tmpl b/templates/repo/blame.tmpl index c2410e8c1d0d7..9ccad5b7e6655 100644 --- a/templates/repo/blame.tmpl +++ b/templates/repo/blame.tmpl @@ -1,51 +1,51 @@ -
- -

-
-
- - {{.FileName}} {{FileSize .FileSize}}{{if .IsLFSFile}} ({{.i18n.Tr "repo.stored_lfs"}}){{end}} +
+

+
+
+ {{if .NumLinesSet}} +
+ {{.NumLines}} {{.i18n.Tr (TrN .i18n.Lang .NumLines "repo.line" "repo.lines") }} +
+ {{end}} + {{if .FileSize}} +
+ {{FileSize .FileSize}}{{if .IsLFSFile}} ({{.i18n.Tr "repo.stored_lfs"}}){{end}} +
+ {{end}}
-
-
- - {{if .Repository.CanEnableEditor}} - {{if .CanEditFile}} - {{svg "octicon-pencil" 16}} - {{else}} - {{svg "octicon-pencil" 16}} - {{end}} - {{if .CanDeleteFile}} - {{svg "octicon-trashcan" 16}} - {{else}} - {{svg "octicon-trashcan" 16}} - {{end}} - {{end}} -
+
+ {{if not .ReadmeInList}} + + {{end}}

-
-
- - - - - - - - -
{{.BlameCommitInfo}}{{.BlameLineNums}}
    {{.BlameContent}}
-
+
+ {{if .FileSize}} + + + + {{if .IsFileTooLarge}} + + {{else}} + + + + {{end}} + + +
{{.i18n.Tr "repo.file_too_large"}}{{.BlameCommitInfo}}{{.BlameLineNums}}
    {{.BlameContent}}
+ {{end}} +
- -
diff --git a/templates/repo/home.tmpl b/templates/repo/home.tmpl index 3a0d364f34f5d..45f51819f8738 100644 --- a/templates/repo/home.tmpl +++ b/templates/repo/home.tmpl @@ -1,5 +1,5 @@ {{template "base/head" .}} -
+
{{template "repo/header" .}}
{{template "base/alert" .}} diff --git a/web_src/less/_base.less b/web_src/less/_base.less index b88b4a8a5581f..a80806ec20955 100644 --- a/web_src/less/_base.less +++ b/web_src/less/_base.less @@ -1069,7 +1069,6 @@ i.icons { } .lines-num { - vertical-align: top; text-align: right !important; color: #999999; background: #f5f5f5; @@ -1077,7 +1076,13 @@ i.icons { user-select: none; span { - &:before { + &.bottom-line { + &:after { + border-bottom: 1px solid #eaecef; + } + } + + &:after { content: attr(data-line-number); line-height: 20px !important; padding: 0 10px; @@ -1090,6 +1095,7 @@ i.icons { .lines-num, .lines-code { padding: 0 !important; + vertical-align: top; pre, ol, @@ -1101,7 +1107,7 @@ i.icons { li { display: block; width: calc(100% - 1ch); - margin-left: 1ch; + padding-left: 1ch; } } } @@ -1149,7 +1155,6 @@ i.icons { } } -.lines-num, .lines-code, .lines-commit { .bottom-line { diff --git a/web_src/less/_repository.less b/web_src/less/_repository.less index 0687347efdf46..c7258d18a664f 100644 --- a/web_src/less/_repository.less +++ b/web_src/less/_repository.less @@ -1,5 +1,4 @@ .repository { - padding-top: 15px; .repo-header { @@ -242,6 +241,12 @@ } &.file.list { + &.blame { + .ui.container:not(.flex) { + width: 98%; + } + } + .repo-description { display: flex; justify-content: space-between; @@ -1634,7 +1639,6 @@ width: 1%; min-width: 50px; user-select: none; - vertical-align: top; span.fold { display: block; From dea3a2a26d3932fbe63795857944e34b1fd376f3 Mon Sep 17 00:00:00 2001 From: CirnoT <1447794+CirnoT@users.noreply.github.com> Date: Sun, 14 Jun 2020 19:19:39 +0200 Subject: [PATCH 2/2] cleanup template and add missing NumLines --- routers/repo/blame.go | 26 ++++++------------------- templates/repo/blame.tmpl | 40 +++++++++++++-------------------------- 2 files changed, 19 insertions(+), 47 deletions(-) diff --git a/routers/repo/blame.go b/routers/repo/blame.go index 4a9ce720fa98f..d353f3b5dffe7 100644 --- a/routers/repo/blame.go +++ b/routers/repo/blame.go @@ -118,29 +118,15 @@ func RefBlame(ctx *context.Context) { ctx.Data["IsBlame"] = true - if ctx.Repo.CanEnableEditor() { - // Check LFS Lock - lfsLock, err := ctx.Repo.Repository.GetTreePathLock(ctx.Repo.TreePath) - if err != nil { - ctx.ServerError("GetTreePathLock", err) - return - } - if lfsLock != nil && lfsLock.OwnerID != ctx.User.ID { - ctx.Data["CanDeleteFile"] = false - ctx.Data["DeleteFileTooltip"] = ctx.Tr("repo.editor.this_file_locked") - } else { - ctx.Data["CanDeleteFile"] = true - ctx.Data["DeleteFileTooltip"] = ctx.Tr("repo.editor.delete_this_file") - } - } else if !ctx.Repo.IsViewBranch { - ctx.Data["DeleteFileTooltip"] = ctx.Tr("repo.editor.must_be_on_a_branch") - } else if !ctx.Repo.CanWrite(models.UnitTypeCode) { - ctx.Data["DeleteFileTooltip"] = ctx.Tr("repo.editor.must_have_write_access") - } - ctx.Data["FileSize"] = blob.Size() ctx.Data["FileName"] = blob.Name() + ctx.Data["NumLines"], err = blob.GetBlobLineCount() + if err != nil { + ctx.NotFound("GetBlobLineCount", err) + return + } + blameReader, err := git.CreateBlameReader(models.RepoPath(userName, repoName), commitID, fileName) if err != nil { ctx.NotFound("CreateBlameReader", err) diff --git a/templates/repo/blame.tmpl b/templates/repo/blame.tmpl index 9ccad5b7e6655..84e3e8c53e1b4 100644 --- a/templates/repo/blame.tmpl +++ b/templates/repo/blame.tmpl @@ -2,19 +2,12 @@

- {{if .NumLinesSet}} -
- {{.NumLines}} {{.i18n.Tr (TrN .i18n.Lang .NumLines "repo.line" "repo.lines") }} -
- {{end}} - {{if .FileSize}} -
- {{FileSize .FileSize}}{{if .IsLFSFile}} ({{.i18n.Tr "repo.stored_lfs"}}){{end}} -
- {{end}} +
+ {{.NumLines}} {{.i18n.Tr (TrN .i18n.Lang .NumLines "repo.line" "repo.lines") }} +
+
{{FileSize .FileSize}}
- {{if not .ReadmeInList}}
@@ -27,25 +20,18 @@
- {{end}}

- {{if .FileSize}} - - - - {{if .IsFileTooLarge}} - - {{else}} - - - - {{end}} - - -
{{.i18n.Tr "repo.file_too_large"}}{{.BlameCommitInfo}}{{.BlameLineNums}}
    {{.BlameContent}}
- {{end}} + + + + + + + + +
{{.BlameCommitInfo}}{{.BlameLineNums}}
    {{.BlameContent}}