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
# merge_request_id (required) - The ID of MR
def pull_request_changes
@type = params[:type]
@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
@limit = 10
@is_remote = true
@count = @changes_count
@pages = Paginator.new @count, @limit, params['page'] || 1

View File

@ -1,53 +1,31 @@
<% if !@changes.blank? && @type == "3" %>
<div class="pullreques_change_box">
<div class="pullreques_pull_top clear">
<p class="fl c_grey ml15">改动了<span class="fontBlue"> <%= @changes_count %></span> 个文件</p>
</div>
<ul class="pullreques_change_list">
<% @changes.each do |change| %>
<li><span class="fl ml15 mt12 <%= get_type_of_file(change) %>"></span><p class="pullreques_pull_txt ml5 fl"><%= change['new_path'] %></p></li>
<% end %>
</ul>
</div>
<% @changes.each do |change| %>
<div class="showing-changes-row fontGrey2">
<a class="linkGrey3" id="changed-files">
<img src="/images/vlicon/file.png" width="18" height="20" style="vertical-align:middle;" class="mr5" /><%= change['new_path'] %>
</a>
</div>
<div class="autoscroll">
<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>
</div>
<% end %>
<div style="text-align:center;">
<div class="pages" style="width:auto; display:inline-block;">
<ul id="homework_pository_ref_pages">
<%= pagination_links_full @pages, @count, :per_page_links => false, :remote => @is_remote, :flag => true, :is_new => true%>
</ul>
<div class="cl"></div>
</div>
</div>
<% end %>
<% if !@changes.blank? && @type == "3" %>
<div class="pullreques_change_box">
<div class="pullreques_pull_top clear">
<p class="fl c_grey ml15">改动了<span class="fontBlue"> <%= @changes_count %></span> 个文件</p>
</div>
<ul class="pullreques_change_list">
<% @changes.each do |change| %>
<li><span class="fl ml15 mt12 <%= get_type_of_file(change) %>"></span><p class="pullreques_pull_txt ml5 fl"><%= change['new_path'] %></p></li>
<% end %>
</ul>
</div>
<% @changes.each do |change| %>
<div class="showing-changes-row fontGrey2">
<a class="linkGrey3" id="changed-files">
<img src="/images/vlicon/file.png" width="18" height="20" style="vertical-align:middle;" class="mr5" /><%= change['new_path'] %>
</a>
</div>
<div class="autoscroll">
<%= render 'repositories/change_diff', :local => {:change => change} %>
</div>
<% end %>
<div style="text-align:center;">
<div class="pages" style="width:auto; display:inline-block;">
<ul id="homework_pository_ref_pages">
<%= pagination_links_full @pages, @count, :per_page_links => false, :remote => @is_remote, :flag => true, :is_new => true%>
</ul>
<div class="cl"></div>
</div>
</div>
<% 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>
</div>
<div class="showing-changes-project f14"><%= @commit_details.message %></div>
<% @diff_file.diff_lines.each_with_index do |line, index| %>
<%= line[0] %>
<% 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>
<% @commit_diff.each do |commit_diff| %>
<div class="showing-changes-row fontGrey2">
<a href="javascript:void(0);" class="linkGrey3" id="changed-files">
<img src="/images/vlicon/file.png" width="18" height="20" style="vertical-align:middle;" class="mr5" /><%= commit_diff.new_path %>
</a>
</div>
<div class="autoscroll">
<%= render 'repositories/change_diff', :local => {:change => commit_diff} %>
</div>
<% end %>
</div>