Commit ff7352ac authored by Fernando D'Agostino's avatar Fernando D'Agostino
Browse files

Integrate description attribute with API and SampleDetails component

parent 5f23eb3f
......@@ -19,12 +19,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
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>
......
......@@ -43,7 +43,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
})
})
......
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
add_column :samples, :description, :text, :default => ""
end
end
......@@ -83,9 +83,9 @@ ActiveRecord::Schema.define(version: 20150817085601) 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.text "description"
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