Skip to content

Commit

Permalink
Merge pull request #13 from BiodataMiningGroup/annotation-sessions
Browse files Browse the repository at this point in the history
Annotation sessions
  • Loading branch information
mzur authored Oct 20, 2016
2 parents 76adf4c + 96567cb commit e9e67f7
Show file tree
Hide file tree
Showing 11 changed files with 128 additions and 42 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "dias/ate",
"require": {
"dias/transects": "~1.0",
"dias/transects": "~1.1",
"intervention/image": "~2.1"
},
"require-dev": {
Expand Down
2 changes: 1 addition & 1 deletion src/AteServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function boot(Modules $modules, Router $router)
$modules->addMixin('ate', 'annotationsStyles');
$modules->addMixin('ate', 'annotationsSidebar');
$modules->addMixin('ate', 'annotationsSettings');
$modules->addMixin('ate', 'projectsShow');
$modules->addMixin('ate', 'projectsShowToolbar');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Controllers/Api/AteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class AteController extends Controller
* @apiName ShowAnnotationPatch
* @apiParam {Number} id The annotation ID.
* @apiPermission projectMember
* @apiDescription Responds with an image file
* @apiDescription Responds with an image file. If there is an active annotation session, access to annotations hidden by the session is denied.
*
* @param int $id
* @return \Illuminate\Http\Response
Expand Down
15 changes: 6 additions & 9 deletions src/Http/Controllers/Api/ProjectsAnnotationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,14 @@ public function filter(Request $request, $pid, $lid)
$take = $request->input('take');

return Annotation::join('annotation_labels', 'annotations.id', '=', 'annotation_labels.annotation_id')
->whereIn('annotations.image_id', function ($query) use ($pid) {
$query->select('id')
->from('images')
->whereIn('transect_id', function ($query) use ($pid) {
$query->select('transect_id')
->from('project_transect')
->where('project_id', $pid);
});
->join('images', 'annotations.image_id', '=', 'images.id')
->whereIn('images.transect_id', function ($query) use ($pid) {
$query->select('transect_id')
->from('project_transect')
->where('project_id', $pid);
})
->where('annotation_labels.label_id', $lid)
->when($take !== null, function ($query) use ($take) {
->when(!is_null($take), function ($query) use ($take) {
return $query->orderBy('annotations.created_at', 'desc')
->take($take);
})
Expand Down
19 changes: 15 additions & 4 deletions src/Http/Controllers/Api/TransectsAnnotationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Dias\Transect;
use Dias\Annotation;
use Illuminate\Http\Request;
use Illuminate\Contracts\Auth\Guard;
use Dias\Http\Controllers\Api\Controller;

class TransectsAnnotationsController extends Controller
Expand All @@ -19,28 +20,38 @@ class TransectsAnnotationsController extends Controller
* @apiParam {Number} lit The Label ID
* @apiParam (Optional arguments) {Number} take Number of annotations to return. If this parameter is present, the most recent annotations will be returned first. Default is unlimited and unordered.
* @apiPermission projectMember
* @apiDescription Returns a list of annotation IDs
* @apiDescription Returns a list of annotation IDs. If there is an active annotation session, images with annotations hidden by the session are not returned.
*
* @param Request $request
* @param Guard $auth
* @param int $tid Transect ID
* @param int $lid Label ID
* @return \Illuminate\Http\Response
*/
public function filter(Request $request, $tid, $lid)
public function filter(Request $request, Guard $auth, $tid, $lid)
{
$transect = Transect::findOrFail($tid);
$this->authorize('access', $transect);
$this->validate($request, ['take' => 'integer']);
$take = $request->input('take');

return Annotation::join('annotation_labels', 'annotations.id', '=', 'annotation_labels.annotation_id')
$user = $auth->user();
$session = $transect->getActiveAnnotationSession($user);

if ($session) {
$query = Annotation::allowedBySession($session, $user);
} else {
$query = Annotation::query();
}

return $query->join('annotation_labels', 'annotations.id', '=', 'annotation_labels.annotation_id')
->whereIn('annotations.image_id', function ($query) use ($tid) {
$query->select('id')
->from('images')
->where('transect_id', $tid);
})
->where('annotation_labels.label_id', $lid)
->when($take !== null, function ($query) use ($take) {
->when(!is_null($take), function ($query) use ($take) {
return $query->orderBy('annotations.created_at', 'desc')
->take($take);
})
Expand Down
6 changes: 3 additions & 3 deletions src/Jobs/GenerateAnnotationPatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace Dias\Modules\Ate\Jobs;

use Dias\Annotation;
use File;
use Dias\Shape;
use Dias\Jobs\Job;
use Dias\Annotation;
use InterventionImage as IImage;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use InterventionImage as IImage;
use File;

class GenerateAnnotationPatch extends Job implements ShouldQueue
{
Expand Down
15 changes: 1 addition & 14 deletions src/resources/views/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,7 @@

@section('navbar')
<div class="navbar-text navbar-ate-breadcrumbs">
@if ($projects->count() > 1)
<span class="dropdown">
<a href="#" class="dropdown-toggle navbar-link">Projects <span class="caret"></span></a>
<ul class="dropdown-menu">
@foreach ($projects as $project)
<li><a href="{{route('project', $project->id)}}">{{$project->name}}</a></li>
@endforeach
</ul>
</span>
@else
<a href="{{route('project', $projects->first()->id)}}" class="navbar-link" title="Show project {{$projects->first()->name}}">{{$projects->first()->name}}</a>
@endif
/ <a href="{{route('transect', $transect->id)}}" title="Show transect {{$transect->name}}">{{$transect->name}}</a>
/ <strong id="dismiss-mode-title">ATE - dismiss existing annotations</strong><strong id="re-labelling-mode-title" class="ng-hide">ATE - re-label dismissed annotations</strong> <small>(<span id="annotation-count">0</span>&nbsp;annotations)</small>
@include('transects::partials.projectsBreadcrumb') / <a href="{{route('transect', $transect->id)}}" title="Show transect {{$transect->name}}" class="navbar-link">{{$transect->name}}</a> / <strong id="dismiss-mode-title">ATE - dismiss existing annotations</strong><strong id="re-labelling-mode-title" class="ng-hide">ATE - re-label dismissed annotations</strong> <small>(<span id="annotation-count">0</span>&nbsp;annotations)</small> @include('transects::partials.annotationSessionIndicator')
</div>
@endsection

Expand Down
8 changes: 0 additions & 8 deletions src/resources/views/projectsShow.blade.php

This file was deleted.

1 change: 1 addition & 0 deletions src/resources/views/projectsShowToolbar.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<a href="{{route('projectsAte', $project->id)}}" class="btn btn-default" title="Perform ATE re-evaluation of annotations for this project"><span class="glyphicon glyphicon-check" aria-hidden="true"></span> ATE re-evaluation</a>
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php


class AteModuleHttpControllersApiProjectsAnnotationsControllerTest extends ApiTestCase {

public function testFilter() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use Carbon\Carbon;

class AteModuleHttpControllersApiTransectsAnnotationsControllerTest extends ApiTestCase {

Expand Down Expand Up @@ -51,4 +52,102 @@ public function testFilter() {
$this->assertResponseOk();
$this->seeJsonEquals($expect3);
}

public function testFilterAnnotationSession()
{
$id = $this->transect()->id;
$image = ImageTest::create(['transect_id' => $id]);

$a1 = AnnotationTest::create([
'image_id' => $image->id,
'created_at' => Carbon::yesterday(),
]);

$a2 = AnnotationTest::create([
'image_id' => $image->id,
'created_at' => Carbon::today(),
]);

$a3 = AnnotationTest::create([
'image_id' => $image->id,
'created_at' => Carbon::yesterday(),
]);

$l1 = AnnotationLabelTest::create([
'annotation_id' => $a1->id,
'user_id' => $this->editor()->id,
]);

$l2 = AnnotationLabelTest::create([
'annotation_id' => $a2->id,
'label_id' => $l1->label_id,
'user_id' => $this->editor()->id,
]);

$l3 = AnnotationLabelTest::create([
'annotation_id' => $a3->id,
'label_id' => $l1->label_id,
'user_id' => $this->admin()->id,
]);

$this->beEditor();

// test hide own
$session = AnnotationSessionTest::create([
'transect_id' => $id,
'starts_at' => Carbon::today(),
'ends_at' => Carbon::tomorrow(),
'hide_own_annotations' => true,
'hide_other_users_annotations' => false,
]);

$session->users()->attach($this->editor());

$expect = [$a2->id, $a3->id];
if ($this->isSqlite()) {
$expect = array_map('strval', $expect);
}

$this->get("/api/v1/transects/{$id}/annotations/filter/label/{$l1->label_id}");
$this->assertResponseOk();
$this->seeJsonEquals($expect);

// test hide other
$session->hide_own_annotations = false;
$session->hide_other_users_annotations = true;
$session->save();

$expect = [$a1->id, $a2->id];
if ($this->isSqlite()) {
$expect = array_map('strval', $expect);
}

$this->get("/api/v1/transects/{$id}/annotations/filter/label/{$l1->label_id}");
$this->assertResponseOk();
$this->seeJsonEquals($expect);

// test hide both
$session->hide_own_annotations = true;
$session->save();

$expect = [$a2->id];
if ($this->isSqlite()) {
$expect = array_map('strval', $expect);
}

$this->get("/api/v1/transects/{$id}/annotations/filter/label/{$l1->label_id}");
$this->assertResponseOk();
$this->seeJsonEquals($expect);

$session->users()->detach($this->editor());

$expect = [$a1->id, $a2->id, $a3->id];
if ($this->isSqlite()) {
$expect = array_map('strval', $expect);
}

$this->get("/api/v1/transects/{$id}/annotations/filter/label/{$l1->label_id}");
$this->assertResponseOk();
$this->seeJsonEquals($expect);
}
}

0 comments on commit e9e67f7

Please sign in to comment.