2019-05-30 06:46:45 +02:00
|
|
|
import './ToolbarRow.css';
|
2019-05-30 05:47:26 +02:00
|
|
|
|
2019-05-30 06:46:45 +02:00
|
|
|
import React, { Component } from 'react';
|
2019-07-10 09:26:19 +02:00
|
|
|
import {
|
|
|
|
|
ExpandableToolMenu,
|
|
|
|
|
RoundedButtonGroup,
|
|
|
|
|
ToolbarButton,
|
|
|
|
|
} from 'react-viewerbase';
|
2019-06-16 19:58:25 +02:00
|
|
|
import { commandsManager, extensionManager } from './../App.js';
|
2019-05-30 05:47:26 +02:00
|
|
|
|
2019-06-21 02:30:12 +02:00
|
|
|
import ConnectedCineDialog from './ConnectedCineDialog';
|
2019-05-30 06:46:45 +02:00
|
|
|
import ConnectedLayoutButton from './ConnectedLayoutButton';
|
|
|
|
|
import ConnectedPluginSwitch from './ConnectedPluginSwitch.js';
|
2019-06-12 22:09:35 +02:00
|
|
|
import { MODULE_TYPES } from 'ohif-core';
|
2019-05-30 06:46:45 +02:00
|
|
|
import PropTypes from 'prop-types';
|
2019-07-11 11:32:09 +02:00
|
|
|
import { withTranslation } from 'react-i18next';
|
2019-01-17 17:00:21 +01:00
|
|
|
|
2018-12-18 14:15:55 +01:00
|
|
|
class ToolbarRow extends Component {
|
2019-07-04 20:09:13 +02:00
|
|
|
// TODO: Simplify these? isOpen can be computed if we say "any" value for selected,
|
|
|
|
|
// closed if selected is null/undefined
|
2019-02-01 04:01:39 +01:00
|
|
|
static propTypes = {
|
2019-07-04 20:09:13 +02:00
|
|
|
isLeftSidePanelOpen: PropTypes.bool.isRequired,
|
|
|
|
|
isRightSidePanelOpen: PropTypes.bool.isRequired,
|
|
|
|
|
selectedLeftSidePanel: PropTypes.string.isRequired,
|
|
|
|
|
selectedRightSidePanel: PropTypes.string.isRequired,
|
|
|
|
|
handleSidePanelChange: PropTypes.func,
|
2019-06-17 20:20:32 +02:00
|
|
|
activeContexts: PropTypes.arrayOf(PropTypes.string).isRequired,
|
2019-05-30 06:46:45 +02:00
|
|
|
};
|
2018-12-19 14:53:03 +01:00
|
|
|
|
2019-06-16 19:58:25 +02:00
|
|
|
constructor(props) {
|
|
|
|
|
super(props);
|
|
|
|
|
|
2019-06-17 20:20:32 +02:00
|
|
|
const toolbarButtonDefinitions = _getVisibleToolbarButtons.call(this);
|
2019-06-16 19:58:25 +02:00
|
|
|
// TODO:
|
|
|
|
|
// If it's a tool that can be active... Mark it as active?
|
|
|
|
|
// - Tools that are on/off?
|
|
|
|
|
// - Tools that can be bound to multiple buttons?
|
|
|
|
|
|
|
|
|
|
// Normal ToolbarButtons...
|
|
|
|
|
// Just how high do we need to hoist this state?
|
|
|
|
|
// Why ToolbarRow instead of just Toolbar? Do we have any others?
|
|
|
|
|
this.state = {
|
|
|
|
|
toolbarButtons: toolbarButtonDefinitions,
|
|
|
|
|
activeButtons: [],
|
2019-06-21 02:30:12 +02:00
|
|
|
isCineDialogOpen: false,
|
2019-06-16 19:58:25 +02:00
|
|
|
};
|
2019-06-21 02:30:12 +02:00
|
|
|
|
|
|
|
|
this._handleBuiltIn = _handleBuiltIn.bind(this);
|
2019-07-04 20:09:13 +02:00
|
|
|
|
|
|
|
|
const panelModules = extensionManager.modules[MODULE_TYPES.PANEL];
|
|
|
|
|
this.buttonGroups = {
|
|
|
|
|
left: [
|
|
|
|
|
// TODO: This should come from extensions, instead of being baked in
|
|
|
|
|
{
|
|
|
|
|
value: 'studies',
|
|
|
|
|
icon: 'th-large',
|
2019-07-11 11:32:09 +02:00
|
|
|
bottomLabel: this.props.t('Series'),
|
2019-07-04 20:09:13 +02:00
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
right: [],
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
panelModules.forEach(panelExtension => {
|
|
|
|
|
const panelModule = panelExtension.module;
|
|
|
|
|
const defaultContexts = Array.from(panelModule.defaultContext);
|
|
|
|
|
|
|
|
|
|
// MENU OPTIONS
|
|
|
|
|
panelModule.menuOptions.forEach(menuOption => {
|
|
|
|
|
const contexts = Array.from(menuOption.context || defaultContexts);
|
|
|
|
|
|
|
|
|
|
const activeContextIncludesAnyPanelContexts = this.props.activeContexts.some(
|
|
|
|
|
actx => contexts.includes(actx)
|
|
|
|
|
);
|
|
|
|
|
if (activeContextIncludesAnyPanelContexts) {
|
|
|
|
|
const menuOptionEntry = {
|
|
|
|
|
value: menuOption.target,
|
|
|
|
|
icon: menuOption.icon,
|
|
|
|
|
bottomLabel: menuOption.label,
|
|
|
|
|
};
|
|
|
|
|
const from = menuOption.from || 'right';
|
|
|
|
|
|
|
|
|
|
this.buttonGroups[from].push(menuOptionEntry);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
2019-06-16 19:58:25 +02:00
|
|
|
}
|
|
|
|
|
|
2019-06-17 20:20:32 +02:00
|
|
|
componentDidUpdate(prevProps) {
|
|
|
|
|
const activeContextsChanged =
|
|
|
|
|
prevProps.activeContexts !== this.props.activeContexts;
|
|
|
|
|
|
|
|
|
|
if (activeContextsChanged) {
|
|
|
|
|
this.setState({
|
|
|
|
|
toolbarButtons: _getVisibleToolbarButtons.call(this),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-01 04:01:39 +01:00
|
|
|
render() {
|
2019-06-16 19:58:25 +02:00
|
|
|
const buttonComponents = _getButtonComponents.call(
|
|
|
|
|
this,
|
|
|
|
|
this.state.toolbarButtons,
|
|
|
|
|
this.state.activeButtons
|
2019-06-13 15:51:19 +02:00
|
|
|
);
|
2019-02-24 15:26:50 +01:00
|
|
|
|
2019-06-21 02:30:12 +02:00
|
|
|
const cineDialogContainerStyle = {
|
|
|
|
|
display: this.state.isCineDialogOpen ? 'block' : 'none',
|
|
|
|
|
position: 'absolute',
|
|
|
|
|
top: '82px',
|
|
|
|
|
zIndex: 999,
|
|
|
|
|
};
|
|
|
|
|
|
2019-07-04 20:09:13 +02:00
|
|
|
const onPress = (side, value) => {
|
|
|
|
|
this.props.handleSidePanelChange(side, value);
|
|
|
|
|
};
|
|
|
|
|
const onPressLeft = onPress.bind(this, 'left');
|
|
|
|
|
const onPressRight = onPress.bind(this, 'right');
|
|
|
|
|
|
2019-02-01 04:01:39 +01:00
|
|
|
return (
|
2019-06-21 02:30:12 +02:00
|
|
|
<>
|
|
|
|
|
<div className="ToolbarRow">
|
|
|
|
|
<div className="pull-left m-t-1 p-y-1" style={{ padding: '10px' }}>
|
|
|
|
|
<RoundedButtonGroup
|
2019-07-04 20:09:13 +02:00
|
|
|
options={this.buttonGroups.left}
|
|
|
|
|
value={this.props.selectedLeftSidePanel || ''}
|
|
|
|
|
onValueChanged={onPressLeft}
|
2019-06-21 02:30:12 +02:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
{buttonComponents}
|
|
|
|
|
<ConnectedLayoutButton />
|
|
|
|
|
<ConnectedPluginSwitch />
|
|
|
|
|
<div
|
|
|
|
|
className="pull-right m-t-1 rm-x-1"
|
|
|
|
|
style={{ marginLeft: 'auto' }}
|
|
|
|
|
>
|
2019-07-04 20:09:13 +02:00
|
|
|
{this.buttonGroups.right.length && (
|
|
|
|
|
<RoundedButtonGroup
|
|
|
|
|
options={this.buttonGroups.right}
|
|
|
|
|
value={this.props.selectedRightSidePanel || ''}
|
|
|
|
|
onValueChanged={onPressRight}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2019-06-21 02:30:12 +02:00
|
|
|
</div>
|
2019-02-01 04:01:39 +01:00
|
|
|
</div>
|
2019-06-21 02:30:12 +02:00
|
|
|
<div className="CineDialogContainer" style={cineDialogContainerStyle}>
|
|
|
|
|
<ConnectedCineDialog />
|
2019-02-01 04:01:39 +01:00
|
|
|
</div>
|
2019-06-21 02:30:12 +02:00
|
|
|
</>
|
2019-05-30 06:46:45 +02:00
|
|
|
);
|
2019-02-01 04:01:39 +01:00
|
|
|
}
|
2018-12-18 14:15:55 +01:00
|
|
|
}
|
|
|
|
|
|
2019-06-16 19:58:25 +02:00
|
|
|
/**
|
|
|
|
|
* Determine which extension buttons should be showing, if they're
|
|
|
|
|
* active, and what their onClick behavior should be.
|
|
|
|
|
*/
|
|
|
|
|
function _getButtonComponents(toolbarButtons, activeButtons) {
|
|
|
|
|
return toolbarButtons.map((button, index) => {
|
2019-07-17 10:13:59 +02:00
|
|
|
let activeCommand = undefined;
|
|
|
|
|
|
2019-06-25 00:04:26 +02:00
|
|
|
if (button.buttons && button.buttons.length) {
|
2019-07-04 20:09:13 +02:00
|
|
|
// Iterate over button definitions and update `onClick` behavior
|
|
|
|
|
const childButtons = button.buttons.map(childButton => {
|
|
|
|
|
childButton.onClick = _handleToolbarButtonClick.bind(this, childButton);
|
2019-07-17 10:13:59 +02:00
|
|
|
|
|
|
|
|
if (activeButtons.indexOf(childButton.id) > -1) {
|
|
|
|
|
activeCommand = childButton.id;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-04 20:09:13 +02:00
|
|
|
return childButton;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<ExpandableToolMenu
|
|
|
|
|
key={button.id}
|
|
|
|
|
text={button.label}
|
|
|
|
|
icon={button.icon}
|
|
|
|
|
buttons={childButtons}
|
2019-07-17 10:13:59 +02:00
|
|
|
activeCommand={activeCommand}
|
2019-07-04 20:09:13 +02:00
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
2019-06-16 19:58:25 +02:00
|
|
|
return (
|
|
|
|
|
<ToolbarButton
|
|
|
|
|
key={button.id}
|
|
|
|
|
label={button.label}
|
|
|
|
|
icon={button.icon}
|
2019-07-04 20:09:13 +02:00
|
|
|
onClick={_handleToolbarButtonClick.bind(this, button)}
|
2019-06-16 20:07:13 +02:00
|
|
|
isActive={activeButtons.includes(button.id)}
|
2019-06-16 19:58:25 +02:00
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-04 20:09:13 +02:00
|
|
|
/**
|
|
|
|
|
* A handy way for us to handle different button types. IE. firing commands for
|
|
|
|
|
* buttons, or initiation built in behavior.
|
|
|
|
|
*
|
|
|
|
|
* @param {*} button
|
|
|
|
|
* @param {*} evt
|
|
|
|
|
* @param {*} props
|
|
|
|
|
*/
|
|
|
|
|
function _handleToolbarButtonClick(button, evt, props) {
|
|
|
|
|
if (button.commandName) {
|
|
|
|
|
const options = Object.assign({ evt }, button.commandOptions);
|
|
|
|
|
commandsManager.runCommand(button.commandName, options);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: Use Types ENUM
|
|
|
|
|
// TODO: We can update this to be a `getter` on the extension to query
|
|
|
|
|
// For the active tools after we apply our updates?
|
|
|
|
|
if (button.type === 'setToolActive') {
|
|
|
|
|
this.setState({
|
|
|
|
|
activeButtons: [button.id],
|
|
|
|
|
});
|
|
|
|
|
} else if (button.type === 'builtIn') {
|
|
|
|
|
this._handleBuiltIn(button.options);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
2019-06-17 20:20:32 +02:00
|
|
|
function _getVisibleToolbarButtons() {
|
|
|
|
|
const toolbarModules = extensionManager.modules[MODULE_TYPES.TOOLBAR];
|
|
|
|
|
const toolbarButtonDefinitions = [];
|
|
|
|
|
|
|
|
|
|
toolbarModules.forEach(extension => {
|
|
|
|
|
const { definitions, defaultContext } = extension.module;
|
|
|
|
|
definitions.forEach(definition => {
|
|
|
|
|
const context = definition.context || defaultContext;
|
|
|
|
|
|
|
|
|
|
if (this.props.activeContexts.includes(context)) {
|
|
|
|
|
toolbarButtonDefinitions.push(definition);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return toolbarButtonDefinitions;
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-21 02:30:12 +02:00
|
|
|
function _handleBuiltIn({ behavior } = {}) {
|
|
|
|
|
if (behavior === 'CINE') {
|
|
|
|
|
this.setState({
|
|
|
|
|
isCineDialogOpen: !this.state.isCineDialogOpen,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-11 11:32:09 +02:00
|
|
|
export default withTranslation('Common')(ToolbarRow);
|