Commit 9deeb0f2 authored by pierre.tremouilhac's avatar pierre.tremouilhac
Browse files

Merge branch '255-export-samples-with-checkedall' into 'development'

Resolve "export samples with checkedAll"

Closes #255, #254, and #253

See merge request !450
parents b457a38f 59544eb2
......@@ -13,15 +13,15 @@ module Chemotion
def excluded_field
%w(
id molecule_id created_by deleted_at
user_id fingerprint_id sample_svg_file xref
id molecule_id created_by deleted_at identifier molecule_name_id
user_id fingerprint_id sample_svg_file xref impurities ancestry
)
end
def included_field
%w(
molecule.cano_smiles molecule.sum_formular
molecule.inchistring molecule.molecular_weight
molecule.cano_smiles molecule.sum_formular molecule_name
molecule.inchistring molecule.molecular_weight molecule.inchikey
)
end
......@@ -31,11 +31,11 @@ module Chemotion
elements = "#{type}s".to_sym
if checkedAll
Collection.find(currentCollection)
.send(elements).where.not(id: uncheckedIds)
.send(elements).where.not(id: uncheckedIds).order(updated_at: :desc)
else
Collection.find(currentCollection)
.send(elements).where(id: checkedIds)
.order("position(samples.id::text in '#{checkedIds}')")
.order("position(#{type}s.id::text in '#{checkedIds}')")
end
end
......@@ -69,7 +69,7 @@ module Chemotion
requires :uncheckedIds, type: Array
requires :checkedAll, type: Boolean
requires :currentCollection, type: Integer
requires :removedColumns, type: Array
requires :removedColumns, type: Array[String]
requires :exportType, type: Integer
end
post :export_samples_from_selections do
......@@ -101,7 +101,7 @@ module Chemotion
type, checkedAll, checkedIds, uncheckedIds, currentCollection
)
samples = if type == 'sample'
elements.includes(:molecule)
elements.includes([:molecule,:molecule_name])
elsif type == 'reaction'
elements.map { |r|
r.starting_materials + r.reactants + r.products
......
import React from 'react'
import {Table} from 'react-bootstrap'
import PropTypes from 'prop-types'
const CheckBoxs = ({items, toggleCheckbox, toggleCheckAll, checkedAll}) => {
const CheckBoxs = ({items, toggleCheckbox, toggleCheckAll, checkedAll, customClass = 'check-box-list' , customStyle = {}}) => {
let checkBoxs = items.map( (setting, i) => {
const {text, checked} = setting
return(
......@@ -11,7 +12,10 @@ const CheckBoxs = ({items, toggleCheckbox, toggleCheckAll, checkedAll}) => {
toggleCheckbox={toggleCheckbox.bind(null, text, checked)} />
)
})
const lgth = items && items.length
if (customClass == 'check-box-list') {
customClass = lgth && lgth < 4 ? `check-box-list-${lgth}` : 'check-box-list'
}
return (
<Table striped>
<thead>
......@@ -31,7 +35,7 @@ const CheckBoxs = ({items, toggleCheckbox, toggleCheckAll, checkedAll}) => {
<tbody>
<tr >
<td>
<ul id="export-import">
<ul className={customClass} style={customStyle}>
{checkBoxs}
</ul>
</td>
......@@ -41,11 +45,12 @@ const CheckBoxs = ({items, toggleCheckbox, toggleCheckAll, checkedAll}) => {
)
}
CheckBoxs.propTypes = {
items: React.PropTypes.array,
checkedAll: React.PropTypes.bool,
toggleCheckAll: React.PropTypes.func,
toggleCheckbox: React.PropTypes.func,
items: PropTypes.array,
checkedAll: PropTypes.bool,
toggleCheckAll: PropTypes.func,
toggleCheckbox: PropTypes.func,
customClass: PropTypes.string,
customStyle: PropTypes.object,
}
const CheckBox = ({text, checked, toggleCheckbox}) => {
......@@ -60,10 +65,11 @@ const CheckBox = ({text, checked, toggleCheckbox}) => {
)
}
CheckBox.propTypes = {
text: React.PropTypes.string,
checked: React.PropTypes.bool,
toggleCheckbox: React.PropTypes.func,
text: PropTypes.string,
checked: PropTypes.bool,
toggleCheckbox: PropTypes.func,
}
export default CheckBoxs
......@@ -14,28 +14,30 @@ export default class ModalExport extends React.Component {
columns: [
{value: "Image", text: "image", 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: "inchistring", text: "InChIstring", checked: true},
{value: "inchikey", text: "InChIkey", 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: "created_at", text: "created at", checked: false},
{value: "updated_at", text: "updated at", checked: false},
{value: "molarity_value, molarity_unit", text: "molarity", checked: false},
{value: "density", text: "density", checked: false},
{value: "molfile", text: "molfile", checked: false},
{value: "purity", text: "purity", checked: false},
{value: "solvent", text: "solvent", checked: false},
{value: "molarity_value, molarity_unit", text: "molarity", checked: false},
{value: "location", text: "location", checked: false},
{value: "is_top_secret", text: "is top secret?", 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: "ancestry", text: "ancestry", checked: false},
{value: "imported_readout", text: "imported readout", checked: false},
{value: "identifier", text: "identifier", checked: false},
{value: "density", text: "density", checked: false},
// {value: "identifier", text: "identifier", checked: false},
{value: "melting_point", text: "melting 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},
],
checkedAllColumns: true,
......@@ -94,7 +96,7 @@ export default class ModalExport extends React.Component {
removedColumns() {
const { columns } = this.state;
return this.chainedItems(columns);
return this.chainedItems(columns).join().split(/\s*,\s*/);
}
chainedItems(items) {
......
......@@ -47,18 +47,31 @@
margin-bottom: 10px;
}
#export-import {
list-style-type: none;
-moz-column-count: 4;
-moz-column-gap: 20px;
-webkit-column-count: 4;
-webkit-column-gap: 20px;
column-count: 4;
column-gap: 20px;
@mixin check-box-list-common($i) {
list-style-type: none;
-moz-column-gap: 20px;
-webkit-column-gap: 20px;
column-gap: 20px;
-moz-column-count: $i;
-webkit-column-count: $i;
column-count: $i;
}
.check-box-list {
@include check-box-list-common(4);
}
.check-box-list-1 {
@include check-box-list-common(1);
}
.check-box-list-2 {
@include check-box-list-common(2);
}
.check-box-list-3 {
@include check-box-list-common(3);
}
.select-assign-collection {
.separator {
......
......@@ -12,11 +12,11 @@ class Reporter::ExcelExport
def generate_file(default_excluded_field, default_included_field, removed_field = [])
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.workbook.styles.fonts.first.name = 'Calibri'
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
width = 0
......@@ -70,6 +70,8 @@ class Reporter::ExcelExport
if is_molecule_attribute(key)
asso = sample.send("molecule")
data = asso.attributes[key]
elsif key == 'molecule_name' && (nid = sample.molecule_name_id)
data = MoleculeName.find_by(id: nid)&.attributes['name']
else
data = sample.attributes[key]
end
......@@ -78,7 +80,7 @@ class Reporter::ExcelExport
end
def is_molecule_attribute(key)
["cano_smiles", "sum_formular", "inchistring",
["cano_smiles", "sum_formular", "inchistring", 'inchikey',
"molecular_weight"].index(key)
end
......
......@@ -26,7 +26,12 @@ class Reporter::SdfExport
sample_mdf = sample.molfile.split(/#|END/).first + "END\n"
(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?
value = validate_value(value)
......
......@@ -18,8 +18,14 @@ if defined?(Slackistrano::Messaging)
# end
def payload_for_updating
t = <<-TXT
#{member_links}\n current revision: #{fetch(:git_current_rev)}\n
base revision: <#{fetch(:git_url)} | #{fetch(:git_base_rev)}>\n
On server #{server_hostnames} #{super[:text]} \n
```#{fetch(:git_log_message)}```
TXT
{
text: "#{member_links}: On server #{server_hostnames} " + super[:text]
text: t
}
end
......@@ -82,14 +88,13 @@ if defined?(Slackistrano::Messaging)
def server_hostnames
roles(:web).map do |host|
"#{host.user}@#{host.hostname}"
# "#{host.user}@#{host.hostname}"
"#{host.hostname}"
end.join(', ')
end
def member_links
fetch(:slack_members, nil)&.inject do |ms,m|
ms << "<@#{m}>"
end
fetch(:slack_members, nil)&.map { |m| "<@#{m}>" }.join(', ')
end
end
end
......
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