Commit 08ab1f32 authored by pierre.tremouilhac's avatar pierre.tremouilhac
Browse files

Merge branch '241-report-format-20170918' into 'development'

Resolve "Report format - 20170918"

Closes #241

See merge request !437
parents 55d063f7 b112cb55
......@@ -52,7 +52,7 @@ module Reporter
def rm_head_space(ops = [])
head = nil
ops.each do |op|
head = op['insert'].gsub(/^\s+/, '')
head = op['insert'].gsub(/^[\u00A0\s]+/, '')
break if head.present?
ops = ops[1..-1]
end
......@@ -64,7 +64,7 @@ module Reporter
def rm_tail_space(ops = [])
tail = nil
ops.reverse.each do |op|
tail = op['insert'].gsub(/\s*[,.;]*\s*$/, '')
tail = op['insert'].gsub(/[\u00A0\s]*[,.;]*[\u00A0\s]*$/, '')
break if tail.present?
ops = ops[0..-2]
end
......@@ -85,7 +85,7 @@ module Reporter
def remove_redundant_space_break(ops)
ops.map.with_index do |op, i|
op["insert"] = op["insert"].gsub(/\s\s+/, " ")
op["insert"] = op["insert"].gsub(/[\u00A0\s]{2,}/, " ")
op["insert"] = op["insert"].lstrip if i == 0
op["insert"] = op["insert"].gsub(/\n/, " ")
op
......
......@@ -377,8 +377,9 @@ module Reporter
delta = merge_items_symbols(delta, sorted_analyses, '; ')
end
return [] if delta.length.zero?
remove_redundant_space_break(delta)[0..-2] +
result = remove_redundant_space_break(delta)[0..-2] +
[{ 'insert' => '.' }, { 'insert' => "\n" }]
sanitize_attributes(result)
end
def materials_table_delta
......@@ -462,6 +463,13 @@ module Reporter
counter = counter >= 1 && counter <=26 ? counter - 1 : 25
alphabets[counter]
end
def sanitize_attributes(content)
content.map do |c|
c['attributes'].delete('color') if c['attributes']
c
end
end
end
end
end
......@@ -39,6 +39,8 @@ describe 'Reporter::Docx::DetailReaction instance' do
let!(:s3) { create(:sample, name: 'Sample 3') }
let!(:s4) { create(:sample, name: 'Solvent') }
let!(:correct_content) { "analysis contents (true for report)" }
let!(:non_breaking_space) { " " }
let!(:inverse) { "{\"attributes\":{\"color\":\"black\",\"script\":\"super\"},\"insert\":\"-1\"}" }
let!(:r1_serialized) do
CollectionsReaction.create!(reaction: r1, collection: c1)
CollectionsSample.create!(sample: s1, collection: c1)
......@@ -58,7 +60,14 @@ describe 'Reporter::Docx::DetailReaction instance' do
)
con = r1.products[0].container.children[0].children[0]
con.extended_metadata["report"] = "true"
con.extended_metadata["content"] = "{\"ops\": [{\"insert\": \" \\n\"}, {\"insert\": \" #{correct_content} \"}, {\"insert\": \" ; \\n\"}]}"
con.extended_metadata["content"] = "{\"ops\":
[
{\"insert\": \" \\n\"},
#{inverse},
{\"insert\": \"#{correct_content} #{non_breaking_space} \"},
{\"insert\": \" #{non_breaking_space} ;#{non_breaking_space} \\n\"}
]
}"
con.save!
ElementReportPermissionProxy.new(user, r1, [user.id]).serialized
......@@ -193,6 +202,7 @@ describe 'Reporter::Docx::DetailReaction instance' do
{"attributes"=>{"italic"=>true}, "insert"=>"R"},
{"attributes"=>{"italic"=>true, "script"=>"sub"}, "insert"=>"f"},
{"insert"=>" = #{rf} (#{t_sol})."}, {"insert"=>"\n"},
{"attributes"=>{"script"=>"super"}, "insert"=>"-1"},
{"insert"=>correct_content},
{"insert"=>"."},
{"insert"=>"\n"},
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment