2019-05-29 08:39:54 -04:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
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';
|
|
|
|
|
import './LabellingManager.css';
|
2019-05-02 17:12:06 -04:00
|
|
|
|
|
|
|
|
export default class LabellingManager extends Component {
|
|
|
|
|
static propTypes = {
|
|
|
|
|
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 = {
|
|
|
|
|
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}
|
|
|
|
|
measurementData={measurementData}
|
|
|
|
|
/>
|
2019-05-29 08:39:54 -04:00
|
|
|
);
|
2019-05-02 17:12:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (editLocation || editDescription) {
|
2019-12-09 14:47:23 -03:00
|
|
|
return <LabellingFlow {...this.props} />;
|
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
|
|
|
}
|
2019-12-09 14:47:23 -03:00
|
|
|
|
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 => {
|
2019-12-09 14:47:23 -03:00
|
|
|
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 => {
|
2019-12-09 14:47:23 -03:00
|
|
|
this.props.updateLabelling({ description });
|
2019-05-29 08:39:54 -04:00
|
|
|
this.props.labellingDoneCallback();
|
|
|
|
|
};
|
2019-05-02 17:12:06 -04:00
|
|
|
}
|