Commit c2268b17 authored by PiTrem's avatar PiTrem
Browse files

fixed double name column sorted

cleaned column list
fix reverted sorting
fix sorting when selection type not sample
added molecule_name field
clean attribute selection
closes #255
parent e1a5ae2f
...@@ -13,15 +13,15 @@ module Chemotion ...@@ -13,15 +13,15 @@ module Chemotion
def excluded_field def excluded_field
%w( %w(
id molecule_id created_by deleted_at id molecule_id created_by deleted_at identifier molecule_name_id
user_id fingerprint_id sample_svg_file xref user_id fingerprint_id sample_svg_file xref impurities ancestry
) )
end end
def included_field def included_field
%w( %w(
molecule.cano_smiles molecule.sum_formular molecule.cano_smiles molecule.sum_formular molecule_name
molecule.inchistring molecule.molecular_weight molecule.inchistring molecule.molecular_weight molecule.inchikey
) )
end end
...@@ -31,11 +31,11 @@ module Chemotion ...@@ -31,11 +31,11 @@ module Chemotion
elements = "#{type}s".to_sym elements = "#{type}s".to_sym
if checkedAll if checkedAll
Collection.find(currentCollection) Collection.find(currentCollection)
.send(elements).where.not(id: uncheckedIds) .send(elements).where.not(id: uncheckedIds).order(updated_at: :desc)
else else
Collection.find(currentCollection) Collection.find(currentCollection)
.send(elements).where(id: checkedIds) .send(elements).where(id: checkedIds)
.order("position(samples.id::text in '#{checkedIds}')") .order("position(#{type}s.id::text in '#{checkedIds}')")
end end
end end
...@@ -69,7 +69,7 @@ module Chemotion ...@@ -69,7 +69,7 @@ module Chemotion
requires :uncheckedIds, type: Array requires :uncheckedIds, type: Array
requires :checkedAll, type: Boolean requires :checkedAll, type: Boolean
requires :currentCollection, type: Integer requires :currentCollection, type: Integer
requires :removedColumns, type: Array requires :removedColumns, type: Array[String]
requires :exportType, type: Integer requires :exportType, type: Integer
end end
post :export_samples_from_selections do post :export_samples_from_selections do
...@@ -101,7 +101,7 @@ module Chemotion ...@@ -101,7 +101,7 @@ module Chemotion
type, checkedAll, checkedIds, uncheckedIds, currentCollection type, checkedAll, checkedIds, uncheckedIds, currentCollection
) )
samples = if type == 'sample' samples = if type == 'sample'
elements.includes(:molecule) elements.includes([:molecule,:molecule_name])
elsif type == 'reaction' elsif type == 'reaction'
elements.map { |r| elements.map { |r|
r.starting_materials + r.reactants + r.products r.starting_materials + r.reactants + r.products
......
...@@ -14,28 +14,30 @@ export default class ModalExport extends React.Component { ...@@ -14,28 +14,30 @@ export default class ModalExport extends React.Component {
columns: [ columns: [
{value: "Image", text: "image", checked: true}, {value: "Image", text: "image", checked: true},
{value: "name", text: "name", checked: true}, {value: "name", text: "name", checked: true},
{value: "description", text: "description", checked: true}, {value: "molecule_name", text: "molecule name", checked: true},
{value: "cano_smiles", text: "canonical smiles", checked: true}, {value: "cano_smiles", text: "canonical smiles", checked: true},
{value: "inchistring", text: "InChIstring", checked: true},
{value: "inchikey", text: "InChIkey", checked: true},
{value: "sum_formular", text: "sum formula", checked: true}, {value: "sum_formular", text: "sum formula", checked: true},
{value: "inchistring", text: "inchistring", checked: true}, {value: "external_label", text: "external label", checked: false},
{value: "short_label", text: "short label", checked: false},
{value: "description", text: "description", checked: true},
{value: "real_amount_value,real_amount_unit", text: "real amount", checked: false},
{value: "target_amount_value, target_amount_unit", text: "target amount", checked: false}, {value: "target_amount_value, target_amount_unit", text: "target amount", checked: false},
{value: "created_at", text: "created at", checked: false}, {value: "molarity_value, molarity_unit", text: "molarity", checked: false},
{value: "updated_at", text: "updated at", checked: false}, {value: "density", text: "density", checked: false},
{value: "molfile", text: "molfile", checked: false}, {value: "molfile", text: "molfile", checked: false},
{value: "purity", text: "purity", checked: false}, {value: "purity", text: "purity", checked: false},
{value: "solvent", text: "solvent", checked: false}, {value: "solvent", text: "solvent", checked: false},
{value: "molarity_value, molarity_unit", text: "molarity", checked: false},
{value: "location", text: "location", checked: false}, {value: "location", text: "location", checked: false},
{value: "is_top_secret", text: "is top secret?", checked: false}, {value: "is_top_secret", text: "is top secret?", checked: false},
{value: "ancestry", text: "ancestry", checked: false}, // {value: "ancestry", text: "ancestry", checked: false},
{value: "external_label", text: "external label", checked: false},
{value: "short_label", text: "short label", checked: false},
{value: "real_amount_value,real_amount_unit", text: "real amount", checked: false},
{value: "imported_readout", text: "imported readout", checked: false}, {value: "imported_readout", text: "imported readout", checked: false},
{value: "identifier", text: "identifier", checked: false}, // {value: "identifier", text: "identifier", checked: false},
{value: "density", text: "density", checked: false},
{value: "melting_point", text: "melting point", checked: false}, {value: "melting_point", text: "melting point", checked: false},
{value: "boiling_point", text: "boiling point", checked: false}, {value: "boiling_point", text: "boiling point", checked: false},
{value: "created_at", text: "created at", checked: false},
{value: "updated_at", text: "updated at", checked: false},
{value: "molecular_weight", text: "molecular weight", checked: false}, {value: "molecular_weight", text: "molecular weight", checked: false},
], ],
checkedAllColumns: true, checkedAllColumns: true,
...@@ -94,7 +96,7 @@ export default class ModalExport extends React.Component { ...@@ -94,7 +96,7 @@ export default class ModalExport extends React.Component {
removedColumns() { removedColumns() {
const { columns } = this.state; const { columns } = this.state;
return this.chainedItems(columns); return this.chainedItems(columns).join().split(/\s*,\s*/);
} }
chainedItems(items) { chainedItems(items) {
......
...@@ -12,11 +12,11 @@ class Reporter::ExcelExport ...@@ -12,11 +12,11 @@ class Reporter::ExcelExport
def generate_file(default_excluded_field, default_included_field, removed_field = []) def generate_file(default_excluded_field, default_included_field, removed_field = [])
return -1 if @@sample_list.empty? || @@sample_list.first == nil return -1 if @@sample_list.empty? || @@sample_list.first == nil
header = process_header(default_excluded_field, default_included_field, removed_field)
return -1 if header.empty?
p = Axlsx::Package.new p = Axlsx::Package.new
p.workbook.styles.fonts.first.name = 'Calibri' p.workbook.styles.fonts.first.name = 'Calibri'
p.workbook.add_worksheet(:name => "ChemOffice") do |sheet| p.workbook.add_worksheet(:name => "ChemOffice") do |sheet|
header = process_header(default_excluded_field, default_included_field, removed_field)
sheet.add_row(fix_typo(header)) # Add header sheet.add_row(fix_typo(header)) # Add header
width = 0 width = 0
...@@ -70,6 +70,8 @@ class Reporter::ExcelExport ...@@ -70,6 +70,8 @@ class Reporter::ExcelExport
if is_molecule_attribute(key) if is_molecule_attribute(key)
asso = sample.send("molecule") asso = sample.send("molecule")
data = asso.attributes[key] data = asso.attributes[key]
elsif key == 'molecule_name' && (nid = sample.molecule_name_id)
data = MoleculeName.find_by(id: nid)&.attributes['name']
else else
data = sample.attributes[key] data = sample.attributes[key]
end end
...@@ -78,7 +80,7 @@ class Reporter::ExcelExport ...@@ -78,7 +80,7 @@ class Reporter::ExcelExport
end end
def is_molecule_attribute(key) def is_molecule_attribute(key)
["cano_smiles", "sum_formular", "inchistring", ["cano_smiles", "sum_formular", "inchistring", 'inchikey',
"molecular_weight"].index(key) "molecular_weight"].index(key)
end end
......
...@@ -26,7 +26,12 @@ class Reporter::SdfExport ...@@ -26,7 +26,12 @@ class Reporter::SdfExport
sample_mdf = sample.molfile.split(/#|END/).first + "END\n" sample_mdf = sample.molfile.split(/#|END/).first + "END\n"
(default_included_field - removed_field).each do |field| (default_included_field - removed_field).each do |field|
value = sample.molecule.send(field).to_s || "" if field == 'molecule_name' && (nid = sample.molecule_name_id)
value = sample.molecule_name.attributes['name']
else
value = sample.molecule.send(field).to_s || ""
end
next if value.empty? next if value.empty?
value = validate_value(value) value = validate_value(value)
......
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