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';
|
2022-04-06 19:28:42 +02:00
|
|
|
import { useNavigate } from 'react-router-dom';
|
2020-08-19 21:02:59 +02:00
|
|
|
import { useTranslation } from 'react-i18next';
|
2020-09-15 03:18:46 +02:00
|
|
|
import {
|
|
|
|
|
SidePanel,
|
|
|
|
|
ErrorBoundary,
|
|
|
|
|
UserPreferences,
|
|
|
|
|
AboutModal,
|
|
|
|
|
Header,
|
|
|
|
|
useModal,
|
|
|
|
|
} from '@ohif/ui';
|
|
|
|
|
|
2021-06-15 16:56:33 +02:00
|
|
|
import i18n from '@ohif/i18n';
|
2021-07-21 12:58:15 +02:00
|
|
|
import { hotkeys } from '@ohif/core';
|
2022-04-06 19:28:42 +02:00
|
|
|
import { useAppConfig } from '@state';
|
2021-06-15 16:56:33 +02:00
|
|
|
|
|
|
|
|
const { availableLanguages, defaultLanguage, currentLanguage } = i18n;
|
|
|
|
|
|
2020-09-15 03:18:46 +02:00
|
|
|
function Toolbar({ servicesManager }) {
|
2020-05-19 11:01:44 +02:00
|
|
|
const { ToolBarService } = servicesManager.services;
|
2020-09-15 03:18:46 +02:00
|
|
|
const [toolbarButtons, setToolbarButtons] = useState([]);
|
|
|
|
|
const [buttonState, setButtonState] = useState({
|
|
|
|
|
primaryToolId: '',
|
|
|
|
|
toggles: {},
|
|
|
|
|
groups: {},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Could track buttons and state separately...?
|
2020-08-17 10:19:12 +02:00
|
|
|
useEffect(() => {
|
2020-09-15 03:18:46 +02:00
|
|
|
const { unsubscribe: unsub1 } = ToolBarService.subscribe(
|
2020-08-17 10:19:12 +02:00
|
|
|
ToolBarService.EVENTS.TOOL_BAR_MODIFIED,
|
2020-09-15 03:18:46 +02:00
|
|
|
() => setToolbarButtons(ToolBarService.getButtonSection('primary'))
|
|
|
|
|
);
|
|
|
|
|
const { unsubscribe: unsub2 } = ToolBarService.subscribe(
|
|
|
|
|
ToolBarService.EVENTS.TOOL_BAR_STATE_MODIFIED,
|
|
|
|
|
() => setButtonState({ ...ToolBarService.state })
|
2020-08-17 10:19:12 +02:00
|
|
|
);
|
2020-05-15 19:07:21 +02:00
|
|
|
|
2020-09-15 03:18:46 +02:00
|
|
|
return () => {
|
|
|
|
|
unsub1();
|
|
|
|
|
unsub2();
|
|
|
|
|
};
|
2020-08-17 10:19:12 +02:00
|
|
|
}, [ToolBarService]);
|
2020-05-15 19:07:21 +02:00
|
|
|
|
2020-09-15 03:18:46 +02:00
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
{toolbarButtons.map((toolDef, index) => {
|
2020-08-17 10:19:12 +02:00
|
|
|
const { id, Component, componentProps } = toolDef;
|
2020-09-15 03:18:46 +02:00
|
|
|
// TODO: ...
|
2020-08-17 10:19:12 +02:00
|
|
|
|
2020-09-15 03:18:46 +02:00
|
|
|
// isActive if:
|
|
|
|
|
// - id is primary?
|
|
|
|
|
// - id is in list of "toggled on"?
|
2021-05-28 20:32:48 +02:00
|
|
|
let isActive;
|
|
|
|
|
if (componentProps.type === 'toggle') {
|
|
|
|
|
isActive = buttonState.toggles[id];
|
|
|
|
|
}
|
2020-09-15 03:18:46 +02:00
|
|
|
// Also need... to filter list for splitButton, and set primary based on most recently clicked
|
|
|
|
|
// Also need to kill the radioGroup button's magic logic
|
|
|
|
|
// Everything should be reactive off these props, so commands can inform ToolbarService
|
2020-05-14 21:57:45 +02:00
|
|
|
|
2020-09-15 03:18:46 +02:00
|
|
|
// These can... Trigger toolbar events based on updates?
|
|
|
|
|
// Then sync using useEffect, or simply modify the state here?
|
|
|
|
|
return (
|
|
|
|
|
<Component
|
|
|
|
|
key={id}
|
|
|
|
|
id={id}
|
|
|
|
|
{...componentProps}
|
|
|
|
|
bState={buttonState}
|
2021-05-28 20:32:48 +02:00
|
|
|
isActive={isActive}
|
2020-09-15 03:18:46 +02:00
|
|
|
onInteraction={args => ToolBarService.recordInteraction(args)}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</>
|
|
|
|
|
);
|
2020-08-17 10:19:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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,
|
2022-09-28 21:46:58 +02:00
|
|
|
leftPanelDefaultClosed,
|
|
|
|
|
rightPanelDefaultClosed,
|
2020-08-17 10:19:12 +02:00
|
|
|
viewports,
|
|
|
|
|
ViewportGridComp,
|
|
|
|
|
}) {
|
2021-05-28 20:32:48 +02:00
|
|
|
const [appConfig] = useAppConfig();
|
2021-07-08 15:23:09 +02:00
|
|
|
const navigate = useNavigate();
|
|
|
|
|
|
|
|
|
|
const onClickReturnButton = () => {
|
2022-04-06 19:28:42 +02:00
|
|
|
navigate('/');
|
2021-07-08 15:23:09 +02:00
|
|
|
};
|
2021-05-28 20:32:48 +02:00
|
|
|
|
2020-08-19 21:02:59 +02:00
|
|
|
const { t } = useTranslation();
|
|
|
|
|
const { show, hide } = useModal();
|
|
|
|
|
|
|
|
|
|
const { hotkeyDefinitions, hotkeyDefaults } = hotkeysManager;
|
2021-08-24 14:13:54 +02:00
|
|
|
const versionNumber = process.env.VERSION_NUMBER;
|
|
|
|
|
const buildNumber = process.env.BUILD_NUM;
|
|
|
|
|
|
2020-08-19 21:02:59 +02:00
|
|
|
const menuOptions = [
|
|
|
|
|
{
|
|
|
|
|
title: t('Header:About'),
|
|
|
|
|
icon: 'info',
|
2022-04-06 19:28:42 +02:00
|
|
|
onClick: () =>
|
|
|
|
|
show({
|
|
|
|
|
content: AboutModal,
|
|
|
|
|
title: 'About OHIF Viewer',
|
|
|
|
|
contentProps: { versionNumber, buildNumber },
|
|
|
|
|
}),
|
2020-08-19 21:02:59 +02:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: t('Header:Preferences'),
|
|
|
|
|
icon: 'settings',
|
2020-09-15 03:18:46 +02:00
|
|
|
onClick: () =>
|
|
|
|
|
show({
|
|
|
|
|
title: t('UserPreferencesModal:User Preferences'),
|
|
|
|
|
content: UserPreferences,
|
|
|
|
|
contentProps: {
|
|
|
|
|
hotkeyDefaults: hotkeysManager.getValidHotkeyDefinitions(
|
|
|
|
|
hotkeyDefaults
|
|
|
|
|
),
|
|
|
|
|
hotkeyDefinitions,
|
2021-06-15 16:56:33 +02:00
|
|
|
currentLanguage: currentLanguage(),
|
|
|
|
|
availableLanguages,
|
|
|
|
|
defaultLanguage,
|
2021-07-06 04:32:06 +02:00
|
|
|
onCancel: () => {
|
|
|
|
|
hotkeys.stopRecord();
|
|
|
|
|
hotkeys.unpause();
|
|
|
|
|
hide();
|
|
|
|
|
},
|
2021-06-15 16:56:33 +02:00
|
|
|
onSubmit: ({ hotkeyDefinitions, language }) => {
|
|
|
|
|
i18n.changeLanguage(language.value);
|
2020-09-15 03:18:46 +02:00
|
|
|
hotkeysManager.setHotkeys(hotkeyDefinitions);
|
|
|
|
|
hide();
|
|
|
|
|
},
|
|
|
|
|
onReset: () => hotkeysManager.restoreDefaultBindings(),
|
2022-04-06 19:28:42 +02:00
|
|
|
hotkeysModule: hotkeys,
|
2020-08-19 21:02:59 +02:00
|
|
|
},
|
2020-09-15 03:18:46 +02:00
|
|
|
}),
|
2020-08-19 21:02:59 +02:00
|
|
|
},
|
|
|
|
|
];
|
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>
|
2022-04-06 19:28:42 +02:00
|
|
|
<Header
|
|
|
|
|
menuOptions={menuOptions}
|
|
|
|
|
onClickReturnButton={onClickReturnButton}
|
|
|
|
|
WhiteLabeling={appConfig.whiteLabeling}
|
|
|
|
|
>
|
2020-06-26 19:08:29 +02:00
|
|
|
<ErrorBoundary context="Primary Toolbar">
|
|
|
|
|
<div className="relative flex justify-center">
|
2020-09-15 03:18:46 +02:00
|
|
|
<Toolbar 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
|
2022-07-27 18:39:04 +02:00
|
|
|
className="bg-black flex flex-row items-stretch w-full overflow-hidden flex-nowrap"
|
2020-09-21 10:42:53 +02:00
|
|
|
style={{ height: 'calc(100vh - 52px' }}
|
2020-05-14 21:57:45 +02:00
|
|
|
>
|
2020-05-15 04:55:17 +02:00
|
|
|
{/* LEFT SIDEPANELS */}
|
2022-07-27 18:39:04 +02:00
|
|
|
{leftPanelComponents.length ? (
|
2020-06-26 19:08:29 +02:00
|
|
|
<ErrorBoundary context="Left Panel">
|
|
|
|
|
<SidePanel
|
|
|
|
|
side="left"
|
2022-09-28 21:46:58 +02:00
|
|
|
defaultComponentOpen={
|
|
|
|
|
leftPanelDefaultClosed ? null : leftPanelComponents[0].name
|
|
|
|
|
}
|
2020-06-26 19:08:29 +02:00
|
|
|
childComponents={leftPanelComponents}
|
|
|
|
|
/>
|
|
|
|
|
</ErrorBoundary>
|
2022-07-27 18:39:04 +02:00
|
|
|
) : null}
|
2020-05-15 04:55:17 +02:00
|
|
|
{/* TOOLBAR + GRID */}
|
|
|
|
|
<div className="flex flex-col flex-1 h-full">
|
2022-07-27 18:39:04 +02:00
|
|
|
<div className="flex items-center justify-center flex-1 h-full 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>
|
2022-07-27 18:39:04 +02:00
|
|
|
{rightPanelComponents.length ? (
|
2020-06-26 19:08:29 +02:00
|
|
|
<ErrorBoundary context="Right Panel">
|
|
|
|
|
<SidePanel
|
|
|
|
|
side="right"
|
2022-09-28 21:46:58 +02:00
|
|
|
defaultComponentOpen={
|
|
|
|
|
rightPanelDefaultClosed ? null : rightPanelComponents[0].name
|
|
|
|
|
}
|
2020-06-26 19:08:29 +02:00
|
|
|
childComponents={rightPanelComponents}
|
|
|
|
|
/>
|
|
|
|
|
</ErrorBoundary>
|
2022-07-27 18:39:04 +02:00
|
|
|
) : null}
|
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,
|
2022-09-28 21:46:58 +02:00
|
|
|
leftPanelDefaultClosed: PropTypes.bool.isRequired,
|
|
|
|
|
rightPanelDefaultClosed: PropTypes.bool.isRequired,
|
2020-05-14 21:57:45 +02:00
|
|
|
/** 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: [],
|
2022-09-28 21:46:58 +02:00
|
|
|
leftPanelDefaultClosed: false,
|
|
|
|
|
rightPanelDefaultClosed: false,
|
2020-05-26 15:02:47 +02:00
|
|
|
};
|
|
|
|
|
|
2020-05-14 21:57:45 +02:00
|
|
|
export default ViewerLayout;
|