Commit 2b359798 authored by Marco Sehrer's avatar Marco Sehrer
Browse files

Integrate sample with molecule

parent 0c30ede2
......@@ -15,9 +15,9 @@ module Chemotion
get do
scope = if params[:collection_id]
Collection.where("user_id = ? OR shared_by_id = ?", current_user.id, current_user.id).find(params[:collection_id]).samples
Collection.where("user_id = ? OR shared_by_id = ?", current_user.id, current_user.id).find(params[:collection_id]).samples.includes(:molecule)
else
Sample
Sample.includes(:molecule)
end
paginate(scope)
end
......
......@@ -99,7 +99,7 @@ export default class ElementsTable extends React.Component {
</td>
)
let svgPath = `/assets/${element.molecule_svg}`;
let svgPath = `/assets/${element.molecule.molecule_svg_file}`;
optionalMoleculeColumn = (
<td className="molecule" margin="0" padding="0">
<SVG src={svgPath} className="molecule" key={element.id}/>
......
......@@ -108,7 +108,8 @@ export default class SampleDetails extends React.Component {
render() {
let sample = this.state.sample || {}
let sampleAmount = sample.amount_value && sample.amount_unit ? `(${sample.amount_value} ${sample.amount_unit})` : '';
let svgPath = sample.molecule_svg ? `/assets/${sample.molecule_svg}` : '';
let svgPath = sample.molecule && sample.molecule.molecule_svg_file ? `/assets/${sample.molecule.molecule_svg_file}` : '';
return (
<div>
<Panel header="Sample Details" bsStyle='primary'>
......
......@@ -2,6 +2,8 @@ class SampleSerializer < ActiveModel::Serializer
attributes :id, :type, :name, :description, :created_at, :collection_labels, :amount_value, :amount_unit, :molecule_svg
has_one :molecule
def created_at
object.created_at.strftime("%d.%m.%Y, %H:%M")
end
......@@ -15,7 +17,7 @@ class SampleSerializer < ActiveModel::Serializer
end
def molecule_svg
['168.svg','171.svg','361.svg'][id % 3]
molecule.molecule_svg_file
end
end
......@@ -22,15 +22,21 @@ reaction_6 = Reaction.create(name: 'Reaction 6')
# shared_collection_1 = Collection.create!(is_shared: true, label: 'My project with Hattori', user_id: hattori.id, shared_by_id: u.id)
# shared_collection_2 = Collection.create!(is_shared: true, label: 'My project with Momochi', user_id: momochi.id, shared_by_id: u.id)
# create some molecules
molecule_1 = Molecule.create!(inchikey: '1', iupac_name: 'MOL 168', molecule_svg_file: '168.svg')
molecule_2 = Molecule.create!(inchikey: '2', iupac_name: 'MOL 171', molecule_svg_file: '171.svg')
molecule_3 = Molecule.create!(inchikey: '3', iupac_name: 'MOL 361', molecule_svg_file: '361.svg')
# create some samples
sample_1 = Sample.create!(name: 'Sample 1')
sample_2 = Sample.create!(name: 'Sample 2')
sample_3 = Sample.create!(name: 'Sample 3')
sample_4 = Sample.create!(name: 'Sample 4')
sample_5 = Sample.create!(name: 'Sample 5')
sample_6 = Sample.create!(name: 'Sample 6')
sample_7 = Sample.create!(name: 'Sample 7')
sample_8 = Sample.create!(name: 'Sample 8')
sample_1 = Sample.create!(name: 'Sample 1', molecule: molecule_1)
sample_2 = Sample.create!(name: 'Sample 2', molecule: molecule_2)
sample_3 = Sample.create!(name: 'Sample 3', molecule: molecule_3)
sample_4 = Sample.create!(name: 'Sample 4', molecule: molecule_1)
sample_5 = Sample.create!(name: 'Sample 5', molecule: molecule_2)
sample_6 = Sample.create!(name: 'Sample 6', molecule: molecule_3)
sample_7 = Sample.create!(name: 'Sample 7', molecule: molecule_1)
sample_8 = Sample.create!(name: 'Sample 8', molecule: molecule_2)
# associate samples with reactions
ReactionsStartingMaterialSample.create!(reaction: reaction_1, sample: sample_1)
......
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