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-01-24 10:22:40 +01:00
|
|
|
import {
|
|
|
|
|
loadUser,
|
|
|
|
|
OidcProvider,
|
|
|
|
|
createUserManager,
|
2019-04-28 21:54:56 +02:00
|
|
|
reducer as oidcReducer,
|
|
|
|
|
} from 'redux-oidc'
|
|
|
|
|
import cornerstoneWADOImageLoader from 'cornerstone-wado-image-loader'
|
2019-02-07 15:10:03 +01:00
|
|
|
|
2019-04-28 21:54:56 +02:00
|
|
|
const { ExtensionManager } = OHIF.extensions
|
2019-01-24 10:22:40 +01:00
|
|
|
|
2019-04-28 21:54:56 +02:00
|
|
|
const Icons = 'icons.svg'
|
2019-01-17 17:00:21 +01:00
|
|
|
|
2019-04-28 21:54:56 +02:00
|
|
|
const { reducers, localStorage } = OHIF.redux
|
|
|
|
|
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
|
|
|
|
|
|
|
|
const defaultButtons = [
|
|
|
|
|
{
|
|
|
|
|
command: 'StackScroll',
|
|
|
|
|
type: 'tool',
|
|
|
|
|
text: 'Stack Scroll',
|
|
|
|
|
svgUrl: `${Icons}#icon-tools-stack-scroll`,
|
2019-04-28 21:54:56 +02:00
|
|
|
active: false,
|
2019-01-17 17:00:21 +01:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
command: 'Zoom',
|
|
|
|
|
type: 'tool',
|
|
|
|
|
text: 'Zoom',
|
|
|
|
|
svgUrl: `${Icons}#icon-tools-zoom`,
|
2019-04-28 21:54:56 +02:00
|
|
|
active: false,
|
2019-01-17 17:00:21 +01:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
command: 'Wwwc',
|
|
|
|
|
type: 'tool',
|
|
|
|
|
text: 'Levels',
|
|
|
|
|
svgUrl: `${Icons}#icon-tools-levels`,
|
2019-04-28 21:54:56 +02:00
|
|
|
active: true,
|
2019-01-17 17:00:21 +01:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
command: 'Pan',
|
|
|
|
|
type: 'tool',
|
|
|
|
|
text: 'Pan',
|
|
|
|
|
svgUrl: `${Icons}#icon-tools-pan`,
|
2019-04-28 21:54:56 +02:00
|
|
|
active: false,
|
2019-01-17 17:00:21 +01:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
command: 'Length',
|
|
|
|
|
type: 'tool',
|
|
|
|
|
text: 'Length',
|
|
|
|
|
svgUrl: `${Icons}#icon-tools-measure-temp`,
|
2019-04-28 21:54:56 +02:00
|
|
|
active: false,
|
2019-01-17 17:00:21 +01:00
|
|
|
},
|
|
|
|
|
/*{
|
|
|
|
|
command: 'Annotate',
|
|
|
|
|
type: 'tool',
|
|
|
|
|
text: 'Annotate',
|
|
|
|
|
svgUrl: `${Icons}#icon-tools-measure-non-target`,
|
|
|
|
|
active: false
|
|
|
|
|
},*/
|
|
|
|
|
{
|
|
|
|
|
command: 'Angle',
|
|
|
|
|
type: 'tool',
|
|
|
|
|
text: 'Angle',
|
|
|
|
|
iconClasses: 'fa fa-angle-left',
|
2019-04-28 21:54:56 +02:00
|
|
|
active: false,
|
2019-01-17 17:00:21 +01:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
command: 'Bidirectional',
|
|
|
|
|
type: 'tool',
|
|
|
|
|
text: 'Bidirectional',
|
|
|
|
|
svgUrl: `${Icons}#icon-tools-measure-target`,
|
2019-04-28 21:54:56 +02:00
|
|
|
active: false,
|
2019-01-17 17:00:21 +01:00
|
|
|
},
|
2019-01-30 17:51:54 +01:00
|
|
|
{
|
|
|
|
|
command: 'Brush',
|
|
|
|
|
type: 'tool',
|
|
|
|
|
text: 'Brush',
|
|
|
|
|
iconClasses: 'fa fa-circle',
|
2019-04-28 21:54:56 +02:00
|
|
|
active: false,
|
2019-01-30 17:51:54 +01:00
|
|
|
},
|
2019-02-10 22:28:42 +01:00
|
|
|
{
|
|
|
|
|
command: 'FreehandMouse',
|
|
|
|
|
type: 'tool',
|
|
|
|
|
text: 'Freehand',
|
|
|
|
|
iconClasses: 'fa fa-star',
|
2019-04-28 21:54:56 +02:00
|
|
|
active: false,
|
2019-02-10 22:28:42 +01:00
|
|
|
},
|
2019-01-17 17:00:21 +01:00
|
|
|
{
|
|
|
|
|
command: 'reset',
|
|
|
|
|
type: 'command',
|
|
|
|
|
text: 'Reset',
|
|
|
|
|
svgUrl: `${Icons}#icon-tools-reset`,
|
2019-04-28 21:54:56 +02:00
|
|
|
active: false,
|
|
|
|
|
},
|
|
|
|
|
]
|
2019-01-17 17:00:21 +01:00
|
|
|
|
2019-04-28 21:54:56 +02:00
|
|
|
const buttonsAction = OHIF.redux.actions.setAvailableButtons(defaultButtons)
|
2019-01-17 17:00:21 +01:00
|
|
|
|
2019-04-28 21:54:56 +02:00
|
|
|
store.dispatch(buttonsAction)
|
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-02-06 14:46:06 +01: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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function handleOIDC(oidc) {
|
|
|
|
|
if (!oidc) {
|
2019-04-28 21:54:56 +02:00
|
|
|
return
|
2019-01-24 10:22:40 +01:00
|
|
|
}
|
|
|
|
|
|
2019-04-28 21:54:56 +02:00
|
|
|
const oidcClient = oidc[0]
|
2019-01-24 10:22:40 +01:00
|
|
|
|
|
|
|
|
const settings = {
|
|
|
|
|
authority: oidcClient.authServerUrl,
|
|
|
|
|
client_id: oidcClient.clientId,
|
|
|
|
|
redirect_uri: oidcClient.authRedirectUri,
|
|
|
|
|
silent_redirect_uri: '/silent-refresh.html',
|
|
|
|
|
post_logout_redirect_uri: oidcClient.postLogoutRedirectUri,
|
|
|
|
|
response_type: oidcClient.responseType,
|
|
|
|
|
scope: 'email profile openid', // Note: Request must have scope 'openid' to be considered an OpenID Connect request
|
|
|
|
|
automaticSilentRenew: true,
|
|
|
|
|
revokeAccessTokenOnSignout: true,
|
|
|
|
|
filterProtocolClaims: true,
|
|
|
|
|
loadUserInfo: true,
|
2019-04-28 21:54:56 +02:00
|
|
|
extraQueryParams: oidcClient.extraQueryParams,
|
|
|
|
|
}
|
2019-01-24 10:22:40 +01:00
|
|
|
|
2019-04-28 21:54:56 +02:00
|
|
|
const userManager = createUserManager(settings)
|
2019-01-24 10:22:40 +01:00
|
|
|
|
2019-04-28 21:54:56 +02:00
|
|
|
loadUser(store, userManager)
|
2019-01-24 10:22:40 +01:00
|
|
|
|
2019-04-28 21:54:56 +02:00
|
|
|
return userManager
|
2019-01-24 10:22:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function handleWebWorkerInit(basename) {
|
|
|
|
|
const config = {
|
|
|
|
|
maxWebWorkers: Math.max(navigator.hardwareConcurrency - 1, 1),
|
|
|
|
|
startWebWorkersOnDemand: true,
|
|
|
|
|
webWorkerPath: basename + '/cornerstoneWADOImageLoaderWebWorker.min.js',
|
|
|
|
|
taskConfiguration: {
|
|
|
|
|
decodeTask: {
|
|
|
|
|
loadCodecsOnStartup: true,
|
|
|
|
|
initializeCodecsOnStartup: false,
|
|
|
|
|
codecsPath: basename + '/cornerstoneWADOImageLoaderCodecs.min.js',
|
|
|
|
|
usePDFJS: false,
|
2019-04-28 21:54:56 +02:00
|
|
|
strict: false,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
2019-01-17 17:00:21 +01:00
|
|
|
|
2019-04-28 21:54:56 +02:00
|
|
|
cornerstoneWADOImageLoader.webWorkerManager.initialize(config)
|
2019-01-24 10:22:40 +01:00
|
|
|
}
|
2019-01-17 17:00:21 +01:00
|
|
|
|
2019-02-18 10:53:36 +01:00
|
|
|
/**
|
|
|
|
|
* Set or update the HTML Base tag present on the document
|
|
|
|
|
* to point to the provided ROOT Url.
|
|
|
|
|
*
|
|
|
|
|
* @param rootUrl
|
|
|
|
|
*/
|
|
|
|
|
function updateBaseTag(rootUrl) {
|
2019-04-28 21:54:56 +02:00
|
|
|
const bases = document.getElementsByTagName('base')
|
|
|
|
|
let baseHref = rootUrl
|
|
|
|
|
baseHref += baseHref.endsWith('/') ? '' : '/'
|
2019-02-18 10:53:36 +01:00
|
|
|
|
|
|
|
|
if (bases.length > 1) {
|
2019-04-28 21:54:56 +02:00
|
|
|
throw new Error('For some reason there is more than one base tag present.')
|
2019-02-18 10:53:36 +01:00
|
|
|
} else if (bases.length === 1) {
|
2019-04-28 21:54:56 +02:00
|
|
|
bases[0].href = baseHref
|
2019-02-18 10:53:36 +01:00
|
|
|
} else {
|
2019-04-28 21:54:56 +02:00
|
|
|
document.write(`<base href='${baseHref}'/>`)
|
2019-02-18 10:53:36 +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-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
|
|
|
routerBasename: PropTypes.string,
|
2019-02-02 12:10:56 +01:00
|
|
|
rootUrl: PropTypes.string,
|
2019-01-31 08:55:05 +01:00
|
|
|
userManager: PropTypes.object,
|
2019-04-28 21:54:56 +02:00
|
|
|
location: PropTypes.object,
|
|
|
|
|
}
|
2019-01-24 10:22:40 +01:00
|
|
|
|
2019-01-30 12:24:34 +01:00
|
|
|
static defaultProps = {
|
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-04-28 21:54:56 +02:00
|
|
|
this.userManager = handleOIDC(this.props.oidc)
|
|
|
|
|
handleServers(this.props.servers)
|
|
|
|
|
handleWebWorkerInit(this.props.rootUrl)
|
|
|
|
|
updateBaseTag(this.props.rootUrl)
|
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
|