From 8f51533104415733060f29ae7a51fd442be960fa Mon Sep 17 00:00:00 2001 From: Mark Cottman-Fields Date: Thu, 20 Feb 2014 15:39:09 +1000 Subject: [PATCH] Work on annotation library. --- .../annotationLibrary/annotationLibrary.js | 52 +++++++++++++++++-- .../annotationLibrary.tpl.html | 21 ++++++-- src/baw.configuration.tpl.js | 3 ++ 3 files changed, 68 insertions(+), 8 deletions(-) diff --git a/src/app/annotationLibrary/annotationLibrary.js b/src/app/annotationLibrary/annotationLibrary.js index 2341a2b0..ff0858c7 100644 --- a/src/app/annotationLibrary/annotationLibrary.js +++ b/src/app/annotationLibrary/annotationLibrary.js @@ -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, @@ -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 = {}; @@ -30,7 +32,7 @@ angular.module('bawApp.annotationLibrary', ['bawApp.configuration']) } } } - console.log(hash); + //console.log(hash); return hash; }; $scope.calcOffsetStart = function calcOffsetStart(startOffset) { @@ -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(); }]); \ No newline at end of file diff --git a/src/app/annotationLibrary/annotationLibrary.tpl.html b/src/app/annotationLibrary/annotationLibrary.tpl.html index bf85fd78..583fb78f 100644 --- a/src/app/annotationLibrary/annotationLibrary.tpl.html +++ b/src/app/annotationLibrary/annotationLibrary.tpl.html @@ -79,8 +79,21 @@

Annotation Library

- - {{tag.text}}  
-
+ +
+
+ + +
+ + Annotation: {{tag.text}}  
+
+ +
+ + \ No newline at end of file diff --git a/src/baw.configuration.tpl.js b/src/baw.configuration.tpl.js index 341e271d..d75dc97d 100644 --- a/src/baw.configuration.tpl.js +++ b/src/baw.configuration.tpl.js @@ -180,5 +180,8 @@ angular.module('bawApp.configuration', ['url']) muted: false }, userName: "Unknown user" + }, + annotationLibrary: { + paddingSeconds: 1.0 } }); \ No newline at end of file