Skip to content

Commit

Permalink
Work on annotation library.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Cottman-Fields committed Feb 20, 2014
1 parent cc558b5 commit 8f51533
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 8 deletions.
52 changes: 48 additions & 4 deletions src/app/annotationLibrary/annotationLibrary.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
angular.module('bawApp.annotationLibrary', ['bawApp.configuration'])

.controller('AnnotationLibraryCtrl', ['$scope', '$location', '$resource', '$routeParams', 'AudioEvent',
function ($scope, $location, $resource, $routeParams, AudioEvent) {
.controller('AnnotationLibraryCtrl', ['$scope', '$location', '$resource', '$routeParams', 'conf.paths', 'conf.constants', 'AudioEvent', 'Media',
function ($scope, $location, $resource, $routeParams, paths, constants, AudioEvent, Media) {

$scope.filterSettings = {
tagsPartial: null,
Expand All @@ -18,7 +18,9 @@ angular.module('bawApp.annotationLibrary', ['bawApp.configuration'])
};
$scope.loadFilter = function loadFilter() {
$scope.filterSettings = $scope.createQuery($routeParams);
$scope.library = AudioEvent.library($scope.filterSettings);
$scope.library = AudioEvent.library($scope.filterSettings, null, function librarySuccess(value) {
value.map(getMedia);
});
};
$scope.createQuery = function createQuery(params) {
var hash = {};
Expand All @@ -30,7 +32,7 @@ angular.module('bawApp.annotationLibrary', ['bawApp.configuration'])
}
}
}
console.log(hash);
//console.log(hash);
return hash;
};
$scope.calcOffsetStart = function calcOffsetStart(startOffset) {
Expand All @@ -39,5 +41,47 @@ angular.module('bawApp.annotationLibrary', ['bawApp.configuration'])
$scope.calcOffsetEnd = function calcOffsetEnd(startOffset) {
return (Math.floor(startOffset / 30) * 30) + 30;
};

function getMediaParameters(value) {
return {
start_offset: Math.floor(value.startTimeSeconds - constants.annotationLibrary.paddingSeconds),
end_offset: Math.ceil(value.endTimeSeconds + constants.annotationLibrary.paddingSeconds),
// this one is different, it is encoded into the path of the request by angular
recordingId: value.audioRecordingId,
format: "json"
};
}

function getMedia(value, index, array) {
Media
.get(getMediaParameters(value), null, function getMediaSuccess(mediaValue) {
// adds a media resource to each audio event
formatPaths(mediaValue);
value.media = mediaValue;
//console.debug(value.media);
});
}


function formatPaths(media) {

var imgKeys = Object.keys(media.availableImageFormats);
if (imgKeys.length > 1) {
throw "don't know how to handle more than one image format!";
}

media.availableImageFormats[imgKeys[0]].url =
paths.joinFragments(
paths.api.root,
media.availableImageFormats[imgKeys[0]].url);

angular.forEach(media.availableAudioFormats, function (value, key) {

// just update the url so it is an absolute uri
this[key].url = paths.joinFragments(paths.api.root, value.url);

}, media.availableAudioFormats);
};

$scope.loadFilter();
}]);
21 changes: 17 additions & 4 deletions src/app/annotationLibrary/annotationLibrary.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,21 @@ <h1>Annotation Library</h1>
</form>
</div>
</div>
<a ng-repeat="item in library"
ng-href="/listen/{{item.audioRecordingId}}?start={{calcOffsetStart(item.startTimeSeconds)}}&end={{calcOffsetEnd(item.startTimeSeconds)}}">
<span ng-repeat="tag in item.tags">{{tag.text}}&nbsp;&nbsp;</span><br>
</a>

<div ng-repeat="item in library">
<div>
<grid-lines></grid-lines>
<img ng-src="{{item.media.availableImageFormats.png.url}}">
</div>
<a ng-href="/listen/{{item.audioRecordingId}}?start={{calcOffsetStart(item.startTimeSeconds)}}&end={{calcOffsetEnd(item.startTimeSeconds)}}">
Annotation: <span ng-repeat="tag in item.tags">{{tag.text}}&nbsp;&nbsp;</span><br>
</a>
<audio controls>
<source ng-repeat="resource in item.media.availableAudioFormats" ng-src="{{resource.url}}" src=""
type="{{resource.mimeType}}">
Your browser does not support the audio element.
</audio>
</div>


</div>
3 changes: 3 additions & 0 deletions src/baw.configuration.tpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,5 +180,8 @@ angular.module('bawApp.configuration', ['url'])
muted: false
},
userName: "Unknown user"
},
annotationLibrary: {
paddingSeconds: 1.0
}
});

0 comments on commit 8f51533

Please sign in to comment.