Skip to content

Commit 63df78a

Browse files
authored
Merge pull request #728 from biigle/annotation-deletion-bug
Remove null (gap) to prevent validation errors
2 parents 6342078 + 16d1f2a commit 63df78a

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

app/VideoAnnotation.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ public function validatePoints(array $points = [])
105105
throw new Exception('The number of key frames does not match the number of annotation coordinates.');
106106
}
107107

108-
array_map([$this, 'parent::validatePoints'], $this->points);
108+
// Gaps are represented as empty arrays
109+
array_map(function ($point) { if (count($point)) { parent::validatePoints($point); } }, $this->points);
109110
}
110111

111112
/**

resources/assets/js/videos/models/Annotation.vue

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,16 @@ export default Vue.extend({
282282
this.frames.splice(index, 1);
283283
this.points.splice(index, 1);
284284
285+
// Remove "null" elements of adjacent gaps to
286+
// avoid multiple consecutive "null"s.
287+
if (index === 0 && this.frames[0] === null) {
288+
this.frames.splice(0, 1);
289+
this.points.splice(0, 1);
290+
} else if (this.frames[index - 1] === null) {
291+
this.frames.splice(index - 1, 1);
292+
this.points.splice(index - 1, 1);
293+
}
294+
285295
return VideoAnnotationApi.update({id: this.id}, {
286296
frames: this.frames,
287297
points: this.points

tests/php/VideoAnnotationTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ public function testValidatePointsFramesMismatch()
4949
$this->model->validatePoints();
5050
}
5151

52+
public function testValidatePointsWithGap()
53+
{
54+
$this->expectNotToPerformAssertions();
55+
$this->model->points = [[10, 10], [], [20, 20]];
56+
$this->model->frames = [0.0, null, 1.0];
57+
$this->model->validatePoints();
58+
}
59+
5260
public function testValidatePointsPoint()
5361
{
5462
$this->model->shape_id = Shape::pointId();

0 commit comments

Comments
 (0)