From a19f6ffd3811fd45aac4986e2dcef401eeb9556f Mon Sep 17 00:00:00 2001 From: huang Date: Tue, 29 Nov 2016 17:05:14 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E6=96=87=E4=BB=B6=E5=8E=86?= =?UTF-8?q?=E5=8F=B2=E8=AE=B0=E5=BD=95=E6=98=BE=E7=A4=BA=E5=86=85=E5=AE=B9?= =?UTF-8?q?=E5=8C=BA=E5=88=86=E5=8E=86=E5=8F=B2=E6=96=B0=E5=A2=9E=E5=92=8C?= =?UTF-8?q?=E5=88=A0=E9=99=A4=20=E9=A1=B9=E7=9B=AE=E5=8F=98=E6=9B=B4?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E9=AB=98=E4=BA=AE=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/pull_requests_controller.rb | 3 + app/controllers/repositories_controller.rb | 1 + .../_pull_request_changes.html.erb | 25 +++++++- app/views/repositories/_change_diff.html.erb | 64 +++++++++++++------ app/views/repositories/commit_diff.html.erb | 2 +- lib/trustie/gitlab/inline_diff.rb | 30 ++++----- public/stylesheets/css/project.css | 11 ++++ 7 files changed, 98 insertions(+), 38 deletions(-) diff --git a/app/controllers/pull_requests_controller.rb b/app/controllers/pull_requests_controller.rb index 71d736bdf..00259ee4f 100644 --- a/app/controllers/pull_requests_controller.rb +++ b/app/controllers/pull_requests_controller.rb @@ -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 diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index ce03962e1..f932748af 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -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 diff --git a/app/views/pull_requests/_pull_request_changes.html.erb b/app/views/pull_requests/_pull_request_changes.html.erb index 897cb9659..d64a65772 100644 --- a/app/views/pull_requests/_pull_request_changes.html.erb +++ b/app/views/pull_requests/_pull_request_changes.html.erb @@ -16,7 +16,30 @@
- <%= render 'repositories/change_diff', :local => {:change => change} %> + + + <% 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']) %> + + +
+ <%#= render :partial => 'repositories/change_diff', :locals => {:change => change} %>
<% end %> diff --git a/app/views/repositories/_change_diff.html.erb b/app/views/repositories/_change_diff.html.erb index 81bae132e..d7eef5ce0 100644 --- a/app/views/repositories/_change_diff.html.erb +++ b/app/views/repositories/_change_diff.html.erb @@ -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 %> - - - <% if type == "match" %> - - - - +
<%= line_old.center(4) %><%= last_line.center(4) %><%= line.text %>
+ + <% 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" %> + + + + <% else %> <% old_line = type == 'new' ? ' '*4: line_old %> <% new_line = type == 'old' ? ' '*4: last_line %> - - - - + + + + <% end %> - -
+ <%= type == "match" ? "..." : line_old.center(4) %> + + <%= type == "match" ? "..." : last_line.center(4) %> + " > +
<%= line.text.html_safe %>
+
<%= old_line.to_s.center(4) %><%= new_line.to_s.center(4) %><%= line.text %>
+ <%= old_line.to_s.center(4) %> + + <%= new_line.to_s.center(4) %> + +
<%= line.text.html_safe %>
+
-<% end %> \ No newline at end of file + <% end %> + + + ... + + + ... + + + + + \ No newline at end of file diff --git a/app/views/repositories/commit_diff.html.erb b/app/views/repositories/commit_diff.html.erb index d78465cdb..7693b385c 100644 --- a/app/views/repositories/commit_diff.html.erb +++ b/app/views/repositories/commit_diff.html.erb @@ -16,7 +16,7 @@
- <%= render 'repositories/change_diff', :local => {:change => commit_diff} %> + <%= render :partial => 'repositories/change_diff', :locals => {:change => commit_diff} %>
<% end %> diff --git a/lib/trustie/gitlab/inline_diff.rb b/lib/trustie/gitlab/inline_diff.rb index 942f08fcb..902167776 100644 --- a/lib/trustie/gitlab/inline_diff.rb +++ b/lib/trustie/gitlab/inline_diff.rb @@ -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 diff --git a/public/stylesheets/css/project.css b/public/stylesheets/css/project.css index 530287ed4..cc0ded22a 100644 --- a/public/stylesheets/css/project.css +++ b/public/stylesheets/css/project.css @@ -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; } \ No newline at end of file