Move ExtensionManager and localStorage into ohif-core
This commit is contained in:
parent
14c344ecb5
commit
3d1eff07ad
@ -1 +1 @@
|
||||
Subproject commit 8b3a80a85a466924cb1bdcb9450408130ebec9a0
|
||||
Subproject commit 847511a526739d20b9178878989ae8593800e031
|
||||
@ -11,7 +11,6 @@ import WhiteLabellingContext from './WhiteLabellingContext';
|
||||
import OHIFCornerstoneExtension from 'ohif-cornerstone-extension';
|
||||
import OHIFDicomPDFExtension from 'ohif-dicom-pdf-extension';
|
||||
import OHIFDicomMicroscopyExtension from 'ohif-dicom-microscopy-extension';
|
||||
import { loadState, saveState } from './redux/localStorageState.js';
|
||||
import {
|
||||
loadUser,
|
||||
OidcProvider,
|
||||
@ -19,21 +18,22 @@ import {
|
||||
reducer as oidcReducer
|
||||
} from 'redux-oidc';
|
||||
import cornerstoneWADOImageLoader from 'cornerstone-wado-image-loader';
|
||||
import ExtensionManager from './ExtensionManager';
|
||||
|
||||
const { ExtensionManager } = OHIF.extensions;
|
||||
|
||||
//import Icons from "./images/icons.svg"
|
||||
|
||||
const Icons = '/icons.svg';
|
||||
|
||||
let reducers = OHIF.redux.reducers;
|
||||
const { reducers, localStorage } = OHIF.redux;
|
||||
reducers.ui = ui;
|
||||
reducers.oidc = oidcReducer;
|
||||
|
||||
const combined = combineReducers(reducers);
|
||||
const store = createStore(combined, loadState());
|
||||
const store = createStore(combined, localStorage.loadState());
|
||||
|
||||
store.subscribe(() => {
|
||||
saveState({
|
||||
localStorage.saveState({
|
||||
preferences: store.getState().preferences
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,38 +0,0 @@
|
||||
import OHIF from 'ohif-core';
|
||||
|
||||
export default class ExtensionManager {
|
||||
static registerExtensions(store, extensions) {
|
||||
extensions.forEach(extension => {
|
||||
ExtensionManager.registerExtension(store, extension);
|
||||
});
|
||||
}
|
||||
|
||||
static registerExtension(store, extension) {
|
||||
/**
|
||||
* TODO:
|
||||
* - Use this function for checking extensions definition and throw errors early/ignore extension if format is not conformant or any required stuff is missing
|
||||
* - Check uniqueness of extension id
|
||||
* - Id Management: SopClassHandlers currently refer to viewport module by id; setting the extension id as viewport module id is a workaround for now
|
||||
* - Add loading of panel and toolbar modules */
|
||||
let viewportModule = extension.getViewportModule();
|
||||
let sopClassHandler = extension.getSopClassHandler();
|
||||
if (viewportModule) {
|
||||
store.dispatch(
|
||||
OHIF.redux.actions.addPlugin({
|
||||
id: extension.getExtensionId(),
|
||||
type: 'viewport',
|
||||
component: viewportModule
|
||||
})
|
||||
);
|
||||
}
|
||||
if (sopClassHandler) {
|
||||
store.dispatch(
|
||||
OHIF.redux.actions.addPlugin({
|
||||
id: extension.getExtensionId() + '_sopClass_handler',
|
||||
type: 'sopClassHandler',
|
||||
component: sopClassHandler
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,21 +0,0 @@
|
||||
import { connect } from 'react-redux';
|
||||
import ExampleViewportPlugin from './ExampleViewportPlugin';
|
||||
|
||||
// We don't really need Redux to do this, this is just an example
|
||||
const mapStateToProps = (state, ownProps) => {
|
||||
const { displaySet } = ownProps.viewportData;
|
||||
const { studyInstanceUid, seriesInstanceUid } = displaySet;
|
||||
|
||||
return {
|
||||
studyInstanceUid,
|
||||
seriesInstanceUid,
|
||||
displaySet
|
||||
};
|
||||
};
|
||||
|
||||
const ConnectedExampleViewportPlugin = connect(
|
||||
mapStateToProps,
|
||||
null
|
||||
)(ExampleViewportPlugin);
|
||||
|
||||
export default ConnectedExampleViewportPlugin;
|
||||
@ -1,27 +0,0 @@
|
||||
import React, { Component } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
class ExampleViewportPlugin extends Component {
|
||||
static propTypes = {
|
||||
studyInstanceUid: PropTypes.string.isRequired,
|
||||
seriesInstanceUid: PropTypes.string.isRequired,
|
||||
displaySet: PropTypes.object
|
||||
};
|
||||
|
||||
static defaultProps = {
|
||||
studyInstanceUid: '',
|
||||
seriesInstanceUid: ''
|
||||
};
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div className="ExampleViewportPlugin">
|
||||
<p>StudyInstanceUid: {this.props.studyInstanceUid}</p>
|
||||
<p>SeriesInstanceUid: {this.props.seriesInstanceUid}</p>
|
||||
{JSON.stringify(this.props.displaySet)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default ExampleViewportPlugin;
|
||||
@ -24,34 +24,6 @@ OHIF.external.cornerstone = cornerstone;
|
||||
OHIF.external.cornerstoneMath = cornerstoneMath;
|
||||
OHIF.external.cornerstoneWADOImageLoader = cornerstoneWADOImageLoader;
|
||||
|
||||
// TODO: Is there a better way to guess ROOT_URL?
|
||||
//let ROOT_URL = homepage;
|
||||
|
||||
// If the page we are on is not a subset of the expected homepage
|
||||
// provided in the package.json file, we might be doing local development.
|
||||
// In this case, set the base URL to the current location's origin.
|
||||
/*if (homepage.includes(window.location.origin) === false) {
|
||||
ROOT_URL = window.location.origin;
|
||||
}
|
||||
|
||||
const config = {
|
||||
maxWebWorkers: Math.max(navigator.hardwareConcurrency - 1, 1),
|
||||
startWebWorkersOnDemand: true,
|
||||
webWorkerPath: ROOT_URL + '/cornerstoneWADOImageLoaderWebWorker.min.js',
|
||||
taskConfiguration: {
|
||||
decodeTask: {
|
||||
loadCodecsOnStartup: true,
|
||||
initializeCodecsOnStartup: false,
|
||||
codecsPath: ROOT_URL + '/cornerstoneWADOImageLoaderCodecs.min.js',
|
||||
usePDFJS: false,
|
||||
strict: false
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
cornerstoneWADOImageLoader.webWorkerManager.initialize(config);
|
||||
*/
|
||||
|
||||
OHIF.user.getAccessToken = () => {
|
||||
// TODO: Get the Redux store from somewhere else
|
||||
const state = window.store.getState();
|
||||
|
||||
@ -1,15 +0,0 @@
|
||||
import React from 'react';
|
||||
import PropTypes from "prop-types";
|
||||
|
||||
function OHIFComponentPlugin(props) {
|
||||
return (<React.Fragment>{props.children}</React.Fragment>);
|
||||
}
|
||||
|
||||
OHIFComponentPlugin.propTypes = {
|
||||
id: PropTypes.string.isRequired,
|
||||
init: PropTypes.func.isRequired,
|
||||
destroy: PropTypes.func.isRequired,
|
||||
children: PropTypes.node
|
||||
};
|
||||
|
||||
export default OHIFComponentPlugin;
|
||||
@ -1,56 +1,57 @@
|
||||
import React, {Component} from "react";
|
||||
import PropTypes from "prop-types";
|
||||
import React, { Component } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import OHIF from 'ohif-core';
|
||||
import Viewer from "./Viewer.js";
|
||||
import Viewer from './Viewer.js';
|
||||
|
||||
const { createDisplaySets } = OHIF.utils;
|
||||
|
||||
class ViewerRetrieveStudyData extends Component {
|
||||
static propTypes = {
|
||||
studyInstanceUids: PropTypes.array.isRequired,
|
||||
seriesInstanceUids: PropTypes.array,
|
||||
server: PropTypes.object
|
||||
};
|
||||
static propTypes = {
|
||||
studyInstanceUids: PropTypes.array.isRequired,
|
||||
seriesInstanceUids: PropTypes.array,
|
||||
server: PropTypes.object
|
||||
};
|
||||
|
||||
state = {
|
||||
studies: null,
|
||||
error: null
|
||||
}
|
||||
state = {
|
||||
studies: null,
|
||||
error: null
|
||||
};
|
||||
|
||||
componentDidMount() {
|
||||
// TODO: Avoid using timepoints here
|
||||
//const params = { studyInstanceUids, seriesInstanceUids, timepointId, timepointsFilter={} };
|
||||
const { studyInstanceUids, seriesInstanceUids, server } = this.props;
|
||||
const promise = OHIF.studies.retrieveStudiesMetadata(server, studyInstanceUids, seriesInstanceUids)
|
||||
componentDidMount() {
|
||||
const { studyInstanceUids, seriesInstanceUids, server } = this.props;
|
||||
const promise = OHIF.studies.retrieveStudiesMetadata(
|
||||
server,
|
||||
studyInstanceUids,
|
||||
seriesInstanceUids
|
||||
);
|
||||
|
||||
// Render the viewer when the data is ready
|
||||
promise.then(studies => {
|
||||
const updatedStudies = createDisplaySets(studies);
|
||||
// Render the viewer when the data is ready
|
||||
promise
|
||||
.then(studies => {
|
||||
const updatedStudies = createDisplaySets(studies);
|
||||
|
||||
this.setState({
|
||||
studies: updatedStudies,
|
||||
});
|
||||
}).catch(error => {
|
||||
this.setState({
|
||||
error: true,
|
||||
});
|
||||
|
||||
throw new Error(error);
|
||||
this.setState({
|
||||
studies: updatedStudies
|
||||
});
|
||||
})
|
||||
.catch(error => {
|
||||
this.setState({
|
||||
error: true
|
||||
});
|
||||
|
||||
throw new Error(error);
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
if (this.state.error) {
|
||||
return <div>Error: {JSON.stringify(this.state.error)}</div>;
|
||||
} else if (!this.state.studies) {
|
||||
return <div>Loading...</div>;
|
||||
}
|
||||
|
||||
render() {
|
||||
if (this.state.error) {
|
||||
return (<div>Error: {JSON.stringify(this.state.error)}</div>);
|
||||
} else if (!this.state.studies) {
|
||||
return (<div>Loading...</div>);
|
||||
}
|
||||
|
||||
return (
|
||||
<Viewer studies={this.state.studies}/>
|
||||
);
|
||||
}
|
||||
return <Viewer studies={this.state.studies} />;
|
||||
}
|
||||
}
|
||||
|
||||
export default ViewerRetrieveStudyData;
|
||||
|
||||
@ -1,19 +0,0 @@
|
||||
export const loadState = () => {
|
||||
try {
|
||||
const serializedState = window.localStorage.getItem('state');
|
||||
if (!serializedState) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return JSON.parse(serializedState);
|
||||
} catch (e) {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
export const saveState = state => {
|
||||
try {
|
||||
const serializedState = JSON.stringify(state);
|
||||
localStorage.setItem('state', serializedState);
|
||||
} catch (e) {}
|
||||
};
|
||||
@ -1 +1 @@
|
||||
export default '22202141b8ce2fd087627fe24c0d401dc096029a';
|
||||
export default '5bb64fd9254dbd2dd152424fcf584d3a34b05c8a';
|
||||
|
||||
Loading…
Reference in New Issue
Block a user