From 563e8b4ea98e57adf3992dcaef76b86d29c13cec Mon Sep 17 00:00:00 2001 From: Alexey Makhov Date: Thu, 19 Feb 2015 00:52:22 +0300 Subject: [PATCH 1/2] gitlab-like hash naming --- modules/base/template.go | 5 +++++ public/ng/js/gogs.js | 20 ++++++++++---------- templates/repo/diff.tmpl | 6 +++--- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/modules/base/template.go b/modules/base/template.go index 0fd519e6c564..cfcabb71a20a 100644 --- a/modules/base/template.go +++ b/modules/base/template.go @@ -41,6 +41,10 @@ func List(l *list.List) chan interface{} { return c } +func Sha1(str string) string { + return EncodeSha1(str) +} + func ShortSha(sha1 string) string { if len(sha1) == 40 { return sha1[:10] @@ -160,6 +164,7 @@ var TemplateFuncs template.FuncMap = map[string]interface{}{ }, "DiffTypeToStr": DiffTypeToStr, "DiffLineTypeToStr": DiffLineTypeToStr, + "Sha1": Sha1, "ShortSha": ShortSha, "Md5": EncodeMd5, "ActionContent2Commits": ActionContent2Commits, diff --git a/public/ng/js/gogs.js b/public/ng/js/gogs.js index a6b9753e1775..bd320b4403ab 100644 --- a/public/ng/js/gogs.js +++ b/public/ng/js/gogs.js @@ -209,14 +209,14 @@ var Gogs = {}; $list.parents('tr').removeClass('end-selected-line'); $list.parents('tr').find('td').removeClass('selected-line'); if ($from) { - var expr = new RegExp(/diff-(\d+)L(\d+)/); + var expr = new RegExp(/diff-(\w+)([LR])(\d+)/); var selectMatches = $select.attr('rel').match(expr) var fromMatches = $from.attr('rel').match(expr) - var a = parseInt(selectMatches[2]); - var b = parseInt(fromMatches[2]); + var a = parseInt(selectMatches[3]); + var b = parseInt(fromMatches[3]); var linesIntToStr = {}; - linesIntToStr[a] = selectMatches[2]; - linesIntToStr[b] = fromMatches[2]; + linesIntToStr[a] = selectMatches[3]; + linesIntToStr[b] = fromMatches[3]; var c; if (a != b) { @@ -225,11 +225,11 @@ var Gogs = {}; a = b; b = c; } - $('[rel=diff-'+fromMatches[1]+'L' + linesIntToStr[b] + ']').parents('tr').next().addClass('end-selected-line'); - var $selectedLines = $('[rel=diff-'+fromMatches[1]+'L' + linesIntToStr[a] + ']').parents('tr').nextUntil('.end-selected-line').andSelf(); + $('[rel=diff-'+fromMatches[1] + fromMatches[2] + linesIntToStr[b] + ']').parents('tr').next().addClass('end-selected-line'); + var $selectedLines = $('[rel=diff-'+fromMatches[1]+selectMatches[2] + linesIntToStr[a] + ']').parents('tr').nextUntil('.end-selected-line').andSelf(); $selectedLines.find('td.lines-num > span').addClass('active') $selectedLines.find('td').addClass('selected-line'); - $.changeHash('#diff-'+fromMatches[1]+'L' + linesIntToStr[a] + '-L' + linesIntToStr[b]); + $.changeHash('#diff-'+fromMatches[1]+fromMatches[2] + linesIntToStr[a] + '-' + selectMatches[2] + + linesIntToStr[b]); return } } @@ -262,7 +262,7 @@ var Gogs = {}; }); $(window).on('hashchange', function (e) { - var m = window.location.hash.match(/^#diff-(\d+)(L\d+)\-(L\d+)$/); + var m = window.location.hash.match(/^#diff-(\w+)([LR]\d+)\-([LR]\d+)$/); var $list = $('.code-diff td.lines-num > span'); var $first; if (m) { @@ -271,7 +271,7 @@ var Gogs = {}; $("html, body").scrollTop($first.offset().top - 200); return; } - m = window.location.hash.match(/^#diff-(\d+)(L\d+)$/); + m = window.location.hash.match(/^#diff-(\w+)([LR]\d+)$/); if (m) { $first = $list.filter('[rel=diff-' + m[1] + m[2] + ']'); selectRange($list, $first); diff --git a/templates/repo/diff.tmpl b/templates/repo/diff.tmpl index 443e002d5951..2bc5c7d7d7d9 100644 --- a/templates/repo/diff.tmpl +++ b/templates/repo/diff.tmpl @@ -106,13 +106,13 @@ {{range $j, $section := $file.Sections}} - {{range $k, $line := $section.Lines}} + {{range $k, $line := $section.Lines}}
- {{if $line.LeftIdx}}{{$line.LeftIdx}}{{end}} + {{if $line.LeftIdx}}{{$line.LeftIdx}}{{end}} - {{if $line.RightIdx}}{{$line.RightIdx}}{{end}} + {{if $line.RightIdx}}{{$line.RightIdx}}{{end}} From c0ad512398e0d8232f5e729f2c38e887e6d9329a Mon Sep 17 00:00:00 2001 From: Alexey Makhov Date: Thu, 19 Feb 2015 00:55:17 +0300 Subject: [PATCH 2/2] remove not using vars --- templates/repo/diff.tmpl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/repo/diff.tmpl b/templates/repo/diff.tmpl index 2bc5c7d7d7d9..7da932a4f8e2 100644 --- a/templates/repo/diff.tmpl +++ b/templates/repo/diff.tmpl @@ -105,9 +105,9 @@ {{else}} - {{range $j, $section := $file.Sections}} - {{range $k, $line := $section.Lines}} - + {{range .Sections}} + {{range $k, $line := .Lines}} +
{{if $line.LeftIdx}}{{$line.LeftIdx}}{{end}}