Make it possible to pass in extensions as App props

This commit is contained in:
dannyrb 2019-07-08 10:18:03 -04:00
parent f3009c7a45
commit f5d6674b62
4 changed files with 60 additions and 137 deletions

View File

@ -3,6 +3,7 @@ window.config = {
routerBasename: '/',
// default: ''
relativeWebWorkerScriptsPath: '',
extensions: [],
servers: {
dicomWeb: [
{

View File

@ -29,6 +29,13 @@
href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700|Sanchez&display=swap"
rel="stylesheet"
/>
<!-- EXTENSIONS -->
<!-- <script type="text/javascript" src="path/to/some-extension.js"></script>
<script>
window.config.extensions = [SomeExtension];
</script> -->
</head>
<body>

View File

@ -22,11 +22,7 @@ import initCornerstoneTools from './initCornerstoneTools.js';
// ~~ EXTENSIONS
import { GenericViewerCommands, MeasurementsPanel } from './appExtensions';
import OHIFCornerstoneExtension from '@ohif/extension-cornerstone';
import OHIFDicomHtmlExtension from '@ohif/extension-dicom-html';
import OHIFDicomMicroscopyExtension from '@ohif/extension-dicom-microscopy';
import OHIFDicomPDFExtension from '@ohif/extension-dicom-pdf';
import OHIFStandaloneViewer from './OHIFStandaloneViewer';
import OHIFVTKExtension from '@ohif/extension-vtk';
// ~~ EXTENSIONS
import { OidcProvider } from 'redux-oidc';
import PropTypes from 'prop-types';
@ -56,45 +52,28 @@ const extensionManager = new ExtensionManager({ commandsManager });
setupTools(store);
// ~~~~ END APP SETUP
/** 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([
// Core
GenericViewerCommands,
MeasurementsPanel,
//
OHIFCornerstoneExtension,
OHIFVTKExtension,
OHIFDicomPDFExtension,
OHIFDicomHtmlExtension,
OHIFDicomMicroscopyExtension,
]);
// Must run after extension commands are registered
if (window.config.hotkeys) {
hotkeysManager.setHotkeys(window.config.hotkeys, true);
}
// TODO[react] Use a provider when the whole tree is React
window.store = store;
function handleServers(servers) {
if (servers) {
utils.addServers(servers, store);
}
}
class App extends Component {
static propTypes = {
routerBasename: PropTypes.string.isRequired,
relativeWebWorkerScriptsPath: PropTypes.string.isRequired,
servers: PropTypes.object.isRequired,
//
oidc: PropTypes.array,
whiteLabelling: PropTypes.object,
extensions: PropTypes.arrayOf(
PropTypes.shape({
id: PropTypes.string.isRequired,
})
),
};
static defaultProps = {
whiteLabelling: {},
oidc: [],
extensions: [],
};
constructor(props) {
@ -108,7 +87,9 @@ class App extends Component {
firstOpenIdClient
);
}
handleServers(this.props.servers);
_initExtensions(this.props.extensions);
_initServers(this.props.servers);
initWebWorkers(
this.props.routerBasename,
this.props.relativeWebWorkerScriptsPath
@ -150,6 +131,34 @@ class App extends Component {
}
}
function _initExtensions(extensions) {
const defaultExtensions = [
GenericViewerCommands,
MeasurementsPanel,
OHIFCornerstoneExtension,
];
const mergedExtensions = defaultExtensions.concat(extensions);
extensionManager.registerExtensions(mergedExtensions);
// [
// OHIFVTKExtension,
// OHIFDicomPDFExtension,
// OHIFDicomHtmlExtension,
// OHIFDicomMicroscopyExtension,
// ]
// Must run after extension commands are registered
if (window.config.hotkeys) {
hotkeysManager.setHotkeys(window.config.hotkeys, true);
}
}
function _initServers(servers) {
if (servers) {
utils.addServers(servers, store);
}
}
export default App;
// Make our managers accessible

View File

@ -6,118 +6,24 @@ import App from './App.js';
import React from 'react';
import ReactDOM from 'react-dom';
export { App };
// EXTENSIONS
import OHIFVTKExtension from '@ohif/extension-vtk';
import OHIFDicomHtmlExtension from '@ohif/extension-dicom-html';
import OHIFDicomMicroscopyExtension from '@ohif/extension-dicom-microscopy';
import OHIFDicomPDFExtension from '@ohif/extension-dicom-pdf';
// Default Settings
window.config = window.config || {};
const applicationDefaults = {
window.config.extensions = [OHIFVTKExtension];
const appDefaults = {
routerBasename: '/',
relativeWebWorkerScriptsPath: '',
};
const applicationProps = Object.assign({}, applicationDefaults, window.config);
const app = React.createElement(App, applicationProps, null);
const appProps = Object.assign({}, appDefaults, window.config);
// Create App
const app = React.createElement(App, appProps, null);
// Render
ReactDOM.render(app, document.getElementById('root'));
/*
Example config with OIDC
*/
// Uncomment the next two blocks, comment out the config without OIDC
// Try going to:
// http://localhost:5000/viewer/1.2.276.0.7230010.3.1.2.0.94237.1537373823.634387 //PDF
// http://localhost:5000/viewer/1.3.6.1.4.1.25403.345050719074.3824.20170126082328.1
// http://ohif-viewer-react.s3-website-us-east-1.amazonaws.com/viewer/1.3.6.1.4.1.25403.345050719074.3824.20170126082328.1
/*props.servers = {
dicomWeb: [
{
name: 'DCM4CHEE',
wadoUriRoot:
'https://cancer.crowds-cure.org/dcm4chee-arc/aets/DCM4CHEE/wado',
qidoRoot: 'https://cancer.crowds-cure.org/dcm4chee-arc/aets/DCM4CHEE/rs',
wadoRoot: 'https://cancer.crowds-cure.org/dcm4chee-arc/aets/DCM4CHEE/rs',
qidoSupportsIncludeField: true,
imageRendering: 'wadors',
thumbnailRendering: 'wadors',
requestOptions: {
requestFromBrowser: true
}
}
]
};
props.oidc = [
{
authServerUrl: 'https://cancer.crowds-cure.org/auth/realms/dcm4che',
authRedirectUri: rootUrl + '/callback',
postLogoutRedirectUri: rootUrl + '/logout-redirect.html',
clientId: 'crowds-cure-cancer',
responseType: 'id_token token',
scope: 'email profile openid',
revokeAccessTokenOnSignout: true,
extraQueryParams: {
kc_idp_hint: 'crowds-cure-cancer-auth0-oidc',
client_id: 'crowds-cure-cancer'
}
}
];*/
/* props.servers = {
dicomWeb: [
{
name: 'DCM4CHEE',
wadoUriRoot:
'https://k8s-testing.ohif.org/dcm4chee-arc/aets/DCM4CHEE/wado',
qidoRoot: 'https://k8s-testing.ohif.org/dcm4chee-arc/aets/DCM4CHEE/rs',
wadoRoot: 'https://k8s-testing.ohif.org/dcm4chee-arc/aets/DCM4CHEE/rs',
qidoSupportsIncludeField: true,
imageRendering: 'wadors',
thumbnailRendering: 'wadors',
requestOptions: {
requestFromBrowser: true
}
}
]
};
props.oidc = [
{
authServerUrl: 'https://k8s-testing.ohif.org/auth/realms/dcm4che',
authRedirectUri: rootUrl + '/callback',
postLogoutRedirectUri: rootUrl + '/logout-redirect.html',
clientId: 'ohif-viewer',
responseType: 'id_token token',
scope: 'email profile openid',
revokeAccessTokenOnSignout: true
}
]; */
/*props.servers = {
"dicomWeb": [
{
"name": "DCM4CHEE",
"wadoUriRoot": "http://localhost:8080/dcm4chee-arc/aets/DCM4CHEE/wado",
"qidoRoot": "http://localhost:8080/dcm4chee-arc/aets/DCM4CHEE/rs",
"wadoRoot": "http://localhost:8080/dcm4chee-arc/aets/DCM4CHEE/rs",
"qidoSupportsIncludeField": true,
"imageRendering": "wadors",
"thumbnailRendering": "wadors",
"requestOptions": {
"requestFromBrowser": true,
"auth": "admin:admin"
}
}
]
};*/
/*
/*"PUBLIC_SETTINGS": {
"ui": {
"studyListFunctionsEnabled": true,
"displaySetNavigationLoopOverSeries": false,
"displaySetNavigationMultipleViewports": true,
"autoPositionMeasurementsTextCallOuts": "TRLB"
},
"prefetch": {
"order": "topdown",
"displaySetCount": 1
}
*/