diff --git a/app/controllers/pull_requests_controller.rb b/app/controllers/pull_requests_controller.rb index 808459665..87cd9ac23 100644 --- a/app/controllers/pull_requests_controller.rb +++ b/app/controllers/pull_requests_controller.rb @@ -48,6 +48,7 @@ class PullRequestsController < ApplicationController end def show + @type = params[:type] @request = @g.merge_request(@project.gpid, params[:id]) @commits = @g.merge_request_commits(@project.gpid, params[:id].to_i) end @@ -72,12 +73,12 @@ class PullRequestsController < ApplicationController # 获取某次请求的提交次数 def pull_request_commits + @type = parms[:type] @commits = @g.merge_request_commits(@project.gpid, params[:id].to_i) end # 获取某次请求的改动 def pull_request_changes - @type = 2 @changes = @g.merge_request_changes(@project.gpid, params[:id]) end diff --git a/app/helpers/pull_requests_helper.rb b/app/helpers/pull_requests_helper.rb index fa8554854..e9446e654 100644 --- a/app/helpers/pull_requests_helper.rb +++ b/app/helpers/pull_requests_helper.rb @@ -1,2 +1,13 @@ module PullRequestsHelper + + # 获取diff内容行号 + def diff_line_num content + content.scan(/@@ -(\d+),\d+ \+\d+,\d+ @@/).first.nil? ? "" : content.scan(/@@ -(\d+),\d+ \+\d+,\d+ @@/).first.join("").to_i + end + + # 处理内容 + def diff_content content + content.gsub!(/.*@@ -\d+,\d+ \+\d+,\d+ @@\n/m,'') + end + end diff --git a/app/views/pull_requests/_pull_request_changes.html.erb b/app/views/pull_requests/_pull_request_changes.html.erb index b1abe1383..66ce993e5 100644 --- a/app/views/pull_requests/_pull_request_changes.html.erb +++ b/app/views/pull_requests/_pull_request_changes.html.erb @@ -1,34 +1,33 @@ -<% @changes.each do |changes| %> -
Showing 3 changed files with 3 additions and 3 deletions -
    -
  1. app/views/organizations/_org_course_homework.html.erb
  2. -
  3. app/views/users/_course_homework.html.erb
  4. -
  5. app/views/users/_user_homework_detail.html.erb
  6. -
-
-
app/views/organizations/_org_course_homework.html.erb
-
- - - - - - - - - - - - - - - - - - - - - -
9999<% if activity.homework_type == 3 && activity.homework_detail_group.base_on_project == 1 %>
100100<div class="mt10">
111- <div class="fl mr5 fontGrey3">
111+ <div class="fl mr20 fontGrey3 w80">
-
+<% if @changes %> + <% @changes.try(:changes).each do |cd| %> +
+ + <%= cd['new_path'] %> + +
+
+ + + <% line_num = diff_line_num(cd['diff']) %> + <% diff_content = diff_content(cd['diff']) %> + <% syntax_highlight_lines('new_path', Redmine::CodesetUtil.to_utf8_by_setting(diff_content)).each do |line| %> + + + <% if line[0,1] == "-" %> + + <% elsif line[0,1] == "+" %> + + <% else%> + + <% end %> + + <% line_num += 1 %> + <% end %> + +
+ <%= line_num %> +
<%= line.html_safe %>
<%= line.html_safe %>
<%= line.html_safe %>
+
+ <% end %> <% end %> + diff --git a/app/views/pull_requests/pull_request_changes.js.erb b/app/views/pull_requests/pull_request_changes.js.erb index 10374c213..2b3d77537 100644 --- a/app/views/pull_requests/pull_request_changes.js.erb +++ b/app/views/pull_requests/pull_request_changes.js.erb @@ -1 +1 @@ -$("#merge_record_1").html('<%= render :partial => "pull_requests/pull_request_changes" %>'); \ No newline at end of file +$("#merge_record_1").html('<%= escape_javascript( render :partial => "pull_requests/pull_request_changes", :locals => {:type => @type} ) %>'); \ No newline at end of file diff --git a/app/views/pull_requests/show.html.erb b/app/views/pull_requests/show.html.erb index 634ed2916..fa84102bd 100644 --- a/app/views/pull_requests/show.html.erb +++ b/app/views/pull_requests/show.html.erb @@ -12,18 +12,16 @@
根据最近提交时间排列
<%= render :partial => "pull_requests/pull_request_commits" %>
-<% if @type == 2 %> -
- <%= render :partial => "pull_requests/pull_request_changes" %> -
-<% end %> +
+ <%= render :partial => "pull_requests/pull_request_changes" %> +