Skip to content

Commit

Permalink
feat: show nmrium button for reaction and research plan
Browse files Browse the repository at this point in the history
  • Loading branch information
Lan Le committed Aug 21, 2023
1 parent 5d2cf58 commit 56182cf
Show file tree
Hide file tree
Showing 6 changed files with 440 additions and 99 deletions.
4 changes: 2 additions & 2 deletions app/packs/src/apps/mydb/elements/details/ViewSpectra.js
Original file line number Diff line number Diff line change
Expand Up @@ -524,8 +524,8 @@ class ViewSpectra extends React.Component {
buildOpsByLayout(et) {
if (this.props.sample && this.props.sample instanceof ResearchPlan) {
return [
{ name: 'write & save', value: this.writeOp },
{ name: 'write, save & close', value: this.writeCloseOp },
{ name: 'write & save', value: this.saveOp },
{ name: 'write, save & close', value: this.saveCloseOp },
];
}
const updatable = this.props.sample && this.props.sample.can_update;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ import { hNmrCount, cNmrCount, instrumentText } from 'src/utilities/ElementUtils
import { contentToText } from 'src/utilities/quillFormat';
import { chmoConversions } from 'src/components/OlsComponent';
import { previewContainerImage } from 'src/utilities/imageHelper';
import { JcampIds, BuildSpcInfos } from 'src/utilities/SpectraHelper';
import { JcampIds, BuildSpcInfos, BuildSpcInfosForNMRDisplayer, isNMRKind } from 'src/utilities/SpectraHelper';
import UIStore from 'src/stores/alt/stores/UIStore';
import SpectraActions from 'src/stores/alt/actions/SpectraActions';
import LoadingActions from 'src/stores/alt/actions/LoadingActions';
import ViewSpectra from 'src/apps/mydb/elements/details/ViewSpectra';
import NMRiumDisplayer from 'src/components/nmriumWrapper/NMRiumDisplayer';

import TextTemplateActions from 'src/stores/alt/actions/TextTemplateActions';

Expand All @@ -42,48 +43,74 @@ const nmrMsg = (reaction, container) => {
const SpectraEditorBtn = ({
element, spcInfo, hasJcamp, hasChemSpectra,
toggleSpectraModal, confirmRegenerate,
toggleNMRDisplayerModal, hasNMRium,
}) => (
<OverlayTrigger
placement="bottom"
delayShow={500}
overlay={<Tooltip id="spectra">Spectra Editor {!spcInfo ? ': Reprocess' : ''}</Tooltip>}
>{spcInfo ? (
<ButtonGroup className="button-right">
<SplitButton
id="spectra-editor-split-button"
pullRight
bsStyle="info"
<span>
<OverlayTrigger
placement="bottom"
delayShow={500}
overlay={<Tooltip id="spectra">Spectra Editor {!spcInfo ? ': Reprocess' : ''}</Tooltip>}
>{spcInfo ? (
<ButtonGroup className="button-right">
<SplitButton
id="spectra-editor-split-button"
pullRight
bsStyle="info"
bsSize="xsmall"
title={<i className="fa fa-area-chart" />}
onToggle={(open, event) => { if (event) { event.stopPropagation(); } }}
onClick={toggleSpectraModal}
disabled={!spcInfo || !hasChemSpectra}
>
<MenuItem
id="regenerate-spectra"
key="regenerate-spectra"
onSelect={(eventKey, event) => {
event.stopPropagation();
confirmRegenerate(event);
}}
disabled={!hasJcamp || !element.can_update}
>
<i className="fa fa-refresh" /> Reprocess
</MenuItem>
</SplitButton>
</ButtonGroup>
) : (
<Button
bsStyle="warning"
bsSize="xsmall"
title={<i className="fa fa-area-chart" />}
onToggle={(open, event) => { if (event) { event.stopPropagation(); } }}
onClick={toggleSpectraModal}
disabled={!spcInfo || !hasChemSpectra}
className="button-right"
onClick={confirmRegenerate}
disabled={false}
>
<MenuItem
id="regenerate-spectra"
key="regenerate-spectra"
onSelect={(eventKey, event) => {
event.stopPropagation();
confirmRegenerate(event);
}}
disabled={!hasJcamp || !element.can_update}
<i className="fa fa-area-chart" /><i className="fa fa-refresh " />
</Button>
)}
</OverlayTrigger>
{
hasNMRium ? (
<OverlayTrigger
placement="top"
delayShow={500}
overlay={<Tooltip id="spectra_nmrium_wrapper">Process with NMRium</Tooltip>}
>
<i className="fa fa-refresh" /> Reprocess
</MenuItem>
</SplitButton>
</ButtonGroup>
) : (
<Button
bsStyle="warning"
bsSize="xsmall"
className="button-right"
onClick={confirmRegenerate}
disabled={false}
>
<i className="fa fa-area-chart" /><i className="fa fa-refresh " />
</Button>
)}
</OverlayTrigger>
<ButtonGroup className="button-right">
<Button
id="spectra-editor-split-button"
pullRight
bsStyle="info"
bsSize="xsmall"
onToggle={(open, event) => { if (event) { event.stopPropagation(); } }}
onClick={toggleNMRDisplayerModal}
disabled={!hasJcamp || !element.can_update}
>
<i className="fa fa-bar-chart"/>
</Button>
</ButtonGroup>
</OverlayTrigger>
) : null
}
</span>
);

SpectraEditorBtn.propTypes = {
Expand All @@ -96,13 +123,17 @@ SpectraEditorBtn.propTypes = {
hasChemSpectra: PropTypes.bool,
toggleSpectraModal: PropTypes.func.isRequired,
confirmRegenerate: PropTypes.func.isRequired,
toggleNMRDisplayerModal: PropTypes.func.isRequired,
hasNMRium: PropTypes.bool,
};

SpectraEditorBtn.defaultProps = {
hasJcamp: false,
spcInfo: false,
element: {},
hasChemSpectra: false,
hasEditedJcamp: false,
hasNMRium: false,
};

export default class ReactionDetailsContainers extends Component {
Expand Down Expand Up @@ -192,13 +223,22 @@ export default class ReactionDetailsContainers extends Component {
}
};
const spcInfo = BuildSpcInfos(reaction, container);
const { hasChemSpectra } = UIStore.getState();
const { hasChemSpectra, hasNmriumWrapper } = UIStore.getState();
const toggleSpectraModal = (e) => {
e.stopPropagation();
SpectraActions.ToggleModal();
SpectraActions.LoadSpectra.defer(spcInfo);
};

//process open NMRium
const toggleNMRDisplayerModal = (e) => {
const spcInfosForNMRDisplayer = BuildSpcInfosForNMRDisplayer(reaction, container);
e.stopPropagation();
SpectraActions.ToggleModalNMRDisplayer();
SpectraActions.LoadSpectraForNMRDisplayer.defer(spcInfosForNMRDisplayer); // going to fetch files base on spcInfos
}

const hasNMRium = isNMRKind(container) && hasNmriumWrapper;

return (
<div className="upper-btn">
Expand All @@ -219,6 +259,8 @@ export default class ReactionDetailsContainers extends Component {
hasChemSpectra={hasChemSpectra}
toggleSpectraModal={toggleSpectraModal}
confirmRegenerate={confirmRegenerate}
toggleNMRDisplayerModal={toggleNMRDisplayerModal}
hasNMRium={hasNMRium}
/>
</div>
);
Expand Down Expand Up @@ -388,6 +430,11 @@ export default class ReactionDetailsContainers extends Component {
handleSampleChanged={this.handleSpChange}
handleSubmit={this.props.handleSubmit}
/>
<NMRiumDisplayer
sample={reaction}
handleSampleChanged={this.handleSpChange}
handleSubmit={this.props.handleSubmit}
/>
</Panel.Body>
</Panel>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,59 +7,87 @@ import QuillViewer from 'src/components/QuillViewer';
import ImageModal from 'src/components/common/ImageModal';
import { instrumentText } from 'src/utilities/ElementUtils';
import { previewContainerImage } from 'src/utilities/imageHelper';
import { JcampIds, BuildSpcInfos } from 'src/utilities/SpectraHelper';
import { JcampIds, BuildSpcInfos, BuildSpcInfosForNMRDisplayer, isNMRKind } from 'src/utilities/SpectraHelper';
import UIStore from 'src/stores/alt/stores/UIStore';
import SpectraActions from 'src/stores/alt/actions/SpectraActions';
import LoadingActions from 'src/stores/alt/actions/LoadingActions';
import ViewSpectra from 'src/apps/mydb/elements/details/ViewSpectra';
import NMRiumDisplayer from 'src/components/nmriumWrapper/NMRiumDisplayer';

import TextTemplateActions from 'src/stores/alt/actions/TextTemplateActions';

const SpectraEditorBtn = ({
element, spcInfo, hasJcamp, hasChemSpectra,
toggleSpectraModal, confirmRegenerate,
toggleNMRDisplayerModal, hasNMRium,
}) => (
<OverlayTrigger
placement="bottom"
delayShow={500}
overlay={<Tooltip id="spectra">Spectra Editor {!spcInfo ? ': Reprocess' : ''}</Tooltip>}
>{spcInfo ? (
<ButtonGroup className="button-right">
<SplitButton
id="spectra-editor-split-button"
pullRight
bsStyle="info"
<span>
<OverlayTrigger
placement="bottom"
delayShow={500}
overlay={<Tooltip id="spectra">Spectra Editor {!spcInfo ? ': Reprocess' : ''}</Tooltip>}
>{spcInfo ? (
<ButtonGroup className="button-right">
<SplitButton
id="spectra-editor-split-button"
pullRight
bsStyle="info"
bsSize="xsmall"
title={<i className="fa fa-area-chart" />}
onToggle={(open, event) => { if (event) { event.stopPropagation(); } }}
onClick={toggleSpectraModal}
disabled={!spcInfo || !hasChemSpectra}
>
<MenuItem
id="regenerate-spectra"
key="regenerate-spectra"
onSelect={(eventKey, event) => {
event.stopPropagation();
confirmRegenerate(event);
}}
disabled={!hasJcamp || !element.can_update}
>
<i className="fa fa-refresh" /> Reprocess
</MenuItem>
</SplitButton>
</ButtonGroup>
) : (
<Button
bsStyle="warning"
bsSize="xsmall"
title={<i className="fa fa-area-chart" />}
onToggle={(open, event) => { if (event) { event.stopPropagation(); } }}
onClick={toggleSpectraModal}
disabled={!spcInfo || !hasChemSpectra}
className="button-right"
onClick={confirmRegenerate}
disabled={false}
>
<MenuItem
id="regenerate-spectra"
key="regenerate-spectra"
onSelect={(eventKey, event) => {
event.stopPropagation();
confirmRegenerate(event);
}}
disabled={!hasJcamp || !element.can_update}
<i className="fa fa-area-chart" /><i className="fa fa-refresh " />
</Button>
)}
</OverlayTrigger>
{
hasNMRium ? (
<OverlayTrigger
placement="top"
delayShow={500}
overlay={<Tooltip id="spectra_nmrium_wrapper">Process with NMRium</Tooltip>}
>
<i className="fa fa-refresh" /> Reprocess
</MenuItem>
</SplitButton>
</ButtonGroup>
) : (
<Button
bsStyle="warning"
bsSize="xsmall"
className="button-right"
onClick={confirmRegenerate}
disabled={false}
>
<i className="fa fa-area-chart" /><i className="fa fa-refresh " />
</Button>
)}
</OverlayTrigger>
<ButtonGroup className="button-right">
<Button
id="spectra-editor-split-button"
pullRight
bsStyle="info"
bsSize="xsmall"
onToggle={(open, event) => { if (event) { event.stopPropagation(); } }}
onClick={toggleNMRDisplayerModal}
disabled={!hasJcamp}
>
<i className="fa fa-bar-chart"/>
</Button>
</ButtonGroup>
</OverlayTrigger>
) : null
}
</span>

);


Expand All @@ -73,13 +101,16 @@ SpectraEditorBtn.propTypes = {
hasChemSpectra: PropTypes.bool,
toggleSpectraModal: PropTypes.func.isRequired,
confirmRegenerate: PropTypes.func.isRequired,
toggleNMRDisplayerModal: PropTypes.func.isRequired,
hasNMRium: PropTypes.bool,
};

SpectraEditorBtn.defaultProps = {
hasJcamp: false,
spcInfo: false,
element: {},
hasChemSpectra: false,
hasNMRium: false,
};

export default class ResearchPlanDetailsContainers extends Component {
Expand Down Expand Up @@ -163,12 +194,23 @@ export default class ResearchPlanDetailsContainers extends Component {
}
};
const spcInfo = BuildSpcInfos(researchPlan, container);
const { hasChemSpectra } = UIStore.getState();
const { hasChemSpectra, hasNmriumWrapper } = UIStore.getState();
const toggleSpectraModal = (e) => {
e.stopPropagation();
SpectraActions.ToggleModal();
SpectraActions.LoadSpectra.defer(spcInfo);
};

//process open NMRium
const toggleNMRDisplayerModal = (e) => {
const spcInfosForNMRDisplayer = BuildSpcInfosForNMRDisplayer(researchPlan, container);
e.stopPropagation();
SpectraActions.ToggleModalNMRDisplayer();
SpectraActions.LoadSpectraForNMRDisplayer.defer(spcInfosForNMRDisplayer); // going to fetch files base on spcInfos
}

const hasNMRium = isNMRKind(container) && hasNmriumWrapper;

return (
<div className="upper-btn">
<Button
Expand All @@ -187,6 +229,8 @@ export default class ResearchPlanDetailsContainers extends Component {
hasChemSpectra={hasChemSpectra}
toggleSpectraModal={toggleSpectraModal}
confirmRegenerate={confirmRegenerate}
toggleNMRDisplayerModal={toggleNMRDisplayerModal}
hasNMRium={hasNMRium}
/>
</div>
);
Expand Down Expand Up @@ -349,6 +393,11 @@ export default class ResearchPlanDetailsContainers extends Component {
handleSampleChanged={this.handleSpChange}
handleSubmit={this.props.handleSubmit}
/>
<NMRiumDisplayer
sample={this.props.researchPlan}
handleSampleChanged={this.handleSpChange}
handleSubmit={this.props.handleSubmit}
/>
</Panel.Body>
</Panel>
);
Expand Down
Loading

0 comments on commit 56182cf

Please sign in to comment.