Skip to content

Commit

Permalink
Merge pull request #728 from biigle/annotation-deletion-bug
Browse files Browse the repository at this point in the history
Remove null (gap) to prevent validation errors
  • Loading branch information
mzur authored Jan 19, 2024
2 parents 6342078 + 16d1f2a commit 63df78a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/VideoAnnotation.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ public function validatePoints(array $points = [])
throw new Exception('The number of key frames does not match the number of annotation coordinates.');
}

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

/**
Expand Down
10 changes: 10 additions & 0 deletions resources/assets/js/videos/models/Annotation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,16 @@ export default Vue.extend({
this.frames.splice(index, 1);
this.points.splice(index, 1);
// Remove "null" elements of adjacent gaps to
// avoid multiple consecutive "null"s.
if (index === 0 && this.frames[0] === null) {
this.frames.splice(0, 1);
this.points.splice(0, 1);
} else if (this.frames[index - 1] === null) {
this.frames.splice(index - 1, 1);
this.points.splice(index - 1, 1);
}
return VideoAnnotationApi.update({id: this.id}, {
frames: this.frames,
points: this.points
Expand Down
8 changes: 8 additions & 0 deletions tests/php/VideoAnnotationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ public function testValidatePointsFramesMismatch()
$this->model->validatePoints();
}

public function testValidatePointsWithGap()
{
$this->expectNotToPerformAssertions();
$this->model->points = [[10, 10], [], [20, 20]];
$this->model->frames = [0.0, null, 1.0];
$this->model->validatePoints();
}

public function testValidatePointsPoint()
{
$this->model->shape_id = Shape::pointId();
Expand Down

0 comments on commit 63df78a

Please sign in to comment.