2019-04-28 21:54:56 +02:00
|
|
|
import React, { Component } from 'react'
|
|
|
|
|
import { BrowserRouter as Router } from 'react-router-dom'
|
|
|
|
|
import { Provider } from 'react-redux'
|
|
|
|
|
import { createStore, combineReducers } from 'redux'
|
|
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
|
import OHIF from 'ohif-core'
|
|
|
|
|
import './config'
|
|
|
|
|
import ui from './redux/ui.js'
|
|
|
|
|
import OHIFStandaloneViewer from './OHIFStandaloneViewer'
|
|
|
|
|
import WhiteLabellingContext from './WhiteLabellingContext'
|
|
|
|
|
import OHIFCornerstoneExtension from 'ohif-cornerstone-extension'
|
|
|
|
|
import OHIFVTKExtension from 'ohif-vtk-extension'
|
|
|
|
|
import OHIFDicomPDFExtension from 'ohif-dicom-pdf-extension'
|
|
|
|
|
import OHIFDicomHtmlExtension from 'ohif-dicom-html-extension'
|
|
|
|
|
import OHIFDicomMicroscopyExtension from 'ohif-dicom-microscopy-extension'
|
2019-04-29 21:39:09 +02:00
|
|
|
import { OidcProvider, reducer as oidcReducer } from 'redux-oidc'
|
2019-01-24 10:22:40 +01:00
|
|
|
import {
|
2019-05-01 18:56:41 +02:00
|
|
|
getDefaultToolbarButtons,
|
2019-04-29 21:39:09 +02:00
|
|
|
getUserManagerForOpenIdConnectClient,
|
|
|
|
|
initWebWorkers,
|
|
|
|
|
} from './utils/index.js'
|
2019-01-24 10:22:40 +01:00
|
|
|
|
2019-04-29 21:39:09 +02:00
|
|
|
const { ExtensionManager } = OHIF.extensions
|
2019-04-28 21:54:56 +02:00
|
|
|
const { reducers, localStorage } = OHIF.redux
|
2019-04-29 21:39:09 +02:00
|
|
|
|
2019-04-28 21:54:56 +02:00
|
|
|
reducers.ui = ui
|
|
|
|
|
reducers.oidc = oidcReducer
|
2019-01-17 17:00:21 +01:00
|
|
|
|
2019-04-28 21:54:56 +02:00
|
|
|
const combined = combineReducers(reducers)
|
|
|
|
|
const store = createStore(combined, localStorage.loadState())
|
2019-01-17 17:00:21 +01:00
|
|
|
|
2019-01-31 08:55:05 +01:00
|
|
|
store.subscribe(() => {
|
2019-02-07 15:10:03 +01:00
|
|
|
localStorage.saveState({
|
2019-04-28 21:54:56 +02:00
|
|
|
preferences: store.getState().preferences,
|
|
|
|
|
})
|
|
|
|
|
})
|
2019-01-17 17:00:21 +01:00
|
|
|
|
2019-02-10 22:28:42 +01:00
|
|
|
const availableTools = [
|
|
|
|
|
{ name: 'Pan', mouseButtonMasks: [1, 4] },
|
|
|
|
|
{ name: 'Zoom', mouseButtonMasks: [1, 2] },
|
|
|
|
|
{ name: 'Wwwc', mouseButtonMasks: [1] },
|
|
|
|
|
{ name: 'Bidirectional', mouseButtonMasks: [1] },
|
|
|
|
|
{ name: 'Length', mouseButtonMasks: [1] },
|
|
|
|
|
{ name: 'Angle', mouseButtonMasks: [1] },
|
|
|
|
|
{ name: 'StackScroll', mouseButtonMasks: [1] },
|
|
|
|
|
{ name: 'Brush', mouseButtonMasks: [1] },
|
|
|
|
|
{ name: 'FreehandMouse', mouseButtonMasks: [1] },
|
|
|
|
|
{ name: 'PanMultiTouch' },
|
|
|
|
|
{ name: 'ZoomTouchPinch' },
|
|
|
|
|
{ name: 'StackScrollMouseWheel' },
|
2019-04-28 21:54:56 +02:00
|
|
|
{ name: 'StackScrollMultiTouch' },
|
|
|
|
|
]
|
2019-02-10 22:28:42 +01:00
|
|
|
|
2019-02-13 10:15:54 +01:00
|
|
|
const toolAction = OHIF.redux.actions.setExtensionData('cornerstone', {
|
2019-04-28 21:54:56 +02:00
|
|
|
availableTools,
|
|
|
|
|
})
|
2019-02-10 22:28:42 +01:00
|
|
|
|
2019-04-28 21:54:56 +02:00
|
|
|
store.dispatch(toolAction)
|
2019-02-10 22:28:42 +01:00
|
|
|
|
2019-02-02 12:10:56 +01:00
|
|
|
/** TODO: extensions should be passed in as prop as soon as we have the extensions as separate packages and then registered by ExtensionsManager */
|
2019-02-08 19:13:12 +01:00
|
|
|
const extensions = [
|
2019-04-30 22:47:14 +02:00
|
|
|
new OHIFCornerstoneExtension({}),
|
2019-03-01 10:55:52 +01:00
|
|
|
new OHIFVTKExtension(),
|
2019-02-02 12:10:56 +01:00
|
|
|
new OHIFDicomPDFExtension(),
|
2019-02-08 19:13:12 +01:00
|
|
|
new OHIFDicomHtmlExtension(),
|
2019-04-28 21:54:56 +02:00
|
|
|
new OHIFDicomMicroscopyExtension(),
|
|
|
|
|
]
|
|
|
|
|
ExtensionManager.registerExtensions(store, extensions)
|
2019-01-17 17:00:21 +01:00
|
|
|
|
2019-01-24 10:22:40 +01:00
|
|
|
// TODO[react] Use a provider when the whole tree is React
|
2019-04-28 21:54:56 +02:00
|
|
|
window.store = store
|
2019-01-24 10:22:40 +01:00
|
|
|
|
|
|
|
|
function handleServers(servers) {
|
|
|
|
|
if (servers) {
|
2019-04-28 21:54:56 +02:00
|
|
|
OHIF.utils.addServers(servers, store)
|
2019-01-24 10:22:40 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-17 17:00:21 +01:00
|
|
|
class App extends Component {
|
2019-01-17 17:39:08 +01:00
|
|
|
static propTypes = {
|
2019-04-29 20:42:29 +02:00
|
|
|
routerBasename: PropTypes.string,
|
|
|
|
|
relativeWebWorkerScriptsPath: PropTypes.string,
|
|
|
|
|
//
|
2019-01-30 10:34:55 +01:00
|
|
|
servers: PropTypes.object,
|
2019-01-24 10:22:40 +01:00
|
|
|
oidc: PropTypes.array,
|
2019-01-31 08:55:05 +01:00
|
|
|
userManager: PropTypes.object,
|
2019-04-28 21:54:56 +02:00
|
|
|
location: PropTypes.object,
|
2019-04-29 21:06:17 +02:00
|
|
|
whiteLabelling: PropTypes.object,
|
2019-04-28 21:54:56 +02:00
|
|
|
}
|
2019-01-24 10:22:40 +01:00
|
|
|
|
2019-01-30 12:24:34 +01:00
|
|
|
static defaultProps = {
|
2019-04-29 21:06:17 +02:00
|
|
|
routerBasename: '/',
|
|
|
|
|
relativeWebWorkerScriptsPath: '',
|
2019-04-28 21:54:56 +02:00
|
|
|
whiteLabelling: {},
|
|
|
|
|
}
|
2019-01-30 12:24:34 +01:00
|
|
|
|
2019-01-24 10:22:40 +01:00
|
|
|
constructor(props) {
|
2019-04-28 21:54:56 +02:00
|
|
|
super(props)
|
2019-01-24 10:22:40 +01:00
|
|
|
|
2019-05-01 18:56:41 +02:00
|
|
|
//
|
|
|
|
|
const defaultButtons = getDefaultToolbarButtons(this.props.routerBasename)
|
|
|
|
|
const buttonsAction = OHIF.redux.actions.setAvailableButtons(defaultButtons)
|
|
|
|
|
|
|
|
|
|
store.dispatch(buttonsAction)
|
|
|
|
|
|
|
|
|
|
//
|
2019-04-29 21:39:09 +02:00
|
|
|
this.userManager = getUserManagerForOpenIdConnectClient(
|
|
|
|
|
store,
|
|
|
|
|
this.props.oidc
|
|
|
|
|
)
|
2019-04-28 21:54:56 +02:00
|
|
|
handleServers(this.props.servers)
|
2019-04-29 21:39:09 +02:00
|
|
|
initWebWorkers(
|
2019-04-29 20:42:29 +02:00
|
|
|
this.props.routerBasename,
|
|
|
|
|
this.props.relativeWebWorkerScriptsPath
|
|
|
|
|
)
|
2019-01-17 17:39:08 +01:00
|
|
|
}
|
|
|
|
|
|
2019-01-17 17:00:21 +01:00
|
|
|
render() {
|
2019-04-28 21:54:56 +02:00
|
|
|
const userManager = this.userManager
|
2019-01-24 10:22:40 +01:00
|
|
|
|
|
|
|
|
if (userManager) {
|
|
|
|
|
return (
|
|
|
|
|
<Provider store={store}>
|
|
|
|
|
<OidcProvider store={store} userManager={userManager}>
|
2019-04-28 21:54:56 +02:00
|
|
|
<Router basename={this.props.routerBasename}>
|
2019-01-24 14:00:01 +01:00
|
|
|
<WhiteLabellingContext.Provider value={this.props.whiteLabelling}>
|
|
|
|
|
<OHIFStandaloneViewer userManager={userManager} />
|
|
|
|
|
</WhiteLabellingContext.Provider>
|
2019-04-28 21:54:56 +02:00
|
|
|
</Router>
|
2019-01-24 10:22:40 +01:00
|
|
|
</OidcProvider>
|
|
|
|
|
</Provider>
|
2019-04-28 21:54:56 +02:00
|
|
|
)
|
2019-01-24 10:22:40 +01:00
|
|
|
}
|
|
|
|
|
|
2019-01-17 17:00:21 +01:00
|
|
|
return (
|
|
|
|
|
<Provider store={store}>
|
2019-04-28 21:54:56 +02:00
|
|
|
<Router basename={this.props.routerBasename}>
|
2019-01-24 14:00:01 +01:00
|
|
|
<WhiteLabellingContext.Provider value={this.props.whiteLabelling}>
|
|
|
|
|
<OHIFStandaloneViewer />
|
|
|
|
|
</WhiteLabellingContext.Provider>
|
2019-04-28 21:54:56 +02:00
|
|
|
</Router>
|
2019-01-17 17:00:21 +01:00
|
|
|
</Provider>
|
2019-04-28 21:54:56 +02:00
|
|
|
)
|
2019-01-17 17:00:21 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-28 21:54:56 +02:00
|
|
|
export default App
|