Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
gy4443
chemotion_eln_server
Commits
63473fa5
Commit
63473fa5
authored
Aug 17, 2015
by
Marco Sehrer
Browse files
Merge pull request #38 from ninjaconcept/38-add-description-attribute-into-samples
Add description attribute into Samples
parents
c067b21f
ff7352ac
Changes
7
Hide whitespace changes
Inline
Side-by-side
app/api/chemotion/sample_api.rb
View file @
63473fa5
...
...
@@ -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
...
...
app/assets/javascripts/components/SampleDetails.js
View file @
63473fa5
...
...
@@ -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
>
...
...
app/assets/javascripts/components/fetchers/SamplesFetcher.js
View file @
63473fa5
...
...
@@ -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
})
})
...
...
app/models/sample.rb
View file @
63473fa5
...
...
@@ -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
app/serializers/sample_serializer.rb
View file @
63473fa5
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"
)
...
...
db/migrate/20150817085601_add_description_attr_to_samples.rb
0 → 100644
View file @
63473fa5
class
AddDescriptionAttrToSamples
<
ActiveRecord
::
Migration
def
change
add_column
:samples
,
:description
,
:text
,
:default
=>
""
end
end
db/schema.rb
View file @
63473fa5
...
...
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
20150
728120436
)
do
ActiveRecord
::
Schema
.
define
(
version:
20150
817085601
)
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
|
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment