有几处相同的content key
This commit is contained in:
parent
e202a7b99c
commit
c2629ebdc0
|
@ -525,13 +525,13 @@ class UsersController < ApplicationController
|
||||||
|
|
||||||
member.course_group_id = 0
|
member.course_group_id = 0
|
||||||
member.save
|
member.save
|
||||||
CourseMessage.create(:user_id => @msg.course_message_id, :course_id => @msg.course_id, :viewed => false,:content=> @msg.content,:course_message_id=>User.current.id,:content=>@msg.content,:course_message_type=>'CourseRequestDealResult',:status=>1)
|
CourseMessage.create(:user_id => @msg.course_message_id, :course_id => @msg.course_id, :viewed => false,:course_message_id=>User.current.id,:content=>@msg.content,:course_message_type=>'CourseRequestDealResult',:status=>1)
|
||||||
@msg.update_attributes(:status=>1,:viewed=>1)
|
@msg.update_attributes(:status=>1,:viewed=>1)
|
||||||
else
|
else
|
||||||
members = []
|
members = []
|
||||||
members << Member.new(:role_ids => integer_ids, :user_id => @msg.course_message_id)
|
members << Member.new(:role_ids => integer_ids, :user_id => @msg.course_message_id)
|
||||||
Course.find(@msg.course_id).members << members
|
Course.find(@msg.course_id).members << members
|
||||||
CourseMessage.create(:user_id => @msg.course_message_id, :course_id => @msg.course_id, :viewed => false,:content=> @msg.content,:course_message_id=>User.current.id,:content=>@msg.content,:course_message_type=>'CourseRequestDealResult',:status=>1)
|
CourseMessage.create(:user_id => @msg.course_message_id, :course_id => @msg.course_id, :viewed => false,:course_message_id=>User.current.id,:content=>@msg.content,:course_message_type=>'CourseRequestDealResult',:status=>1)
|
||||||
@msg.update_attributes(:status=>1,:viewed=>1)
|
@msg.update_attributes(:status=>1,:viewed=>1)
|
||||||
|
|
||||||
if integer_ids.include?(9)
|
if integer_ids.include?(9)
|
||||||
|
@ -546,7 +546,7 @@ class UsersController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
when 'N'
|
when 'N'
|
||||||
CourseMessage.create(:user_id => @msg.course_message_id, :course_id => @msg.course_id, :viewed => false,:content=> @msg.content,:course_message_id=>User.current.id,:content=>@msg.content,:course_message_type=>'CourseRequestDealResult',:status=>2)
|
CourseMessage.create(:user_id => @msg.course_message_id, :course_id => @msg.course_id, :viewed => false,:course_message_id=>User.current.id,:content=>@msg.content,:course_message_type=>'CourseRequestDealResult',:status=>2)
|
||||||
@msg.update_attributes(:status=>2,:viewed=>1)
|
@msg.update_attributes(:status=>2,:viewed=>1)
|
||||||
|
|
||||||
if integer_ids.include?(9)
|
if integer_ids.include?(9)
|
||||||
|
@ -596,13 +596,13 @@ class UsersController < ApplicationController
|
||||||
when 'Y'
|
when 'Y'
|
||||||
unless ah.empty?
|
unless ah.empty?
|
||||||
ah.first.update_column('status', 2)
|
ah.first.update_column('status', 2)
|
||||||
CourseMessage.create(:user_id => @msg.apply_user_id, :course_id => @msg.course_id, :viewed => false,:content=> @msg.content,:course_message_id=>@msg.course_message_id,:content=>@msg.content,:course_message_type=>'HomeworkCommon',:status=>6,:apply_result=>1)
|
CourseMessage.create(:user_id => @msg.apply_user_id, :course_id => @msg.course_id, :viewed => false,:course_message_id=>@msg.course_message_id,:content=>@msg.content,:course_message_type=>'HomeworkCommon',:status=>6,:apply_result=>1)
|
||||||
@msg.update_attributes(:apply_result=>1,:viewed=>1)
|
@msg.update_attributes(:apply_result=>1,:viewed=>1)
|
||||||
end
|
end
|
||||||
when 'N'
|
when 'N'
|
||||||
unless ah.empty?
|
unless ah.empty?
|
||||||
ah.first.update_column('status', 3)
|
ah.first.update_column('status', 3)
|
||||||
CourseMessage.create(:user_id => @msg.apply_user_id, :course_id => @msg.course_id, :viewed => false,:content=> @msg.content,:course_message_id=>@msg.course_message_id,:content=>@msg.content,:course_message_type=>'HomeworkCommon',:status=>6,:apply_result=>2)
|
CourseMessage.create(:user_id => @msg.apply_user_id, :course_id => @msg.course_id, :viewed => false,:course_message_id=>@msg.course_message_id,:content=>@msg.content,:course_message_type=>'HomeworkCommon',:status=>6,:apply_result=>2)
|
||||||
@msg.update_attributes(:apply_result=>2,:viewed=>1)
|
@msg.update_attributes(:apply_result=>2,:viewed=>1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
module Gitlab
|
||||||
|
module Diff
|
||||||
|
class File
|
||||||
|
attr_reader :diff
|
||||||
|
|
||||||
|
delegate :new_file, :deleted_file, :renamed_file,
|
||||||
|
:old_path, :new_path, to: :diff, prefix: false
|
||||||
|
|
||||||
|
def initialize(diff)
|
||||||
|
@diff = diff
|
||||||
|
end
|
||||||
|
|
||||||
|
# Array of Gitlab::DIff::Line objects
|
||||||
|
def diff_lines
|
||||||
|
@lines ||= parser.parse(raw_diff.lines)
|
||||||
|
end
|
||||||
|
|
||||||
|
def mode_changed?
|
||||||
|
!!(diff.a_mode && diff.b_mode && diff.a_mode != diff.b_mode)
|
||||||
|
end
|
||||||
|
|
||||||
|
def parser
|
||||||
|
Gitlab::Diff::Parser.new
|
||||||
|
end
|
||||||
|
|
||||||
|
def raw_diff
|
||||||
|
diff.diff.to_s
|
||||||
|
end
|
||||||
|
|
||||||
|
def next_line(index)
|
||||||
|
diff_lines[index + 1]
|
||||||
|
end
|
||||||
|
|
||||||
|
def prev_line(index)
|
||||||
|
if index > 0
|
||||||
|
diff_lines[index - 1]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def file_path
|
||||||
|
if diff.new_path.present?
|
||||||
|
diff.new_path
|
||||||
|
elsif diff.old_path.present?
|
||||||
|
diff.old_path
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def added_lines
|
||||||
|
diff_lines.count(&:added?)
|
||||||
|
end
|
||||||
|
|
||||||
|
def removed_lines
|
||||||
|
diff_lines.count(&:removed?)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,20 @@
|
||||||
|
module Gitlab
|
||||||
|
module Diff
|
||||||
|
class Line
|
||||||
|
attr_reader :type, :text, :index, :old_pos, :new_pos
|
||||||
|
|
||||||
|
def initialize(text, type, index, old_pos, new_pos)
|
||||||
|
@text, @type, @index = text, type, index
|
||||||
|
@old_pos, @new_pos = old_pos, new_pos
|
||||||
|
end
|
||||||
|
|
||||||
|
def added?
|
||||||
|
type == 'new'
|
||||||
|
end
|
||||||
|
|
||||||
|
def removed?
|
||||||
|
type == 'old'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,9 @@
|
||||||
|
module Gitlab
|
||||||
|
module Diff
|
||||||
|
class LineCode
|
||||||
|
def self.generate(file_path, new_line_position, old_line_position)
|
||||||
|
"#{Digest::SHA1.hexdigest(file_path)}_#{old_line_position}_#{new_line_position}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,79 @@
|
||||||
|
module Gitlab
|
||||||
|
module Diff
|
||||||
|
class Parser
|
||||||
|
include Enumerable
|
||||||
|
|
||||||
|
def parse(lines)
|
||||||
|
@lines = lines
|
||||||
|
lines_obj = []
|
||||||
|
line_obj_index = 0
|
||||||
|
line_old = 1
|
||||||
|
line_new = 1
|
||||||
|
type = nil
|
||||||
|
|
||||||
|
lines_arr = ::Gitlab::InlineDiff.processing lines
|
||||||
|
|
||||||
|
lines_arr.each do |line|
|
||||||
|
next if filename?(line)
|
||||||
|
|
||||||
|
full_line = html_escape(line.gsub(/\n/, ''))
|
||||||
|
full_line = ::Gitlab::InlineDiff.replace_markers full_line
|
||||||
|
|
||||||
|
if line.match(/^@@ -/)
|
||||||
|
type = "match"
|
||||||
|
|
||||||
|
line_old = line.match(/\-[0-9]*/)[0].to_i.abs rescue 0
|
||||||
|
line_new = line.match(/\+[0-9]*/)[0].to_i.abs rescue 0
|
||||||
|
|
||||||
|
next if line_old <= 1 && line_new <= 1 #top of file
|
||||||
|
lines_obj << Gitlab::Diff::Line.new(full_line, type, line_obj_index, line_old, line_new)
|
||||||
|
line_obj_index += 1
|
||||||
|
next
|
||||||
|
else
|
||||||
|
type = identification_type(line)
|
||||||
|
lines_obj << Gitlab::Diff::Line.new(full_line, type, line_obj_index, line_old, line_new)
|
||||||
|
line_obj_index += 1
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
if line[0] == "+"
|
||||||
|
line_new += 1
|
||||||
|
elsif line[0] == "-"
|
||||||
|
line_old += 1
|
||||||
|
else
|
||||||
|
line_new += 1
|
||||||
|
line_old += 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
lines_obj
|
||||||
|
end
|
||||||
|
|
||||||
|
def empty?
|
||||||
|
@lines.empty?
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def filename?(line)
|
||||||
|
line.start_with?('--- /dev/null', '+++ /dev/null', '--- a', '+++ b',
|
||||||
|
'--- /tmp/diffy', '+++ /tmp/diffy')
|
||||||
|
end
|
||||||
|
|
||||||
|
def identification_type(line)
|
||||||
|
if line[0] == "+"
|
||||||
|
"new"
|
||||||
|
elsif line[0] == "-"
|
||||||
|
"old"
|
||||||
|
else
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def html_escape(str)
|
||||||
|
replacements = { '&' => '&', '>' => '>', '<' => '<', '"' => '"', "'" => ''' }
|
||||||
|
str.gsub(/[&"'><]/, replacements)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,104 @@
|
||||||
|
module Gitlab
|
||||||
|
class InlineDiff
|
||||||
|
class << self
|
||||||
|
|
||||||
|
START = "#!idiff-start!#"
|
||||||
|
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
|
||||||
|
|
||||||
|
diff_arr
|
||||||
|
end
|
||||||
|
|
||||||
|
def apply_first_token(diff_arr, index, first_token)
|
||||||
|
start = first_token + START
|
||||||
|
|
||||||
|
if first_token.empty?
|
||||||
|
# In case if we remove string of spaces in commit
|
||||||
|
diff_arr[index+1].sub!("-", "-" => "-#{START}")
|
||||||
|
diff_arr[index+2].sub!("+", "+" => "+#{START}")
|
||||||
|
else
|
||||||
|
diff_arr[index+1].sub!(first_token, first_token => start)
|
||||||
|
diff_arr[index+2].sub!(first_token, first_token => start)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def apply_last_token(diff_arr, index, last_token)
|
||||||
|
# This is tricky: escape backslashes so that `sub` doesn't interpret them
|
||||||
|
# as backreferences. Regexp.escape does NOT do the right thing.
|
||||||
|
replace_token = FINISH + last_token.gsub(/\\/, '\&\&')
|
||||||
|
diff_arr[index+1].sub!(/#{Regexp.escape(last_token)}$/, replace_token)
|
||||||
|
diff_arr[index+2].sub!(/#{Regexp.escape(last_token)}$/, replace_token)
|
||||||
|
end
|
||||||
|
|
||||||
|
def find_first_token(first_line, second_line)
|
||||||
|
max_length = [first_line.size, second_line.size].max
|
||||||
|
first_the_same_symbols = 0
|
||||||
|
|
||||||
|
(0..max_length + 1).each do |i|
|
||||||
|
first_the_same_symbols = i - 1
|
||||||
|
|
||||||
|
if first_line[i] != second_line[i] && i > 0
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
first_line[0..first_the_same_symbols][1..-1]
|
||||||
|
end
|
||||||
|
|
||||||
|
def find_last_token(first_line, second_line, first_token)
|
||||||
|
max_length = [first_line.size, second_line.size].max
|
||||||
|
last_the_same_symbols = 0
|
||||||
|
|
||||||
|
(1..max_length + 1).each do |i|
|
||||||
|
last_the_same_symbols = -i
|
||||||
|
shortest_line = second_line.size > first_line.size ? first_line : second_line
|
||||||
|
|
||||||
|
if (first_line[-i] != second_line[-i]) || "#{first_token}#{START}".size == shortest_line[1..-i].size
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
last_the_same_symbols += 1
|
||||||
|
first_line[last_the_same_symbols..-1]
|
||||||
|
end
|
||||||
|
|
||||||
|
def _indexes_of_changed_lines(diff_arr)
|
||||||
|
chain_of_first_symbols = ""
|
||||||
|
diff_arr.each_with_index do |line, i|
|
||||||
|
chain_of_first_symbols += line[0]
|
||||||
|
end
|
||||||
|
chain_of_first_symbols.gsub!(/[^\-\+]/, "#")
|
||||||
|
|
||||||
|
offset = 0
|
||||||
|
indexes = []
|
||||||
|
while index = chain_of_first_symbols.index("#-+#", offset)
|
||||||
|
indexes << index
|
||||||
|
offset = index + 1
|
||||||
|
end
|
||||||
|
indexes
|
||||||
|
end
|
||||||
|
|
||||||
|
def replace_markers(line)
|
||||||
|
line.gsub!(START, "<span class='idiff'>")
|
||||||
|
line.gsub!(FINISH, "</span>")
|
||||||
|
line
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue