Browse Source

new line naming style in comments

pull/946/head
Alexey Makhov 10 years ago
parent
commit
44952acc0f
  1. 13
      modules/base/template.go
  2. 13
      public/ng/js/gogs.js
  3. 2
      routers/repo/commit.go
  4. 5
      templates/repo/diff.tmpl

13
modules/base/template.go

@ -245,8 +245,17 @@ func DiffLineTypeToStr(diffType int) string {
return "same" return "same"
} }
func DiffLinePosToStr(file int, section int, line int) string { func DiffLinePosToStr(filepath string, leftIdx, rightIdx int) string {
return fmt.Sprintf("%vL%v%v", file + 1, section, line) var idx int;
var letter string;
if leftIdx > 0 {
idx = leftIdx
letter = "L"
} else {
idx = rightIdx
letter = "R"
}
return fmt.Sprintf("%v%v%v", Sha1(filepath), letter, idx)
} }
func Oauth2Icon(t int) string { func Oauth2Icon(t int) string {

13
public/ng/js/gogs.js

@ -262,8 +262,10 @@ var Gogs = {};
if ($(this).prop("tagName") == "BUTTON") { if ($(this).prop("tagName") == "BUTTON") {
lineNum = $(this).attr('rel'); lineNum = $(this).attr('rel');
} else { } else {
lineNum = $(this).parent().prev().find('span').attr('rel'); var span = $(this).parents('tr').find('span:not([rel=""])');
lineNum = span.first().attr('rel');
} }
console.log(lineNum);
$('button[rel='+lineNum+']').fadeOut(); $('button[rel='+lineNum+']').fadeOut();
lineNum = lineNum.substr(5); lineNum = lineNum.substr(5);
var commentTr = $(".comment-"+lineNum); var commentTr = $(".comment-"+lineNum);
@ -372,12 +374,9 @@ var Gogs = {};
} }
}); });
$('.code-diff .add-code .lines-code > pre, \ $('.code-diff .lines-code > pre, \
.code-diff .del-code .lines-code > pre, \ .code-diff .lines-code > b, \
.code-diff .add-code .lines-code > b, \ .code-diff .lines-num').hover(function () {
.code-diff .del-code .lines-code > b, \
.code-diff .add-code .lines-num, \
.code-diff .del-code .lines-num').hover(function () {
var $b = $(this).parents('tr').find('b'); var $b = $(this).parents('tr').find('b');
$b.addClass('ishovered'); $b.addClass('ishovered');
}); });

2
routers/repo/commit.go

@ -394,7 +394,7 @@ func CreateCommitComment(ctx *middleware.Context) {
switch ctx.Params(":action") { switch ctx.Params(":action") {
case "new": case "new":
line := ctx.Query("line") line := ctx.Query("line")
lineRe, err := regexp.Compile("[0-9]+L[0-9]+") lineRe, err := regexp.Compile("[a-zA-Z0-9]{40}[LR][0-9]+")
if len(line) > 0 && !lineRe.MatchString(line) { if len(line) > 0 && !lineRe.MatchString(line) {
err := errors.New("Something went wrong") err := errors.New("Something went wrong")
send(200, err.Error(), err) send(200, err.Error(), err)

5
templates/repo/diff.tmpl

@ -107,7 +107,6 @@
<tbody> <tbody>
{{range .Sections}} {{range .Sections}}
{{range $k, $line := .Lines}} {{range $k, $line := .Lines}}
{{$lineNum := (DiffLinePosToStr $file.Name $line.LeftIdx)}}
<tr class="{{DiffLineTypeToStr .Type}}-code nl-{{$k}} ol-{{$k}}"> <tr class="{{DiffLineTypeToStr .Type}}-code nl-{{$k}} ol-{{$k}}">
<td class="lines-num lines-num-old"> <td class="lines-num lines-num-old">
<span rel="{{if $line.LeftIdx}}diff-{{Sha1 $file.Name}}L{{$line.LeftIdx}}{{end}}">{{if $line.LeftIdx}}{{$line.LeftIdx}}{{end}}</span> <span rel="{{if $line.LeftIdx}}diff-{{Sha1 $file.Name}}L{{$line.LeftIdx}}{{end}}">{{if $line.LeftIdx}}{{$line.LeftIdx}}{{end}}</span>
@ -120,7 +119,8 @@
<pre>{{$line.Content}}</pre> <pre>{{$line.Content}}</pre>
</td> </td>
</tr> </tr>
{{if index $.Comments $lineNum}} {{$lineNum := (DiffLinePosToStr $file.Name $line.LeftIdx $line.RightIdx)}}
{{if index $.Comments $lineNum }}
<tr class="comment comment-{{$lineNum}}"> <tr class="comment comment-{{$lineNum}}">
<td class="lines-code" colspan="3"> <td class="lines-code" colspan="3">
{{range (index $.Comments $lineNum)}} {{range (index $.Comments $lineNum)}}
@ -162,6 +162,7 @@
</tr> </tr>
{{end}} {{end}}
{{end}} {{end}}
{{end}}
</tbody> </tbody>
</table> </table>
{{end}} {{end}}

Loading…
Cancel
Save