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
8daa41aa
Commit
8daa41aa
authored
Oct 05, 2015
by
Florian Hübsch
Browse files
Refactor Sample Details, add external_label to samples.
parent
c76d142f
Changes
14
Expand all
Hide whitespace changes
Inline
Side-by-side
app/api/chemotion/sample_api.rb
View file @
8daa41aa
...
...
@@ -76,6 +76,7 @@ module Chemotion
params
do
requires
:id
,
type:
Integer
,
desc:
"Sample id"
optional
:name
,
type:
String
,
desc:
"Sample name"
optional
:external_label
,
type:
String
,
desc:
"Sample external label"
optional
:amount_value
,
type:
Float
,
desc:
"Sample amount_value"
optional
:amount_unit
,
type:
String
,
desc:
"Sample amount_unit"
optional
:description
,
type:
String
,
desc:
"Sample description"
...
...
@@ -106,6 +107,7 @@ module Chemotion
desc
"Create a sample"
params
do
requires
:name
,
type:
String
,
desc:
"Sample name"
optional
:external_label
,
type:
String
,
desc:
"Sample external label"
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"
...
...
app/assets/javascripts/components/SampleDetails.js
View file @
8daa41aa
This diff is collapsed.
Click to expand it.
app/assets/javascripts/components/actions/ElementActions.js
View file @
8daa41aa
...
...
@@ -152,6 +152,7 @@ class ElementActions {
id
:
'
_new_
'
,
type
:
'
sample
'
,
name
:
'
New Sample
'
,
external_label
:
''
,
amount_value
:
0
,
amount_unit
:
'
g
'
,
description
:
''
,
...
...
app/assets/javascripts/components/fetchers/SamplesFetcher.js
View file @
8daa41aa
import
'
whatwg-fetch
'
;
import
Sample
from
'
../models/Sample
'
;
import
SampleProxy
from
'
../proxies/SampleProxy
'
;
// TODO: SamplesFetcher also updates Samples and so on...naming?
...
...
@@ -11,7 +12,7 @@ export default class SamplesFetcher {
.
then
((
response
)
=>
{
return
response
.
json
()
}).
then
((
json
)
=>
{
return
new
Sample
(
json
.
sample
);
return
new
Sample
Proxy
(
json
.
sample
);
}).
catch
((
errorMessage
)
=>
{
console
.
log
(
errorMessage
);
});
...
...
@@ -52,6 +53,7 @@ export default class SamplesFetcher {
},
body
:
JSON
.
stringify
({
name
:
paramObj
.
name
,
external_label
:
paramObj
.
external_label
,
amount_value
:
paramObj
.
amount_value
,
amount_unit
:
paramObj
.
amount_unit
,
description
:
paramObj
.
description
,
...
...
@@ -79,6 +81,7 @@ export default class SamplesFetcher {
},
body
:
JSON
.
stringify
({
name
:
paramObj
.
name
,
external_label
:
paramObj
.
external_label
,
amount_value
:
paramObj
.
amount_value
,
amount_unit
:
paramObj
.
amount_unit
,
description
:
paramObj
.
description
,
...
...
app/assets/javascripts/components/models/Sample.js
View file @
8daa41aa
...
...
@@ -6,6 +6,11 @@ export default class Sample {
Object
.
assign
(
this
,
args
);
}
// methods regarding sharing and sample detail levels
isRestricted
()
{
return
this
.
is_restricted
;
}
get
name
()
{
return
this
.
_name
}
...
...
@@ -14,10 +19,42 @@ export default class Sample {
this
.
_name
=
name
}
get
external_label
()
{
return
this
.
_external_label
;
}
set
external_label
(
label
)
{
this
.
_external_label
=
label
;
}
get
location
()
{
return
this
.
_location
;
}
set
location
(
location
)
{
this
.
_location
=
location
;
}
get
description
()
{
return
this
.
_description
;
}
set
description
(
description
)
{
this
.
_description
=
description
;
}
get
impurities
()
{
return
this
.
_impurities
;
}
set
impurities
(
impurities
)
{
this
.
_impurities
=
impurities
;
}
get
amount
()
{
return
({
value
:
amount_value
,
unit
:
amount_unit
value
:
this
.
amount_value
,
unit
:
this
.
amount_unit
})
}
...
...
@@ -66,11 +103,17 @@ export default class Sample {
return
amount_mg
;
break
;
case
'
ml
'
:
return
amount_mg
/
this
.
molecule_density
;
break
;
let
molecule_density
=
this
.
molecule_density
;
if
(
molecule_density
)
{
return
amount_mg
/
this
.
molecule_density
;
break
;
}
case
'
mmol
'
:
return
amount_mg
*
this
.
purity
/
this
.
molecule_molecular_weight
;
break
;
let
molecule_molecular_weight
=
this
.
molecule_molecular_weight
if
(
molecule_molecular_weight
)
{
return
amount_mg
*
this
.
purity
/
molecule_molecular_weight
;
break
;
}
default
:
return
amount_mg
}
...
...
@@ -96,10 +139,38 @@ export default class Sample {
return
this
.
molecule
&&
this
.
molecule
.
density
||
1.0
}
set
molecule_density
(
density
)
{
this
.
molecule
.
density
=
density
;
}
get
molecule_molecular_weight
()
{
return
this
.
molecule
&&
this
.
molecule
.
molecular_weight
}
get
molecule_formula
()
{
return
this
.
molecule
&&
this
.
molecule
.
sum_formular
;
}
get
molecule_inchistring
()
{
return
this
.
molecule
&&
this
.
molecule
.
inchistring
;
}
get
molecule_boiling_point
()
{
return
this
.
molecule
&&
this
.
molecule
.
boiling_point
;
}
set
molecule_boiling_point
(
bp
)
{
this
.
molecule
.
boiling_point
=
bp
;
}
get
molecule_melting_point
()
{
return
this
.
molecule
&&
this
.
molecule
.
melting_point
;
}
set
molecule_melting_point
(
mp
)
{
this
.
molecule
.
melting_point
=
mp
;
}
get
purity
()
{
return
this
.
_purity
||
1.0
}
...
...
@@ -115,5 +186,4 @@ export default class Sample {
set
molecule
(
molecule
)
{
this
.
_molecule
=
new
Molecule
(
molecule
)
}
};
app/assets/javascripts/components/proxies/SampleProxy.js
0 → 100644
View file @
8daa41aa
import
Sample
from
'
../models/Sample
'
;
import
Molecule
from
'
../models/Molecule
'
;
export
default
class
SampleProxy
extends
Sample
{
constructor
(
args
)
{
super
(
args
)
let
sampleMethodsWithGetAndSet
=
[
'
name
'
,
'
external_label
'
,
'
location
'
,
'
description
'
,
'
impurities
'
,
'
amount_unit
'
,
'
amount_value
'
,
'
purity
'
]
sampleMethodsWithGetAndSet
.
forEach
((
m
)
=>
{
Object
.
defineProperty
(
this
,
m
,
{
get
:
function
()
{
return
this
.
methodOrRestrictionPattern
(
m
)
},
set
:
function
(
arg
)
{
super
[
m
]
=
arg
}
})
})
let
sampleMethodsWithGet
=
[
'
amount_mg
'
,
'
amount_ml
'
,
'
amount_mmol
'
]
sampleMethodsWithGet
.
forEach
((
m
)
=>
{
Object
.
defineProperty
(
this
,
m
,
{
get
:
function
()
{
return
this
.
methodOrRestrictionPattern
(
m
)
},
})
})
let
moleculeMethodsWithGetAndSet
=
[
'
molecule_density
'
,
'
molecule_boiling_point
'
,
'
molecule_melting_point
'
]
moleculeMethodsWithGetAndSet
.
forEach
((
m
)
=>
{
Object
.
defineProperty
(
this
,
m
,
{
get
:
function
()
{
return
this
.
methodOnMoleculeOrRestrictionPattern
(
m
)
},
set
:
function
(
arg
)
{
super
[
m
]
=
arg
}
})
})
let
moleculeMethodsWithGet
=
[
'
molecule_molecular_weight
'
,
'
molecule_formula
'
,
'
molecule_inchistring
'
]
moleculeMethodsWithGet
.
forEach
((
m
)
=>
{
Object
.
defineProperty
(
this
,
m
,
{
get
:
function
()
{
return
this
.
methodOnMoleculeOrRestrictionPattern
(
m
)
},
})
})
}
get
restrictionPattern
()
{
return
'
***
'
;
}
methodOrRestrictionPattern
(
method
)
{
if
(
super
.
isRestricted
&&
super
[
method
]
==
undefined
)
{
return
this
.
restrictionPattern
;
}
else
{
return
super
[
method
];
}
}
methodOnMoleculeOrRestrictionPattern
(
method
)
{
if
(
super
.
isRestricted
&&
super
.
molecule
==
undefined
)
{
return
this
.
restrictionPattern
;
}
else
{
return
super
[
method
];
}
}
get
amount
()
{
return
({
value
:
this
.
amount_value
,
unit
:
this
.
amount_unit
})
}
get
molecule
()
{
return
this
.
methodOrRestrictionPattern
(
'
molecule
'
);
}
set
molecule
(
molecule
)
{
super
.
molecule
=
new
Molecule
(
molecule
)
}
}
app/models/user.rb
View file @
8daa41aa
...
...
@@ -18,4 +18,8 @@ class User < ActiveRecord::Base
def
owns_unshared_collections?
(
collections
)
owns_collections?
(
collections
)
&&
collections
.
pluck
(
:is_shared
).
none?
end
def
name
"
#{
first_name
}
#{
last_name
}
"
end
end
app/proxies/sample_proxy.rb
View file @
8daa41aa
...
...
@@ -18,7 +18,7 @@ class SampleProxy
sample_attr
.
each
do
|
attr
|
new_sample_hash
[
attr
]
=
s
[
attr
]
end
new_sample_hash
[
:is_
scop
ed
]
=
true
new_sample_hash
[
:is_
restrict
ed
]
=
true
{
sample:
new_sample_hash
}
else
...
...
@@ -54,13 +54,18 @@ class SampleProxy
[
:id
,
:type
,
#:weight
:external_label
,
:amount_value
,
:amount_unit
]
when
1
[
:id
,
:type
,
:molecule
:external_label
,
:molecule
,
:amount_value
,
:amount_unit
]
when
2
...
...
app/serializers/sample_serializer.rb
View file @
8daa41aa
class
SampleSerializer
<
ActiveModel
::
Serializer
attributes
:id
,
:type
,
:name
,
:description
,
:created_at
,
:collection_labels
,
:amount_value
,
:amount_unit
,
:molfile
,
:purity
,
:solvent
,
:impurities
,
:location
,
:weight
,
:volume
,
:is_top_secret
,
:is_
scoped
:purity
,
:solvent
,
:impurities
,
:location
,
:weight
,
:volume
,
:is_top_secret
,
:is_
restricted
,
:external_label
has_one
:molecule
...
...
@@ -29,7 +29,7 @@ class SampleSerializer < ActiveModel::Serializer
object
.
volume
end
def
is_
scop
ed
def
is_
restrict
ed
false
end
end
app/serializers/user_serializer.rb
View file @
8daa41aa
...
...
@@ -2,7 +2,7 @@ class UserSerializer < ActiveModel::Serializer
attributes
:id
,
:name
,
:initials
def
name
"
#{
object
.
first_name
}
#{
object
.
last_name
}
"
object
.
name
end
def
initials
...
...
config/environments/production.rb
View file @
8daa41aa
...
...
@@ -29,7 +29,7 @@ Rails.application.configure do
# config.assets.css_compressor = :sass
# Do not fallback to assets pipeline if a precompiled asset is missed.
config
.
assets
.
compile
=
fals
e
config
.
assets
.
compile
=
tru
e
# Asset digests allow you to set far-future HTTP expiration dates on all assets,
# yet still be able to expire them through the digest params.
...
...
db/migrate/20151005151021_add_external_label_to_samples.rb
0 → 100644
View file @
8daa41aa
class
AddExternalLabelToSamples
<
ActiveRecord
::
Migration
def
change
add_column
:samples
,
:external_label
,
:string
,
default:
""
end
end
db/schema.rb
View file @
8daa41aa
...
...
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
2015100
4084416
)
do
ActiveRecord
::
Schema
.
define
(
version:
2015100
5151021
)
do
# These are extensions that must be enabled in order to support this database
enable_extension
"plpgsql"
...
...
@@ -145,17 +145,18 @@ ActiveRecord::Schema.define(version: 20151004084416) 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"
,
default:
""
t
.
datetime
"created_at"
,
null:
false
t
.
datetime
"updated_at"
,
null:
false
t
.
text
"description"
,
default:
""
t
.
integer
"molecule_id"
t
.
binary
"molfile"
t
.
float
"purity"
t
.
string
"solvent"
,
default:
""
t
.
string
"impurities"
,
default:
""
t
.
string
"location"
,
default:
""
t
.
boolean
"is_top_secret"
,
default:
false
t
.
string
"solvent"
,
default:
""
t
.
string
"impurities"
,
default:
""
t
.
string
"location"
,
default:
""
t
.
boolean
"is_top_secret"
,
default:
false
t
.
string
"ancestry"
t
.
string
"external_label"
,
default:
""
end
add_index
"samples"
,
[
"molecule_id"
],
name:
"index_samples_on_sample_id"
,
using: :btree
...
...
spec/api/collection_api_spec.rb
View file @
8daa41aa
...
...
@@ -9,7 +9,7 @@ describe Chemotion::CollectionAPI do
}
context
'authorized user logged in'
do
let
(
:user
)
{
create
(
:user
,
name:
'Musashi'
)
}
let
(
:user
)
{
create
(
:user
,
first_
name:
'Musashi'
,
last_name:
'M'
)
}
let
(
:u2
)
{
create
(
:user
)
}
let!
(
:c1
)
{
create
(
:collection
,
user:
user
,
is_shared:
false
)
}
let!
(
:c2
)
{
create
(
:collection
,
user:
user
,
shared_by_id:
user
.
id
,
is_shared:
true
)
}
...
...
@@ -304,7 +304,7 @@ describe Chemotion::CollectionAPI do
post
'/api/v1/collections/shared'
,
params
# naming convention for shared collections
c
=
Collection
.
find_by
(
label:
'My project with Musashi'
)
c
=
Collection
.
find_by
(
label:
'My project with Musashi
M
'
)
expect
(
c
).
to_not
be_nil
expect
(
c
.
user_id
).
to
eq
user
.
id
expect
(
c
.
samples
).
to
match_array
[
s1
,
s2
]
...
...
@@ -347,7 +347,7 @@ describe Chemotion::CollectionAPI do
it
'creates no shared collection'
do
post
'/api/v1/collections/shared'
,
params
c
=
Collection
.
find_by
(
label:
'My project with Musashi'
)
c
=
Collection
.
find_by
(
label:
'My project with Musashi
M
'
)
expect
(
c
).
to
be_nil
end
end
...
...
Write
Preview
Markdown
is supported
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