2020-06-15 03:18:29 +02:00
|
|
|
import React, { useEffect, useState } from 'react';
|
2020-05-14 21:57:45 +02:00
|
|
|
import PropTypes from 'prop-types';
|
2020-08-19 21:02:59 +02:00
|
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
|
import { SidePanel, ErrorBoundary, UserPreferences, AboutModal, Header, useModal } from '@ohif/ui';
|
|
|
|
|
|
2020-06-15 06:51:36 +02:00
|
|
|
import NestedMenu from './ToolbarButtonNestedMenu.jsx';
|
2020-05-16 11:05:50 +02:00
|
|
|
|
2020-08-17 10:19:12 +02:00
|
|
|
// TODO: Having ToolbarPrimary and ToolbarSecondary is ugly, but
|
|
|
|
|
// these are going to be unified shortly so this is good enough for now.
|
2020-08-19 21:02:59 +02:00
|
|
|
function ToolbarPrimary({ servicesManager }) {
|
2020-05-19 11:01:44 +02:00
|
|
|
const { ToolBarService } = servicesManager.services;
|
2020-08-17 10:19:12 +02:00
|
|
|
const defaultTool = {
|
|
|
|
|
icon: 'tool-more-menu',
|
|
|
|
|
label: 'More',
|
|
|
|
|
isActive: false,
|
|
|
|
|
};
|
|
|
|
|
const [toolbars, setToolbars] = useState({ primary: [], secondary: [] });
|
|
|
|
|
const [activeTool, setActiveTool] = useState(defaultTool);
|
2020-05-19 11:01:44 +02:00
|
|
|
|
2020-08-17 10:19:12 +02:00
|
|
|
const setActiveToolHandler = (tool, isNested) => {
|
|
|
|
|
setActiveTool(isNested ? tool : defaultTool);
|
|
|
|
|
};
|
2020-05-14 21:57:45 +02:00
|
|
|
|
2020-08-17 10:19:12 +02:00
|
|
|
const onPrimaryClickHandler = (evt, btn) => {
|
|
|
|
|
if (
|
|
|
|
|
btn.props &&
|
|
|
|
|
btn.props.commands &&
|
|
|
|
|
evt.value &&
|
|
|
|
|
btn.props.commands[evt.value]
|
|
|
|
|
) {
|
|
|
|
|
const { commandName, commandOptions } = btn.props.commands[evt.value];
|
|
|
|
|
commandsManager.runCommand(commandName, commandOptions);
|
|
|
|
|
}
|
2020-05-14 21:57:45 +02:00
|
|
|
};
|
|
|
|
|
|
2020-08-17 10:19:12 +02:00
|
|
|
useEffect(() => {
|
|
|
|
|
const { unsubscribe } = ToolBarService.subscribe(
|
|
|
|
|
ToolBarService.EVENTS.TOOL_BAR_MODIFIED,
|
|
|
|
|
() => {
|
|
|
|
|
console.warn('~~~ TOOL BAR MODIFIED EVENT CAUGHT');
|
|
|
|
|
const updatedToolbars = {
|
|
|
|
|
primary: ToolBarService.getButtonSection('primary', {
|
|
|
|
|
onClick: onPrimaryClickHandler,
|
|
|
|
|
setActiveTool: setActiveToolHandler,
|
|
|
|
|
}),
|
|
|
|
|
secondary: ToolBarService.getButtonSection('secondary', {
|
|
|
|
|
setActiveTool: setActiveToolHandler,
|
|
|
|
|
}),
|
|
|
|
|
};
|
|
|
|
|
setToolbars(updatedToolbars);
|
|
|
|
|
}
|
|
|
|
|
);
|
2020-05-15 19:07:21 +02:00
|
|
|
|
2020-08-17 10:19:12 +02:00
|
|
|
return unsubscribe;
|
|
|
|
|
}, [ToolBarService]);
|
2020-05-15 19:07:21 +02:00
|
|
|
|
2020-08-17 10:19:12 +02:00
|
|
|
return <>
|
|
|
|
|
{toolbars.primary.map((toolDef, index) => {
|
|
|
|
|
const isNested = Array.isArray(toolDef);
|
|
|
|
|
if (!isNested) {
|
|
|
|
|
const { id, Component, componentProps } = toolDef;
|
|
|
|
|
return <Component key={id} id={id} {...componentProps} />;
|
|
|
|
|
} else {
|
|
|
|
|
return (
|
|
|
|
|
<NestedMenu
|
|
|
|
|
key={index}
|
|
|
|
|
isActive={activeTool.isActive}
|
|
|
|
|
icon={activeTool.icon}
|
|
|
|
|
label={activeTool.label}
|
|
|
|
|
>
|
|
|
|
|
<div className="flex">
|
|
|
|
|
{toolDef.map(x => {
|
|
|
|
|
const { id, Component, componentProps } = x;
|
|
|
|
|
return (
|
|
|
|
|
<Component key={id} id={id} {...componentProps} />
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</div>
|
|
|
|
|
</NestedMenu>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
})}
|
|
|
|
|
</>
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-19 21:02:59 +02:00
|
|
|
function ToolbarSecondary({ servicesManager }) {
|
2020-08-17 10:19:12 +02:00
|
|
|
const { ToolBarService } = servicesManager.services;
|
2020-07-24 12:51:57 +02:00
|
|
|
const defaultTool = {
|
|
|
|
|
icon: 'tool-more-menu',
|
|
|
|
|
label: 'More',
|
|
|
|
|
isActive: false,
|
|
|
|
|
};
|
2020-06-15 03:18:29 +02:00
|
|
|
const [toolbars, setToolbars] = useState({ primary: [], secondary: [] });
|
2020-08-19 21:24:07 +02:00
|
|
|
const [nestedActiveTool, setNestedActiveTool] = useState(defaultTool);
|
2020-06-25 21:03:06 +02:00
|
|
|
|
|
|
|
|
const setActiveToolHandler = (tool, isNested) => {
|
2020-08-19 21:24:07 +02:00
|
|
|
setNestedActiveTool(isNested ? tool : defaultTool);
|
2020-06-24 17:11:54 +02:00
|
|
|
};
|
2020-05-18 17:21:57 +02:00
|
|
|
|
2020-06-25 20:27:42 +02:00
|
|
|
const onPrimaryClickHandler = (evt, btn) => {
|
2020-07-24 12:51:57 +02:00
|
|
|
if (
|
|
|
|
|
btn.props &&
|
|
|
|
|
btn.props.commands &&
|
2020-08-19 21:49:00 +02:00
|
|
|
evt.item && evt.item.value &&
|
|
|
|
|
btn.props.commands[evt.item.value]
|
2020-07-24 12:51:57 +02:00
|
|
|
) {
|
2020-08-19 21:49:00 +02:00
|
|
|
const { commandName, commandOptions } = btn.props.commands[evt.item.value];
|
2020-06-25 20:27:42 +02:00
|
|
|
commandsManager.runCommand(commandName, commandOptions);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
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 = {
|
2020-07-24 12:51:57 +02:00
|
|
|
primary: ToolBarService.getButtonSection('primary', {
|
|
|
|
|
onClick: onPrimaryClickHandler,
|
|
|
|
|
setActiveTool: setActiveToolHandler,
|
|
|
|
|
}),
|
|
|
|
|
secondary: ToolBarService.getButtonSection('secondary', {
|
|
|
|
|
setActiveTool: setActiveToolHandler,
|
|
|
|
|
}),
|
2020-06-15 03:18:29 +02:00
|
|
|
};
|
|
|
|
|
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-08-17 10:19:12 +02:00
|
|
|
return <>
|
|
|
|
|
{toolbars.secondary.map(toolDef => {
|
|
|
|
|
const { id, Component, componentProps } = toolDef;
|
|
|
|
|
return <Component key={id} id={id} {...componentProps} />;
|
|
|
|
|
})}
|
|
|
|
|
</>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function ViewerLayout({
|
|
|
|
|
// From Extension Module Params
|
|
|
|
|
extensionManager,
|
|
|
|
|
servicesManager,
|
2020-08-19 21:02:59 +02:00
|
|
|
hotkeysManager,
|
2020-08-19 22:17:05 +02:00
|
|
|
commandsManager,
|
2020-08-17 10:19:12 +02:00
|
|
|
// From Modes
|
|
|
|
|
leftPanels,
|
|
|
|
|
rightPanels,
|
|
|
|
|
viewports,
|
|
|
|
|
ViewportGridComp,
|
|
|
|
|
}) {
|
2020-08-19 21:02:59 +02:00
|
|
|
const { t } = useTranslation();
|
|
|
|
|
const { show, hide } = useModal();
|
|
|
|
|
|
|
|
|
|
const { hotkeyDefinitions, hotkeyDefaults } = hotkeysManager;
|
|
|
|
|
const menuOptions = [
|
|
|
|
|
{
|
|
|
|
|
title: t('Header:About'),
|
|
|
|
|
icon: 'info',
|
|
|
|
|
onClick: () => show({ content: AboutModal, title: 'About OHIF Viewer' })
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: t('Header:Preferences'),
|
|
|
|
|
icon: 'settings',
|
|
|
|
|
onClick: () => show({
|
|
|
|
|
title: t('UserPreferencesModal:User Preferences'),
|
|
|
|
|
content: UserPreferences,
|
|
|
|
|
contentProps: {
|
|
|
|
|
hotkeyDefaults: hotkeysManager.getValidHotkeyDefinitions(hotkeyDefaults),
|
|
|
|
|
hotkeyDefinitions,
|
|
|
|
|
onCancel: hide,
|
|
|
|
|
onSubmit: ({ hotkeyDefinitions }) => {
|
|
|
|
|
hotkeysManager.setHotkeys(hotkeyDefinitions);
|
|
|
|
|
hide();
|
|
|
|
|
},
|
|
|
|
|
onReset: () => hotkeysManager.restoreDefaultBindings()
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
];
|
2020-08-17 10:19:12 +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');
|
|
|
|
|
};
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
const getPanelData = id => {
|
|
|
|
|
const entry = extensionManager.getModuleEntry(id);
|
|
|
|
|
// TODO, not sure why sidepanel content has to be JSX, and not a children prop?
|
|
|
|
|
const content = entry.component;
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
iconName: entry.iconName,
|
|
|
|
|
iconLabel: entry.iconLabel,
|
|
|
|
|
label: entry.label,
|
|
|
|
|
name: entry.name,
|
|
|
|
|
content,
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const getViewportComponentData = viewportComponent => {
|
|
|
|
|
const entry = extensionManager.getModuleEntry(viewportComponent.namespace);
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
component: entry.component,
|
|
|
|
|
displaySetsToDisplay: viewportComponent.displaySetsToDisplay,
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
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-08-19 21:02:59 +02:00
|
|
|
<Header menuOptions={menuOptions}>
|
2020-06-26 19:08:29 +02:00
|
|
|
<ErrorBoundary context="Primary Toolbar">
|
|
|
|
|
<div className="relative flex justify-center">
|
2020-08-19 21:02:59 +02:00
|
|
|
<ToolbarPrimary servicesManager={servicesManager} />
|
2020-06-26 19:08:29 +02:00
|
|
|
</div>
|
|
|
|
|
</ErrorBoundary>
|
2020-06-15 03:18:29 +02:00
|
|
|
</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 && (
|
2020-06-26 19:08:29 +02:00
|
|
|
<ErrorBoundary context="Left Panel">
|
|
|
|
|
<SidePanel
|
|
|
|
|
side="left"
|
|
|
|
|
defaultComponentOpen={leftPanelComponents[0].name}
|
|
|
|
|
childComponents={leftPanelComponents}
|
|
|
|
|
/>
|
|
|
|
|
</ErrorBoundary>
|
2020-05-26 15:02:47 +02:00
|
|
|
)}
|
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-26 19:08:29 +02:00
|
|
|
<ErrorBoundary context="Secondary Toolbar">
|
|
|
|
|
<div className="flex items-center w-full px-3 bg-primary-dark">
|
2020-08-19 21:02:59 +02:00
|
|
|
<ToolbarSecondary servicesManager={servicesManager} />
|
2020-06-26 19:08:29 +02:00
|
|
|
</div>
|
|
|
|
|
</ErrorBoundary>
|
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-06-26 19:08:29 +02:00
|
|
|
<ErrorBoundary context="Grid">
|
|
|
|
|
<ViewportGridComp
|
|
|
|
|
servicesManager={servicesManager}
|
|
|
|
|
viewportComponents={viewportComponents}
|
2020-08-19 21:24:07 +02:00
|
|
|
commandsManager={commandsManager}
|
2020-06-26 19:08:29 +02:00
|
|
|
/>
|
|
|
|
|
</ErrorBoundary>
|
2020-05-14 21:57:45 +02:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2020-05-26 15:02:47 +02:00
|
|
|
{rightPanelComponents.length && (
|
2020-06-26 19:08:29 +02:00
|
|
|
<ErrorBoundary context="Right Panel">
|
|
|
|
|
<SidePanel
|
|
|
|
|
side="right"
|
|
|
|
|
defaultComponentOpen={rightPanelComponents[0].name}
|
|
|
|
|
childComponents={rightPanelComponents}
|
|
|
|
|
/>
|
|
|
|
|
</ErrorBoundary>
|
2020-05-26 15:02:47 +02:00
|
|
|
)}
|
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-07-24 12:51: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;
|