Commit 63473fa5 authored by Marco Sehrer's avatar Marco Sehrer
Browse files

Merge pull request #38 from ninjaconcept/38-add-description-attribute-into-samples

Add description attribute into Samples
parents c067b21f ff7352ac
......@@ -34,12 +34,14 @@ module Chemotion
requires :name, type: String, desc: "Sample name"
requires :amount_value, type: Float, desc: "Sample amount_value"
requires :amount_unit, type: String, desc: "Sample amount_unit"
requires :description, type: String, desc: "Sample description"
end
put ':id' do
Sample.find(params[:id]).update({
name: params[:name],
amount_value: params[:amount_value],
amount_unit: params[:amount_unit]
amount_unit: params[:amount_unit],
description: params[:description]
})
end
......
......@@ -47,7 +47,8 @@ export default class SampleDetails extends React.Component {
id: this.state.id,
name: this.state.sample.name,
amount_value: this.state.sample.amount_value,
amount_unit: this.state.sample.amount_unit
amount_unit: this.state.sample.amount_unit,
description: this.state.sample.description
})
}
......@@ -59,6 +60,14 @@ export default class SampleDetails extends React.Component {
});
}
handleDescriptionChanged(e) {
let sample = this.state.sample;
sample.description = this.refs.descriptionInput.getValue();
this.setState({
sample: sample
});
}
handleAmountChanged(amount) {
let sample = this.state.sample;
sample.amount_unit = amount.unit;
......@@ -94,6 +103,8 @@ export default class SampleDetails extends React.Component {
let sampleAmount = sample.amount_value && sample.amount_unit ? `(${sample.amount_value} ${sample.amount_unit})` : '';
let svgPath = sample.molecule_svg ? `/assets/${sample.molecule_svg}` : '';
let MarkdownTextarea = require('react-markdown-textarea');
return (
<div>
<Panel header="Sample Details" bsStyle='primary'>
......@@ -125,7 +136,12 @@ export default class SampleDetails extends React.Component {
convertValueFromUnitToNextUnit={(unit, nextUnit, value) => ajaxCall(unit, nextUnit, value)}
onChange={(amount) => this.handleAmountChanged(amount)}
/>
<Input type='textarea' label='Description' rows={3} />
<Input type="textarea" label="Description" ref="descriptionInput"
placeholder={sample.description}
value={sample.description}
onChange={(e) => this.handleDescriptionChanged(e)}
rows={3}
/>
<ButtonToolbar>
<Button bsStyle="primary" onClick={this.closeDetails.bind(this)}>Back</Button>
<Button bsStyle="warning" onClick={this.updateSample.bind(this)}>Update Sample</Button>
......
......@@ -44,7 +44,8 @@ export default class SamplesFetcher {
body: JSON.stringify({
name: paramObj.name,
amount_value: paramObj.amount_value,
amount_unit: paramObj.amount_unit
amount_unit: paramObj.amount_unit,
description: paramObj.description
})
})
......
......@@ -9,6 +9,6 @@ class Sample < ActiveRecord::Base
has_many :reactions_as_starting_material, through: :reactions_starting_material_samples, source: :reaction
has_many :reactions_as_reactant, through: :reactions_reactant_samples, source: :reaction
has_many :reactions_as_product, through: :reactions_product_samples, source: :reaction
composed_of :amount, mapping: %w(amount_value, amount_unit)
composed_of :amount, mapping: %w(amount_value, amount_unit)
end
class SampleSerializer < ActiveModel::Serializer
attributes :id, :type, :name, :created_at, :collection_labels, :amount_value, :amount_unit, :molecule_svg
attributes :id, :type, :name, :description, :created_at, :collection_labels, :amount_value, :amount_unit, :molecule_svg
def created_at
object.created_at.strftime("%d.%m.%Y, %H:%M")
......
class AddDescriptionAttrToSamples < ActiveRecord::Migration
def change
add_column :samples, :description, :text, :default => ""
end
end
......@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20150728120436) do
ActiveRecord::Schema.define(version: 20150817085601) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
......@@ -83,8 +83,9 @@ ActiveRecord::Schema.define(version: 20150728120436) do
t.string "name"
t.float "amount_value"
t.string "amount_unit"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.text "description", default: ""
end
create_table "users", force: :cascade do |t|
......
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