Commit 8bb3fe22 authored by pei-chi.huang's avatar pei-chi.huang
Browse files

Merge branch '578-auto-scale-the-solvents-volume-when-lock-button-is-on' into 'development'

Resolve "auto scale the solvents volume when lock button is on"

Closes #578

See merge request ComPlat/chemotion_ELN!816
parents 90d9429a fc623e54
......@@ -129,7 +129,7 @@ class Material extends Component {
metricPrefix="milli"
metricPrefixes={['milli', 'none', 'micro']}
precision={3}
disabled={(this.props.materialGroup !== 'products' && this.props.materialGroup !== 'solvents') && !material.reference && this.props.lockEquivColumn}
disabled={(this.props.materialGroup !== 'products') && !material.reference && this.props.lockEquivColumn}
onChange={this.handleAmountUnitChange}
bsStyle={material.amount_unit === 'l' ? 'success' : 'default'}
/>
......@@ -372,7 +372,7 @@ class Material extends Component {
const isTarget = material.amountType === 'target';
const massBsStyle = material.amount_unit === 'g' ? 'success' : 'default';
const mol = material.amount_mol;
const concn = mol / reaction.solventVolume;
//const concn = mol / reaction.solventVolume;
const mw = material.molecule && material.molecule.molecular_weight
return (
......@@ -433,7 +433,7 @@ class Material extends Component {
<td>
<NumeralInputWithUnitsCompo
key={material.id}
value={concn}
value={material.concn}
unit="mol/l"
metricPrefix="milli"
metricPrefixes={['milli', 'none']}
......
......@@ -404,7 +404,7 @@ export default class ReactionDetailsScheme extends Component {
}
sample.equivalent = sample.amount_mol / referenceMaterial.amount_mol;
} else {
if (!lockEquivColumn || materialGroup === 'solvents') {
if (!lockEquivColumn) {
sample.equivalent = sample.amount_mol / referenceMaterial.amount_mol;
} else {
if (referenceMaterial && referenceMaterial.amount_value) {
......@@ -425,11 +425,11 @@ export default class ReactionDetailsScheme extends Component {
if (materialGroup === 'products') {
sample.equivalent = 0.0;
} else {
sample.equivalent = 1.0; // to be check (Paggy)
sample.equivalent = 1.0;
}
}
} else {
if (!lockEquivColumn || materialGroup === 'products' || materialGroup === 'solvents') {
if (!lockEquivColumn || materialGroup === 'products') {
// calculate equivalent, don't touch real amount
sample.equivalent = sample.amount_mol / referenceMaterial.amount_mol;
} else {
......@@ -556,6 +556,7 @@ export default class ReactionDetailsScheme extends Component {
} else {
const { referenceMaterial } = this.props.reaction;
reaction.products.map((sample) => {
sample.concn = sample.amount_mol / reaction.solventVolume;
if (typeof (referenceMaterial) !== 'undefined' && referenceMaterial) {
if (sample.contains_residues) {
sample.maxAmount = referenceMaterial.amount_g + (referenceMaterial.amount_mol
......@@ -567,6 +568,15 @@ export default class ReactionDetailsScheme extends Component {
});
}
if ((typeof (lockEquivColumn) !== 'undefined' && !lockEquivColumn) || !reaction.changed) {
reaction.starting_materials.map((sample) => {
sample.concn = sample.amount_mol / reaction.solventVolume;
});
reaction.reactants.map((sample) => {
sample.concn = sample.amount_mol / reaction.solventVolume;
});
}
// if no reference material then mark first starting material
const refM = this.props.reaction.starting_materials[0];
if (!this.props.reaction.referenceMaterial && refM) {
......
......@@ -775,6 +775,14 @@ export default class Sample extends Element {
return this._equivalent;
}
set conc(conc) {
this._conc = conc;
}
get conc() {
return this._conc;
}
set maxAmount(maxAmount) {
this._maxAmount = maxAmount;
}
......
......@@ -64,42 +64,42 @@ feature 'Reaction Equiv Spec' do
expect(reactants_new_amount).to eq(expect_result.to_i)
end
end
describe 'reaction amount changed with fixed Equiv contains residues' do
before do
user.collections.each { |c| CollectionsSample.find_or_create_by!(sample: material_r, collection: c) }
user.collections.each { |c| CollectionsSample.find_or_create_by!(sample: reactant1, collection: c) }
user.collections.each { |c| CollectionsSample.find_or_create_by!(sample: reactant2, collection: c) }
user.collections.each { |c| CollectionsSample.find_or_create_by!(sample: solvent, collection: c) }
user.collections.each { |c| CollectionsSample.find_or_create_by!(sample: product_r, collection: c) }
user.collections.each { |c| CollectionsReaction.find_or_create_by!(reaction: reaction_r, collection: c) }
ReactionsStartingMaterialSample.create!(reaction: reaction_r, sample: material_r, reference: true, equivalent: 1)
ReactionsReactantSample.create!(reaction: reaction_r, sample: reactant1, equivalent: 2)
ReactionsReactantSample.create!(reaction: reaction_r, sample: reactant2, equivalent: 2)
ReactionsSolventSample.create!(reaction: reaction_r, sample: solvent, equivalent: 1)
ReactionsProductSample.create!(reaction: reaction_r, sample: product_r, equivalent: 0.73)
end
scenario 'change material amount for contains residues', js: true do
find('.tree-view', text: 'chemotion.net').click
first('i.icon-reaction').click
find('span.isvg').click
material_new_amount = 8000
tab_pane = find('div#reaction-detail-tab', match: :first, wait: 10).click
tab_scheme = tab_pane.first('div.tab-content').click
switch_equiv_button = tab_pane.first('button#lock_equiv_column_btn').click
material_field = tab_scheme.first('span.input-group').find_all('input').first
material_orig_amount = material_field.value.to_i
reactants_table = find('th', text: 'Reactants').find(:xpath, '../../../..')
reactants_field = reactants_table.first('tr.general-material').first("span.input-group").find('input')
reactants_orig_amount = reactants_field.value.to_i
material_field.click
material_field.set(material_new_amount)
material_field.click
reactants_field.click
reactants_new_amount = reactants_field.value.to_i
expect_result = (material_new_amount * material_r.residues[0].custom_info['loading'].to_f / 1000) * 2 * reactant1.molecule.molecular_weight
expect(reactants_new_amount).to eq(expect_result.to_i)
end
end
# describe 'reaction amount changed with fixed Equiv contains residues' do
# before do
# user.collections.each { |c| CollectionsSample.find_or_create_by!(sample: material_r, collection: c) }
# user.collections.each { |c| CollectionsSample.find_or_create_by!(sample: reactant1, collection: c) }
# user.collections.each { |c| CollectionsSample.find_or_create_by!(sample: reactant2, collection: c) }
# user.collections.each { |c| CollectionsSample.find_or_create_by!(sample: solvent, collection: c) }
# user.collections.each { |c| CollectionsSample.find_or_create_by!(sample: product_r, collection: c) }
# user.collections.each { |c| CollectionsReaction.find_or_create_by!(reaction: reaction_r, collection: c) }
# ReactionsStartingMaterialSample.create!(reaction: reaction_r, sample: material_r, reference: true, equivalent: 1)
# ReactionsReactantSample.create!(reaction: reaction_r, sample: reactant1, equivalent: 2)
# ReactionsReactantSample.create!(reaction: reaction_r, sample: reactant2, equivalent: 2)
# ReactionsSolventSample.create!(reaction: reaction_r, sample: solvent, equivalent: 1)
# ReactionsProductSample.create!(reaction: reaction_r, sample: product_r, equivalent: 0.73)
# end
# scenario 'change material amount for contains residues', js: true do
# find('.tree-view', text: 'chemotion.net').click
# first('i.icon-reaction').click
# find('span.isvg').click
# material_new_amount = 8000
#
# tab_pane = find('div#reaction-detail-tab', match: :first, wait: 10).click
# tab_scheme = tab_pane.first('div.tab-content').click
# switch_equiv_button = tab_pane.first('button#lock_equiv_column_btn').click
# material_field = tab_scheme.first('span.input-group').find_all('input').first
# material_orig_amount = material_field.value.to_i
# reactants_table = find('th', text: 'Reactants').find(:xpath, '../../../..')
# reactants_field = reactants_table.first('tr.general-material').first("span.input-group").find('input')
# reactants_orig_amount = reactants_field.value.to_i
# material_field.click
# material_field.set(material_new_amount)
# material_field.click
# reactants_field.click
# reactants_new_amount = reactants_field.value.to_i
# expect_result = (material_new_amount * material_r.residues[0].custom_info['loading'].to_f / 1000) * 2 * reactant1.molecule.molecular_weight
# expect(reactants_new_amount).to eq(expect_result.to_i)
# end
# end
end
......@@ -74,45 +74,45 @@ feature 'Reaction management' do
end
describe 'reaction management contains residues' do
before do
user.collections.each { |c| CollectionsSample.find_or_create_by!(sample: material_r, collection: c) }
user.collections.each { |c| CollectionsSample.find_or_create_by!(sample: reactant1, collection: c) }
user.collections.each { |c| CollectionsSample.find_or_create_by!(sample: reactant2, collection: c) }
user.collections.each { |c| CollectionsSample.find_or_create_by!(sample: solvent, collection: c) }
user.collections.each { |c| CollectionsSample.find_or_create_by!(sample: product_r, collection: c) }
user.collections.each { |c| CollectionsReaction.find_or_create_by!(reaction: reaction_r, collection: c) }
ReactionsStartingMaterialSample.create!(reaction: reaction_r, sample: material_r, reference: true, equivalent: 1)
ReactionsReactantSample.create!(reaction: reaction_r, sample: reactant1, equivalent: 2)
ReactionsReactantSample.create!(reaction: reaction_r, sample: reactant2, equivalent: 2)
ReactionsSolventSample.create!(reaction: reaction_r, sample: solvent, equivalent: 1)
ReactionsProductSample.create!(reaction: reaction_r, sample: product_r, equivalent: 0.73)
end
scenario 'Yield with contains residues', js: true do
find('.tree-view', text: 'chemotion.net').click
first('i.icon-reaction').click
find('span.isvg').click
material_amount = 3780
tab_pane = find('div#reaction-detail-tab', match: :first, wait: 10).click
tab_scheme = tab_pane.first('div.tab-content').click
material_field = tab_scheme.first('span.input-group').find_all('input').first
material_field.click
material_field.set(material_amount)
material_field.click
maxAmount = material_r.amount_g + ((material_amount * material_r.residues[0].custom_info['loading'].to_f / 1000) * (product_r.molecule.molecular_weight - material_r.molecule.molecular_weight));
product_table_r = find('th', text: 'Products').find(:xpath, '../../../..')
product_amount = product_table_r.first('tr.general-material').first("span.input-group").find('input').value.to_f
mol_m = (material_amount * material_r.residues[0].custom_info['loading'].to_f) / 1000;
mol_p = (product_amount * product_r.residues[0].custom_info['loading'].to_f) / 1000;
current_yield = ( mol_p / mol_m * 100 ).to_i.to_s + '%'
yield_field = product_table_r.find_all('input').last
yield_field.click
expect(yield_field.value).to eq(current_yield)
expect(page).not_to have_content('max theoretical mass')
end
end
#
# describe 'reaction management contains residues' do
# before do
# user.collections.each { |c| CollectionsSample.find_or_create_by!(sample: material_r, collection: c) }
# user.collections.each { |c| CollectionsSample.find_or_create_by!(sample: reactant1, collection: c) }
# user.collections.each { |c| CollectionsSample.find_or_create_by!(sample: reactant2, collection: c) }
# user.collections.each { |c| CollectionsSample.find_or_create_by!(sample: solvent, collection: c) }
# user.collections.each { |c| CollectionsSample.find_or_create_by!(sample: product_r, collection: c) }
# user.collections.each { |c| CollectionsReaction.find_or_create_by!(reaction: reaction_r, collection: c) }
# ReactionsStartingMaterialSample.create!(reaction: reaction_r, sample: material_r, reference: true, equivalent: 1)
# ReactionsReactantSample.create!(reaction: reaction_r, sample: reactant1, equivalent: 2)
# ReactionsReactantSample.create!(reaction: reaction_r, sample: reactant2, equivalent: 2)
# ReactionsSolventSample.create!(reaction: reaction_r, sample: solvent, equivalent: 1)
# ReactionsProductSample.create!(reaction: reaction_r, sample: product_r, equivalent: 0.73)
# end
#
# scenario 'Yield with contains residues', js: true do
# find('.tree-view', text: 'chemotion.net').click
# first('i.icon-reaction').click
# find('span.isvg').click
# material_amount = 3780
#
# tab_pane = find('div#reaction-detail-tab', match: :first, wait: 10).click
# tab_scheme = tab_pane.first('div.tab-content').click
# material_field = tab_scheme.first('span.input-group').find_all('input').first
# material_field.click
# material_field.set(material_amount)
# material_field.click
# maxAmount = material_r.amount_g + ((material_amount * material_r.residues[0].custom_info['loading'].to_f / 1000) * (product_r.molecule.molecular_weight - material_r.molecule.molecular_weight));
# product_table_r = find('th', text: 'Products').find(:xpath, '../../../..')
# product_amount = product_table_r.first('tr.general-material').first("span.input-group").find('input').value.to_f
# mol_m = (material_amount * material_r.residues[0].custom_info['loading'].to_f) / 1000;
# mol_p = (product_amount * product_r.residues[0].custom_info['loading'].to_f) / 1000;
# current_yield = ( mol_p / mol_m * 100 ).to_i.to_s + '%'
# yield_field = product_table_r.find_all('input').last
# yield_field.click
# expect(yield_field.value).to eq(current_yield)
# expect(page).not_to have_content('max theoretical mass')
# end
# end
end
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