Skip to content

Commit

Permalink
feat(citizenScienceLabels): moved annotation media requests to labels…
Browse files Browse the repository at this point in the history
… component so they are batched
  • Loading branch information
peichins committed May 3, 2017
1 parent 45770ec commit b712a85
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 69 deletions.
4 changes: 3 additions & 1 deletion src/app/annotationLibrary/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ angular

var mediaPromises = [];

// modify annotations by reference
// modify annotations by reference and include them in the returned object
annotations.forEach(annotation => {
annotationToProjectLinker(annotation, {
Project: projects,
Expand All @@ -266,6 +266,8 @@ angular
mediaPromises.push(getMedia(annotation));
});

arspData.annotations = annotations;

return $q.all(mediaPromises).then(function () {
return arspData;
});
Expand Down
15 changes: 1 addition & 14 deletions src/app/citizenScience/bristlebird/bristlebird.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,28 +118,15 @@ class BristlebirdController {
)).then(function (response) {
if (Array.isArray(response.data)) {
$scope.labels = response.data;

self.fetchAnnotationData($scope.labels);


} else {
$scope.labels = [];
}
});


/**
* fetches site/project/media data for all label examples
* updates the labels' examples array
* @param labels Object
* @TODO
*/
self.fetchAnnotationData = function (labels) {
//$scope.labels = JSON.parse(`[{"label":"Eastern Bristlebird click","tags":["ebb","type 1"],"examples":[{"annotationId":124730},{"annotationId":124727}]},{"label":"Eastern Bristlebird whistle","tags":["ebb","type 2"],"examples":[{"annotationId":124622}]},{"label":"Ground Parrot","tags":["ground parrot","type 1"],"examples":[]},{"label":"Spotted Quoll","tags":["quoll","type1"],"examples":[]},{"label":"Rufus Bristlebird","tags":["rbb","type1"],"examples":[]}]`);



};




Expand Down
48 changes: 0 additions & 48 deletions src/app/citizenScience/thumbLabels/label.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,55 +13,7 @@ angular.module("bawApp.components.citizenScienceThumbLabels.label",
"baw.models.AudioEvent",
function ($scope, $http, CitizenScienceCommon, libraryCommon, AudioEventService, AudioEvent) {

var self = this;

$scope.thumbSrc = "";



self.getThumbSrc = function () {

if (self.examples.length < 1) {
console.error("no examples for label thumbnail", self.tags, self.label);
return;
}

var firstExample = self.examples[0];

AudioEventService
.getAudioEventsByIds([firstExample.annotationId])
.then(function annotationShowSuccess(response, responseHeaders) {
var audioEvents = response.data.data;

var annotation = new AudioEvent(audioEvents[0]);

var commonData = {
annotations: [annotation],
annotationIds: new Set([annotation.id]),
recordingIds: new Set([annotation.audioRecordingId])
};


// do we need this stuff? if so, need more dependencies
libraryCommon.addCalculatedProperties(annotation);
libraryCommon.getSiteMediaAndProject(commonData).then(function (result) {

$scope.thumbSrc = annotation.media.available.image.png.url;
console.log("got the annotation", annotation);

});
libraryCommon.getUsers(commonData);


},
function annotationShowError(httpResponse) {
console.error("Failed to load citizen science example item response.", httpResponse);
});

};


self.getThumbSrc();



Expand Down
4 changes: 2 additions & 2 deletions src/app/citizenScience/thumbLabels/label.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

<!-- stuff to show thumb image -->
<div class="citizen-science-thumb">
<img ng-src="{{thumbSrc}}" alt="{{$ctrl.label}}">
<img ng-src="{{$ctrl.examples[0].annotation.media.available.image.png.url}}" alt="{{$ctrl.label}}">
</div>


<citizen-science-label-examples examples="$ctrl.examples"></citizen-science-label-examples>
<!-- <citizen-science-label-examples examples="$ctrl.examples"></citizen-science-label-examples> -->
</div>
92 changes: 91 additions & 1 deletion src/app/citizenScience/thumbLabels/labels.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,97 @@ angular.module("bawApp.components.citizenScienceThumbLabels",
"$scope",
"$http",
"CitizenScienceCommon",
function ($scope, $http, CitizenScienceCommon) {
"annotationLibraryCommon",
"AudioEvent",
"baw.models.AudioEvent",
"$q",
function ($scope,
$http,
CitizenScienceCommon,
libraryCommon,
AudioEventService,
AudioEvent,
$q) {

var self = this;


$scope.$watch(function () {
return self.labels;
}, function (newVal, oldVal) {
self.fetchAnnotationData(newVal);
});


/**
* fetches site/project/media data for all label examples
* updates the labels' examples array, replacing each annotationId with a
* full "anotation" object that contains the AudioEvent model as well Media model
* @param labels Object
*/
self.fetchAnnotationData = function (labels) {

// transform labels structure into a single array of annotationsIds
var annotationIds = [].concat.apply([], labels.map(l => l.examples)).map(e => e.annotationId);

if (annotationIds.length === 0) {
return;
}

var annotations = [];


AudioEventService
.getAudioEventsByIds(annotationIds)
.then(function (response) {

annotations = response.data.data || [];

var annotationIds = new Set(),
recordingIds = new Set();

annotations.forEach(function (resource, index) {

annotationIds.add(resource.id);
recordingIds.add(resource.audioRecordingId);
libraryCommon.addCalculatedProperties(resource);

});

var data = {
annotations,
annotationIds,
recordingIds
};

var x = libraryCommon.getSiteMediaAndProject(data);
return x;

}, function (error) {
console.log("get audio events by ids failed", error);
})
.then(function (response) {

// add annotations back into labels object
response.annotations.forEach(function (annotation) {
self.labels.forEach(function (l) {
l.examples.forEach(function (e) {
if (e.annotationId === annotation.id) {
e.annotation = annotation;
}
});
});
});

console.log(self.labels);


}, function (httpResponse) {
console.error("Failed to load citizen science example item response.", httpResponse);
});


};


}],
Expand Down
14 changes: 11 additions & 3 deletions src/app/citizenScience/thumbLabels/labels.tpl.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@

<div class="thumb-labels-container">
<div ng-repeat="(key,label) in $ctrl.labels" class="label-thumbs" ng-if="label.examples.length" ng-class="{selected : label.showExamples}">
<citizen-science-label tags="label.tags" examples="label.examples" label="label.label" selected="label.showExamples"></citizen-science-label>
</div>

<citizen-science-label
ng-repeat="(key,label) in $ctrl.labels"
class="label-thumbs"
ng-if="label.examples.length"
tags="label.tags"
examples="label.examples"
label="label.label"
selected="label.showExamples"
ng-class="{selected : label.showExamples}"></citizen-science-label>

</div>

0 comments on commit b712a85

Please sign in to comment.