Commit 26e944dc authored by jasonych99's avatar jasonych99
Browse files

remove additional space between observation & Rf

parent 3986067a
......@@ -7,8 +7,8 @@ import ArrayUtils from '../utils/ArrayUtils';
import { Alphabet } from '../utils/ElementUtils';
import _ from 'lodash';
const insertBlank = (target) => {
if(target.length === 0) return true;
const onlyBlank = (target) => {
if (target.length === 0) return true;
const content = target.map(t => t.insert).join('').replace(/\s+/, '');
return !content;
};
......@@ -145,8 +145,7 @@ const obsvTlcContent = (el) => {
let content = [];
content = [...el.observation.ops, ...tlcContent(el)];
content = rmOpsRedundantSpaceBreak(content);
if(content.length === 0) return [];
if(insertBlank) return [];
if (onlyBlank(content)) return [];
return frontBreak(content);
}
......@@ -168,7 +167,7 @@ const rmHeadSpace = (content) => {
if (!head) els = [...els.slice(1)];
return head;
});
if (els.length === 0 || !head) return [];
if (onlyBlank(els) || !head) return [];
els[0].insert = head;
return els;
......@@ -182,7 +181,7 @@ const rmTailSpace = (content) => {
if (!tail) els = [...els.slice(1)];
return tail;
});
if (els.length === 0 || !tail) return [];
if (onlyBlank(els) || !tail) return [];
els.reverse();
els[els.length - 1].insert = tail;
......@@ -194,12 +193,12 @@ const opsTailWithSymbol = (els, symbol) => {
};
const endingSymbol = (content, symbol) => {
if (content.length === 0) return [];
if (onlyBlank(content)) return [];
let els = rmHeadSpace(content);
els = rmTailSpace(els);
if (els.length === 0) return [];
if (onlyBlank(els)) return [];
return opsTailWithSymbol(els, symbol);
};
......@@ -217,7 +216,7 @@ const analysesContent = (products) => {
content = [...content, ...endingSymbol(data.ops, '; ')];
});
});
if (content.length === 0) return [];
if (onlyBlank(content)) return [];
content = rmOpsRedundantSpaceBreak(content);
content = [...content.slice(0, -1), { insert: '.' }];
return frontBreak(content);
......@@ -239,7 +238,7 @@ const dangContent = (el) => {
const DangerBlock = ({el}) => {
const block = dangContent(el);
return <QuillViewer value={{ops: block}} />
return block.length > 0 ? <QuillViewer value={{ops: block}} /> : null;
};
const ContentBlock = ({el}) => {
......
......@@ -81,7 +81,7 @@ module Reporter
end
end
def remove_redundant_space_break(ops)
def remove_redundant_space_break(ops) # ensure one line
ops.map.with_index do |op, i|
op["insert"] = op["insert"].gsub(/[\u00A0\s]{2,}/, " ")
op["insert"] = op["insert"].lstrip if i == 0
......
......@@ -310,7 +310,8 @@ module Reporter
def observation
delta_obs = obj.observation.deep_stringify_keys['ops']
clean_obs = { 'ops' => remove_redundant_space_break(delta_obs) }
one_line_obs = remove_redundant_space_break(delta_obs)
clean_obs = { 'ops' => rm_head_tail_space(one_line_obs) }
Sablon.content(:html, Delta.new(clean_obs, @font_family).getHTML)
end
......@@ -343,13 +344,15 @@ module Reporter
def observation_delta
delta_obs = obj.observation.deep_stringify_keys['ops']
clean_obs = remove_redundant_space_break(delta_obs)
clean_obs
one_line_obs = remove_redundant_space_break(delta_obs)
rm_head_tail_space(one_line_obs)
end
def obsv_tlc_delta
observation_delta + [{"insert"=>" "}] + tlc_delta + obsv_tlc_break_delta
tlc_delta_arr = tlc_delta
return [] if obsv_blank && tlc_delta_arr.blank?
observation_delta + [{"insert"=>"."}] +
[{"insert"=>" "}] + tlc_delta_arr + [{"insert"=>"\n"}]
end
def tlc_delta
......@@ -364,11 +367,6 @@ module Reporter
obsv_arr.join('').gsub(/\s+/, '').blank?
end
def obsv_tlc_break_delta
return [] if obsv_blank && tlc_delta.blank?
[{"insert"=>"\n"}]
end
def product_analyses_delta
delta = []
obj.products.each do |product|
......
......@@ -8,7 +8,8 @@ describe 'Reporter::Docx::DetailReaction instance' do
let(:rf) { 'correct tlc_rf' }
let(:t_sol) { 'correct tlc_solvents' }
let(:t_des) { 'correct tlc_description' }
let(:obs) { { "ops" => [{"insert" => "correct observation" }] } }
let!(:correct_obsv) { "correct observation" }
let(:obs) { { "ops" => [{"insert" => "#{correct_obsv}\n" }] } }
let(:des) { { "ops" => [{"insert" => "correct description" }] } }
let(:prev_index) { 5 }
let(:equiv) { 0.88 }
......@@ -197,7 +198,8 @@ describe 'Reporter::Docx::DetailReaction instance' do
{"insert"=>"} = #{(equiv * 100).to_i}% (0.000 g, 0.000 mmol)"},
{"insert"=>"."},
{"insert"=>"\n"},
{"insert"=>"correct observation"},
{"insert"=>"#{correct_obsv}"},
{"insert"=>"."},
{"insert"=>" "},
{"attributes"=>{"italic"=>true}, "insert"=>"R"},
{"attributes"=>{"italic"=>true, "script"=>"sub"}, "insert"=>"f"},
......
Markdown is supported
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