Commit 33a36ea6 authored by pierre.tremouilhac's avatar pierre.tremouilhac
Browse files

Merge branch '176-create-well-plate-copy' into 'development'

Split Wellplate

Closes #176

See merge request ComPlat/chemotion_ELN!818
parents e69ed5e5 a25dd07b
......@@ -4,6 +4,7 @@ module Chemotion
helpers ContainerHelpers
helpers ParamsHelpers
helpers CollectionHelpers
helpers SampleHelpers
resource :wellplates do
namespace :bulk do
......@@ -155,6 +156,21 @@ module Chemotion
current_user.increment_counter 'wellplates'
{wellplate: ElementPermissionProxy.new(current_user, wellplate, user_ids).serialized}
end
namespace :subwellplates do
desc "Split Wellplates into Subwellplates"
params do
requires :ui_state, type: Hash, desc: "Selected wellplates from the UI"
end
post do
ui_state = params[:ui_state]
col_id = ui_state[:currentCollectionId]
wellplate_ids = Wellplate.for_user(current_user.id).for_ui_state_with_collection(ui_state[:wellplate], CollectionsWellplate, col_id)
Wellplate.where(id: wellplate_ids).each do |wellplate|
subwellplate = wellplate.create_subwellplate current_user, col_id, true
end
end
end
end
end
end
......@@ -93,7 +93,7 @@ export default class WellplateDetails extends Component {
switch (type) {
case 'name':
wellplate.name = value;
wellplate.name = value === '' ? 'New Wellplate' : value;
break;
case 'description':
wellplate.description = value;
......
......@@ -73,7 +73,7 @@ export default class WellplateDetailsContainers extends Component {
const {wellplate, activeContainer} = this.state;
const {readOnly} = this.props;
let containerHeader = (container) => <p style={{width: '100%'}}>
let containerHeader = (container) => <div style={{width: '100%'}}>
{container.name}
{(container.extended_metadata['kind'] &&
container.extended_metadata['kind'] != '')
......@@ -89,7 +89,7 @@ export default class WellplateDetailsContainers extends Component {
</Button>
<PrintCodeButton element={wellplate} analyses={[container]}
ident={container.id}/>
</p>
</div>
let containerHeaderDeleted = (container) => <p style={{width: '100%'}}><strike>{container.name}
{(container.extended_metadata['kind'] && container.extended_metadata['kind'] != '') ? (' - Type: ' + container.extended_metadata['kind']) : ''}
......
......@@ -394,6 +394,16 @@ class ElementActions {
}
// -- Wellplates --
splitAsSubwellplates(ui_state) {
return (dispatch) => {
WellplatesFetcher.splitAsSubwellplates(ui_state)
.then((result) => {
dispatch(ui_state);
}).catch((errorMessage) => {
console.log(errorMessage);
});
};
}
bulkCreateWellplatesFromSamples(params) {
let { collection_id, samples, wellplateCount } = params;
......
......@@ -199,6 +199,15 @@ export default class CreateButton extends React.Component {
)
}
noWellplateSelected() {
const { wellplate } = UIStore.getState();
return wellplate.checkedIds.size == 0 && wellplate.checkedAll == false;
}
splitSelectionAsSubwellplates() {
ElementActions.splitAsSubwellplates(UIStore.getState());
}
render() {
const { isDisabled, customClass } = this.props
const type = UserStore.getState().currentType
......@@ -230,6 +239,12 @@ export default class CreateButton extends React.Component {
disabled={this.noSampleSelected() || this.isAllCollection()}>
Split Sample
</MenuItem>
<MenuItem
onSelect={() => this.splitSelectionAsSubwellplates()}
disabled={this.noWellplateSelected() || this.isAllCollection()}
>
Split Wellplate
</MenuItem>
</SplitButton>
</div>
)
......
......@@ -144,4 +144,33 @@ export default class WellplatesFetcher {
console.log(errorMessage);
});
}
static splitAsSubwellplates(params) {
const promise = fetch('/api/v1/wellplates/subwellplates/', {
credentials: 'same-origin',
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
ui_state: {
wellplate: {
all: params.wellplate.checkedAll,
included_ids: params.wellplate.checkedIds,
excluded_ids: params.wellplate.uncheckedIds
},
currentCollectionId: params.currentCollection.id
}
})
}).then((response) => {
return response.json();
}).then((json) => {
return json;
}).catch((errorMessage) => {
console.log(errorMessage);
});
return promise;
}
}
......@@ -204,6 +204,7 @@ class ElementStore {
handleAssignElementsCollection: ElementActions.assignElementsCollection,
handleRemoveElementsCollection: ElementActions.removeElementsCollection,
handleSplitAsSubsamples: ElementActions.splitAsSubsamples,
handleSplitAsSubwellplates: ElementActions.splitAsSubwellplates,
// formerly from DetailStore
handleSelect: DetailActions.select,
handleClose: DetailActions.close,
......@@ -575,6 +576,14 @@ class ElementStore {
ui_state.isSync, this.state.moleculeSort);
}
handleSplitAsSubwellplates(ui_state) {
ElementActions.fetchWellplatesByCollectionId(ui_state.currentCollection.id);
ElementActions.fetchSamplesByCollectionId(
ui_state.currentCollection.id, {},
ui_state.isSync, this.state.moleculeSort
);
}
// Molecules
handleFetchMoleculeByMolfile(result) {
// Attention: This is intended to update SampleDetails
......
......@@ -68,4 +68,45 @@ class Wellplate < ActiveRecord::Base
self.container ? self.container.analyses : []
end
def create_subwellplate user, collection_ids, copy_ea = false
# Split Wellplate, based on the code from SplitSample
subwellplate = self.dup
subwellplate.name = "#{self.name}-Split"
collections = (
Collection.where(id: collection_ids) | Collection.where(user_id: user, label: 'All', is_locked: true)
)
subwellplate.collections << collections
subwellplate.container = Container.create_root_container
subwellplate.save! && subwellplate
# Split Wells and Samples
wells = (
Well.where(wellplate_id: self.id).order('id')
)
subwell_ary = Array.new
wells.each { |w|
subsample_id = nil;
if w.sample
begin
# Call Sample.create_subsample to perform SampleSplit
subsample = Sample.find_by(id: w.sample.id).create_subsample user, collection_ids, true
subsample_id = subsample.id
end
end
subwell = Well.create!(
wellplate_id: subwellplate.id,
sample_id: subsample_id,
readout: w.readout,
additive: w.additive,
position_x: w.position_x,
position_y: w.position_y,
)
subwell_ary.push(subwell)
}
if subwell_ary.length > 0
subwellplate.update!(wells: subwell_ary)
end
subwellplate
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