2020-05-07 20:02:51 +02:00
|
|
|
import React, { useContext } from 'react';
|
|
|
|
|
import SOPClassHandlerManager from './SOPClassHandlerManager';
|
|
|
|
|
import ViewModelContext from './ViewModelContext';
|
|
|
|
|
import Compose from './Compose';
|
|
|
|
|
|
|
|
|
|
export default function ModeRoute({
|
|
|
|
|
location,
|
|
|
|
|
mode,
|
|
|
|
|
dataSourceId,
|
|
|
|
|
extensionManager,
|
|
|
|
|
}) {
|
|
|
|
|
const { routes, sopClassHandlers, extensions } = mode;
|
|
|
|
|
const dataSource = extensionManager.getDataSource(dataSourceId);
|
|
|
|
|
|
|
|
|
|
const { displaySetInstanceUids, setDisplaySetInstanceUids } = useContext(
|
|
|
|
|
ViewModelContext
|
|
|
|
|
);
|
2020-05-07 16:55:59 +02:00
|
|
|
// Deal with toolbar.
|
|
|
|
|
|
|
|
|
|
// Only handling one route per mode for now
|
2020-05-09 20:23:43 +02:00
|
|
|
// You can test via http://localhost:3000/example-mode/dicomweb
|
2020-05-09 10:57:52 +02:00
|
|
|
const layoutTemplateData = routes[0].layoutTemplate({ location });
|
|
|
|
|
|
2020-05-09 20:23:43 +02:00
|
|
|
const layoutTemplateModuleEntry = extensionManager.getModuleEntry(
|
|
|
|
|
layoutTemplateData.id
|
2020-05-07 20:02:51 +02:00
|
|
|
);
|
2020-05-07 16:55:59 +02:00
|
|
|
|
2020-05-09 20:23:43 +02:00
|
|
|
const LayoutComponent = layoutTemplateModuleEntry.component;
|
|
|
|
|
|
2020-05-07 16:55:59 +02:00
|
|
|
// Add SOPClassHandlers to a new SOPClassManager.
|
2020-05-10 16:33:04 +02:00
|
|
|
const manager = new SOPClassHandlerManager(
|
2020-05-07 20:02:51 +02:00
|
|
|
extensionManager,
|
|
|
|
|
sopClassHandlers
|
2020-05-10 16:33:04 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/*setInterval(() => {
|
|
|
|
|
setDisplaySetInstanceUids(manager.displaySets);
|
|
|
|
|
}, 5000);*/
|
2020-05-07 16:55:59 +02:00
|
|
|
|
|
|
|
|
const queryParams = location.search;
|
|
|
|
|
|
|
|
|
|
// Call the data source to start building the view model?
|
2020-05-07 20:02:51 +02:00
|
|
|
//dataSource(queryParams);
|
|
|
|
|
//metadataStore.onModified();
|
2020-05-07 16:55:59 +02:00
|
|
|
|
|
|
|
|
const onUpdatedCallback = () => {
|
|
|
|
|
// TODO: This should append, not create from scratch so we don't nuke existing display sets
|
|
|
|
|
// when e.g. a new series arrives
|
2020-05-09 10:57:52 +02:00
|
|
|
//manager.createDisplaySets.then(setDisplaySetInstanceUids);
|
2020-05-07 16:55:59 +02:00
|
|
|
};
|
|
|
|
|
|
2020-05-09 20:23:43 +02:00
|
|
|
// For each extension, look up their context modules
|
|
|
|
|
let contextModules = [];
|
|
|
|
|
extensions.forEach(extensionId => {
|
|
|
|
|
const allRegisteredModuleIds = Object.keys(extensionManager.modulesMap);
|
|
|
|
|
const moduleIds = allRegisteredModuleIds.filter(id =>
|
|
|
|
|
id.includes(`${extensionId}.contextModule.`)
|
|
|
|
|
);
|
2020-05-07 16:55:59 +02:00
|
|
|
|
2020-05-09 20:23:43 +02:00
|
|
|
if (!moduleIds || !moduleIds.length) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const modules = moduleIds.map(extensionManager.getModuleEntry);
|
|
|
|
|
contextModules = contextModules.concat(modules);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const contextModuleProviders = contextModules.map(a => a.provider);
|
|
|
|
|
const CombinedContextProvider = ({ children }) =>
|
|
|
|
|
Compose({ components: contextModuleProviders, children });
|
2020-05-09 10:57:52 +02:00
|
|
|
|
2020-05-09 20:23:43 +02:00
|
|
|
return (
|
2020-05-07 20:02:51 +02:00
|
|
|
<CombinedContextProvider>
|
2020-05-09 10:57:52 +02:00
|
|
|
<LayoutComponent
|
2020-05-09 20:23:43 +02:00
|
|
|
extensionManager={extensionManager}
|
2020-05-09 10:57:52 +02:00
|
|
|
displaySetInstanceUids={displaySetInstanceUids}
|
|
|
|
|
{...layoutTemplateData.props}
|
|
|
|
|
/>
|
2020-05-07 20:02:51 +02:00
|
|
|
</CombinedContextProvider>
|
2020-05-09 20:23:43 +02:00
|
|
|
);
|
2020-05-07 16:55:59 +02:00
|
|
|
}
|