ohif-viewer/src/App.js

148 lines
4.3 KiB
JavaScript
Raw Normal View History

2019-05-29 14:39:54 +02:00
import './config';
2019-05-30 18:57:46 +02:00
2019-06-03 21:41:49 +02:00
import {
CommandsManager,
ExtensionManager,
2019-06-03 21:41:49 +02:00
HotkeysManager,
utils,
} from 'ohif-core';
2019-05-30 18:57:46 +02:00
import React, { Component } from 'react';
import {
getUserManagerForOpenIdConnectClient,
initWebWorkers,
2019-05-29 14:39:54 +02:00
} from './utils/index.js';
2019-05-30 18:57:46 +02:00
import { I18nextProvider } from 'react-i18next';
// import ConnectedToolContextMenu from './connectedComponents/ConnectedToolContextMenu';
2019-05-30 18:57:46 +02:00
import OHIFCornerstoneExtension from '@ohif/extension-cornerstone';
// import OHIFDicomHtmlExtension from 'ohif-dicom-html-extension';
2019-06-17 21:42:11 +02:00
import OHIFDicomMicroscopyExtension from '@ohif/extension-dicom-microscopy';
2019-06-17 21:05:51 +02:00
import OHIFDicomPDFExtension from '@ohif/extension-dicom-pdf';
2019-05-30 18:57:46 +02:00
import OHIFStandaloneViewer from './OHIFStandaloneViewer';
2019-06-17 05:11:43 +02:00
import OHIFVTKExtension from '@ohif/extension-vtk';
2019-05-31 17:55:44 +02:00
import { OidcProvider } from 'redux-oidc';
2019-05-30 18:57:46 +02:00
import PropTypes from 'prop-types';
import { Provider } from 'react-redux';
import { BrowserRouter as Router } from 'react-router-dom';
import WhiteLabellingContext from './WhiteLabellingContext';
2019-06-03 21:41:49 +02:00
import appCommands from './appCommands';
import { getActiveContexts } from './store/layout/selectors.js';
import i18n from '@ohif/i18n';
import setupTools from './setupTools';
2019-05-31 17:55:44 +02:00
import store from './store';
// ~~~~ APP SETUP
2019-06-03 21:41:49 +02:00
const commandsManagerConfig = {
getAppState: () => store.getState(),
getActiveContexts: () => getActiveContexts(store.getState()),
2019-06-03 21:41:49 +02:00
};
const commandsManager = new CommandsManager(commandsManagerConfig);
const hotkeysManager = new HotkeysManager(commandsManager);
const extensionManager = new ExtensionManager({ commandsManager });
2019-06-03 21:41:49 +02:00
// TODO: Should be done in extensions w/ commandsModule
// ~~ ADD COMMANDS
appCommands.init(commandsManager);
if (window.config.hotkeys) {
hotkeysManager.setHotkeys(window.config.hotkeys, true);
}
// ~~~~ END APP SETUP
2019-05-29 14:39:54 +02:00
setupTools(store);
// const children = {
// viewport: [<ConnectedToolContextMenu key="tool-context" />],
// };
/** TODO: extensions should be passed in as prop as soon as we have the extensions as separate packages and then registered by ExtensionsManager */
extensionManager.registerExtensions([
// new OHIFCornerstoneExtension({ children }),
2019-06-17 05:11:43 +02:00
OHIFCornerstoneExtension,
OHIFVTKExtension,
2019-06-17 21:05:51 +02:00
OHIFDicomPDFExtension,
// new OHIFDicomHtmlExtension(),
2019-06-17 21:42:11 +02:00
OHIFDicomMicroscopyExtension,
]);
// TODO[react] Use a provider when the whole tree is React
2019-05-29 14:39:54 +02:00
window.store = store;
function handleServers(servers) {
if (servers) {
utils.addServers(servers, store);
}
}
class App extends Component {
2019-01-17 17:39:08 +01:00
static propTypes = {
routerBasename: PropTypes.string.isRequired,
relativeWebWorkerScriptsPath: PropTypes.string.isRequired,
servers: PropTypes.object.isRequired,
oidc: PropTypes.array,
2019-04-29 21:06:17 +02:00
whiteLabelling: PropTypes.object,
2019-05-29 14:39:54 +02:00
};
2019-01-30 12:24:34 +01:00
static defaultProps = {
whiteLabelling: {},
oidc: [],
2019-05-29 14:39:54 +02:00
};
2019-01-30 12:24:34 +01:00
constructor(props) {
2019-05-29 14:39:54 +02:00
super(props);
if (this.props.oidc.length) {
2019-05-29 14:39:54 +02:00
const firstOpenIdClient = this.props.oidc[0];
this.userManager = getUserManagerForOpenIdConnectClient(
store,
firstOpenIdClient
2019-05-29 14:39:54 +02:00
);
}
2019-05-29 14:39:54 +02:00
handleServers(this.props.servers);
initWebWorkers(
2019-04-29 20:42:29 +02:00
this.props.routerBasename,
this.props.relativeWebWorkerScriptsPath
2019-05-29 14:39:54 +02:00
);
2019-01-17 17:39:08 +01:00
}
render() {
2019-05-29 14:39:54 +02:00
const userManager = this.userManager;
if (userManager) {
return (
<Provider store={store}>
2019-06-04 23:16:07 +02:00
<I18nextProvider i18n={i18n}>
2019-05-30 20:41:15 +02:00
<OidcProvider store={store} userManager={userManager}>
<Router basename={this.props.routerBasename}>
<WhiteLabellingContext.Provider
value={this.props.whiteLabelling}
>
<OHIFStandaloneViewer userManager={userManager} />
</WhiteLabellingContext.Provider>
</Router>
</OidcProvider>
2019-06-04 23:16:07 +02:00
</I18nextProvider>
</Provider>
2019-05-29 14:39:54 +02:00
);
}
return (
<Provider store={store}>
2019-06-06 23:57:45 +02:00
<I18nextProvider i18n={i18n}>
<Router basename={this.props.routerBasename}>
<WhiteLabellingContext.Provider value={this.props.whiteLabelling}>
<OHIFStandaloneViewer />
</WhiteLabellingContext.Provider>
</Router>
</I18nextProvider>
</Provider>
2019-05-29 14:39:54 +02:00
);
}
}
2019-05-29 14:39:54 +02:00
export default App;
// Make our managers accessible
export { commandsManager, extensionManager, hotkeysManager };