2020-06-15 03:18:29 +02:00
|
|
|
import React, { useEffect, useState } from 'react';
|
|
|
|
|
import classnames from 'classnames';
|
2020-05-14 21:57:45 +02:00
|
|
|
import PropTypes from 'prop-types';
|
2020-06-15 05:42:44 +02:00
|
|
|
import { SidePanel } from '@ohif/ui';
|
2020-05-14 21:57:45 +02:00
|
|
|
import Header from './Header.jsx';
|
2020-06-15 05:42:44 +02:00
|
|
|
import NestedToolbar from './NestedToolbar.jsx';
|
2020-05-16 11:05:50 +02:00
|
|
|
|
2020-05-14 21:57:45 +02:00
|
|
|
function ViewerLayout({
|
|
|
|
|
// From Extension Module Params
|
|
|
|
|
extensionManager,
|
2020-05-18 17:21:57 +02:00
|
|
|
servicesManager,
|
2020-05-19 14:01:39 +02:00
|
|
|
commandsManager,
|
2020-05-14 21:57:45 +02:00
|
|
|
// From Modes
|
|
|
|
|
leftPanels,
|
|
|
|
|
rightPanels,
|
2020-05-15 19:07:21 +02:00
|
|
|
viewports,
|
2020-05-18 18:21:43 +02:00
|
|
|
children,
|
2020-05-19 11:01:44 +02:00
|
|
|
ViewportGridComp,
|
2020-05-14 21:57:45 +02:00
|
|
|
}) {
|
2020-05-19 11:01:44 +02:00
|
|
|
const { ToolBarService } = servicesManager.services;
|
2020-05-15 04:53:32 +02:00
|
|
|
/**
|
|
|
|
|
* Set body classes (tailwindcss) that don't allow vertical
|
|
|
|
|
* or horizontal overflow (no scrolling). Also guarantee window
|
|
|
|
|
* is sized to our viewport.
|
|
|
|
|
*/
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
document.body.classList.add('bg-black');
|
|
|
|
|
document.body.classList.add('overflow-hidden');
|
|
|
|
|
return () => {
|
|
|
|
|
document.body.classList.remove('bg-black');
|
|
|
|
|
document.body.classList.remove('overflow-hidden');
|
|
|
|
|
};
|
|
|
|
|
}, []);
|
2020-05-19 11:01:44 +02:00
|
|
|
|
2020-05-14 21:57:45 +02:00
|
|
|
const getPanelData = id => {
|
|
|
|
|
const entry = extensionManager.getModuleEntry(id);
|
|
|
|
|
// TODO, not sure why sidepanel content has to be JSX, and not a children prop?
|
2020-05-15 12:48:00 +02:00
|
|
|
const content = entry.component;
|
2020-05-14 21:57:45 +02:00
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
iconName: entry.iconName,
|
|
|
|
|
iconLabel: entry.iconLabel,
|
|
|
|
|
label: entry.label,
|
|
|
|
|
name: entry.name,
|
|
|
|
|
content,
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2020-05-15 19:07:21 +02:00
|
|
|
const getViewportComponentData = viewportComponent => {
|
|
|
|
|
const entry = extensionManager.getModuleEntry(viewportComponent.namespace);
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
component: entry.component,
|
|
|
|
|
displaySetsToDisplay: viewportComponent.displaySetsToDisplay,
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2020-06-15 03:18:29 +02:00
|
|
|
const [toolbars, setToolbars] = useState({ primary: [], secondary: [] });
|
2020-05-18 17:21:57 +02:00
|
|
|
|
2020-05-19 11:01:44 +02:00
|
|
|
useEffect(() => {
|
|
|
|
|
const { unsubscribe } = ToolBarService.subscribe(
|
|
|
|
|
ToolBarService.EVENTS.TOOL_BAR_MODIFIED,
|
2020-06-15 03:18:29 +02:00
|
|
|
() => {
|
|
|
|
|
console.warn('~~~ TOOL BAR MODIFIED EVENT CAUGHT');
|
|
|
|
|
const updatedToolbars = {
|
|
|
|
|
primary: ToolBarService.getButtonSection('primary'),
|
|
|
|
|
secondary: ToolBarService.getButtonSection('secondary'),
|
|
|
|
|
};
|
|
|
|
|
setToolbars(updatedToolbars);
|
|
|
|
|
}
|
2020-05-19 11:01:44 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return unsubscribe;
|
2020-06-15 03:18:29 +02:00
|
|
|
}, [ToolBarService]);
|
2020-05-14 21:57:45 +02:00
|
|
|
|
2020-05-19 11:01:44 +02:00
|
|
|
const leftPanelComponents = leftPanels.map(getPanelData);
|
|
|
|
|
const rightPanelComponents = rightPanels.map(getPanelData);
|
|
|
|
|
const viewportComponents = viewports.map(getViewportComponentData);
|
2020-05-14 21:57:45 +02:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div>
|
2020-06-15 03:18:29 +02:00
|
|
|
<Header>
|
2020-06-15 05:42:44 +02:00
|
|
|
<div className="relative flex justify-center">
|
2020-06-15 03:18:29 +02:00
|
|
|
{toolbars.primary.map(toolDef => {
|
2020-06-15 05:42:44 +02:00
|
|
|
const isNested = Array.isArray(toolDef);
|
2020-06-15 03:18:29 +02:00
|
|
|
|
2020-06-15 05:42:44 +02:00
|
|
|
if (!isNested) {
|
|
|
|
|
const { id, Component, componentProps } = toolDef;
|
|
|
|
|
|
|
|
|
|
return <Component key={id} id={id} {...componentProps} />;
|
|
|
|
|
} else {
|
|
|
|
|
return (
|
|
|
|
|
<NestedToolbar>
|
|
|
|
|
<div className="flex">
|
|
|
|
|
{toolDef.map(x => {
|
|
|
|
|
const { id, Component, componentProps } = x;
|
|
|
|
|
return <Component key={id} id={id} {...componentProps} />;
|
|
|
|
|
})}
|
|
|
|
|
</div>
|
|
|
|
|
</NestedToolbar>
|
|
|
|
|
);
|
|
|
|
|
}
|
2020-06-15 03:18:29 +02:00
|
|
|
})}
|
|
|
|
|
</div>
|
|
|
|
|
</Header>
|
2020-05-14 21:57:45 +02:00
|
|
|
<div
|
2020-05-21 22:24:35 +02:00
|
|
|
className="flex flex-row flex-no-wrap items-stretch w-full overflow-hidden"
|
2020-05-14 21:57:45 +02:00
|
|
|
style={{ height: 'calc(100vh - 57px' }}
|
|
|
|
|
>
|
2020-05-15 04:55:17 +02:00
|
|
|
{/* LEFT SIDEPANELS */}
|
2020-05-26 15:02:47 +02:00
|
|
|
{leftPanelComponents.length && (
|
|
|
|
|
<SidePanel
|
|
|
|
|
side="left"
|
|
|
|
|
defaultComponentOpen={leftPanelComponents[0].name}
|
|
|
|
|
childComponents={leftPanelComponents}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2020-05-15 04:55:17 +02:00
|
|
|
{/* TOOLBAR + GRID */}
|
|
|
|
|
<div className="flex flex-col flex-1 h-full">
|
2020-05-21 22:24:35 +02:00
|
|
|
<div className="flex h-12 border-b border-transparent flex-2 w-100">
|
2020-06-15 03:18:29 +02:00
|
|
|
{toolbars.secondary.map(toolDef => {
|
|
|
|
|
const { id, Component, componentProps } = toolDef;
|
|
|
|
|
|
|
|
|
|
return <Component key={id} id={id} {...componentProps} />;
|
|
|
|
|
})}
|
2020-05-14 21:57:45 +02:00
|
|
|
</div>
|
2020-05-21 22:24:35 +02:00
|
|
|
<div className="flex items-center justify-center flex-1 h-full pt-1 pb-2 overflow-hidden bg-black">
|
2020-05-18 19:49:32 +02:00
|
|
|
<ViewportGridComp
|
2020-05-18 17:21:57 +02:00
|
|
|
servicesManager={servicesManager}
|
2020-05-15 19:07:21 +02:00
|
|
|
viewportComponents={viewportComponents}
|
2020-05-18 19:49:32 +02:00
|
|
|
/>
|
2020-05-14 21:57:45 +02:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2020-05-26 15:02:47 +02:00
|
|
|
{rightPanelComponents.length && (
|
|
|
|
|
<SidePanel
|
|
|
|
|
side="right"
|
|
|
|
|
defaultComponentOpen={rightPanelComponents[0].name}
|
|
|
|
|
childComponents={rightPanelComponents}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2020-05-14 21:57:45 +02:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ViewerLayout.propTypes = {
|
|
|
|
|
// From extension module params
|
|
|
|
|
extensionManager: PropTypes.shape({
|
|
|
|
|
getModuleEntry: PropTypes.func.isRequired,
|
|
|
|
|
}).isRequired,
|
2020-05-19 14:01:39 +02:00
|
|
|
commandsManager: PropTypes.object,
|
2020-05-14 21:57:45 +02:00
|
|
|
// From modes
|
|
|
|
|
leftPanels: PropTypes.array,
|
|
|
|
|
rightPanels: PropTypes.array,
|
|
|
|
|
/** Responsible for rendering our grid of viewports; provided by consuming application */
|
2020-05-18 17:21:57 +02:00
|
|
|
children: PropTypes.oneOfType(PropTypes.node, PropTypes.func).isRequired,
|
2020-05-14 21:57:45 +02:00
|
|
|
};
|
|
|
|
|
|
2020-05-26 15:02:47 +02:00
|
|
|
ViewerLayout.defaultProps = {
|
|
|
|
|
leftPanels: [],
|
|
|
|
|
rightPanels: [],
|
|
|
|
|
};
|
|
|
|
|
|
2020-05-14 21:57:45 +02:00
|
|
|
export default ViewerLayout;
|