bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/whiteboard/annotation-factory/component.jsx

105 lines
3.0 KiB
React
Raw Normal View History

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import StaticAnnotation from './static-annotation/component';
import ReactiveAnnotationContainer from './reactive-annotation/container';
import Ellipse from '../annotations/ellipse/component';
import Line from '../annotations/line/component';
import Poll from '../annotations/poll/component';
import Rectangle from '../annotations/rectangle/component';
import Text from '../annotations/text/container';
import Triangle from '../annotations/triangle/component';
import Pencil from '../annotations/pencil/component';
const ANNOTATION_CONFIG = Meteor.settings.public.whiteboard.annotations;
const DRAW_END = ANNOTATION_CONFIG.status.end;
export default class AnnotationFactory extends Component {
2018-04-10 07:18:49 +08:00
static renderStaticAnnotation(annotationInfo, slideWidth, slideHeight, drawObject, whiteboardId) {
return (
<StaticAnnotation
key={annotationInfo._id}
shapeId={annotationInfo._id}
drawObject={drawObject}
slideWidth={slideWidth}
slideHeight={slideHeight}
2018-04-10 07:18:49 +08:00
whiteboardId={whiteboardId}
/>
);
}
2018-04-10 07:18:49 +08:00
static renderReactiveAnnotation(annotationInfo, slideWidth, slideHeight, drawObject, whiteboardId) {
return (
<ReactiveAnnotationContainer
key={annotationInfo._id}
shapeId={annotationInfo._id}
drawObject={drawObject}
slideWidth={slideWidth}
slideHeight={slideHeight}
2018-04-10 07:18:49 +08:00
whiteboardId={whiteboardId}
/>
);
}
constructor() {
super();
this.renderAnnotation = this.renderAnnotation.bind(this);
}
renderAnnotation(annotationInfo) {
const drawObject = this.props.annotationSelector[annotationInfo.annotationType];
if (annotationInfo.status === DRAW_END) {
return AnnotationFactory.renderStaticAnnotation(
2018-04-10 07:18:49 +08:00
annotationInfo,
this.props.slideWidth,
this.props.slideHeight,
drawObject,
this.props.whiteboardId,
);
}
return AnnotationFactory.renderReactiveAnnotation(
2018-04-10 07:18:49 +08:00
annotationInfo,
this.props.slideWidth,
this.props.slideHeight,
drawObject,
this.props.whiteboardId,
);
}
render() {
const { annotationsInfo } = this.props;
2018-12-06 01:42:31 +08:00
return (
<g>
2018-12-06 01:42:31 +08:00
{annotationsInfo
? annotationsInfo.map(annotationInfo => this.renderAnnotation(annotationInfo))
: null }
</g>
);
}
}
AnnotationFactory.propTypes = {
2018-04-10 07:18:49 +08:00
whiteboardId: PropTypes.string.isRequired,
// initial width and height of the slide are required
// to calculate the coordinates for each annotation
slideWidth: PropTypes.number.isRequired,
slideHeight: PropTypes.number.isRequired,
// array of annotations, optional
annotationsInfo: PropTypes.arrayOf(PropTypes.object).isRequired,
2017-09-06 09:36:15 +08:00
annotationSelector: PropTypes.objectOf(PropTypes.func).isRequired,
};
AnnotationFactory.defaultProps = {
annotationSelector: {
ellipse: Ellipse,
line: Line,
poll_result: Poll,
rectangle: Rectangle,
text: Text,
triangle: Triangle,
pencil: Pencil,
},
};