Commit e35c743c authored by pierre.tremouilhac's avatar pierre.tremouilhac
Browse files

Merge branch '268-import-samples-from-xlsx-with-correct-headers' into 'development'

Resolve "import samples from xlsx with correct headers"

Closes #268

See merge request ComPlat/chemotion_ELN!467
parents 380171e5 2aeff7d9
class RemoveDensityNullOnSample < ActiveRecord::Migration
def change
change_column_null :samples, :density, true
end
end
......@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20170928124229) do
ActiveRecord::Schema.define(version: 20171004132647) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
......@@ -589,7 +589,7 @@ ActiveRecord::Schema.define(version: 20170928124229) do
t.string "sample_svg_file"
t.integer "user_id"
t.string "identifier"
t.float "density", default: 0.0, null: false
t.float "density", default: 0.0
t.float "melting_point"
t.float "boiling_point"
t.integer "fingerprint_id"
......@@ -679,14 +679,14 @@ ActiveRecord::Schema.define(version: 20170928124229) do
t.datetime "deleted_at"
t.hstore "counters", default: {"samples"=>"0", "reactions"=>"0", "wellplates"=>"0"}, null: false
t.string "name_abbreviation", limit: 5
t.string "type", default: "Person"
t.boolean "is_templates_moderator", default: false, null: false
t.string "type", default: "Person"
t.string "reaction_name_prefix", limit: 3, default: "R"
t.hstore "layout", default: {"sample"=>"1", "screen"=>"4", "reaction"=>"2", "wellplate"=>"3", "research_plan"=>"5"}, null: false
t.string "confirmation_token"
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
t.string "unconfirmed_email"
t.hstore "layout", default: {"sample"=>"1", "screen"=>"4", "reaction"=>"2", "wellplate"=>"3", "research_plan"=>"5"}, null: false
t.integer "selected_device_id"
end
......
......@@ -180,12 +180,9 @@ class Import::ImportSamples
sample.molfile = molfile
sample.molecule = molecule
# Populate new sample
sample_attr = Sample.attribute_names
header.each_with_index do |field, index|
next if excluded_field.include?(field)
next unless sample_attr.include?(field)
field_assign = field + "="
sample.send(field_assign, row[field])
next unless included_fields.include?(field)
sample[field] = row[field]
end
sample.collections << Collection.find(collection_id)
sample.collections << Collection.get_all_collection_for_user(current_user_id)
......@@ -193,8 +190,46 @@ class Import::ImportSamples
processed.push(sample)
end
def excluded_field
["ancestry", "short_label"]
def excluded_fields
[
'id',
# 'name',
# 'target_amount_value',
# 'target_amount_unit',
'created_at',
'updated_at',
# 'description',
'molecule_id',
'molfile',
# 'purity',
# 'solvent',
'impurities',
# 'location',
'is_top_secret',
'ancestry',
# 'external_label',
'created_by',
'short_label',
# 'real_amount_value',
# 'real_amount_unit',
# 'imported_readout',
'deleted_at',
'sample_svg_file',
'user_id',
'identifier',
# 'density',
# 'melting_point',
# 'boiling_point',
'fingerprint_id',
'xref',
# 'molarity_value',
# 'molarity_unit',
'molecule_name_id',
]
end
def included_fields
Sample.attribute_names - excluded_fields
end
def error_process_file
......
Markdown is supported
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