项目文件历史记录显示内容区分历史新增和删除

项目变更文件高亮显示
This commit is contained in:
huang 2016-11-29 17:05:14 +08:00
parent e7b2b1edfa
commit a19f6ffd38
7 changed files with 98 additions and 38 deletions

View File

@ -291,6 +291,9 @@ class PullRequestsController < ApplicationController
@type = params[:type]
@changes = @g.merge_request_changes(@project.gpid, params[:id]).try(:changes)
@changes_count = @changes.count
@limit = 10
@is_remote = true

View File

@ -586,6 +586,7 @@ update
diff = OpenStruct.new(diff)
@diff_file = Trustie::Gitlab::Diff::File.new(diff)
@commit_details = @g.commit(@project.gpid, params[:changeset])
render :layout => 'base_projects'
end

View File

@ -16,7 +16,30 @@
</a>
</div>
<div class="autoscroll">
<%= render 'repositories/change_diff', :local => {:change => change} %>
<table class="filecontent syntaxhl" style="width:100%;" >
<tbody>
<% diff = ActiveSupport::JSON.decode(change['diff']).first %>
<% diff = OpenStruct.new(diff) %>
<% diff_file = Trustie::Gitlab::Diff::File.new(diff) %>
<% diff_file.diff_lines.each_with_index do |line, index| %>
<% type = line.type %>
<% last_line = line.new_pos %>
<% line_old = line.old_pos.to_s %>
<% if type == 'match' %>
<!--表示没有修改,两个都要显示行号-->
<% output += "|#{line_old.center(4)}|#{last_line.to_s.center(4)}|#{line.text}\n" %>
<% else %>
<% old_line = type == 'new' ? ' '*4: line_old %>
<% new_line = type == 'old' ? ' '*4: last_line %>
<% output += "|#{old_line.to_s.center(4)}|#{new_line.to_s.center(4)}|#{line.text}\n" %>
<% end %>
<% end %>
<%# line_num = diff_line_num(change['diff']) %>
<%# diff_content = diff_content(change['diff']) %>
</tbody>
</table>
<%#= render :partial => 'repositories/change_diff', :locals => {:change => change} %>
</div>
<% end %>

View File

@ -1,27 +1,49 @@
<% diff = ActiveSupport::JSON.decode(change.to_json) %>
<% diff = OpenStruct.new(diff) %>
<% @diff_file = Trustie::Gitlab::Diff::File.new(diff) %>
<% @diff_file.diff_lines.each_with_index do |line, index| %>
<% type = line.type %>
<% last_line = line.new_pos.to_s %>
<% line_old = line.old_pos.to_s %>
<table>
<tbody>
<% if type == "match" %>
<tr>
<td class="old_line"><%= line_old.center(4) %></td>
<td class="new_line"><%= last_line.center(4) %></td>
<td class="line_content"><%= line.text %></td>
<table class="filecontent syntaxhl">
<tbody>
<% diff = ActiveSupport::JSON.decode(change.to_json) %>
<% diff = OpenStruct.new(diff) %>
<% @diff_file = Trustie::Gitlab::Diff::File.new(diff) %>
<% @diff_file.diff_lines.each_with_index do |line, index| %>
<% type = line.type %>
<% last_line = line.new_pos.to_s %>
<% line_old = line.old_pos.to_s %>
<% if type.nil? || type == "match" %>
<tr class="line_holder" >
<td class="old_line">
<a><%= type == "match" ? "..." : line_old.center(4) %></a>
</td>
<td class="new_line" >
<a><%= type == "match" ? "..." : last_line.center(4) %></a>
</td>
<td class="line_content noteable_line <%= 'c_grey' if type == "match" %>" >
<pre style="width:auto;overflow: auto; "><%= line.text.html_safe %></pre>
</td>
</tr>
<% else %>
<% old_line = type == 'new' ? ' '*4: line_old %>
<% new_line = type == 'old' ? ' '*4: last_line %>
<tr>
<td class="old_line"><%= old_line.to_s.center(4) %></td>
<td class="new_line"><%= new_line.to_s.center(4) %></td>
<td class="line_content"><%= line.text %></td>
<tr class="<%= type == 'old' ? 'line_holder old' : 'line_holder new' %>" >
<td class="old_line">
<a><%= old_line.to_s.center(4) %></a>
</td>
<td class="new_line" data-linenumber="2">
<a><%= new_line.to_s.center(4) %></a>
</td>
<td class="<%= type == 'old' ? 'line_content noteable_line old' : 'line_content new noteable_line' %> " >
<pre style="width:auto;overflow: auto; "><%= line.text.html_safe %></pre>
</td>
</tr>
<% end %>
</tbody>
</table>
<% end %>
<% end %>
<tr>
<td class=" old_line " data-linenumber="5">
...
</td>
<td class="new_line " data-linenumber="5">
...
</td>
<td class="line_content "></td>
</tr>
</tbody>
</table>

View File

@ -16,7 +16,7 @@
</a>
</div>
<div class="autoscroll">
<%= render 'repositories/change_diff', :local => {:change => commit_diff} %>
<%= render :partial => 'repositories/change_diff', :locals => {:change => commit_diff} %>
</div>
<% end %>
</div>

View File

@ -7,21 +7,21 @@ module Trustie
FINISH = "#!idiff-finish!#"
def processing(diff_arr)
indexes = _indexes_of_changed_lines diff_arr
indexes.each do |index|
first_line = diff_arr[index+1]
second_line = diff_arr[index+2]
# Skip inline diff if empty line was replaced with content
next if first_line == "-\n"
first_token = find_first_token(first_line, second_line)
apply_first_token(diff_arr, index, first_token)
last_token = find_last_token(first_line, second_line, first_token)
apply_last_token(diff_arr, index, last_token)
end
# indexes = _indexes_of_changed_lines diff_arr
#
# indexes.each do |index|
# first_line = diff_arr[index+1]
# second_line = diff_arr[index+2]
#
# # Skip inline diff if empty line was replaced with content
# next if first_line == "-\n"
#
# first_token = find_first_token(first_line, second_line)
# apply_first_token(diff_arr, index, first_token)
#
# last_token = find_last_token(first_line, second_line, first_token)
# apply_last_token(diff_arr, index, last_token)
# end
diff_arr
end

View File

@ -1043,3 +1043,14 @@ table.quality_list tbody td, table.quality_list tbody tr td {
font-size: 11px;
padding: 4px 10px 4px 3px;
}
/* 文本变更样式 */
.autoscroll {overflow-x: auto; margin-bottom: 0.2em;}
table.filecontent { border: 1px solid #e2e2e2; border-collapse: collapse; width: 100%;background-color: #fafafa;}
table.text-file{}
.old_line,.new_line,.diff_line {margin: 0px; padding: 0px;border: none; background: #f7f8fa;color: rgba(0,0,0,0.3); padding: 0px 5px; border-right: 1px solid #dce0e6;text-align: right; min-width: 35px; max-width: 50px; width: 35px; -webkit-user-select: none;}
.old_line a,.new_line a,.diff_line a { float: left;width: 35px; font-weight: normal; color: rgba(0,0,0,0.3);}
.line_content{padding: 0px 5px;}
.old{ background:#ffecec; }
.old:hover{ background:#fffaf1; }
.new{ background: #eaffea;}
.new:hover{ background:#fffaf1; }