-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change loading of users with annotations from rendering to API
This commit changes the way the user filters are loaded in Largo. Rather then being loaded from within the Controller, it is loaded from the API once the user clicks on the annotation filter.
- Loading branch information
1 parent
c8a16bc
commit 9f76329
Showing
10 changed files
with
142 additions
and
31 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
src/Http/Controllers/Api/Projects/GetUsersWithAnnotations.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace Biigle\Modules\Largo\Http\Controllers\Api\Projects; | ||
|
||
use Biigle\Http\Controllers\Api\Controller; | ||
use Biigle\ImageAnnotationLabel; | ||
use Biigle\VideoAnnotationLabel; | ||
use Biigle\Project; | ||
use Illuminate\Http\Request; | ||
|
||
class GetUsersWithAnnotations extends Controller | ||
{ | ||
/** | ||
* Show all image annotations of the volume that have a specific label attached. | ||
* | ||
* @api {get} projects/image/users-with-annotations/:vid Get users with annotations | ||
* @apiGroup Projects | ||
* @apiName ShowUsersWithImageAnnotations | ||
* @apiParam {Number} pid The Project ID | ||
* @apiPermission projectMember | ||
* @apiDescription Returns the users with annotations | ||
* | ||
* @param Request $request | ||
* @param int $pid Project ID | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function index(Request $request, $pid) | ||
{ | ||
$project = Project::findOrFail($pid); | ||
$this->authorize('access', $project); | ||
$volumes = $project->volumes()->pluck('id'); | ||
|
||
$usersWithImageAnnotations = ImageAnnotationLabel::query() | ||
->join('image_annotations', 'image_annotations.id', '=', 'image_annotation_labels.annotation_id') | ||
->join('images', 'image_annotations.image_id', '=', 'images.id') | ||
->whereIn('images.volume_id', $volumes) | ||
->join('users', 'image_annotation_labels.user_id', '=', 'users.id') | ||
->distinct('image_annotation_labels.user_id') | ||
->select('image_annotation_labels.user_id', 'users.lastname', 'users.firstname') | ||
->get()->toArray(); | ||
|
||
$usersWithVideoAnnotations = VideoAnnotationLabel::query() | ||
->join('video_annotations', 'video_annotations.id', '=', 'video_annotation_labels.annotation_id') | ||
->join('videos', 'video_annotations.video_id', '=', 'videos.id') | ||
->whereIn('videos.volume_id', $volumes) | ||
->join('users', 'video_annotation_labels.user_id', '=', 'users.id') | ||
->distinct('video_annotation_labels.user_id') | ||
->select('video_annotation_labels.user_id', 'users.lastname', 'users.firstname') | ||
->get()->toArray(); | ||
|
||
return array_merge($usersWithImageAnnotations, $usersWithVideoAnnotations); | ||
} | ||
}; |
54 changes: 54 additions & 0 deletions
54
src/Http/Controllers/Api/Volumes/GetUsersWithAnnotations.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
namespace Biigle\Modules\Largo\Http\Controllers\Api\Volumes; | ||
|
||
use Biigle\Http\Controllers\Api\Controller; | ||
use Biigle\ImageAnnotationLabel; | ||
use Biigle\Volume; | ||
use Biigle\MediaType; | ||
use Illuminate\Http\Request; | ||
|
||
class GetUsersWithAnnotations extends Controller | ||
{ | ||
/** | ||
* Show all image annotations of the volume that have a specific label attached. | ||
* | ||
* @api {get} volumes/image/users-with-annotations/:vid Get users with annotations | ||
* @apiGroup Volumes | ||
* @apiName ShowUsersWithImageAnnotations | ||
* @apiParam {Number} vid The volume ID | ||
* @apiPermission projectMember | ||
* @apiDescription Returns the users with annotations | ||
* | ||
* @param Request $request | ||
* @param int $vid Volume ID | ||
* @param int $lid Label ID | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function index(Request $request, $vid) | ||
{ | ||
$volume = Volume::findOrFail($vid); | ||
$this->authorize('access', $volume); | ||
if ($volume->media_type_id == MediaType::imageId()){ | ||
$usersWithAnnotations = ImageAnnotationLabel::query() | ||
->join('image_annotations', 'image_annotations.id', '=', 'image_annotation_labels.annotation_id') | ||
->join('images', 'image_annotations.image_id', '=', 'images.id') | ||
->where('images.volume_id', $vid) | ||
->join('users', 'image_annotation_labels.user_id', '=', 'users.id') | ||
->distinct('image_annotation_labels.user_id') | ||
->select('image_annotation_labels.user_id', 'users.lastname', 'users.firstname') | ||
->get(); | ||
} else { | ||
$usersWithAnnotations = VideoAnnotationLabel::query() | ||
->join('video_annotations', 'video_annotations.id', '=', 'video_annotation_labels.annotation_id') | ||
->join('videos', 'video_annotations.video_id', '=', 'videos.id') | ||
->whereIn('videos.volume_id', $vid) | ||
->join('users', 'video_annotation_labels.user_id', '=', 'users.id') | ||
->distinct('video_annotation_labels.user_id') | ||
->select('video_annotation_labels.user_id', 'users.lastname', 'users.firstname') | ||
->get(); | ||
} | ||
|
||
return $usersWithAnnotations; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters