Commit 87dbe6a3 authored by hh1966's avatar hh1966
Browse files

Add UI and API to export all collections

parent bbe58c81
Pipeline #44849 canceled with stage
......@@ -358,12 +358,17 @@ module Chemotion
format = params[:format]
nested = params[:nested] == true
# check if the user is allowed to export these collections
collection_ids.each do |collection_id|
begin
collection = Collection.belongs_to_or_shared_by(current_user.id, current_user.group_ids).find(collection_id)
rescue ActiveRecord::RecordNotFound
error!('401 Unauthorized', 401)
if collection_ids.empty?
# no collection was given, export all collections for this user
collection_ids = Collection.belongs_to_or_shared_by(current_user.id, current_user.group_ids).pluck(:id)
else
# check if the user is allowed to export these collections
collection_ids.each do |collection_id|
begin
collection = Collection.belongs_to_or_shared_by(current_user.id, current_user.group_ids).find(collection_id)
rescue ActiveRecord::RecordNotFound
error!('401 Unauthorized', 401)
end
end
end
......
......@@ -32,14 +32,19 @@ const ExportImportButton = ({ isDisabled, updateModalProps, customClass }) => (
Import samples to collection
</MenuItem>
<MenuItem divider />
<MenuItem onSelect={() => exportCollectionFunction(updateModalProps)} disabled={isDisabled}
<MenuItem onSelect={() => exportCollectionFunction(updateModalProps)}
title='Export collections as ZIP archive'>
Export collections
Export selected collection
</MenuItem>
<MenuItem onSelect={() => importCollectionFunction(updateModalProps)} disabled={isDisabled}
title='Import collections as ZIP archive'>
<MenuItem onSelect={() => importCollectionFunction(updateModalProps)}
title='Import collections from ZIP archive'>
Import collections
</MenuItem>
<MenuItem divider />
<MenuItem onSelect={() => exportCollectionFunctionFull(updateModalProps)}
title='Export all collections as one ZIP archive'>
Export all collections
</MenuItem>
{/* <MenuItem onSelect={() => importChemScannerFunction(updateModalProps)} disabled={isDisabled} */}
{/* title='Import from Docs'> */}
{/* Import elements from Docs */}
......@@ -112,9 +117,29 @@ const exportReactionFunction = (updateModalProps) => {
}
const exportCollectionFunction = (updateModalProps) => {
const title = "Export Collections to ZIP archive";
const title = "Export Collection as ZIP archive";
const component = ModalExportCollection;
const action = CollectionActions.exportCollectionsToFile;
const full = false;
const listSharedCollections = false;
const modalProps = {
show: true,
title,
component,
action,
full,
listSharedCollections,
};
updateModalProps(modalProps);
}
const exportCollectionFunctionFull = (updateModalProps) => {
const title = "Export all collections as one ZIP archive";
const component = ModalExportCollection;
const action = CollectionActions.exportCollectionsToFile;
const full = true;
const listSharedCollections = false;
const modalProps = {
......@@ -122,6 +147,7 @@ const exportCollectionFunction = (updateModalProps) => {
title,
component,
action,
full,
listSharedCollections,
};
......
......@@ -29,10 +29,10 @@ export default class ModalExportCollection extends React.Component {
handleClick() {
const uiState = UIStore.getState();
const { onHide, action } = this.props;
const { onHide, action, full } = this.props;
let params = {
collections: [uiState.currentCollection.id],
collections: (full ? [] : [uiState.currentCollection.id]),
format: 'zip',
nested: true
}
......
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