Skip to content

Commit

Permalink
add rf_value tlc_solvents sample property in reaction properties and …
Browse files Browse the repository at this point in the history
…sample property
  • Loading branch information
adambasha0 committed Apr 4, 2022
1 parent 49f4d18 commit 8f14fb0
Show file tree
Hide file tree
Showing 24 changed files with 550 additions and 58 deletions.
3 changes: 2 additions & 1 deletion app/api/chemotion/reaction_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def update_materials_for_reaction(reaction, material_attributes, current_user)
subsample.real_amount_value = sample.real_amount_value
subsample.real_amount_unit = sample.real_amount_unit
subsample.metrics = sample.metrics

subsample.rf_value = sample.rf_value
# add new data container
# subsample.container = create_root_container
subsample.container = update_datamodel(sample.container) if sample.container
Expand Down Expand Up @@ -151,6 +151,7 @@ def update_materials_for_reaction(reaction, material_attributes, current_user)
existing_sample.short_label = sample.short_label if sample.short_label
existing_sample.short_label = fixed_label if fixed_label
existing_sample.name = sample.name if sample.name
existing_sample.rf_value = sample.rf_value if sample.rf_value

if r = existing_sample.residues[0]
r.assign_attributes sample.residues_attributes[0]
Expand Down
3 changes: 3 additions & 0 deletions app/api/chemotion/sample_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ class SampleAPI < Grape::API
optional :location, type: String, desc: "Sample location"
optional :molfile, type: String, desc: "Sample molfile"
optional :sample_svg_file, type: String, desc: "Sample SVG file"
optional :rf_value, type: Array[Hash], desc: "Sample rf value"
# optional :molecule, type: Hash, desc: "Sample molecule" do
# optional :id, type: Integer
# end
Expand Down Expand Up @@ -397,6 +398,7 @@ class SampleAPI < Grape::API
optional :molarity_unit, type: String, desc: "Sample real amount_unit"
requires :description, type: String, desc: "Sample description"
requires :purity, type: Float, desc: "Sample purity"
optional :rf_value, type: Array[Hash], desc: "Sample rf value"
# requires :solvent, type: String, desc: "Sample solvent"
optional :solvent, type: Array[Hash], desc: "Sample solvent"
requires :location, type: String, desc: "Sample location"
Expand Down Expand Up @@ -435,6 +437,7 @@ class SampleAPI < Grape::API
target_amount_unit: params[:target_amount_unit],
real_amount_value: params[:real_amount_value],
real_amount_unit: params[:real_amount_unit],
rf_value: params[:rf_value],
molarity_value: params[:molarity_value],
molarity_unit: params[:molarity_unit],
description: params[:description],
Expand Down
2 changes: 1 addition & 1 deletion app/api/entities/sample_attr_entity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class SampleAttrEntity < Grape::Entity
:pubchem_tag, :xref, :code_log,
:can_update, :can_copy, :can_publish, :molecule_name_hash, #:molecule_computed_props,
:showed_name, :user_labels, :decoupled,
:molecular_mass, :sum_formula
:molecular_mass, :sum_formula, :rf_value

