Merge branch 'dev_newproject' of https://git.trustie.net/jacknudt/trustieforge into dev_newproject

Conflicts:
	app/controllers/pull_requests_controller.rb
This commit is contained in:
daiao 2016-11-29 12:28:31 +08:00
commit e7b2b1edfa
4 changed files with 68 additions and 100 deletions

View File

@ -288,33 +288,11 @@ class PullRequestsController < ApplicationController
# id (required) - The ID of a project # id (required) - The ID of a project
# merge_request_id (required) - The ID of MR # merge_request_id (required) - The ID of MR
def pull_request_changes def pull_request_changes
@type = params[:type] @type = params[:type]
@changes = @g.merge_request_changes(@project.gpid, params[:id]).try(:changes) @changes = @g.merge_request_changes(@project.gpid, params[:id]).try(:changes)
logger.info("###############################{@changes}")
diff = ActiveSupport::JSON.decode(@changes).first
diff = OpenStruct.new(diff)
diff_file = Trustie::Gitlab::Diff::File.new(diff)
logger.info("##############################")
output = ''
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
@changes_count = @changes.count @changes_count = @changes.count
@limit = 10
@is_remote = true @is_remote = true
@count = @changes_count @count = @changes_count
@pages = Paginator.new @count, @limit, params['page'] || 1 @pages = Paginator.new @count, @limit, params['page'] || 1

View File

@ -16,29 +16,7 @@
</a> </a>
</div> </div>
<div class="autoscroll"> <div class="autoscroll">
<table class="filecontent syntaxhl" style="width:100%;" > <%= render 'repositories/change_diff', :local => {:change => change} %>
<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>
</div> </div>
<% end %> <% end %>

View File

@ -0,0 +1,27 @@
<% 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>
</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>
<% end %>
</tbody>
</table>
<% end %>

View File

@ -9,29 +9,14 @@
</li> </li>
</div> </div>
<div class="showing-changes-project f14"><%= @commit_details.message %></div> <div class="showing-changes-project f14"><%= @commit_details.message %></div>
<% @diff_file.diff_lines.each_with_index do |line, index| %> <% @commit_diff.each do |commit_diff| %>
<%= line[0] %> <div class="showing-changes-row fontGrey2">
<% type = line.type %> <a href="javascript:void(0);" class="linkGrey3" id="changed-files">
<% last_line = line.new_pos.to_s %> <img src="/images/vlicon/file.png" width="18" height="20" style="vertical-align:middle;" class="mr5" /><%= commit_diff.new_path %>
<% line_old = line.old_pos.to_s %> </a>
<table> </div>
<tbody> <div class="autoscroll">
<% if type == "match" %> <%= render 'repositories/change_diff', :local => {:change => commit_diff} %>
<tr> </div>
<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>
</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>
<% end %>
</tbody>
</table>
<% end %> <% end %>
</div> </div>