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,
|
2022-11-16 20:19:52 +01:00
|
|
|
LoadingIndicatorProgress,
|
2020-09-15 03:18:46 +02:00
|
|
|
} 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';
|
2022-11-16 20:19:52 +01:00
|
|
|
import Toolbar from '../Toolbar/Toolbar';
|
2021-06-15 16:56:33 +02:00
|
|
|
|
|
|
|
|
const { availableLanguages, defaultLanguage, currentLanguage } = i18n;
|
|
|
|
|
|
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
|
|
|
|
|
viewports,
|
|
|
|
|
ViewportGridComp,
|
2022-11-16 20:19:52 +01:00
|
|
|
leftPanels = [],
|
|
|
|
|
rightPanels = [],
|
|
|
|
|
leftPanelDefaultClosed = false,
|
|
|
|
|
rightPanelDefaultClosed = false,
|
2020-08-17 10:19:12 +02:00
|
|
|
}) {
|
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();
|
|
|
|
|
|
2022-11-16 20:19:52 +01:00
|
|
|
const [showLoadingIndicator, setShowLoadingIndicator] = useState(
|
|
|
|
|
appConfig.showLoadingIndicator
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const { HangingProtocolService } = servicesManager.services;
|
|
|
|
|
|
2020-08-19 21:02:59 +02:00
|
|
|
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
|
|
|
|
2022-10-07 04:40:16 +02:00
|
|
|
if (appConfig.oidc) {
|
|
|
|
|
menuOptions.push({
|
|
|
|
|
title: t('Header:Logout'),
|
|
|
|
|
icon: 'power-off',
|
|
|
|
|
onClick: async () => {
|
2022-11-16 20:19:52 +01:00
|
|
|
navigate(
|
|
|
|
|
`/logout?redirect_uri=${encodeURIComponent(window.location.href)}`
|
|
|
|
|
);
|
|
|
|
|
},
|
2022-10-07 04:40:16 +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,
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2022-11-16 20:19:52 +01:00
|
|
|
useEffect(() => {
|
|
|
|
|
const { unsubscribe } = HangingProtocolService.subscribe(
|
|
|
|
|
HangingProtocolService.EVENTS.HANGING_PROTOCOL_APPLIED_FOR_VIEWPORT,
|
|
|
|
|
|
|
|
|
|
// Todo: right now to set the loading indicator to false, we need to wait for the
|
|
|
|
|
// HangingProtocolService to finish applying the viewport matching to each viewport,
|
|
|
|
|
// however, this might not be the only approach to set the loading indicator to false. we need to explore this further.
|
|
|
|
|
({ progress }) => {
|
|
|
|
|
if (progress === 100) {
|
|
|
|
|
setShowLoadingIndicator(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
|
unsubscribe();
|
|
|
|
|
};
|
|
|
|
|
}, [HangingProtocolService]);
|
|
|
|
|
|
2020-08-17 10:19:12 +02:00
|
|
|
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-11-16 20:19:52 +01:00
|
|
|
className="bg-black flex flex-row items-stretch w-full overflow-hidden flex-nowrap relative"
|
2020-09-21 10:42:53 +02:00
|
|
|
style={{ height: 'calc(100vh - 52px' }}
|
2020-05-14 21:57:45 +02:00
|
|
|
>
|
2022-11-16 20:19:52 +01:00
|
|
|
<React.Fragment>
|
|
|
|
|
{showLoadingIndicator && (
|
|
|
|
|
<LoadingIndicatorProgress className="h-full w-full bg-black" />
|
|
|
|
|
)}
|
|
|
|
|
{/* LEFT SIDEPANELS */}
|
|
|
|
|
{leftPanelComponents.length ? (
|
|
|
|
|
<ErrorBoundary context="Left Panel">
|
|
|
|
|
<SidePanel
|
|
|
|
|
side="left"
|
|
|
|
|
activeTabIndex={leftPanelDefaultClosed ? null : 0}
|
|
|
|
|
tabs={leftPanelComponents}
|
2020-06-26 19:08:29 +02:00
|
|
|
/>
|
|
|
|
|
</ErrorBoundary>
|
2022-11-16 20:19:52 +01:00
|
|
|
) : null}
|
|
|
|
|
{/* TOOLBAR + GRID */}
|
|
|
|
|
<div className="flex flex-col flex-1 h-full">
|
|
|
|
|
<div className="flex items-center justify-center flex-1 h-full overflow-hidden bg-black relative">
|
|
|
|
|
<ErrorBoundary context="Grid">
|
|
|
|
|
<ViewportGridComp
|
|
|
|
|
servicesManager={servicesManager}
|
|
|
|
|
viewportComponents={viewportComponents}
|
|
|
|
|
commandsManager={commandsManager}
|
|
|
|
|
/>
|
|
|
|
|
</ErrorBoundary>
|
|
|
|
|
</div>
|
2020-05-14 21:57:45 +02:00
|
|
|
</div>
|
2022-11-16 20:19:52 +01:00
|
|
|
{rightPanelComponents.length ? (
|
|
|
|
|
<ErrorBoundary context="Right Panel">
|
|
|
|
|
<SidePanel
|
|
|
|
|
side="right"
|
|
|
|
|
activeTabIndex={rightPanelDefaultClosed ? null : 0}
|
|
|
|
|
tabs={rightPanelComponents}
|
|
|
|
|
/>
|
|
|
|
|
</ErrorBoundary>
|
|
|
|
|
) : null}
|
|
|
|
|
</React.Fragment>
|
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
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default ViewerLayout;
|