ohif-viewer/OHIFViewer-react/src/index.js

172 lines
4.4 KiB
JavaScript
Raw Normal View History

import React from "react";
2018-12-14 15:23:48 +01:00
import ReactDOM from 'react-dom';
import { BrowserRouter } from "react-router-dom";
2018-12-14 15:23:48 +01:00
import { Provider } from 'react-redux';
import { createStore, combineReducers } from 'redux';
import { loadUser, reducer as oidcReducer, OidcProvider, createUserManager } from 'redux-oidc';
import OHIF from 'ohif-core';
2018-12-14 15:23:48 +01:00
import './config';
import ui from './redux/ui.js';
2019-01-07 19:17:10 +01:00
import App from './App.js';
import OHIFCornerstoneViewportPlugin from "./connectedComponents/OHIFCornerstoneViewportPlugin/OHIFCornerstoneViewportPlugin.js";
//import ConnectedExampleViewportPlugin from './components/ConnectedExampleViewportPlugin.js';
2018-12-14 15:23:48 +01:00
const reducers = OHIF.redux.reducers;
reducers.ui = ui;
2019-01-07 19:17:10 +01:00
reducers.oidc = oidcReducer;
const Icons = '/icons.svg';
const combined = combineReducers(reducers)
const store = createStore(combined);
// Note: Run your build like this:
// REACT_APP_CONFIG=$(cat ../config-react/ccc.json) yarn start
//
// If you change the JSON config, you need to re-run the command!
let config;
if (process.env.REACT_APP_CONFIG) {
config = JSON.parse(process.env.REACT_APP_CONFIG);
}
let userManager;
if (config.oidc) {
const oidcClient = config.oidc[0];
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,
extraQueryParams: oidcClient.extraQueryParams
};
userManager = createUserManager(settings);
loadUser(store, userManager);
}
if (config.servers) {
OHIF.utils.addServers(config.servers, store);
}
2018-12-14 15:23:48 +01:00
2019-01-06 21:59:25 +01:00
const defaultButtons = [
{
2019-01-07 14:00:54 +01:00
command: 'StackScroll',
2019-01-06 21:59:25 +01:00
type: 'tool',
2019-01-07 14:00:54 +01:00
text: 'Stack Scroll',
svgUrl: `${Icons}#icon-tools-stack-scroll`,
2019-01-06 21:59:25 +01:00
active: false
},
{
command: 'Zoom',
type: 'tool',
text: 'Zoom',
2019-01-07 11:18:59 +01:00
svgUrl: `${Icons}#icon-tools-zoom`,
2019-01-06 21:59:25 +01:00
active: false
},
{
2019-01-07 14:00:54 +01:00
command: 'Wwwc',
2019-01-06 21:59:25 +01:00
type: 'tool',
2019-01-07 14:00:54 +01:00
text: 'Levels',
svgUrl: `${Icons}#icon-tools-levels`,
active: true
},
{
command: 'Pan',
type: 'tool',
text: 'Pan',
svgUrl: `${Icons}#icon-tools-pan`,
2019-01-06 21:59:25 +01:00
active: false
},
{
2019-01-07 14:00:54 +01:00
command: 'Length',
2019-01-06 21:59:25 +01:00
type: 'tool',
2019-01-07 14:00:54 +01:00
text: 'Length',
svgUrl: `${Icons}#icon-tools-measure-temp`,
active: false
},
/*{
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',
active: false
},
{
command: 'Bidirectional',
type: 'tool',
text: 'Bidirectional',
svgUrl: `${Icons}#icon-tools-measure-target`,
2019-01-06 21:59:25 +01:00
active: false
},
{
command: 'reset',
type: 'command',
text: 'Reset',
2019-01-07 11:18:59 +01:00
svgUrl: `${Icons}#icon-tools-reset`,
2019-01-06 21:59:25 +01:00
active: false
},
];
const buttonsAction = OHIF.redux.actions.setAvailableButtons(defaultButtons);
store.dispatch(buttonsAction);
// Uncomment this and comment the Cornerstone version to see how the
// example plugin works
/*const pluginAction = OHIF.redux.actions.addPlugin({
id: 'example',
type: 'viewport',
component: ConnectedExampleViewportPlugin
});*/
const pluginAction = OHIF.redux.actions.addPlugin({
id: 'cornerstone',
type: 'viewport',
component: OHIFCornerstoneViewportPlugin
2019-01-06 21:59:25 +01:00
});
store.dispatch(pluginAction);
2018-12-14 15:23:48 +01:00
// TODO[react] Use a provider when the whole tree is React
window.store = store;
if (userManager) {
ReactDOM.render(
2018-12-14 15:23:48 +01:00
<Provider store={store}>
<OidcProvider store={store} userManager={userManager}>
<BrowserRouter>
<App userManager={userManager}/>
</BrowserRouter>
</OidcProvider>
2018-12-14 15:23:48 +01:00
</Provider>,
document.getElementById('root')
);
} else {
ReactDOM.render(
<Provider store={store}>
<BrowserRouter>
<App/>
</BrowserRouter>
</Provider>,
document.getElementById('root')
);
}