Skip to content

Commit

Permalink
#444 feat: Allow dicom viewer loader customization
Browse files Browse the repository at this point in the history
  • Loading branch information
afonsobspinto committed Dec 12, 2022
1 parent d52f2ca commit 3523f97
Showing 1 changed file with 59 additions and 3 deletions.
62 changes: 59 additions & 3 deletions geppetto.js/geppetto-ui/src/dicom-viewer/DicomViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
} from '@fortawesome/free-solid-svg-icons';
import CustomToolbar from '../common/CustomToolbar';
import { createZipFromRemoteFiles } from './util';
import Loader from "../loader/Loader";

const styles = {
dicomViewer: {
Expand Down Expand Up @@ -55,6 +56,7 @@ class DicomViewer extends Component {
? 'coronal'
: this.props.orientation,
fullScreen: false,
ready: false
};

// 3d renderer
Expand Down Expand Up @@ -330,6 +332,7 @@ class DicomViewer extends Component {
_this.configureEvents();
_this.ready = true;
_this.props.onLoaded()
_this.setState({ ready: true })
})
.catch(function (error) {
window.console.log('oops... something went wrong...');
Expand Down Expand Up @@ -692,7 +695,7 @@ class DicomViewer extends Component {
}

render () {
const { classes, toolbarOptions } = this.props;
const { classes, toolbarOptions, loaderOptions } = this.props;
const { fullScreen } = this.state;
const customButtons = this.getCustomButtons();

Expand All @@ -710,6 +713,18 @@ class DicomViewer extends Component {
height: '100%',
width: '100%',
};

const loader = loaderOptions && loaderOptions.instance ? (
<loaderOptions.instance
{...loaderOptions.props}
/>
) : <Loader fullscreen={this.state.fullScreen}
handleClose={toolbarOptions?.handleClose}
messages={toolbarOptions?.messages}
messagesInterval={toolbarOptions?.messagesInterval}
elapsed={toolbarOptions?.elapsed}
backgroundStyle={toolbarOptions?.backgroundStyle}
/>

const toolbar = toolbarOptions && toolbarOptions.instance ? (
<toolbarOptions.instance
Expand All @@ -728,6 +743,7 @@ class DicomViewer extends Component {
id={this.props.id + '_component'}
style={containerStyle}
>
{!this.state.ready && loader}
{toolbar}
<div
className={classes.dicomViewer}
Expand Down Expand Up @@ -819,7 +835,7 @@ class DicomViewer extends Component {
/>
</div>
</div>
);
)
}
}

Expand All @@ -832,7 +848,8 @@ DicomViewer.defaultProps = {
onShiftClick: 'goToPoint',
onDoubleClick: 'goToPoint',
showDownloadButton: false,
toolbarOptions: null
toolbarOptions: null,
loaderOptions: null
};


Expand Down Expand Up @@ -918,6 +935,45 @@ DicomViewer.propTypes = {
*/
buttonStyles: PropTypes.shape({}),
}),
/**
* Options to customize the loader
*/
loaderOptions: PropTypes.shape({
/**
* Reference to toolbar component
*/
instance: PropTypes.elementType,
/**
* Custom toolbar props
*/
props: PropTypes.shape({}),
/**
* Function to handle the close of the Loader
*/
handleClose: PropTypes.func,
/**
* Array of Custom messages to display
*/
messages: PropTypes.array,
/**
* Number of milliseconds between custom messages
*/
messagesInterval: PropTypes.number,
/**
* Number of the progress value to show in linear determinate (in percentage)
*/
elapsed: PropTypes.number,
/**
* Style to be applied to the Loader background
*/
backgroundStyle: PropTypes.shape({
/**
* Loader's background color. Defaults to rgba(255,142,0,0.1)
*/
backgroundColor: PropTypes.string,
}),

}),
};

export default withStyles(styles)(DicomViewer);

0 comments on commit 3523f97

Please sign in to comment.