finsih diff and compare

pull/197/head
Unknwon 9 years ago
parent aa65761d81
commit 4275b3720a
  1. 2
      public/css/gogs.min.css
  2. 19
      public/js/gogs.js
  3. 13
      public/less/_base.less
  4. 142
      public/less/_repository.less
  5. 2
      routers/repo/commit.go
  6. 2
      templates/repo/commits_table.tmpl
  7. 78
      templates/repo/diff.tmpl

File diff suppressed because one or more lines are too long

@ -339,6 +339,25 @@ function initRepository() {
}) })
} }
// Diff
if ($('.repository.diff').length > 0) {
$('.diff-detail-box .toggle.button').click(function () {
$($(this).data('target')).slideToggle(100);
})
var $counter = $('.diff-counter');
if ($counter.length < 1) {
return;
}
$counter.each(function (i, item) {
var $item = $(item);
var addLine = $item.find('span[data-line].add').data("line");
var delLine = $item.find('span[data-line].del').data("line");
var addPercent = parseFloat(addLine) / (parseFloat(addLine) + parseFloat(delLine)) * 100;
$item.find(".bar .add").css("width", addPercent + "%");
});
}
// Pull request // Pull request
if ($('.repository.compare.pull').length > 0) { if ($('.repository.compare.pull').length > 0) {
var $branch_dropdown = $('.choose.branch .dropdown') var $branch_dropdown = $('.choose.branch .dropdown')

@ -118,6 +118,19 @@ img {
border-color: #F0C36D; border-color: #F0C36D;
} }
} }
.info {
&.header {
background-color: #d9edf7!important;
border-color: #85c5e5;
}
&.segment {
border-color: #85c5e5;
}
}
.normal.header {
font-weight: normal;
}
.avatar.image { .avatar.image {
border-radius: 3px; border-radius: 3px;

@ -455,19 +455,149 @@
.author { .author {
min-width: 180px; min-width: 180px;
} }
.sha { .message span {
a { max-width: 500px;
}
.date {
width: 120px;
}
}
.sha.label {
font-family: Consolas, Menlo, Monaco, "Lucida Console", monospace; font-family: Consolas, Menlo, Monaco, "Lucida Console", monospace;
font-size: 14px; font-size: 14px;
padding: 6px 10px 4px 10px; padding: 6px 10px 4px 10px;
font-weight: normal; font-weight: normal;
} }
.diff-detail-box {
margin: 15px 0;
line-height: 30px;
ol {
clear: both;
padding-left: 0;
margin-top: 5px;
margin-bottom: 28px;
li {
list-style: none;
padding-bottom: 4px;
margin-bottom: 4px;
border-bottom: 1px dashed #DDD;
padding-left: 6px;
}
}
span.status{
display: inline-block;
width: 12px;
height: 12px;
margin-right: 8px;
vertical-align: middle;
&.modify {
background-color: #f0db88;
}
&.add {
background-color: #b4e2b4;
}
&.del {
background-color: #e9aeae;
}
&.rename {
background-color: #dad8ff;
}
}
}
.diff-box {
.count {
margin-right: 12px;
.bar {
background-color: #e75316;
height: 12px;
width: 40px;
display: inline-block;
margin: 2px 4px 0 4px;
vertical-align: text-top;
.add {
background-color: #77c64a;
height: 12px;
}
}
}
.file {
color: #888;
}
}
.diff-file-box {
.header {
border-bottom: 1px solid #d4d4d5!important;
}
.file-body.file-code {
.lines-num {
text-align: right;
color: #999;
background: #fafafa;
width: 1%;
}
.lines-num-old {
border-right: 1px solid #DDD;
}
}
.code-diff {
font-size: 13px;
td {
padding: 0;
border-top: none;
}
pre {
margin: 0;
}
.lines-num {
border-right: 1px solid #d4d4d5;
padding: 0 5px;
}
tbody {
tr {
&.tag-code {
td, pre {
background-color: #E0E0E0 !important;
border-color: #ADADAD!important;
}
// td.selected-line, td.selected-line pre {
// background-color: #ffffdd !important;
// }
}
// &.same-code {
// td.selected-line, td.selected-line pre {
// background-color: #ffffdd !important;
// }
// }
&.del-code {
td, pre {
background-color: #ffe2dd !important;
border-color: #e9aeae !important;
}
// td.selected-line, td.selected-line pre {
// background-color: #ffffdd !important;
// }
}
&.add-code {
td, pre {
background-color: #d1ffd6 !important;
border-color: #b4e2b4 !important;
}
// td.selected-line, td.selected-line pre {
// background-color: #ffffdd !important;
// }
}
&:hover {
td {
background-color: #FFF8D2 !important;
border-color: #F0DB88 !important;
}
pre {
background-color: transparent !important;
}
}
} }
.message span {
max-width: 500px;
} }
.date {
width: 120px;
} }
} }
} }

