Commit 95494625 authored by Adrià Labay's avatar Adrià Labay
Browse files

restrict widget size on creation

parent a512b2d2
......@@ -121,6 +121,7 @@ class ExamEditor extends React.Component {
this.props.createNewWidget(widgetData)
}).catch(err => {
console.log(err)
err.json().then(e => Notification.error(e.message))
})
}
}
......@@ -141,18 +142,19 @@ class ExamEditor extends React.Component {
/**
* Calculate selection box dimensions
*
* TODO: Clamp values to parent
*/
calculateSelectionBox = (selectionStartPoint, selectionEndPoint) => {
if (!this.state.mouseDown || selectionEndPoint === null || selectionStartPoint === null) {
return null
}
const left = Math.min(selectionStartPoint.x, selectionEndPoint.x)
const top = Math.min(selectionStartPoint.y, selectionEndPoint.y)
const width = Math.abs(selectionStartPoint.x - selectionEndPoint.x)
const height = Math.abs(selectionStartPoint.y - selectionEndPoint.y)
// add a small padding to all the sides
const padding = 1
const left = Math.max(Math.min(selectionStartPoint.x, selectionEndPoint.x), padding)
const top = Math.max(Math.min(selectionStartPoint.y, selectionEndPoint.y), padding)
const width = Math.min(Math.abs(left - Math.max(selectionStartPoint.x, selectionEndPoint.x)), 595 - padding - left)
const height = Math.min(Math.abs(top - Math.max(selectionStartPoint.y, selectionEndPoint.y)), 841 - padding - top)
const result = {
left: left,
top: top,
......
......@@ -97,6 +97,13 @@ class Problems(Resource):
msg = f"Exam with id {exam_id} doesn't exist"
return dict(status=400, message=msg), 400
page_size = current_app.config['PAGE_FORMATS'][current_app.config['PAGE_FORMAT']]
if not (args['x'] >= 0 and
args['y'] >= 0 and
args['width'] + args['x'] < page_size[0] and
args['height'] + args['y'] < page_size[1]):
return dict(status=400, message='Problem size exceeds the page size.'), 400
widget = ProblemWidget(
x=args['x'],
y=args['y'],
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment