bigbluebutton-Github/bigbluebutton-html5/imports/api/1.1/shapes/server/modifiers/addShape.js

89 lines
2.7 KiB
JavaScript
Raw Normal View History

2016-11-19 01:35:28 +08:00
import { check } from 'meteor/check';
import Logger from '/imports/startup/server/logger';
2017-08-31 07:12:03 +08:00
import Shapes from './../../';
2016-11-19 01:35:28 +08:00
const SHAPE_TYPE_TEXT = 'text';
const SHAPE_TYPE_POLL_RESULT = 'poll_result';
export default function addShape(meetingId, whiteboardId, shape) {
check(meetingId, String);
check(whiteboardId, String);
check(shape, Object);
const selector = {
meetingId,
'shape.id': shape.id,
};
2017-06-03 03:25:02 +08:00
const modifier = {
2016-11-19 01:35:28 +08:00
$set: {
meetingId,
whiteboardId,
'shape.id': shape.id,
'shape.wb_id': shape.wb_id,
'shape.shape_type': shape.shape_type,
'shape.status': shape.status,
'shape.shape.type': shape.shape.type,
'shape.shape.status': shape.shape.status,
},
$inc: { 'shape.shape.version': 1 },
2016-11-19 01:35:28 +08:00
};
const shapeType = shape.shape_type;
switch (shapeType) {
case SHAPE_TYPE_TEXT:
modifier.$set = Object.assign(modifier.$set, {
'shape.shape.textBoxHeight': shape.shape.textBoxHeight,
'shape.shape.fontColor': shape.shape.fontColor,
'shape.shape.dataPoints': shape.shape.dataPoints,
'shape.shape.x': shape.shape.x,
'shape.shape.textBoxWidth': shape.shape.textBoxWidth,
'shape.shape.whiteboardId': shape.shape.whiteboardId,
'shape.shape.fontSize': shape.shape.fontSize,
'shape.shape.id': shape.shape.id,
'shape.shape.y': shape.shape.y,
'shape.shape.calcedFontSize': shape.shape.calcedFontSize,
'shape.shape.text': shape.shape.text.replace(/[\r]/g, '\n'),
2016-11-19 01:35:28 +08:00
});
break;
case SHAPE_TYPE_POLL_RESULT:
shape.shape.result = JSON.parse(shape.shape.result);
2017-08-31 07:12:03 +08:00
break;
2016-11-19 01:35:28 +08:00
default:
modifier.$set = Object.assign(modifier.$set, {
'shape.shape.points': shape.shape.points,
'shape.shape.whiteboardId': shape.shape.whiteboardId,
'shape.shape.id': shape.shape.id,
'shape.shape.square': shape.shape.square,
'shape.shape.transparency': shape.shape.transparency,
'shape.shape.thickness': shape.shape.thickness,
'shape.shape.color': shape.shape.color,
'shape.shape.result': shape.shape.result,
'shape.shape.num_respondents': shape.shape.num_respondents,
'shape.shape.num_responders': shape.shape.num_responders,
});
break;
}
const cb = (err, numChanged) => {
if (err) {
return Logger.error(`Adding shape to collection: ${err}`);
}
const { insertedId } = numChanged;
if (insertedId) {
return Logger.info(`Added shape id=${shape.id} whiteboard=${whiteboardId}`);
}
if (numChanged) {
return Logger.info(`Upserted shape id=${shape.id} whiteboard=${whiteboardId}`);
}
};
return Shapes.upsert(selector, modifier, cb);
2017-06-03 03:25:02 +08:00
}