def created_at
object.created_at.strftime("%d.%m.%Y, %H:%M")
Expand Down
3 changes: 2 additions & 1 deletion app/api/helpers/report_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,8 @@ def build_sql_reaction_sample(columns, c_id, ids, checkedAll = false)
updated_at: ['s.updated_at', nil, 0],
# deleted_at: ['wp.deleted_at', nil, 10],
molecule_name: ['mn."name"', '"molecule name"', 1],
molarity_value: ['s."molarity_value"', '"molarity_value"', 0]
molarity_value: ['s."molarity_value"', '"molarity_value"', 0],
rf_value: ['s."rf_value"', '"rf_value"', 0]
},
sample_id: {
external_label: ['s.external_label', '"sample external label"', 0],
Expand Down
1 change: 1 addition & 0 deletions app/models/sample.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
# molecular_mass :float
# sum_formula :string
# solvent :jsonb
# rf_value :jsonb
#
# Indexes
#
Expand Down
11 changes: 9 additions & 2 deletions app/packs/src/components/ReactionDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ export default class ReactionDetails extends Component {
this.handleSubmit = this.handleSubmit.bind(this);
this.onTabPositionChanged = this.onTabPositionChanged.bind(this);
this.handleSegmentsChange = this.handleSegmentsChange.bind(this);
this.handleTlcChange = this.handleTlcChange.bind(this);

if(!reaction.reaction_svg_file) {
this.updateReactionSvg();
}
Expand Down Expand Up @@ -153,6 +155,11 @@ export default class ReactionDetails extends Component {
this.handleReactionChange(newReaction, options);
}

handleTlcChange() {
const { reaction } = this.state;
this.handleReactionChange(reaction, false);
}

handleProductClick(product) {
const uri = Aviator.getCurrentURI();
const uriArray = uri.split(/\//);
Expand Down Expand Up @@ -407,14 +414,14 @@ export default class ReactionDetails extends Component {
reaction={reaction}
onReactionChange={(reaction, options) => this.handleReactionChange(reaction, options)}
onInputChange={(type, event) => this.handleInputChange(type, event)}
/>
/>
</Tab>
),
properties: (
<Tab eventKey="properties" title="Properties" key={`properties_${reaction.id}`}>
<ReactionDetailsProperties
reaction={reaction}
onReactionChange={r => this.handleReactionChange(r)}
onChange={this.handleTlcChange}
onInputChange={(type, event) => this.handleInputChange(type, event)}
key={reaction.checksum}
/>
Expand Down
106 changes: 62 additions & 44 deletions app/packs/src/components/ReactionDetailsProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { Component } from 'react';
import PropTypes from 'prop-types';
import {
Row, Col, FormGroup, ControlLabel, FormControl, MenuItem,
ListGroupItem, ListGroup, InputGroup, DropdownButton
ListGroupItem, ListGroup, InputGroup, DropdownButton, OverlayTrigger, Tooltip
} from 'react-bootstrap';
import Select from 'react-select';
import 'moment-precise-range-plugin';
Expand All @@ -13,6 +13,8 @@ import StringTag from './StringTag';
import { solventsTL } from './utils/reactionPredefined';
import OlsTreeSelect from './OlsComponent';
import { permitOn } from './common/uis';
import ReactionTlcSection from './ReactionTlcSection';
import Sample from './models/Sample';

export default class ReactionDetailsProperties extends Component {
constructor(props) {
Expand Down Expand Up @@ -60,7 +62,7 @@ export default class ReactionDetailsProperties extends Component {
}

render() {
const { reaction } = this.props;
const { reaction, onChange } = this.props;
const solventsItems = solventsTL.map((x, i) => {
const val = Object.keys(x)[0];
return (
Expand All @@ -76,6 +78,53 @@ export default class ReactionDetailsProperties extends Component {
</MenuItem>
);

const oldTlcRow = (reaction.rf_value || reaction.tlc_solvents) ? (
<Row>
<OverlayTrigger placement="top" overlay={<Tooltip id="oldTlc">please enter this solvent data to the tlc section above of the respective sample</Tooltip>}>
<Col md={6}>
<FormGroup>
<ControlLabel>Solvents (parts)</ControlLabel>
<FormGroup>
<InputGroup>
<DropdownButton
disabled={permitOn(reaction)}
componentClass={InputGroup.Button}
id="solvents_dd"
title=""
onSelect={this.handleOnSolventSelect}
>
{ solventsItems }
</DropdownButton>
<FormControl
style={{ zIndex: 0 }}
type="text"
value={reaction.tlc_solvents || ''}
disabled={permitOn(reaction) || reaction.isMethodDisabled('tlc_solvents')}
placeholder="Solvents as parts..."
onChange={event => this.props.onInputChange('tlc_solvents', event)}
/>
</InputGroup>
</FormGroup>
</FormGroup>
</Col>
</OverlayTrigger>
<OverlayTrigger placement="top" overlay={<Tooltip id="oldTlc">please enter this rf value to the tlc section above of the respective sample</Tooltip>}>
<Col md={6}>
<FormGroup>
<ControlLabel>RF Value</ControlLabel>
<FormControl
type="text"
value={reaction.rf_value || ''}
disabled={permitOn(reaction) || reaction.isMethodDisabled('rf_value')}
placeholder="RF Value..."
onChange={event => this.props.onInputChange('rfValue', event)}
/>
</FormGroup>
</Col>
</OverlayTrigger>
</Row>
) : null;

return (
<div>
<ListGroup>
Expand Down Expand Up @@ -109,57 +158,25 @@ export default class ReactionDetailsProperties extends Component {
</Col>
</Row>
</ListGroupItem>

<ListGroupItem>
<h4 className="list-group-item-heading" >TLC-Control</h4>
<h4 className="list-group-item-heading" >TLC Control</h4>
<Row>
<Col md={6}>
<FormGroup>
<ControlLabel>Solvents (parts)</ControlLabel>
<FormGroup>
<InputGroup>
<DropdownButton
disabled={!permitOn(reaction)}
componentClass={InputGroup.Button}
id="solvents_dd"
title=""
onSelect={this.handleOnSolventSelect}
>
{ solventsItems }
</DropdownButton>
<FormControl
style={{ zIndex: 0 }}
type="text"
value={reaction.tlc_solvents || ''}
disabled={!permitOn(reaction) || reaction.isMethodDisabled('tlc_solvents')}
placeholder="Solvents as parts..."
onChange={event => this.props.onInputChange('tlc_solvents', event)}
/>
</InputGroup>
</FormGroup>
</FormGroup>
</Col>
<Col md={6}>
<FormGroup>
<ControlLabel>Rf-Value</ControlLabel>
<FormControl
type="text"
value={reaction.rf_value || ''}
disabled={!permitOn(reaction) || reaction.isMethodDisabled('rf_value')}
placeholder="Rf-Value..."
onChange={event => this.props.onInputChange('rfValue', event)}
/>
</FormGroup>
</Col>
<ReactionTlcSection
reaction={reaction}
onChange={onChange}
/>
</Row>
{oldTlcRow}
<Row>
<Col md={12}>
<FormGroup>
<ControlLabel>TLC-Description</ControlLabel>
<ControlLabel>TLC Description</ControlLabel>
<FormControl
componentClass="textarea"
value={reaction.tlc_description || ''}
disabled={!permitOn(reaction) || reaction.isMethodDisabled('tlc_description')}
placeholder="TLC-Description..."
placeholder="TLC Description..."
onChange={event => this.props.onInputChange('tlcDescription', event)}
/>
</FormGroup>
Expand All @@ -175,5 +192,6 @@ export default class ReactionDetailsProperties extends Component {
ReactionDetailsProperties.propTypes = {
reaction: PropTypes.object,
onReactionChange: PropTypes.func,
onInputChange: PropTypes.func
onInputChange: PropTypes.func,
onChange: PropTypes.func.isRequired
};
88 changes: 88 additions & 0 deletions app/packs/src/components/ReactionTlcDetails.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { Tab, Tabs } from 'react-bootstrap';
import Reaction from './models/Reaction';
import SampleTlcControl from './SampleTlcControl';

// eslint-disable-next-line react/prefer-stateless-function
export default class ReactionTlcDetails extends Component {

constructor(props) {
super(props);

const { reaction } = props;
this.state = {
// eslint-disable-next-line object-shorthand
reaction: reaction
};
}

// eslint-disable-next-line class-methods-use-this
title(sample) {
const moleculeLabel = sample.molecule_name_hash ? sample.molecule_name_hash.label : sample.molecule_iupac_name;
// eslint-disable-next-line prefer-template
const moleculeLabelMiniString = moleculeLabel ? moleculeLabel.substring(0, 12) + '...' : moleculeLabel;
const sampleTabLabel = (moleculeLabel && moleculeLabel.length <= 12) ? moleculeLabel : moleculeLabelMiniString;
return (
<span
className="pseudo-link"
style={{ cursor: 'pointer' }}
title={moleculeLabel || sample.name}
>
<i />{sampleTabLabel}
</span>
);
}

allReactionMaterials() {
const { products, reactants, starting_materials } = this.state.reaction;
const respectiveSamples = [];
const { onChange, tabType } = this.props;
if (tabType === 'Starting Materials') {
respectiveSamples.push(...starting_materials);
} else if (tabType === 'Reactants') {
respectiveSamples.push(...reactants);
} else {
respectiveSamples.push(...products);
}

const tabs = respectiveSamples.map((sample) => {
return (
<Tab
key={sample.id}
eventKey={sample.id}
title={this.title(sample)}
>
<SampleTlcControl
sample={sample}
onChange={onChange}
/>
</Tab>
);
});

return (
<Tabs
id="TlcTabs"
style={{ marginTop: '2px' }}
>
{tabs}
</Tabs>
);
}

render() {
return (
<div>
{this.allReactionMaterials()}
</div>
);
}
}

ReactionTlcDetails.propTypes = {
reaction: PropTypes.instanceOf(Reaction).isRequired,
onChange: PropTypes.func.isRequired,
tabType: PropTypes.string.isRequired
};

Loading

0 comments on commit 8f14fb0

Please sign in to comment.