Files
ohif-viewer/platform/viewer/src/components/Labelling/LabellingManager.js
T

130 lines
3.1 KiB
JavaScript
Raw Normal View History

2019-05-29 08:39:54 -04:00
import React, { Component } from 'react';
import PropTypes from 'prop-types';
2019-05-02 17:12:06 -04:00
2019-05-29 08:39:54 -04:00
import cloneDeep from 'lodash.clonedeep';
2019-05-02 17:12:06 -04:00
2019-05-29 08:39:54 -04:00
import EditDescriptionDialog from './../EditDescriptionDialog/EditDescriptionDialog.js';
import LabellingFlow from './LabellingFlow.js';
2019-05-02 17:12:06 -04:00
2019-05-29 08:39:54 -04:00
import './LabellingManager.css';
2019-05-02 17:12:06 -04:00
export default class LabellingManager extends Component {
static propTypes = {
eventData: PropTypes.object.isRequired,
measurementData: PropTypes.object.isRequired,
labellingDoneCallback: PropTypes.func.isRequired,
updateLabelling: PropTypes.func.isRequired,
skipAddLabelButton: PropTypes.bool,
editLocation: PropTypes.bool,
editDescription: PropTypes.bool,
editDescriptionOnDialog: PropTypes.bool,
2019-05-29 08:39:54 -04:00
};
2019-05-02 17:12:06 -04:00
static defaultProps = {
skipAddLabelButton: false,
editLocation: false,
editDescription: false,
editDescriptionOnDialog: false,
2019-05-29 08:39:54 -04:00
};
2019-05-02 17:12:06 -04:00
constructor(props) {
2019-05-29 08:39:54 -04:00
super(props);
2019-05-02 17:12:06 -04:00
2019-05-29 08:39:54 -04:00
const measurementData = cloneDeep(props.measurementData);
this.treatMeasurementData(measurementData);
2019-05-02 17:12:06 -04:00
2019-05-29 08:39:54 -04:00
let editLocation = props.editLocation;
2019-05-02 17:12:06 -04:00
if (!props.editDescription && !props.editLocation) {
2019-05-29 08:39:54 -04:00
editLocation = true;
2019-05-02 17:12:06 -04:00
}
this.state = {
componentStyle: getComponentPosition(props.eventData),
skipAddLabelButton: props.skipAddLabelButton,
editLocation: editLocation,
editDescription: props.editDescription,
editDescriptionOnDialog: props.editDescriptionOnDialog,
measurementData: measurementData,
2019-05-29 08:39:54 -04:00
};
2019-05-02 17:12:06 -04:00
}
componentDidMount = () => {
2019-05-29 08:39:54 -04:00
document.addEventListener('touchstart', this.onTouchStart);
};
2019-05-02 17:12:06 -04:00
componentWillUnmount = () => {
2019-05-29 08:39:54 -04:00
document.removeEventListener('touchstart', this.onTouchStart);
};
2019-05-02 17:12:06 -04:00
render() {
2019-05-29 08:39:54 -04:00
return this.getRenderComponent();
2019-05-02 17:12:06 -04:00
}
getRenderComponent = () => {
const {
editLocation,
editDescription,
editDescriptionOnDialog,
measurementData,
2019-05-29 08:39:54 -04:00
} = this.state;
2019-05-02 17:12:06 -04:00
if (editDescriptionOnDialog) {
return (
<EditDescriptionDialog
onCancel={this.props.labellingDoneCallback}
onUpdate={this.descriptionDialogUpdate}
componentRef={this.editDescriptionDialog}
componentStyle={this.state.componentStyle}
measurementData={measurementData}
/>
2019-05-29 08:39:54 -04:00
);
2019-05-02 17:12:06 -04:00
}
if (editLocation || editDescription) {
return (
<LabellingFlow
{...this.props}
componentStyle={this.state.componentStyle}
/>
2019-05-29 08:39:54 -04:00
);
2019-05-02 17:12:06 -04:00
}
2019-05-29 08:39:54 -04:00
};
2019-05-02 17:12:06 -04:00
treatMeasurementData = measurementData => {
2019-05-29 08:39:54 -04:00
const { editDescription, editLocation } = this.props;
2019-05-02 17:12:06 -04:00
if (editDescription) {
2019-05-29 08:39:54 -04:00
measurementData.description = undefined;
2019-05-02 17:12:06 -04:00
}
if (editLocation) {
2019-05-29 08:39:54 -04:00
measurementData.location = undefined;
2019-05-02 17:12:06 -04:00
}
2019-05-29 08:39:54 -04:00
};
2019-05-02 17:12:06 -04:00
responseDialogUpdate = response => {
this.props.updateLabelling({
response,
2019-05-29 08:39:54 -04:00
});
this.props.labellingDoneCallback();
};
2019-05-02 17:12:06 -04:00
descriptionDialogUpdate = description => {
this.props.updateLabelling({
description,
2019-05-29 08:39:54 -04:00
});
this.props.labellingDoneCallback();
};
2019-05-02 17:12:06 -04:00
}
function getComponentPosition(eventData) {
const {
event: { clientX: left, clientY: top },
2019-05-29 08:39:54 -04:00
} = eventData;
2019-05-02 17:12:06 -04:00
return {
left,
top,
2019-05-29 08:39:54 -04:00
};
2019-05-02 17:12:06 -04:00
}