@ -189,7 +189,7 @@ func FileHistory(ctx *middleware.Context) {
} }
func Diff(ctx *middleware.Context) { func Diff(ctx *middleware.Context) {
ctx.Data["IsRepoToolbarCommits"] = true ctx.Data["PageIsDiff"] = true
userName := ctx.Repo.Owner.Name userName := ctx.Repo.Owner.Name
repoName := ctx.Repo.Repository.Name repoName := ctx.Repo.Repository.Name

@ -34,7 +34,7 @@
<img class="ui avatar image" src="{{AvatarLink .Author.Email}}" alt=""/>&nbsp;&nbsp;{{.Author.Name}} <img class="ui avatar image" src="{{AvatarLink .Author.Email}}" alt=""/>&nbsp;&nbsp;{{.Author.Name}}
{{end}} {{end}}
</td> </td>
<td class="sha"><a rel="nofollow" class="ui green label" href="{{AppSubUrl}}/{{$username}}/{{$reponame}}/commit/{{.Id}} ">{{SubStr .Id.String 0 10}} </a></td> <td class="sha"><a rel="nofollow" class="ui green sha label" href="{{AppSubUrl}}/{{$username}}/{{$reponame}}/commit/{{.Id}} ">{{SubStr .Id.String 0 10}} </a></td>
<td class="message"><span class="text truncate">{{RenderCommitMessage .Summary $.RepoLink}}</span></td> <td class="message"><span class="text truncate">{{RenderCommitMessage .Summary $.RepoLink}}</span></td>
<td class="date">{{TimeSince .Author.When $.Lang}}</td> <td class="date">{{TimeSince .Author.When $.Lang}}</td>
</tr> </tr>

@ -13,31 +13,36 @@
</div> </div>
{{template "repo/commits_table" .}} {{template "repo/commits_table" .}}
{{else}} {{else}}
<div class="panel panel-info panel-radius diff-head-box"> <h4 class="ui top attached info header">
<div class="panel-header"> {{RenderCommitMessage .Commit.Message $.RepoLink}}
<a class="pull-right btn btn-blue btn-header btn-medium btn-radius" rel="nofollow" href="{{EscapePound .SourcePath}}">{{.i18n.Tr "repo.diff.browse_source"}}</a> <div class="ui right">
<h4 class="commit-message">{{RenderCommitMessage .Commit.Message $.RepoLink}}</h4> <a class="ui blue tiny button" href="{{EscapePound .SourcePath}}">
{{.i18n.Tr "repo.diff.browse_source"}}
</a>
</div> </div>
<div class="panel-body"> </h4>
<span class="pull-right"> <div class="ui attached info segment">
<ul class="list-unstyled">
<li class="inline">{{.i18n.Tr "repo.diff.parent"}}</li>
{{range .Parents}}
<li class="inline"><a href="{{$.RepoLink}}/commit/{{.}}"><span class="label label-blue">{{ShortSha .}}</span></a></li>
{{end}}
<li class="inline">{{.i18n.Tr "repo.diff.commit"}} <span class="label label-blue">{{ShortSha .CommitId}}</span></li>
</ul>
</span>
<p class="author">
{{if .Author}} {{if .Author}}
<img class="avatar-30" src="{{.Author.AvatarLink}}" /> <img class="ui avatar image" src="{{.Author.AvatarLink}}" />
<a href="{{AppSubUrl}}/{{.Author.Name}}"><strong>{{.Commit.Author.Name}}</strong></a> <a href="{{.Author.HomeLink}}"><strong>{{.Commit.Author.Name}}</strong></a>
{{else}} {{else}}
<img class="avatar-30" src="{{AvatarLink .Commit.Author.Email}}" /> <img class="ui avatar image" src="{{AvatarLink .Commit.Author.Email}}" />
<strong>{{.Commit.Author.Name}}</strong> <strong>{{.Commit.Author.Name}}</strong>
{{end}} {{end}}
<span class="text-grey" id="authored-time">{{TimeSince .Commit.Author.When $.Lang}}</span> <span class="text grey" id="authored-time">{{TimeSince .Commit.Author.When $.Lang}}</span>
</p> <div class="ui right">
<div class="ui horizontal list">
<div class="item">
{{.i18n.Tr "repo.diff.parent"}}
</div>
<div class="item">
{{range .Parents}}
<a class="ui blue sha label" href="{{$.RepoLink}}/commit/{{.}}">{{ShortSha .}}</a>
{{end}}
</div>
<div class="item">{{.i18n.Tr "repo.diff.commit"}}</div>
<div class="item"><span class="ui blue sha label">{{ShortSha .CommitId}}</span></div>
</div>
</div> </div>
</div> </div>
{{end}} {{end}}
@ -46,12 +51,14 @@
<h4>{{.i18n.Tr "repo.diff.data_not_available"}}</h4> <h4>{{.i18n.Tr "repo.diff.data_not_available"}}</h4>
{{else}} {{else}}
<div class="diff-detail-box diff-box"> <div class="diff-detail-box diff-box">
<a class="pull-right btn btn-gray btn-header btn-radius text-black" data-target="#diff-files">{{.i18n.Tr "repo.diff.show_diff_stats"}}</a> <div>
<p class="showing">
<i class="fa fa-retweet"></i> <i class="fa fa-retweet"></i>
{{.i18n.Tr "repo.diff.stats_desc" .Diff.NumFiles .Diff.TotalAddition .Diff.TotalDeletion | Str2html}} {{.i18n.Tr "repo.diff.stats_desc" .Diff.NumFiles .Diff.TotalAddition .Diff.TotalDeletion | Str2html}}
</p> <div class="ui right">
<ol class="detail-files collapse hide" id="diff-files"> <a class="ui tiny basic black toggle button" data-target="#diff-files">{{.i18n.Tr "repo.diff.show_diff_stats"}}</a>
</div>
</div>
<ol class="detail-files hide" id="diff-files">
{{range .Diff.Files}} {{range .Diff.Files}}
<li> <li>
<div class="diff-counter count pull-right"> <div class="diff-counter count pull-right">
@ -67,7 +74,7 @@
{{end}} {{end}}
</div> </div>
<!-- todo finish all file status, now modify, add, delete and rename --> <!-- todo finish all file status, now modify, add, delete and rename -->
<span class="status {{DiffTypeToStr .Type}}" data-toggle="tooltip" data-placement="right" title="{{DiffTypeToStr .Type}}">&nbsp;</span> <span class="status {{DiffTypeToStr .Type}} poping up" data-content="{{DiffTypeToStr .Type}}" data-variation="inverted tiny" data-position="right center">&nbsp;</span>
<a class="file" href="#diff-{{.Index}}">{{.Name}}</a> <a class="file" href="#diff-{{.Index}}">{{.Name}}</a>
</li> </li>
{{end}} {{end}}
@ -75,9 +82,9 @@
</div> </div>
{{range $i, $file := .Diff.Files}} {{range $i, $file := .Diff.Files}}
<div class="panel panel-radius diff-file-box diff-box file-content" id="diff-{{.Index}}"> <div class="diff-file-box diff-box file-content" id="diff-{{.Index}}">
<div class="panel-header"> <h4 class="ui top attached normal header">
<div class="diff-counter count pull-left"> <div class="diff-counter count ui left">
{{if not $file.IsBin}} {{if not $file.IsBin}}
<span class="add" data-line="{{.Addition}}">+ {{.Addition}}</span> <span class="add" data-line="{{.Addition}}">+ {{.Addition}}</span>
<span class="bar"> <span class="bar">
@ -89,20 +96,23 @@
{{$.i18n.Tr "repo.diff.bin"}} {{$.i18n.Tr "repo.diff.bin"}}
{{end}} {{end}}
</div> </div>
<span class="file">{{$file.Name}}</span>
<div class="ui right">
{{if $file.IsDeleted}} {{if $file.IsDeleted}}
<a class="btn btn-gray btn-header btn-radius text-black pull-right" rel="nofollow" href="{{EscapePound $.BeforeSourcePath}}/{{EscapePound .Name}}">{{$.i18n.Tr "repo.diff.view_file"}}</a> <a class="ui basic tiny button" rel="nofollow" href="{{EscapePound $.BeforeSourcePath}}/{{EscapePound .Name}}">{{$.i18n.Tr "repo.diff.view_file"}}</a>
{{else}} {{else}}
<a class="btn btn-gray btn-header btn-radius text-black pull-right" rel="nofollow" href="{{EscapePound $.SourcePath}}/{{EscapePound .Name}}">{{$.i18n.Tr "repo.diff.view_file"}}</a> <a class="ui basic tiny button" rel="nofollow" href="{{EscapePound $.SourcePath}}/{{EscapePound .Name}}">{{$.i18n.Tr "repo.diff.view_file"}}</a>
{{end}} {{end}}
<span class="file">{{$file.Name}}</span>
</div> </div>
</h4>
<div class="ui attached table segment">
{{$isImage := (call $.IsImageFile $file.Name)}} {{$isImage := (call $.IsImageFile $file.Name)}}
<div class="panel-body file-body file-code code-view code-diff">
{{if $isImage}} {{if $isImage}}
<div class="text-center"> <div class="center">
<img src="{{$.RawPath}}/{{EscapePound .Name}}"> <img src="{{$.RawPath}}/{{EscapePound .Name}}">
</div> </div>
{{else}} {{else}}
<div class="file-body file-code code-view code-diff">
<table> <table>
<tbody> <tbody>
{{range .Sections}} {{range .Sections}}
@ -114,7 +124,6 @@
<td class="lines-num lines-num-new"> <td class="lines-num lines-num-new">
<span rel="{{if $line.RightIdx}}diff-{{Sha1 $file.Name}}R{{$line.RightIdx}}{{end}}">{{if $line.RightIdx}}{{$line.RightIdx}}{{end}}</span> <span rel="{{if $line.RightIdx}}diff-{{Sha1 $file.Name}}R{{$line.RightIdx}}{{end}}">{{if $line.RightIdx}}{{$line.RightIdx}}{{end}}</span>
</td> </td>
<td class="lines-code"> <td class="lines-code">
<pre>{{$line.Content}}</pre> <pre>{{$line.Content}}</pre>
</td> </td>
@ -123,6 +132,7 @@
{{end}} {{end}}
</tbody> </tbody>
</table> </table>
</div>
{{end}} {{end}}
</div> </div>
</div> </div>

Loading…
Cancel
Save